@stryke/json 0.9.44 → 0.11.0
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/CHANGELOG.md +22 -0
- package/dist/code-frames-BUtrssZ5.d.cts +17 -0
- package/dist/code-frames-BUtrssZ5.d.cts.map +1 -0
- package/dist/code-frames-BmUvlJ0w.cjs +82 -0
- package/dist/code-frames-CrTAYYSE.d.mts +17 -0
- package/dist/code-frames-CrTAYYSE.d.mts.map +1 -0
- package/dist/code-frames-DuBfTMu4.mjs +77 -0
- package/dist/code-frames-DuBfTMu4.mjs.map +1 -0
- package/dist/find-reference-B8xshNXL.d.mts +52 -0
- package/dist/find-reference-B8xshNXL.d.mts.map +1 -0
- package/dist/find-reference-C-YleCds.d.cts +52 -0
- package/dist/find-reference-C-YleCds.d.cts.map +1 -0
- package/dist/find-reference-DMSYEaaI.mjs +64 -0
- package/dist/find-reference-DMSYEaaI.mjs.map +1 -0
- package/dist/find-reference-De5vBQV2.cjs +86 -0
- package/dist/index-B_e8BwCm.d.cts +1 -0
- package/dist/index-CCt0lwyI.d.mts +1 -0
- package/dist/index-CDAfh8Ew.d.cts +1 -0
- package/dist/index-DvuJXuAN.d.mts +1 -0
- package/dist/index.cjs +37 -14
- package/dist/index.d.cts +11 -8
- package/dist/index.d.mts +12 -9
- package/dist/index.mjs +13 -8
- package/dist/is-number-BIwzZzyi.mjs +31 -0
- package/dist/is-number-BIwzZzyi.mjs.map +1 -0
- package/dist/is-number-c5xguIbS.cjs +42 -0
- package/dist/{type-checks/src/is-plain-object.mjs → is-object-BpfmzHWa.mjs} +19 -3
- package/dist/is-object-BpfmzHWa.mjs.map +1 -0
- package/dist/{type-checks/src/is-plain-object.cjs → is-object-umGh91v1.cjs} +24 -3
- package/dist/is-set-object-BmHip9em.cjs +108 -0
- package/dist/is-set-object-C1Qnj1Q8.mjs +98 -0
- package/dist/is-set-object-C1Qnj1Q8.mjs.map +1 -0
- package/dist/{type-checks/src/is-string.mjs → is-string-C2RK4Gjs.cjs} +7 -2
- package/dist/{type-checks/src/is-string.cjs → is-string-CLiBUSKV.mjs} +2 -2
- package/dist/is-string-CLiBUSKV.mjs.map +1 -0
- package/dist/{type-checks/src/is-undefined.cjs → is-undefined-CmyJWYGD.mjs} +2 -2
- package/dist/is-undefined-CmyJWYGD.mjs.map +1 -0
- package/dist/{type-checks/src/is-undefined.mjs → is-undefined-CnI0qe-z.cjs} +7 -2
- package/dist/parse-BGlhbY16.d.cts +9 -0
- package/dist/parse-BGlhbY16.d.cts.map +1 -0
- package/dist/parse-Bp6kkcQ4.cjs +127 -0
- package/dist/parse-ByDxRup5.cjs +62 -0
- package/dist/parse-Cj-YfhrI.d.mts +51 -0
- package/dist/parse-Cj-YfhrI.d.mts.map +1 -0
- package/dist/parse-DZfi3d96.d.cts +51 -0
- package/dist/parse-DZfi3d96.d.cts.map +1 -0
- package/dist/parse-Dn43ZK9y.mjs +52 -0
- package/dist/parse-Dn43ZK9y.mjs.map +1 -0
- package/dist/parse-error-7K8s4vWf.d.cts +15 -0
- package/dist/parse-error-7K8s4vWf.d.cts.map +1 -0
- package/dist/parse-error-Af4zHUQ_.mjs +34 -0
- package/dist/parse-error-Af4zHUQ_.mjs.map +1 -0
- package/dist/parse-error-DpEv3vo_.d.mts +15 -0
- package/dist/parse-error-DpEv3vo_.d.mts.map +1 -0
- package/dist/parse-error-N7UE-HMh.cjs +39 -0
- package/dist/parse-fXy5pbmE.d.mts +9 -0
- package/dist/parse-fXy5pbmE.d.mts.map +1 -0
- package/dist/parse-vw_qRD3F.mjs +81 -0
- package/dist/parse-vw_qRD3F.mjs.map +1 -0
- package/dist/pointer/find-reference.cjs +5 -65
- package/dist/pointer/find-reference.d.cts +2 -52
- package/dist/pointer/find-reference.d.mts +2 -52
- package/dist/pointer/find-reference.mjs +2 -63
- package/dist/pointer/index.cjs +15 -14
- package/dist/pointer/index.d.cts +2 -2
- package/dist/pointer/index.d.mts +2 -2
- package/dist/pointer/index.mjs +3 -2
- package/dist/pointer/parse.cjs +9 -86
- package/dist/pointer/parse.d.cts +2 -44
- package/dist/pointer/parse.d.mts +2 -44
- package/dist/pointer/parse.mjs +2 -80
- package/dist/pointer-B3W_Sme3.cjs +0 -0
- package/dist/pointer-Dn__XOdY.mjs +0 -0
- package/dist/schema-BO1HCrxv.d.cts +55 -0
- package/dist/schema-BO1HCrxv.d.cts.map +1 -0
- package/dist/schema-CmH1V_uI.d.mts +55 -0
- package/dist/schema-CmH1V_uI.d.mts.map +1 -0
- package/dist/schema-DGmzxHja.mjs +72 -0
- package/dist/schema-DGmzxHja.mjs.map +1 -0
- package/dist/schema-Dl018Aq4.cjs +106 -0
- package/dist/schema.cjs +8 -0
- package/dist/schema.d.cts +2 -0
- package/dist/schema.d.mts +3 -0
- package/dist/schema.mjs +3 -0
- package/dist/storm-json-8F9CKpXu.d.mts +70 -0
- package/dist/storm-json-8F9CKpXu.d.mts.map +1 -0
- package/dist/storm-json-BD6WFbrI.cjs +154 -0
- package/dist/storm-json-DvIEWMEH.d.cts +70 -0
- package/dist/storm-json-DvIEWMEH.d.cts.map +1 -0
- package/dist/storm-json-nkhJgTz4.mjs +116 -0
- package/dist/storm-json-nkhJgTz4.mjs.map +1 -0
- package/dist/storm-json.cjs +3 -116
- package/dist/storm-json.d.cts +2 -70
- package/dist/storm-json.d.mts +3 -70
- package/dist/storm-json.mjs +3 -115
- package/dist/stringify-Bc8OkhIr.d.cts +13 -0
- package/dist/stringify-Bc8OkhIr.d.cts.map +1 -0
- package/dist/stringify-BehjrfhS.cjs +78 -0
- package/dist/stringify-CFT1K1LE.d.mts +13 -0
- package/dist/stringify-CFT1K1LE.d.mts.map +1 -0
- package/dist/stringify-CYHjAvWm.mjs +68 -0
- package/dist/stringify-CYHjAvWm.mjs.map +1 -0
- package/dist/strip-comments-BA8MS_Fs.d.mts +11 -0
- package/dist/strip-comments-BA8MS_Fs.d.mts.map +1 -0
- package/dist/strip-comments-CmEG_smS.cjs +94 -0
- package/dist/strip-comments-Cz_Wc25t.d.cts +11 -0
- package/dist/strip-comments-Cz_Wc25t.d.cts.map +1 -0
- package/dist/strip-comments-Dq00N_Sg.mjs +89 -0
- package/dist/strip-comments-Dq00N_Sg.mjs.map +1 -0
- package/dist/types-Bn8rC098.d.cts +222 -0
- package/dist/types-Bn8rC098.d.cts.map +1 -0
- package/dist/types-CPQlxauZ.d.mts +222 -0
- package/dist/types-CPQlxauZ.d.mts.map +1 -0
- package/dist/types.d.cts +2 -69
- package/dist/types.d.mts +2 -69
- package/dist/types.mjs +0 -1
- package/dist/utils/code-frames.cjs +2 -76
- package/dist/utils/code-frames.d.cts +2 -17
- package/dist/utils/code-frames.d.mts +2 -17
- package/dist/utils/code-frames.mjs +2 -76
- package/dist/utils/index.cjs +13 -12
- package/dist/utils/index.d.cts +5 -5
- package/dist/utils/index.d.mts +6 -5
- package/dist/utils/index.mjs +6 -5
- package/dist/utils/parse-error.cjs +2 -33
- package/dist/utils/parse-error.d.cts +2 -15
- package/dist/utils/parse-error.d.mts +2 -15
- package/dist/utils/parse-error.mjs +2 -33
- package/dist/utils/parse.cjs +3 -51
- package/dist/utils/parse.d.cts +2 -9
- package/dist/utils/parse.d.mts +2 -9
- package/dist/utils/parse.mjs +2 -51
- package/dist/utils/stringify.cjs +3 -67
- package/dist/utils/stringify.d.cts +2 -13
- package/dist/utils/stringify.d.mts +2 -13
- package/dist/utils/stringify.mjs +2 -67
- package/dist/utils/strip-comments.cjs +2 -85
- package/dist/utils/strip-comments.d.cts +2 -11
- package/dist/utils/strip-comments.d.mts +2 -11
- package/dist/utils/strip-comments.mjs +2 -86
- package/dist/utils-jN2UkvqB.cjs +0 -0
- package/dist/utils-mEkKIcgl.mjs +0 -0
- package/package.json +12 -3
- package/dist/_virtual/rolldown_runtime.cjs +0 -29
- package/dist/pointer/find-reference.d.cts.map +0 -1
- package/dist/pointer/find-reference.d.mts.map +0 -1
- package/dist/pointer/find-reference.mjs.map +0 -1
- package/dist/pointer/parse.d.cts.map +0 -1
- package/dist/pointer/parse.d.mts.map +0 -1
- package/dist/pointer/parse.mjs.map +0 -1
- package/dist/storm-json.d.cts.map +0 -1
- package/dist/storm-json.d.mts.map +0 -1
- package/dist/storm-json.mjs.map +0 -1
- package/dist/type-checks/src/get-object-tag.cjs +0 -15
- package/dist/type-checks/src/get-object-tag.mjs +0 -15
- package/dist/type-checks/src/get-object-tag.mjs.map +0 -1
- package/dist/type-checks/src/is-empty.cjs +0 -20
- package/dist/type-checks/src/is-empty.mjs +0 -21
- package/dist/type-checks/src/is-empty.mjs.map +0 -1
- package/dist/type-checks/src/is-non-null-object.cjs +0 -16
- package/dist/type-checks/src/is-non-null-object.mjs +0 -17
- package/dist/type-checks/src/is-non-null-object.mjs.map +0 -1
- package/dist/type-checks/src/is-null.cjs +0 -12
- package/dist/type-checks/src/is-null.mjs +0 -12
- package/dist/type-checks/src/is-null.mjs.map +0 -1
- package/dist/type-checks/src/is-number.cjs +0 -18
- package/dist/type-checks/src/is-number.mjs +0 -18
- package/dist/type-checks/src/is-number.mjs.map +0 -1
- package/dist/type-checks/src/is-object.cjs +0 -19
- package/dist/type-checks/src/is-object.mjs +0 -20
- package/dist/type-checks/src/is-object.mjs.map +0 -1
- package/dist/type-checks/src/is-plain-object.mjs.map +0 -1
- package/dist/type-checks/src/is-set-object.cjs +0 -19
- package/dist/type-checks/src/is-set-object.mjs +0 -20
- package/dist/type-checks/src/is-set-object.mjs.map +0 -1
- package/dist/type-checks/src/is-set.cjs +0 -19
- package/dist/type-checks/src/is-set.mjs +0 -20
- package/dist/type-checks/src/is-set.mjs.map +0 -1
- package/dist/type-checks/src/is-string.mjs.map +0 -1
- package/dist/type-checks/src/is-undefined.mjs.map +0 -1
- package/dist/types/src/base.cjs +0 -6
- package/dist/types/src/base.mjs +0 -6
- package/dist/types/src/base.mjs.map +0 -1
- package/dist/types/src/json.d.cts +0 -12
- package/dist/types/src/json.d.cts.map +0 -1
- package/dist/types/src/json.d.mts +0 -12
- package/dist/types/src/json.d.mts.map +0 -1
- package/dist/types.d.cts.map +0 -1
- package/dist/types.d.mts.map +0 -1
- package/dist/utils/code-frames.d.cts.map +0 -1
- package/dist/utils/code-frames.d.mts.map +0 -1
- package/dist/utils/code-frames.mjs.map +0 -1
- package/dist/utils/parse-error.d.cts.map +0 -1
- package/dist/utils/parse-error.d.mts.map +0 -1
- package/dist/utils/parse-error.mjs.map +0 -1
- package/dist/utils/parse.d.cts.map +0 -1
- package/dist/utils/parse.d.mts.map +0 -1
- package/dist/utils/parse.mjs.map +0 -1
- package/dist/utils/stringify.d.cts.map +0 -1
- package/dist/utils/stringify.d.mts.map +0 -1
- package/dist/utils/stringify.mjs.map +0 -1
- package/dist/utils/strip-comments.d.cts.map +0 -1
- package/dist/utils/strip-comments.d.mts.map +0 -1
- package/dist/utils/strip-comments.mjs.map +0 -1
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
const require_is_number = require('./is-number-c5xguIbS.cjs');
|
|
2
|
+
const require_is_string = require('./is-string-C2RK4Gjs.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/pointer/parse.ts
|
|
5
|
+
const TILDE_ONE = /~1/g;
|
|
6
|
+
const TILDE_ZERO = /~0/g;
|
|
7
|
+
const TILDE = /~/g;
|
|
8
|
+
const FORWARD_SLASH = /\//g;
|
|
9
|
+
/**
|
|
10
|
+
* Escapes a JSON pointer path segment.
|
|
11
|
+
*
|
|
12
|
+
* @param segment - JSON pointer path segment.
|
|
13
|
+
* @returns Escaped JSON pointer path segment.
|
|
14
|
+
*/
|
|
15
|
+
function escapePointerSegment(segment) {
|
|
16
|
+
if (!segment.includes("/") && !segment.includes("~")) return segment;
|
|
17
|
+
return segment.replace(TILDE, "~0").replace(FORWARD_SLASH, "~1");
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Unescapes a JSON pointer path segment.
|
|
21
|
+
*
|
|
22
|
+
* @param segment - JSON pointer path segment.
|
|
23
|
+
* @returns Unescaped JSON pointer path segment.
|
|
24
|
+
*/
|
|
25
|
+
function unescapePointerSegment(segment) {
|
|
26
|
+
if (!segment.includes("~")) return segment;
|
|
27
|
+
return segment.replace(TILDE_ONE, "/").replace(TILDE_ZERO, "~");
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Convert JSON pointer like "/foo/bar" to array like ["", "foo", "bar"], while
|
|
31
|
+
* also un-escaping reserved characters.
|
|
32
|
+
*/
|
|
33
|
+
function parseJsonPointer(pointer) {
|
|
34
|
+
if (!pointer) return [];
|
|
35
|
+
return pointer.slice(1).split("/").map((segment) => unescapePointerSegment(segment));
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Escape and format a path array like ["", "foo", "bar"] to JSON pointer
|
|
39
|
+
* like "/foo/bar".
|
|
40
|
+
*/
|
|
41
|
+
function formatJsonPointer(path) {
|
|
42
|
+
if (isRoot(path)) return "";
|
|
43
|
+
return `/${path.map((segment) => escapePointerSegment(String(segment))).join("/")}`;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Returns true if JSON Pointer points to root value, false otherwise.
|
|
47
|
+
*/
|
|
48
|
+
const isRoot = (path) => require_is_string.isString(path) ? path === "" : require_is_number.isNumber(path) ? path === 0 : Array.isArray(path) && path.length === 0;
|
|
49
|
+
/**
|
|
50
|
+
* Returns parent path, e.g. for ['foo', 'bar', 'baz'] returns ['foo', 'bar'].
|
|
51
|
+
*/
|
|
52
|
+
function parent(path) {
|
|
53
|
+
if (path.length === 0) throw new Error("NO_PARENT");
|
|
54
|
+
return path.slice(0, -1);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Check if path component can be a valid array index.
|
|
58
|
+
*/
|
|
59
|
+
function isValidIndex(index) {
|
|
60
|
+
if (require_is_number.isNumber(index)) return true;
|
|
61
|
+
const n = Number.parseInt(index, 10);
|
|
62
|
+
return String(n) === index && n >= 0;
|
|
63
|
+
}
|
|
64
|
+
const isInteger = (str) => {
|
|
65
|
+
const len = str.length;
|
|
66
|
+
let i = 0;
|
|
67
|
+
let charCode;
|
|
68
|
+
while (i < len) {
|
|
69
|
+
charCode = str.codePointAt(i);
|
|
70
|
+
if (charCode >= 48 && charCode <= 57) {
|
|
71
|
+
i++;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
Object.defineProperty(exports, 'escapePointerSegment', {
|
|
81
|
+
enumerable: true,
|
|
82
|
+
get: function () {
|
|
83
|
+
return escapePointerSegment;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
Object.defineProperty(exports, 'formatJsonPointer', {
|
|
87
|
+
enumerable: true,
|
|
88
|
+
get: function () {
|
|
89
|
+
return formatJsonPointer;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
Object.defineProperty(exports, 'isInteger', {
|
|
93
|
+
enumerable: true,
|
|
94
|
+
get: function () {
|
|
95
|
+
return isInteger;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
Object.defineProperty(exports, 'isRoot', {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
get: function () {
|
|
101
|
+
return isRoot;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
Object.defineProperty(exports, 'isValidIndex', {
|
|
105
|
+
enumerable: true,
|
|
106
|
+
get: function () {
|
|
107
|
+
return isValidIndex;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
Object.defineProperty(exports, 'parent', {
|
|
111
|
+
enumerable: true,
|
|
112
|
+
get: function () {
|
|
113
|
+
return parent;
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
Object.defineProperty(exports, 'parseJsonPointer', {
|
|
117
|
+
enumerable: true,
|
|
118
|
+
get: function () {
|
|
119
|
+
return parseJsonPointer;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
Object.defineProperty(exports, 'unescapePointerSegment', {
|
|
123
|
+
enumerable: true,
|
|
124
|
+
get: function () {
|
|
125
|
+
return unescapePointerSegment;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const require_strip_comments = require('./strip-comments-CmEG_smS.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/utils/parse.ts
|
|
4
|
+
const suspectProtoRx = /"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/;
|
|
5
|
+
const suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
|
|
6
|
+
const JsonSigRx = /^\s*["[{]|^\s*-?\d{1,16}(?:\.\d{1,17})?(?:E[+-]?\d+)?\s*$/i;
|
|
7
|
+
function jsonParseTransform(key, value) {
|
|
8
|
+
if (key === "__proto__" || key === "constructor" && value && typeof value === "object" && "prototype" in value) {
|
|
9
|
+
console.warn(`Dropping "${key}" key to prevent prototype pollution.`);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
function parse(value, options = {}) {
|
|
15
|
+
if (typeof value !== "string") return value;
|
|
16
|
+
let stripped = require_strip_comments.stripComments(value);
|
|
17
|
+
if (stripped[0] === "\"" && stripped[stripped.length - 1] === "\"" && !stripped.includes("\\")) return stripped.slice(1, -1);
|
|
18
|
+
stripped = stripped.trim();
|
|
19
|
+
if (stripped.length <= 9) switch (stripped.toLowerCase()) {
|
|
20
|
+
case "true": return true;
|
|
21
|
+
case "false": return false;
|
|
22
|
+
case "undefined": return;
|
|
23
|
+
case "null": return null;
|
|
24
|
+
case "nan": return NaN;
|
|
25
|
+
case "infinity": return Number.POSITIVE_INFINITY;
|
|
26
|
+
case "-infinity": return Number.NEGATIVE_INFINITY;
|
|
27
|
+
}
|
|
28
|
+
if (!JsonSigRx.test(stripped)) {
|
|
29
|
+
if (options.strict) throw new Error("Invalid JSON");
|
|
30
|
+
return stripped;
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
if (suspectProtoRx.test(stripped) || suspectConstructorRx.test(stripped)) {
|
|
34
|
+
if (options.strict) throw new Error("Possible prototype pollution");
|
|
35
|
+
return JSON.parse(stripped, jsonParseTransform);
|
|
36
|
+
}
|
|
37
|
+
return JSON.parse(stripped);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
if (options.strict) throw error;
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function safeParse(value, options = {}) {
|
|
44
|
+
return parse(value, {
|
|
45
|
+
...options,
|
|
46
|
+
strict: true
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
51
|
+
Object.defineProperty(exports, 'parse', {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function () {
|
|
54
|
+
return parse;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
Object.defineProperty(exports, 'safeParse', {
|
|
58
|
+
enumerable: true,
|
|
59
|
+
get: function () {
|
|
60
|
+
return safeParse;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
//#region ../types/src/json.d.ts
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Matches a JSON pointer's path segments.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* These segments are used to navigate through the JSON object structure and point to a specific, referenced value.
|
|
8
|
+
*/
|
|
9
|
+
type JsonPointerPath = (string | number)[];
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/pointer/parse.d.ts
|
|
12
|
+
/**
|
|
13
|
+
* Escapes a JSON pointer path segment.
|
|
14
|
+
*
|
|
15
|
+
* @param segment - JSON pointer path segment.
|
|
16
|
+
* @returns Escaped JSON pointer path segment.
|
|
17
|
+
*/
|
|
18
|
+
declare function escapePointerSegment(segment: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Unescapes a JSON pointer path segment.
|
|
21
|
+
*
|
|
22
|
+
* @param segment - JSON pointer path segment.
|
|
23
|
+
* @returns Unescaped JSON pointer path segment.
|
|
24
|
+
*/
|
|
25
|
+
declare function unescapePointerSegment(segment: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Convert JSON pointer like "/foo/bar" to array like ["", "foo", "bar"], while
|
|
28
|
+
* also un-escaping reserved characters.
|
|
29
|
+
*/
|
|
30
|
+
declare function parseJsonPointer(pointer: string): JsonPointerPath;
|
|
31
|
+
/**
|
|
32
|
+
* Escape and format a path array like ["", "foo", "bar"] to JSON pointer
|
|
33
|
+
* like "/foo/bar".
|
|
34
|
+
*/
|
|
35
|
+
declare function formatJsonPointer(path: JsonPointerPath): string;
|
|
36
|
+
/**
|
|
37
|
+
* Returns true if JSON Pointer points to root value, false otherwise.
|
|
38
|
+
*/
|
|
39
|
+
declare const isRoot: (path: string | number | JsonPointerPath) => boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Returns parent path, e.g. for ['foo', 'bar', 'baz'] returns ['foo', 'bar'].
|
|
42
|
+
*/
|
|
43
|
+
declare function parent(path: JsonPointerPath): JsonPointerPath;
|
|
44
|
+
/**
|
|
45
|
+
* Check if path component can be a valid array index.
|
|
46
|
+
*/
|
|
47
|
+
declare function isValidIndex(index: string | number): boolean;
|
|
48
|
+
declare const isInteger: (str: string) => boolean;
|
|
49
|
+
//#endregion
|
|
50
|
+
export { isValidIndex as a, unescapePointerSegment as c, isRoot as i, formatJsonPointer as n, parent as o, isInteger as r, parseJsonPointer as s, escapePointerSegment as t };
|
|
51
|
+
//# sourceMappingURL=parse-Cj-YfhrI.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-Cj-YfhrI.d.mts","names":[],"sources":["../../types/src/json.ts","../src/pointer/parse.ts"],"sourcesContent":[],"mappings":";;;;;;;;KA6CY,eAAA;;;AAAZ;;;;ACZA;AAcA;AAYgB,iBA1BA,oBAAA,CA0BmC,OAAe,EAAA,MAAA,CAAA,EAAA,MAAA;AAalE;AAYA;AAUA;AAWA;AAUA;;iBApEgB,sBAAA;;;;;iBAYA,gBAAA,mBAAmC;;;;;iBAanC,iBAAA,OAAwB;;;;cAY3B,iCAAkC;;;;iBAU/B,MAAA,OAAa,kBAAkB;;;;iBAW/B,YAAA;cAUH"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
//#region ../types/src/json.d.ts
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Matches a JSON pointer's path segments.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* These segments are used to navigate through the JSON object structure and point to a specific, referenced value.
|
|
8
|
+
*/
|
|
9
|
+
type JsonPointerPath = (string | number)[];
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/pointer/parse.d.ts
|
|
12
|
+
/**
|
|
13
|
+
* Escapes a JSON pointer path segment.
|
|
14
|
+
*
|
|
15
|
+
* @param segment - JSON pointer path segment.
|
|
16
|
+
* @returns Escaped JSON pointer path segment.
|
|
17
|
+
*/
|
|
18
|
+
declare function escapePointerSegment(segment: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Unescapes a JSON pointer path segment.
|
|
21
|
+
*
|
|
22
|
+
* @param segment - JSON pointer path segment.
|
|
23
|
+
* @returns Unescaped JSON pointer path segment.
|
|
24
|
+
*/
|
|
25
|
+
declare function unescapePointerSegment(segment: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Convert JSON pointer like "/foo/bar" to array like ["", "foo", "bar"], while
|
|
28
|
+
* also un-escaping reserved characters.
|
|
29
|
+
*/
|
|
30
|
+
declare function parseJsonPointer(pointer: string): JsonPointerPath;
|
|
31
|
+
/**
|
|
32
|
+
* Escape and format a path array like ["", "foo", "bar"] to JSON pointer
|
|
33
|
+
* like "/foo/bar".
|
|
34
|
+
*/
|
|
35
|
+
declare function formatJsonPointer(path: JsonPointerPath): string;
|
|
36
|
+
/**
|
|
37
|
+
* Returns true if JSON Pointer points to root value, false otherwise.
|
|
38
|
+
*/
|
|
39
|
+
declare const isRoot: (path: string | number | JsonPointerPath) => boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Returns parent path, e.g. for ['foo', 'bar', 'baz'] returns ['foo', 'bar'].
|
|
42
|
+
*/
|
|
43
|
+
declare function parent(path: JsonPointerPath): JsonPointerPath;
|
|
44
|
+
/**
|
|
45
|
+
* Check if path component can be a valid array index.
|
|
46
|
+
*/
|
|
47
|
+
declare function isValidIndex(index: string | number): boolean;
|
|
48
|
+
declare const isInteger: (str: string) => boolean;
|
|
49
|
+
//#endregion
|
|
50
|
+
export { isValidIndex as a, unescapePointerSegment as c, isRoot as i, formatJsonPointer as n, parent as o, isInteger as r, parseJsonPointer as s, escapePointerSegment as t };
|
|
51
|
+
//# sourceMappingURL=parse-DZfi3d96.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-DZfi3d96.d.cts","names":[],"sources":["../../types/src/json.ts","../src/pointer/parse.ts"],"sourcesContent":[],"mappings":";;;;;;;;KA6CY,eAAA;;;AAAZ;;;;ACZA;AAcA;AAYgB,iBA1BA,oBAAA,CA0BmC,OAAe,EAAA,MAAA,CAAA,EAAA,MAAA;AAalE;AAYA;AAUA;AAWA;AAUA;;iBApEgB,sBAAA;;;;;iBAYA,gBAAA,mBAAmC;;;;;iBAanC,iBAAA,OAAwB;;;;cAY3B,iCAAkC;;;;iBAU/B,MAAA,OAAa,kBAAkB;;;;iBAW/B,YAAA;cAUH"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { t as stripComments } from "./strip-comments-Dq00N_Sg.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/parse.ts
|
|
4
|
+
const suspectProtoRx = /"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/;
|
|
5
|
+
const suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
|
|
6
|
+
const JsonSigRx = /^\s*["[{]|^\s*-?\d{1,16}(?:\.\d{1,17})?(?:E[+-]?\d+)?\s*$/i;
|
|
7
|
+
function jsonParseTransform(key, value) {
|
|
8
|
+
if (key === "__proto__" || key === "constructor" && value && typeof value === "object" && "prototype" in value) {
|
|
9
|
+
console.warn(`Dropping "${key}" key to prevent prototype pollution.`);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
function parse(value, options = {}) {
|
|
15
|
+
if (typeof value !== "string") return value;
|
|
16
|
+
let stripped = stripComments(value);
|
|
17
|
+
if (stripped[0] === "\"" && stripped[stripped.length - 1] === "\"" && !stripped.includes("\\")) return stripped.slice(1, -1);
|
|
18
|
+
stripped = stripped.trim();
|
|
19
|
+
if (stripped.length <= 9) switch (stripped.toLowerCase()) {
|
|
20
|
+
case "true": return true;
|
|
21
|
+
case "false": return false;
|
|
22
|
+
case "undefined": return;
|
|
23
|
+
case "null": return null;
|
|
24
|
+
case "nan": return NaN;
|
|
25
|
+
case "infinity": return Number.POSITIVE_INFINITY;
|
|
26
|
+
case "-infinity": return Number.NEGATIVE_INFINITY;
|
|
27
|
+
}
|
|
28
|
+
if (!JsonSigRx.test(stripped)) {
|
|
29
|
+
if (options.strict) throw new Error("Invalid JSON");
|
|
30
|
+
return stripped;
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
if (suspectProtoRx.test(stripped) || suspectConstructorRx.test(stripped)) {
|
|
34
|
+
if (options.strict) throw new Error("Possible prototype pollution");
|
|
35
|
+
return JSON.parse(stripped, jsonParseTransform);
|
|
36
|
+
}
|
|
37
|
+
return JSON.parse(stripped);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
if (options.strict) throw error;
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function safeParse(value, options = {}) {
|
|
44
|
+
return parse(value, {
|
|
45
|
+
...options,
|
|
46
|
+
strict: true
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
51
|
+
export { safeParse as n, parse as t };
|
|
52
|
+
//# sourceMappingURL=parse-Dn43ZK9y.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-Dn43ZK9y.mjs","names":[],"sources":["../src/utils/parse.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { stripComments } from \"./strip-comments\";\n\n// https://github.com/fastify/secure-json-parse\n// https://github.com/hapijs/bourne\nconst suspectProtoRx =\n /\"(?:_|\\\\u0{2}5[Ff]){2}(?:p|\\\\u0{2}70)(?:r|\\\\u0{2}72)(?:o|\\\\u0{2}6[Ff])(?:t|\\\\u0{2}74)(?:o|\\\\u0{2}6[Ff])(?:_|\\\\u0{2}5[Ff]){2}\"\\s*:/;\nconst suspectConstructorRx =\n /\"(?:c|\\\\u0063)(?:o|\\\\u006[Ff])(?:n|\\\\u006[Ee])(?:s|\\\\u0073)(?:t|\\\\u0074)(?:r|\\\\u0072)(?:u|\\\\u0075)(?:c|\\\\u0063)(?:t|\\\\u0074)(?:o|\\\\u006[Ff])(?:r|\\\\u0072)\"\\s*:/;\n\nconst JsonSigRx = /^\\s*[\"[{]|^\\s*-?\\d{1,16}(?:\\.\\d{1,17})?(?:E[+-]?\\d+)?\\s*$/i;\n\nfunction jsonParseTransform(key: string, value: any): any {\n if (\n key === \"__proto__\" ||\n (key === \"constructor\" &&\n value &&\n typeof value === \"object\" &&\n \"prototype\" in value)\n ) {\n // eslint-disable-next-line no-console\n console.warn(`Dropping \"${key}\" key to prevent prototype pollution.`);\n return;\n }\n return value;\n}\n\nexport interface Options {\n strict?: boolean;\n}\n\nexport function parse<T = unknown>(value: any, options: Options = {}): T {\n if (typeof value !== \"string\") {\n return value;\n }\n\n let stripped = stripComments(value);\n\n if (\n stripped[0] === '\"' &&\n stripped[stripped.length - 1] === '\"' &&\n !stripped.includes(\"\\\\\")\n ) {\n return stripped.slice(1, -1) as T;\n }\n\n stripped = stripped.trim();\n\n if (stripped.length <= 9) {\n switch (stripped.toLowerCase()) {\n case \"true\": {\n return true as T;\n }\n case \"false\": {\n return false as T;\n }\n case \"undefined\": {\n return undefined as T;\n }\n case \"null\": {\n return null as T;\n }\n case \"nan\": {\n return Number.NaN as T;\n }\n case \"infinity\": {\n return Number.POSITIVE_INFINITY as T;\n }\n case \"-infinity\": {\n return Number.NEGATIVE_INFINITY as T;\n }\n }\n }\n\n if (!JsonSigRx.test(stripped)) {\n if (options.strict) {\n throw new Error(\"Invalid JSON\");\n }\n return stripped as T;\n }\n\n try {\n if (suspectProtoRx.test(stripped) || suspectConstructorRx.test(stripped)) {\n if (options.strict) {\n throw new Error(\"Possible prototype pollution\");\n }\n return JSON.parse(stripped, jsonParseTransform);\n }\n\n return JSON.parse(stripped);\n } catch (error) {\n if (options.strict) {\n throw error;\n }\n return value as T;\n }\n}\n\nexport function safeParse<T = unknown>(value: any, options: Options = {}): T {\n return parse<T>(value, { ...options, strict: true });\n}\n"],"mappings":";;;AAsBA,MAAM,iBACJ;AACF,MAAM,uBACJ;AAEF,MAAM,YAAY;AAElB,SAAS,mBAAmB,KAAa,OAAiB;AACxD,KACE,QAAQ,eACP,QAAQ,iBACP,SACA,OAAO,UAAU,YACjB,eAAe,OACjB;AAEA,UAAQ,KAAK,aAAa,IAAI,uCAAuC;AACrE;;AAEF,QAAO;;AAOT,SAAgB,MAAmB,OAAY,UAAmB,EAAE,EAAK;AACvE,KAAI,OAAO,UAAU,SACnB,QAAO;CAGT,IAAI,WAAW,cAAc,MAAM;AAEnC,KACE,SAAS,OAAO,QAChB,SAAS,SAAS,SAAS,OAAO,QAClC,CAAC,SAAS,SAAS,KAAK,CAExB,QAAO,SAAS,MAAM,GAAG,GAAG;AAG9B,YAAW,SAAS,MAAM;AAE1B,KAAI,SAAS,UAAU,EACrB,SAAQ,SAAS,aAAa,EAA9B;EACE,KAAK,OACH,QAAO;EAET,KAAK,QACH,QAAO;EAET,KAAK,YACH;EAEF,KAAK,OACH,QAAO;EAET,KAAK,MACH,QAAO;EAET,KAAK,WACH,QAAO,OAAO;EAEhB,KAAK,YACH,QAAO,OAAO;;AAKpB,KAAI,CAAC,UAAU,KAAK,SAAS,EAAE;AAC7B,MAAI,QAAQ,OACV,OAAM,IAAI,MAAM,eAAe;AAEjC,SAAO;;AAGT,KAAI;AACF,MAAI,eAAe,KAAK,SAAS,IAAI,qBAAqB,KAAK,SAAS,EAAE;AACxE,OAAI,QAAQ,OACV,OAAM,IAAI,MAAM,+BAA+B;AAEjD,UAAO,KAAK,MAAM,UAAU,mBAAmB;;AAGjD,SAAO,KAAK,MAAM,SAAS;UACpB,OAAO;AACd,MAAI,QAAQ,OACV,OAAM;AAER,SAAO;;;AAIX,SAAgB,UAAuB,OAAY,UAAmB,EAAE,EAAK;AAC3E,QAAO,MAAS,OAAO;EAAE,GAAG;EAAS,QAAQ;EAAM,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ParseError } from "jsonc-parser";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/parse-error.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Nicely formats a JSON error with context
|
|
7
|
+
*
|
|
8
|
+
* @param input - JSON content as string
|
|
9
|
+
* @param parseError - jsonc ParseError
|
|
10
|
+
* @returns Formatted error message with context
|
|
11
|
+
*/
|
|
12
|
+
declare function formatParseError(input: string, parseError: ParseError): string;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { formatParseError as t };
|
|
15
|
+
//# sourceMappingURL=parse-error-7K8s4vWf.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-error-7K8s4vWf.d.cts","names":[],"sources":["../src/utils/parse-error.ts"],"sourcesContent":[],"mappings":";;;;;;AA8BA;;;;;iBAAgB,gBAAA,4BAA4C"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { t as codeFrameColumns } from "./code-frames-DuBfTMu4.mjs";
|
|
2
|
+
import { printParseErrorCode } from "jsonc-parser";
|
|
3
|
+
import { LinesAndColumns } from "lines-and-columns";
|
|
4
|
+
|
|
5
|
+
//#region src/utils/parse-error.ts
|
|
6
|
+
/**
|
|
7
|
+
* Nicely formats a JSON error with context
|
|
8
|
+
*
|
|
9
|
+
* @param input - JSON content as string
|
|
10
|
+
* @param parseError - jsonc ParseError
|
|
11
|
+
* @returns Formatted error message with context
|
|
12
|
+
*/
|
|
13
|
+
function formatParseError(input, parseError) {
|
|
14
|
+
const { error, offset, length } = parseError;
|
|
15
|
+
const result = new LinesAndColumns(input).locationForIndex(offset);
|
|
16
|
+
let line = result?.line ?? 0;
|
|
17
|
+
let column = result?.column ?? 0;
|
|
18
|
+
line++;
|
|
19
|
+
column++;
|
|
20
|
+
return `${printParseErrorCode(error)} in JSON at ${line}:${column}\n${codeFrameColumns(input, {
|
|
21
|
+
start: {
|
|
22
|
+
line,
|
|
23
|
+
column
|
|
24
|
+
},
|
|
25
|
+
end: {
|
|
26
|
+
line,
|
|
27
|
+
column: column + length
|
|
28
|
+
}
|
|
29
|
+
})}\n`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
export { formatParseError as t };
|
|
34
|
+
//# sourceMappingURL=parse-error-Af4zHUQ_.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-error-Af4zHUQ_.mjs","names":[],"sources":["../src/utils/parse-error.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { ParseError } from \"jsonc-parser\";\nimport { printParseErrorCode } from \"jsonc-parser\";\nimport { LinesAndColumns } from \"lines-and-columns\";\nimport { codeFrameColumns } from \"./code-frames\";\n\n/**\n * Nicely formats a JSON error with context\n *\n * @param input - JSON content as string\n * @param parseError - jsonc ParseError\n * @returns Formatted error message with context\n */\nexport function formatParseError(input: string, parseError: ParseError) {\n const { error, offset, length } = parseError;\n const result = new LinesAndColumns(input).locationForIndex(offset);\n let line = result?.line ?? 0;\n let column = result?.column ?? 0;\n\n line++;\n column++;\n\n return `${printParseErrorCode(error)} in JSON at ${line}:${column}\\n${codeFrameColumns(\n input,\n {\n start: {\n line,\n column\n },\n end: {\n line,\n column: column + length\n }\n }\n )}\\n`;\n}\n"],"mappings":";;;;;;;;;;;;AA8BA,SAAgB,iBAAiB,OAAe,YAAwB;CACtE,MAAM,EAAE,OAAO,QAAQ,WAAW;CAClC,MAAM,SAAS,IAAI,gBAAgB,MAAM,CAAC,iBAAiB,OAAO;CAClE,IAAI,OAAO,QAAQ,QAAQ;CAC3B,IAAI,SAAS,QAAQ,UAAU;AAE/B;AACA;AAEA,QAAO,GAAG,oBAAoB,MAAM,CAAC,cAAc,KAAK,GAAG,OAAO,IAAI,iBACpE,OACA;EACE,OAAO;GACL;GACA;GACD;EACD,KAAK;GACH;GACA,QAAQ,SAAS;GAClB;EACF,CACF,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ParseError } from "jsonc-parser";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/parse-error.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Nicely formats a JSON error with context
|
|
7
|
+
*
|
|
8
|
+
* @param input - JSON content as string
|
|
9
|
+
* @param parseError - jsonc ParseError
|
|
10
|
+
* @returns Formatted error message with context
|
|
11
|
+
*/
|
|
12
|
+
declare function formatParseError(input: string, parseError: ParseError): string;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { formatParseError as t };
|
|
15
|
+
//# sourceMappingURL=parse-error-DpEv3vo_.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-error-DpEv3vo_.d.mts","names":[],"sources":["../src/utils/parse-error.ts"],"sourcesContent":[],"mappings":";;;;;;AA8BA;;;;;iBAAgB,gBAAA,4BAA4C"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const require_storm_json = require('./storm-json-BD6WFbrI.cjs');
|
|
2
|
+
const require_code_frames = require('./code-frames-BmUvlJ0w.cjs');
|
|
3
|
+
let jsonc_parser = require("jsonc-parser");
|
|
4
|
+
let lines_and_columns = require("lines-and-columns");
|
|
5
|
+
|
|
6
|
+
//#region src/utils/parse-error.ts
|
|
7
|
+
/**
|
|
8
|
+
* Nicely formats a JSON error with context
|
|
9
|
+
*
|
|
10
|
+
* @param input - JSON content as string
|
|
11
|
+
* @param parseError - jsonc ParseError
|
|
12
|
+
* @returns Formatted error message with context
|
|
13
|
+
*/
|
|
14
|
+
function formatParseError(input, parseError) {
|
|
15
|
+
const { error, offset, length } = parseError;
|
|
16
|
+
const result = new lines_and_columns.LinesAndColumns(input).locationForIndex(offset);
|
|
17
|
+
let line = result?.line ?? 0;
|
|
18
|
+
let column = result?.column ?? 0;
|
|
19
|
+
line++;
|
|
20
|
+
column++;
|
|
21
|
+
return `${(0, jsonc_parser.printParseErrorCode)(error)} in JSON at ${line}:${column}\n${require_code_frames.codeFrameColumns(input, {
|
|
22
|
+
start: {
|
|
23
|
+
line,
|
|
24
|
+
column
|
|
25
|
+
},
|
|
26
|
+
end: {
|
|
27
|
+
line,
|
|
28
|
+
column: column + length
|
|
29
|
+
}
|
|
30
|
+
})}\n`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
Object.defineProperty(exports, 'formatParseError', {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
get: function () {
|
|
37
|
+
return formatParseError;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/utils/parse.d.ts
|
|
2
|
+
interface Options {
|
|
3
|
+
strict?: boolean;
|
|
4
|
+
}
|
|
5
|
+
declare function parse<T = unknown>(value: any, options?: Options): T;
|
|
6
|
+
declare function safeParse<T = unknown>(value: any, options?: Options): T;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { parse as n, safeParse as r, Options as t };
|
|
9
|
+
//# sourceMappingURL=parse-fXy5pbmE.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-fXy5pbmE.d.mts","names":[],"sources":["../src/utils/parse.ts"],"sourcesContent":[],"mappings":";UA4CiB,OAAA;EAAA,MAAA,CAAA,EAAA,OAAO;AAIxB;AAmEgB,iBAnEA,KAmE4C,CAAA,IAAA,OAAgB,CAAA,CAAA,KAAA,EAAA,GAAA,EAAA,OAAA,CAAA,EAnEpB,OAmEoB,CAAA,EAnEL,CAmEK;iBAA5D,6CAA4C,UAAe"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { t as isNumber } from "./is-number-BIwzZzyi.mjs";
|
|
2
|
+
import { t as isString } from "./is-string-CLiBUSKV.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/pointer/parse.ts
|
|
5
|
+
const TILDE_ONE = /~1/g;
|
|
6
|
+
const TILDE_ZERO = /~0/g;
|
|
7
|
+
const TILDE = /~/g;
|
|
8
|
+
const FORWARD_SLASH = /\//g;
|
|
9
|
+
/**
|
|
10
|
+
* Escapes a JSON pointer path segment.
|
|
11
|
+
*
|
|
12
|
+
* @param segment - JSON pointer path segment.
|
|
13
|
+
* @returns Escaped JSON pointer path segment.
|
|
14
|
+
*/
|
|
15
|
+
function escapePointerSegment(segment) {
|
|
16
|
+
if (!segment.includes("/") && !segment.includes("~")) return segment;
|
|
17
|
+
return segment.replace(TILDE, "~0").replace(FORWARD_SLASH, "~1");
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Unescapes a JSON pointer path segment.
|
|
21
|
+
*
|
|
22
|
+
* @param segment - JSON pointer path segment.
|
|
23
|
+
* @returns Unescaped JSON pointer path segment.
|
|
24
|
+
*/
|
|
25
|
+
function unescapePointerSegment(segment) {
|
|
26
|
+
if (!segment.includes("~")) return segment;
|
|
27
|
+
return segment.replace(TILDE_ONE, "/").replace(TILDE_ZERO, "~");
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Convert JSON pointer like "/foo/bar" to array like ["", "foo", "bar"], while
|
|
31
|
+
* also un-escaping reserved characters.
|
|
32
|
+
*/
|
|
33
|
+
function parseJsonPointer(pointer) {
|
|
34
|
+
if (!pointer) return [];
|
|
35
|
+
return pointer.slice(1).split("/").map((segment) => unescapePointerSegment(segment));
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Escape and format a path array like ["", "foo", "bar"] to JSON pointer
|
|
39
|
+
* like "/foo/bar".
|
|
40
|
+
*/
|
|
41
|
+
function formatJsonPointer(path) {
|
|
42
|
+
if (isRoot(path)) return "";
|
|
43
|
+
return `/${path.map((segment) => escapePointerSegment(String(segment))).join("/")}`;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Returns true if JSON Pointer points to root value, false otherwise.
|
|
47
|
+
*/
|
|
48
|
+
const isRoot = (path) => isString(path) ? path === "" : isNumber(path) ? path === 0 : Array.isArray(path) && path.length === 0;
|
|
49
|
+
/**
|
|
50
|
+
* Returns parent path, e.g. for ['foo', 'bar', 'baz'] returns ['foo', 'bar'].
|
|
51
|
+
*/
|
|
52
|
+
function parent(path) {
|
|
53
|
+
if (path.length === 0) throw new Error("NO_PARENT");
|
|
54
|
+
return path.slice(0, -1);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Check if path component can be a valid array index.
|
|
58
|
+
*/
|
|
59
|
+
function isValidIndex(index) {
|
|
60
|
+
if (isNumber(index)) return true;
|
|
61
|
+
const n = Number.parseInt(index, 10);
|
|
62
|
+
return String(n) === index && n >= 0;
|
|
63
|
+
}
|
|
64
|
+
const isInteger = (str) => {
|
|
65
|
+
const len = str.length;
|
|
66
|
+
let i = 0;
|
|
67
|
+
let charCode;
|
|
68
|
+
while (i < len) {
|
|
69
|
+
charCode = str.codePointAt(i);
|
|
70
|
+
if (charCode >= 48 && charCode <= 57) {
|
|
71
|
+
i++;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
export { isValidIndex as a, unescapePointerSegment as c, isRoot as i, formatJsonPointer as n, parent as o, isInteger as r, parseJsonPointer as s, escapePointerSegment as t };
|
|
81
|
+
//# sourceMappingURL=parse-vw_qRD3F.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-vw_qRD3F.mjs","names":["charCode: any"],"sources":["../src/pointer/parse.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { isNumber } from \"@stryke/type-checks/is-number\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport type { JsonPointerPath } from \"@stryke/types/json\";\n\nconst TILDE_ONE = /~1/g;\nconst TILDE_ZERO = /~0/g;\nconst TILDE = /~/g;\nconst FORWARD_SLASH = /\\//g;\n\n/**\n * Escapes a JSON pointer path segment.\n *\n * @param segment - JSON pointer path segment.\n * @returns Escaped JSON pointer path segment.\n */\nexport function escapePointerSegment(segment: string): string {\n if (!segment.includes(\"/\") && !segment.includes(\"~\")) {\n return segment;\n }\n\n return segment.replace(TILDE, \"~0\").replace(FORWARD_SLASH, \"~1\");\n}\n\n/**\n * Unescapes a JSON pointer path segment.\n *\n * @param segment - JSON pointer path segment.\n * @returns Unescaped JSON pointer path segment.\n */\nexport function unescapePointerSegment(segment: string): string {\n if (!segment.includes(\"~\")) {\n return segment;\n }\n\n return segment.replace(TILDE_ONE, \"/\").replace(TILDE_ZERO, \"~\");\n}\n\n/**\n * Convert JSON pointer like \"/foo/bar\" to array like [\"\", \"foo\", \"bar\"], while\n * also un-escaping reserved characters.\n */\nexport function parseJsonPointer(pointer: string): JsonPointerPath {\n if (!pointer) return [];\n // TODO: Performance of this line can be improved: (1) don't use .split(); (2) don't use .map().\n return pointer\n .slice(1)\n .split(\"/\")\n .map(segment => unescapePointerSegment(segment));\n}\n\n/**\n * Escape and format a path array like [\"\", \"foo\", \"bar\"] to JSON pointer\n * like \"/foo/bar\".\n */\nexport function formatJsonPointer(path: JsonPointerPath): string {\n // eslint-disable-next-line ts/no-use-before-define\n if (isRoot(path)) {\n return \"\";\n }\n\n return `/${path.map(segment => escapePointerSegment(String(segment))).join(\"/\")}`;\n}\n\n/**\n * Returns true if JSON Pointer points to root value, false otherwise.\n */\nexport const isRoot = (path: string | number | JsonPointerPath): boolean =>\n isString(path)\n ? path === \"\"\n : isNumber(path)\n ? path === 0\n : Array.isArray(path) && path.length === 0;\n\n/**\n * Returns parent path, e.g. for ['foo', 'bar', 'baz'] returns ['foo', 'bar'].\n */\nexport function parent(path: JsonPointerPath): JsonPointerPath {\n if (path.length === 0) {\n throw new Error(\"NO_PARENT\");\n }\n\n return path.slice(0, -1);\n}\n\n/**\n * Check if path component can be a valid array index.\n */\nexport function isValidIndex(index: string | number): boolean {\n if (isNumber(index)) {\n return true;\n }\n\n const n = Number.parseInt(index, 10);\n\n return String(n) === index && n >= 0;\n}\n\nexport const isInteger = (str: string): boolean => {\n const len = str.length;\n let i = 0;\n let charCode: any;\n while (i < len) {\n charCode = str.codePointAt(i);\n if (charCode >= 48 && charCode <= 57) {\n i++;\n continue;\n }\n return false;\n }\n return true;\n};\n"],"mappings":";;;;AAsBA,MAAM,YAAY;AAClB,MAAM,aAAa;AACnB,MAAM,QAAQ;AACd,MAAM,gBAAgB;;;;;;;AAQtB,SAAgB,qBAAqB,SAAyB;AAC5D,KAAI,CAAC,QAAQ,SAAS,IAAI,IAAI,CAAC,QAAQ,SAAS,IAAI,CAClD,QAAO;AAGT,QAAO,QAAQ,QAAQ,OAAO,KAAK,CAAC,QAAQ,eAAe,KAAK;;;;;;;;AASlE,SAAgB,uBAAuB,SAAyB;AAC9D,KAAI,CAAC,QAAQ,SAAS,IAAI,CACxB,QAAO;AAGT,QAAO,QAAQ,QAAQ,WAAW,IAAI,CAAC,QAAQ,YAAY,IAAI;;;;;;AAOjE,SAAgB,iBAAiB,SAAkC;AACjE,KAAI,CAAC,QAAS,QAAO,EAAE;AAEvB,QAAO,QACJ,MAAM,EAAE,CACR,MAAM,IAAI,CACV,KAAI,YAAW,uBAAuB,QAAQ,CAAC;;;;;;AAOpD,SAAgB,kBAAkB,MAA+B;AAE/D,KAAI,OAAO,KAAK,CACd,QAAO;AAGT,QAAO,IAAI,KAAK,KAAI,YAAW,qBAAqB,OAAO,QAAQ,CAAC,CAAC,CAAC,KAAK,IAAI;;;;;AAMjF,MAAa,UAAU,SACrB,SAAS,KAAK,GACV,SAAS,KACT,SAAS,KAAK,GACZ,SAAS,IACT,MAAM,QAAQ,KAAK,IAAI,KAAK,WAAW;;;;AAK/C,SAAgB,OAAO,MAAwC;AAC7D,KAAI,KAAK,WAAW,EAClB,OAAM,IAAI,MAAM,YAAY;AAG9B,QAAO,KAAK,MAAM,GAAG,GAAG;;;;;AAM1B,SAAgB,aAAa,OAAiC;AAC5D,KAAI,SAAS,MAAM,CACjB,QAAO;CAGT,MAAM,IAAI,OAAO,SAAS,OAAO,GAAG;AAEpC,QAAO,OAAO,EAAE,KAAK,SAAS,KAAK;;AAGrC,MAAa,aAAa,QAAyB;CACjD,MAAM,MAAM,IAAI;CAChB,IAAI,IAAI;CACR,IAAIA;AACJ,QAAO,IAAI,KAAK;AACd,aAAW,IAAI,YAAY,EAAE;AAC7B,MAAI,YAAY,MAAM,YAAY,IAAI;AACpC;AACA;;AAEF,SAAO;;AAET,QAAO"}
|
|
@@ -1,66 +1,6 @@
|
|
|
1
|
-
const
|
|
2
|
-
const require_is_set_object = require('../type-checks/src/is-set-object.cjs');
|
|
1
|
+
const require_find_reference = require('../find-reference-De5vBQV2.cjs');
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* object containing the target and key used to reference that object.
|
|
9
|
-
*
|
|
10
|
-
* Throws Error('NOT_FOUND') if pointer does not result into a value in the middle
|
|
11
|
-
* of the path. If the last element of the path does not result into a value, the
|
|
12
|
-
* lookup succeeds with `val` set to `undefined`. It can be used to discriminate
|
|
13
|
-
* missing values, because `undefined` is not a valid JSON value.
|
|
14
|
-
*
|
|
15
|
-
* If last element in array is targeted using "-", e.g. "/arr/-", use
|
|
16
|
-
* `isArrayEnd` to verify that:
|
|
17
|
-
*
|
|
18
|
-
* ```js
|
|
19
|
-
* const ref = find({arr: [1, 2, 3], ['arr', '-']});
|
|
20
|
-
* if (isArrayReference(ref)) {
|
|
21
|
-
* if (isArrayEnd(ref)) {
|
|
22
|
-
* // ...
|
|
23
|
-
* }
|
|
24
|
-
* }
|
|
25
|
-
* ```
|
|
26
|
-
*
|
|
27
|
-
* @param val - Document to search in.
|
|
28
|
-
* @param path - JSON Pointer path.
|
|
29
|
-
* @returns Reference to the target.
|
|
30
|
-
*/
|
|
31
|
-
const find = (val, path) => {
|
|
32
|
-
const pathLength = path.length;
|
|
33
|
-
if (!pathLength) return { val };
|
|
34
|
-
let obj;
|
|
35
|
-
let key;
|
|
36
|
-
for (let i = 0; i < pathLength; i++) {
|
|
37
|
-
obj = val;
|
|
38
|
-
key = path[i];
|
|
39
|
-
if (isArray(obj)) {
|
|
40
|
-
const length = obj.length;
|
|
41
|
-
if (key === "-") key = length;
|
|
42
|
-
else if (require_is_string.isString(key)) {
|
|
43
|
-
const key2 = Math.trunc(Number.parseInt(key));
|
|
44
|
-
if (String(key2) !== key) throw new Error("INVALID_INDEX");
|
|
45
|
-
key = key2;
|
|
46
|
-
if (key < 0) throw new Error("INVALID_INDEX");
|
|
47
|
-
}
|
|
48
|
-
if (key) val = obj[key];
|
|
49
|
-
} else if (require_is_set_object.isSetObject(obj)) val = key && key in obj ? obj[key] : void 0;
|
|
50
|
-
else throw new Error("NOT_FOUND");
|
|
51
|
-
}
|
|
52
|
-
return {
|
|
53
|
-
val,
|
|
54
|
-
obj,
|
|
55
|
-
key
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
const isArrayReference = (ref) => isArray(ref.obj) && typeof ref.key === "number";
|
|
59
|
-
const isArrayEnd = (ref) => ref.obj.length === ref.key;
|
|
60
|
-
const isObjectReference = (ref) => typeof ref.obj === "object" && typeof ref.key === "string";
|
|
61
|
-
|
|
62
|
-
//#endregion
|
|
63
|
-
exports.find = find;
|
|
64
|
-
exports.isArrayEnd = isArrayEnd;
|
|
65
|
-
exports.isArrayReference = isArrayReference;
|
|
66
|
-
exports.isObjectReference = isObjectReference;
|
|
3
|
+
exports.find = require_find_reference.find;
|
|
4
|
+
exports.isArrayEnd = require_find_reference.isArrayEnd;
|
|
5
|
+
exports.isArrayReference = require_find_reference.isArrayReference;
|
|
6
|
+
exports.isObjectReference = require_find_reference.isObjectReference;
|