@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.
- package/CHANGELOG.md +18 -0
- package/dist/_virtual/rolldown_runtime.cjs +29 -1
- package/dist/buffer.cjs +60 -1
- package/dist/buffer.mjs +56 -1
- package/dist/buffer.mjs.map +1 -1
- package/dist/chmod-x.cjs +93 -1
- package/dist/chmod-x.d.cts.map +1 -1
- package/dist/chmod-x.mjs +87 -1
- package/dist/chmod-x.mjs.map +1 -1
- package/dist/command-exists.cjs +102 -1
- package/dist/command-exists.mjs +100 -1
- package/dist/command-exists.mjs.map +1 -1
- package/dist/compress.cjs +29 -1
- package/dist/compress.mjs +28 -1
- package/dist/compress.mjs.map +1 -1
- package/dist/constants.mjs +1 -1
- package/dist/convert/src/array-buffer-to-string.cjs +19 -1
- package/dist/convert/src/array-buffer-to-string.mjs +18 -1
- package/dist/convert/src/array-buffer-to-string.mjs.map +1 -1
- package/dist/convert/src/to-array.cjs +15 -1
- package/dist/convert/src/to-array.mjs +14 -1
- package/dist/convert/src/to-array.mjs.map +1 -1
- package/dist/convert/src/uint8-array-to-string.cjs +15 -1
- package/dist/convert/src/uint8-array-to-string.mjs +15 -1
- package/dist/convert/src/uint8-array-to-string.mjs.map +1 -1
- package/dist/copy-file.cjs +87 -1
- package/dist/copy-file.mjs +83 -1
- package/dist/copy-file.mjs.map +1 -1
- package/dist/exists.cjs +27 -1
- package/dist/exists.mjs +25 -1
- package/dist/exists.mjs.map +1 -1
- package/dist/get-parent-path.cjs +35 -1
- package/dist/get-parent-path.mjs +34 -1
- package/dist/get-parent-path.mjs.map +1 -1
- package/dist/get-workspace-root.cjs +158 -1
- package/dist/get-workspace-root.mjs +150 -1
- package/dist/get-workspace-root.mjs.map +1 -1
- package/dist/helpers/src/get-unique.cjs +14 -1
- package/dist/helpers/src/get-unique.mjs +13 -1
- package/dist/helpers/src/get-unique.mjs.map +1 -1
- package/dist/helpers.cjs +83 -1
- package/dist/helpers.mjs +77 -1
- package/dist/helpers.mjs.map +1 -1
- package/dist/index.cjs +122 -1
- package/dist/index.mjs +25 -1
- package/dist/install.cjs +35 -1
- package/dist/install.mjs +33 -1
- package/dist/install.mjs.map +1 -1
- package/dist/is-file.cjs +51 -1
- package/dist/is-file.mjs +47 -1
- package/dist/is-file.mjs.map +1 -1
- package/dist/json/src/storm-json.cjs +117 -1
- package/dist/json/src/storm-json.mjs +115 -1
- package/dist/json/src/storm-json.mjs.map +1 -1
- package/dist/json/src/utils/code-frames.cjs +77 -3
- package/dist/json/src/utils/code-frames.mjs +76 -3
- package/dist/json/src/utils/code-frames.mjs.map +1 -1
- package/dist/json/src/utils/parse-error.cjs +34 -1
- package/dist/json/src/utils/parse-error.mjs +33 -1
- package/dist/json/src/utils/parse-error.mjs.map +1 -1
- package/dist/json/src/utils/parse.cjs +45 -1
- package/dist/json/src/utils/parse.mjs +45 -1
- package/dist/json/src/utils/parse.mjs.map +1 -1
- package/dist/json/src/utils/stringify.cjs +67 -1
- package/dist/json/src/utils/stringify.mjs +67 -1
- package/dist/json/src/utils/stringify.mjs.map +1 -1
- package/dist/json/src/utils/strip-comments.cjs +86 -4
- package/dist/json/src/utils/strip-comments.mjs +86 -4
- package/dist/json/src/utils/strip-comments.mjs.map +1 -1
- package/dist/json.cjs +74 -1
- package/dist/json.mjs +71 -1
- package/dist/json.mjs.map +1 -1
- package/dist/list-files.cjs +86 -1
- package/dist/list-files.mjs +79 -1
- package/dist/list-files.mjs.map +1 -1
- package/dist/package-fns.cjs +148 -1
- package/dist/package-fns.mjs +141 -1
- package/dist/package-fns.mjs.map +1 -1
- package/dist/path/src/append.cjs +57 -1
- package/dist/path/src/append.mjs +56 -1
- package/dist/path/src/append.mjs.map +1 -1
- package/dist/path/src/correct-path.cjs +138 -1
- package/dist/path/src/correct-path.mjs +134 -1
- package/dist/path/src/correct-path.mjs.map +1 -1
- package/dist/path/src/cwd.cjs +17 -1
- package/dist/path/src/cwd.mjs +16 -1
- package/dist/path/src/cwd.mjs.map +1 -1
- package/dist/path/src/file-path-fns.cjs +169 -1
- package/dist/path/src/file-path-fns.mjs +164 -1
- package/dist/path/src/file-path-fns.mjs.map +1 -1
- package/dist/path/src/is-parent-path.cjs +32 -1
- package/dist/path/src/is-parent-path.mjs +32 -1
- package/dist/path/src/is-parent-path.mjs.map +1 -1
- package/dist/path/src/is-root-dir.cjs +14 -1
- package/dist/path/src/is-root-dir.mjs +13 -1
- package/dist/path/src/is-root-dir.mjs.map +1 -1
- package/dist/path/src/is-type.cjs +68 -1
- package/dist/path/src/is-type.mjs +66 -1
- package/dist/path/src/is-type.mjs.map +1 -1
- package/dist/path/src/join-paths.cjs +106 -1
- package/dist/path/src/join-paths.mjs +106 -1
- package/dist/path/src/join-paths.mjs.map +1 -1
- package/dist/path/src/regex.cjs +18 -1
- package/dist/path/src/regex.mjs +11 -1
- package/dist/path/src/regex.mjs.map +1 -1
- package/dist/path/src/replace.cjs +24 -1
- package/dist/path/src/replace.mjs +24 -1
- package/dist/path/src/replace.mjs.map +1 -1
- package/dist/path/src/resolve-parent-path.cjs +18 -1
- package/dist/path/src/resolve-parent-path.mjs +18 -1
- package/dist/path/src/resolve-parent-path.mjs.map +1 -1
- package/dist/path/src/slash.cjs +15 -1
- package/dist/path/src/slash.mjs +14 -1
- package/dist/path/src/slash.mjs.map +1 -1
- package/dist/read-file.cjs +47 -1
- package/dist/read-file.mjs +43 -1
- package/dist/read-file.mjs.map +1 -1
- package/dist/registry.cjs +142 -1
- package/dist/registry.mjs +137 -1
- package/dist/registry.mjs.map +1 -1
- package/dist/remove-file.cjs +27 -1
- package/dist/remove-file.mjs +25 -1
- package/dist/remove-file.mjs.map +1 -1
- package/dist/resolve.cjs +228 -3
- package/dist/resolve.mjs +217 -3
- package/dist/resolve.mjs.map +1 -1
- package/dist/semver-fns.cjs +129 -1
- package/dist/semver-fns.mjs +119 -1
- package/dist/semver-fns.mjs.map +1 -1
- package/dist/string-format/src/package.cjs +92 -1
- package/dist/string-format/src/package.mjs +91 -1
- package/dist/string-format/src/package.mjs.map +1 -1
- package/dist/toml.cjs +66 -3
- package/dist/toml.mjs +61 -3
- package/dist/toml.mjs.map +1 -1
- package/dist/tsconfig.cjs +37 -1
- package/dist/tsconfig.mjs +35 -1
- package/dist/tsconfig.mjs.map +1 -1
- package/dist/type-checks/src/get-object-tag.cjs +15 -1
- package/dist/type-checks/src/get-object-tag.mjs +14 -1
- package/dist/type-checks/src/get-object-tag.mjs.map +1 -1
- package/dist/type-checks/src/index.cjs +14 -1
- package/dist/type-checks/src/index.mjs +16 -1
- package/dist/type-checks/src/is-buffer.cjs +12 -1
- package/dist/type-checks/src/is-buffer.mjs +11 -1
- package/dist/type-checks/src/is-buffer.mjs.map +1 -1
- package/dist/type-checks/src/is-collection.cjs +1 -1
- package/dist/type-checks/src/is-collection.mjs +3 -1
- package/dist/type-checks/src/is-empty.cjs +20 -1
- package/dist/type-checks/src/is-empty.mjs +20 -1
- package/dist/type-checks/src/is-empty.mjs.map +1 -1
- package/dist/type-checks/src/is-error.cjs +29 -1
- package/dist/type-checks/src/is-error.mjs +29 -1
- package/dist/type-checks/src/is-error.mjs.map +1 -1
- package/dist/type-checks/src/is-null.cjs +12 -1
- package/dist/type-checks/src/is-null.mjs +11 -1
- package/dist/type-checks/src/is-null.mjs.map +1 -1
- package/dist/type-checks/src/is-number.cjs +18 -1
- package/dist/type-checks/src/is-number.mjs +17 -1
- package/dist/type-checks/src/is-number.mjs.map +1 -1
- package/dist/type-checks/src/is-object.cjs +19 -1
- package/dist/type-checks/src/is-object.mjs +19 -1
- package/dist/type-checks/src/is-object.mjs.map +1 -1
- package/dist/type-checks/src/is-plain-object.cjs +64 -1
- package/dist/type-checks/src/is-plain-object.mjs +63 -1
- package/dist/type-checks/src/is-plain-object.mjs.map +1 -1
- package/dist/type-checks/src/is-set-string.cjs +20 -1
- package/dist/type-checks/src/is-set-string.mjs +20 -1
- package/dist/type-checks/src/is-set-string.mjs.map +1 -1
- package/dist/type-checks/src/is-set.cjs +19 -1
- package/dist/type-checks/src/is-set.mjs +19 -1
- package/dist/type-checks/src/is-set.mjs.map +1 -1
- package/dist/type-checks/src/is-string.cjs +12 -1
- package/dist/type-checks/src/is-string.mjs +11 -1
- package/dist/type-checks/src/is-string.mjs.map +1 -1
- package/dist/type-checks/src/is-undefined.cjs +8 -1
- package/dist/type-checks/src/is-undefined.mjs +7 -1
- package/dist/type-checks/src/is-undefined.mjs.map +1 -1
- package/dist/type-checks/src/type-detect.cjs +15 -1
- package/dist/type-checks/src/type-detect.mjs +16 -1
- package/dist/type-checks/src/type-detect.mjs.map +1 -1
- package/dist/types/src/base.cjs +6 -1
- package/dist/types/src/base.mjs +5 -1
- package/dist/types/src/base.mjs.map +1 -1
- package/dist/write-file.cjs +40 -1
- package/dist/write-file.mjs +38 -1
- package/dist/write-file.mjs.map +1 -1
- package/dist/yaml.cjs +29 -1
- package/dist/yaml.mjs +27 -1
- package/dist/yaml.mjs.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1,67 @@
|
|
|
1
|
-
const
|
|
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
|
|
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":"
|
|
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
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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":"
|
|
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
|
|
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
|
|
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":"
|
|
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"}
|