@trim21/personal-pi-extensions 0.0.216 → 0.0.222

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/lib/jsonc.ts DELETED
@@ -1,67 +0,0 @@
1
- /**
2
- * Minimal JSONC → JSON conversion for small user-edited config files.
3
- *
4
- * Strips line and block comments and trailing commas outside of string
5
- * literals, so a stray comment in a config file does not silently void the
6
- * whole file (the way a plain `JSON.parse` would).
7
- */
8
-
9
- export function jsoncToJson(raw: string): string {
10
- let out = "";
11
- let inString = false;
12
- let i = 0;
13
- while (i < raw.length) {
14
- const c = raw[i];
15
- if (inString) {
16
- out += c;
17
- if (c === "\\" && i + 1 < raw.length) {
18
- out += raw[i + 1];
19
- i += 2;
20
- continue;
21
- }
22
- if (c === '"') inString = false;
23
- i++;
24
- continue;
25
- }
26
- switch (c) {
27
- case '"': {
28
- inString = true;
29
- out += c;
30
- i++;
31
- continue;
32
- }
33
- case "/": {
34
- if (raw[i + 1] === "/") {
35
- while (i < raw.length && raw[i] !== "\n") i++;
36
- continue;
37
- }
38
- if (raw[i + 1] === "*") {
39
- i += 2;
40
- while (i < raw.length && !(raw[i] === "*" && raw[i + 1] === "/")) i++;
41
- i += 2;
42
- continue;
43
- }
44
- out += c;
45
- i++;
46
- continue;
47
- }
48
- case ",": {
49
- // Drop a trailing comma before } or ] (outside strings).
50
- let j = i + 1;
51
- while (j < raw.length && /\s/.test(raw[j])) j++;
52
- if (raw[j] === "}" || raw[j] === "]") {
53
- i++;
54
- continue;
55
- }
56
- out += c;
57
- i++;
58
- continue;
59
- }
60
- default: {
61
- out += c;
62
- i++;
63
- }
64
- }
65
- }
66
- return out;
67
- }
File without changes
File without changes