πŸ“„ File detail

utils/jsonRead.ts

🧩 .tsπŸ“ 17 linesπŸ’Ύ 657 bytesπŸ“ text
← Back to All Files

🎯 Use case

This file lives under β€œutils/”, which covers cross-cutting helpers (shell, tempfiles, settings, messages, process input, …). On the API surface it exposes stripBOM β€” mainly functions, hooks, or classes. What the file header says: Leaf stripBOM β€” extracted from json.ts to break settings β†’ json β†’ log β†’ types/logs β†’ … β†’ settings. json.ts imports this for its memoized+logging safeParseJSON; leaf callers that can't import json.ts use stripBOM + jsonParse inline (syncCacheState does this). UTF-8 BOM (U+FEFF): P.

Generated from folder role, exports, dependency roots, and inline comments β€” not hand-reviewed for every path.

🧠 Inline summary

Leaf stripBOM β€” extracted from json.ts to break settings β†’ json β†’ log β†’ types/logs β†’ … β†’ settings. json.ts imports this for its memoized+logging safeParseJSON; leaf callers that can't import json.ts use stripBOM + jsonParse inline (syncCacheState does this). UTF-8 BOM (U+FEFF): PowerShell 5.x writes UTF-8 with BOM by default (Out-File, Set-Content). We can't control user environments, so strip on read. Without this, JSON.parse fails with "Unexpected token".

πŸ“€ Exports (heuristic)

  • stripBOM

πŸ–₯️ Source preview

/**
 * Leaf stripBOM β€” extracted from json.ts to break settings β†’ json β†’ log β†’
 * types/logs β†’ … β†’ settings. json.ts imports this for its memoized+logging
 * safeParseJSON; leaf callers that can't import json.ts use stripBOM +
 * jsonParse inline (syncCacheState does this).
 *
 * UTF-8 BOM (U+FEFF): PowerShell 5.x writes UTF-8 with BOM by default
 * (Out-File, Set-Content). We can't control user environments, so strip on
 * read. Without this, JSON.parse fails with "Unexpected token".
 */

const UTF8_BOM = '\uFEFF'

export function stripBOM(content: string): string {
  return content.startsWith(UTF8_BOM) ? content.slice(1) : content
}