@stryke/fs 0.33.32 → 0.33.34

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 (190) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/_virtual/rolldown_runtime.cjs +29 -1
  3. package/dist/buffer.cjs +60 -1
  4. package/dist/buffer.mjs +56 -1
  5. package/dist/buffer.mjs.map +1 -1
  6. package/dist/chmod-x.cjs +93 -1
  7. package/dist/chmod-x.mjs +87 -1
  8. package/dist/chmod-x.mjs.map +1 -1
  9. package/dist/command-exists.cjs +102 -1
  10. package/dist/command-exists.mjs +100 -1
  11. package/dist/command-exists.mjs.map +1 -1
  12. package/dist/compress.cjs +29 -1
  13. package/dist/compress.mjs +28 -1
  14. package/dist/compress.mjs.map +1 -1
  15. package/dist/constants.mjs +1 -1
  16. package/dist/convert/src/array-buffer-to-string.cjs +19 -1
  17. package/dist/convert/src/array-buffer-to-string.mjs +18 -1
  18. package/dist/convert/src/array-buffer-to-string.mjs.map +1 -1
  19. package/dist/convert/src/to-array.cjs +15 -1
  20. package/dist/convert/src/to-array.mjs +14 -1
  21. package/dist/convert/src/to-array.mjs.map +1 -1
  22. package/dist/convert/src/uint8-array-to-string.cjs +15 -1
  23. package/dist/convert/src/uint8-array-to-string.mjs +15 -1
  24. package/dist/convert/src/uint8-array-to-string.mjs.map +1 -1
  25. package/dist/copy-file.cjs +87 -1
  26. package/dist/copy-file.mjs +83 -1
  27. package/dist/copy-file.mjs.map +1 -1
  28. package/dist/exists.cjs +27 -1
  29. package/dist/exists.mjs +25 -1
  30. package/dist/exists.mjs.map +1 -1
  31. package/dist/get-parent-path.cjs +35 -1
  32. package/dist/get-parent-path.mjs +34 -1
  33. package/dist/get-parent-path.mjs.map +1 -1
  34. package/dist/get-workspace-root.cjs +158 -1
  35. package/dist/get-workspace-root.mjs +150 -1
  36. package/dist/get-workspace-root.mjs.map +1 -1
  37. package/dist/helpers/src/get-unique.cjs +14 -1
  38. package/dist/helpers/src/get-unique.mjs +13 -1
  39. package/dist/helpers/src/get-unique.mjs.map +1 -1
  40. package/dist/helpers.cjs +83 -1
  41. package/dist/helpers.mjs +77 -1
  42. package/dist/helpers.mjs.map +1 -1
  43. package/dist/index.cjs +122 -1
  44. package/dist/index.mjs +25 -1
  45. package/dist/install.cjs +35 -1
  46. package/dist/install.mjs +33 -1
  47. package/dist/install.mjs.map +1 -1
  48. package/dist/is-file.cjs +51 -1
  49. package/dist/is-file.mjs +47 -1
  50. package/dist/is-file.mjs.map +1 -1
  51. package/dist/json/src/storm-json.cjs +117 -1
  52. package/dist/json/src/storm-json.mjs +115 -1
  53. package/dist/json/src/storm-json.mjs.map +1 -1
  54. package/dist/json/src/utils/code-frames.cjs +77 -3
  55. package/dist/json/src/utils/code-frames.mjs +76 -3
  56. package/dist/json/src/utils/code-frames.mjs.map +1 -1
  57. package/dist/json/src/utils/parse-error.cjs +34 -1
  58. package/dist/json/src/utils/parse-error.mjs +33 -1
  59. package/dist/json/src/utils/parse-error.mjs.map +1 -1
  60. package/dist/json/src/utils/parse.cjs +45 -1
  61. package/dist/json/src/utils/parse.mjs +45 -1
  62. package/dist/json/src/utils/parse.mjs.map +1 -1
  63. package/dist/json/src/utils/stringify.cjs +67 -1
  64. package/dist/json/src/utils/stringify.mjs +67 -1
  65. package/dist/json/src/utils/stringify.mjs.map +1 -1
  66. package/dist/json/src/utils/strip-comments.cjs +86 -4
  67. package/dist/json/src/utils/strip-comments.mjs +86 -4
  68. package/dist/json/src/utils/strip-comments.mjs.map +1 -1
  69. package/dist/json.cjs +74 -1
  70. package/dist/json.mjs +71 -1
  71. package/dist/json.mjs.map +1 -1
  72. package/dist/list-files.cjs +86 -1
  73. package/dist/list-files.mjs +79 -1
  74. package/dist/list-files.mjs.map +1 -1
  75. package/dist/package-fns.cjs +148 -1
  76. package/dist/package-fns.mjs +141 -1
  77. package/dist/package-fns.mjs.map +1 -1
  78. package/dist/path/src/append.cjs +57 -1
  79. package/dist/path/src/append.mjs +56 -1
  80. package/dist/path/src/append.mjs.map +1 -1
  81. package/dist/path/src/correct-path.cjs +138 -1
  82. package/dist/path/src/correct-path.mjs +134 -1
  83. package/dist/path/src/correct-path.mjs.map +1 -1
  84. package/dist/path/src/cwd.cjs +17 -1
  85. package/dist/path/src/cwd.mjs +16 -1
  86. package/dist/path/src/cwd.mjs.map +1 -1
  87. package/dist/path/src/file-path-fns.cjs +169 -1
  88. package/dist/path/src/file-path-fns.mjs +164 -1
  89. package/dist/path/src/file-path-fns.mjs.map +1 -1
  90. package/dist/path/src/is-parent-path.cjs +32 -1
  91. package/dist/path/src/is-parent-path.mjs +32 -1
  92. package/dist/path/src/is-parent-path.mjs.map +1 -1
  93. package/dist/path/src/is-root-dir.cjs +14 -1
  94. package/dist/path/src/is-root-dir.mjs +13 -1
  95. package/dist/path/src/is-root-dir.mjs.map +1 -1
  96. package/dist/path/src/is-type.cjs +68 -1
  97. package/dist/path/src/is-type.mjs +66 -1
  98. package/dist/path/src/is-type.mjs.map +1 -1
  99. package/dist/path/src/join-paths.cjs +106 -1
  100. package/dist/path/src/join-paths.mjs +106 -1
  101. package/dist/path/src/join-paths.mjs.map +1 -1
  102. package/dist/path/src/regex.cjs +18 -1
  103. package/dist/path/src/regex.mjs +11 -1
  104. package/dist/path/src/regex.mjs.map +1 -1
  105. package/dist/path/src/replace.cjs +24 -1
  106. package/dist/path/src/replace.mjs +24 -1
  107. package/dist/path/src/replace.mjs.map +1 -1
  108. package/dist/path/src/resolve-parent-path.cjs +18 -1
  109. package/dist/path/src/resolve-parent-path.mjs +18 -1
  110. package/dist/path/src/resolve-parent-path.mjs.map +1 -1
  111. package/dist/path/src/slash.cjs +15 -1
  112. package/dist/path/src/slash.mjs +14 -1
  113. package/dist/path/src/slash.mjs.map +1 -1
  114. package/dist/read-file.cjs +47 -1
  115. package/dist/read-file.mjs +43 -1
  116. package/dist/read-file.mjs.map +1 -1
  117. package/dist/registry.cjs +142 -1
  118. package/dist/registry.mjs +137 -1
  119. package/dist/registry.mjs.map +1 -1
  120. package/dist/remove-file.cjs +27 -1
  121. package/dist/remove-file.mjs +25 -1
  122. package/dist/remove-file.mjs.map +1 -1
  123. package/dist/resolve.cjs +228 -3
  124. package/dist/resolve.mjs +217 -3
  125. package/dist/resolve.mjs.map +1 -1
  126. package/dist/semver-fns.cjs +129 -1
  127. package/dist/semver-fns.mjs +119 -1
  128. package/dist/semver-fns.mjs.map +1 -1
  129. package/dist/string-format/src/package.cjs +92 -1
  130. package/dist/string-format/src/package.mjs +91 -1
  131. package/dist/string-format/src/package.mjs.map +1 -1
  132. package/dist/toml.cjs +66 -3
  133. package/dist/toml.mjs +61 -3
  134. package/dist/toml.mjs.map +1 -1
  135. package/dist/tsconfig.cjs +37 -1
  136. package/dist/tsconfig.mjs +35 -1
  137. package/dist/tsconfig.mjs.map +1 -1
  138. package/dist/type-checks/src/get-object-tag.cjs +15 -1
  139. package/dist/type-checks/src/get-object-tag.mjs +14 -1
  140. package/dist/type-checks/src/get-object-tag.mjs.map +1 -1
  141. package/dist/type-checks/src/index.cjs +14 -1
  142. package/dist/type-checks/src/index.mjs +16 -1
  143. package/dist/type-checks/src/is-buffer.cjs +12 -1
  144. package/dist/type-checks/src/is-buffer.mjs +11 -1
  145. package/dist/type-checks/src/is-buffer.mjs.map +1 -1
  146. package/dist/type-checks/src/is-collection.cjs +1 -1
  147. package/dist/type-checks/src/is-collection.mjs +3 -1
  148. package/dist/type-checks/src/is-empty.cjs +20 -1
  149. package/dist/type-checks/src/is-empty.mjs +20 -1
  150. package/dist/type-checks/src/is-empty.mjs.map +1 -1
  151. package/dist/type-checks/src/is-error.cjs +29 -1
  152. package/dist/type-checks/src/is-error.mjs +29 -1
  153. package/dist/type-checks/src/is-error.mjs.map +1 -1
  154. package/dist/type-checks/src/is-null.cjs +12 -1
  155. package/dist/type-checks/src/is-null.mjs +11 -1
  156. package/dist/type-checks/src/is-null.mjs.map +1 -1
  157. package/dist/type-checks/src/is-number.cjs +18 -1
  158. package/dist/type-checks/src/is-number.mjs +17 -1
  159. package/dist/type-checks/src/is-number.mjs.map +1 -1
  160. package/dist/type-checks/src/is-object.cjs +19 -1
  161. package/dist/type-checks/src/is-object.mjs +19 -1
  162. package/dist/type-checks/src/is-object.mjs.map +1 -1
  163. package/dist/type-checks/src/is-plain-object.cjs +64 -1
  164. package/dist/type-checks/src/is-plain-object.mjs +63 -1
  165. package/dist/type-checks/src/is-plain-object.mjs.map +1 -1
  166. package/dist/type-checks/src/is-set-string.cjs +20 -1
  167. package/dist/type-checks/src/is-set-string.mjs +20 -1
  168. package/dist/type-checks/src/is-set-string.mjs.map +1 -1
  169. package/dist/type-checks/src/is-set.cjs +19 -1
  170. package/dist/type-checks/src/is-set.mjs +19 -1
  171. package/dist/type-checks/src/is-set.mjs.map +1 -1
  172. package/dist/type-checks/src/is-string.cjs +12 -1
  173. package/dist/type-checks/src/is-string.mjs +11 -1
  174. package/dist/type-checks/src/is-string.mjs.map +1 -1
  175. package/dist/type-checks/src/is-undefined.cjs +8 -1
  176. package/dist/type-checks/src/is-undefined.mjs +7 -1
  177. package/dist/type-checks/src/is-undefined.mjs.map +1 -1
  178. package/dist/type-checks/src/type-detect.cjs +15 -1
  179. package/dist/type-checks/src/type-detect.mjs +16 -1
  180. package/dist/type-checks/src/type-detect.mjs.map +1 -1
  181. package/dist/types/src/base.cjs +6 -1
  182. package/dist/types/src/base.mjs +5 -1
  183. package/dist/types/src/base.mjs.map +1 -1
  184. package/dist/write-file.cjs +40 -1
  185. package/dist/write-file.mjs +38 -1
  186. package/dist/write-file.mjs.map +1 -1
  187. package/dist/yaml.cjs +29 -1
  188. package/dist/yaml.mjs +27 -1
  189. package/dist/yaml.mjs.map +1 -1
  190. package/package.json +6 -6
