@stryke/json 0.9.36 → 0.9.37

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 (70) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/_virtual/rolldown_runtime.cjs +29 -1
  3. package/dist/index.cjs +16 -1
  4. package/dist/index.mjs +9 -1
  5. package/dist/pointer/find-reference.cjs +66 -1
  6. package/dist/pointer/find-reference.mjs +63 -1
  7. package/dist/pointer/find-reference.mjs.map +1 -1
  8. package/dist/pointer/index.cjs +15 -1
  9. package/dist/pointer/index.mjs +4 -1
  10. package/dist/pointer/parse.cjs +87 -1
  11. package/dist/pointer/parse.mjs +80 -1
  12. package/dist/pointer/parse.mjs.map +1 -1
  13. package/dist/storm-json.cjs +117 -1
  14. package/dist/storm-json.mjs +115 -1
  15. package/dist/storm-json.mjs.map +1 -1
  16. package/dist/type-checks/src/get-object-tag.cjs +15 -1
  17. package/dist/type-checks/src/get-object-tag.mjs +14 -1
  18. package/dist/type-checks/src/get-object-tag.mjs.map +1 -1
  19. package/dist/type-checks/src/is-empty.cjs +20 -1
  20. package/dist/type-checks/src/is-empty.mjs +20 -1
  21. package/dist/type-checks/src/is-empty.mjs.map +1 -1
  22. package/dist/type-checks/src/is-non-null-object.cjs +16 -1
  23. package/dist/type-checks/src/is-non-null-object.mjs +16 -1
  24. package/dist/type-checks/src/is-non-null-object.mjs.map +1 -1
  25. package/dist/type-checks/src/is-null.cjs +12 -1
  26. package/dist/type-checks/src/is-null.mjs +11 -1
  27. package/dist/type-checks/src/is-null.mjs.map +1 -1
  28. package/dist/type-checks/src/is-number.cjs +18 -1
  29. package/dist/type-checks/src/is-number.mjs +17 -1
  30. package/dist/type-checks/src/is-number.mjs.map +1 -1
  31. package/dist/type-checks/src/is-object.cjs +19 -1
  32. package/dist/type-checks/src/is-object.mjs +19 -1
  33. package/dist/type-checks/src/is-object.mjs.map +1 -1
  34. package/dist/type-checks/src/is-plain-object.cjs +63 -1
  35. package/dist/type-checks/src/is-plain-object.mjs +63 -1
  36. package/dist/type-checks/src/is-plain-object.mjs.map +1 -1
  37. package/dist/type-checks/src/is-set-object.cjs +19 -1
  38. package/dist/type-checks/src/is-set-object.mjs +19 -1
  39. package/dist/type-checks/src/is-set-object.mjs.map +1 -1
  40. package/dist/type-checks/src/is-set.cjs +19 -1
  41. package/dist/type-checks/src/is-set.mjs +19 -1
  42. package/dist/type-checks/src/is-set.mjs.map +1 -1
  43. package/dist/type-checks/src/is-string.cjs +12 -1
  44. package/dist/type-checks/src/is-string.mjs +11 -1
  45. package/dist/type-checks/src/is-string.mjs.map +1 -1
  46. package/dist/type-checks/src/is-undefined.cjs +8 -1
  47. package/dist/type-checks/src/is-undefined.mjs +7 -1
  48. package/dist/type-checks/src/is-undefined.mjs.map +1 -1
  49. package/dist/types/src/base.cjs +6 -1
  50. package/dist/types/src/base.mjs +5 -1
  51. package/dist/types/src/base.mjs.map +1 -1
  52. package/dist/types.mjs +1 -1
  53. package/dist/utils/code-frames.cjs +77 -3
  54. package/dist/utils/code-frames.mjs +76 -3
  55. package/dist/utils/code-frames.mjs.map +1 -1
  56. package/dist/utils/index.cjs +13 -1
  57. package/dist/utils/index.mjs +7 -1
  58. package/dist/utils/parse-error.cjs +34 -1
  59. package/dist/utils/parse-error.mjs +33 -1
  60. package/dist/utils/parse-error.mjs.map +1 -1
  61. package/dist/utils/parse.cjs +52 -1
  62. package/dist/utils/parse.mjs +51 -1
  63. package/dist/utils/parse.mjs.map +1 -1
  64. package/dist/utils/stringify.cjs +68 -1
  65. package/dist/utils/stringify.mjs +67 -1
  66. package/dist/utils/stringify.mjs.map +1 -1
  67. package/dist/utils/strip-comments.cjs +86 -4
  68. package/dist/utils/strip-comments.mjs +86 -4
  69. package/dist/utils/strip-comments.mjs.map +1 -1
  70. package/package.json +2 -2
