Diffinery

codician/diffinerypublic

Open-source, agent-first GitHub and GitHub Actions alternative that runs on your own Cloudflare account: git hosting, pull requests, code review and drop-in GitHub Actions YAML on Workers, Durable Objects, R2 and Containers.

21 lines · 786 BRaw History
1// JSONC (wrangler.jsonc) for the deploy scripts: scripts/render-config.mjs and scripts/turnstile.sh.
2
3/** Strip // and /* *\/ comments and trailing commas from JSONC, leaving strings intact. */
4export function parseJsonc(text) {
5 let out = "";
6 for (let i = 0; i < text.length; i++) {
7 const ch = text[i];
8 if (ch === '"') {
9 let j = i + 1;
10 while (j < text.length && text[j] !== '"') j += text[j] === "\\" ? 2 : 1;
11 out += text.slice(i, j + 1);
12 i = j;
13 } else if (ch === "/" && text[i + 1] === "/") {
14 while (i < text.length && text[i] !== "\n") i++;
15 out += "\n";
16 } else if (ch === "/" && text[i + 1] === "*") {
17 i = text.indexOf("*/", i + 2) + 1;
18 } else out += ch;
19 }
20 return JSON.parse(out.replace(/,(\s*[}\]])/g, "$1"));
21}