@@ -1,2 +1,116 @@
1
- import{isString as e}from"../../type-checks/src/is-string.mjs";import{isObject as t}from"../../type-checks/src/is-object.mjs";import{parse as n}from"./utils/parse.mjs";import{formatParseError as r}from"./utils/parse-error.mjs";import{stringify as i}from"./utils/stringify.mjs";import{Buffer as a}from"node:buffer";import{parse as o}from"jsonc-parser";import s from"superjson";var c=class a extends s{static#e;static get instance(){return a.#e||=new a,a.#e}static deserialize(e){return a.instance.deserialize(e)}static serialize(e){return a.instance.serialize(e)}static parse(e){return n(e)}static stringify(e,t){let n=a.instance.customTransformerRegistry.findApplicable(e),r=e;return n&&n.isApplicable(e)&&(r=n.serialize(r)),i(r)}static parseJson(e,t){try{if(t?.expectComments===!1)return a.instance.parse(e)}catch{}let n=[],i=o(e,n,{allowTrailingComma:!0,...t});if(n.length>0&&n[0])throw Error(r(e,n[0]));return i}static register(e,t,n,r){a.instance.registerCustom({isApplicable:r,serialize:t,deserialize:n},e)}static registerClass(n,r){a.instance.registerClass(n,{identifier:e(r)?r:r?.identifier||n.name,allowProps:r&&t(r)&&r?.allowProps&&Array.isArray(r.allowProps)?r.allowProps:[`__typename`]})}constructor(){super({dedupe:!0})}};c.instance.registerCustom({isApplicable:e=>a.isBuffer(e),serialize:e=>e.toString(`base64`),deserialize:e=>a.from(e,`base64`)},`Bytes`);export{c as StormJSON};
1
+ import { isString } from "../../type-checks/src/is-string.mjs";
2
+ import { isObject } from "../../type-checks/src/is-object.mjs";
3
+ import { parse as parse$1 } from "./utils/parse.mjs";
4
+ import { formatParseError } from "./utils/parse-error.mjs";
5
+ import { stringify } from "./utils/stringify.mjs";
6
+ import { Buffer } from "node:buffer";
7
+ import { parse } from "jsonc-parser";
8
+ import SuperJSON from "superjson";
9
+
10
+ //#region ../json/src/storm-json.ts
11
+ /**
12
+ * A static JSON parser class used by Storm Software to serialize and deserialize JSON data
13
+ *
14
+ * @remarks
15
+ * This class uses the [SuperJSON](https://github.com/blitz-js/superjson) library under the hood.
16
+ */
17
+ var StormJSON = class StormJSON extends SuperJSON {
18
+ static #instance;
19
+ static get instance() {
20
+ if (!StormJSON.#instance) StormJSON.#instance = new StormJSON();
21
+ return StormJSON.#instance;
22
+ }
23
+ /**
24
+ * Deserialize the given value with superjson using the given metadata
25
+ */
26
+ static deserialize(payload) {
27
+ return StormJSON.instance.deserialize(payload);
28
+ }
29
+ /**
30
+ * Serialize the given value with superjson
31
+ */
32
+ static serialize(object) {
33
+ return StormJSON.instance.serialize(object);
34
+ }
35
+ /**
36
+ * Parse the given string value with superjson using the given metadata
37
+ *
38
+ * @param value - The string value to parse
39
+ * @returns The parsed data
40
+ */
41
+ static parse(value) {
42
+ return parse$1(value);
43
+ }
44
+ /**
45
+ * Serializes the given data to a JSON string.
46
+ * By default the JSON string is formatted with a 2 space indentation to be easy readable.
47
+ *
48
+ * @param value - Object which should be serialized to JSON
49
+ * @param _options - JSON serialize options
50
+ * @returns the formatted JSON representation of the object
51
+ */
52
+ static stringify(value, _options) {
53
+ const customTransformer = StormJSON.instance.customTransformerRegistry.findApplicable(value);
54
+ let result = value;
55
+ if (customTransformer && customTransformer.isApplicable(value)) result = customTransformer.serialize(result);
56
+ return stringify(result);
57
+ }
58
+ /**
59
+ * Parses the given JSON string and returns the object the JSON content represents.
60
+ * By default javascript-style comments and trailing commas are allowed.
61
+ *
62
+ * @param strData - JSON content as string
63
+ * @param options - JSON parse options
64
+ * @returns Object the JSON content represents
65
+ */
66
+ static parseJson(strData, options) {
67
+ try {
68
+ if (options?.expectComments === false) return StormJSON.instance.parse(strData);
69
+ } catch {}
70
+ const errors = [];
71
+ const result = parse(strData, errors, {
72
+ allowTrailingComma: true,
73
+ ...options
74
+ });
75
+ if (errors.length > 0 && errors[0]) throw new Error(formatParseError(strData, errors[0]));
76
+ return result;
77
+ }
78
+ /**
79
+ * Register a custom schema with superjson
80
+ *
81
+ * @param name - The name of the schema
82
+ * @param serialize - The function to serialize the schema
83
+ * @param deserialize - The function to deserialize the schema
84
+ * @param isApplicable - The function to check if the schema is applicable
85
+ */
86
+ static register(name, serialize, deserialize, isApplicable) {
87
+ StormJSON.instance.registerCustom({
88
+ isApplicable,
89
+ serialize,
90
+ deserialize
91
+ }, name);
92
+ }
93
+ /**
94
+ * Register a class with superjson
95
+ *
96
+ * @param classConstructor - The class constructor to register
97
+ */
98
+ static registerClass(classConstructor, options) {
99
+ StormJSON.instance.registerClass(classConstructor, {
100
+ identifier: isString(options) ? options : options?.identifier || classConstructor.name,
101
+ allowProps: options && isObject(options) && options?.allowProps && Array.isArray(options.allowProps) ? options.allowProps : ["__typename"]
102
+ });
103
+ }
104
+ constructor() {
105
+ super({ dedupe: true });
106
+ }
107
+ };
108
+ StormJSON.instance.registerCustom({
109
+ isApplicable: (v) => Buffer.isBuffer(v),
110
+ serialize: (v) => v.toString("base64"),
111
+ deserialize: (v) => Buffer.from(v, "base64")
112
+ }, "Bytes");
113
+
114
+ //#endregion
115
+ export { StormJSON };
2
116
  //# sourceMappingURL=storm-json.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"storm-json.mjs","names":["#instance","parseValue","stringifyValue","errors: ParseError[]"],"sources":["../../../../json/src/storm-json.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { ParseError } from \"jsonc-parser\";\nimport type {\n Class,\n JsonParseOptions,\n JsonParserResult,\n JsonSerializeOptions,\n JsonValue\n} from \"./types\";\n// import { Decimal } from \"decimal.js\";\nimport { isObject } from \"@stryke/type-checks/is-object\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport { parse } from \"jsonc-parser\";\nimport { Buffer } from \"node:buffer\";\nimport SuperJSON from \"superjson\";\nimport { parse as parseValue } from \"./utils/parse\";\nimport { formatParseError } from \"./utils/parse-error\";\nimport { stringify as stringifyValue } from \"./utils/stringify\";\n\n/**\n * A static JSON parser class used by Storm Software to serialize and deserialize JSON data\n *\n * @remarks\n * This class uses the [SuperJSON](https://github.com/blitz-js/superjson) library under the hood.\n */\nexport class StormJSON extends SuperJSON {\n static #instance: StormJSON;\n\n public static get instance(): StormJSON {\n if (!StormJSON.#instance) {\n StormJSON.#instance = new StormJSON();\n }\n\n return StormJSON.#instance;\n }\n\n /**\n * Deserialize the given value with superjson using the given metadata\n */\n public static override deserialize<TData = unknown>(\n payload: JsonParserResult\n ): TData {\n return StormJSON.instance.deserialize(payload);\n }\n\n /**\n * Serialize the given value with superjson\n */\n public static override serialize(object: JsonValue): JsonParserResult {\n return StormJSON.instance.serialize(object);\n }\n\n /**\n * Parse the given string value with superjson using the given metadata\n *\n * @param value - The string value to parse\n * @returns The parsed data\n */\n public static override parse<TData = unknown>(value: string): TData {\n return parseValue(value);\n }\n\n /**\n * Serializes the given data to a JSON string.\n * By default the JSON string is formatted with a 2 space indentation to be easy readable.\n *\n * @param value - Object which should be serialized to JSON\n * @param _options - JSON serialize options\n * @returns the formatted JSON representation of the object\n */\n public static override stringify<T>(\n value: T,\n _options?: JsonSerializeOptions\n ): string {\n const customTransformer =\n StormJSON.instance.customTransformerRegistry.findApplicable(value);\n\n let result = value;\n if (customTransformer && customTransformer.isApplicable(value)) {\n result = customTransformer.serialize(result) as T;\n }\n\n return stringifyValue(result);\n }\n\n /**\n * Parses the given JSON string and returns the object the JSON content represents.\n * By default javascript-style comments and trailing commas are allowed.\n *\n * @param strData - JSON content as string\n * @param options - JSON parse options\n * @returns Object the JSON content represents\n */\n public static parseJson<TData = unknown>(\n strData: string,\n options?: JsonParseOptions\n ): TData {\n try {\n if (options?.expectComments === false) {\n return StormJSON.instance.parse(strData);\n }\n } catch {\n // Do nothing\n }\n\n const errors: ParseError[] = [];\n const opts = {\n allowTrailingComma: true,\n ...options\n };\n const result = parse(strData, errors, opts) as TData;\n\n if (errors.length > 0 && errors[0]) {\n throw new Error(formatParseError(strData, errors[0]));\n }\n\n return result;\n }\n\n /**\n * Register a custom schema with superjson\n *\n * @param name - The name of the schema\n * @param serialize - The function to serialize the schema\n * @param deserialize - The function to deserialize the schema\n * @param isApplicable - The function to check if the schema is applicable\n */\n public static register<\n TData = any,\n TJsonObject extends JsonValue = JsonValue\n >(\n name: string,\n serialize: (data: TData) => TJsonObject,\n deserialize: (json: TJsonObject) => TData,\n isApplicable: (data: any) => data is TData\n ) {\n StormJSON.instance.registerCustom<TData, TJsonObject>(\n {\n isApplicable,\n serialize,\n deserialize\n },\n name\n );\n }\n\n /**\n * Register a class with superjson\n *\n * @param classConstructor - The class constructor to register\n */\n public static override registerClass(\n classConstructor: Class,\n options?: { identifier?: string; allowProps?: string[] } | string\n ) {\n StormJSON.instance.registerClass(classConstructor, {\n identifier: isString(options)\n ? options\n : options?.identifier || classConstructor.name,\n allowProps:\n options &&\n isObject(options) &&\n options?.allowProps &&\n Array.isArray(options.allowProps)\n ? options.allowProps\n : [\"__typename\"]\n });\n }\n\n private constructor() {\n super({ dedupe: true });\n }\n}\n\nStormJSON.instance.registerCustom<Buffer, string>(\n {\n isApplicable: (v): v is Buffer => Buffer.isBuffer(v),\n serialize: v => v.toString(\"base64\"),\n deserialize: v => Buffer.from(v, \"base64\")\n },\n \"Bytes\"\n);\n"],"mappings":"wXA0CA,IAAa,EAAb,MAAa,UAAkB,CAAU,CACvC,OAAA,EAEA,WAAkB,UAAsB,CAKtC,MAJA,CACE,GAAA,IAAsB,IAAI,EAGrB,GAAA,EAMT,OAAuB,YACrB,EACO,CACP,OAAO,EAAU,SAAS,YAAY,EAAQ,CAMhD,OAAuB,UAAU,EAAqC,CACpE,OAAO,EAAU,SAAS,UAAU,EAAO,CAS7C,OAAuB,MAAuB,EAAsB,CAClE,OAAOC,EAAW,EAAM,CAW1B,OAAuB,UACrB,EACA,EACQ,CACR,IAAM,EACJ,EAAU,SAAS,0BAA0B,eAAe,EAAM,CAEhE,EAAS,EAKb,OAJI,GAAqB,EAAkB,aAAa,EAAM,GAC5D,EAAS,EAAkB,UAAU,EAAO,EAGvCC,EAAe,EAAO,CAW/B,OAAc,UACZ,EACA,EACO,CACP,GAAI,CACF,GAAI,GAAS,iBAAmB,GAC9B,OAAO,EAAU,SAAS,MAAM,EAAQ,MAEpC,EAIR,IAAMC,EAAuB,EAAE,CAKzB,EAAS,EAAM,EAAS,EAJjB,CACX,mBAAoB,GACpB,GAAG,EACJ,CAC0C,CAE3C,GAAI,EAAO,OAAS,GAAK,EAAO,GAC9B,MAAU,MAAM,EAAiB,EAAS,EAAO,GAAG,CAAC,CAGvD,OAAO,EAWT,OAAc,SAIZ,EACA,EACA,EACA,EACA,CACA,EAAU,SAAS,eACjB,CACE,eACA,YACA,cACD,CACD,EACD,CAQH,OAAuB,cACrB,EACA,EACA,CACA,EAAU,SAAS,cAAc,EAAkB,CACjD,WAAY,EAAS,EAAQ,CACzB,EACA,GAAS,YAAc,EAAiB,KAC5C,WACE,GACA,EAAS,EAAQ,EACjB,GAAS,YACT,MAAM,QAAQ,EAAQ,WAAW,CAC7B,EAAQ,WACR,CAAC,aAAa,CACrB,CAAC,CAGJ,aAAsB,CACpB,MAAM,CAAE,OAAQ,GAAM,CAAC,GAI3B,EAAU,SAAS,eACjB,CACE,aAAe,GAAmB,EAAO,SAAS,EAAE,CACpD,UAAW,GAAK,EAAE,SAAS,SAAS,CACpC,YAAa,GAAK,EAAO,KAAK,EAAG,SAAS,CAC3C,CACD,QACD"}
1
+ {"version":3,"file":"storm-json.mjs","names":["#instance","parseValue","stringifyValue","errors: ParseError[]"],"sources":["../../../../json/src/storm-json.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { ParseError } from \"jsonc-parser\";\nimport type {\n Class,\n JsonParseOptions,\n JsonParserResult,\n JsonSerializeOptions,\n JsonValue\n} from \"./types\";\n// import { Decimal } from \"decimal.js\";\nimport { isObject } from \"@stryke/type-checks/is-object\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport { parse } from \"jsonc-parser\";\nimport { Buffer } from \"node:buffer\";\nimport SuperJSON from \"superjson\";\nimport { parse as parseValue } from \"./utils/parse\";\nimport { formatParseError } from \"./utils/parse-error\";\nimport { stringify as stringifyValue } from \"./utils/stringify\";\n\n/**\n * A static JSON parser class used by Storm Software to serialize and deserialize JSON data\n *\n * @remarks\n * This class uses the [SuperJSON](https://github.com/blitz-js/superjson) library under the hood.\n */\nexport class StormJSON extends SuperJSON {\n static #instance: StormJSON;\n\n public static get instance(): StormJSON {\n if (!StormJSON.#instance) {\n StormJSON.#instance = new StormJSON();\n }\n\n return StormJSON.#instance;\n }\n\n /**\n * Deserialize the given value with superjson using the given metadata\n */\n public static override deserialize<TData = unknown>(\n payload: JsonParserResult\n ): TData {\n return StormJSON.instance.deserialize(payload);\n }\n\n /**\n * Serialize the given value with superjson\n */\n public static override serialize(object: JsonValue): JsonParserResult {\n return StormJSON.instance.serialize(object);\n }\n\n /**\n * Parse the given string value with superjson using the given metadata\n *\n * @param value - The string value to parse\n * @returns The parsed data\n */\n public static override parse<TData = unknown>(value: string): TData {\n return parseValue(value);\n }\n\n /**\n * Serializes the given data to a JSON string.\n * By default the JSON string is formatted with a 2 space indentation to be easy readable.\n *\n * @param value - Object which should be serialized to JSON\n * @param _options - JSON serialize options\n * @returns the formatted JSON representation of the object\n */\n public static override stringify<T>(\n value: T,\n _options?: JsonSerializeOptions\n ): string {\n const customTransformer =\n StormJSON.instance.customTransformerRegistry.findApplicable(value);\n\n let result = value;\n if (customTransformer && customTransformer.isApplicable(value)) {\n result = customTransformer.serialize(result) as T;\n }\n\n return stringifyValue(result);\n }\n\n /**\n * Parses the given JSON string and returns the object the JSON content represents.\n * By default javascript-style comments and trailing commas are allowed.\n *\n * @param strData - JSON content as string\n * @param options - JSON parse options\n * @returns Object the JSON content represents\n */\n public static parseJson<TData = unknown>(\n strData: string,\n options?: JsonParseOptions\n ): TData {\n try {\n if (options?.expectComments === false) {\n return StormJSON.instance.parse(strData);\n }\n } catch {\n // Do nothing\n }\n\n const errors: ParseError[] = [];\n const opts = {\n allowTrailingComma: true,\n ...options\n };\n const result = parse(strData, errors, opts) as TData;\n\n if (errors.length > 0 && errors[0]) {\n throw new Error(formatParseError(strData, errors[0]));\n }\n\n return result;\n }\n\n /**\n * Register a custom schema with superjson\n *\n * @param name - The name of the schema\n * @param serialize - The function to serialize the schema\n * @param deserialize - The function to deserialize the schema\n * @param isApplicable - The function to check if the schema is applicable\n */\n public static register<\n TData = any,\n TJsonObject extends JsonValue = JsonValue\n >(\n name: string,\n serialize: (data: TData) => TJsonObject,\n deserialize: (json: TJsonObject) => TData,\n isApplicable: (data: any) => data is TData\n ) {\n StormJSON.instance.registerCustom<TData, TJsonObject>(\n {\n isApplicable,\n serialize,\n deserialize\n },\n name\n );\n }\n\n /**\n * Register a class with superjson\n *\n * @param classConstructor - The class constructor to register\n */\n public static override registerClass(\n classConstructor: Class,\n options?: { identifier?: string; allowProps?: string[] } | string\n ) {\n StormJSON.instance.registerClass(classConstructor, {\n identifier: isString(options)\n ? options\n : options?.identifier || classConstructor.name,\n allowProps:\n options &&\n isObject(options) &&\n options?.allowProps &&\n Array.isArray(options.allowProps)\n ? options.allowProps\n : [\"__typename\"]\n });\n }\n\n private constructor() {\n super({ dedupe: true });\n }\n}\n\nStormJSON.instance.registerCustom<Buffer, string>(\n {\n isApplicable: (v): v is Buffer => Buffer.isBuffer(v),\n serialize: v => v.toString(\"base64\"),\n deserialize: v => Buffer.from(v, \"base64\")\n },\n \"Bytes\"\n);\n"],"mappings":";;;;;;;;;;;;;;;;AA0CA,IAAa,YAAb,MAAa,kBAAkB,UAAU;CACvC,QAAOA;CAEP,WAAkB,WAAsB;AACtC,MAAI,CAAC,WAAUA,SACb,YAAUA,WAAY,IAAI,WAAW;AAGvC,SAAO,WAAUA;;;;;CAMnB,OAAuB,YACrB,SACO;AACP,SAAO,UAAU,SAAS,YAAY,QAAQ;;;;;CAMhD,OAAuB,UAAU,QAAqC;AACpE,SAAO,UAAU,SAAS,UAAU,OAAO;;;;;;;;CAS7C,OAAuB,MAAuB,OAAsB;AAClE,SAAOC,QAAW,MAAM;;;;;;;;;;CAW1B,OAAuB,UACrB,OACA,UACQ;EACR,MAAM,oBACJ,UAAU,SAAS,0BAA0B,eAAe,MAAM;EAEpE,IAAI,SAAS;AACb,MAAI,qBAAqB,kBAAkB,aAAa,MAAM,CAC5D,UAAS,kBAAkB,UAAU,OAAO;AAG9C,SAAOC,UAAe,OAAO;;;;;;;;;;CAW/B,OAAc,UACZ,SACA,SACO;AACP,MAAI;AACF,OAAI,SAAS,mBAAmB,MAC9B,QAAO,UAAU,SAAS,MAAM,QAAQ;UAEpC;EAIR,MAAMC,SAAuB,EAAE;EAK/B,MAAM,SAAS,MAAM,SAAS,QAJjB;GACX,oBAAoB;GACpB,GAAG;GACJ,CAC0C;AAE3C,MAAI,OAAO,SAAS,KAAK,OAAO,GAC9B,OAAM,IAAI,MAAM,iBAAiB,SAAS,OAAO,GAAG,CAAC;AAGvD,SAAO;;;;;;;;;;CAWT,OAAc,SAIZ,MACA,WACA,aACA,cACA;AACA,YAAU,SAAS,eACjB;GACE;GACA;GACA;GACD,EACD,KACD;;;;;;;CAQH,OAAuB,cACrB,kBACA,SACA;AACA,YAAU,SAAS,cAAc,kBAAkB;GACjD,YAAY,SAAS,QAAQ,GACzB,UACA,SAAS,cAAc,iBAAiB;GAC5C,YACE,WACA,SAAS,QAAQ,IACjB,SAAS,cACT,MAAM,QAAQ,QAAQ,WAAW,GAC7B,QAAQ,aACR,CAAC,aAAa;GACrB,CAAC;;CAGJ,AAAQ,cAAc;AACpB,QAAM,EAAE,QAAQ,MAAM,CAAC;;;AAI3B,UAAU,SAAS,eACjB;CACE,eAAe,MAAmB,OAAO,SAAS,EAAE;CACpD,YAAW,MAAK,EAAE,SAAS,SAAS;CACpC,cAAa,MAAK,OAAO,KAAK,GAAG,SAAS;CAC3C,EACD,QACD"}
@@ -1,3 +1,77 @@
1
- const e=/\r\n|[\n\r\u2028\u2029]/;function t(e,t,n={}){let r={column:0,line:-1,...e.start},i={...r,...e.end},{linesAbove:a=2,linesBelow:o=3}=n||{},s=r.line,c=r.column,l=i.line,u=i.column,d=Math.max(s-(a+1),0),f=Math.min(t.length,l+o);s===-1&&(d=0),l===-1&&(f=t.length);let p=l-s,m={};if(p)for(let e=0;e<=p;e++){let n=e+s;c?e===0?m[n]=[c,(t[n-1]?.length??0)-c+1]:e===p?m[n]=[0,u]:m[n]=[0,t[n-e]?.length??0]:m[n]=!0}else c===u?m[s]=c?[c,0]:!0:m[s]=[c,u-c];return{start:d,end:f,markerLines:m}}function n(n,r,i={}){let{start:a,end:o,markerLines:s}=t(r,n.split(e),i),c=String(o).length;return(i.highlight?i.highlight(n):n).split(e).slice(a,o).map((e,t)=>{let n=a+1+t,r=` ${` ${n}`.slice(-c)} | `,i=!!(s[n]??!1);if(i){let t=``;if(Array.isArray(i)){let n=e.slice(0,Math.max(i[0]-1,0)).replace(/[^\t]/g,` `),a=i[1]||1;t=[`
2
- `,r.replace(/\d/g,` `),n,`^`.repeat(a)].join(``)}return[`>`,r,e,t].join(``)}return` ${r}${e}`}).join(`
3
- `)}exports.codeFrameColumns=n;
1
+
2
+ //#region ../json/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
+ exports.codeFrameColumns = codeFrameColumns;
@@ -1,4 +1,77 @@
1
- const e=/\r\n|[\n\r\u2028\u2029]/;function t(e,t,n={}){let r={column:0,line:-1,...e.start},i={...r,...e.end},{linesAbove:a=2,linesBelow:o=3}=n||{},s=r.line,c=r.column,l=i.line,u=i.column,d=Math.max(s-(a+1),0),f=Math.min(t.length,l+o);s===-1&&(d=0),l===-1&&(f=t.length);let p=l-s,m={};if(p)for(let e=0;e<=p;e++){let n=e+s;c?e===0?m[n]=[c,(t[n-1]?.length??0)-c+1]:e===p?m[n]=[0,u]:m[n]=[0,t[n-e]?.length??0]:m[n]=!0}else c===u?m[s]=c?[c,0]:!0:m[s]=[c,u-c];return{start:d,end:f,markerLines:m}}function n(n,r,i={}){let{start:a,end:o,markerLines:s}=t(r,n.split(e),i),c=String(o).length;return(i.highlight?i.highlight(n):n).split(e).slice(a,o).map((e,t)=>{let n=a+1+t,r=` ${` ${n}`.slice(-c)} | `,i=!!(s[n]??!1);if(i){let t=``;if(Array.isArray(i)){let n=e.slice(0,Math.max(i[0]-1,0)).replace(/[^\t]/g,` `),a=i[1]||1;t=[`
2
- `,r.replace(/\d/g,` `),n,`^`.repeat(a)].join(``)}return[`>`,r,e,t].join(``)}return` ${r}${e}`}).join(`
3
- `)}export{n as codeFrameColumns};
1
+ //#region ../json/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 };
4
77
  //# sourceMappingURL=code-frames.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"code-frames.mjs","names":["startLoc: Location","endLoc: Location"],"sources":["../../../../../json/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,EAAU,0BAKhB,SAAS,EACP,EACA,EACA,EAAqD,EAAE,CAKvD,CACA,IAAMA,EAAqB,CACzB,OAAQ,EACR,KAAM,GACN,GAAG,EAAI,MACR,CACKC,EAAmB,CACvB,GAAG,EACH,GAAG,EAAI,IACR,CACK,CAAE,aAAa,EAAG,aAAa,GAAM,GAAQ,EAAE,CAC/C,EAAY,EAAS,KACrB,EAAc,EAAS,OACvB,EAAU,EAAO,KACjB,EAAY,EAAO,OAErB,EAAQ,KAAK,IAAI,GAAa,EAAa,GAAI,EAAE,CACjD,EAAM,KAAK,IAAI,EAAO,OAAQ,EAAU,EAAW,CAEnD,IAAc,KAChB,EAAQ,GAGN,IAAY,KACd,EAAM,EAAO,QAGf,IAAM,EAAW,EAAU,EACrB,EAAc,EAAE,CAEtB,GAAI,EACF,IAAK,IAAI,EAAI,EAAG,GAAK,EAAU,IAAK,CAClC,IAAM,EAAa,EAAI,EAElB,EAEM,IAAM,EAGf,EAAY,GAAc,CAAC,GAFN,EAAO,EAAa,IAAI,QAAU,GAEA,EAAc,EAAE,CAC9D,IAAM,EACf,EAAY,GAAc,CAAC,EAAG,EAAU,CAIxC,EAAY,GAAc,CAAC,EAFN,EAAO,EAAa,IAAI,QAAU,EAEZ,CAV3C,EAAY,GAAc,QAarB,IAAgB,EACzB,EAAY,GAAa,EAAc,CAAC,EAAa,EAAE,CAAG,GAE1D,EAAY,GAAa,CAAC,EAAa,EAAY,EAAY,CAGjE,MAAO,CACL,QACA,MACA,cACD,CAGH,SAAgB,EACd,EACA,EACA,EAII,EAAE,CACE,CAER,GAAM,CAAE,QAAO,MAAK,eAAgB,EAAe,EADrC,EAAS,MAAM,EAAQ,CAC0B,EAAK,CAE9D,EAAiB,OAAO,EAAI,CAAC,OAgCnC,OA/ByB,EAAK,UAAY,EAAK,UAAU,EAAS,CAAG,GAGlE,MAAM,EAAQ,CACd,MAAM,EAAO,EAAI,CACjB,KAAK,EAAM,IAAU,CACpB,IAAM,EAAS,EAAQ,EAAI,EAErB,EAAS,IADM,IAAI,IAAS,MAAM,CAAC,EAAe,CACxB,KAC1B,EAAY,GAAQ,EAAY,IAAW,IACjD,GAAI,EAAW,CACb,IAAI,EAAa,GACjB,GAAI,MAAM,QAAQ,EAAU,CAAE,CAC5B,IAAM,EAAgB,EACnB,MAAM,EAAG,KAAK,IAAI,EAAU,GAAK,EAAG,EAAE,CAAC,CACvC,QAAQ,SAAU,IAAI,CACnB,EAAkB,EAAU,IAAM,EAExC,EAAa,CACX;GACA,EAAO,QAAQ,MAAO,IAAI,CAC1B,EACA,IAAI,OAAO,EAAgB,CAC5B,CAAC,KAAK,GAAG,CAEZ,MAAO,CAAC,IAAK,EAAQ,EAAM,EAAW,CAAC,KAAK,GAAG,CAEjD,MAAO,IAAI,IAAS,KACpB,CACD,KAAK;EAAK"}
1
+ {"version":3,"file":"code-frames.mjs","names":["startLoc: Location","endLoc: Location"],"sources":["../../../../../json/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"}
@@ -1 +1,34 @@
1
- const e=require(`../../../_virtual/rolldown_runtime.cjs`),t=require(`./code-frames.cjs`);let n=require(`jsonc-parser`),r=require(`lines-and-columns`);function i(e,i){let{error:a,offset:o,length:s}=i,c=new r.LinesAndColumns(e).locationForIndex(o),l=c?.line??0,u=c?.column??0;return l++,u++,`${(0,n.printParseErrorCode)(a)} in JSON at ${l}:${u}\n${t.codeFrameColumns(e,{start:{line:l,column:u},end:{line:l,column:u+s}})}\n`}exports.formatParseError=i;
1
+ const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
2
+ const require_code_frames = require('./code-frames.cjs');
3
+ let jsonc_parser = require("jsonc-parser");
4
+ let lines_and_columns = require("lines-and-columns");
5
+
6
+ //#region ../json/src/utils/parse-error.ts
7
+ /**
8
+ * Nicely formats a JSON error with context
9
+ *
10
+ * @param input - JSON content as string
11
+ * @param parseError - jsonc ParseError
12
+ * @returns
13
+ */
14
+ function formatParseError(input, parseError) {
15
+ const { error, offset, length } = parseError;
16
+ const result = new lines_and_columns.LinesAndColumns(input).locationForIndex(offset);
17
+ let line = result?.line ?? 0;
18
+ let column = result?.column ?? 0;
19
+ line++;
20
+ column++;
21
+ return `${(0, jsonc_parser.printParseErrorCode)(error)} in JSON at ${line}:${column}\n${require_code_frames.codeFrameColumns(input, {
22
+ start: {
23
+ line,
24
+ column
25
+ },
26
+ end: {
27
+ line,
28
+ column: column + length
29
+ }
30
+ })}\n`;
31
+ }
32
+
33
+ //#endregion
34
+ exports.formatParseError = formatParseError;
@@ -1,2 +1,34 @@
1
- import{codeFrameColumns as e}from"./code-frames.mjs";import{printParseErrorCode as t}from"jsonc-parser";import{LinesAndColumns as n}from"lines-and-columns";function r(r,i){let{error:a,offset:o,length:s}=i,c=new n(r).locationForIndex(o),l=c?.line??0,u=c?.column??0;return l++,u++,`${t(a)} in JSON at ${l}:${u}\n${e(r,{start:{line:l,column:u},end:{line:l,column:u+s}})}\n`}export{r as formatParseError};
1
+ import { codeFrameColumns } from "./code-frames.mjs";
2
+ import { printParseErrorCode } from "jsonc-parser";
3
+ import { LinesAndColumns } from "lines-and-columns";
4
+
5
+ //#region ../json/src/utils/parse-error.ts
6
+ /**
7
+ * Nicely formats a JSON error with context
8
+ *
9
+ * @param input - JSON content as string
10
+ * @param parseError - jsonc ParseError
11
+ * @returns
12
+ */
13
+ function formatParseError(input, parseError) {
14
+ const { error, offset, length } = parseError;
15
+ const result = new LinesAndColumns(input).locationForIndex(offset);
16
+ let line = result?.line ?? 0;
17
+ let column = result?.column ?? 0;
18
+ line++;
19
+ column++;
20
+ return `${printParseErrorCode(error)} in JSON at ${line}:${column}\n${codeFrameColumns(input, {
21
+ start: {
22
+ line,
23
+ column
24
+ },
25
+ end: {
26
+ line,
27
+ column: column + length
28
+ }
29
+ })}\n`;
30
+ }
31
+
32
+ //#endregion
33
+ export { formatParseError };
2
34
  //# sourceMappingURL=parse-error.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"parse-error.mjs","names":[],"sources":["../../../../../json/src/utils/parse-error.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { ParseError } from \"jsonc-parser\";\nimport { printParseErrorCode } from \"jsonc-parser\";\nimport { LinesAndColumns } from \"lines-and-columns\";\nimport { codeFrameColumns } from \"./code-frames\";\n\n/**\n * Nicely formats a JSON error with context\n *\n * @param input - JSON content as string\n * @param parseError - jsonc ParseError\n * @returns\n */\nexport function formatParseError(input: string, parseError: ParseError) {\n const { error, offset, length } = parseError;\n const result = new LinesAndColumns(input).locationForIndex(offset);\n let line = result?.line ?? 0;\n let column = result?.column ?? 0;\n\n line++;\n column++;\n\n return `${printParseErrorCode(error)} in JSON at ${line}:${column}\\n${codeFrameColumns(\n input,\n {\n start: {\n line,\n column\n },\n end: {\n line,\n column: column + length\n }\n }\n )}\\n`;\n}\n"],"mappings":"4JA8BA,SAAgB,EAAiB,EAAe,EAAwB,CACtE,GAAM,CAAE,QAAO,SAAQ,UAAW,EAC5B,EAAS,IAAI,EAAgB,EAAM,CAAC,iBAAiB,EAAO,CAC9D,EAAO,GAAQ,MAAQ,EACvB,EAAS,GAAQ,QAAU,EAK/B,MAHA,KACA,IAEO,GAAG,EAAoB,EAAM,CAAC,cAAc,EAAK,GAAG,EAAO,IAAI,EACpE,EACA,CACE,MAAO,CACL,OACA,SACD,CACD,IAAK,CACH,OACA,OAAQ,EAAS,EAClB,CACF,CACF,CAAC"}
1
+ {"version":3,"file":"parse-error.mjs","names":[],"sources":["../../../../../json/src/utils/parse-error.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { ParseError } from \"jsonc-parser\";\nimport { printParseErrorCode } from \"jsonc-parser\";\nimport { LinesAndColumns } from \"lines-and-columns\";\nimport { codeFrameColumns } from \"./code-frames\";\n\n/**\n * Nicely formats a JSON error with context\n *\n * @param input - JSON content as string\n * @param parseError - jsonc ParseError\n * @returns\n */\nexport function formatParseError(input: string, parseError: ParseError) {\n const { error, offset, length } = parseError;\n const result = new LinesAndColumns(input).locationForIndex(offset);\n let line = result?.line ?? 0;\n let column = result?.column ?? 0;\n\n line++;\n column++;\n\n return `${printParseErrorCode(error)} in JSON at ${line}:${column}\\n${codeFrameColumns(\n input,\n {\n start: {\n line,\n column\n },\n end: {\n line,\n column: column + length\n }\n }\n )}\\n`;\n}\n"],"mappings":";;;;;;;;;;;;AA8BA,SAAgB,iBAAiB,OAAe,YAAwB;CACtE,MAAM,EAAE,OAAO,QAAQ,WAAW;CAClC,MAAM,SAAS,IAAI,gBAAgB,MAAM,CAAC,iBAAiB,OAAO;CAClE,IAAI,OAAO,QAAQ,QAAQ;CAC3B,IAAI,SAAS,QAAQ,UAAU;AAE/B;AACA;AAEA,QAAO,GAAG,oBAAoB,MAAM,CAAC,cAAc,KAAK,GAAG,OAAO,IAAI,iBACpE,OACA;EACE,OAAO;GACL;GACA;GACD;EACD,KAAK;GACH;GACA,QAAQ,SAAS;GAClB;EACF,CACF,CAAC"}
@@ -1 +1,45 @@
1
- const e=require(`./strip-comments.cjs`),t=/"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/,n=/"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/,r=/^\s*["[{]|^\s*-?\d{1,16}(?:\.\d{1,17})?(?:E[+-]?\d+)?\s*$/i;function i(e,t){if(e===`__proto__`||e===`constructor`&&t&&typeof t==`object`&&`prototype`in t){console.warn(`Dropping "${e}" key to prevent prototype pollution.`);return}return t}function a(a,o={}){if(typeof a!=`string`)return a;let s=e.stripComments(a);if(s[0]===`"`&&s[s.length-1]===`"`&&!s.includes(`\\`))return s.slice(1,-1);if(s=s.trim(),s.length<=9)switch(s.toLowerCase()){case`true`:return!0;case`false`:return!1;case`undefined`:return;case`null`:return null;case`nan`:return NaN;case`infinity`:return 1/0;case`-infinity`:return-1/0}if(!r.test(s)){if(o.strict)throw Error(`Invalid JSON`);return s}try{if(t.test(s)||n.test(s)){if(o.strict)throw Error(`Possible prototype pollution`);return JSON.parse(s,i)}return JSON.parse(s)}catch(e){if(o.strict)throw e;return a}}exports.parse=a;
1
+ const require_strip_comments = require('./strip-comments.cjs');
2
+
3
+ //#region ../json/src/utils/parse.ts
4
+ const suspectProtoRx = /"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/;
5
+ const suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
6
+ const JsonSigRx = /^\s*["[{]|^\s*-?\d{1,16}(?:\.\d{1,17})?(?:E[+-]?\d+)?\s*$/i;
7
+ function jsonParseTransform(key, value) {
8
+ if (key === "__proto__" || key === "constructor" && value && typeof value === "object" && "prototype" in value) {
9
+ console.warn(`Dropping "${key}" key to prevent prototype pollution.`);
10
+ return;
11
+ }
12
+ return value;
13
+ }
14
+ function parse(value, options = {}) {
15
+ if (typeof value !== "string") return value;
16
+ let stripped = require_strip_comments.stripComments(value);
17
+ if (stripped[0] === "\"" && stripped[stripped.length - 1] === "\"" && !stripped.includes("\\")) return stripped.slice(1, -1);
18
+ stripped = stripped.trim();
19
+ if (stripped.length <= 9) switch (stripped.toLowerCase()) {
20
+ case "true": return true;
21
+ case "false": return false;
22
+ case "undefined": return;
23
+ case "null": return null;
24
+ case "nan": return NaN;
25
+ case "infinity": return Number.POSITIVE_INFINITY;
26
+ case "-infinity": return Number.NEGATIVE_INFINITY;
27
+ }
28
+ if (!JsonSigRx.test(stripped)) {
29
+ if (options.strict) throw new Error("Invalid JSON");
30
+ return stripped;
31
+ }
32
+ try {
33
+ if (suspectProtoRx.test(stripped) || suspectConstructorRx.test(stripped)) {
34
+ if (options.strict) throw new Error("Possible prototype pollution");
35
+ return JSON.parse(stripped, jsonParseTransform);
36
+ }
37
+ return JSON.parse(stripped);
38
+ } catch (error) {
39
+ if (options.strict) throw error;
40
+ return value;
41
+ }
42
+ }
43
+
44
+ //#endregion
45
+ exports.parse = parse;
@@ -1,2 +1,46 @@
1
- import{stripComments as e}from"./strip-comments.mjs";const t=/"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/,n=/"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/,r=/^\s*["[{]|^\s*-?\d{1,16}(?:\.\d{1,17})?(?:E[+-]?\d+)?\s*$/i;function i(e,t){if(e===`__proto__`||e===`constructor`&&t&&typeof t==`object`&&`prototype`in t){console.warn(`Dropping "${e}" key to prevent prototype pollution.`);return}return t}function a(a,o={}){if(typeof a!=`string`)return a;let s=e(a);if(s[0]===`"`&&s[s.length-1]===`"`&&!s.includes(`\\`))return s.slice(1,-1);if(s=s.trim(),s.length<=9)switch(s.toLowerCase()){case`true`:return!0;case`false`:return!1;case`undefined`:return;case`null`:return null;case`nan`:return NaN;case`infinity`:return 1/0;case`-infinity`:return-1/0}if(!r.test(s)){if(o.strict)throw Error(`Invalid JSON`);return s}try{if(t.test(s)||n.test(s)){if(o.strict)throw Error(`Possible prototype pollution`);return JSON.parse(s,i)}return JSON.parse(s)}catch(e){if(o.strict)throw e;return a}}export{a as parse};
1
+ import { stripComments } from "./strip-comments.mjs";
2
+
3
+ //#region ../json/src/utils/parse.ts
4
+ const suspectProtoRx = /"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/;
5
+ const suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
6
+ const JsonSigRx = /^\s*["[{]|^\s*-?\d{1,16}(?:\.\d{1,17})?(?:E[+-]?\d+)?\s*$/i;
7
+ function jsonParseTransform(key, value) {
8
+ if (key === "__proto__" || key === "constructor" && value && typeof value === "object" && "prototype" in value) {
9
+ console.warn(`Dropping "${key}" key to prevent prototype pollution.`);
10
+ return;
11
+ }
12
+ return value;
13
+ }
14
+ function parse(value, options = {}) {
15
+ if (typeof value !== "string") return value;
16
+ let stripped = stripComments(value);
17
+ if (stripped[0] === "\"" && stripped[stripped.length - 1] === "\"" && !stripped.includes("\\")) return stripped.slice(1, -1);
18
+ stripped = stripped.trim();
19
+ if (stripped.length <= 9) switch (stripped.toLowerCase()) {
20
+ case "true": return true;
21
+ case "false": return false;
22
+ case "undefined": return;
23
+ case "null": return null;
24
+ case "nan": return NaN;
25
+ case "infinity": return Number.POSITIVE_INFINITY;
26
+ case "-infinity": return Number.NEGATIVE_INFINITY;
27
+ }
28
+ if (!JsonSigRx.test(stripped)) {
29
+ if (options.strict) throw new Error("Invalid JSON");
30
+ return stripped;
31
+ }
32
+ try {
33
+ if (suspectProtoRx.test(stripped) || suspectConstructorRx.test(stripped)) {
34
+ if (options.strict) throw new Error("Possible prototype pollution");
35
+ return JSON.parse(stripped, jsonParseTransform);
36
+ }
37
+ return JSON.parse(stripped);
38
+ } catch (error) {
39
+ if (options.strict) throw error;
40
+ return value;
41
+ }
42
+ }
43
+
44
+ //#endregion
45
+ export { parse };
2
46
  //# sourceMappingURL=parse.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"parse.mjs","names":[],"sources":["../../../../../json/src/utils/parse.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { stripComments } from \"./strip-comments\";\n\n// https://github.com/fastify/secure-json-parse\n// https://github.com/hapijs/bourne\nconst suspectProtoRx =\n /\"(?:_|\\\\u0{2}5[Ff]){2}(?:p|\\\\u0{2}70)(?:r|\\\\u0{2}72)(?:o|\\\\u0{2}6[Ff])(?:t|\\\\u0{2}74)(?:o|\\\\u0{2}6[Ff])(?:_|\\\\u0{2}5[Ff]){2}\"\\s*:/;\nconst suspectConstructorRx =\n /\"(?:c|\\\\u0063)(?:o|\\\\u006[Ff])(?:n|\\\\u006[Ee])(?:s|\\\\u0073)(?:t|\\\\u0074)(?:r|\\\\u0072)(?:u|\\\\u0075)(?:c|\\\\u0063)(?:t|\\\\u0074)(?:o|\\\\u006[Ff])(?:r|\\\\u0072)\"\\s*:/;\n\nconst JsonSigRx = /^\\s*[\"[{]|^\\s*-?\\d{1,16}(?:\\.\\d{1,17})?(?:E[+-]?\\d+)?\\s*$/i;\n\nfunction jsonParseTransform(key: string, value: any): any {\n if (\n key === \"__proto__\" ||\n (key === \"constructor\" &&\n value &&\n typeof value === \"object\" &&\n \"prototype\" in value)\n ) {\n // eslint-disable-next-line no-console\n console.warn(`Dropping \"${key}\" key to prevent prototype pollution.`);\n return;\n }\n return value;\n}\n\nexport interface Options {\n strict?: boolean;\n}\n\nexport function parse<T = unknown>(value: any, options: Options = {}): T {\n if (typeof value !== \"string\") {\n return value;\n }\n\n let stripped = stripComments(value);\n\n if (\n stripped[0] === '\"' &&\n stripped[stripped.length - 1] === '\"' &&\n !stripped.includes(\"\\\\\")\n ) {\n return stripped.slice(1, -1) as T;\n }\n\n stripped = stripped.trim();\n\n if (stripped.length <= 9) {\n switch (stripped.toLowerCase()) {\n case \"true\": {\n return true as T;\n }\n case \"false\": {\n return false as T;\n }\n case \"undefined\": {\n return undefined as T;\n }\n case \"null\": {\n return null as T;\n }\n case \"nan\": {\n return Number.NaN as T;\n }\n case \"infinity\": {\n return Number.POSITIVE_INFINITY as T;\n }\n case \"-infinity\": {\n return Number.NEGATIVE_INFINITY as T;\n }\n }\n }\n\n if (!JsonSigRx.test(stripped)) {\n if (options.strict) {\n throw new Error(\"Invalid JSON\");\n }\n return stripped as T;\n }\n\n try {\n if (suspectProtoRx.test(stripped) || suspectConstructorRx.test(stripped)) {\n if (options.strict) {\n throw new Error(\"Possible prototype pollution\");\n }\n return JSON.parse(stripped, jsonParseTransform);\n }\n\n return JSON.parse(stripped);\n } catch (error) {\n if (options.strict) {\n throw error;\n }\n return value as T;\n }\n}\n\nexport function safeParse<T = unknown>(value: any, options: Options = {}): T {\n return parse<T>(value, { ...options, strict: true });\n}\n"],"mappings":"qDAsBA,MAAM,EACJ,oIACI,EACJ,iKAEI,EAAY,6DAElB,SAAS,EAAmB,EAAa,EAAiB,CACxD,GACE,IAAQ,aACP,IAAQ,eACP,GACA,OAAO,GAAU,UACjB,cAAe,EACjB,CAEA,QAAQ,KAAK,aAAa,EAAI,uCAAuC,CACrE,OAEF,OAAO,EAOT,SAAgB,EAAmB,EAAY,EAAmB,EAAE,CAAK,CACvE,GAAI,OAAO,GAAU,SACnB,OAAO,EAGT,IAAI,EAAW,EAAc,EAAM,CAEnC,GACE,EAAS,KAAO,KAChB,EAAS,EAAS,OAAS,KAAO,KAClC,CAAC,EAAS,SAAS,KAAK,CAExB,OAAO,EAAS,MAAM,EAAG,GAAG,CAK9B,GAFA,EAAW,EAAS,MAAM,CAEtB,EAAS,QAAU,EACrB,OAAQ,EAAS,aAAa,CAA9B,CACE,IAAK,OACH,MAAO,GAET,IAAK,QACH,MAAO,GAET,IAAK,YACH,OAEF,IAAK,OACH,OAAO,KAET,IAAK,MACH,MAAO,KAET,IAAK,WACH,MAAO,KAET,IAAK,YACH,MAAO,KAKb,GAAI,CAAC,EAAU,KAAK,EAAS,CAAE,CAC7B,GAAI,EAAQ,OACV,MAAU,MAAM,eAAe,CAEjC,OAAO,EAGT,GAAI,CACF,GAAI,EAAe,KAAK,EAAS,EAAI,EAAqB,KAAK,EAAS,CAAE,CACxE,GAAI,EAAQ,OACV,MAAU,MAAM,+BAA+B,CAEjD,OAAO,KAAK,MAAM,EAAU,EAAmB,CAGjD,OAAO,KAAK,MAAM,EAAS,OACpB,EAAO,CACd,GAAI,EAAQ,OACV,MAAM,EAER,OAAO"}
1
+ {"version":3,"file":"parse.mjs","names":[],"sources":["../../../../../json/src/utils/parse.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { stripComments } from \"./strip-comments\";\n\n// https://github.com/fastify/secure-json-parse\n// https://github.com/hapijs/bourne\nconst suspectProtoRx =\n /\"(?:_|\\\\u0{2}5[Ff]){2}(?:p|\\\\u0{2}70)(?:r|\\\\u0{2}72)(?:o|\\\\u0{2}6[Ff])(?:t|\\\\u0{2}74)(?:o|\\\\u0{2}6[Ff])(?:_|\\\\u0{2}5[Ff]){2}\"\\s*:/;\nconst suspectConstructorRx =\n /\"(?:c|\\\\u0063)(?:o|\\\\u006[Ff])(?:n|\\\\u006[Ee])(?:s|\\\\u0073)(?:t|\\\\u0074)(?:r|\\\\u0072)(?:u|\\\\u0075)(?:c|\\\\u0063)(?:t|\\\\u0074)(?:o|\\\\u006[Ff])(?:r|\\\\u0072)\"\\s*:/;\n\nconst JsonSigRx = /^\\s*[\"[{]|^\\s*-?\\d{1,16}(?:\\.\\d{1,17})?(?:E[+-]?\\d+)?\\s*$/i;\n\nfunction jsonParseTransform(key: string, value: any): any {\n if (\n key === \"__proto__\" ||\n (key === \"constructor\" &&\n value &&\n typeof value === \"object\" &&\n \"prototype\" in value)\n ) {\n // eslint-disable-next-line no-console\n console.warn(`Dropping \"${key}\" key to prevent prototype pollution.`);\n return;\n }\n return value;\n}\n\nexport interface Options {\n strict?: boolean;\n}\n\nexport function parse<T = unknown>(value: any, options: Options = {}): T {\n if (typeof value !== \"string\") {\n return value;\n }\n\n let stripped = stripComments(value);\n\n if (\n stripped[0] === '\"' &&\n stripped[stripped.length - 1] === '\"' &&\n !stripped.includes(\"\\\\\")\n ) {\n return stripped.slice(1, -1) as T;\n }\n\n stripped = stripped.trim();\n\n if (stripped.length <= 9) {\n switch (stripped.toLowerCase()) {\n case \"true\": {\n return true as T;\n }\n case \"false\": {\n return false as T;\n }\n case \"undefined\": {\n return undefined as T;\n }\n case \"null\": {\n return null as T;\n }\n case \"nan\": {\n return Number.NaN as T;\n }\n case \"infinity\": {\n return Number.POSITIVE_INFINITY as T;\n }\n case \"-infinity\": {\n return Number.NEGATIVE_INFINITY as T;\n }\n }\n }\n\n if (!JsonSigRx.test(stripped)) {\n if (options.strict) {\n throw new Error(\"Invalid JSON\");\n }\n return stripped as T;\n }\n\n try {\n if (suspectProtoRx.test(stripped) || suspectConstructorRx.test(stripped)) {\n if (options.strict) {\n throw new Error(\"Possible prototype pollution\");\n }\n return JSON.parse(stripped, jsonParseTransform);\n }\n\n return JSON.parse(stripped);\n } catch (error) {\n if (options.strict) {\n throw error;\n }\n return value as T;\n }\n}\n\nexport function safeParse<T = unknown>(value: any, options: Options = {}): T {\n return parse<T>(value, { ...options, strict: true });\n}\n"],"mappings":";;;AAsBA,MAAM,iBACJ;AACF,MAAM,uBACJ;AAEF,MAAM,YAAY;AAElB,SAAS,mBAAmB,KAAa,OAAiB;AACxD,KACE,QAAQ,eACP,QAAQ,iBACP,SACA,OAAO,UAAU,YACjB,eAAe,OACjB;AAEA,UAAQ,KAAK,aAAa,IAAI,uCAAuC;AACrE;;AAEF,QAAO;;AAOT,SAAgB,MAAmB,OAAY,UAAmB,EAAE,EAAK;AACvE,KAAI,OAAO,UAAU,SACnB,QAAO;CAGT,IAAI,WAAW,cAAc,MAAM;AAEnC,KACE,SAAS,OAAO,QAChB,SAAS,SAAS,SAAS,OAAO,QAClC,CAAC,SAAS,SAAS,KAAK,CAExB,QAAO,SAAS,MAAM,GAAG,GAAG;AAG9B,YAAW,SAAS,MAAM;AAE1B,KAAI,SAAS,UAAU,EACrB,SAAQ,SAAS,aAAa,EAA9B;EACE,KAAK,OACH,QAAO;EAET,KAAK,QACH,QAAO;EAET,KAAK,YACH;EAEF,KAAK,OACH,QAAO;EAET,KAAK,MACH,QAAO;EAET,KAAK,WACH,QAAO,OAAO;EAEhB,KAAK,YACH,QAAO,OAAO;;AAKpB,KAAI,CAAC,UAAU,KAAK,SAAS,EAAE;AAC7B,MAAI,QAAQ,OACV,OAAM,IAAI,MAAM,eAAe;AAEjC,SAAO;;AAGT,KAAI;AACF,MAAI,eAAe,KAAK,SAAS,IAAI,qBAAqB,KAAK,SAAS,EAAE;AACxE,OAAI,QAAQ,OACV,OAAM,IAAI,MAAM,+BAA+B;AAEjD,UAAO,KAAK,MAAM,UAAU,mBAAmB;;AAGjD,SAAO,KAAK,MAAM,SAAS;UACpB,OAAO;AACd,MAAI,QAAQ,OACV,OAAM;AAER,SAAO"}