@stryke/json 0.9.44 → 0.10.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 +7 -0
- package/dist/code-frames-BMkA9i6j.d.mts +17 -0
- package/dist/code-frames-BMkA9i6j.d.mts.map +1 -0
- package/dist/code-frames-BUtrssZ5.d.cts +17 -0
- package/dist/code-frames-BUtrssZ5.d.cts.map +1 -0
- package/dist/code-frames-Cv8r5tSN.cjs +82 -0
- package/dist/code-frames-DISWdYL6.mjs +77 -0
- package/dist/code-frames-DISWdYL6.mjs.map +1 -0
- package/dist/find-reference-BCg3dQx1.cjs +157 -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-b7rRdLFx.d.mts +52 -0
- package/dist/find-reference-b7rRdLFx.d.mts.map +1 -0
- package/dist/find-reference-woYMiWzN.mjs +135 -0
- package/dist/find-reference-woYMiWzN.mjs.map +1 -0
- package/dist/index-B_e8BwCm.d.cts +1 -0
- package/dist/index-CDAfh8Ew.d.cts +1 -0
- package/dist/index-DwO9IdNa.d.mts +1 -0
- package/dist/index-VWno75SQ.d.mts +1 -0
- package/dist/index.cjs +32 -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/{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-Crgv3Nl1.mjs +81 -0
- package/dist/parse-Crgv3Nl1.mjs.map +1 -0
- package/dist/parse-DZfi3d96.d.cts +51 -0
- package/dist/parse-DZfi3d96.d.cts.map +1 -0
- package/dist/parse-DgYW5BBj.d.mts +9 -0
- package/dist/parse-DgYW5BBj.d.mts.map +1 -0
- package/dist/parse-KiRakdIR.cjs +127 -0
- package/dist/parse-ZRTh45ZI.d.mts +51 -0
- package/dist/parse-ZRTh45ZI.d.mts.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-C3Qmubee.mjs +34 -0
- package/dist/parse-error-C3Qmubee.mjs.map +1 -0
- package/dist/parse-error-DY_MelEh.d.mts +15 -0
- package/dist/parse-error-DY_MelEh.d.mts.map +1 -0
- package/dist/parse-error-Dzwg4sdE.cjs +39 -0
- package/dist/parse-obdkJfj5.mjs +52 -0
- package/dist/parse-obdkJfj5.mjs.map +1 -0
- package/dist/parse-wxSDzBPf.cjs +62 -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-Cc7IR0Bj.cjs +0 -0
- package/dist/pointer-CiTXvh1G.mjs +0 -0
- package/dist/schema-B1RVJHzJ.d.cts +7 -0
- package/dist/schema-B1RVJHzJ.d.cts.map +1 -0
- package/dist/schema-CfhPLy30.mjs +9 -0
- package/dist/schema-CfhPLy30.mjs.map +1 -0
- package/dist/schema-D5Aqvh2i.cjs +14 -0
- package/dist/schema-ai_NU-JC.d.mts +7 -0
- package/dist/schema-ai_NU-JC.d.mts.map +1 -0
- package/dist/schema.cjs +3 -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-6WpS7qnH.cjs +154 -0
- package/dist/storm-json-AaFeOao2.d.cts +70 -0
- package/dist/storm-json-AaFeOao2.d.cts.map +1 -0
- package/dist/storm-json-BvRkzAlR.d.mts +70 -0
- package/dist/storm-json-BvRkzAlR.d.mts.map +1 -0
- package/dist/storm-json-Cy3PuAhj.mjs +116 -0
- package/dist/storm-json-Cy3PuAhj.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-B6iAeg0u.d.mts +13 -0
- package/dist/stringify-B6iAeg0u.d.mts.map +1 -0
- package/dist/stringify-Bc8OkhIr.d.cts +13 -0
- package/dist/stringify-Bc8OkhIr.d.cts.map +1 -0
- package/dist/stringify-D5baUfEe.mjs +68 -0
- package/dist/stringify-D5baUfEe.mjs.map +1 -0
- package/dist/stringify-DEw3S4_Z.cjs +78 -0
- package/dist/strip-comments-Bg3R_Y4S.d.mts +11 -0
- package/dist/strip-comments-Bg3R_Y4S.d.mts.map +1 -0
- package/dist/strip-comments-CMaAgTqz.mjs +89 -0
- package/dist/strip-comments-CMaAgTqz.mjs.map +1 -0
- package/dist/strip-comments-CtFoX0xG.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/types-BUeTTE_U.d.cts +222 -0
- package/dist/types-BUeTTE_U.d.cts.map +1 -0
- package/dist/types-C_KlcCNw.d.mts +222 -0
- package/dist/types-C_KlcCNw.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-CVcIdLuL.mjs +0 -0
- package/dist/utils-Cz3OCwUK.cjs +0 -0
- package/package.json +7 -2
- 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
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog for Stryke - JSON
|
|
4
4
|
|
|
5
|
+
## [0.9.44](https://github.com/storm-software/stryke/releases/tag/json%400.9.44) (03/02/2026)
|
|
6
|
+
|
|
7
|
+
### Updated Dependencies
|
|
8
|
+
|
|
9
|
+
- Updated **type-checks** to **v0.5.26**
|
|
10
|
+
- Updated **types** to **v0.10.40**
|
|
11
|
+
|
|
5
12
|
## [0.9.43](https://github.com/storm-software/stryke/releases/tag/json%400.9.43) (02/09/2026)
|
|
6
13
|
|
|
7
14
|
### Updated Dependencies
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/utils/code-frames.d.ts
|
|
2
|
+
interface Location {
|
|
3
|
+
column: number;
|
|
4
|
+
line: number;
|
|
5
|
+
}
|
|
6
|
+
interface NodeLocation {
|
|
7
|
+
end?: Location;
|
|
8
|
+
start?: Location;
|
|
9
|
+
}
|
|
10
|
+
declare function codeFrameColumns(rawLines: string, loc: NodeLocation, opts?: {
|
|
11
|
+
linesAbove?: number;
|
|
12
|
+
linesBelow?: number;
|
|
13
|
+
highlight?: (rawLines: string) => string;
|
|
14
|
+
}): string;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { codeFrameColumns as t };
|
|
17
|
+
//# sourceMappingURL=code-frames-BMkA9i6j.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-frames-BMkA9i6j.d.mts","names":[],"sources":["../src/utils/code-frames.ts"],"sourcesContent":[],"mappings":";UAkBU,QAAA;EAAA,MAAA,EAAA,MAAQ;EAKR,IAAA,EAAA,MAAA;AAoFV;UApFU,YAAA;QACF;UACE;;iBAkFM,gBAAA,wBAET"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/utils/code-frames.d.ts
|
|
2
|
+
interface Location {
|
|
3
|
+
column: number;
|
|
4
|
+
line: number;
|
|
5
|
+
}
|
|
6
|
+
interface NodeLocation {
|
|
7
|
+
end?: Location;
|
|
8
|
+
start?: Location;
|
|
9
|
+
}
|
|
10
|
+
declare function codeFrameColumns(rawLines: string, loc: NodeLocation, opts?: {
|
|
11
|
+
linesAbove?: number;
|
|
12
|
+
linesBelow?: number;
|
|
13
|
+
highlight?: (rawLines: string) => string;
|
|
14
|
+
}): string;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { codeFrameColumns as t };
|
|
17
|
+
//# sourceMappingURL=code-frames-BUtrssZ5.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-frames-BUtrssZ5.d.cts","names":[],"sources":["../src/utils/code-frames.ts"],"sourcesContent":[],"mappings":";UAkBU,QAAA;EAAA,MAAA,EAAA,MAAQ;EAKR,IAAA,EAAA,MAAA;AAoFV;UApFU,YAAA;QACF;UACE;;iBAkFM,gBAAA,wBAET"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/utils/code-frames.ts
|
|
3
|
+
/**
|
|
4
|
+
* RegExp to test for newlines in terminal.
|
|
5
|
+
*/
|
|
6
|
+
const NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
|
|
7
|
+
/**
|
|
8
|
+
* Extract what lines should be marked and highlighted.
|
|
9
|
+
*/
|
|
10
|
+
function getMarkerLines(loc, source, opts = {}) {
|
|
11
|
+
const startLoc = {
|
|
12
|
+
column: 0,
|
|
13
|
+
line: -1,
|
|
14
|
+
...loc.start
|
|
15
|
+
};
|
|
16
|
+
const endLoc = {
|
|
17
|
+
...startLoc,
|
|
18
|
+
...loc.end
|
|
19
|
+
};
|
|
20
|
+
const { linesAbove = 2, linesBelow = 3 } = opts || {};
|
|
21
|
+
const startLine = startLoc.line;
|
|
22
|
+
const startColumn = startLoc.column;
|
|
23
|
+
const endLine = endLoc.line;
|
|
24
|
+
const endColumn = endLoc.column;
|
|
25
|
+
let start = Math.max(startLine - (linesAbove + 1), 0);
|
|
26
|
+
let end = Math.min(source.length, endLine + linesBelow);
|
|
27
|
+
if (startLine === -1) start = 0;
|
|
28
|
+
if (endLine === -1) end = source.length;
|
|
29
|
+
const lineDiff = endLine - startLine;
|
|
30
|
+
const markerLines = {};
|
|
31
|
+
if (lineDiff) for (let i = 0; i <= lineDiff; i++) {
|
|
32
|
+
const lineNumber = i + startLine;
|
|
33
|
+
if (!startColumn) markerLines[lineNumber] = true;
|
|
34
|
+
else if (i === 0) markerLines[lineNumber] = [startColumn, (source[lineNumber - 1]?.length ?? 0) - startColumn + 1];
|
|
35
|
+
else if (i === lineDiff) markerLines[lineNumber] = [0, endColumn];
|
|
36
|
+
else markerLines[lineNumber] = [0, source[lineNumber - i]?.length ?? 0];
|
|
37
|
+
}
|
|
38
|
+
else if (startColumn === endColumn) markerLines[startLine] = startColumn ? [startColumn, 0] : true;
|
|
39
|
+
else markerLines[startLine] = [startColumn, endColumn - startColumn];
|
|
40
|
+
return {
|
|
41
|
+
start,
|
|
42
|
+
end,
|
|
43
|
+
markerLines
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function codeFrameColumns(rawLines, loc, opts = {}) {
|
|
47
|
+
const { start, end, markerLines } = getMarkerLines(loc, rawLines.split(NEWLINE), opts);
|
|
48
|
+
const numberMaxWidth = String(end).length;
|
|
49
|
+
return (opts.highlight ? opts.highlight(rawLines) : rawLines).split(NEWLINE).slice(start, end).map((line, index) => {
|
|
50
|
+
const number = start + 1 + index;
|
|
51
|
+
const gutter = ` ${` ${number}`.slice(-numberMaxWidth)} | `;
|
|
52
|
+
const hasMarker = Boolean(markerLines[number] ?? false);
|
|
53
|
+
if (hasMarker) {
|
|
54
|
+
let markerLine = "";
|
|
55
|
+
if (Array.isArray(hasMarker)) {
|
|
56
|
+
const markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " ");
|
|
57
|
+
const numberOfMarkers = hasMarker[1] || 1;
|
|
58
|
+
markerLine = [
|
|
59
|
+
"\n ",
|
|
60
|
+
gutter.replace(/\d/g, " "),
|
|
61
|
+
markerSpacing,
|
|
62
|
+
"^".repeat(numberOfMarkers)
|
|
63
|
+
].join("");
|
|
64
|
+
}
|
|
65
|
+
return [
|
|
66
|
+
">",
|
|
67
|
+
gutter,
|
|
68
|
+
line,
|
|
69
|
+
markerLine
|
|
70
|
+
].join("");
|
|
71
|
+
}
|
|
72
|
+
return ` ${gutter}${line}`;
|
|
73
|
+
}).join("\n");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
//#endregion
|
|
77
|
+
Object.defineProperty(exports, 'codeFrameColumns', {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
get: function () {
|
|
80
|
+
return codeFrameColumns;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
//#region src/utils/code-frames.ts
|
|
2
|
+
/**
|
|
3
|
+
* RegExp to test for newlines in terminal.
|
|
4
|
+
*/
|
|
5
|
+
const NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
|
|
6
|
+
/**
|
|
7
|
+
* Extract what lines should be marked and highlighted.
|
|
8
|
+
*/
|
|
9
|
+
function getMarkerLines(loc, source, opts = {}) {
|
|
10
|
+
const startLoc = {
|
|
11
|
+
column: 0,
|
|
12
|
+
line: -1,
|
|
13
|
+
...loc.start
|
|
14
|
+
};
|
|
15
|
+
const endLoc = {
|
|
16
|
+
...startLoc,
|
|
17
|
+
...loc.end
|
|
18
|
+
};
|
|
19
|
+
const { linesAbove = 2, linesBelow = 3 } = opts || {};
|
|
20
|
+
const startLine = startLoc.line;
|
|
21
|
+
const startColumn = startLoc.column;
|
|
22
|
+
const endLine = endLoc.line;
|
|
23
|
+
const endColumn = endLoc.column;
|
|
24
|
+
let start = Math.max(startLine - (linesAbove + 1), 0);
|
|
25
|
+
let end = Math.min(source.length, endLine + linesBelow);
|
|
26
|
+
if (startLine === -1) start = 0;
|
|
27
|
+
if (endLine === -1) end = source.length;
|
|
28
|
+
const lineDiff = endLine - startLine;
|
|
29
|
+
const markerLines = {};
|
|
30
|
+
if (lineDiff) for (let i = 0; i <= lineDiff; i++) {
|
|
31
|
+
const lineNumber = i + startLine;
|
|
32
|
+
if (!startColumn) markerLines[lineNumber] = true;
|
|
33
|
+
else if (i === 0) markerLines[lineNumber] = [startColumn, (source[lineNumber - 1]?.length ?? 0) - startColumn + 1];
|
|
34
|
+
else if (i === lineDiff) markerLines[lineNumber] = [0, endColumn];
|
|
35
|
+
else markerLines[lineNumber] = [0, source[lineNumber - i]?.length ?? 0];
|
|
36
|
+
}
|
|
37
|
+
else if (startColumn === endColumn) markerLines[startLine] = startColumn ? [startColumn, 0] : true;
|
|
38
|
+
else markerLines[startLine] = [startColumn, endColumn - startColumn];
|
|
39
|
+
return {
|
|
40
|
+
start,
|
|
41
|
+
end,
|
|
42
|
+
markerLines
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function codeFrameColumns(rawLines, loc, opts = {}) {
|
|
46
|
+
const { start, end, markerLines } = getMarkerLines(loc, rawLines.split(NEWLINE), opts);
|
|
47
|
+
const numberMaxWidth = String(end).length;
|
|
48
|
+
return (opts.highlight ? opts.highlight(rawLines) : rawLines).split(NEWLINE).slice(start, end).map((line, index) => {
|
|
49
|
+
const number = start + 1 + index;
|
|
50
|
+
const gutter = ` ${` ${number}`.slice(-numberMaxWidth)} | `;
|
|
51
|
+
const hasMarker = Boolean(markerLines[number] ?? false);
|
|
52
|
+
if (hasMarker) {
|
|
53
|
+
let markerLine = "";
|
|
54
|
+
if (Array.isArray(hasMarker)) {
|
|
55
|
+
const markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " ");
|
|
56
|
+
const numberOfMarkers = hasMarker[1] || 1;
|
|
57
|
+
markerLine = [
|
|
58
|
+
"\n ",
|
|
59
|
+
gutter.replace(/\d/g, " "),
|
|
60
|
+
markerSpacing,
|
|
61
|
+
"^".repeat(numberOfMarkers)
|
|
62
|
+
].join("");
|
|
63
|
+
}
|
|
64
|
+
return [
|
|
65
|
+
">",
|
|
66
|
+
gutter,
|
|
67
|
+
line,
|
|
68
|
+
markerLine
|
|
69
|
+
].join("");
|
|
70
|
+
}
|
|
71
|
+
return ` ${gutter}${line}`;
|
|
72
|
+
}).join("\n");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
export { codeFrameColumns as t };
|
|
77
|
+
//# sourceMappingURL=code-frames-DISWdYL6.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-frames-DISWdYL6.mjs","names":["startLoc: Location","endLoc: Location"],"sources":["../src/utils/code-frames.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\ninterface Location {\n column: number;\n line: number;\n}\n\ninterface NodeLocation {\n end?: Location;\n start?: Location;\n}\n\n// Adapted from https://raw.githubusercontent.com/babel/babel/4108524/packages/babel-code-frame/src/index.js\n\n/**\n * RegExp to test for newlines in terminal.\n */\nconst NEWLINE = /\\r\\n|[\\n\\r\\u2028\\u2029]/;\n\n/**\n * Extract what lines should be marked and highlighted.\n */\nfunction getMarkerLines(\n loc: NodeLocation,\n source: string[],\n opts: { linesAbove?: number; linesBelow?: number } = {}\n): {\n start: number;\n end: number;\n markerLines: Record<number, boolean | [number, number]>;\n} {\n const startLoc: Location = {\n column: 0,\n line: -1,\n ...loc.start\n };\n const endLoc: Location = {\n ...startLoc,\n ...loc.end\n };\n const { linesAbove = 2, linesBelow = 3 } = opts || {};\n const startLine = startLoc.line;\n const startColumn = startLoc.column;\n const endLine = endLoc.line;\n const endColumn = endLoc.column;\n\n let start = Math.max(startLine - (linesAbove + 1), 0);\n let end = Math.min(source.length, endLine + linesBelow);\n\n if (startLine === -1) {\n start = 0;\n }\n\n if (endLine === -1) {\n end = source.length;\n }\n\n const lineDiff = endLine - startLine;\n const markerLines = {} as Record<number, boolean | [number, number]>;\n\n if (lineDiff) {\n for (let i = 0; i <= lineDiff; i++) {\n const lineNumber = i + startLine;\n\n if (!startColumn) {\n markerLines[lineNumber] = true;\n } else if (i === 0) {\n const sourceLength = source[lineNumber - 1]?.length ?? 0;\n\n markerLines[lineNumber] = [startColumn, sourceLength - startColumn + 1];\n } else if (i === lineDiff) {\n markerLines[lineNumber] = [0, endColumn];\n } else {\n const sourceLength = source[lineNumber - i]?.length ?? 0;\n\n markerLines[lineNumber] = [0, sourceLength];\n }\n }\n } else if (startColumn === endColumn) {\n markerLines[startLine] = startColumn ? [startColumn, 0] : true;\n } else {\n markerLines[startLine] = [startColumn, endColumn - startColumn];\n }\n\n return {\n start,\n end,\n markerLines\n };\n}\n\nexport function codeFrameColumns(\n rawLines: string,\n loc: NodeLocation,\n opts: {\n linesAbove?: number;\n linesBelow?: number;\n highlight?: (rawLines: string) => string;\n } = {}\n): string {\n const lines = rawLines.split(NEWLINE);\n const { start, end, markerLines } = getMarkerLines(loc, lines, opts);\n\n const numberMaxWidth = String(end).length;\n const highlightedLines = opts.highlight ? opts.highlight(rawLines) : rawLines;\n\n const frame = highlightedLines\n .split(NEWLINE)\n .slice(start, end)\n .map((line, index) => {\n const number = start + 1 + index;\n const paddedNumber = ` ${number}`.slice(-numberMaxWidth);\n const gutter = ` ${paddedNumber} | `;\n const hasMarker = Boolean(markerLines[number] ?? false);\n if (hasMarker) {\n let markerLine = \"\";\n if (Array.isArray(hasMarker)) {\n const markerSpacing = line\n .slice(0, Math.max(hasMarker[0] - 1, 0))\n .replace(/[^\\t]/g, \" \");\n const numberOfMarkers = hasMarker[1] || 1;\n\n markerLine = [\n \"\\n \",\n gutter.replace(/\\d/g, \" \"),\n markerSpacing,\n \"^\".repeat(numberOfMarkers)\n ].join(\"\");\n }\n return [\">\", gutter, line, markerLine].join(\"\");\n }\n return ` ${gutter}${line}`;\n })\n .join(\"\\n\");\n\n return frame;\n}\n"],"mappings":";;;;AAiCA,MAAM,UAAU;;;;AAKhB,SAAS,eACP,KACA,QACA,OAAqD,EAAE,EAKvD;CACA,MAAMA,WAAqB;EACzB,QAAQ;EACR,MAAM;EACN,GAAG,IAAI;EACR;CACD,MAAMC,SAAmB;EACvB,GAAG;EACH,GAAG,IAAI;EACR;CACD,MAAM,EAAE,aAAa,GAAG,aAAa,MAAM,QAAQ,EAAE;CACrD,MAAM,YAAY,SAAS;CAC3B,MAAM,cAAc,SAAS;CAC7B,MAAM,UAAU,OAAO;CACvB,MAAM,YAAY,OAAO;CAEzB,IAAI,QAAQ,KAAK,IAAI,aAAa,aAAa,IAAI,EAAE;CACrD,IAAI,MAAM,KAAK,IAAI,OAAO,QAAQ,UAAU,WAAW;AAEvD,KAAI,cAAc,GAChB,SAAQ;AAGV,KAAI,YAAY,GACd,OAAM,OAAO;CAGf,MAAM,WAAW,UAAU;CAC3B,MAAM,cAAc,EAAE;AAEtB,KAAI,SACF,MAAK,IAAI,IAAI,GAAG,KAAK,UAAU,KAAK;EAClC,MAAM,aAAa,IAAI;AAEvB,MAAI,CAAC,YACH,aAAY,cAAc;WACjB,MAAM,EAGf,aAAY,cAAc,CAAC,cAFN,OAAO,aAAa,IAAI,UAAU,KAEA,cAAc,EAAE;WAC9D,MAAM,SACf,aAAY,cAAc,CAAC,GAAG,UAAU;MAIxC,aAAY,cAAc,CAAC,GAFN,OAAO,aAAa,IAAI,UAAU,EAEZ;;UAGtC,gBAAgB,UACzB,aAAY,aAAa,cAAc,CAAC,aAAa,EAAE,GAAG;KAE1D,aAAY,aAAa,CAAC,aAAa,YAAY,YAAY;AAGjE,QAAO;EACL;EACA;EACA;EACD;;AAGH,SAAgB,iBACd,UACA,KACA,OAII,EAAE,EACE;CAER,MAAM,EAAE,OAAO,KAAK,gBAAgB,eAAe,KADrC,SAAS,MAAM,QAAQ,EAC0B,KAAK;CAEpE,MAAM,iBAAiB,OAAO,IAAI,CAAC;AAgCnC,SA/ByB,KAAK,YAAY,KAAK,UAAU,SAAS,GAAG,UAGlE,MAAM,QAAQ,CACd,MAAM,OAAO,IAAI,CACjB,KAAK,MAAM,UAAU;EACpB,MAAM,SAAS,QAAQ,IAAI;EAE3B,MAAM,SAAS,IADM,IAAI,SAAS,MAAM,CAAC,eAAe,CACxB;EAChC,MAAM,YAAY,QAAQ,YAAY,WAAW,MAAM;AACvD,MAAI,WAAW;GACb,IAAI,aAAa;AACjB,OAAI,MAAM,QAAQ,UAAU,EAAE;IAC5B,MAAM,gBAAgB,KACnB,MAAM,GAAG,KAAK,IAAI,UAAU,KAAK,GAAG,EAAE,CAAC,CACvC,QAAQ,UAAU,IAAI;IACzB,MAAM,kBAAkB,UAAU,MAAM;AAExC,iBAAa;KACX;KACA,OAAO,QAAQ,OAAO,IAAI;KAC1B;KACA,IAAI,OAAO,gBAAgB;KAC5B,CAAC,KAAK,GAAG;;AAEZ,UAAO;IAAC;IAAK;IAAQ;IAAM;IAAW,CAAC,KAAK,GAAG;;AAEjD,SAAO,IAAI,SAAS;GACpB,CACD,KAAK,KAAK"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
const require_is_object = require('./is-object-umGh91v1.cjs');
|
|
2
|
+
const require_is_undefined = require('./is-undefined-CnI0qe-z.cjs');
|
|
3
|
+
const require_is_string = require('./is-string-C2RK4Gjs.cjs');
|
|
4
|
+
|
|
5
|
+
//#region ../type-checks/src/is-null.ts
|
|
6
|
+
const isNull = (value) => {
|
|
7
|
+
try {
|
|
8
|
+
return value === null;
|
|
9
|
+
} catch {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region ../type-checks/src/is-empty.ts
|
|
16
|
+
/**
|
|
17
|
+
* Check if the provided value's type is `null` or `undefined`
|
|
18
|
+
*
|
|
19
|
+
* @param value - The value to type check
|
|
20
|
+
* @returns An indicator specifying if the value provided is of type `null` or `undefined`
|
|
21
|
+
*/
|
|
22
|
+
const isEmpty = (value) => {
|
|
23
|
+
try {
|
|
24
|
+
return require_is_undefined.isUndefined(value) || isNull(value);
|
|
25
|
+
} catch {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region ../type-checks/src/is-set.ts
|
|
32
|
+
/**
|
|
33
|
+
* The inverse of the `isEmpty` function
|
|
34
|
+
*
|
|
35
|
+
* @param value - The value to type check
|
|
36
|
+
* @returns An indicator specifying if the value provided is **NOT** of type `null` or `undefined`
|
|
37
|
+
*/
|
|
38
|
+
const isSet = (value) => {
|
|
39
|
+
try {
|
|
40
|
+
return !isEmpty(value);
|
|
41
|
+
} catch {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region ../type-checks/src/is-non-null-object.ts
|
|
48
|
+
/**
|
|
49
|
+
* Check if the provided value's type is `Object` and is not `null` or `undefined`
|
|
50
|
+
*
|
|
51
|
+
* @param value - The value to type check
|
|
52
|
+
* @returns An indicator specifying if the value provided is of type `Object` and is not `null` or `undefined`
|
|
53
|
+
*/
|
|
54
|
+
const isNonNullObject = (value) => {
|
|
55
|
+
return isSet(value) && require_is_object.isObject(value);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region ../type-checks/src/is-set-object.ts
|
|
60
|
+
/**
|
|
61
|
+
* Check if the provided value's type is an object with some fields set
|
|
62
|
+
*
|
|
63
|
+
* @param value - The value to type check
|
|
64
|
+
* @returns An indicator specifying if the value provided is an object with some fields se
|
|
65
|
+
*/
|
|
66
|
+
const isSetObject = (value) => {
|
|
67
|
+
try {
|
|
68
|
+
return isNonNullObject(value) && Object.keys(value).length > 0;
|
|
69
|
+
} catch {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/pointer/find-reference.ts
|
|
76
|
+
const { isArray } = Array;
|
|
77
|
+
/**
|
|
78
|
+
* Finds a target in document specified by JSON Pointer. Also returns the
|
|
79
|
+
* object containing the target and key used to reference that object.
|
|
80
|
+
*
|
|
81
|
+
* Throws Error('NOT_FOUND') if pointer does not result into a value in the middle
|
|
82
|
+
* of the path. If the last element of the path does not result into a value, the
|
|
83
|
+
* lookup succeeds with `val` set to `undefined`. It can be used to discriminate
|
|
84
|
+
* missing values, because `undefined` is not a valid JSON value.
|
|
85
|
+
*
|
|
86
|
+
* If last element in array is targeted using "-", e.g. "/arr/-", use
|
|
87
|
+
* `isArrayEnd` to verify that:
|
|
88
|
+
*
|
|
89
|
+
* ```js
|
|
90
|
+
* const ref = find({arr: [1, 2, 3], ['arr', '-']});
|
|
91
|
+
* if (isArrayReference(ref)) {
|
|
92
|
+
* if (isArrayEnd(ref)) {
|
|
93
|
+
* // ...
|
|
94
|
+
* }
|
|
95
|
+
* }
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @param val - Document to search in.
|
|
99
|
+
* @param path - JSON Pointer path.
|
|
100
|
+
* @returns Reference to the target.
|
|
101
|
+
*/
|
|
102
|
+
const find = (val, path) => {
|
|
103
|
+
const pathLength = path.length;
|
|
104
|
+
if (!pathLength) return { val };
|
|
105
|
+
let obj;
|
|
106
|
+
let key;
|
|
107
|
+
for (let i = 0; i < pathLength; i++) {
|
|
108
|
+
obj = val;
|
|
109
|
+
key = path[i];
|
|
110
|
+
if (isArray(obj)) {
|
|
111
|
+
const length = obj.length;
|
|
112
|
+
if (key === "-") key = length;
|
|
113
|
+
else if (require_is_string.isString(key)) {
|
|
114
|
+
const key2 = Math.trunc(Number.parseInt(key));
|
|
115
|
+
if (String(key2) !== key) throw new Error("INVALID_INDEX");
|
|
116
|
+
key = key2;
|
|
117
|
+
if (key < 0) throw new Error("INVALID_INDEX");
|
|
118
|
+
}
|
|
119
|
+
if (key) val = obj[key];
|
|
120
|
+
} else if (isSetObject(obj)) val = key && key in obj ? obj[key] : void 0;
|
|
121
|
+
else throw new Error("NOT_FOUND");
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
val,
|
|
125
|
+
obj,
|
|
126
|
+
key
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
const isArrayReference = (ref) => isArray(ref.obj) && typeof ref.key === "number";
|
|
130
|
+
const isArrayEnd = (ref) => ref.obj.length === ref.key;
|
|
131
|
+
const isObjectReference = (ref) => typeof ref.obj === "object" && typeof ref.key === "string";
|
|
132
|
+
|
|
133
|
+
//#endregion
|
|
134
|
+
Object.defineProperty(exports, 'find', {
|
|
135
|
+
enumerable: true,
|
|
136
|
+
get: function () {
|
|
137
|
+
return find;
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
Object.defineProperty(exports, 'isArrayEnd', {
|
|
141
|
+
enumerable: true,
|
|
142
|
+
get: function () {
|
|
143
|
+
return isArrayEnd;
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
Object.defineProperty(exports, 'isArrayReference', {
|
|
147
|
+
enumerable: true,
|
|
148
|
+
get: function () {
|
|
149
|
+
return isArrayReference;
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
Object.defineProperty(exports, 'isObjectReference', {
|
|
153
|
+
enumerable: true,
|
|
154
|
+
get: function () {
|
|
155
|
+
return isObjectReference;
|
|
156
|
+
}
|
|
157
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
//#region src/pointer/find-reference.d.ts
|
|
2
|
+
interface Reference {
|
|
3
|
+
/** Target value where pointer is pointing. */
|
|
4
|
+
readonly val: unknown;
|
|
5
|
+
/** Object which contains the target value. */
|
|
6
|
+
readonly obj?: unknown | object | unknown[];
|
|
7
|
+
/** Key which targets the target value in the object. */
|
|
8
|
+
readonly key?: string | number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Finds a target in document specified by JSON Pointer. Also returns the
|
|
12
|
+
* object containing the target and key used to reference that object.
|
|
13
|
+
*
|
|
14
|
+
* Throws Error('NOT_FOUND') if pointer does not result into a value in the middle
|
|
15
|
+
* of the path. If the last element of the path does not result into a value, the
|
|
16
|
+
* lookup succeeds with `val` set to `undefined`. It can be used to discriminate
|
|
17
|
+
* missing values, because `undefined` is not a valid JSON value.
|
|
18
|
+
*
|
|
19
|
+
* If last element in array is targeted using "-", e.g. "/arr/-", use
|
|
20
|
+
* `isArrayEnd` to verify that:
|
|
21
|
+
*
|
|
22
|
+
* ```js
|
|
23
|
+
* const ref = find({arr: [1, 2, 3], ['arr', '-']});
|
|
24
|
+
* if (isArrayReference(ref)) {
|
|
25
|
+
* if (isArrayEnd(ref)) {
|
|
26
|
+
* // ...
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @param val - Document to search in.
|
|
32
|
+
* @param path - JSON Pointer path.
|
|
33
|
+
* @returns Reference to the target.
|
|
34
|
+
*/
|
|
35
|
+
declare const find: (val: unknown, path: Reference["key"][]) => Reference;
|
|
36
|
+
interface ArrayReference<T = unknown> {
|
|
37
|
+
/** `undefined` in case JSON Pointer points to last element, e.g. "/foo/-". */
|
|
38
|
+
readonly val: undefined | T;
|
|
39
|
+
readonly obj: T[];
|
|
40
|
+
readonly key: number;
|
|
41
|
+
}
|
|
42
|
+
declare const isArrayReference: <T = unknown>(ref: Reference) => ref is ArrayReference<T>;
|
|
43
|
+
declare const isArrayEnd: (ref: ArrayReference) => boolean;
|
|
44
|
+
interface ObjectReference<T = unknown> {
|
|
45
|
+
readonly val: T;
|
|
46
|
+
readonly obj: Record<string, T>;
|
|
47
|
+
readonly key: string;
|
|
48
|
+
}
|
|
49
|
+
declare const isObjectReference: <T = unknown>(ref: Reference) => ref is ObjectReference<T>;
|
|
50
|
+
//#endregion
|
|
51
|
+
export { isArrayEnd as a, find as i, ObjectReference as n, isArrayReference as o, Reference as r, isObjectReference as s, ArrayReference as t };
|
|
52
|
+
//# sourceMappingURL=find-reference-C-YleCds.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-reference-C-YleCds.d.cts","names":[],"sources":["../src/pointer/find-reference.ts"],"sourcesContent":[],"mappings":";UAqBiB,SAAA;EAAA;EAoCJ,SAyCZ,GAAA,EAAA,OAzCwC;EA2CxB;EAOJ,SAAA,GAAA,CAAA,EAAA,OAEiE,GAAA,MAAA,GAAA,OAAA,EAAA;EADvE;EACkB,SAAA,GAAA,CAAA,EAAA,MAAA,GAAA,MAAA;;;AAEzB;AAGA;;;;;AAMA;;;;;;;;;;;;;;;;;;cA/Da,2BAA4B,uBAAqB;UA2C7C;;4BAEW;gBACZ;;;cAIH,qCACN,qBACG,eAAe;cAEZ,kBAAmB;UAGf;gBACD;gBACA,eAAe;;;cAIlB,sCACN,qBACG,gBAAgB"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
//#region src/pointer/find-reference.d.ts
|
|
2
|
+
interface Reference {
|
|
3
|
+
/** Target value where pointer is pointing. */
|
|
4
|
+
readonly val: unknown;
|
|
5
|
+
/** Object which contains the target value. */
|
|
6
|
+
readonly obj?: unknown | object | unknown[];
|
|
7
|
+
/** Key which targets the target value in the object. */
|
|
8
|
+
readonly key?: string | number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Finds a target in document specified by JSON Pointer. Also returns the
|
|
12
|
+
* object containing the target and key used to reference that object.
|
|
13
|
+
*
|
|
14
|
+
* Throws Error('NOT_FOUND') if pointer does not result into a value in the middle
|
|
15
|
+
* of the path. If the last element of the path does not result into a value, the
|
|
16
|
+
* lookup succeeds with `val` set to `undefined`. It can be used to discriminate
|
|
17
|
+
* missing values, because `undefined` is not a valid JSON value.
|
|
18
|
+
*
|
|
19
|
+
* If last element in array is targeted using "-", e.g. "/arr/-", use
|
|
20
|
+
* `isArrayEnd` to verify that:
|
|
21
|
+
*
|
|
22
|
+
* ```js
|
|
23
|
+
* const ref = find({arr: [1, 2, 3], ['arr', '-']});
|
|
24
|
+
* if (isArrayReference(ref)) {
|
|
25
|
+
* if (isArrayEnd(ref)) {
|
|
26
|
+
* // ...
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @param val - Document to search in.
|
|
32
|
+
* @param path - JSON Pointer path.
|
|
33
|
+
* @returns Reference to the target.
|
|
34
|
+
*/
|
|
35
|
+
declare const find: (val: unknown, path: Reference["key"][]) => Reference;
|
|
36
|
+
interface ArrayReference<T = unknown> {
|
|
37
|
+
/** `undefined` in case JSON Pointer points to last element, e.g. "/foo/-". */
|
|
38
|
+
readonly val: undefined | T;
|
|
39
|
+
readonly obj: T[];
|
|
40
|
+
readonly key: number;
|
|
41
|
+
}
|
|
42
|
+
declare const isArrayReference: <T = unknown>(ref: Reference) => ref is ArrayReference<T>;
|
|
43
|
+
declare const isArrayEnd: (ref: ArrayReference) => boolean;
|
|
44
|
+
interface ObjectReference<T = unknown> {
|
|
45
|
+
readonly val: T;
|
|
46
|
+
readonly obj: Record<string, T>;
|
|
47
|
+
readonly key: string;
|
|
48
|
+
}
|
|
49
|
+
declare const isObjectReference: <T = unknown>(ref: Reference) => ref is ObjectReference<T>;
|
|
50
|
+
//#endregion
|
|
51
|
+
export { isArrayEnd as a, find as i, ObjectReference as n, isArrayReference as o, Reference as r, isObjectReference as s, ArrayReference as t };
|
|
52
|
+
//# sourceMappingURL=find-reference-b7rRdLFx.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-reference-b7rRdLFx.d.mts","names":[],"sources":["../src/pointer/find-reference.ts"],"sourcesContent":[],"mappings":";UAqBiB,SAAA;EAAA;EAoCJ,SAyCZ,GAAA,EAAA,OAzCwC;EA2CxB;EAOJ,SAAA,GAAA,CAAA,EAAA,OAEiE,GAAA,MAAA,GAAA,OAAA,EAAA;EADvE;EACkB,SAAA,GAAA,CAAA,EAAA,MAAA,GAAA,MAAA;;;AAEzB;AAGA;;;;;AAMA;;;;;;;;;;;;;;;;;;cA/Da,2BAA4B,uBAAqB;UA2C7C;;4BAEW;gBACZ;;;cAIH,qCACN,qBACG,eAAe;cAEZ,kBAAmB;UAGf;gBACD;gBACA,eAAe;;;cAIlB,sCACN,qBACG,gBAAgB"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { t as isObject } from "./is-object-BpfmzHWa.mjs";
|
|
2
|
+
import { t as isUndefined } from "./is-undefined-CmyJWYGD.mjs";
|
|
3
|
+
import { t as isString } from "./is-string-CLiBUSKV.mjs";
|
|
4
|
+
|
|
5
|
+
//#region ../type-checks/src/is-null.ts
|
|
6
|
+
const isNull = (value) => {
|
|
7
|
+
try {
|
|
8
|
+
return value === null;
|
|
9
|
+
} catch {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region ../type-checks/src/is-empty.ts
|
|
16
|
+
/**
|
|
17
|
+
* Check if the provided value's type is `null` or `undefined`
|
|
18
|
+
*
|
|
19
|
+
* @param value - The value to type check
|
|
20
|
+
* @returns An indicator specifying if the value provided is of type `null` or `undefined`
|
|
21
|
+
*/
|
|
22
|
+
const isEmpty = (value) => {
|
|
23
|
+
try {
|
|
24
|
+
return isUndefined(value) || isNull(value);
|
|
25
|
+
} catch {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region ../type-checks/src/is-set.ts
|
|
32
|
+
/**
|
|
33
|
+
* The inverse of the `isEmpty` function
|
|
34
|
+
*
|
|
35
|
+
* @param value - The value to type check
|
|
36
|
+
* @returns An indicator specifying if the value provided is **NOT** of type `null` or `undefined`
|
|
37
|
+
*/
|
|
38
|
+
const isSet = (value) => {
|
|
39
|
+
try {
|
|
40
|
+
return !isEmpty(value);
|
|
41
|
+
} catch {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region ../type-checks/src/is-non-null-object.ts
|
|
48
|
+
/**
|
|
49
|
+
* Check if the provided value's type is `Object` and is not `null` or `undefined`
|
|
50
|
+
*
|
|
51
|
+
* @param value - The value to type check
|
|
52
|
+
* @returns An indicator specifying if the value provided is of type `Object` and is not `null` or `undefined`
|
|
53
|
+
*/
|
|
54
|
+
const isNonNullObject = (value) => {
|
|
55
|
+
return isSet(value) && isObject(value);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region ../type-checks/src/is-set-object.ts
|
|
60
|
+
/**
|
|
61
|
+
* Check if the provided value's type is an object with some fields set
|
|
62
|
+
*
|
|
63
|
+
* @param value - The value to type check
|
|
64
|
+
* @returns An indicator specifying if the value provided is an object with some fields se
|
|
65
|
+
*/
|
|
66
|
+
const isSetObject = (value) => {
|
|
67
|
+
try {
|
|
68
|
+
return isNonNullObject(value) && Object.keys(value).length > 0;
|
|
69
|
+
} catch {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/pointer/find-reference.ts
|
|
76
|
+
const { isArray } = Array;
|
|
77
|
+
/**
|
|
78
|
+
* Finds a target in document specified by JSON Pointer. Also returns the
|
|
79
|
+
* object containing the target and key used to reference that object.
|
|
80
|
+
*
|
|
81
|
+
* Throws Error('NOT_FOUND') if pointer does not result into a value in the middle
|
|
82
|
+
* of the path. If the last element of the path does not result into a value, the
|
|
83
|
+
* lookup succeeds with `val` set to `undefined`. It can be used to discriminate
|
|
84
|
+
* missing values, because `undefined` is not a valid JSON value.
|
|
85
|
+
*
|
|
86
|
+
* If last element in array is targeted using "-", e.g. "/arr/-", use
|
|
87
|
+
* `isArrayEnd` to verify that:
|
|
88
|
+
*
|
|
89
|
+
* ```js
|
|
90
|
+
* const ref = find({arr: [1, 2, 3], ['arr', '-']});
|
|
91
|
+
* if (isArrayReference(ref)) {
|
|
92
|
+
* if (isArrayEnd(ref)) {
|
|
93
|
+
* // ...
|
|
94
|
+
* }
|
|
95
|
+
* }
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @param val - Document to search in.
|
|
99
|
+
* @param path - JSON Pointer path.
|
|
100
|
+
* @returns Reference to the target.
|
|
101
|
+
*/
|
|
102
|
+
const find = (val, path) => {
|
|
103
|
+
const pathLength = path.length;
|
|
104
|
+
if (!pathLength) return { val };
|
|
105
|
+
let obj;
|
|
106
|
+
let key;
|
|
107
|
+
for (let i = 0; i < pathLength; i++) {
|
|
108
|
+
obj = val;
|
|
109
|
+
key = path[i];
|
|
110
|
+
if (isArray(obj)) {
|
|
111
|
+
const length = obj.length;
|
|
112
|
+
if (key === "-") key = length;
|
|
113
|
+
else if (isString(key)) {
|
|
114
|
+
const key2 = Math.trunc(Number.parseInt(key));
|
|
115
|
+
if (String(key2) !== key) throw new Error("INVALID_INDEX");
|
|
116
|
+
key = key2;
|
|
117
|
+
if (key < 0) throw new Error("INVALID_INDEX");
|
|
118
|
+
}
|
|
119
|
+
if (key) val = obj[key];
|
|
120
|
+
} else if (isSetObject(obj)) val = key && key in obj ? obj[key] : void 0;
|
|
121
|
+
else throw new Error("NOT_FOUND");
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
val,
|
|
125
|
+
obj,
|
|
126
|
+
key
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
const isArrayReference = (ref) => isArray(ref.obj) && typeof ref.key === "number";
|
|
130
|
+
const isArrayEnd = (ref) => ref.obj.length === ref.key;
|
|
131
|
+
const isObjectReference = (ref) => typeof ref.obj === "object" && typeof ref.key === "string";
|
|
132
|
+
|
|
133
|
+
//#endregion
|
|
134
|
+
export { isObjectReference as i, isArrayEnd as n, isArrayReference as r, find as t };
|
|
135
|
+
//# sourceMappingURL=find-reference-woYMiWzN.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-reference-woYMiWzN.mjs","names":["obj: Reference[\"obj\"]","key: Reference[\"key\"]"],"sources":["../../type-checks/src/is-null.ts","../../type-checks/src/is-empty.ts","../../type-checks/src/is-set.ts","../../type-checks/src/is-non-null-object.ts","../../type-checks/src/is-set-object.ts","../src/pointer/find-reference.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\nexport const isNull = (value: unknown): value is null => {\n try {\n return value === null;\n } catch {\n return false;\n }\n};\n","/* -------------------------------------------------------------------\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 { isDate } from \"./is-date\";\nimport { isFunction } from \"./is-function\";\nimport { isNull } from \"./is-null\";\nimport { isNumber } from \"./is-number\";\nimport { isSymbol } from \"./is-symbol\";\nimport { isUndefined } from \"./is-undefined\";\n\n/**\n * Check if the provided value's type is `null` or `undefined`\n *\n * @param value - The value to type check\n * @returns An indicator specifying if the value provided is of type `null` or `undefined`\n */\nexport const isEmpty = (value: unknown) => {\n try {\n return isUndefined(value) || isNull(value);\n } catch {\n return false;\n }\n};\n\nexport const isEmptyAnything = (value: any) => {\n if (value === true || value === false) return true;\n if (value === null || value === undefined) return true;\n if (isNumber(value)) return value === 0;\n if (isDate(value)) return Number.isNaN(value.getTime());\n if (isFunction(value)) return false;\n if (isSymbol(value)) return false;\n const { length } = value;\n if (isNumber(length)) return length === 0;\n const { size } = value;\n if (isNumber(size)) return size === 0;\n const keys = Object.keys(value).length;\n\n return keys === 0;\n};\n","/* -------------------------------------------------------------------\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 { isEmpty } from \"./is-empty\";\n\n/**\n * The inverse of the `isEmpty` function\n *\n * @param value - The value to type check\n * @returns An indicator specifying if the value provided is **NOT** of type `null` or `undefined`\n */\nexport const isSet = (value: unknown): value is NonNullable<unknown> => {\n try {\n return !isEmpty(value);\n } catch {\n return false;\n }\n};\n","/* -------------------------------------------------------------------\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 { isObject } from \"./is-object\";\nimport { isSet } from \"./is-set\";\n\n/**\n * Check if the provided value's type is `Object` and is not `null` or `undefined`\n *\n * @param value - The value to type check\n * @returns An indicator specifying if the value provided is of type `Object` and is not `null` or `undefined`\n */\nexport const isNonNullObject = (value: any): value is NonNullable<object> => {\n return isSet(value) && isObject(value);\n};\n","/* -------------------------------------------------------------------\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 { isNonNullObject } from \"./is-non-null-object\";\n\n/**\n * Check if the provided value's type is an object with some fields set\n *\n * @param value - The value to type check\n * @returns An indicator specifying if the value provided is an object with some fields se\n */\nexport const isSetObject = (value: unknown): value is NonNullable<object> => {\n try {\n return isNonNullObject(value) && Object.keys(value).length > 0;\n } catch {\n return false;\n }\n};\n","/* -------------------------------------------------------------------\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 { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isString } from \"@stryke/type-checks/is-string\";\n\nexport interface Reference {\n /** Target value where pointer is pointing. */\n readonly val: unknown;\n /** Object which contains the target value. */\n readonly obj?: unknown | object | unknown[];\n /** Key which targets the target value in the object. */\n readonly key?: string | number;\n}\n\nconst { isArray } = Array;\n\n/**\n * Finds a target in document specified by JSON Pointer. Also returns the\n * object containing the target and key used to reference that object.\n *\n * Throws Error('NOT_FOUND') if pointer does not result into a value in the middle\n * of the path. If the last element of the path does not result into a value, the\n * lookup succeeds with `val` set to `undefined`. It can be used to discriminate\n * missing values, because `undefined` is not a valid JSON value.\n *\n * If last element in array is targeted using \"-\", e.g. \"/arr/-\", use\n * `isArrayEnd` to verify that:\n *\n * ```js\n * const ref = find({arr: [1, 2, 3], ['arr', '-']});\n * if (isArrayReference(ref)) {\n * if (isArrayEnd(ref)) {\n * // ...\n * }\n * }\n * ```\n *\n * @param val - Document to search in.\n * @param path - JSON Pointer path.\n * @returns Reference to the target.\n */\nexport const find = (val: unknown, path: Reference[\"key\"][]): Reference => {\n const pathLength = path.length;\n if (!pathLength) {\n return { val };\n }\n\n let obj: Reference[\"obj\"];\n let key: Reference[\"key\"];\n for (let i = 0; i < pathLength; i++) {\n obj = val;\n key = path[i];\n if (isArray(obj)) {\n const length = obj.length;\n if (key === \"-\") {\n key = length;\n } else if (isString(key)) {\n const key2 = Math.trunc(Number.parseInt(key));\n if (String(key2) !== key) {\n throw new Error(\"INVALID_INDEX\");\n }\n\n key = key2;\n if (key < 0) {\n throw new Error(\"INVALID_INDEX\");\n }\n }\n\n if (key) {\n val = obj[key];\n }\n } else if (isSetObject(obj)) {\n val = key && key in obj ? (obj as any)[key] : undefined;\n } else throw new Error(\"NOT_FOUND\");\n }\n const ref: Reference = {\n val,\n obj,\n key\n };\n\n return ref;\n};\n\nexport interface ArrayReference<T = unknown> {\n /** `undefined` in case JSON Pointer points to last element, e.g. \"/foo/-\". */\n readonly val: undefined | T;\n readonly obj: T[];\n readonly key: number;\n}\n\nexport const isArrayReference = <T = unknown>(\n ref: Reference\n): ref is ArrayReference<T> => isArray(ref.obj) && typeof ref.key === \"number\";\n\nexport const isArrayEnd = (ref: ArrayReference): boolean =>\n ref.obj.length === ref.key;\n\nexport interface ObjectReference<T = unknown> {\n readonly val: T;\n readonly obj: Record<string, T>;\n readonly key: string;\n}\n\nexport const isObjectReference = <T = unknown>(\n ref: Reference\n): ref is ObjectReference<T> =>\n typeof ref.obj === \"object\" && typeof ref.key === \"string\";\n"],"mappings":";;;;;AAkBA,MAAa,UAAU,UAAkC;AACvD,KAAI;AACF,SAAO,UAAU;SACX;AACN,SAAO;;;;;;;;;;;;ACSX,MAAa,WAAW,UAAmB;AACzC,KAAI;AACF,SAAO,YAAY,MAAM,IAAI,OAAO,MAAM;SACpC;AACN,SAAO;;;;;;;;;;;;ACTX,MAAa,SAAS,UAAkD;AACtE,KAAI;AACF,SAAO,CAAC,QAAQ,MAAM;SAChB;AACN,SAAO;;;;;;;;;;;;ACHX,MAAa,mBAAmB,UAA6C;AAC3E,QAAO,MAAM,MAAM,IAAI,SAAS,MAAM;;;;;;;;;;;ACFxC,MAAa,eAAe,UAAiD;AAC3E,KAAI;AACF,SAAO,gBAAgB,MAAM,IAAI,OAAO,KAAK,MAAM,CAAC,SAAS;SACvD;AACN,SAAO;;;;;;ACAX,MAAM,EAAE,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BpB,MAAa,QAAQ,KAAc,SAAwC;CACzE,MAAM,aAAa,KAAK;AACxB,KAAI,CAAC,WACH,QAAO,EAAE,KAAK;CAGhB,IAAIA;CACJ,IAAIC;AACJ,MAAK,IAAI,IAAI,GAAG,IAAI,YAAY,KAAK;AACnC,QAAM;AACN,QAAM,KAAK;AACX,MAAI,QAAQ,IAAI,EAAE;GAChB,MAAM,SAAS,IAAI;AACnB,OAAI,QAAQ,IACV,OAAM;YACG,SAAS,IAAI,EAAE;IACxB,MAAM,OAAO,KAAK,MAAM,OAAO,SAAS,IAAI,CAAC;AAC7C,QAAI,OAAO,KAAK,KAAK,IACnB,OAAM,IAAI,MAAM,gBAAgB;AAGlC,UAAM;AACN,QAAI,MAAM,EACR,OAAM,IAAI,MAAM,gBAAgB;;AAIpC,OAAI,IACF,OAAM,IAAI;aAEH,YAAY,IAAI,CACzB,OAAM,OAAO,OAAO,MAAO,IAAY,OAAO;MACzC,OAAM,IAAI,MAAM,YAAY;;AAQrC,QANuB;EACrB;EACA;EACA;EACD;;AAYH,MAAa,oBACX,QAC6B,QAAQ,IAAI,IAAI,IAAI,OAAO,IAAI,QAAQ;AAEtE,MAAa,cAAc,QACzB,IAAI,IAAI,WAAW,IAAI;AAQzB,MAAa,qBACX,QAEA,OAAO,IAAI,QAAQ,YAAY,OAAO,IAAI,QAAQ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|