<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Lifevor Engineering]]></title><description><![CDATA[Lifevor Engineering]]></description><link>https://lifevor.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Dec 2026 21:19:09 GMT</lastBuildDate><atom:link href="https://lifevor.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Designing Zero-Upload Tabular Data Converters in the Browser with TypeScript, SheetJS, and PapaParse]]></title><description><![CDATA[How we built browser-local Excel-to-Markdown, CSV-to-SQL, CSV/JSON converters, and a paginated CSV table viewer using an intermediate representation and…]]></description><link>https://lifevor.hashnode.dev/designing-zero-upload-tabular-data-converters-in-the-browser-with-typescript-sheetjs-and-papaparse</link><guid isPermaLink="true">https://lifevor.hashnode.dev/designing-zero-upload-tabular-data-converters-in-the-browser-with-typescript-sheetjs-and-papaparse</guid><category><![CDATA[TypeScript]]></category><category><![CDATA[webdev]]></category><category><![CDATA[React]]></category><category><![CDATA[Open Source]]></category><dc:creator><![CDATA[Lifevor]]></dc:creator><pubDate>Mon, 30 Nov 2026 15:30:14 GMT</pubDate><content:encoded><![CDATA[<p>Tabular data conversions—turning an Excel range into a Markdown table, generating SQL <code>INSERT</code> statements from a CSV export, or inspecting a messy CSV payload—almost always happen on internal spreadsheets, staging exports, or customer-adjacent datasets. Sending those files to a remote server just to reformat delimiters or escape pipe characters introduces unnecessary privacy risk and latency.</p>
<p>In <a href="https://lifevor.com">Lifevor</a>, we built a suite of browser-local data utilities using Astro, React 19, TypeScript, SheetJS (<code>xlsx</code>), PapaParse, and lazy-loaded Monaco / paginated table views. Everything parses and serializes in memory inside the user's browser tab—zero uploads, zero server queues, and zero account walls.</p>
<p>This post walks through the two complementary architectures powering five of our tabular utilities:</p>
<ol>
<li><strong>A normalized 2D grid pipeline</strong> for spreadsheet-to-text formatting (<a href="https://lifevor.com/en/tools/excel-to-markdown-table/">Excel to Markdown Table</a>).</li>
<li><strong>A record-array intermediate representation (IR)</strong> for structured schema transformations (<a href="https://lifevor.com/en/tools/csv-to-sql/">CSV to SQL</a>, <a href="https://lifevor.com/en/tools/csv-to-json/">CSV to JSON</a>, <a href="https://lifevor.com/en/tools/json-to-csv/">JSON to CSV</a>, and <a href="https://lifevor.com/en/tools/csv-viewer/">CSV Viewer</a>).</li>
</ol>
<hr />
<h2>1. Boundary Parsing for Pasted Spreadsheets &amp; <code>.xlsx</code> Workbooks</h2>
<p>When a user copies cells directly from Excel or Google Sheets, the clipboard payload is typically tab-separated text (<code>\t</code>). When they drop a file, it might be <code>.xlsx</code>, <code>.xls</code>, <code>.csv</code>, or <code>.tsv</code>.</p>
<p>Instead of sprinkling defensive checks throughout the UI, we normalize both input paths at the boundary into a single trusted <code>ParsedGrid</code> contract:</p>
<pre><code class="language-ts">export type GridAlign = 'left' | 'center' | 'right';
export type AlignMode = 'auto' | GridAlign;

