@stryke/fs 0.33.31 → 0.33.33

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 (191) 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.d.cts.map +1 -1
  8. package/dist/chmod-x.mjs +87 -1
  9. package/dist/chmod-x.mjs.map +1 -1
  10. package/dist/command-exists.cjs +102 -1
  11. package/dist/command-exists.mjs +100 -1
  12. package/dist/command-exists.mjs.map +1 -1
  13. package/dist/compress.cjs +29 -1
  14. package/dist/compress.mjs +28 -1
  15. package/dist/compress.mjs.map +1 -1
  16. package/dist/constants.mjs +1 -1
  17. package/dist/convert/src/array-buffer-to-string.cjs +19 -1
  18. package/dist/convert/src/array-buffer-to-string.mjs +18 -1
  19. package/dist/convert/src/array-buffer-to-string.mjs.map +1 -1
  20. package/dist/convert/src/to-array.cjs +15 -1
  21. package/dist/convert/src/to-array.mjs +14 -1
  22. package/dist/convert/src/to-array.mjs.map +1 -1
  23. package/dist/convert/src/uint8-array-to-string.cjs +15 -1
  24. package/dist/convert/src/uint8-array-to-string.mjs +15 -1
  25. package/dist/convert/src/uint8-array-to-string.mjs.map +1 -1
  26. package/dist/copy-file.cjs +87 -1
  27. package/dist/copy-file.mjs +83 -1
  28. package/dist/copy-file.mjs.map +1 -1
  29. package/dist/exists.cjs +27 -1
  30. package/dist/exists.mjs +25 -1
  31. package/dist/exists.mjs.map +1 -1
  32. package/dist/get-parent-path.cjs +35 -1
  33. package/dist/get-parent-path.mjs +34 -1
  34. package/dist/get-parent-path.mjs.map +1 -1
  35. package/dist/get-workspace-root.cjs +158 -1
  36. package/dist/get-workspace-root.mjs +150 -1
  37. package/dist/get-workspace-root.mjs.map +1 -1
  38. package/dist/helpers/src/get-unique.cjs +14 -1
  39. package/dist/helpers/src/get-unique.mjs +13 -1
  40. package/dist/helpers/src/get-unique.mjs.map +1 -1
  41. package/dist/helpers.cjs +83 -1
  42. package/dist/helpers.mjs +77 -1
  43. package/dist/helpers.mjs.map +1 -1
  44. package/dist/index.cjs +122 -1
  45. package/dist/index.mjs +25 -1
  46. package/dist/install.cjs +35 -1
  47. package/dist/install.mjs +33 -1
  48. package/dist/install.mjs.map +1 -1
  49. package/dist/is-file.cjs +51 -1
  50. package/dist/is-file.mjs +47 -1
  51. package/dist/is-file.mjs.map +1 -1
  52. package/dist/json/src/storm-json.cjs +117 -1
  53. package/dist/json/src/storm-json.mjs +115 -1
  54. package/dist/json/src/storm-json.mjs.map +1 -1
  55. package/dist/json/src/utils/code-frames.cjs +77 -3
  56. package/dist/json/src/utils/code-frames.mjs +76 -3
  57. package/dist/json/src/utils/code-frames.mjs.map +1 -1
  58. package/dist/json/src/utils/parse-error.cjs +34 -1
  59. package/dist/json/src/utils/parse-error.mjs +33 -1
  60. package/dist/json/src/utils/parse-error.mjs.map +1 -1
  61. package/dist/json/src/utils/parse.cjs +45 -1
  62. package/dist/json/src/utils/parse.mjs +45 -1
  63. package/dist/json/src/utils/parse.mjs.map +1 -1
  64. package/dist/json/src/utils/stringify.cjs +67 -1
  65. package/dist/json/src/utils/stringify.mjs +67 -1
  66. package/dist/json/src/utils/stringify.mjs.map +1 -1
  67. package/dist/json/src/utils/strip-comments.cjs +86 -4
  68. package/dist/json/src/utils/strip-comments.mjs +86 -4
  69. package/dist/json/src/utils/strip-comments.mjs.map +1 -1
  70. package/dist/json.cjs +74 -1
  71. package/dist/json.mjs +71 -1
  72. package/dist/json.mjs.map +1 -1
  73. package/dist/list-files.cjs +86 -1
  74. package/dist/list-files.mjs +79 -1
  75. package/dist/list-files.mjs.map +1 -1
  76. package/dist/package-fns.cjs +148 -1
  77. package/dist/package-fns.mjs +141 -1
  78. package/dist/package-fns.mjs.map +1 -1
  79. package/dist/path/src/append.cjs +57 -1
  80. package/dist/path/src/append.mjs +56 -1
  81. package/dist/path/src/append.mjs.map +1 -1
  82. package/dist/path/src/correct-path.cjs +138 -1
  83. package/dist/path/src/correct-path.mjs +134 -1
  84. package/dist/path/src/correct-path.mjs.map +1 -1
  85. package/dist/path/src/cwd.cjs +17 -1
  86. package/dist/path/src/cwd.mjs +16 -1
  87. package/dist/path/src/cwd.mjs.map +1 -1
  88. package/dist/path/src/file-path-fns.cjs +169 -1
  89. package/dist/path/src/file-path-fns.mjs +164 -1
  90. package/dist/path/src/file-path-fns.mjs.map +1 -1
  91. package/dist/path/src/is-parent-path.cjs +32 -1
  92. package/dist/path/src/is-parent-path.mjs +32 -1
  93. package/dist/path/src/is-parent-path.mjs.map +1 -1
  94. package/dist/path/src/is-root-dir.cjs +14 -1
  95. package/dist/path/src/is-root-dir.mjs +13 -1
  96. package/dist/path/src/is-root-dir.mjs.map +1 -1
  97. package/dist/path/src/is-type.cjs +68 -1
  98. package/dist/path/src/is-type.mjs +66 -1
  99. package/dist/path/src/is-type.mjs.map +1 -1
  100. package/dist/path/src/join-paths.cjs +106 -1
  101. package/dist/path/src/join-paths.mjs +106 -1
  102. package/dist/path/src/join-paths.mjs.map +1 -1
  103. package/dist/path/src/regex.cjs +18 -1
  104. package/dist/path/src/regex.mjs +11 -1
  105. package/dist/path/src/regex.mjs.map +1 -1
  106. package/dist/path/src/replace.cjs +24 -1
  107. package/dist/path/src/replace.mjs +24 -1
  108. package/dist/path/src/replace.mjs.map +1 -1
  109. package/dist/path/src/resolve-parent-path.cjs +18 -1
  110. package/dist/path/src/resolve-parent-path.mjs +18 -1
  111. package/dist/path/src/resolve-parent-path.mjs.map +1 -1
  112. package/dist/path/src/slash.cjs +15 -1
  113. package/dist/path/src/slash.mjs +14 -1
  114. package/dist/path/src/slash.mjs.map +1 -1
  115. package/dist/read-file.cjs +47 -1
  116. package/dist/read-file.mjs +43 -1
  117. package/dist/read-file.mjs.map +1 -1
  118. package/dist/registry.cjs +142 -1
  119. package/dist/registry.mjs +137 -1
  120. package/dist/registry.mjs.map +1 -1
  121. package/dist/remove-file.cjs +27 -1
  122. package/dist/remove-file.mjs +25 -1
  123. package/dist/remove-file.mjs.map +1 -1
  124. package/dist/resolve.cjs +228 -3
  125. package/dist/resolve.mjs +217 -3
  126. package/dist/resolve.mjs.map +1 -1
  127. package/dist/semver-fns.cjs +129 -1
  128. package/dist/semver-fns.mjs +119 -1
  129. package/dist/semver-fns.mjs.map +1 -1
  130. package/dist/string-format/src/package.cjs +92 -1
  131. package/dist/string-format/src/package.mjs +91 -1
  132. package/dist/string-format/src/package.mjs.map +1 -1
  133. package/dist/toml.cjs +66 -3
  134. package/dist/toml.mjs +61 -3
  135. package/dist/toml.mjs.map +1 -1
  136. package/dist/tsconfig.cjs +37 -1
  137. package/dist/tsconfig.mjs +35 -1
  138. package/dist/tsconfig.mjs.map +1 -1
  139. package/dist/type-checks/src/get-object-tag.cjs +15 -1
  140. package/dist/type-checks/src/get-object-tag.mjs +14 -1
  141. package/dist/type-checks/src/get-object-tag.mjs.map +1 -1
  142. package/dist/type-checks/src/index.cjs +14 -1
  143. package/dist/type-checks/src/index.mjs +16 -1
  144. package/dist/type-checks/src/is-buffer.cjs +12 -1
  145. package/dist/type-checks/src/is-buffer.mjs +11 -1
  146. package/dist/type-checks/src/is-buffer.mjs.map +1 -1
  147. package/dist/type-checks/src/is-collection.cjs +1 -1
  148. package/dist/type-checks/src/is-collection.mjs +3 -1
  149. package/dist/type-checks/src/is-empty.cjs +20 -1
  150. package/dist/type-checks/src/is-empty.mjs +20 -1
  151. package/dist/type-checks/src/is-empty.mjs.map +1 -1
  152. package/dist/type-checks/src/is-error.cjs +29 -1
  153. package/dist/type-checks/src/is-error.mjs +29 -1
  154. package/dist/type-checks/src/is-error.mjs.map +1 -1
  155. package/dist/type-checks/src/is-null.cjs +12 -1
  156. package/dist/type-checks/src/is-null.mjs +11 -1
  157. package/dist/type-checks/src/is-null.mjs.map +1 -1
  158. package/dist/type-checks/src/is-number.cjs +18 -1
  159. package/dist/type-checks/src/is-number.mjs +17 -1
  160. package/dist/type-checks/src/is-number.mjs.map +1 -1
  161. package/dist/type-checks/src/is-object.cjs +19 -1
  162. package/dist/type-checks/src/is-object.mjs +19 -1
  163. package/dist/type-checks/src/is-object.mjs.map +1 -1
  164. package/dist/type-checks/src/is-plain-object.cjs +64 -1
  165. package/dist/type-checks/src/is-plain-object.mjs +63 -1
  166. package/dist/type-checks/src/is-plain-object.mjs.map +1 -1
  167. package/dist/type-checks/src/is-set-string.cjs +20 -1
  168. package/dist/type-checks/src/is-set-string.mjs +20 -1
  169. package/dist/type-checks/src/is-set-string.mjs.map +1 -1
  170. package/dist/type-checks/src/is-set.cjs +19 -1
  171. package/dist/type-checks/src/is-set.mjs +19 -1
  172. package/dist/type-checks/src/is-set.mjs.map +1 -1
  173. package/dist/type-checks/src/is-string.cjs +12 -1
  174. package/dist/type-checks/src/is-string.mjs +11 -1
  175. package/dist/type-checks/src/is-string.mjs.map +1 -1
  176. package/dist/type-checks/src/is-undefined.cjs +8 -1
  177. package/dist/type-checks/src/is-undefined.mjs +7 -1
  178. package/dist/type-checks/src/is-undefined.mjs.map +1 -1
  179. package/dist/type-checks/src/type-detect.cjs +15 -1
  180. package/dist/type-checks/src/type-detect.mjs +16 -1
  181. package/dist/type-checks/src/type-detect.mjs.map +1 -1
  182. package/dist/types/src/base.cjs +6 -1
  183. package/dist/types/src/base.mjs +5 -1
  184. package/dist/types/src/base.mjs.map +1 -1
  185. package/dist/write-file.cjs +40 -1
  186. package/dist/write-file.mjs +38 -1
  187. package/dist/write-file.mjs.map +1 -1
  188. package/dist/yaml.cjs +29 -1
  189. package/dist/yaml.mjs +27 -1
  190. package/dist/yaml.mjs.map +1 -1
  191. package/package.json +6 -6