@@ -1 +1,52 @@
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}}function o(e,t={}){return a(e,{...t,strict:!0})}exports.parse=a,exports.safeParse=o;
1
+ const require_utils_strip_comments = require('./strip-comments.cjs');
2
+
3
+ //#region src/utils/parse.ts
4
+ const suspectProtoRx = /"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/;
5
+ const suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
6
+ const JsonSigRx = /^\s*["[{]|^\s*-?\d{1,16}(?:\.\d{1,17})?(?:E[+-]?\d+)?\s*$/i;
7
+ function jsonParseTransform(key, value) {
8
+ if (key === "__proto__" || key === "constructor" && value && typeof value === "object" && "prototype" in value) {
9
+ console.warn(`Dropping "${key}" key to prevent prototype pollution.`);
10
+ return;
11
+ }
12
+ return value;
13
+ }
14
+ function parse(value, options = {}) {
15
+ if (typeof value !== "string") return value;
16
+ let stripped = require_utils_strip_comments.stripComments(value);
17
+ if (stripped[0] === "\"" && stripped[stripped.length - 1] === "\"" && !stripped.includes("\\")) return stripped.slice(1, -1);
18
+ stripped = stripped.trim();
19
+ if (stripped.length <= 9) switch (stripped.toLowerCase()) {
20
+ case "true": return true;
21
+ case "false": return false;
22
+ case "undefined": return;
23
+ case "null": return null;
24
+ case "nan": return NaN;
25
+ case "infinity": return Number.POSITIVE_INFINITY;
26
+ case "-infinity": return Number.NEGATIVE_INFINITY;
27
+ }
28
+ if (!JsonSigRx.test(stripped)) {
29
+ if (options.strict) throw new Error("Invalid JSON");
30
+ return stripped;
31
+ }
32
+ try {
33
+ if (suspectProtoRx.test(stripped) || suspectConstructorRx.test(stripped)) {
34
+ if (options.strict) throw new Error("Possible prototype pollution");
35
+ return JSON.parse(stripped, jsonParseTransform);
36
+ }
37
+ return JSON.parse(stripped);
38
+ } catch (error) {
39
+ if (options.strict) throw error;
40
+ return value;
41
+ }
42
+ }
43
+ function safeParse(value, options = {}) {
44
+ return parse(value, {
45
+ ...options,
46
+ strict: true
47
+ });
48
+ }
49
+
50
+ //#endregion
51
+ exports.parse = parse;
52
+ exports.safeParse = safeParse;
@@ -1,2 +1,52 @@
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}}function o(e,t={}){return a(e,{...t,strict:!0})}export{a as parse,o as safeParse};
1
+ import { stripComments } from "./strip-comments.mjs";
2
+
3
+ //#region src/utils/parse.ts
4
+ const suspectProtoRx = /"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/;
5
+ const suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
6
+ const JsonSigRx = /^\s*["[{]|^\s*-?\d{1,16}(?:\.\d{1,17})?(?:E[+-]?\d+)?\s*$/i;
7
+ function jsonParseTransform(key, value) {
8
+ if (key === "__proto__" || key === "constructor" && value && typeof value === "object" && "prototype" in value) {
9
+ console.warn(`Dropping "${key}" key to prevent prototype pollution.`);
10
+ return;
11
+ }
12
+ return value;
13
+ }
14
+ function parse(value, options = {}) {
15
+ if (typeof value !== "string") return value;
16
+ let stripped = stripComments(value);
17
+ if (stripped[0] === "\"" && stripped[stripped.length - 1] === "\"" && !stripped.includes("\\")) return stripped.slice(1, -1);
18
+ stripped = stripped.trim();
19
+ if (stripped.length <= 9) switch (stripped.toLowerCase()) {
20
+ case "true": return true;
21
+ case "false": return false;
22
+ case "undefined": return;
23
+ case "null": return null;
24
+ case "nan": return NaN;
25
+ case "infinity": return Number.POSITIVE_INFINITY;
26
+ case "-infinity": return Number.NEGATIVE_INFINITY;
27
+ }
28
+ if (!JsonSigRx.test(stripped)) {
29
+ if (options.strict) throw new Error("Invalid JSON");
30
+ return stripped;
31
+ }
32
+ try {
33
+ if (suspectProtoRx.test(stripped) || suspectConstructorRx.test(stripped)) {
34
+ if (options.strict) throw new Error("Possible prototype pollution");
35
+ return JSON.parse(stripped, jsonParseTransform);
36
+ }
37
+ return JSON.parse(stripped);
38
+ } catch (error) {
39
+ if (options.strict) throw error;
40
+ return value;
41
+ }
42
+ }
43
+ function safeParse(value, options = {}) {
44
+ return parse(value, {
45
+ ...options,
46
+ strict: true
47
+ });
48
+ }
49
+
50
+ //#endregion
51
+ export { parse, safeParse };
2
52
  //# sourceMappingURL=parse.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"parse.mjs","names":[],"sources":["../../src/utils/parse.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { stripComments } from \"./strip-comments\";\n\n// https://github.com/fastify/secure-json-parse\n// https://github.com/hapijs/bourne\nconst suspectProtoRx =\n /\"(?:_|\\\\u0{2}5[Ff]){2}(?:p|\\\\u0{2}70)(?:r|\\\\u0{2}72)(?:o|\\\\u0{2}6[Ff])(?:t|\\\\u0{2}74)(?:o|\\\\u0{2}6[Ff])(?:_|\\\\u0{2}5[Ff]){2}\"\\s*:/;\nconst suspectConstructorRx =\n /\"(?:c|\\\\u0063)(?:o|\\\\u006[Ff])(?:n|\\\\u006[Ee])(?:s|\\\\u0073)(?:t|\\\\u0074)(?:r|\\\\u0072)(?:u|\\\\u0075)(?:c|\\\\u0063)(?:t|\\\\u0074)(?:o|\\\\u006[Ff])(?:r|\\\\u0072)\"\\s*:/;\n\nconst JsonSigRx = /^\\s*[\"[{]|^\\s*-?\\d{1,16}(?:\\.\\d{1,17})?(?:E[+-]?\\d+)?\\s*$/i;\n\nfunction jsonParseTransform(key: string, value: any): any {\n if (\n key === \"__proto__\" ||\n (key === \"constructor\" &&\n value &&\n typeof value === \"object\" &&\n \"prototype\" in value)\n ) {\n // eslint-disable-next-line no-console\n console.warn(`Dropping \"${key}\" key to prevent prototype pollution.`);\n return;\n }\n return value;\n}\n\nexport interface Options {\n strict?: boolean;\n}\n\nexport function parse<T = unknown>(value: any, options: Options = {}): T {\n if (typeof value !== \"string\") {\n return value;\n }\n\n let stripped = stripComments(value);\n\n if (\n stripped[0] === '\"' &&\n stripped[stripped.length - 1] === '\"' &&\n !stripped.includes(\"\\\\\")\n ) {\n return stripped.slice(1, -1) as T;\n }\n\n stripped = stripped.trim();\n\n if (stripped.length <= 9) {\n switch (stripped.toLowerCase()) {\n case \"true\": {\n return true as T;\n }\n case \"false\": {\n return false as T;\n }\n case \"undefined\": {\n return undefined as T;\n }\n case \"null\": {\n return null as T;\n }\n case \"nan\": {\n return Number.NaN as T;\n }\n case \"infinity\": {\n return Number.POSITIVE_INFINITY as T;\n }\n case \"-infinity\": {\n return Number.NEGATIVE_INFINITY as T;\n }\n }\n }\n\n if (!JsonSigRx.test(stripped)) {\n if (options.strict) {\n throw new Error(\"Invalid JSON\");\n }\n return stripped as T;\n }\n\n try {\n if (suspectProtoRx.test(stripped) || suspectConstructorRx.test(stripped)) {\n if (options.strict) {\n throw new Error(\"Possible prototype pollution\");\n }\n return JSON.parse(stripped, jsonParseTransform);\n }\n\n return JSON.parse(stripped);\n } catch (error) {\n if (options.strict) {\n throw error;\n }\n return value as T;\n }\n}\n\nexport function safeParse<T = unknown>(value: any, options: Options = {}): T {\n return parse<T>(value, { ...options, strict: true });\n}\n"],"mappings":"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,GAIX,SAAgB,EAAuB,EAAY,EAAmB,EAAE,CAAK,CAC3E,OAAO,EAAS,EAAO,CAAE,GAAG,EAAS,OAAQ,GAAM,CAAC"}
1
+ {"version":3,"file":"parse.mjs","names":[],"sources":["../../src/utils/parse.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { stripComments } from \"./strip-comments\";\n\n// https://github.com/fastify/secure-json-parse\n// https://github.com/hapijs/bourne\nconst suspectProtoRx =\n /\"(?:_|\\\\u0{2}5[Ff]){2}(?:p|\\\\u0{2}70)(?:r|\\\\u0{2}72)(?:o|\\\\u0{2}6[Ff])(?:t|\\\\u0{2}74)(?:o|\\\\u0{2}6[Ff])(?:_|\\\\u0{2}5[Ff]){2}\"\\s*:/;\nconst suspectConstructorRx =\n /\"(?:c|\\\\u0063)(?:o|\\\\u006[Ff])(?:n|\\\\u006[Ee])(?:s|\\\\u0073)(?:t|\\\\u0074)(?:r|\\\\u0072)(?:u|\\\\u0075)(?:c|\\\\u0063)(?:t|\\\\u0074)(?:o|\\\\u006[Ff])(?:r|\\\\u0072)\"\\s*:/;\n\nconst JsonSigRx = /^\\s*[\"[{]|^\\s*-?\\d{1,16}(?:\\.\\d{1,17})?(?:E[+-]?\\d+)?\\s*$/i;\n\nfunction jsonParseTransform(key: string, value: any): any {\n if (\n key === \"__proto__\" ||\n (key === \"constructor\" &&\n value &&\n typeof value === \"object\" &&\n \"prototype\" in value)\n ) {\n // eslint-disable-next-line no-console\n console.warn(`Dropping \"${key}\" key to prevent prototype pollution.`);\n return;\n }\n return value;\n}\n\nexport interface Options {\n strict?: boolean;\n}\n\nexport function parse<T = unknown>(value: any, options: Options = {}): T {\n if (typeof value !== \"string\") {\n return value;\n }\n\n let stripped = stripComments(value);\n\n if (\n stripped[0] === '\"' &&\n stripped[stripped.length - 1] === '\"' &&\n !stripped.includes(\"\\\\\")\n ) {\n return stripped.slice(1, -1) as T;\n }\n\n stripped = stripped.trim();\n\n if (stripped.length <= 9) {\n switch (stripped.toLowerCase()) {\n case \"true\": {\n return true as T;\n }\n case \"false\": {\n return false as T;\n }\n case \"undefined\": {\n return undefined as T;\n }\n case \"null\": {\n return null as T;\n }\n case \"nan\": {\n return Number.NaN as T;\n }\n case \"infinity\": {\n return Number.POSITIVE_INFINITY as T;\n }\n case \"-infinity\": {\n return Number.NEGATIVE_INFINITY as T;\n }\n }\n }\n\n if (!JsonSigRx.test(stripped)) {\n if (options.strict) {\n throw new Error(\"Invalid JSON\");\n }\n return stripped as T;\n }\n\n try {\n if (suspectProtoRx.test(stripped) || suspectConstructorRx.test(stripped)) {\n if (options.strict) {\n throw new Error(\"Possible prototype pollution\");\n }\n return JSON.parse(stripped, jsonParseTransform);\n }\n\n return JSON.parse(stripped);\n } catch (error) {\n if (options.strict) {\n throw error;\n }\n return value as T;\n }\n}\n\nexport function safeParse<T = unknown>(value: any, options: Options = {}): T {\n return parse<T>(value, { ...options, strict: true });\n}\n"],"mappings":";;;AAsBA,MAAM,iBACJ;AACF,MAAM,uBACJ;AAEF,MAAM,YAAY;AAElB,SAAS,mBAAmB,KAAa,OAAiB;AACxD,KACE,QAAQ,eACP,QAAQ,iBACP,SACA,OAAO,UAAU,YACjB,eAAe,OACjB;AAEA,UAAQ,KAAK,aAAa,IAAI,uCAAuC;AACrE;;AAEF,QAAO;;AAOT,SAAgB,MAAmB,OAAY,UAAmB,EAAE,EAAK;AACvE,KAAI,OAAO,UAAU,SACnB,QAAO;CAGT,IAAI,WAAW,cAAc,MAAM;AAEnC,KACE,SAAS,OAAO,QAChB,SAAS,SAAS,SAAS,OAAO,QAClC,CAAC,SAAS,SAAS,KAAK,CAExB,QAAO,SAAS,MAAM,GAAG,GAAG;AAG9B,YAAW,SAAS,MAAM;AAE1B,KAAI,SAAS,UAAU,EACrB,SAAQ,SAAS,aAAa,EAA9B;EACE,KAAK,OACH,QAAO;EAET,KAAK,QACH,QAAO;EAET,KAAK,YACH;EAEF,KAAK,OACH,QAAO;EAET,KAAK,MACH,QAAO;EAET,KAAK,WACH,QAAO,OAAO;EAEhB,KAAK,YACH,QAAO,OAAO;;AAKpB,KAAI,CAAC,UAAU,KAAK,SAAS,EAAE;AAC7B,MAAI,QAAQ,OACV,OAAM,IAAI,MAAM,eAAe;AAEjC,SAAO;;AAGT,KAAI;AACF,MAAI,eAAe,KAAK,SAAS,IAAI,qBAAqB,KAAK,SAAS,EAAE;AACxE,OAAI,QAAQ,OACV,OAAM,IAAI,MAAM,+BAA+B;AAEjD,UAAO,KAAK,MAAM,UAAU,mBAAmB;;AAGjD,SAAO,KAAK,MAAM,SAAS;UACpB,OAAO;AACd,MAAI,QAAQ,OACV,OAAM;AAER,SAAO;;;AAIX,SAAgB,UAAuB,OAAY,UAAmB,EAAE,EAAK;AAC3E,QAAO,MAAS,OAAO;EAAE,GAAG;EAAS,QAAQ;EAAM,CAAC"}
@@ -1 +1,68 @@
1
- const e=require(`../type-checks/src/is-number.cjs`),t=require(`../type-checks/src/is-undefined.cjs`),n=`@/#$ :;,.!?&=+-*%^~|\\"'\`{}[]()<>`.split(``),r=(i,a=2)=>{let o=e.isNumber(a)?` `.repeat(a):a;switch(i){case null:return`null`;case void 0:return`"undefined"`;case!0:return`true`;case!1:return`false`;case 1/0:return`infinity`;case-1/0:return`-infinity`}if(Array.isArray(i))return`[${o}${i.map(e=>r(e,o)).join(`,${o}`)}${o}]`;if(i instanceof Uint8Array)return i.toString();switch(typeof i){case`number`:return`${i}`;case`string`:return JSON.stringify(i);case`object`:return`{${o}${Object.keys(i).filter(e=>!t.isUndefined(i[e])).map(e=>`${n.some(t=>e.includes(t))?`"${e}"`:e}: ${o}${r(i[e],o)}`).join(`,${o}`)}${o}}`;default:return`null`}};exports.invalidKeyChars=n,exports.stringify=r;
1
+ const require_is_number = require('../type-checks/src/is-number.cjs');
2
+ const require_is_undefined = require('../type-checks/src/is-undefined.cjs');
3
+
4
+ //#region src/utils/stringify.ts
5
+ const invalidKeyChars = [
6
+ "@",
7
+ "/",
8
+ "#",
9
+ "$",
10
+ " ",
11
+ ":",
12
+ ";",
13
+ ",",
14
+ ".",
15
+ "!",
16
+ "?",
17
+ "&",
18
+ "=",
19
+ "+",
20
+ "-",
21
+ "*",
22
+ "%",
23
+ "^",
24
+ "~",
25
+ "|",
26
+ "\\",
27
+ "\"",
28
+ "'",
29
+ "`",
30
+ "{",
31
+ "}",
32
+ "[",
33
+ "]",
34
+ "(",
35
+ ")",
36
+ "<",
37
+ ">"
38
+ ];
39
+ /**
40
+ * Stringify a value to a JSON-like string.
41
+ *
42
+ * @param value - The value to stringify
43
+ * @param spacing - The spacing to use for the stringification
44
+ * @returns The stringified value
45
+ */
46
+ const stringify = (value, spacing = 2) => {
47
+ const space = require_is_number.isNumber(spacing) ? " ".repeat(spacing) : spacing;
48
+ switch (value) {
49
+ case null: return "null";
50
+ case void 0: return "\"undefined\"";
51
+ case true: return "true";
52
+ case false: return "false";
53
+ case Number.POSITIVE_INFINITY: return "infinity";
54
+ case Number.NEGATIVE_INFINITY: return "-infinity";
55
+ }
56
+ if (Array.isArray(value)) return `[${space}${value.map((v) => stringify(v, space)).join(`,${space}`)}${space}]`;
57
+ if (value instanceof Uint8Array) return value.toString();
58
+ switch (typeof value) {
59
+ case "number": return `${value}`;
60
+ case "string": return JSON.stringify(value);
61
+ case "object": return `{${space}${Object.keys(value).filter((key) => !require_is_undefined.isUndefined(value[key])).map((key) => `${invalidKeyChars.some((invalidKeyChar) => key.includes(invalidKeyChar)) ? `"${key}"` : key}: ${space}${stringify(value[key], space)}`).join(`,${space}`)}${space}}`;
62
+ default: return "null";
63
+ }
64
+ };
65
+
66
+ //#endregion
67
+ exports.invalidKeyChars = invalidKeyChars;
68
+ exports.stringify = stringify;
@@ -1,2 +1,68 @@
1
- import{isNumber as e}from"../type-checks/src/is-number.mjs";import{isUndefined as t}from"../type-checks/src/is-undefined.mjs";const n=`@/#$ :;,.!?&=+-*%^~|\\"'\`{}[]()<>`.split(``),r=(i,a=2)=>{let o=e(a)?` `.repeat(a):a;switch(i){case null:return`null`;case void 0:return`"undefined"`;case!0:return`true`;case!1:return`false`;case 1/0:return`infinity`;case-1/0:return`-infinity`}if(Array.isArray(i))return`[${o}${i.map(e=>r(e,o)).join(`,${o}`)}${o}]`;if(i instanceof Uint8Array)return i.toString();switch(typeof i){case`number`:return`${i}`;case`string`:return JSON.stringify(i);case`object`:return`{${o}${Object.keys(i).filter(e=>!t(i[e])).map(e=>`${n.some(t=>e.includes(t))?`"${e}"`:e}: ${o}${r(i[e],o)}`).join(`,${o}`)}${o}}`;default:return`null`}};export{n as invalidKeyChars,r as stringify};
1
+ import { isNumber } from "../type-checks/src/is-number.mjs";
2
+ import { isUndefined } from "../type-checks/src/is-undefined.mjs";
3
+
4
+ //#region src/utils/stringify.ts
5
+ const invalidKeyChars = [
6
+ "@",
7
+ "/",
8
+ "#",
9
+ "$",
10
+ " ",
11
+ ":",
12
+ ";",
13
+ ",",
14
+ ".",
15
+ "!",
16
+ "?",
17
+ "&",
18
+ "=",
19
+ "+",
20
+ "-",
21
+ "*",
22
+ "%",
23
+ "^",
24
+ "~",
25
+ "|",
26
+ "\\",
27
+ "\"",
28
+ "'",
29
+ "`",
30
+ "{",
31
+ "}",
32
+ "[",
33
+ "]",
34
+ "(",
35
+ ")",
36
+ "<",
37
+ ">"
38
+ ];
39
+ /**
40
+ * Stringify a value to a JSON-like string.
41
+ *
42
+ * @param value - The value to stringify
43
+ * @param spacing - The spacing to use for the stringification
44
+ * @returns The stringified value
45
+ */
46
+ const stringify = (value, spacing = 2) => {
47
+ const space = isNumber(spacing) ? " ".repeat(spacing) : spacing;
48
+ switch (value) {
49
+ case null: return "null";
50
+ case void 0: return "\"undefined\"";
51
+ case true: return "true";
52
+ case false: return "false";
53
+ case Number.POSITIVE_INFINITY: return "infinity";
54
+ case Number.NEGATIVE_INFINITY: return "-infinity";
55
+ }
56
+ if (Array.isArray(value)) return `[${space}${value.map((v) => stringify(v, space)).join(`,${space}`)}${space}]`;
57
+ if (value instanceof Uint8Array) return value.toString();
58
+ switch (typeof value) {
59
+ case "number": return `${value}`;
60
+ case "string": return JSON.stringify(value);
61
+ case "object": return `{${space}${Object.keys(value).filter((key) => !isUndefined(value[key])).map((key) => `${invalidKeyChars.some((invalidKeyChar) => key.includes(invalidKeyChar)) ? `"${key}"` : key}: ${space}${stringify(value[key], space)}`).join(`,${space}`)}${space}}`;
62
+ default: return "null";
63
+ }
64
+ };
65
+
66
+ //#endregion
67
+ export { invalidKeyChars, stringify };
2
68
  //# sourceMappingURL=stringify.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"stringify.mjs","names":[],"sources":["../../src/utils/stringify.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { isNumber } from \"@stryke/type-checks/is-number\";\nimport { isUndefined } from \"@stryke/type-checks/is-undefined\";\n\nexport const invalidKeyChars = [\n \"@\",\n \"/\",\n \"#\",\n \"$\",\n \" \",\n \":\",\n \";\",\n \",\",\n \".\",\n \"!\",\n \"?\",\n \"&\",\n \"=\",\n \"+\",\n \"-\",\n \"*\",\n \"%\",\n \"^\",\n \"~\",\n \"|\",\n \"\\\\\",\n '\"',\n \"'\",\n \"`\",\n \"{\",\n \"}\",\n \"[\",\n \"]\",\n \"(\",\n \")\",\n \"<\",\n \">\"\n] as const;\n\n/**\n * Stringify a value to a JSON-like string.\n *\n * @param value - The value to stringify\n * @param spacing - The spacing to use for the stringification\n * @returns The stringified value\n */\nexport const stringify = (\n value: unknown,\n spacing: string | number = 2\n): string => {\n const space = isNumber(spacing) ? \" \".repeat(spacing) : spacing;\n\n switch (value) {\n case null: {\n return \"null\";\n }\n case undefined: {\n return '\"undefined\"';\n }\n case true: {\n return \"true\";\n }\n case false: {\n return \"false\";\n }\n case Number.POSITIVE_INFINITY: {\n return \"infinity\";\n }\n case Number.NEGATIVE_INFINITY: {\n return \"-infinity\";\n }\n }\n\n if (Array.isArray(value)) {\n return `[${space}${value.map(v => stringify(v, space)).join(`,${space}`)}${space}]`;\n }\n if (value instanceof Uint8Array) {\n return value.toString();\n }\n\n // eslint-disable-next-line ts/switch-exhaustiveness-check\n switch (typeof value) {\n case \"number\": {\n return `${value}`;\n }\n case \"string\": {\n return JSON.stringify(value);\n }\n case \"object\": {\n const keys = Object.keys(value as object).filter(\n key => !isUndefined((value as any)[key])\n );\n\n return `{${space}${keys\n .map(\n key =>\n `${invalidKeyChars.some(invalidKeyChar => key.includes(invalidKeyChar)) ? `\"${key}\"` : key}: ${space}${stringify((value as any)[key], space)}`\n )\n .join(`,${space}`)}${space}}`;\n }\n default:\n return \"null\";\n }\n};\n"],"mappings":"8HAqBA,MAAa,EAAkB,8CAiC9B,CASY,GACX,EACA,EAA2B,IAChB,CACX,IAAM,EAAQ,EAAS,EAAQ,CAAG,IAAI,OAAO,EAAQ,CAAG,EAExD,OAAQ,EAAR,CACE,KAAK,KACH,MAAO,OAET,KAAK,IAAA,GACH,MAAO,cAET,IAAK,GACH,MAAO,OAET,IAAK,GACH,MAAO,QAET,IAAK,KACH,MAAO,WAET,IAAK,KACH,MAAO,YAIX,GAAI,MAAM,QAAQ,EAAM,CACtB,MAAO,IAAI,IAAQ,EAAM,IAAI,GAAK,EAAU,EAAG,EAAM,CAAC,CAAC,KAAK,IAAI,IAAQ,GAAG,EAAM,GAEnF,GAAI,aAAiB,WACnB,OAAO,EAAM,UAAU,CAIzB,OAAQ,OAAO,EAAf,CACE,IAAK,SACH,MAAO,GAAG,IAEZ,IAAK,SACH,OAAO,KAAK,UAAU,EAAM,CAE9B,IAAK,SAKH,MAAO,IAAI,IAJE,OAAO,KAAK,EAAgB,CAAC,OACxC,GAAO,CAAC,EAAa,EAAc,GAAK,CACzC,CAGE,IACC,GACE,GAAG,EAAgB,KAAK,GAAkB,EAAI,SAAS,EAAe,CAAC,CAAG,IAAI,EAAI,GAAK,EAAI,IAAI,IAAQ,EAAW,EAAc,GAAM,EAAM,GAC/I,CACA,KAAK,IAAI,IAAQ,GAAG,EAAM,GAE/B,QACE,MAAO"}
1
+ {"version":3,"file":"stringify.mjs","names":[],"sources":["../../src/utils/stringify.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { isNumber } from \"@stryke/type-checks/is-number\";\nimport { isUndefined } from \"@stryke/type-checks/is-undefined\";\n\nexport const invalidKeyChars = [\n \"@\",\n \"/\",\n \"#\",\n \"$\",\n \" \",\n \":\",\n \";\",\n \",\",\n \".\",\n \"!\",\n \"?\",\n \"&\",\n \"=\",\n \"+\",\n \"-\",\n \"*\",\n \"%\",\n \"^\",\n \"~\",\n \"|\",\n \"\\\\\",\n '\"',\n \"'\",\n \"`\",\n \"{\",\n \"}\",\n \"[\",\n \"]\",\n \"(\",\n \")\",\n \"<\",\n \">\"\n] as const;\n\n/**\n * Stringify a value to a JSON-like string.\n *\n * @param value - The value to stringify\n * @param spacing - The spacing to use for the stringification\n * @returns The stringified value\n */\nexport const stringify = (\n value: unknown,\n spacing: string | number = 2\n): string => {\n const space = isNumber(spacing) ? \" \".repeat(spacing) : spacing;\n\n switch (value) {\n case null: {\n return \"null\";\n }\n case undefined: {\n return '\"undefined\"';\n }\n case true: {\n return \"true\";\n }\n case false: {\n return \"false\";\n }\n case Number.POSITIVE_INFINITY: {\n return \"infinity\";\n }\n case Number.NEGATIVE_INFINITY: {\n return \"-infinity\";\n }\n }\n\n if (Array.isArray(value)) {\n return `[${space}${value.map(v => stringify(v, space)).join(`,${space}`)}${space}]`;\n }\n if (value instanceof Uint8Array) {\n return value.toString();\n }\n\n // eslint-disable-next-line ts/switch-exhaustiveness-check\n switch (typeof value) {\n case \"number\": {\n return `${value}`;\n }\n case \"string\": {\n return JSON.stringify(value);\n }\n case \"object\": {\n const keys = Object.keys(value as object).filter(\n key => !isUndefined((value as any)[key])\n );\n\n return `{${space}${keys\n .map(\n key =>\n `${invalidKeyChars.some(invalidKeyChar => key.includes(invalidKeyChar)) ? `\"${key}\"` : key}: ${space}${stringify((value as any)[key], space)}`\n )\n .join(`,${space}`)}${space}}`;\n }\n default:\n return \"null\";\n }\n};\n"],"mappings":";;;;AAqBA,MAAa,kBAAkB;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;;;;;;;AASD,MAAa,aACX,OACA,UAA2B,MAChB;CACX,MAAM,QAAQ,SAAS,QAAQ,GAAG,IAAI,OAAO,QAAQ,GAAG;AAExD,SAAQ,OAAR;EACE,KAAK,KACH,QAAO;EAET,KAAK,OACH,QAAO;EAET,KAAK,KACH,QAAO;EAET,KAAK,MACH,QAAO;EAET,KAAK,OAAO,kBACV,QAAO;EAET,KAAK,OAAO,kBACV,QAAO;;AAIX,KAAI,MAAM,QAAQ,MAAM,CACtB,QAAO,IAAI,QAAQ,MAAM,KAAI,MAAK,UAAU,GAAG,MAAM,CAAC,CAAC,KAAK,IAAI,QAAQ,GAAG,MAAM;AAEnF,KAAI,iBAAiB,WACnB,QAAO,MAAM,UAAU;AAIzB,SAAQ,OAAO,OAAf;EACE,KAAK,SACH,QAAO,GAAG;EAEZ,KAAK,SACH,QAAO,KAAK,UAAU,MAAM;EAE9B,KAAK,SAKH,QAAO,IAAI,QAJE,OAAO,KAAK,MAAgB,CAAC,QACxC,QAAO,CAAC,YAAa,MAAc,KAAK,CACzC,CAGE,KACC,QACE,GAAG,gBAAgB,MAAK,mBAAkB,IAAI,SAAS,eAAe,CAAC,GAAG,IAAI,IAAI,KAAK,IAAI,IAAI,QAAQ,UAAW,MAAc,MAAM,MAAM,GAC/I,CACA,KAAK,IAAI,QAAQ,GAAG,MAAM;EAE/B,QACE,QAAO"}
@@ -1,4 +1,86 @@
1
- const e=require(`../types/src/base.cjs`),t=Symbol(`singleComment`),n=Symbol(`multiComment`);function r(){return``}function i(e,t,n){return e.slice(t,n).replace(/\S/g,` `)}function a(e,t){let n=t-1,r=0;for(;e[n]===`\\`;)--n,r+=1;return!!(r%2)}function o(o,{whitespace:s=!0,trailingCommas:c=!1}={}){if(typeof o!=`string`)throw TypeError(`Expected argument \`jsonString\` to be a \`string\`, got \`${typeof o}\``);let l=s?i:r,u=!1,d=!1,f=0,p=``,m=``,h=-1;for(let r=0;r<o.length;r++){let i=o[r],s=o[r+1];!d&&i===`"`&&(a(o,r)||(u=!u)),!u&&(!d&&i+(s??e.EMPTY_STRING)===`//`?(p+=o.slice(f,r),f=r,d=t,r++):d===t&&i+(s??e.EMPTY_STRING)===`\r
2
- `?(r++,d=!1,p+=l(o,f,r),f=r):d===t&&i===`
3
- `?(d=!1,p+=l(o,f,r),f=r):!d&&i+(s??e.EMPTY_STRING)===`/*`?(p+=o.slice(f,r),f=r,d=n,r++):d===n&&i+(s??e.EMPTY_STRING)===`*/`?(r++,d=!1,p+=l(o,f,r+1),f=r+1):c&&!d&&(h===-1?i===`,`&&(m+=p+o.slice(f,r),p=``,f=r,h=r):i===`}`||i===`]`?(p+=o.slice(f,r),m+=l(p,0,1)+p.slice(1),p=``,f=r,h=-1):i!==` `&&i!==` `&&i!==`\r`&&i!==`
4
- `&&(p+=o.slice(f,r),f=r,h=-1)))}return m+p+(d?l(o.slice(f)):o.slice(f))}exports.stripComments=o;
1
+ const require_base = require('../types/src/base.cjs');
2
+
3
+ //#region src/utils/strip-comments.ts
4
+ const singleComment = Symbol("singleComment");
5
+ const multiComment = Symbol("multiComment");
6
+ function stripWithoutWhitespace() {
7
+ return "";
8
+ }
9
+ function stripWithWhitespace(value, start, end) {
10
+ return value.slice(start, end).replace(/\S/g, " ");
11
+ }
12
+ function isEscaped(value, quotePosition) {
13
+ let index = quotePosition - 1;
14
+ let backslashCount = 0;
15
+ while (value[index] === "\\") {
16
+ index -= 1;
17
+ backslashCount += 1;
18
+ }
19
+ return Boolean(backslashCount % 2);
20
+ }
21
+ function stripComments(value, { whitespace = true, trailingCommas = false } = {}) {
22
+ if (typeof value !== "string") throw new TypeError(`Expected argument \`jsonString\` to be a \`string\`, got \`${typeof value}\``);
23
+ const strip = whitespace ? stripWithWhitespace : stripWithoutWhitespace;
24
+ let isInsideString = false;
25
+ let isInsideComment = false;
26
+ let offset = 0;
27
+ let buffer = "";
28
+ let result = "";
29
+ let commaIndex = -1;
30
+ for (let index = 0; index < value.length; index++) {
31
+ const currentCharacter = value[index];
32
+ const nextCharacter = value[index + 1];
33
+ if (!isInsideComment && currentCharacter === "\"") {
34
+ if (!isEscaped(value, index)) isInsideString = !isInsideString;
35
+ }
36
+ if (isInsideString) continue;
37
+ if (!isInsideComment && currentCharacter + (nextCharacter ?? require_base.EMPTY_STRING) === "//") {
38
+ buffer += value.slice(offset, index);
39
+ offset = index;
40
+ isInsideComment = singleComment;
41
+ index++;
42
+ } else if (isInsideComment === singleComment && currentCharacter + (nextCharacter ?? require_base.EMPTY_STRING) === "\r\n") {
43
+ index++;
44
+ isInsideComment = false;
45
+ buffer += strip(value, offset, index);
46
+ offset = index;
47
+ } else if (isInsideComment === singleComment && currentCharacter === "\n") {
48
+ isInsideComment = false;
49
+ buffer += strip(value, offset, index);
50
+ offset = index;
51
+ } else if (!isInsideComment && currentCharacter + (nextCharacter ?? require_base.EMPTY_STRING) === "/*") {
52
+ buffer += value.slice(offset, index);
53
+ offset = index;
54
+ isInsideComment = multiComment;
55
+ index++;
56
+ } else if (isInsideComment === multiComment && currentCharacter + (nextCharacter ?? require_base.EMPTY_STRING) === "*/") {
57
+ index++;
58
+ isInsideComment = false;
59
+ buffer += strip(value, offset, index + 1);
60
+ offset = index + 1;
61
+ } else if (trailingCommas && !isInsideComment) {
62
+ if (commaIndex !== -1) {
63
+ if (currentCharacter === "}" || currentCharacter === "]") {
64
+ buffer += value.slice(offset, index);
65
+ result += strip(buffer, 0, 1) + buffer.slice(1);
66
+ buffer = "";
67
+ offset = index;
68
+ commaIndex = -1;
69
+ } else if (currentCharacter !== " " && currentCharacter !== " " && currentCharacter !== "\r" && currentCharacter !== "\n") {
70
+ buffer += value.slice(offset, index);
71
+ offset = index;
72
+ commaIndex = -1;
73
+ }
74
+ } else if (currentCharacter === ",") {
75
+ result += buffer + value.slice(offset, index);
76
+ buffer = "";
77
+ offset = index;
78
+ commaIndex = index;
79
+ }
80
+ }
81
+ }
82
+ return result + buffer + (isInsideComment ? strip(value.slice(offset)) : value.slice(offset));
83
+ }
84
+
85
+ //#endregion
86
+ exports.stripComments = stripComments;
@@ -1,5 +1,87 @@
1
- import{EMPTY_STRING as e}from"../types/src/base.mjs";const t=Symbol(`singleComment`),n=Symbol(`multiComment`);function r(){return``}function i(e,t,n){return e.slice(t,n).replace(/\S/g,` `)}function a(e,t){let n=t-1,r=0;for(;e[n]===`\\`;)--n,r+=1;return!!(r%2)}function o(o,{whitespace:s=!0,trailingCommas:c=!1}={}){if(typeof o!=`string`)throw TypeError(`Expected argument \`jsonString\` to be a \`string\`, got \`${typeof o}\``);let l=s?i:r,u=!1,d=!1,f=0,p=``,m=``,h=-1;for(let r=0;r<o.length;r++){let i=o[r],s=o[r+1];!d&&i===`"`&&(a(o,r)||(u=!u)),!u&&(!d&&i+(s??e)===`//`?(p+=o.slice(f,r),f=r,d=t,r++):d===t&&i+(s??e)===`\r
2
- `?(r++,d=!1,p+=l(o,f,r),f=r):d===t&&i===`
3
- `?(d=!1,p+=l(o,f,r),f=r):!d&&i+(s??e)===`/*`?(p+=o.slice(f,r),f=r,d=n,r++):d===n&&i+(s??e)===`*/`?(r++,d=!1,p+=l(o,f,r+1),f=r+1):c&&!d&&(h===-1?i===`,`&&(m+=p+o.slice(f,r),p=``,f=r,h=r):i===`}`||i===`]`?(p+=o.slice(f,r),m+=l(p,0,1)+p.slice(1),p=``,f=r,h=-1):i!==` `&&i!==` `&&i!==`\r`&&i!==`
4
- `&&(p+=o.slice(f,r),f=r,h=-1)))}return m+p+(d?l(o.slice(f)):o.slice(f))}export{o as stripComments};
1
+ import { EMPTY_STRING } from "../types/src/base.mjs";
2
+
3
+ //#region src/utils/strip-comments.ts
4
+ const singleComment = Symbol("singleComment");
5
+ const multiComment = Symbol("multiComment");
6
+ function stripWithoutWhitespace() {
7
+ return "";
8
+ }
9
+ function stripWithWhitespace(value, start, end) {
10
+ return value.slice(start, end).replace(/\S/g, " ");
11
+ }
12
+ function isEscaped(value, quotePosition) {
13
+ let index = quotePosition - 1;
14
+ let backslashCount = 0;
15
+ while (value[index] === "\\") {
16
+ index -= 1;
17
+ backslashCount += 1;
18
+ }
19
+ return Boolean(backslashCount % 2);
20
+ }
21
+ function stripComments(value, { whitespace = true, trailingCommas = false } = {}) {
22
+ if (typeof value !== "string") throw new TypeError(`Expected argument \`jsonString\` to be a \`string\`, got \`${typeof value}\``);
23
+ const strip = whitespace ? stripWithWhitespace : stripWithoutWhitespace;
24
+ let isInsideString = false;
25
+ let isInsideComment = false;
26
+ let offset = 0;
27
+ let buffer = "";
28
+ let result = "";
29
+ let commaIndex = -1;
30
+ for (let index = 0; index < value.length; index++) {
31
+ const currentCharacter = value[index];
32
+ const nextCharacter = value[index + 1];
33
+ if (!isInsideComment && currentCharacter === "\"") {
34
+ if (!isEscaped(value, index)) isInsideString = !isInsideString;
35
+ }
36
+ if (isInsideString) continue;
37
+ if (!isInsideComment && currentCharacter + (nextCharacter ?? EMPTY_STRING) === "//") {
38
+ buffer += value.slice(offset, index);
39
+ offset = index;
40
+ isInsideComment = singleComment;
41
+ index++;
42
+ } else if (isInsideComment === singleComment && currentCharacter + (nextCharacter ?? EMPTY_STRING) === "\r\n") {
43
+ index++;
44
+ isInsideComment = false;
45
+ buffer += strip(value, offset, index);
46
+ offset = index;
47
+ } else if (isInsideComment === singleComment && currentCharacter === "\n") {
48
+ isInsideComment = false;
49
+ buffer += strip(value, offset, index);
50
+ offset = index;
51
+ } else if (!isInsideComment && currentCharacter + (nextCharacter ?? EMPTY_STRING) === "/*") {
52
+ buffer += value.slice(offset, index);
53
+ offset = index;
54
+ isInsideComment = multiComment;
55
+ index++;
56
+ } else if (isInsideComment === multiComment && currentCharacter + (nextCharacter ?? EMPTY_STRING) === "*/") {
57
+ index++;
58
+ isInsideComment = false;
59
+ buffer += strip(value, offset, index + 1);
60
+ offset = index + 1;
61
+ } else if (trailingCommas && !isInsideComment) {
62
+ if (commaIndex !== -1) {
63
+ if (currentCharacter === "}" || currentCharacter === "]") {
64
+ buffer += value.slice(offset, index);
65
+ result += strip(buffer, 0, 1) + buffer.slice(1);
66
+ buffer = "";
67
+ offset = index;
68
+ commaIndex = -1;
69
+ } else if (currentCharacter !== " " && currentCharacter !== " " && currentCharacter !== "\r" && currentCharacter !== "\n") {
70
+ buffer += value.slice(offset, index);
71
+ offset = index;
72
+ commaIndex = -1;
73
+ }
74
+ } else if (currentCharacter === ",") {
75
+ result += buffer + value.slice(offset, index);
76
+ buffer = "";
77
+ offset = index;
78
+ commaIndex = index;
79
+ }
80
+ }
81
+ }
82
+ return result + buffer + (isInsideComment ? strip(value.slice(offset)) : value.slice(offset));
83
+ }
84
+
85
+ //#endregion
86
+ export { stripComments };
5
87
  //# sourceMappingURL=strip-comments.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"strip-comments.mjs","names":["isInsideString: boolean | symbol","isInsideComment: boolean | symbol"],"sources":["../../src/utils/strip-comments.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 { EMPTY_STRING } from \"@stryke/types/base\";\n\nconst singleComment = Symbol(\"singleComment\");\nconst multiComment = Symbol(\"multiComment\");\n\nfunction stripWithoutWhitespace() {\n return \"\";\n}\nfunction stripWithWhitespace(value: string, start?: number, end?: number) {\n return value.slice(start, end).replace(/\\S/g, \" \");\n}\n\nfunction isEscaped(value: string, quotePosition: number) {\n let index = quotePosition - 1;\n let backslashCount = 0;\n while (value[index] === \"\\\\\") {\n index -= 1;\n backslashCount += 1;\n }\n\n return Boolean(backslashCount % 2);\n}\n\nexport function stripComments(\n value: string,\n { whitespace = true, trailingCommas = false } = {}\n) {\n if (typeof value !== \"string\") {\n throw new TypeError(\n `Expected argument \\`jsonString\\` to be a \\`string\\`, got \\`${typeof value}\\``\n );\n }\n\n const strip = whitespace ? stripWithWhitespace : stripWithoutWhitespace;\n let isInsideString: boolean | symbol = false;\n let isInsideComment: boolean | symbol = false;\n let offset = 0;\n let buffer = \"\";\n let result = \"\";\n let commaIndex = -1;\n for (let index = 0; index < value.length; index++) {\n const currentCharacter = value[index];\n const nextCharacter = value[index + 1];\n if (!isInsideComment && currentCharacter === '\"') {\n const escaped = isEscaped(value, index);\n if (!escaped) {\n isInsideString = !isInsideString;\n }\n }\n if (isInsideString) {\n continue;\n }\n if (\n !isInsideComment &&\n currentCharacter + (nextCharacter ?? EMPTY_STRING) === \"//\"\n ) {\n buffer += value.slice(offset, index);\n offset = index;\n isInsideComment = singleComment;\n index++;\n } else if (\n isInsideComment === singleComment &&\n currentCharacter + (nextCharacter ?? EMPTY_STRING) === \"\\r\\n\"\n ) {\n index++;\n isInsideComment = false;\n buffer += strip(value, offset, index);\n offset = index;\n } else if (isInsideComment === singleComment && currentCharacter === \"\\n\") {\n isInsideComment = false;\n buffer += strip(value, offset, index);\n offset = index;\n } else if (\n !isInsideComment &&\n currentCharacter + (nextCharacter ?? EMPTY_STRING) === \"/*\"\n ) {\n buffer += value.slice(offset, index);\n offset = index;\n isInsideComment = multiComment;\n index++;\n } else if (\n isInsideComment === multiComment &&\n currentCharacter + (nextCharacter ?? EMPTY_STRING) === \"*/\"\n ) {\n index++;\n isInsideComment = false;\n buffer += strip(value, offset, index + 1);\n offset = index + 1;\n } else if (trailingCommas && !isInsideComment) {\n if (commaIndex !== -1) {\n if (currentCharacter === \"}\" || currentCharacter === \"]\") {\n buffer += value.slice(offset, index);\n result += strip(buffer, 0, 1) + buffer.slice(1);\n buffer = \"\";\n offset = index;\n commaIndex = -1;\n } else if (\n currentCharacter !== \" \" &&\n currentCharacter !== \"\t\" &&\n currentCharacter !== \"\\r\" &&\n currentCharacter !== \"\\n\"\n ) {\n buffer += value.slice(offset, index);\n offset = index;\n commaIndex = -1;\n }\n } else if (currentCharacter === \",\") {\n result += buffer + value.slice(offset, index);\n buffer = \"\";\n offset = index;\n commaIndex = index;\n }\n }\n }\n\n return (\n result +\n buffer +\n (isInsideComment ? strip(value.slice(offset)) : value.slice(offset))\n );\n}\n"],"mappings":"qDAoBA,MAAM,EAAgB,OAAO,gBAAgB,CACvC,EAAe,OAAO,eAAe,CAE3C,SAAS,GAAyB,CAChC,MAAO,GAET,SAAS,EAAoB,EAAe,EAAgB,EAAc,CACxE,OAAO,EAAM,MAAM,EAAO,EAAI,CAAC,QAAQ,MAAO,IAAI,CAGpD,SAAS,EAAU,EAAe,EAAuB,CACvD,IAAI,EAAQ,EAAgB,EACxB,EAAiB,EACrB,KAAO,EAAM,KAAW,MACtB,IACA,GAAkB,EAGpB,MAAO,GAAQ,EAAiB,GAGlC,SAAgB,EACd,EACA,CAAE,aAAa,GAAM,iBAAiB,IAAU,EAAE,CAClD,CACA,GAAI,OAAO,GAAU,SACnB,MAAU,UACR,8DAA8D,OAAO,EAAM,IAC5E,CAGH,IAAM,EAAQ,EAAa,EAAsB,EAC7CA,EAAmC,GACnCC,EAAoC,GACpC,EAAS,EACT,EAAS,GACT,EAAS,GACT,EAAa,GACjB,IAAK,IAAI,EAAQ,EAAG,EAAQ,EAAM,OAAQ,IAAS,CACjD,IAAM,EAAmB,EAAM,GACzB,EAAgB,EAAM,EAAQ,GAChC,CAAC,GAAmB,IAAqB,MAC3B,EAAU,EAAO,EAAM,GAErC,EAAiB,CAAC,IAGlB,KAIF,CAAC,GACD,GAAoB,GAAiB,KAAkB,MAEvD,GAAU,EAAM,MAAM,EAAQ,EAAM,CACpC,EAAS,EACT,EAAkB,EAClB,KAEA,IAAoB,GACpB,GAAoB,GAAiB,KAAkB;GAEvD,IACA,EAAkB,GAClB,GAAU,EAAM,EAAO,EAAQ,EAAM,CACrC,EAAS,GACA,IAAoB,GAAiB,IAAqB;GACnE,EAAkB,GAClB,GAAU,EAAM,EAAO,EAAQ,EAAM,CACrC,EAAS,GAET,CAAC,GACD,GAAoB,GAAiB,KAAkB,MAEvD,GAAU,EAAM,MAAM,EAAQ,EAAM,CACpC,EAAS,EACT,EAAkB,EAClB,KAEA,IAAoB,GACpB,GAAoB,GAAiB,KAAkB,MAEvD,IACA,EAAkB,GAClB,GAAU,EAAM,EAAO,EAAQ,EAAQ,EAAE,CACzC,EAAS,EAAQ,GACR,GAAkB,CAAC,IACxB,IAAe,GAiBR,IAAqB,MAC9B,GAAU,EAAS,EAAM,MAAM,EAAQ,EAAM,CAC7C,EAAS,GACT,EAAS,EACT,EAAa,GApBT,IAAqB,KAAO,IAAqB,KACnD,GAAU,EAAM,MAAM,EAAQ,EAAM,CACpC,GAAU,EAAM,EAAQ,EAAG,EAAE,CAAG,EAAO,MAAM,EAAE,CAC/C,EAAS,GACT,EAAS,EACT,EAAa,IAEb,IAAqB,KACrB,IAAqB,KACrB,IAAqB,MACrB,IAAqB;IAErB,GAAU,EAAM,MAAM,EAAQ,EAAM,CACpC,EAAS,EACT,EAAa,MAWrB,OACE,EACA,GACC,EAAkB,EAAM,EAAM,MAAM,EAAO,CAAC,CAAG,EAAM,MAAM,EAAO"}
1
+ {"version":3,"file":"strip-comments.mjs","names":["isInsideString: boolean | symbol","isInsideComment: boolean | symbol"],"sources":["../../src/utils/strip-comments.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 { EMPTY_STRING } from \"@stryke/types/base\";\n\nconst singleComment = Symbol(\"singleComment\");\nconst multiComment = Symbol(\"multiComment\");\n\nfunction stripWithoutWhitespace() {\n return \"\";\n}\nfunction stripWithWhitespace(value: string, start?: number, end?: number) {\n return value.slice(start, end).replace(/\\S/g, \" \");\n}\n\nfunction isEscaped(value: string, quotePosition: number) {\n let index = quotePosition - 1;\n let backslashCount = 0;\n while (value[index] === \"\\\\\") {\n index -= 1;\n backslashCount += 1;\n }\n\n return Boolean(backslashCount % 2);\n}\n\nexport function stripComments(\n value: string,\n { whitespace = true, trailingCommas = false } = {}\n) {\n if (typeof value !== \"string\") {\n throw new TypeError(\n `Expected argument \\`jsonString\\` to be a \\`string\\`, got \\`${typeof value}\\``\n );\n }\n\n const strip = whitespace ? stripWithWhitespace : stripWithoutWhitespace;\n let isInsideString: boolean | symbol = false;\n let isInsideComment: boolean | symbol = false;\n let offset = 0;\n let buffer = \"\";\n let result = \"\";\n let commaIndex = -1;\n for (let index = 0; index < value.length; index++) {\n const currentCharacter = value[index];\n const nextCharacter = value[index + 1];\n if (!isInsideComment && currentCharacter === '\"') {\n const escaped = isEscaped(value, index);\n if (!escaped) {\n isInsideString = !isInsideString;\n }\n }\n if (isInsideString) {\n continue;\n }\n if (\n !isInsideComment &&\n currentCharacter + (nextCharacter ?? EMPTY_STRING) === \"//\"\n ) {\n buffer += value.slice(offset, index);\n offset = index;\n isInsideComment = singleComment;\n index++;\n } else if (\n isInsideComment === singleComment &&\n currentCharacter + (nextCharacter ?? EMPTY_STRING) === \"\\r\\n\"\n ) {\n index++;\n isInsideComment = false;\n buffer += strip(value, offset, index);\n offset = index;\n } else if (isInsideComment === singleComment && currentCharacter === \"\\n\") {\n isInsideComment = false;\n buffer += strip(value, offset, index);\n offset = index;\n } else if (\n !isInsideComment &&\n currentCharacter + (nextCharacter ?? EMPTY_STRING) === \"/*\"\n ) {\n buffer += value.slice(offset, index);\n offset = index;\n isInsideComment = multiComment;\n index++;\n } else if (\n isInsideComment === multiComment &&\n currentCharacter + (nextCharacter ?? EMPTY_STRING) === \"*/\"\n ) {\n index++;\n isInsideComment = false;\n buffer += strip(value, offset, index + 1);\n offset = index + 1;\n } else if (trailingCommas && !isInsideComment) {\n if (commaIndex !== -1) {\n if (currentCharacter === \"}\" || currentCharacter === \"]\") {\n buffer += value.slice(offset, index);\n result += strip(buffer, 0, 1) + buffer.slice(1);\n buffer = \"\";\n offset = index;\n commaIndex = -1;\n } else if (\n currentCharacter !== \" \" &&\n currentCharacter !== \"\t\" &&\n currentCharacter !== \"\\r\" &&\n currentCharacter !== \"\\n\"\n ) {\n buffer += value.slice(offset, index);\n offset = index;\n commaIndex = -1;\n }\n } else if (currentCharacter === \",\") {\n result += buffer + value.slice(offset, index);\n buffer = \"\";\n offset = index;\n commaIndex = index;\n }\n }\n }\n\n return (\n result +\n buffer +\n (isInsideComment ? strip(value.slice(offset)) : value.slice(offset))\n );\n}\n"],"mappings":";;;AAoBA,MAAM,gBAAgB,OAAO,gBAAgB;AAC7C,MAAM,eAAe,OAAO,eAAe;AAE3C,SAAS,yBAAyB;AAChC,QAAO;;AAET,SAAS,oBAAoB,OAAe,OAAgB,KAAc;AACxE,QAAO,MAAM,MAAM,OAAO,IAAI,CAAC,QAAQ,OAAO,IAAI;;AAGpD,SAAS,UAAU,OAAe,eAAuB;CACvD,IAAI,QAAQ,gBAAgB;CAC5B,IAAI,iBAAiB;AACrB,QAAO,MAAM,WAAW,MAAM;AAC5B,WAAS;AACT,oBAAkB;;AAGpB,QAAO,QAAQ,iBAAiB,EAAE;;AAGpC,SAAgB,cACd,OACA,EAAE,aAAa,MAAM,iBAAiB,UAAU,EAAE,EAClD;AACA,KAAI,OAAO,UAAU,SACnB,OAAM,IAAI,UACR,8DAA8D,OAAO,MAAM,IAC5E;CAGH,MAAM,QAAQ,aAAa,sBAAsB;CACjD,IAAIA,iBAAmC;CACvC,IAAIC,kBAAoC;CACxC,IAAI,SAAS;CACb,IAAI,SAAS;CACb,IAAI,SAAS;CACb,IAAI,aAAa;AACjB,MAAK,IAAI,QAAQ,GAAG,QAAQ,MAAM,QAAQ,SAAS;EACjD,MAAM,mBAAmB,MAAM;EAC/B,MAAM,gBAAgB,MAAM,QAAQ;AACpC,MAAI,CAAC,mBAAmB,qBAAqB,MAE3C;OAAI,CADY,UAAU,OAAO,MAAM,CAErC,kBAAiB,CAAC;;AAGtB,MAAI,eACF;AAEF,MACE,CAAC,mBACD,oBAAoB,iBAAiB,kBAAkB,MACvD;AACA,aAAU,MAAM,MAAM,QAAQ,MAAM;AACpC,YAAS;AACT,qBAAkB;AAClB;aAEA,oBAAoB,iBACpB,oBAAoB,iBAAiB,kBAAkB,QACvD;AACA;AACA,qBAAkB;AAClB,aAAU,MAAM,OAAO,QAAQ,MAAM;AACrC,YAAS;aACA,oBAAoB,iBAAiB,qBAAqB,MAAM;AACzE,qBAAkB;AAClB,aAAU,MAAM,OAAO,QAAQ,MAAM;AACrC,YAAS;aAET,CAAC,mBACD,oBAAoB,iBAAiB,kBAAkB,MACvD;AACA,aAAU,MAAM,MAAM,QAAQ,MAAM;AACpC,YAAS;AACT,qBAAkB;AAClB;aAEA,oBAAoB,gBACpB,oBAAoB,iBAAiB,kBAAkB,MACvD;AACA;AACA,qBAAkB;AAClB,aAAU,MAAM,OAAO,QAAQ,QAAQ,EAAE;AACzC,YAAS,QAAQ;aACR,kBAAkB,CAAC,iBAC5B;OAAI,eAAe,IACjB;QAAI,qBAAqB,OAAO,qBAAqB,KAAK;AACxD,eAAU,MAAM,MAAM,QAAQ,MAAM;AACpC,eAAU,MAAM,QAAQ,GAAG,EAAE,GAAG,OAAO,MAAM,EAAE;AAC/C,cAAS;AACT,cAAS;AACT,kBAAa;eAEb,qBAAqB,OACrB,qBAAqB,OACrB,qBAAqB,QACrB,qBAAqB,MACrB;AACA,eAAU,MAAM,MAAM,QAAQ,MAAM;AACpC,cAAS;AACT,kBAAa;;cAEN,qBAAqB,KAAK;AACnC,cAAU,SAAS,MAAM,MAAM,QAAQ,MAAM;AAC7C,aAAS;AACT,aAAS;AACT,iBAAa;;;;AAKnB,QACE,SACA,UACC,kBAAkB,MAAM,MAAM,MAAM,OAAO,CAAC,GAAG,MAAM,MAAM,OAAO"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/json",
3
- "version": "0.9.36",
3
+ "version": "0.9.37",
4
4
  "type": "module",
5
5
  "description": "A package containing JSON parsing/stringify utilities used by Storm Software.",
6
6
  "repository": {
@@ -64,5 +64,5 @@
64
64
  },
65
65
  "devDependencies": { "@types/node": "^24.10.9", "tsdown": "^0.17.2" },
66
66
  "publishConfig": { "access": "public" },
67
- "gitHead": "8b7fc067d9cb2000a264ca3829f8c94c1b5e4424"
67
+ "gitHead": "9c02f25b3bf83a1228a94fc2ef3fcd816dc0f707"
68
68
  }