@gesslar/toolkit 2.10.1 → 2.11.1
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/README.md +1 -1
- package/package.json +1 -1
- package/src/browser/lib/Collection.js +12 -6
- package/src/browser/lib/Data.js +1 -1
- package/src/browser/lib/TypeSpec.js +35 -8
- package/src/lib/CappedDirectoryObject.js +2 -2
- package/src/lib/TempDirectoryObject.js +2 -1
- package/src/types/browser/lib/Collection.d.ts +3 -1
- package/src/types/browser/lib/Collection.d.ts.map +1 -1
- package/src/types/browser/lib/TypeSpec.d.ts +6 -8
- package/src/types/browser/lib/TypeSpec.d.ts.map +1 -1
- package/src/types/lib/TempDirectoryObject.d.ts.map +1 -1
package/README.md
CHANGED
|
@@ -97,7 +97,7 @@ The browser version includes: Collection, Data, Disposer, HTML, Notify, Sass, Ta
|
|
|
97
97
|
|
|
98
98
|
## Post Partum
|
|
99
99
|
|
|
100
|
-
If you made it this far, please understand that I have absolutely zero scruples when it comes to breaking changes. Primarily, the audience for this library is myself. Consequently, anything that relies on the contents of this library will dutifully crash and I'll have to refactor those things then. It's like leaving
|
|
100
|
+
If you made it this far, please understand that I have absolutely zero scruples when it comes to breaking changes. Primarily, the audience for this library is myself. Consequently, anything that relies on the contents of this library will dutifully crash and I'll have to refactor those things then. It's like leaving nicky nicky nine doors. But with myself. And there's a lazy bomb waiting for me. That I planted. For me. And the bomb just explodes poop.
|
|
101
101
|
|
|
102
102
|
You're of course welcome to use my library! It's pretty robust. Uhhh, but maybe lock in the version until you see if something is gonna poop all over you. I make robots make my PR notifications and generally they're very good at firing off klaxons about my fetish for breaking changes, so you should be all right if you're paying attention. 🤷🏻
|
|
103
103
|
|
package/package.json
CHANGED
|
@@ -10,6 +10,7 @@ import Data from "./Data.js"
|
|
|
10
10
|
import Valid from "./Valid.js"
|
|
11
11
|
import Sass from "./Sass.js"
|
|
12
12
|
import Util from "./Util.js"
|
|
13
|
+
import TypeSpec from "./TypeSpec.js"
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Utility class for collection operations.
|
|
@@ -204,9 +205,11 @@ export default class Collection {
|
|
|
204
205
|
*
|
|
205
206
|
* @param {Array<unknown>} arr - The array to check
|
|
206
207
|
* @param {string} [type] - The type to check for (optional, defaults to the type of the first element)
|
|
208
|
+
* @param {unknown} options - Options for checking types
|
|
209
|
+
* @param {boolean} [options.strict] - Whether to use strict type or looser TypeSpec checking
|
|
207
210
|
* @returns {boolean} Whether all elements are of the specified type
|
|
208
211
|
*/
|
|
209
|
-
static isArrayUniform(arr, type) {
|
|
212
|
+
static isArrayUniform(arr, type, options={strict: true}) {
|
|
210
213
|
const req = "Array"
|
|
211
214
|
const arrType = Data.typeOf(arr)
|
|
212
215
|
|
|
@@ -217,12 +220,15 @@ export default class Collection {
|
|
|
217
220
|
Valid.type(type, "string", `Invalid type parameter. Expected 'string', got '${Data.typeOf(type)}'`)
|
|
218
221
|
}
|
|
219
222
|
|
|
220
|
-
const checkType = type ? Util.capitalize(type) :
|
|
223
|
+
const checkType = type ? Util.capitalize(type) : Data.typeOf(arr[0])
|
|
221
224
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
225
|
+
if(options?.strict === false) {
|
|
226
|
+
const ts = new TypeSpec(checkType)
|
|
227
|
+
|
|
228
|
+
return arr.every(e => ts.matches(e))
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return arr.every(e => Data.typeOf(e) === checkType)
|
|
226
232
|
}
|
|
227
233
|
|
|
228
234
|
/**
|
package/src/browser/lib/Data.js
CHANGED
|
@@ -20,7 +20,7 @@ export default class TypeSpec {
|
|
|
20
20
|
* Creates a new TypeSpec instance.
|
|
21
21
|
*
|
|
22
22
|
* @param {string} string - The type specification string (e.g., "string|number", "object[]")
|
|
23
|
-
* @param {
|
|
23
|
+
* @param {unknown} options - Additional parsing options
|
|
24
24
|
*/
|
|
25
25
|
constructor(string, options) {
|
|
26
26
|
this.#specs = []
|
|
@@ -48,7 +48,7 @@ export default class TypeSpec {
|
|
|
48
48
|
/**
|
|
49
49
|
* Returns a JSON representation of the TypeSpec.
|
|
50
50
|
*
|
|
51
|
-
* @returns {
|
|
51
|
+
* @returns {unknown} Object containing specs, length, and string representation
|
|
52
52
|
*/
|
|
53
53
|
toJSON() {
|
|
54
54
|
// Serialize as a string representation or as raw data
|
|
@@ -134,12 +134,12 @@ export default class TypeSpec {
|
|
|
134
134
|
* Handles array types, union types, and empty value validation.
|
|
135
135
|
*
|
|
136
136
|
* @param {unknown} value - The value to test against the type specifications
|
|
137
|
-
* @param {
|
|
137
|
+
* @param {unknown} options - Validation options
|
|
138
138
|
* @param {boolean} options.allowEmpty - Whether empty values are allowed
|
|
139
139
|
* @returns {boolean} True if the value matches any type specification
|
|
140
140
|
*/
|
|
141
141
|
matches(value, options) {
|
|
142
|
-
return this.match(value,options).length > 0
|
|
142
|
+
return this.match(value, options).length > 0
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
match(value, options) {
|
|
@@ -167,7 +167,16 @@ export default class TypeSpec {
|
|
|
167
167
|
if(valueType === allowedType)
|
|
168
168
|
return allowEmpty || !empty
|
|
169
169
|
|
|
170
|
-
|
|
170
|
+
if(valueType === "Null" || valueType === "Undefined")
|
|
171
|
+
return false
|
|
172
|
+
|
|
173
|
+
if(allowedType === "Object" && Data.isPlainObject(value))
|
|
174
|
+
return true
|
|
175
|
+
|
|
176
|
+
// We already don't match directly, let's check their breeding.
|
|
177
|
+
const lineage = this.#getTypeLineage(value)
|
|
178
|
+
|
|
179
|
+
return lineage.includes(allowedType)
|
|
171
180
|
}
|
|
172
181
|
|
|
173
182
|
// Handle array values
|
|
@@ -200,11 +209,11 @@ export default class TypeSpec {
|
|
|
200
209
|
*
|
|
201
210
|
* @private
|
|
202
211
|
* @param {string} string - The type specification string to parse
|
|
203
|
-
* @param {
|
|
212
|
+
* @param {unknown} options - Parsing options
|
|
204
213
|
* @param {string} options.delimiter - The delimiter for union types
|
|
205
|
-
* @throws {
|
|
214
|
+
* @throws {Sass} If the type specification is invalid
|
|
206
215
|
*/
|
|
207
|
-
#parse(string, options) {
|
|
216
|
+
#parse(string, options={delimiter: "|"}) {
|
|
208
217
|
const delimiter = options?.delimiter ?? "|"
|
|
209
218
|
const parts = string.split(delimiter)
|
|
210
219
|
|
|
@@ -225,4 +234,22 @@ export default class TypeSpec {
|
|
|
225
234
|
}
|
|
226
235
|
})
|
|
227
236
|
}
|
|
237
|
+
|
|
238
|
+
#getTypeLineage(value) {
|
|
239
|
+
const lineage = [Object.getPrototypeOf(value)]
|
|
240
|
+
const names = [lineage.at(-1).constructor.name]
|
|
241
|
+
|
|
242
|
+
for(;;) {
|
|
243
|
+
const prototype = Object.getPrototypeOf(lineage.at(-1))
|
|
244
|
+
const name = prototype?.constructor.name
|
|
245
|
+
|
|
246
|
+
if(!prototype || !name || name === "Object")
|
|
247
|
+
break
|
|
248
|
+
|
|
249
|
+
lineage.push(prototype)
|
|
250
|
+
names.push(prototype.constructor.name)
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return names
|
|
254
|
+
}
|
|
228
255
|
}
|
|
@@ -60,8 +60,8 @@ export default class CappedDirectoryObject extends DirectoryObject {
|
|
|
60
60
|
Valid.type(dirPath, "String")
|
|
61
61
|
Valid.assert(dirPath.length > 0, "Path must not be empty.")
|
|
62
62
|
|
|
63
|
-
// Validate parent using
|
|
64
|
-
if(parent !== null && !(parent
|
|
63
|
+
// Validate parent using inheritance-aware type checking
|
|
64
|
+
if(parent !== null && !Data.isType(parent, "CappedDirectoryObject")) {
|
|
65
65
|
throw Sass.new(`Parent must be null or a CappedDirectoryObject instance, got ${Data.typeOf(parent)}`)
|
|
66
66
|
}
|
|
67
67
|
|
|
@@ -9,6 +9,7 @@ import os from "node:os"
|
|
|
9
9
|
import path from "node:path"
|
|
10
10
|
|
|
11
11
|
import CappedDirectoryObject from "./CappedDirectoryObject.js"
|
|
12
|
+
import Data from "../browser/lib/Data.js"
|
|
12
13
|
import Sass from "./Sass.js"
|
|
13
14
|
|
|
14
15
|
/**
|
|
@@ -92,7 +93,7 @@ export default class TempDirectoryObject extends CappedDirectoryObject {
|
|
|
92
93
|
}
|
|
93
94
|
} else {
|
|
94
95
|
// With parent: validate it's a proper temp directory parent
|
|
95
|
-
if(!(parent
|
|
96
|
+
if(!Data.isType(parent, "CappedDirectoryObject")) {
|
|
96
97
|
throw Sass.new(
|
|
97
98
|
"Parent must be a CappedDirectoryObject or TempDirectoryObject."
|
|
98
99
|
)
|
|
@@ -77,9 +77,11 @@ export default class Collection {
|
|
|
77
77
|
*
|
|
78
78
|
* @param {Array<unknown>} arr - The array to check
|
|
79
79
|
* @param {string} [type] - The type to check for (optional, defaults to the type of the first element)
|
|
80
|
+
* @param {unknown} options - Options for checking types
|
|
81
|
+
* @param {boolean} [options.strict] - Whether to use strict type or looser TypeSpec checking
|
|
80
82
|
* @returns {boolean} Whether all elements are of the specified type
|
|
81
83
|
*/
|
|
82
|
-
static isArrayUniform(arr: Array<unknown>, type?: string): boolean;
|
|
84
|
+
static isArrayUniform(arr: Array<unknown>, type?: string, options?: unknown): boolean;
|
|
83
85
|
/**
|
|
84
86
|
* Checks if an array is unique
|
|
85
87
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Collection.d.ts","sourceRoot":"","sources":["../../../browser/lib/Collection.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Collection.d.ts","sourceRoot":"","sources":["../../../browser/lib/Collection.js"],"names":[],"mappings":"AAcA;;;GAGG;AACH;IACE;;;;;;;;;OASG;IACH,6BANW,KAAK,CAAC,OAAO,CAAC,aACd,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,OAAO,YACjE,OAAO,GACL,OAAO,GAAC,SAAS,CAqB7B;IAED;;;;;;;;OAQG;IACH,8BALW,MAAM,aACN,C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AAA,GAC7E,OAAO,CAAC,MAAM,CAAC,CA0C3B;IAED;;;;;;;;OAQG;IACH,sBALW,KAAK,CAAC,OAAO,CAAC,WACd,KAAK,CAAC,OAAO,CAAC,GACZ,KAAK,CAAC,OAAO,CAAC,CAW1B;IAED;;;;;;;;OAQG;IACH,2BALW,KAAK,CAAC,OAAO,CAAC,WACd,KAAK,CAAC,OAAO,CAAC,GACZ,KAAK,CAAC,OAAO,CAAC,CAY1B;IAED;;;;;;;;OAQG;IACH,0BALW,KAAK,CAAC,OAAO,CAAC,WACd,KAAK,CAAC,OAAO,CAAC,GACZ,KAAK,CAAC,OAAO,CAAC,CAiB1B;IAED;;;;;;;OAOG;IACH,iCAJW,KAAK,CAAC,MAAM,CAAC,GACX,MAAM,CA0BlB;IAED;;;;;;OAMG;IACH,iCAHW,KAAK,CAAC,MAAM,CAAC,GAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,GAChC,MAAM,CAMlB;CACF"}
|
|
@@ -7,9 +7,9 @@ export default class TypeSpec {
|
|
|
7
7
|
* Creates a new TypeSpec instance.
|
|
8
8
|
*
|
|
9
9
|
* @param {string} string - The type specification string (e.g., "string|number", "object[]")
|
|
10
|
-
* @param {
|
|
10
|
+
* @param {unknown} options - Additional parsing options
|
|
11
11
|
*/
|
|
12
|
-
constructor(string: string, options:
|
|
12
|
+
constructor(string: string, options: unknown);
|
|
13
13
|
specs: any[];
|
|
14
14
|
length: number;
|
|
15
15
|
stringRepresentation: string;
|
|
@@ -22,9 +22,9 @@ export default class TypeSpec {
|
|
|
22
22
|
/**
|
|
23
23
|
* Returns a JSON representation of the TypeSpec.
|
|
24
24
|
*
|
|
25
|
-
* @returns {
|
|
25
|
+
* @returns {unknown} Object containing specs, length, and string representation
|
|
26
26
|
*/
|
|
27
|
-
toJSON():
|
|
27
|
+
toJSON(): unknown;
|
|
28
28
|
/**
|
|
29
29
|
* Executes a provided function once for each type specification.
|
|
30
30
|
*
|
|
@@ -79,13 +79,11 @@ export default class TypeSpec {
|
|
|
79
79
|
* Handles array types, union types, and empty value validation.
|
|
80
80
|
*
|
|
81
81
|
* @param {unknown} value - The value to test against the type specifications
|
|
82
|
-
* @param {
|
|
82
|
+
* @param {unknown} options - Validation options
|
|
83
83
|
* @param {boolean} options.allowEmpty - Whether empty values are allowed
|
|
84
84
|
* @returns {boolean} True if the value matches any type specification
|
|
85
85
|
*/
|
|
86
|
-
matches(value: unknown, options:
|
|
87
|
-
allowEmpty: boolean;
|
|
88
|
-
}): boolean;
|
|
86
|
+
matches(value: unknown, options: unknown): boolean;
|
|
89
87
|
match(value: any, options: any): unknown[];
|
|
90
88
|
#private;
|
|
91
89
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeSpec.d.ts","sourceRoot":"","sources":["../../../browser/lib/TypeSpec.js"],"names":[],"mappings":"AAWA;;;GAGG;AACH;IAGE;;;;;OAKG;IACH,oBAHW,MAAM,WACN,
|
|
1
|
+
{"version":3,"file":"TypeSpec.d.ts","sourceRoot":"","sources":["../../../browser/lib/TypeSpec.js"],"names":[],"mappings":"AAWA;;;GAGG;AACH;IAGE;;;;;OAKG;IACH,oBAHW,MAAM,WACN,OAAO,EAUjB;IAJC,aAAwB;IACxB,eAAgC;IAChC,6BAA2C;IAI7C;;;;OAIG;IACH,YAFa,MAAM,CAQlB;IAED;;;;OAIG;IACH,UAFa,OAAO,CASnB;IAED;;;;OAIG;IACH,kBAFW,CAAS,IAAO,EAAP,OAAO,KAAG,IAAI,QAIjC;IAED;;;;;OAKG;IACH,gBAHW,CAAS,IAAO,EAAP,OAAO,KAAG,OAAO,GACxB,OAAO,CAInB;IAED;;;;;OAKG;IACH,eAHW,CAAS,IAAO,EAAP,OAAO,KAAG,OAAO,GACxB,OAAO,CAInB;IAED;;;;;OAKG;IACH,iBAHW,CAAS,IAAO,EAAP,OAAO,KAAG,OAAO,GACxB,KAAK,CAAC,OAAO,CAAC,CAI1B;IAED;;;;;OAKG;IACH,cAHW,CAAS,IAAO,EAAP,OAAO,KAAG,OAAO,GACxB,KAAK,CAAC,OAAO,CAAC,CAI1B;IAED;;;;;;OAMG;IACH,iBAJW,CAAS,IAAO,EAAP,OAAO,EAAE,IAAO,EAAP,OAAO,KAAG,OAAO,gBACnC,OAAO,GACL,OAAO,CAInB;IAED;;;;;OAKG;IACH,eAHW,CAAS,IAAO,EAAP,OAAO,KAAG,OAAO,GACxB,MAAM,GAAC,SAAS,CAI5B;IAED;;;;;;;;OAQG;IACH,eALW,OAAO,WACP,OAAO,GAEL,OAAO,CAInB;IAED,2CA2DC;;CAmDF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TempDirectoryObject.d.ts","sourceRoot":"","sources":["../../lib/TempDirectoryObject.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TempDirectoryObject.d.ts","sourceRoot":"","sources":["../../lib/TempDirectoryObject.js"],"names":[],"mappings":"AAcA;;;;;;;;;GASG;AACH;IAEE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACH,mBAxBW,MAAM,OAAC,WACP,mBAAmB,OAAC,EAoF9B;IAsBD;;;;;;;;;;;;;;OAcG;IACH,sBAVW,MAAM,GACJ,mBAAmB,CAY/B;IAED;;;;;;;;;;;;;;OAcG;IACH,kBAVW,MAAM,GACJ,UAAU,CAYtB;;CAUF;kCArLiC,4BAA4B"}
|