@@ -1 +1,67 @@
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.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 ../json/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.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{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 ../json/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 { stringify };
2
68
  //# sourceMappingURL=stringify.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"stringify.mjs","names":[],"sources":["../../../../../json/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":"0IAqBA,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":["../../../../../json/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 ../json/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 ../json/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":["../../../../../json/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":"2DAoBA,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":["../../../../../json/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/dist/json.cjs CHANGED
@@ -1 +1,74 @@
1
- const e=require(`./type-checks/src/is-error.cjs`),t=require(`./read-file.cjs`),n=require(`./write-file.cjs`),r=require(`./json/src/storm-json.cjs`);function i(n,i){let a=t.readFileSync(n);i&&(i.endsWithNewline=a.codePointAt(a.length-1)===10);try{return r.StormJSON.parseJson(a,i)}catch(t){throw e.isError(t)?(t.message=t.message.replace(`JSON`,n),t):Error(`Failed to parse JSON: ${n}`)}}async function a(n,i){let a=await t.readFile(n);i&&(i.endsWithNewline=a.codePointAt(a.length-1)===10);try{return r.StormJSON.parseJson(a,i)}catch(t){throw e.isError(t)?(t.message=t.message.replace(`JSON`,n),t):Error(`Failed to parse JSON: ${n}`)}}function o(e,t,i){let a=r.StormJSON.stringify(t,i);return n.writeFileSync(e,i?.appendNewLine?`${a}\n`:a)}async function s(e,t,i){let a=r.StormJSON.stringify(t);return n.writeFile(e,i?.appendNewLine?`${a}\n`:a)}exports.readJsonFile=a,exports.readJsonFileSync=i,exports.writeJsonFile=s,exports.writeJsonFileSync=o;
1
+ const require_is_error = require('./type-checks/src/is-error.cjs');
2
+ const require_read_file = require('./read-file.cjs');
3
+ const require_write_file = require('./write-file.cjs');
4
+ const require_storm_json = require('./json/src/storm-json.cjs');
5
+
6
+ //#region src/json.ts
7
+ /**
8
+ * Reads a JSON file and returns the object the JSON content represents.
9
+ *
10
+ * @param path - A path to a file.
11
+ * @param options - JSON parse options
12
+ * @returns Object the JSON content of the file represents
13
+ */
14
+ function readJsonFileSync(path, options) {
15
+ const content = require_read_file.readFileSync(path);
16
+ if (options) options.endsWithNewline = content.codePointAt(content.length - 1) === 10;
17
+ try {
18
+ return require_storm_json.StormJSON.parseJson(content, options);
19
+ } catch (error) {
20
+ if (require_is_error.isError(error)) {
21
+ error.message = error.message.replace("JSON", path);
22
+ throw error;
23
+ }
24
+ throw new Error(`Failed to parse JSON: ${path}`);
25
+ }
26
+ }
27
+ /**
28
+ * Reads a JSON file and returns the object the JSON content represents.
29
+ *
30
+ * @param path - A path to a file.
31
+ * @param options - JSON parse options
32
+ * @returns Object the JSON content of the file represents
33
+ */
34
+ async function readJsonFile(path, options) {
35
+ const content = await require_read_file.readFile(path);
36
+ if (options) options.endsWithNewline = content.codePointAt(content.length - 1) === 10;
37
+ try {
38
+ return require_storm_json.StormJSON.parseJson(content, options);
39
+ } catch (error) {
40
+ if (require_is_error.isError(error)) {
41
+ error.message = error.message.replace("JSON", path);
42
+ throw error;
43
+ }
44
+ throw new Error(`Failed to parse JSON: ${path}`);
45
+ }
46
+ }
47
+ /**
48
+ * Serializes the given data to JSON and writes it to a file.
49
+ *
50
+ * @param path - A path to a file.
51
+ * @param data - data which should be serialized to JSON and written to the file
52
+ * @param options - JSON serialize options
53
+ */
54
+ function writeJsonFileSync(path, data, options) {
55
+ const serializedJson = require_storm_json.StormJSON.stringify(data, options);
56
+ return require_write_file.writeFileSync(path, options?.appendNewLine ? `${serializedJson}\n` : serializedJson);
57
+ }
58
+ /**
59
+ * Serializes the given data to JSON and writes it to a file asynchronously.
60
+ *
61
+ * @param path - A path to a file.
62
+ * @param data - data which should be serialized to JSON and written to the file
63
+ * @param options - JSON serialize options
64
+ */
65
+ async function writeJsonFile(path, data, options) {
66
+ const serializedJson = require_storm_json.StormJSON.stringify(data);
67
+ return require_write_file.writeFile(path, options?.appendNewLine ? `${serializedJson}\n` : serializedJson);
68
+ }
69
+
70
+ //#endregion
71
+ exports.readJsonFile = readJsonFile;
72
+ exports.readJsonFileSync = readJsonFileSync;
73
+ exports.writeJsonFile = writeJsonFile;
74
+ exports.writeJsonFileSync = writeJsonFileSync;
package/dist/json.mjs CHANGED
@@ -1,2 +1,72 @@
1
- import{isError as e}from"./type-checks/src/is-error.mjs";import{readFile as t,readFileSync as n}from"./read-file.mjs";import{writeFile as r,writeFileSync as i}from"./write-file.mjs";import{StormJSON as a}from"./json/src/storm-json.mjs";function o(t,r){let i=n(t);r&&(r.endsWithNewline=i.codePointAt(i.length-1)===10);try{return a.parseJson(i,r)}catch(n){throw e(n)?(n.message=n.message.replace(`JSON`,t),n):Error(`Failed to parse JSON: ${t}`)}}async function s(n,r){let i=await t(n);r&&(r.endsWithNewline=i.codePointAt(i.length-1)===10);try{return a.parseJson(i,r)}catch(t){throw e(t)?(t.message=t.message.replace(`JSON`,n),t):Error(`Failed to parse JSON: ${n}`)}}function c(e,t,n){let r=a.stringify(t,n);return i(e,n?.appendNewLine?`${r}\n`:r)}async function l(e,t,n){let i=a.stringify(t);return r(e,n?.appendNewLine?`${i}\n`:i)}export{s as readJsonFile,o as readJsonFileSync,l as writeJsonFile,c as writeJsonFileSync};
1
+ import { isError } from "./type-checks/src/is-error.mjs";
2
+ import { readFile, readFileSync } from "./read-file.mjs";
3
+ import { writeFile, writeFileSync } from "./write-file.mjs";
4
+ import { StormJSON } from "./json/src/storm-json.mjs";
5
+
6
+ //#region src/json.ts
7
+ /**
8
+ * Reads a JSON file and returns the object the JSON content represents.
9
+ *
10
+ * @param path - A path to a file.
11
+ * @param options - JSON parse options
12
+ * @returns Object the JSON content of the file represents
13
+ */
14
+ function readJsonFileSync(path, options) {
15
+ const content = readFileSync(path);
16
+ if (options) options.endsWithNewline = content.codePointAt(content.length - 1) === 10;
17
+ try {
18
+ return StormJSON.parseJson(content, options);
19
+ } catch (error) {
20
+ if (isError(error)) {
21
+ error.message = error.message.replace("JSON", path);
22
+ throw error;
23
+ }
24
+ throw new Error(`Failed to parse JSON: ${path}`);
25
+ }
26
+ }
27
+ /**
28
+ * Reads a JSON file and returns the object the JSON content represents.
29
+ *
30
+ * @param path - A path to a file.
31
+ * @param options - JSON parse options
32
+ * @returns Object the JSON content of the file represents
33
+ */
34
+ async function readJsonFile(path, options) {
35
+ const content = await readFile(path);
36
+ if (options) options.endsWithNewline = content.codePointAt(content.length - 1) === 10;
37
+ try {
38
+ return StormJSON.parseJson(content, options);
39
+ } catch (error) {
40
+ if (isError(error)) {
41
+ error.message = error.message.replace("JSON", path);
42
+ throw error;
43
+ }
44
+ throw new Error(`Failed to parse JSON: ${path}`);
45
+ }
46
+ }
47
+ /**
48
+ * Serializes the given data to JSON and writes it to a file.
49
+ *
50
+ * @param path - A path to a file.
51
+ * @param data - data which should be serialized to JSON and written to the file
52
+ * @param options - JSON serialize options
53
+ */
54
+ function writeJsonFileSync(path, data, options) {
55
+ const serializedJson = StormJSON.stringify(data, options);
56
+ return writeFileSync(path, options?.appendNewLine ? `${serializedJson}\n` : serializedJson);
57
+ }
58
+ /**
59
+ * Serializes the given data to JSON and writes it to a file asynchronously.
60
+ *
61
+ * @param path - A path to a file.
62
+ * @param data - data which should be serialized to JSON and written to the file
63
+ * @param options - JSON serialize options
64
+ */
65
+ async function writeJsonFile(path, data, options) {
66
+ const serializedJson = StormJSON.stringify(data);
67
+ return writeFile(path, options?.appendNewLine ? `${serializedJson}\n` : serializedJson);
68
+ }
69
+
70
+ //#endregion
71
+ export { readJsonFile, readJsonFileSync, writeJsonFile, writeJsonFileSync };
2
72
  //# sourceMappingURL=json.mjs.map
package/dist/json.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"json.mjs","names":[],"sources":["../src/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 { StormJSON } from \"@stryke/json/storm-json\";\nimport type {\n JsonParseOptions,\n JsonSerializeOptions\n} from \"@stryke/json/types\";\nimport { isError } from \"@stryke/type-checks/is-error\";\nimport { readFile, readFileSync } from \"./read-file\";\nimport { writeFile, writeFileSync } from \"./write-file\";\n\nexport interface JsonReadOptions extends JsonParseOptions {\n /**\n * mutable field recording whether JSON ends with new line\n *\n * @defaultValue false\n */\n endsWithNewline?: boolean;\n}\n\n/**\n * Reads a JSON file and returns the object the JSON content represents.\n *\n * @param path - A path to a file.\n * @param options - JSON parse options\n * @returns Object the JSON content of the file represents\n */\nexport function readJsonFileSync<T extends object = any>(\n path: string,\n options?: JsonReadOptions\n): T {\n const content = readFileSync(path);\n if (options) {\n options.endsWithNewline = content.codePointAt(content.length - 1) === 10;\n }\n\n try {\n return StormJSON.parseJson<T>(content, options);\n } catch (error) {\n if (isError(error)) {\n error.message = error.message.replace(\"JSON\", path);\n throw error;\n }\n\n throw new Error(`Failed to parse JSON: ${path}`);\n }\n}\n\n/**\n * Reads a JSON file and returns the object the JSON content represents.\n *\n * @param path - A path to a file.\n * @param options - JSON parse options\n * @returns Object the JSON content of the file represents\n */\nexport async function readJsonFile<T extends object = any>(\n path: string,\n options?: JsonReadOptions\n): Promise<T> {\n const content = await readFile(path);\n if (options) {\n options.endsWithNewline = content.codePointAt(content.length - 1) === 10;\n }\n\n try {\n return StormJSON.parseJson<T>(content, options);\n } catch (error) {\n if (isError(error)) {\n error.message = error.message.replace(\"JSON\", path);\n throw error;\n }\n\n throw new Error(`Failed to parse JSON: ${path}`);\n }\n}\n\nexport interface JsonWriteOptions extends JsonSerializeOptions {\n /**\n * whether to append new line at the end of JSON file\n *\n * @defaultValue false\n */\n appendNewLine?: boolean;\n}\n\n/**\n * Serializes the given data to JSON and writes it to a file.\n *\n * @param path - A path to a file.\n * @param data - data which should be serialized to JSON and written to the file\n * @param options - JSON serialize options\n */\nexport function writeJsonFileSync<T extends object = object>(\n path: string,\n data: T,\n options?: JsonWriteOptions\n): void {\n const serializedJson = StormJSON.stringify(data, options);\n\n return writeFileSync(\n path,\n options?.appendNewLine ? `${serializedJson}\\n` : serializedJson\n );\n}\n\n/**\n * Serializes the given data to JSON and writes it to a file asynchronously.\n *\n * @param path - A path to a file.\n * @param data - data which should be serialized to JSON and written to the file\n * @param options - JSON serialize options\n */\nexport async function writeJsonFile<T extends object = object>(\n path: string,\n data: T,\n options?: JsonWriteOptions\n): Promise<void> {\n const serializedJson = StormJSON.stringify(data);\n\n return writeFile(\n path,\n options?.appendNewLine ? `${serializedJson}\\n` : serializedJson\n );\n}\n"],"mappings":"4OA2CA,SAAgB,EACd,EACA,EACG,CACH,IAAM,EAAU,EAAa,EAAK,CAC9B,IACF,EAAQ,gBAAkB,EAAQ,YAAY,EAAQ,OAAS,EAAE,GAAK,IAGxE,GAAI,CACF,OAAO,EAAU,UAAa,EAAS,EAAQ,OACxC,EAAO,CAMd,MALI,EAAQ,EAAM,EAChB,EAAM,QAAU,EAAM,QAAQ,QAAQ,OAAQ,EAAK,CAC7C,GAGE,MAAM,yBAAyB,IAAO,EAWpD,eAAsB,EACpB,EACA,EACY,CACZ,IAAM,EAAU,MAAM,EAAS,EAAK,CAChC,IACF,EAAQ,gBAAkB,EAAQ,YAAY,EAAQ,OAAS,EAAE,GAAK,IAGxE,GAAI,CACF,OAAO,EAAU,UAAa,EAAS,EAAQ,OACxC,EAAO,CAMd,MALI,EAAQ,EAAM,EAChB,EAAM,QAAU,EAAM,QAAQ,QAAQ,OAAQ,EAAK,CAC7C,GAGE,MAAM,yBAAyB,IAAO,EAoBpD,SAAgB,EACd,EACA,EACA,EACM,CACN,IAAM,EAAiB,EAAU,UAAU,EAAM,EAAQ,CAEzD,OAAO,EACL,EACA,GAAS,cAAgB,GAAG,EAAe,IAAM,EAClD,CAUH,eAAsB,EACpB,EACA,EACA,EACe,CACf,IAAM,EAAiB,EAAU,UAAU,EAAK,CAEhD,OAAO,EACL,EACA,GAAS,cAAgB,GAAG,EAAe,IAAM,EAClD"}
1
+ {"version":3,"file":"json.mjs","names":[],"sources":["../src/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 { StormJSON } from \"@stryke/json/storm-json\";\nimport type {\n JsonParseOptions,\n JsonSerializeOptions\n} from \"@stryke/json/types\";\nimport { isError } from \"@stryke/type-checks/is-error\";\nimport { readFile, readFileSync } from \"./read-file\";\nimport { writeFile, writeFileSync } from \"./write-file\";\n\nexport interface JsonReadOptions extends JsonParseOptions {\n /**\n * mutable field recording whether JSON ends with new line\n *\n * @defaultValue false\n */\n endsWithNewline?: boolean;\n}\n\n/**\n * Reads a JSON file and returns the object the JSON content represents.\n *\n * @param path - A path to a file.\n * @param options - JSON parse options\n * @returns Object the JSON content of the file represents\n */\nexport function readJsonFileSync<T extends object = any>(\n path: string,\n options?: JsonReadOptions\n): T {\n const content = readFileSync(path);\n if (options) {\n options.endsWithNewline = content.codePointAt(content.length - 1) === 10;\n }\n\n try {\n return StormJSON.parseJson<T>(content, options);\n } catch (error) {\n if (isError(error)) {\n error.message = error.message.replace(\"JSON\", path);\n throw error;\n }\n\n throw new Error(`Failed to parse JSON: ${path}`);\n }\n}\n\n/**\n * Reads a JSON file and returns the object the JSON content represents.\n *\n * @param path - A path to a file.\n * @param options - JSON parse options\n * @returns Object the JSON content of the file represents\n */\nexport async function readJsonFile<T extends object = any>(\n path: string,\n options?: JsonReadOptions\n): Promise<T> {\n const content = await readFile(path);\n if (options) {\n options.endsWithNewline = content.codePointAt(content.length - 1) === 10;\n }\n\n try {\n return StormJSON.parseJson<T>(content, options);\n } catch (error) {\n if (isError(error)) {\n error.message = error.message.replace(\"JSON\", path);\n throw error;\n }\n\n throw new Error(`Failed to parse JSON: ${path}`);\n }\n}\n\nexport interface JsonWriteOptions extends JsonSerializeOptions {\n /**\n * whether to append new line at the end of JSON file\n *\n * @defaultValue false\n */\n appendNewLine?: boolean;\n}\n\n/**\n * Serializes the given data to JSON and writes it to a file.\n *\n * @param path - A path to a file.\n * @param data - data which should be serialized to JSON and written to the file\n * @param options - JSON serialize options\n */\nexport function writeJsonFileSync<T extends object = object>(\n path: string,\n data: T,\n options?: JsonWriteOptions\n): void {\n const serializedJson = StormJSON.stringify(data, options);\n\n return writeFileSync(\n path,\n options?.appendNewLine ? `${serializedJson}\\n` : serializedJson\n );\n}\n\n/**\n * Serializes the given data to JSON and writes it to a file asynchronously.\n *\n * @param path - A path to a file.\n * @param data - data which should be serialized to JSON and written to the file\n * @param options - JSON serialize options\n */\nexport async function writeJsonFile<T extends object = object>(\n path: string,\n data: T,\n options?: JsonWriteOptions\n): Promise<void> {\n const serializedJson = StormJSON.stringify(data);\n\n return writeFile(\n path,\n options?.appendNewLine ? `${serializedJson}\\n` : serializedJson\n );\n}\n"],"mappings":";;;;;;;;;;;;;AA2CA,SAAgB,iBACd,MACA,SACG;CACH,MAAM,UAAU,aAAa,KAAK;AAClC,KAAI,QACF,SAAQ,kBAAkB,QAAQ,YAAY,QAAQ,SAAS,EAAE,KAAK;AAGxE,KAAI;AACF,SAAO,UAAU,UAAa,SAAS,QAAQ;UACxC,OAAO;AACd,MAAI,QAAQ,MAAM,EAAE;AAClB,SAAM,UAAU,MAAM,QAAQ,QAAQ,QAAQ,KAAK;AACnD,SAAM;;AAGR,QAAM,IAAI,MAAM,yBAAyB,OAAO;;;;;;;;;;AAWpD,eAAsB,aACpB,MACA,SACY;CACZ,MAAM,UAAU,MAAM,SAAS,KAAK;AACpC,KAAI,QACF,SAAQ,kBAAkB,QAAQ,YAAY,QAAQ,SAAS,EAAE,KAAK;AAGxE,KAAI;AACF,SAAO,UAAU,UAAa,SAAS,QAAQ;UACxC,OAAO;AACd,MAAI,QAAQ,MAAM,EAAE;AAClB,SAAM,UAAU,MAAM,QAAQ,QAAQ,QAAQ,KAAK;AACnD,SAAM;;AAGR,QAAM,IAAI,MAAM,yBAAyB,OAAO;;;;;;;;;;AAoBpD,SAAgB,kBACd,MACA,MACA,SACM;CACN,MAAM,iBAAiB,UAAU,UAAU,MAAM,QAAQ;AAEzD,QAAO,cACL,MACA,SAAS,gBAAgB,GAAG,eAAe,MAAM,eAClD;;;;;;;;;AAUH,eAAsB,cACpB,MACA,MACA,SACe;CACf,MAAM,iBAAiB,UAAU,UAAU,KAAK;AAEhD,QAAO,UACL,MACA,SAAS,gBAAgB,GAAG,eAAe,MAAM,eAClD"}