poku 4.3.1-canary.e84e648d → 4.3.1
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/lib/configs/poku.js +1 -1
- package/lib/polyfills/jsonc.d.ts +3 -6
- package/lib/polyfills/jsonc.js +80 -38
- package/package.json +1 -1
package/lib/configs/poku.js
CHANGED
package/lib/polyfills/jsonc.d.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Adapted from https://github.com/wellwelwel/jsonc.min
|
|
3
3
|
*/
|
|
4
|
-
declare
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
export declare const JSONC: JsoncProcessor;
|
|
9
|
-
export {};
|
|
4
|
+
export declare const JSONC: {
|
|
5
|
+
parse: <T = unknown>(text: string) => T;
|
|
6
|
+
};
|
package/lib/polyfills/jsonc.js
CHANGED
|
@@ -4,54 +4,96 @@ exports.JSONC = void 0;
|
|
|
4
4
|
/**
|
|
5
5
|
* Adapted from https://github.com/wellwelwel/jsonc.min
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
exports.JSONC = (() => {
|
|
8
|
+
const DOUBLE_QUOTE = 0x22;
|
|
9
|
+
const BACKSLASH = 0x5c;
|
|
10
|
+
const SLASH = 0x2f;
|
|
11
|
+
const ASTERISK = 0x2a;
|
|
12
|
+
const COMMA = 0x2c;
|
|
13
|
+
const CLOSE_BRACKET = 0x5d;
|
|
14
|
+
const CLOSE_BRACE = 0x7d;
|
|
15
|
+
const SPACE = 0x20;
|
|
16
|
+
const BOM = 0xfeff;
|
|
17
|
+
const toJSON = (content) => {
|
|
18
|
+
const offset = content.charCodeAt(0) === BOM ? 1 : 0;
|
|
9
19
|
const length = content.length;
|
|
10
|
-
let inBlockComment = false;
|
|
11
|
-
let inString = false;
|
|
12
|
-
let skipChar = false;
|
|
13
20
|
let result = '';
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
let segment = offset;
|
|
22
|
+
let pendingComma = false;
|
|
23
|
+
let cursor = offset;
|
|
24
|
+
while (cursor < length) {
|
|
25
|
+
const current = content.charCodeAt(cursor);
|
|
26
|
+
if (current === DOUBLE_QUOTE) {
|
|
27
|
+
if (pendingComma) {
|
|
28
|
+
result += `,${content.slice(segment, cursor)}`;
|
|
29
|
+
segment = cursor;
|
|
30
|
+
pendingComma = false;
|
|
31
|
+
}
|
|
32
|
+
cursor++;
|
|
33
|
+
for (;;) {
|
|
34
|
+
const closing = content.indexOf('"', cursor);
|
|
35
|
+
if (closing === -1) {
|
|
36
|
+
cursor = length;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
let backslashes = 0;
|
|
40
|
+
for (let pos = closing - 1; pos >= cursor && content.charCodeAt(pos) === BACKSLASH; pos--) {
|
|
41
|
+
backslashes++;
|
|
42
|
+
}
|
|
43
|
+
cursor = closing + 1;
|
|
44
|
+
if ((backslashes & 1) === 0) {
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
24
47
|
}
|
|
25
48
|
continue;
|
|
26
49
|
}
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
50
|
+
if (current === SLASH) {
|
|
51
|
+
const next = content.charCodeAt(cursor + 1);
|
|
52
|
+
if (next === SLASH) {
|
|
53
|
+
result += content.slice(segment, cursor);
|
|
54
|
+
const endOfLine = content.indexOf('\n', cursor + 2);
|
|
55
|
+
cursor = endOfLine === -1 ? length : endOfLine;
|
|
56
|
+
segment = cursor;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (next === ASTERISK) {
|
|
60
|
+
result += content.slice(segment, cursor);
|
|
61
|
+
const endOfBlock = content.indexOf('*/', cursor + 2);
|
|
62
|
+
cursor = endOfBlock === -1 ? length : endOfBlock + 2;
|
|
63
|
+
segment = cursor;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
32
66
|
}
|
|
33
|
-
if (
|
|
34
|
-
|
|
35
|
-
|
|
67
|
+
if (current === COMMA) {
|
|
68
|
+
if (pendingComma) {
|
|
69
|
+
result += `,${content.slice(segment, cursor)}`;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
result += content.slice(segment, cursor);
|
|
73
|
+
}
|
|
74
|
+
segment = cursor + 1;
|
|
75
|
+
pendingComma = true;
|
|
76
|
+
cursor++;
|
|
36
77
|
continue;
|
|
37
78
|
}
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
|
|
79
|
+
if (current === CLOSE_BRACKET || current === CLOSE_BRACE) {
|
|
80
|
+
pendingComma = false;
|
|
81
|
+
cursor++;
|
|
41
82
|
continue;
|
|
42
83
|
}
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
84
|
+
if (pendingComma && current > SPACE) {
|
|
85
|
+
result += `,${content.slice(segment, cursor)}`;
|
|
86
|
+
segment = cursor;
|
|
87
|
+
pendingComma = false;
|
|
47
88
|
}
|
|
48
|
-
|
|
89
|
+
cursor++;
|
|
90
|
+
}
|
|
91
|
+
if (pendingComma) {
|
|
92
|
+
result += ',';
|
|
49
93
|
}
|
|
94
|
+
result += content.slice(segment, length);
|
|
50
95
|
return result;
|
|
51
|
-
}
|
|
52
|
-
parse(text)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
exports.JSONC = new JsoncProcessor();
|
|
96
|
+
};
|
|
97
|
+
const parse = (text) => JSON.parse(toJSON(text));
|
|
98
|
+
return { parse };
|
|
99
|
+
})();
|