export interface ParsedGrid {
  readonly headers: readonly string[];
  readonly rows: readonly (readonly string[])[];
}
</code></pre>
<h3>Handling Ragged Matrices and Mixed Clipboard Formats</h3>
<p>Real-world spreadsheets often contain trailing empty rows, uneven row lengths, or non-string cell values. Our <code>normalizeMatrix</code> helper handles these uniformly:</p>
<pre><code class="language-ts">function normalizeMatrix(rawRows: unknown[][]): ParsedGrid | null {
  const cleaned = rawRows
    .map((row) =&gt;
      row.map((cell) =&gt; (cell === null || cell === undefined ? '' : String(cell).trim()))
    )
    .filter((row) =&gt; row.some((cell) =&gt; cell.length &gt; 0));

  if (cleaned.length === 0) return null;

  const colCount = cleaned.reduce((max, row) =&gt; Math.max(max, row.length), 0);
  if (colCount === 0) return null;

  const padRow = (row: string[]): string[] =&gt;
    Array.from({ length: colCount }, (_, idx) =&gt; row[idx] ?? '');

  const headers = padRow(cleaned[0]!);
  const rows = cleaned.slice(1).map(padRow);
  return { headers, rows };
}
</code></pre>
<p>Two practical details make this reliable across clipboard pastes and file uploads:</p>
<ul>
<li><strong>Tab-first delimiter detection</strong>: In <code>parseSpreadsheetText</code>, if the trimmed text contains <code>\t</code>, we force <code>delimiter: '\t'</code> in <code>Papa.parse</code> so commas inside formatted numbers (e.g., <code>12,000</code> or <code>15,500</code>) are never misread as column separators. Otherwise, we pass <code>delimiter: ''</code> so PapaParse auto-detects CSV delimiters.</li>
<li><strong>Formatted cell strings from SheetJS</strong>: In <code>parseXlsxBuffer</code>, we read <code>ArrayBuffer</code> bytes with <code>XLSX.read(buffer, { type: 'array' })</code> and extract <code>XLSX.utils.sheet_to_json(sheet, { header: 1, raw: false, defval: '' })</code>. Setting <code>raw: false</code> preserves display formatting (percentages, currencies, dates) instead of raw serial numbers.</li>
<li><strong>Async drop race protection</strong>: Dropping a second spreadsheet while a large workbook is still reading <code>file.arrayBuffer()</code> can cause out-of-order state updates. Tracking an incrementing <code>fileSeqRef</code> ensures stale async reads exit early before calling <code>setFileGrid</code>.</li>
</ul>
<h3>Generating Safe GitHub Flavored Markdown Tables</h3>
<p>Once we have a <code>ParsedGrid</code>, producing a valid GFM pipe table in <a href="https://lifevor.com/en/tools/excel-to-markdown-table/">Excel to Markdown Table</a> only requires two small guarantees:</p>
<ol>
<li><strong>Cell escaping</strong>: Literal <code>|</code> characters inside cells must become <code>\|</code>, and embedded newlines (<code>\r?\n</code>) must collapse to <code>&lt;br&gt;</code> so a single multiline cell never splits into broken Markdown rows.</li>
<li><strong>Automatic numeric alignment</strong>: In <code>auto</code> mode, each column inspects its non-empty body cells against <code>/^[+-]?(?:\$)?\d[\d,]*(?:\.\d+)?%?$/</code>. If every non-empty value matches, the separator row emits <code>---:</code> (right-aligned); otherwise it defaults to <code>:---</code> (left-aligned).</li>
</ol>
<hr />
<h2>2. One Intermediate Representation (<code>Record&lt;string, any&gt;[]</code>) for CSV, JSON, and SQL</h2>
<p>For structured developer formats, a 2D string array isn't enough—we want named keys, nested object serialization, and consistent SQL escaping. Our <code>DataConverterEngine</code> defines a minimal <code>ConverterConfig</code> interface around a single IR (<code>Record&lt;string, any&gt;[]</code>):</p>
<pre><code class="language-ts">export type FormatType = 'json' | 'csv' | 'sql' | 'table';

export interface ConverterOptions {
  tableName?: string;
  csvDelimiter?: string;
}

