MCPcopy Create free account
hub / github.com/callumalpass/tasknotes / objectToTypeScript

Function objectToTypeScript

scripts/i18n-manager.mjs:375–392  ·  view source on GitHub ↗
(obj, indent = 0)

Source from the content-addressed store, hash-verified

373
374 // Convert to TypeScript code
375 function objectToTypeScript(obj, indent = 0) {
376 const indentStr = '\t'.repeat(indent);
377 const lines = [];
378
379 for (const [key, value] of Object.entries(obj)) {
380 if (typeof value === 'object' && value !== null) {
381 lines.push(`${indentStr}${key}: {`);
382 lines.push(objectToTypeScript(value, indent + 1));
383 lines.push(`${indentStr}},`);
384 } else {
385 // Escape quotes and handle multiline strings
386 const escapedValue = value.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
387 lines.push(`${indentStr}${key}: "${escapedValue}",`);
388 }
389 }
390
391 return lines.join('\n');
392 }
393
394 const tsContent = `import { Translation } from "../types";
395

Callers 1

generateTemplateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected