@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.
Files changed (204) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/code-frames-BUtrssZ5.d.cts +17 -0
  3. package/dist/code-frames-BUtrssZ5.d.cts.map +1 -0
  4. package/dist/code-frames-BmUvlJ0w.cjs +82 -0
  5. package/dist/code-frames-CrTAYYSE.d.mts +17 -0
  6. package/dist/code-frames-CrTAYYSE.d.mts.map +1 -0
  7. package/dist/code-frames-DuBfTMu4.mjs +77 -0
  8. package/dist/code-frames-DuBfTMu4.mjs.map +1 -0
  9. package/dist/find-reference-B8xshNXL.d.mts +52 -0
  10. package/dist/find-reference-B8xshNXL.d.mts.map +1 -0
  11. package/dist/find-reference-C-YleCds.d.cts +52 -0
  12. package/dist/find-reference-C-YleCds.d.cts.map +1 -0
  13. package/dist/find-reference-DMSYEaaI.mjs +64 -0
  14. package/dist/find-reference-DMSYEaaI.mjs.map +1 -0
  15. package/dist/find-reference-De5vBQV2.cjs +86 -0
  16. package/dist/index-B_e8BwCm.d.cts +1 -0
  17. package/dist/index-CCt0lwyI.d.mts +1 -0
  18. package/dist/index-CDAfh8Ew.d.cts +1 -0
  19. package/dist/index-DvuJXuAN.d.mts +1 -0
  20. package/dist/index.cjs +37 -14
  21. package/dist/index.d.cts +11 -8
  22. package/dist/index.d.mts +12 -9
  23. package/dist/index.mjs +13 -8
  24. package/dist/is-number-BIwzZzyi.mjs +31 -0
  25. package/dist/is-number-BIwzZzyi.mjs.map +1 -0
  26. package/dist/is-number-c5xguIbS.cjs +42 -0
  27. package/dist/{type-checks/src/is-plain-object.mjs → is-object-BpfmzHWa.mjs} +19 -3
  28. package/dist/is-object-BpfmzHWa.mjs.map +1 -0
  29. package/dist/{type-checks/src/is-plain-object.cjs → is-object-umGh91v1.cjs} +24 -3
  30. package/dist/is-set-object-BmHip9em.cjs +108 -0
  31. package/dist/is-set-object-C1Qnj1Q8.mjs +98 -0
  32. package/dist/is-set-object-C1Qnj1Q8.mjs.map +1 -0
  33. package/dist/{type-checks/src/is-string.mjs → is-string-C2RK4Gjs.cjs} +7 -2
  34. package/dist/{type-checks/src/is-string.cjs → is-string-CLiBUSKV.mjs} +2 -2
  35. package/dist/is-string-CLiBUSKV.mjs.map +1 -0
  36. package/dist/{type-checks/src/is-undefined.cjs → is-undefined-CmyJWYGD.mjs} +2 -2
  37. package/dist/is-undefined-CmyJWYGD.mjs.map +1 -0
  38. package/dist/{type-checks/src/is-undefined.mjs → is-undefined-CnI0qe-z.cjs} +7 -2
  39. package/dist/parse-BGlhbY16.d.cts +9 -0
  40. package/dist/parse-BGlhbY16.d.cts.map +1 -0
  41. package/dist/parse-Bp6kkcQ4.cjs +127 -0
  42. package/dist/parse-ByDxRup5.cjs +62 -0
  43. package/dist/parse-Cj-YfhrI.d.mts +51 -0
  44. package/dist/parse-Cj-YfhrI.d.mts.map +1 -0
  45. package/dist/parse-DZfi3d96.d.cts +51 -0
  46. package/dist/parse-DZfi3d96.d.cts.map +1 -0
  47. package/dist/parse-Dn43ZK9y.mjs +52 -0
  48. package/dist/parse-Dn43ZK9y.mjs.map +1 -0
  49. package/dist/parse-error-7K8s4vWf.d.cts +15 -0
  50. package/dist/parse-error-7K8s4vWf.d.cts.map +1 -0
  51. package/dist/parse-error-Af4zHUQ_.mjs +34 -0
  52. package/dist/parse-error-Af4zHUQ_.mjs.map +1 -0
  53. package/dist/parse-error-DpEv3vo_.d.mts +15 -0
  54. package/dist/parse-error-DpEv3vo_.d.mts.map +1 -0
  55. package/dist/parse-error-N7UE-HMh.cjs +39 -0
  56. package/dist/parse-fXy5pbmE.d.mts +9 -0
  57. package/dist/parse-fXy5pbmE.d.mts.map +1 -0
  58. package/dist/parse-vw_qRD3F.mjs +81 -0
  59. package/dist/parse-vw_qRD3F.mjs.map +1 -0
  60. package/dist/pointer/find-reference.cjs +5 -65
  61. package/dist/pointer/find-reference.d.cts +2 -52
  62. package/dist/pointer/find-reference.d.mts +2 -52
  63. package/dist/pointer/find-reference.mjs +2 -63
  64. package/dist/pointer/index.cjs +15 -14
  65. package/dist/pointer/index.d.cts +2 -2
  66. package/dist/pointer/index.d.mts +2 -2
  67. package/dist/pointer/index.mjs +3 -2
  68. package/dist/pointer/parse.cjs +9 -86
  69. package/dist/pointer/parse.d.cts +2 -44
  70. package/dist/pointer/parse.d.mts +2 -44
  71. package/dist/pointer/parse.mjs +2 -80
  72. package/dist/pointer-B3W_Sme3.cjs +0 -0
  73. package/dist/pointer-Dn__XOdY.mjs +0 -0
  74. package/dist/schema-BO1HCrxv.d.cts +55 -0
  75. package/dist/schema-BO1HCrxv.d.cts.map +1 -0
  76. package/dist/schema-CmH1V_uI.d.mts +55 -0
  77. package/dist/schema-CmH1V_uI.d.mts.map +1 -0
  78. package/dist/schema-DGmzxHja.mjs +72 -0
  79. package/dist/schema-DGmzxHja.mjs.map +1 -0
  80. package/dist/schema-Dl018Aq4.cjs +106 -0
  81. package/dist/schema.cjs +8 -0
  82. package/dist/schema.d.cts +2 -0
  83. package/dist/schema.d.mts +3 -0
  84. package/dist/schema.mjs +3 -0
  85. package/dist/storm-json-8F9CKpXu.d.mts +70 -0
  86. package/dist/storm-json-8F9CKpXu.d.mts.map +1 -0
  87. package/dist/storm-json-BD6WFbrI.cjs +154 -0
  88. package/dist/storm-json-DvIEWMEH.d.cts +70 -0
  89. package/dist/storm-json-DvIEWMEH.d.cts.map +1 -0
  90. package/dist/storm-json-nkhJgTz4.mjs +116 -0
  91. package/dist/storm-json-nkhJgTz4.mjs.map +1 -0
  92. package/dist/storm-json.cjs +3 -116
  93. package/dist/storm-json.d.cts +2 -70
  94. package/dist/storm-json.d.mts +3 -70
  95. package/dist/storm-json.mjs +3 -115
  96. package/dist/stringify-Bc8OkhIr.d.cts +13 -0
  97. package/dist/stringify-Bc8OkhIr.d.cts.map +1 -0
  98. package/dist/stringify-BehjrfhS.cjs +78 -0
  99. package/dist/stringify-CFT1K1LE.d.mts +13 -0
  100. package/dist/stringify-CFT1K1LE.d.mts.map +1 -0
  101. package/dist/stringify-CYHjAvWm.mjs +68 -0
  102. package/dist/stringify-CYHjAvWm.mjs.map +1 -0
  103. package/dist/strip-comments-BA8MS_Fs.d.mts +11 -0
  104. package/dist/strip-comments-BA8MS_Fs.d.mts.map +1 -0
  105. package/dist/strip-comments-CmEG_smS.cjs +94 -0
  106. package/dist/strip-comments-Cz_Wc25t.d.cts +11 -0
  107. package/dist/strip-comments-Cz_Wc25t.d.cts.map +1 -0
  108. package/dist/strip-comments-Dq00N_Sg.mjs +89 -0
  109. package/dist/strip-comments-Dq00N_Sg.mjs.map +1 -0
  110. package/dist/types-Bn8rC098.d.cts +222 -0
  111. package/dist/types-Bn8rC098.d.cts.map +1 -0
  112. package/dist/types-CPQlxauZ.d.mts +222 -0
  113. package/dist/types-CPQlxauZ.d.mts.map +1 -0
  114. package/dist/types.d.cts +2 -69
  115. package/dist/types.d.mts +2 -69
  116. package/dist/types.mjs +0 -1
  117. package/dist/utils/code-frames.cjs +2 -76
  118. package/dist/utils/code-frames.d.cts +2 -17
  119. package/dist/utils/code-frames.d.mts +2 -17
  120. package/dist/utils/code-frames.mjs +2 -76
  121. package/dist/utils/index.cjs +13 -12
  122. package/dist/utils/index.d.cts +5 -5
  123. package/dist/utils/index.d.mts +6 -5
  124. package/dist/utils/index.mjs +6 -5
  125. package/dist/utils/parse-error.cjs +2 -33
  126. package/dist/utils/parse-error.d.cts +2 -15
  127. package/dist/utils/parse-error.d.mts +2 -15
  128. package/dist/utils/parse-error.mjs +2 -33
  129. package/dist/utils/parse.cjs +3 -51
  130. package/dist/utils/parse.d.cts +2 -9
  131. package/dist/utils/parse.d.mts +2 -9
  132. package/dist/utils/parse.mjs +2 -51
  133. package/dist/utils/stringify.cjs +3 -67
  134. package/dist/utils/stringify.d.cts +2 -13
  135. package/dist/utils/stringify.d.mts +2 -13
  136. package/dist/utils/stringify.mjs +2 -67
  137. package/dist/utils/strip-comments.cjs +2 -85
  138. package/dist/utils/strip-comments.d.cts +2 -11
  139. package/dist/utils/strip-comments.d.mts +2 -11
  140. package/dist/utils/strip-comments.mjs +2 -86
  141. package/dist/utils-jN2UkvqB.cjs +0 -0
  142. package/dist/utils-mEkKIcgl.mjs +0 -0
  143. package/package.json +12 -3
  144. package/dist/_virtual/rolldown_runtime.cjs +0 -29
  145. package/dist/pointer/find-reference.d.cts.map +0 -1
  146. package/dist/pointer/find-reference.d.mts.map +0 -1
  147. package/dist/pointer/find-reference.mjs.map +0 -1
  148. package/dist/pointer/parse.d.cts.map +0 -1
  149. package/dist/pointer/parse.d.mts.map +0 -1
  150. package/dist/pointer/parse.mjs.map +0 -1
  151. package/dist/storm-json.d.cts.map +0 -1
  152. package/dist/storm-json.d.mts.map +0 -1
  153. package/dist/storm-json.mjs.map +0 -1
  154. package/dist/type-checks/src/get-object-tag.cjs +0 -15
  155. package/dist/type-checks/src/get-object-tag.mjs +0 -15
  156. package/dist/type-checks/src/get-object-tag.mjs.map +0 -1
  157. package/dist/type-checks/src/is-empty.cjs +0 -20
  158. package/dist/type-checks/src/is-empty.mjs +0 -21
  159. package/dist/type-checks/src/is-empty.mjs.map +0 -1
  160. package/dist/type-checks/src/is-non-null-object.cjs +0 -16
  161. package/dist/type-checks/src/is-non-null-object.mjs +0 -17
  162. package/dist/type-checks/src/is-non-null-object.mjs.map +0 -1
  163. package/dist/type-checks/src/is-null.cjs +0 -12
  164. package/dist/type-checks/src/is-null.mjs +0 -12
  165. package/dist/type-checks/src/is-null.mjs.map +0 -1
  166. package/dist/type-checks/src/is-number.cjs +0 -18
  167. package/dist/type-checks/src/is-number.mjs +0 -18
  168. package/dist/type-checks/src/is-number.mjs.map +0 -1
  169. package/dist/type-checks/src/is-object.cjs +0 -19
  170. package/dist/type-checks/src/is-object.mjs +0 -20
  171. package/dist/type-checks/src/is-object.mjs.map +0 -1
  172. package/dist/type-checks/src/is-plain-object.mjs.map +0 -1
  173. package/dist/type-checks/src/is-set-object.cjs +0 -19
  174. package/dist/type-checks/src/is-set-object.mjs +0 -20
  175. package/dist/type-checks/src/is-set-object.mjs.map +0 -1
  176. package/dist/type-checks/src/is-set.cjs +0 -19
  177. package/dist/type-checks/src/is-set.mjs +0 -20
  178. package/dist/type-checks/src/is-set.mjs.map +0 -1
  179. package/dist/type-checks/src/is-string.mjs.map +0 -1
  180. package/dist/type-checks/src/is-undefined.mjs.map +0 -1
  181. package/dist/types/src/base.cjs +0 -6
  182. package/dist/types/src/base.mjs +0 -6
  183. package/dist/types/src/base.mjs.map +0 -1
  184. package/dist/types/src/json.d.cts +0 -12
  185. package/dist/types/src/json.d.cts.map +0 -1
  186. package/dist/types/src/json.d.mts +0 -12
  187. package/dist/types/src/json.d.mts.map +0 -1
  188. package/dist/types.d.cts.map +0 -1
  189. package/dist/types.d.mts.map +0 -1
  190. package/dist/utils/code-frames.d.cts.map +0 -1
  191. package/dist/utils/code-frames.d.mts.map +0 -1
  192. package/dist/utils/code-frames.mjs.map +0 -1
  193. package/dist/utils/parse-error.d.cts.map +0 -1
  194. package/dist/utils/parse-error.d.mts.map +0 -1
  195. package/dist/utils/parse-error.mjs.map +0 -1
  196. package/dist/utils/parse.d.cts.map +0 -1
  197. package/dist/utils/parse.d.mts.map +0 -1
  198. package/dist/utils/parse.mjs.map +0 -1
  199. package/dist/utils/stringify.d.cts.map +0 -1
  200. package/dist/utils/stringify.d.mts.map +0 -1
  201. package/dist/utils/stringify.mjs.map +0 -1
  202. package/dist/utils/strip-comments.d.cts.map +0 -1
  203. package/dist/utils/strip-comments.d.mts.map +0 -1
  204. package/dist/utils/strip-comments.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,28 @@
2
2
 
3
3
  # Changelog for Stryke - JSON
4
4
 
5
+ ## [0.10.0](https://github.com/storm-software/stryke/releases/tag/json%400.10.0) (03/02/2026)
6
+
7
+ ### Miscellaneous
8
+
9
+ - **json:** Added `$defs` to JSON schema meta definition ([7808fbd0](https://github.com/storm-software/stryke/commit/7808fbd0))
10
+
11
+ ### Features
12
+
13
+ - **json:** Added `JsonSchema7` type defintions and helpers ([677e7c39](https://github.com/storm-software/stryke/commit/677e7c39))
14
+
15
+ ### Updated Dependencies
16
+
17
+ - Updated **type-checks** to **v0.5.27**
18
+ - Updated **types** to **v0.10.41**
19
+
20
+ ## [0.9.44](https://github.com/storm-software/stryke/releases/tag/json%400.9.44) (03/02/2026)
21
+
22
+ ### Updated Dependencies
23
+
24
+ - Updated **type-checks** to **v0.5.26**
25
+ - Updated **types** to **v0.10.40**
26
+
5
27
  ## [0.9.43](https://github.com/storm-software/stryke/releases/tag/json%400.9.43) (02/09/2026)
6
28
 
7
29
  ### 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-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,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-CrTAYYSE.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-frames-CrTAYYSE.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,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-DuBfTMu4.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-frames-DuBfTMu4.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,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-B8xshNXL.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-reference-B8xshNXL.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,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,64 @@
1
+ import { t as isSetObject } from "./is-set-object-C1Qnj1Q8.mjs";
2
+ import { t as isString } from "./is-string-CLiBUSKV.mjs";
3
+
4
+ //#region src/pointer/find-reference.ts
5
+ const { isArray } = Array;
6
+ /**
7
+ * Finds a target in document specified by JSON Pointer. Also returns the
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 (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 (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
+ export { isObjectReference as i, isArrayEnd as n, isArrayReference as r, find as t };
64
+ //# sourceMappingURL=find-reference-DMSYEaaI.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-reference-DMSYEaaI.mjs","names":["obj: Reference[\"obj\"]","key: Reference[\"key\"]"],"sources":["../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\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":";;;;AA8BA,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,86 @@
1
+ const require_is_set_object = require('./is-set-object-BmHip9em.cjs');
2
+ const require_is_string = require('./is-string-C2RK4Gjs.cjs');
3
+
4
+ //#region src/pointer/find-reference.ts
5
+ const { isArray } = Array;
6
+ /**
7
+ * Finds a target in document specified by JSON Pointer. Also returns the
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
+ Object.defineProperty(exports, 'find', {
64
+ enumerable: true,
65
+ get: function () {
66
+ return find;
67
+ }
68
+ });
69
+ Object.defineProperty(exports, 'isArrayEnd', {
70
+ enumerable: true,
71
+ get: function () {
72
+ return isArrayEnd;
73
+ }
74
+ });
75
+ Object.defineProperty(exports, 'isArrayReference', {
76
+ enumerable: true,
77
+ get: function () {
78
+ return isArrayReference;
79
+ }
80
+ });
81
+ Object.defineProperty(exports, 'isObjectReference', {
82
+ enumerable: true,
83
+ get: function () {
84
+ return isObjectReference;
85
+ }
86
+ });
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };
package/dist/index.cjs CHANGED
@@ -1,16 +1,39 @@
1
- const require_utils_strip_comments = require('./utils/strip-comments.cjs');
2
- const require_utils_parse = require('./utils/parse.cjs');
3
- const require_utils_code_frames = require('./utils/code-frames.cjs');
4
- const require_utils_parse_error = require('./utils/parse-error.cjs');
5
- const require_utils_stringify = require('./utils/stringify.cjs');
6
- const require_storm_json = require('./storm-json.cjs');
7
- require('./utils/index.cjs');
1
+ const require_storm_json = require('./storm-json-BD6WFbrI.cjs');
2
+ const require_find_reference = require('./find-reference-De5vBQV2.cjs');
3
+ const require_parse = require('./parse-Bp6kkcQ4.cjs');
4
+ require('./pointer-B3W_Sme3.cjs');
5
+ const require_schema = require('./schema-Dl018Aq4.cjs');
6
+ const require_strip_comments = require('./strip-comments-CmEG_smS.cjs');
7
+ const require_parse$1 = require('./parse-ByDxRup5.cjs');
8
+ const require_code_frames = require('./code-frames-BmUvlJ0w.cjs');
9
+ const require_parse_error = require('./parse-error-N7UE-HMh.cjs');
10
+ const require_stringify = require('./stringify-BehjrfhS.cjs');
11
+ require('./types.cjs');
12
+ require('./utils-jN2UkvqB.cjs');
8
13
 
9
14
  exports.StormJSON = require_storm_json.StormJSON;
10
- exports.codeFrameColumns = require_utils_code_frames.codeFrameColumns;
11
- exports.formatParseError = require_utils_parse_error.formatParseError;
12
- exports.invalidKeyChars = require_utils_stringify.invalidKeyChars;
13
- exports.parse = require_utils_parse.parse;
14
- exports.safeParse = require_utils_parse.safeParse;
15
- exports.stringify = require_utils_stringify.stringify;
16
- exports.stripComments = require_utils_strip_comments.stripComments;
15
+ exports.codeFrameColumns = require_code_frames.codeFrameColumns;
16
+ exports.escapePointerSegment = require_parse.escapePointerSegment;
17
+ exports.find = require_find_reference.find;
18
+ exports.formatJsonPointer = require_parse.formatJsonPointer;
19
+ exports.formatParseError = require_parse_error.formatParseError;
20
+ exports.invalidKeyChars = require_stringify.invalidKeyChars;
21
+ exports.isArrayEnd = require_find_reference.isArrayEnd;
22
+ exports.isArrayReference = require_find_reference.isArrayReference;
23
+ exports.isInteger = require_parse.isInteger;
24
+ exports.isJsonSchema7AllOfType = require_schema.isJsonSchema7AllOfType;
25
+ exports.isJsonSchema7ArrayType = require_schema.isJsonSchema7ArrayType;
26
+ exports.isJsonSchema7LiteralType = require_schema.isJsonSchema7LiteralType;
27
+ exports.isJsonSchema7ObjectType = require_schema.isJsonSchema7ObjectType;
28
+ exports.isJsonSchema7PrimitiveLiteralType = require_schema.isJsonSchema7PrimitiveLiteralType;
29
+ exports.isObjectReference = require_find_reference.isObjectReference;
30
+ exports.isRoot = require_parse.isRoot;
31
+ exports.isStandardJsonSchema = require_schema.isStandardJsonSchema;
32
+ exports.isValidIndex = require_parse.isValidIndex;
33
+ exports.parent = require_parse.parent;
34
+ exports.parse = require_parse$1.parse;
35
+ exports.parseJsonPointer = require_parse.parseJsonPointer;
36
+ exports.safeParse = require_parse$1.safeParse;
37
+ exports.stringify = require_stringify.stringify;
38
+ exports.stripComments = require_strip_comments.stripComments;
39
+ exports.unescapePointerSegment = require_parse.unescapePointerSegment;
package/dist/index.d.cts CHANGED
@@ -1,8 +1,11 @@
1
- import { Class, ClassInstance, ClassTypeAnnotation, CompositeTypeAnnotation, CustomTypeAnnotation, InnerNode, JsonArray, JsonObject, JsonParseOptions, JsonParserInterface, JsonParserResult, JsonSerializeOptions, JsonValue, Leaf, LeafTypeAnnotation, PrimitiveJsonValue, PrimitiveTypeAnnotation, SerializableJsonValue, SimpleTypeAnnotation, SymbolTypeAnnotation, Tree, TypeAnnotation, TypedArrayAnnotation } from "./types.cjs";
2
- import { StormJSON } from "./storm-json.cjs";
3
- import { codeFrameColumns } from "./utils/code-frames.cjs";
4
- import { Options, parse, safeParse } from "./utils/parse.cjs";
5
- import { formatParseError } from "./utils/parse-error.cjs";
6
- import { invalidKeyChars, stringify } from "./utils/stringify.cjs";
7
- import { stripComments } from "./utils/strip-comments.cjs";
8
- export { Class, ClassInstance, ClassTypeAnnotation, CompositeTypeAnnotation, CustomTypeAnnotation, InnerNode, JsonArray, JsonObject, JsonParseOptions, JsonParserInterface, JsonParserResult, JsonSerializeOptions, JsonValue, Leaf, LeafTypeAnnotation, Options, PrimitiveJsonValue, PrimitiveTypeAnnotation, SerializableJsonValue, SimpleTypeAnnotation, StormJSON, SymbolTypeAnnotation, Tree, TypeAnnotation, TypedArrayAnnotation, codeFrameColumns, formatParseError, invalidKeyChars, parse, safeParse, stringify, stripComments };
1
+ import { a as isArrayEnd, i as find, n as ObjectReference, o as isArrayReference, r as Reference, s as isObjectReference, t as ArrayReference } from "./find-reference-C-YleCds.cjs";
2
+ import { a as isValidIndex, c as unescapePointerSegment, i as isRoot, n as formatJsonPointer, o as parent, r as isInteger, s as parseJsonPointer, t as escapePointerSegment } from "./parse-DZfi3d96.cjs";
3
+ import { $ as TypeAnnotation, A as JsonSchema7PrimitiveLiteralType, B as JsonSchema7UndefinedType, C as JsonSchema7NativeEnumType, D as JsonSchema7NumberType, E as JsonSchema7NullableType, F as JsonSchema7SetType, G as Leaf, H as JsonSchema7UnknownType, I as JsonSchema7StringType, J as PrimitiveTypeAnnotation, K as LeafTypeAnnotation, L as JsonSchema7TupleType, M as JsonSchema7RecordPropertyNamesType, N as JsonSchema7RecordType, O as JsonSchema7ObjectType, P as JsonSchema7RefType, Q as Tree, R as JsonSchema7Type, S as JsonSchema7Meta, T as JsonSchema7NullType, U as JsonSerializeOptions, V as JsonSchema7UnionType, W as JsonValue, X as SimpleTypeAnnotation, Y as SerializableJsonValue, Z as SymbolTypeAnnotation, _ as JsonSchema7BooleanType, a as CustomTypeAnnotation, b as JsonSchema7LiteralType, c as JsonObject, d as JsonParserResult, et as TypedArrayAnnotation, f as JsonSchema7AllOfType, g as JsonSchema7BigintType, h as JsonSchema7ArrayType, i as CompositeTypeAnnotation, j as JsonSchema7PrimitiveUnionType, k as JsonSchema7Primitive, l as JsonParseOptions, m as JsonSchema7AnyType, n as ClassInstance, o as InnerNode, p as JsonSchema7AnyOfType, q as PrimitiveJsonValue, r as ClassTypeAnnotation, s as JsonArray, t as Class, u as JsonParserInterface, v as JsonSchema7DateType, w as JsonSchema7NeverType, x as JsonSchema7MapType, y as JsonSchema7EnumType, z as JsonSchema7TypeUnion } from "./types-Bn8rC098.cjs";
4
+ import { a as isJsonSchema7PrimitiveLiteralType, i as isJsonSchema7ObjectType, n as isJsonSchema7ArrayType, o as isStandardJsonSchema, r as isJsonSchema7LiteralType, t as isJsonSchema7AllOfType } from "./schema-BO1HCrxv.cjs";
5
+ import { t as StormJSON } from "./storm-json-DvIEWMEH.cjs";
6
+ import { t as codeFrameColumns } from "./code-frames-BUtrssZ5.cjs";
7
+ import { n as parse, r as safeParse, t as Options } from "./parse-BGlhbY16.cjs";
8
+ import { t as formatParseError } from "./parse-error-7K8s4vWf.cjs";
9
+ import { n as stringify, t as invalidKeyChars } from "./stringify-Bc8OkhIr.cjs";
10
+ import { t as stripComments } from "./strip-comments-Cz_Wc25t.cjs";
11
+ export { ArrayReference, Class, ClassInstance, ClassTypeAnnotation, CompositeTypeAnnotation, CustomTypeAnnotation, InnerNode, JsonArray, JsonObject, JsonParseOptions, JsonParserInterface, JsonParserResult, JsonSchema7AllOfType, JsonSchema7AnyOfType, JsonSchema7AnyType, JsonSchema7ArrayType, JsonSchema7BigintType, JsonSchema7BooleanType, JsonSchema7DateType, JsonSchema7EnumType, JsonSchema7LiteralType, JsonSchema7MapType, JsonSchema7Meta, JsonSchema7NativeEnumType, JsonSchema7NeverType, JsonSchema7NullType, JsonSchema7NullableType, JsonSchema7NumberType, JsonSchema7ObjectType, JsonSchema7Primitive, JsonSchema7PrimitiveLiteralType, JsonSchema7PrimitiveUnionType, JsonSchema7RecordPropertyNamesType, JsonSchema7RecordType, JsonSchema7RefType, JsonSchema7SetType, JsonSchema7StringType, JsonSchema7TupleType, JsonSchema7Type, JsonSchema7TypeUnion, JsonSchema7UndefinedType, JsonSchema7UnionType, JsonSchema7UnknownType, JsonSerializeOptions, JsonValue, Leaf, LeafTypeAnnotation, ObjectReference, Options, PrimitiveJsonValue, PrimitiveTypeAnnotation, Reference, SerializableJsonValue, SimpleTypeAnnotation, StormJSON, SymbolTypeAnnotation, Tree, TypeAnnotation, TypedArrayAnnotation, codeFrameColumns, escapePointerSegment, find, formatJsonPointer, formatParseError, invalidKeyChars, isArrayEnd, isArrayReference, isInteger, isJsonSchema7AllOfType, isJsonSchema7ArrayType, isJsonSchema7LiteralType, isJsonSchema7ObjectType, isJsonSchema7PrimitiveLiteralType, isObjectReference, isRoot, isStandardJsonSchema, isValidIndex, parent, parse, parseJsonPointer, safeParse, stringify, stripComments, unescapePointerSegment };