export interface ConverterConfig {
  slug: string;
  inputFormat: FormatType;
  outputFormat: FormatType;
  availableInputs: FormatType[];
  availableOutputs: FormatType[];
  parse: (text: string) =&gt; Record&lt;string, any&gt;[];
  stringify: (ir: Record&lt;string, any&gt;[], options?: ConverterOptions) =&gt; string;
}
</code></pre>
<p>With this abstraction, each tool is a tiny declarative config:</p>
<ul>
<li><a href="https://lifevor.com/en/tools/csv-to-sql/">CSV to SQL</a>: <code>parseCsv</code> -&gt; <code>stringifySql</code></li>
<li><a href="https://lifevor.com/en/tools/csv-to-json/">CSV to JSON</a>: <code>parseCsv</code> -&gt; <code>stringifyJson</code></li>
<li><a href="https://lifevor.com/en/tools/json-to-csv/">JSON to CSV</a>: <code>parseJson</code> -&gt; <code>stringifyCsv</code></li>
<li><a href="https://lifevor.com/en/tools/csv-viewer/">CSV Viewer</a>: <code>parseCsv</code> -&gt; interactive <code>TableViewer</code></li>
</ul>
<h3>SQL Generation Edge Cases That Bite Naive Scripts</h3>
<p>When generating <code>CREATE TABLE</code> + <code>INSERT INTO</code> output in <code>stringifySql</code>, naive string interpolation breaks quickly on real CSVs:</p>
<ol>
<li><strong>Heterogeneous keys across rows</strong>: Rather than assuming row <code>0</code> has every column, we build a <code>Set&lt;string&gt;</code> across all rows in the IR so sparse JSON arrays or irregular records still produce a complete schema.</li>
<li><strong>Identifier sanitization</strong>: The user-editable table name strips backticks and backslashes (<code>rawTableName.replace(/[</code>\]/g, '').trim() || 'my_table'<code>) before wrapping in ``</code> ...` ``.</li>
<li><strong>Typed literal mapping</strong>:<ul>
<li><code>null</code>, <code>undefined</code>, <code>''</code>, and non-finite numbers map to <code>NULL</code>.</li>
<li>Booleans map to <code>TRUE</code> / <code>FALSE</code>.</li>
<li>Finite numbers emit unquoted numeric literals.</li>
<li>Strings and nested objects (serialized with <code>JSON.stringify</code>) escape single quotes via <code>.replace(/'/g, "''")</code> before single-quote wrapping.</li>
</ul>
</li>
</ol>
<h3>Keeping Large Edits Responsive with Lazy Viewers &amp; Debounced Parsing</h3>
<p>Mounting Monaco Editor or rendering thousands of DOM table cells synchronously on every keystroke makes the input laggy. In <code>DataConverterEngine</code>:</p>
<ul>
<li>Parsing and stringifying run inside a <code>200ms</code> debounced effect whenever <code>inputText</code> or <code>tableName</code> changes.</li>
<li>Both <code>@monaco-editor/react</code> (<code>CodeViewer</code>) and <code>TableViewer</code> are loaded via <code>React.lazy</code> + <code>Suspense</code>.</li>
<li><code>TableViewer</code> slices rows into configurable pages (<code>20</code>, <code>50</code>, or <code>100</code> rows per page) with client-side column sorting and one-click CSV export—making <a href="https://lifevor.com/en/tools/csv-viewer/">CSV Viewer</a> usable even on multi-thousand-row exports without freezing the browser tab.</li>
</ul>
<hr />
<h2>Try the Tools (100% Client-Side)</h2>
<p>All five tools run locally in your browser with no file size upload limits or sign-up gates:</p>
<ul>
<li><a href="https://lifevor.com/en/tools/excel-to-markdown-table/">Excel to Markdown Table</a> — Paste Excel cells or drop <code>.xlsx</code>/<code>.xls</code>/<code>.csv</code> files with auto numeric alignment and live Markdown preview.</li>
<li><a href="https://lifevor.com/en/tools/csv-to-sql/">CSV to SQL</a> — Generate <code>CREATE TABLE</code> and multi-row <code>INSERT INTO</code> SQL statements locally with customizable table names.</li>
<li><a href="https://lifevor.com/en/tools/csv-to-json/">CSV to JSON</a> — Parse headered CSV into formatted JSON arrays with Monaco preview and download.</li>
<li><a href="https://lifevor.com/en/tools/json-to-csv/">JSON to CSV</a> — Convert JSON arrays or single objects into RFC-compliant CSV via PapaParse.</li>
<li><a href="https://lifevor.com/en/tools/csv-viewer/">CSV Viewer</a> — Inspect, sort, paginate, and re-export CSV datasets entirely in-browser.</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Round-Tripping Markdown, LaTeX Math, and Native Word (.docx) Equations in the Browser]]></title><description><![CDATA[How we convert LaTeX <-> Word OMML and Markdown <-> DOCX 100% client-side using Temml, mathml2omml, Marked, docx, and JSZip]]></description><link>https://lifevor.hashnode.dev/round-tripping-markdown-latex-math-and-native-word-docx-equations-in-the-browser</link><guid isPermaLink="true">https://lifevor.hashnode.dev/round-tripping-markdown-latex-math-and-native-word-docx-equations-in-the-browser</guid><category><![CDATA[markdown]]></category><category><![CDATA[latex]]></category><category><![CDATA[.docx]]></category><category><![CDATA[TypeScript]]></category><dc:creator><![CDATA[Lifevor]]></dc:creator><pubDate>Tue, 24 Nov 2026 06:25:30 GMT</pubDate><content:encoded><![CDATA[<p>Most web-based Markdown-to-Word or LaTeX-to-Word converters take one of two shortcuts: they either send your document to a server running Pandoc, or they rasterize equations into blurry PNG images inside <code>.docx</code>.</p>
<p>On <a href="https://lifevor.com">Lifevor</a>, we wanted <strong>native, editable Microsoft Word equations</strong> (Office Math Markup Language, or <strong>OMML</strong>) and full <strong>Markdown ↔ DOCX</strong> round-tripping—running 100% inside the browser with zero server uploads.</p>
<p>Here is how we wired up <strong>Temml</strong>, <strong>mathml2omml</strong>, <strong>Marked</strong>, <strong>docx</strong>, and <strong>JSZip</strong> to handle both directions cleanly.</p>
<hr />
<h2>1. LaTeX → Native Word OMML (<code>&lt;m:oMath&gt;</code>)</h2>
<p>Word does not understand raw LaTeX strings inside <code>.docx</code> XML; it expects <strong>OMML</strong> (<code>&lt;m:oMath&gt;</code> / <code>&lt;m:oMathPara&gt;</code>). Fortunately, <strong>MathML</strong> sits right in the middle as a clean bridge:</p>
<pre><code class="language-text">LaTeX  ──(temml)──▶  XML MathML  ──(mathml2omml)──▶  Word OMML  ──(docx ImportedXmlComponent)──▶  .docx
</code></pre>
<p>In our <a href="https://lifevor.com/en/tools/latex-to-word-equation/">LaTeX to Word Equation</a> converter, we first normalize common AI-generated macros (like <code>\bm</code> / <code>\bold</code> → <code>\mathbf</code>) and strip outer delimiters (<code>$$...$$</code>, <code>\[...\]</code>, <code>\(...\)</code>). Then we compile to strict XML MathML with <code>temml</code> and transform it into OMML via <code>mathml2omml</code>:</p>
<pre><code class="language-ts">export function latexToDocxMath(
  latex: string,
  displayMode: boolean
): ImportedXmlComponent | TextRun {
  const clean = normalizeLatex(latex);
  try {
    const mathml = temml.renderToString(clean, {
      displayMode,
      xml: true,
      throwOnError: false,
    });
    if (mathml) {
      const omml = mml2omml(mathml);
      if (omml &amp;&amp; omml.includes('&lt;m:oMath')) {
        const parsed = ImportedXmlComponent.fromXmlString(omml) as unknown as {
          root?: ImportedXmlComponent[];
        };
        const inner = parsed.root?.[0];
        if (inner) return inner;
      }
    }
  } catch {
    // Fall back safely so .docx export never corrupts
  }
  return new TextRun({ text: clean, font: 'Cambria Math' });
}
</code></pre>
<p><strong>Why the fallback matters:</strong> if an exotic macro fails OMML conversion, falling back to a <code>Cambria Math</code> <code>TextRun</code> ensures the generated <code>.docx</code> archive still opens cleanly in Microsoft Word without triggering XML repair dialogs.</p>
<hr />
<h2>2. Extending <code>marked</code> for Block &amp; Inline Math in Markdown → DOCX</h2>
<p>In our <a href="https://lifevor.com/en/tools/markdown-to-word/">Markdown to Word</a> tool, standard GFM Markdown isn't enough—technical and AI-generated drafts are full of <code>$$...$$</code> display blocks and <code>$...$</code> / <code>\(...\)</code> inline math.</p>
<p>Instead of regex-replacing the document before parsing (which breaks inside fenced code blocks), we extended <code>marked</code> with two custom tokenizer extensions:</p>
<ul>
<li><code>mathBlock</code> (<code>level: 'block'</code>): matches <code>$$...$$</code> and <code>\[...\]</code></li>
<li><code>inlineMath</code> (<code>level: 'inline'</code>): matches <code>\(...\)</code> and <code>$...$</code> (while guarding against <code>$ </code> currency literals and escaped <code>\$</code>)</li>
</ul>
<p>When building paragraphs with <code>docx</code>'s <code>Packer</code>, each <code>mathBlock</code> or <code>inlineMath</code> token delegates directly to <code>latexToDocxMath(...)</code>. The result is a <code>.docx</code> file where headings, GFM tables, lists, code blocks, <strong>and equations</strong> are all native Word objects.</p>
<hr />
<h2>3. Reverse Direction: Unpacking <code>.docx</code> OMML Back to LaTeX</h2>
<p>Going from <code>.docx</code> back to LaTeX is a completely different problem. A <code>.docx</code> file is just a <strong>ZIP archive</strong> containing <code>word/document.xml</code> (and <code>word/numbering.xml</code> for lists).</p>
<p>In our <a href="https://lifevor.com/en/tools/word-to-latex-equation/">Word to LaTeX Equation</a> extractor:</p>
<ol>
<li>We unpack the <code>.docx</code> buffer in browser memory using <strong>JSZip</strong>.</li>
<li>We parse <code>word/document.xml</code> into a lightweight XML AST (<code>parseXmlTree</code>) without relying on Node-only XML libraries.</li>
<li>We recursively walk <code>&lt;m:oMath&gt;</code> and <code>&lt;m:oMathPara&gt;</code> nodes—translating OMML constructs (<code>m:f</code> fractions, <code>m:rad</code> radicals, <code>m:nary</code> integrals/sums, <code>m:sSup</code>/<code>m:sSub</code> scripts, <code>m:m</code> matrices) and mapping Unicode math symbols (<code>±</code>, <code>≤</code>, <code>∑</code>, <code>∫</code>, Greek letters) back to clean LaTeX commands.</li>
</ol>
<hr />
<h2>4. Resolving Lists &amp; Math in Word → Markdown</h2>
<p>When converting an entire <code>.docx</code> file back into Markdown in our <a href="https://lifevor.com/en/tools/word-to-markdown/">Word to Markdown</a> converter, the hardest part isn't headings or bold text—it's <strong>lists and embedded equations</strong>.</p>
<p>Word stores list definitions separately in <code>word/numbering.xml</code> using two indirection levels:</p>
<pre><code class="language-text">paragraph (&lt;w:numPr&gt;) ──▶ numId + ilvl ──▶ abstractNumId ──▶ numFmt ("bullet" vs "decimal")
</code></pre>
<p>By building a <code>numId -&gt; (ilvl -&gt; isOrdered)</code> lookup table first, we accurately reconstruct nested <code>-</code> bullet lists and <code>1.</code> ordered lists. Meanwhile, any inline or display <code>&lt;m:oMath&gt;</code> encountered inside a paragraph is passed to the exact same <code>ommlNodeToLatex</code> AST walker so formulas round-trip back into <code>$...$</code> or <code>$$...$$</code>.</p>
<hr />
<h2>Wrapping Up</h2>
<p>Keeping document conversion local in the browser gives users instant previews and keeps sensitive specs, papers, and AI drafts off third-party servers. You can test all four converters directly on <a href="https://lifevor.com">Lifevor</a>.</p>
]]></content:encoded></item></channel></rss>