@gesslar/toolkit 5.7.0 → 5.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/node/lib/Data.js +35 -18
- package/src/node/lib/FileObject.js +3 -2
- package/types/node/lib/Data.d.ts +15 -5
- package/types/node/lib/Data.d.ts.map +1 -1
- package/types/node/lib/FileObject.d.ts +3 -2
- package/types/node/lib/FileObject.d.ts.map +1 -1
- package/vendor/toolkit.esm.js +1 -1
- package/vendor/toolkit.umd.js +1 -1
package/package.json
CHANGED
package/src/node/lib/Data.js
CHANGED
|
@@ -2,36 +2,46 @@ import JSON5 from "json5"
|
|
|
2
2
|
import YAML from "yaml"
|
|
3
3
|
import BrowserData from "../../browser/lib/Data.js"
|
|
4
4
|
import Sass from "./Sass.js"
|
|
5
|
+
import Valid from "../../node/lib/Valid.js"
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Node-side extension of Data with parsing utilities that require
|
|
8
9
|
* node-specific dependencies.
|
|
9
10
|
*/
|
|
10
11
|
export default class Data extends BrowserData {
|
|
12
|
+
static LOAD_DATA_TYPES = Object.freeze({
|
|
13
|
+
json: Object.freeze([JSON]), // least permissive
|
|
14
|
+
json5: Object.freeze([JSON5]),
|
|
15
|
+
yaml: Object.freeze([YAML]), // most permissive
|
|
16
|
+
})
|
|
17
|
+
|
|
11
18
|
/**
|
|
12
|
-
* Parses text content as structured data (JSON5 or YAML).
|
|
19
|
+
* Parses text content as structured data (JSON, JSON5, or YAML).
|
|
20
|
+
*
|
|
21
|
+
* The `json` type uses strict JSON parsing and will NOT accept JSON5
|
|
22
|
+
* extensions (comments, trailing commas, unquoted keys); use `json5` for
|
|
23
|
+
* that. The `any` type tries each format from least to most permissive.
|
|
13
24
|
*
|
|
14
25
|
* @param {string} source - The text content to parse
|
|
15
|
-
* @param {string} [type="any"] - The expected format ("json",
|
|
16
|
-
*
|
|
26
|
+
* @param {string} [type="any"] - The expected format ("json", "json5",
|
|
27
|
+
* "yaml", or "any")
|
|
17
28
|
* @returns {unknown} The parsed data
|
|
18
|
-
* @throws {Sass} If content cannot be parsed or type is
|
|
19
|
-
* unsupported
|
|
29
|
+
* @throws {Sass} If content cannot be parsed or type is unsupported
|
|
20
30
|
*/
|
|
21
31
|
static textAsData(source, type="any") {
|
|
32
|
+
Valid.type(source, "String")
|
|
33
|
+
Valid.type(type, "String")
|
|
34
|
+
|
|
22
35
|
const normalizedType = type.toLowerCase()
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
`Unsupported data type '${type}'.`
|
|
33
|
-
+ ` Supported types: json, json5, yaml.`)
|
|
34
|
-
}
|
|
36
|
+
|
|
37
|
+
Valid.assert(
|
|
38
|
+
normalizedType === "any" || Object.hasOwn(this.LOAD_DATA_TYPES, normalizedType),
|
|
39
|
+
`Type must be one of any, ${Object.keys(this.LOAD_DATA_TYPES).join(", ")}.`
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
const toTry = normalizedType === "any"
|
|
43
|
+
? Object.values(this.LOAD_DATA_TYPES).flat()
|
|
44
|
+
: this.LOAD_DATA_TYPES[normalizedType]
|
|
35
45
|
|
|
36
46
|
for(const format of toTry) {
|
|
37
47
|
try {
|
|
@@ -43,7 +53,14 @@ export default class Data extends BrowserData {
|
|
|
43
53
|
}
|
|
44
54
|
}
|
|
45
55
|
|
|
56
|
+
const tried = toTry.map(format =>
|
|
57
|
+
format === JSON
|
|
58
|
+
? "JSON"
|
|
59
|
+
: format === JSON5
|
|
60
|
+
? "JSON5"
|
|
61
|
+
: "YAML")
|
|
62
|
+
|
|
46
63
|
throw Sass.new(
|
|
47
|
-
`Content is
|
|
64
|
+
`Content is not valid ${tried.join(" or ")}.`)
|
|
48
65
|
}
|
|
49
66
|
}
|
|
@@ -587,8 +587,9 @@ export default class FileObject extends FS {
|
|
|
587
587
|
}
|
|
588
588
|
|
|
589
589
|
/**
|
|
590
|
-
* Loads an object from JSON or YAML file.
|
|
591
|
-
*
|
|
590
|
+
* Loads an object from a JSON, JSON5, or YAML file. With the default "any"
|
|
591
|
+
* type, attempts each format from least to most permissive (JSON, then JSON5,
|
|
592
|
+
* then YAML); a specific type restricts parsing to that format.
|
|
592
593
|
*
|
|
593
594
|
* @param {object} [options] - Load options
|
|
594
595
|
* @param {string} [options.type="any"] - The expected type of data to parse ("json", "json5", "yaml", or "any")
|
package/types/node/lib/Data.d.ts
CHANGED
|
@@ -3,17 +3,27 @@
|
|
|
3
3
|
* node-specific dependencies.
|
|
4
4
|
*/
|
|
5
5
|
export default class Data extends BrowserData {
|
|
6
|
+
static LOAD_DATA_TYPES: Readonly<{
|
|
7
|
+
json: readonly JSON[];
|
|
8
|
+
json5: readonly (typeof JSON5)[];
|
|
9
|
+
yaml: readonly (typeof YAML)[];
|
|
10
|
+
}>;
|
|
6
11
|
/**
|
|
7
|
-
* Parses text content as structured data (JSON5 or YAML).
|
|
12
|
+
* Parses text content as structured data (JSON, JSON5, or YAML).
|
|
13
|
+
*
|
|
14
|
+
* The `json` type uses strict JSON parsing and will NOT accept JSON5
|
|
15
|
+
* extensions (comments, trailing commas, unquoted keys); use `json5` for
|
|
16
|
+
* that. The `any` type tries each format from least to most permissive.
|
|
8
17
|
*
|
|
9
18
|
* @param {string} source - The text content to parse
|
|
10
|
-
* @param {string} [type="any"] - The expected format ("json",
|
|
11
|
-
*
|
|
19
|
+
* @param {string} [type="any"] - The expected format ("json", "json5",
|
|
20
|
+
* "yaml", or "any")
|
|
12
21
|
* @returns {unknown} The parsed data
|
|
13
|
-
* @throws {Sass} If content cannot be parsed or type is
|
|
14
|
-
* unsupported
|
|
22
|
+
* @throws {Sass} If content cannot be parsed or type is unsupported
|
|
15
23
|
*/
|
|
16
24
|
static textAsData(source: string, type?: string): unknown;
|
|
17
25
|
}
|
|
18
26
|
import BrowserData from "../../browser/lib/Data.js";
|
|
27
|
+
import JSON5 from "json5";
|
|
28
|
+
import YAML from "yaml";
|
|
19
29
|
//# sourceMappingURL=Data.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Data.d.ts","sourceRoot":"","sources":["../../../src/node/lib/Data.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Data.d.ts","sourceRoot":"","sources":["../../../src/node/lib/Data.js"],"names":[],"mappings":"AAMA;;;GAGG;AACH;IACE;;;;OAIE;IAEF;;;;;;;;;;;;OAYG;IACH,0BANW,MAAM,SACN,MAAM,GAEJ,OAAO,CAqCnB;CACF;wBA/DuB,2BAA2B;kBAFjC,OAAO;iBACR,MAAM"}
|
|
@@ -240,8 +240,9 @@ export default class FileObject extends FS {
|
|
|
240
240
|
*/
|
|
241
241
|
writeBinary(data: ArrayBuffer | Blob | Buffer): Promise<undefined>;
|
|
242
242
|
/**
|
|
243
|
-
* Loads an object from JSON or YAML file.
|
|
244
|
-
*
|
|
243
|
+
* Loads an object from a JSON, JSON5, or YAML file. With the default "any"
|
|
244
|
+
* type, attempts each format from least to most permissive (JSON, then JSON5,
|
|
245
|
+
* then YAML); a specific type restricts parsing to that format.
|
|
245
246
|
*
|
|
246
247
|
* @param {object} [options] - Load options
|
|
247
248
|
* @param {string} [options.type="any"] - The expected type of data to parse ("json", "json5", "yaml", or "any")
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileObject.d.ts","sourceRoot":"","sources":["../../../src/node/lib/FileObject.js"],"names":[],"mappings":"AAkBA;;;;;;;;;;;;;;GAcG;AAEH;yBA8Ha,MAAM,WACN,MAAM,oBAEJ,MAAM;
|
|
1
|
+
{"version":3,"file":"FileObject.d.ts","sourceRoot":"","sources":["../../../src/node/lib/FileObject.js"],"names":[],"mappings":"AAkBA;;;;;;;;;;;;;;GAcG;AAEH;yBA8Ha,MAAM,WACN,MAAM,oBAEJ,MAAM;IA4jBnB;;;;;;;;;;;OAWG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AC,MAAM,CAAC,CAa3B;IAED;;;;;;;;;;;OAWG;IACH,cARa,OAAO,CAAC,MAAM,CAAC,CAe3B;IAED;;;;;;;;;;;OAWG;IACH,eARW,MAAM,aACN,MAAM,GACJ,OAAO,CAAC,SAAS,CAAC,CAiB9B;IAED;;;;;;;;;;;;;;;OAeG;IACH,kBAXW,WAAW,GAAC,IAAI,GAAC,MAAM,GACrB,OAAO,CAAC,SAAS,CAAC,CAwB9B;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,yCAZG;QAAyB,IAAI,GAArB,MAAM;QACW,QAAQ,GAAzB,MAAM;QACY,SAAS,GAA3B,OAAO;KACf,GAAU,OAAO,CAAC,OAAO,CAAC,CAqB5B;IAED;;;;OAIG;IACH,UAFa,OAAO,CAAC,MAAM,CAAC,CAS3B;IAED;;;;;;;;;;;;OAYG;IACH,kBATW,MAAM,GACJ,OAAO,CAAC,UAAU,CAAC,CAyB/B;IAED;;;;;;;;;;;;;OAaG;IACH,kBATW,MAAM,GACJ,OAAO,CAAC,UAAU,CAAC,CA0C/B;IAED;;;;;;;;;OASG;IACH,UAPa,OAAO,CAAC,SAAS,CAAC,CAc9B;IApjBD;;;;;;;OAOG;IACH,2BAHW,QAAQ,GAAC,QAAQ,GAAC,SAAS,GACzB,MAAM,GAAC,MAAM,CAQzB;;CAolBF;eA7vBc,iBAAiB;4BADJ,sBAAsB;kBAFhC,YAAY"}
|
package/vendor/toolkit.esm.js
CHANGED
package/vendor/toolkit.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @gesslar/toolkit v5.
|
|
1
|
+
// @gesslar/toolkit v5.8.0 - UMD bundle
|
|
2
2
|
(function (global, factory) {
|
|
3
3
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
4
4
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|