| 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. */ |
| 4 | export 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 | } |