UNPKG

@intlayer/chokidar

Version:

Uses chokidar to scan and build Intlayer declaration files into dictionaries based on Intlayer configuration.

41 lines (40 loc) 1 kB
//#region src/init/utils/jsonParser.ts /** * Helper to parse JSON that may contain comments (tsconfig allows comments) */ const parseJSONWithComments = (jsonString) => { try { return JSON.parse(jsonString); } catch {} const cleanedLines = jsonString.split("\n").map((line) => { let inString = false; let result = ""; for (let i = 0; i < line.length; i++) { const char = line[i]; const nextChar = line[i + 1]; if (char === "\"" && (i === 0 || line[i - 1] !== "\\")) { inString = !inString; result += char; continue; } if (inString) { result += char; continue; } if (char === "/" && nextChar === "/") break; if (char === "/" && nextChar === "*") { const endIndex = line.indexOf("*/", i + 2); if (endIndex !== -1) { i = endIndex + 1; continue; } } result += char; } return result; }); return JSON.parse(cleanedLines.join("\n")); }; //#endregion export { parseJSONWithComments }; //# sourceMappingURL=jsonParser.mjs.map