@gesslar/toolkit 1.5.0 → 1.6.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 +2 -2
- package/src/browser/lib/Data.js +0 -7
- package/src/browser/lib/Disposer.js +1 -24
- package/src/browser/lib/Util.js +1 -11
- package/src/types/browser/lib/Data.d.ts.map +1 -1
- package/src/types/browser/lib/Disposer.d.ts +0 -6
- package/src/types/browser/lib/Disposer.d.ts.map +1 -1
- package/src/types/browser/lib/Util.d.ts +0 -1
- package/src/types/browser/lib/Util.d.ts.map +1 -1
- package/src/browser/lib/Hook.js +0 -82
- package/src/browser/lib/test.js +0 -25
- package/src/browser/lib/test2.js +0 -46
- package/src/types/Cache.d.ts +0 -30
- package/src/types/Collection.d.ts +0 -321
- package/src/types/Contract.d.ts +0 -162
- package/src/types/Data.d.ts +0 -175
- package/src/types/DirectoryObject.d.ts +0 -135
- package/src/types/FS.d.ts +0 -40
- package/src/types/FileObject.d.ts +0 -388
- package/src/types/Glog.d.ts +0 -345
- package/src/types/Sass.d.ts +0 -24
- package/src/types/Schemer.d.ts +0 -179
- package/src/types/Tantrum.d.ts +0 -81
- package/src/types/Term.d.ts +0 -16
- package/src/types/Terms.d.ts +0 -145
- package/src/types/Type.d.ts +0 -26
- package/src/types/Util.d.ts +0 -275
- package/src/types/Valid.d.ts +0 -13
- package/src/types/browser/lib/Disposable.d.ts +0 -35
- package/src/types/browser/lib/Disposable.d.ts.map +0 -10
- package/src/types/browser/lib/Hook.d.ts +0 -11
- package/src/types/browser/lib/Hook.d.ts.map +0 -1
- package/src/types/browser/lib/test.d.ts +0 -2
- package/src/types/browser/lib/test.d.ts.map +0 -1
- package/src/types/browser/lib/test2.d.ts +0 -2
- package/src/types/browser/lib/test2.d.ts.map +0 -1
- package/src/types/lib/Chide.d.ts +0 -37
- package/src/types/lib/Chide.d.ts.map +0 -1
- package/src/types/lib/Collection.d.ts +0 -246
- package/src/types/lib/Collection.d.ts.map +0 -1
- package/src/types/lib/Data.d.ts +0 -206
- package/src/types/lib/Data.d.ts.map +0 -1
- package/src/types/lib/Disposable.d.ts +0 -33
- package/src/types/lib/Disposable.d.ts.map +0 -10
- package/src/types/lib/TypeSpec.d.ts +0 -92
- package/src/types/lib/TypeSpec.d.ts.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gesslar/toolkit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Get in, bitches, we're going toolkitting.",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"node": ">=20"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
|
-
"types:build": "tsc -p tsconfig.types.json",
|
|
34
|
+
"types:build": "node -e \"require('fs').rmSync('src/types',{recursive:true,force:true});\" && tsc -p tsconfig.types.json",
|
|
35
35
|
"prepublishOnly": "npm run types:build",
|
|
36
36
|
"lint": "eslint src/",
|
|
37
37
|
"lint:fix": "eslint src/ --fix",
|
package/src/browser/lib/Data.js
CHANGED
|
@@ -27,7 +27,6 @@ export default class Data {
|
|
|
27
27
|
"Undefined",
|
|
28
28
|
|
|
29
29
|
// Object Categories from typeof
|
|
30
|
-
"AsyncFunction",
|
|
31
30
|
"Function",
|
|
32
31
|
"Object",
|
|
33
32
|
])
|
|
@@ -41,7 +40,6 @@ export default class Data {
|
|
|
41
40
|
static constructors = Object.freeze([
|
|
42
41
|
// Object Constructors
|
|
43
42
|
"Array",
|
|
44
|
-
"AsyncFunction",
|
|
45
43
|
"Date",
|
|
46
44
|
"Error",
|
|
47
45
|
"Float32Array",
|
|
@@ -192,11 +190,6 @@ export default class Data {
|
|
|
192
190
|
if(type === "object")
|
|
193
191
|
return value.constructor.name
|
|
194
192
|
|
|
195
|
-
if(type === "function") {
|
|
196
|
-
if(value.constructor.name === "AsyncFunction")
|
|
197
|
-
return "AsyncFunction"
|
|
198
|
-
}
|
|
199
|
-
|
|
200
193
|
const [first, ...rest] = Array.from(type)
|
|
201
194
|
|
|
202
195
|
return `${first?.toLocaleUpperCase() ?? ""}${rest.join("")}`
|
|
@@ -6,8 +6,6 @@ import Valid from "./Valid.js"
|
|
|
6
6
|
*/
|
|
7
7
|
export class Disposer {
|
|
8
8
|
#disposers = []
|
|
9
|
-
#disposed = false
|
|
10
|
-
#noop = () => {}
|
|
11
9
|
|
|
12
10
|
/**
|
|
13
11
|
* Registers a disposer callback to be executed when disposed.
|
|
@@ -21,13 +19,6 @@ export class Disposer {
|
|
|
21
19
|
*/
|
|
22
20
|
register(...disposers) {
|
|
23
21
|
const normalized = this.#normalizeDisposers(disposers)
|
|
24
|
-
|
|
25
|
-
if(this.#disposed) {
|
|
26
|
-
return normalized.length === 1
|
|
27
|
-
? this.#noop
|
|
28
|
-
: normalized.map(() => this.#noop)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
22
|
const unregisters = normalized.map(
|
|
32
23
|
disposer => this.#registerDisposer(disposer)
|
|
33
24
|
)
|
|
@@ -36,7 +27,7 @@ export class Disposer {
|
|
|
36
27
|
}
|
|
37
28
|
|
|
38
29
|
#registerDisposer(disposer) {
|
|
39
|
-
if(
|
|
30
|
+
if(typeof disposer !== "function")
|
|
40
31
|
return () => {}
|
|
41
32
|
|
|
42
33
|
this.#disposers.push(disposer)
|
|
@@ -50,11 +41,6 @@ export class Disposer {
|
|
|
50
41
|
* @returns {void}
|
|
51
42
|
*/
|
|
52
43
|
dispose() {
|
|
53
|
-
if(this.#disposed)
|
|
54
|
-
return
|
|
55
|
-
|
|
56
|
-
this.#disposed = true
|
|
57
|
-
|
|
58
44
|
const errors = []
|
|
59
45
|
this.#disposers.toReversed().forEach(disposer => {
|
|
60
46
|
try {
|
|
@@ -81,15 +67,6 @@ export class Disposer {
|
|
|
81
67
|
return normalized
|
|
82
68
|
}
|
|
83
69
|
|
|
84
|
-
/**
|
|
85
|
-
* Whether disposal has run.
|
|
86
|
-
*
|
|
87
|
-
* @returns {boolean} True when dispose() has already been called.
|
|
88
|
-
*/
|
|
89
|
-
get disposed() {
|
|
90
|
-
return this.#disposed
|
|
91
|
-
}
|
|
92
|
-
|
|
93
70
|
/**
|
|
94
71
|
* Read-only list of registered disposers.
|
|
95
72
|
*
|
package/src/browser/lib/Util.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import Collection from "./Collection.js"
|
|
2
|
-
import Data from "./Data.js"
|
|
3
1
|
import Sass from "./Sass.js"
|
|
4
2
|
import Valid from "./Valid.js"
|
|
3
|
+
import Collection from "./Collection.js"
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Utility class providing common helper functions for string manipulation,
|
|
@@ -255,13 +254,4 @@ export default class Util {
|
|
|
255
254
|
.join("")
|
|
256
255
|
, flags?.join(""))
|
|
257
256
|
}
|
|
258
|
-
|
|
259
|
-
static disasyncify(func) {
|
|
260
|
-
Valid.type(func, "Function|AsyncFunction")
|
|
261
|
-
|
|
262
|
-
if(Data.isType(func, "Function"))
|
|
263
|
-
return func
|
|
264
|
-
|
|
265
|
-
return (async(...arg) => await func(...arg))()
|
|
266
|
-
}
|
|
267
257
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Data.d.ts","sourceRoot":"","sources":["../../../browser/lib/Data.js"],"names":[],"mappings":"AAUA;IACA;;;;;OAKG;IACD,mBAFQ,KAAK,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"Data.d.ts","sourceRoot":"","sources":["../../../browser/lib/Data.js"],"names":[],"mappings":"AAUA;IACA;;;;;OAKG;IACD,mBAFQ,KAAK,CAAC,MAAM,CAAC,CAgBnB;IAEF;;;;;OAKG;IACH,qBAFU,KAAK,CAAC,MAAM,CAAC,CAmBrB;IAEF;;;;;;;OAOG;IACH,kBAFU,KAAK,CAAC,MAAM,CAAC,CAKrB;IAEF;;;;;OAKG;IACH,uBAFU,KAAK,CAAC,MAAM,CAAC,CAE6C;IAEpE;;;;;;OAMG;IACH,4BAJW,MAAM,UACN,MAAM,GACJ,MAAM,CAIlB;IAED;;;;;;OAMG;IACH,6BAJW,MAAM,WACN,MAAM,GACJ,MAAM,CAIlB;IAED;;;;;;;OAOG;IACH,2BAJW,MAAM,WACN,MAAM,GACJ,KAAK,CAAC,MAAM,CAAC,CAIzB;IAED;;;;;;;OAOG;IACH,qBALW,OAAO,QACP,MAAM,GAAC,QAAQ,YACf,MAAM,GACJ,OAAO,CAQnB;IAED;;;;;OAKG;IACH,yBAHW,MAAM,GACJ,OAAO,CASnB;IAED;;;;;;;;OAQG;IACH,yBAJW,OAAO,QACP,MAAM,GACJ,OAAO,CAwBnB;IAED;;;;;OAKG;IACH,qBAHW,OAAO,GACL,MAAM,CAclB;IAED;;;;;OAKG;IACH,wBAHW,OAAO,GACL,OAAO,CAInB;IAED;;;;;;;;OAQG;IACH,sBALW,OAAO,oBACP,OAAO,GAEL,OAAO,CA2BnB;IAED;;;;;OAKG;IACH,6BAHW,MAAM,GACJ,MAAM,CAmBlB;IAED;;;;;;;OAOG;IACH,6BAJW,MAAM,QACN,KAAK,CAAC,MAAM,CAAC,GACX,MAAM,CAiBlB;IAED;;;;;;;OAOG;IACH,2BAJW,MAAM,QACN,KAAK,CAAC,MAAM,CAAC,SACb,OAAO,QAMjB;IAED;;;;;OAKG;IACH,+BAHc,MAAM,EAAA,GACP,MAAM,CAqBlB;IAED;;;;;;;OAOG;IACH,wBAJW,KAAK,CAAC,OAAO,CAAC,aACd,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,GAClC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAMnC;IAED;;;;;;;OAOG;IACH,kBALW,MAAM,OACN,MAAM,OACN,MAAM,GACJ,MAAM,CAIlB;IAED;;;;;;;OAOG;IACH,oBALW,MAAM,OACN,MAAM,OACN,MAAM,GACJ,OAAO,CAInB;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,4BAbW,OAAO,GACL,OAAO,CA+BnB;IAED;;;;;;;;;;;;;;;OAeG;IACH,uBAXW,OAAO,GACL,OAAO,CAgBnB;CACF;qBA5aoB,eAAe"}
|
|
@@ -20,12 +20,6 @@ export class Disposer {
|
|
|
20
20
|
* @returns {void}
|
|
21
21
|
*/
|
|
22
22
|
dispose(): void;
|
|
23
|
-
/**
|
|
24
|
-
* Whether disposal has run.
|
|
25
|
-
*
|
|
26
|
-
* @returns {boolean} True when dispose() has already been called.
|
|
27
|
-
*/
|
|
28
|
-
get disposed(): boolean;
|
|
29
23
|
/**
|
|
30
24
|
* Read-only list of registered disposers.
|
|
31
25
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Disposer.d.ts","sourceRoot":"","sources":["../../../browser/lib/Disposer.js"],"names":[],"mappings":"AAEA;;;GAGG;AACH;
|
|
1
|
+
{"version":3,"file":"Disposer.d.ts","sourceRoot":"","sources":["../../../browser/lib/Disposer.js"],"names":[],"mappings":"AAEA;;;GAGG;AACH;IAGE;;;;;;;;;OASG;IACH,uBAHW,CAAG,CAAC,MAAM,IAAI,CAAC,GAAC,KAAK,CAAC,MAAM,IAAI,CAAC,GAAA,GAC/B,CAAC,MAAM,IAAI,CAAC,GAAC,KAAK,CAAC,MAAM,IAAI,CAAC,CAS1C;IAWD;;;;OAIG;IACH,WAFa,IAAI,CAehB;IAcD;;;;OAIG;IACH,iBAFa,KAAK,CAAC,MAAM,IAAI,CAAC,CAI7B;;CAQF"}
|
|
@@ -125,6 +125,5 @@ export default class Util {
|
|
|
125
125
|
*/
|
|
126
126
|
static findClosestMatch(input: string, allowedValues: Array<string>, threshold?: number): string;
|
|
127
127
|
static regexify(input: any, trim?: boolean, flags?: any[]): RegExp;
|
|
128
|
-
static disasyncify(func: any): any;
|
|
129
128
|
}
|
|
130
129
|
//# sourceMappingURL=Util.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Util.d.ts","sourceRoot":"","sources":["../../../browser/lib/Util.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Util.d.ts","sourceRoot":"","sources":["../../../browser/lib/Util.js"],"names":[],"mappings":"AAIA;;;GAGG;AACH;IACE;;;;;OAKG;IACH,wBAHW,MAAM,GACJ,MAAM,CAYlB;IAED;;;;;;OAMG;IACH,YAJa,CAAC,MACH,MAAM,OAAO,CAAC,CAAC,CAAC,GACd,OAAO,CAAC;QAAC,MAAM,EAAE,CAAC,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAC,CAAC,CAQ9C;IAED;;;;;;;OAOG;IACH,4BAJW,MAAM,GAAC,MAAM,UACb,MAAM,GACJ,MAAM,CAWlB;IAED;;;;;;;OAOG;IACH,6BAJW,MAAM,GAAC,MAAM,UACb,MAAM,GACJ,MAAM,CAalB;IAED;;;;;;OAMG;IACH,0BAHW,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GACrB,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAInC;IAED;;;;;;OAMG;IACH,2BAHW,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GACrB,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAIlC;IAED;;;;;OAKG;IACH,2BAHW,KAAK,CAAC,MAAM,CAAC,GACX,OAAO,CAInB;IAED;;;;;OAKG;IACH,kCAHW,KAAK,CAAC,MAAM,CAAC,GACX,KAAK,CAAC,MAAM,CAAC,CAIzB;IAED;;;;;OAKG;IACH,iCAHW,KAAK,CAAC,MAAM,CAAC,GACX,KAAK,CAAC,OAAO,CAAC,CAI1B;IAED;;;;;;OAMG;IACH,gCAJW,MAAM,YACN,KAAK,CAAC,MAAM,CAAC,QAKvB;IAED;;;;;OAKG;IACH,mCAHW,KAAK,CAAC,MAAM,CAAC,GACX,KAAK,CAAC,MAAM,CAAC,CAIzB;IAED;;;;;OAKG;IACH,+BAHW,KAAK,CAAC,MAAM,CAAC,GACX,KAAK,CAAC,OAAO,CAAC,CAI1B;IAED;;;;;;OAMG;IACH,sBAHW,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GACrB,OAAO,CAAC,OAAO,CAAC,CAI5B;IAED;;;;;;OAMG;IACH,8BAJW,MAAM,KACN,MAAM,GACJ,MAAM,CAsBlB;IAED;;;;;;;;OAQG;IACH,+BALW,MAAM,iBACN,KAAK,CAAC,MAAM,CAAC,cACb,MAAM,GACJ,MAAM,CAwBlB;IAED,mEAiBC;CACF"}
|
package/src/browser/lib/Hook.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import Sass from "./Sass.js"
|
|
2
|
-
import Valid from "./Valid.js"
|
|
3
|
-
|
|
4
|
-
class PipeClass {
|
|
5
|
-
name = "Pipe"
|
|
6
|
-
|
|
7
|
-
#lastResult
|
|
8
|
-
#it = 0
|
|
9
|
-
|
|
10
|
-
constructor(func) {
|
|
11
|
-
Valid.type(func, "Function|AsyncFunction|Promise")
|
|
12
|
-
|
|
13
|
-
this.#processStart(func)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
static source(func) {
|
|
17
|
-
return new this(func)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
async then(func) {
|
|
21
|
-
if(++this.it > 2)
|
|
22
|
-
throw new Error("hi")
|
|
23
|
-
|
|
24
|
-
console.log("then", this.#lastResult, "func", func)
|
|
25
|
-
|
|
26
|
-
this.#lastResult =
|
|
27
|
-
this.#lastResult.then(prev => this.#resolve(func, prev))
|
|
28
|
-
|
|
29
|
-
return this
|
|
30
|
-
/*
|
|
31
|
-
|
|
32
|
-
this.#processThen(func)
|
|
33
|
-
|
|
34
|
-
return this
|
|
35
|
-
*/
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
get value() {
|
|
39
|
-
return this.#processResult()
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
#processStart(func) {
|
|
43
|
-
console.log("start", func)
|
|
44
|
-
|
|
45
|
-
this.#lastResult = Promise.resolve(this.#resolve(func))
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
#processThen(func) {
|
|
49
|
-
if(++this.#it > 2)
|
|
50
|
-
throw new Error("hi")
|
|
51
|
-
|
|
52
|
-
this.#lastResult = this.#lastResult.then(prev => this.#resolve(func, prev))
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
#processResult() {
|
|
56
|
-
const result = this.#lastResult
|
|
57
|
-
this.#lastResult = undefined
|
|
58
|
-
|
|
59
|
-
return result
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
#resolve = (val, prev) => typeof val === "function" ? val(prev) : val
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export default new Proxy(PipeClass, {
|
|
66
|
-
apply(target, _, argumentsList) {
|
|
67
|
-
return target.source(...argumentsList)
|
|
68
|
-
},
|
|
69
|
-
|
|
70
|
-
construct(..._) {
|
|
71
|
-
throw new Sass("This class may not be instantiated in this manner.")
|
|
72
|
-
},
|
|
73
|
-
|
|
74
|
-
get(target, prop) {
|
|
75
|
-
// Hide 'source' method from public API
|
|
76
|
-
if(prop === "source") {
|
|
77
|
-
return undefined
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return Reflect.get(target, prop)
|
|
81
|
-
}
|
|
82
|
-
})
|
package/src/browser/lib/test.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import {setTimeout as timeout} from "node:timers/promises"
|
|
2
|
-
import Pipe from "./Hook.js"
|
|
3
|
-
import Disposer from "./Disposer.js"
|
|
4
|
-
|
|
5
|
-
const step1 = () => 1
|
|
6
|
-
const step2 = num => num+1
|
|
7
|
-
const step3 = num => num+1
|
|
8
|
-
const step4 = async num => {
|
|
9
|
-
console.log("Waiting for",num,typeof num)
|
|
10
|
-
await timeout(5_000)
|
|
11
|
-
|
|
12
|
-
return num + 1
|
|
13
|
-
}
|
|
14
|
-
const step5 = num => num+1
|
|
15
|
-
const step6 = num => num+1
|
|
16
|
-
|
|
17
|
-
const result = await Pipe(step1)
|
|
18
|
-
.then(step2)
|
|
19
|
-
.then(step3)
|
|
20
|
-
.then(step4)
|
|
21
|
-
.then(step5)
|
|
22
|
-
.then(step6)
|
|
23
|
-
.result
|
|
24
|
-
|
|
25
|
-
console.log("result", result)
|
package/src/browser/lib/test2.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import {setTimeout as timeout} from "node:timers/promises"
|
|
2
|
-
|
|
3
|
-
const step1 = () => 1
|
|
4
|
-
const step2 = num => num+1
|
|
5
|
-
const step3 = num => num+1
|
|
6
|
-
const step4 = async num => {
|
|
7
|
-
console.log("Waiting for",num,typeof num)
|
|
8
|
-
await timeout(5_000)
|
|
9
|
-
|
|
10
|
-
return num + 1
|
|
11
|
-
}
|
|
12
|
-
const step5 = num => num+1
|
|
13
|
-
const step6 = num => num+1
|
|
14
|
-
|
|
15
|
-
function Pipe(initialPromise) {
|
|
16
|
-
console.log("start", initialPromise)
|
|
17
|
-
|
|
18
|
-
const resolve = (val, prev) =>
|
|
19
|
-
typeof val === "function" ? val(prev) : val
|
|
20
|
-
|
|
21
|
-
let chain = Promise.resolve(resolve(initialPromise))
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
then(promiseOrFn) {
|
|
25
|
-
console.log("then", chain, "func", promiseOrFn)
|
|
26
|
-
|
|
27
|
-
chain = chain.then(prev => resolve(promiseOrFn, prev))
|
|
28
|
-
|
|
29
|
-
return this
|
|
30
|
-
},
|
|
31
|
-
|
|
32
|
-
get result() {
|
|
33
|
-
return chain
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const result = await Pipe(step1)
|
|
39
|
-
.then(step2)
|
|
40
|
-
.then(step3)
|
|
41
|
-
.then(step4)
|
|
42
|
-
.then(step5)
|
|
43
|
-
.then(step6)
|
|
44
|
-
.result
|
|
45
|
-
|
|
46
|
-
console.log("result", result)
|
package/src/types/Cache.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// Implementation: ../lib/Cache.js
|
|
2
|
-
import FileObject from './FileObject.js'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* File system cache for theme compilation data with automatic invalidation.
|
|
6
|
-
* Provides intelligent caching of parsed JSON5/YAML files with mtime-based
|
|
7
|
-
* cache invalidation to optimize parallel theme compilation performance.
|
|
8
|
-
*
|
|
9
|
-
* The cache eliminates redundant file reads and parsing when multiple themes
|
|
10
|
-
* import the same dependency files, while ensuring data freshness through
|
|
11
|
-
* modification time checking.
|
|
12
|
-
*/
|
|
13
|
-
declare class Cache {
|
|
14
|
-
/**
|
|
15
|
-
* Loads and caches parsed file data with automatic invalidation based on
|
|
16
|
-
* modification time.
|
|
17
|
-
*
|
|
18
|
-
* Implements a sophisticated caching strategy that checks file modification
|
|
19
|
-
* times to determine whether cached data is still valid, ensuring data
|
|
20
|
-
* freshness while optimizing performance for repeated file access during
|
|
21
|
-
* parallel theme compilation.
|
|
22
|
-
*
|
|
23
|
-
* @param fileObject - The file object to load and cache
|
|
24
|
-
* @returns The parsed file data (JSON5 or YAML)
|
|
25
|
-
* @throws If the file cannot be found or accessed
|
|
26
|
-
*/
|
|
27
|
-
loadCachedData(fileObject: FileObject): Promise<unknown>
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export default Cache
|
|
@@ -1,321 +0,0 @@
|
|
|
1
|
-
// Implementation: ../lib/Collection.js
|
|
2
|
-
// Type definitions for Collection utilities
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Collection utility functions for evaluating and manipulating arrays, objects, sets, and maps.
|
|
6
|
-
* Provides functional programming patterns for collection processing with consistent error handling.
|
|
7
|
-
*/
|
|
8
|
-
export default class Collection {
|
|
9
|
-
/**
|
|
10
|
-
* Evaluates an array with a predicate function, returning the first truthy result.
|
|
11
|
-
*
|
|
12
|
-
* @param collection - The array to evaluate
|
|
13
|
-
* @param predicate - Function called for each element: (element, index, array) => result
|
|
14
|
-
* @param forward - Whether to iterate forward (true) or backward (false). Default: true
|
|
15
|
-
* @returns The first truthy result from the predicate, or undefined if none found
|
|
16
|
-
*
|
|
17
|
-
* @throws {Sass} If collection is not an Array or predicate is not a Function
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* import { Collection } from '@gesslar/toolkit'
|
|
22
|
-
*
|
|
23
|
-
* const numbers = [1, 2, 3, 4, 5]
|
|
24
|
-
* const result = Collection.evalArray(numbers, (n, i) => n > 3 ? n * 2 : null)
|
|
25
|
-
* console.log(result) // 8 (first element > 3, doubled)
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
static evalArray<T, R>(
|
|
29
|
-
collection: T[],
|
|
30
|
-
predicate: (element: T, index: number, array: T[]) => R | null | undefined,
|
|
31
|
-
forward?: boolean
|
|
32
|
-
): R | undefined
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Evaluates an object with a predicate function, returning the first truthy result.
|
|
36
|
-
*
|
|
37
|
-
* @param collection - The object to evaluate
|
|
38
|
-
* @param predicate - Function called for each property: (value, key, object) => result
|
|
39
|
-
* @returns The first truthy result from the predicate, or undefined if none found
|
|
40
|
-
*
|
|
41
|
-
* @throws {Sass} If collection is not an Object or predicate is not a Function
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* ```typescript
|
|
45
|
-
* import { Collection } from '@gesslar/toolkit'
|
|
46
|
-
*
|
|
47
|
-
* const obj = {a: 1, b: 2, c: 3}
|
|
48
|
-
* const result = Collection.evalObject(obj, (value, key) => value > 2 ? `${key}:${value}` : null)
|
|
49
|
-
* console.log(result) // "c:3"
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
|
-
static evalObject<T, R>(
|
|
53
|
-
collection: Record<string, T>,
|
|
54
|
-
predicate: (value: T, key: string, object: Record<string, T>) => R | null | undefined
|
|
55
|
-
): R | undefined
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Evaluates a Set with a predicate function, returning the first truthy result.
|
|
59
|
-
*
|
|
60
|
-
* @param collection - The Set to evaluate
|
|
61
|
-
* @param predicate - Function called for each element: (element, set) => result
|
|
62
|
-
* @returns The first truthy result from the predicate, or undefined if none found
|
|
63
|
-
*
|
|
64
|
-
* @throws {Sass} If collection is not a Set or predicate is not a Function
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* ```typescript
|
|
68
|
-
* import { Collection } from '@gesslar/toolkit'
|
|
69
|
-
*
|
|
70
|
-
* const set = new Set([1, 2, 3, 4, 5])
|
|
71
|
-
* const result = Collection.evalSet(set, (n, s) => n > 3 ? n * 2 : null)
|
|
72
|
-
* console.log(result) // 8
|
|
73
|
-
* ```
|
|
74
|
-
*/
|
|
75
|
-
static evalSet<T, R>(
|
|
76
|
-
collection: Set<T>,
|
|
77
|
-
predicate: (element: T, set: Set<T>) => R | null | undefined
|
|
78
|
-
): R | undefined
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Evaluates a Map with a predicate function, returning the first truthy result.
|
|
82
|
-
*
|
|
83
|
-
* @param collection - The Map to evaluate
|
|
84
|
-
* @param predicate - Function called for each entry: (value, key, map) => result
|
|
85
|
-
* @param forward - Whether to iterate forward (true) or backward (false). Default: true
|
|
86
|
-
* @returns The first truthy result from the predicate, or undefined if none found
|
|
87
|
-
*
|
|
88
|
-
* @throws {Sass} If collection is not a Map or predicate is not a Function
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* ```typescript
|
|
92
|
-
* import { Collection } from '@gesslar/toolkit'
|
|
93
|
-
*
|
|
94
|
-
* const map = new Map([['a', 1], ['b', 2], ['c', 3]])
|
|
95
|
-
* const result = Collection.evalMap(map, (value, key) => value > 2 ? `${key}:${value}` : null)
|
|
96
|
-
* console.log(result) // "c:3"
|
|
97
|
-
* ```
|
|
98
|
-
*/
|
|
99
|
-
static evalMap<K, V, R>(
|
|
100
|
-
collection: Map<K, V>,
|
|
101
|
-
predicate: (value: V, key: K, map: Map<K, V>) => R | null | undefined,
|
|
102
|
-
forward?: boolean
|
|
103
|
-
): R | undefined
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Zips two arrays together into an array of pairs.
|
|
107
|
-
*
|
|
108
|
-
* @param array1 - The first array
|
|
109
|
-
* @param array2 - The second array
|
|
110
|
-
* @returns Array of [element1, element2] pairs, length of shorter input array
|
|
111
|
-
*
|
|
112
|
-
* @example
|
|
113
|
-
* ```typescript
|
|
114
|
-
* import { Collection } from '@gesslar/toolkit'
|
|
115
|
-
*
|
|
116
|
-
* const result = Collection.zip([1, 2, 3], ['a', 'b', 'c'])
|
|
117
|
-
* console.log(result) // [[1, 'a'], [2, 'b'], [3, 'c']]
|
|
118
|
-
* ```
|
|
119
|
-
*/
|
|
120
|
-
static zip<T, U>(array1: T[], array2: U[]): [T, U][]
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Unzips an array of arrays into separate arrays.
|
|
124
|
-
*
|
|
125
|
-
* @param array - Array of arrays to unzip
|
|
126
|
-
* @returns Array of separate arrays, one for each position
|
|
127
|
-
*
|
|
128
|
-
* @example
|
|
129
|
-
* ```typescript
|
|
130
|
-
* import { Collection } from '@gesslar/toolkit'
|
|
131
|
-
*
|
|
132
|
-
* const zipped = [[1, 'a'], [2, 'b'], [3, 'c']]
|
|
133
|
-
* const result = Collection.unzip(zipped)
|
|
134
|
-
* console.log(result) // [[1, 2, 3], ['a', 'b', 'c']]
|
|
135
|
-
* ```
|
|
136
|
-
*/
|
|
137
|
-
static unzip<T>(array: T[][]): T[][]
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Maps an array through an async function, executing operations sequentially.
|
|
141
|
-
*
|
|
142
|
-
* Unlike Promise.all(array.map(fn)), this executes each async operation
|
|
143
|
-
* one at a time, maintaining order and preventing overwhelming external resources.
|
|
144
|
-
*
|
|
145
|
-
* @param array - The array to map over
|
|
146
|
-
* @param asyncFn - Async function called for each element: (element) => Promise<result>
|
|
147
|
-
* @returns Promise resolving to array of mapped results
|
|
148
|
-
*
|
|
149
|
-
* @throws {Sass} If array is not an Array or asyncFn is not a Function
|
|
150
|
-
*
|
|
151
|
-
* @example
|
|
152
|
-
* ```typescript
|
|
153
|
-
* import { Collection } from '@gesslar/toolkit'
|
|
154
|
-
*
|
|
155
|
-
* // Sequential API calls (won't overwhelm server)
|
|
156
|
-
* const urls = ['url1', 'url2', 'url3']
|
|
157
|
-
* const responses = await Collection.asyncMap(urls, async (url) => {
|
|
158
|
-
* return await fetch(url).then(r => r.json())
|
|
159
|
-
* })
|
|
160
|
-
* console.log(responses) // [data1, data2, data3]
|
|
161
|
-
*
|
|
162
|
-
* // Works with sync functions too
|
|
163
|
-
* const numbers = [1, 2, 3]
|
|
164
|
-
* const doubled = await Collection.asyncMap(numbers, async (n) => n * 2)
|
|
165
|
-
* console.log(doubled) // [2, 4, 6]
|
|
166
|
-
* ```
|
|
167
|
-
*/
|
|
168
|
-
static asyncMap<T, R>(array: T[], asyncFn: (element: T) => Promise<R> | R): Promise<R[]>
|
|
169
|
-
|
|
170
|
-
/** Check if all elements in an array are of a specified type or all the same type */
|
|
171
|
-
static isArrayUniform(arr: Array<unknown>, type?: string): boolean
|
|
172
|
-
|
|
173
|
-
/** Remove duplicate elements from an array, returning a new array with unique values */
|
|
174
|
-
static isArrayUnique<T>(arr: Array<T>): Array<T>
|
|
175
|
-
|
|
176
|
-
/** Get the intersection of two arrays */
|
|
177
|
-
static intersection<T>(arr1: Array<T>, arr2: Array<T>): Array<T>
|
|
178
|
-
|
|
179
|
-
/** Check if two arrays have any elements in common */
|
|
180
|
-
static intersects<T>(arr1: Array<T>, arr2: Array<T>): boolean
|
|
181
|
-
|
|
182
|
-
/** Pad an array to a specified length */
|
|
183
|
-
static arrayPad<T>(arr: Array<T>, length: number, value: T, position?: number): Array<T>
|
|
184
|
-
|
|
185
|
-
/** Filter an array asynchronously */
|
|
186
|
-
static asyncFilter<T>(arr: Array<T>, predicate: (item: T) => Promise<boolean>): Promise<Array<T>>
|
|
187
|
-
|
|
188
|
-
/** Clone an object */
|
|
189
|
-
static cloneObject<T extends Record<string, any>>(obj: T, freeze?: boolean): T
|
|
190
|
-
|
|
191
|
-
/** Check if an object is empty */
|
|
192
|
-
static isObjectEmpty(obj: Record<string, any>): boolean
|
|
193
|
-
|
|
194
|
-
/** Ensure a nested path of objects exists */
|
|
195
|
-
static assureObjectPath(obj: Record<string, any>, keys: Array<string>): Record<string, any>
|
|
196
|
-
|
|
197
|
-
/** Set a value in a nested object structure */
|
|
198
|
-
static setNestedValue(obj: Record<string, any>, keys: Array<string>, value: unknown): void
|
|
199
|
-
|
|
200
|
-
/** Deeply merge objects */
|
|
201
|
-
static mergeObject<T extends Record<string, any>>(...sources: Array<T>): T
|
|
202
|
-
|
|
203
|
-
/** Recursively freeze an object */
|
|
204
|
-
static deepFreezeObject<T>(obj: T): T
|
|
205
|
-
|
|
206
|
-
/** Map an object using a transformer function */
|
|
207
|
-
static mapObject<T extends Record<string, any>, R>(
|
|
208
|
-
original: T,
|
|
209
|
-
transformer: (key: string, value: any) => R | Promise<R>,
|
|
210
|
-
mutate?: boolean
|
|
211
|
-
): Promise<Record<string, R>>
|
|
212
|
-
|
|
213
|
-
/** Allocate an object from a source array and spec */
|
|
214
|
-
static allocateObject(
|
|
215
|
-
source: Array<unknown>,
|
|
216
|
-
spec:
|
|
217
|
-
| Array<unknown>
|
|
218
|
-
| ((source: Array<unknown>) => Promise<Array<unknown>> | Array<unknown>)
|
|
219
|
-
): Promise<Record<string, unknown>>
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Flattens one level of an array of plain objects, transposing values so each
|
|
223
|
-
* key maps to the collected values from every object.
|
|
224
|
-
*
|
|
225
|
-
* Accepts either a simple array of objects or an array that mixes objects and
|
|
226
|
-
* nested object arrays (one level deep). Nested arrays are flattened before
|
|
227
|
-
* transposition.
|
|
228
|
-
*
|
|
229
|
-
* @param input - Array of plain objects (optionally containing nested arrays)
|
|
230
|
-
* @returns Object with keys mapped to arrays of values from all input objects
|
|
231
|
-
*
|
|
232
|
-
* @throws {Sass} If input is not an Array or if any element is not a plain object after flattening
|
|
233
|
-
*
|
|
234
|
-
* @example
|
|
235
|
-
* ```typescript
|
|
236
|
-
* import { Collection } from '@gesslar/toolkit'
|
|
237
|
-
*
|
|
238
|
-
* const objects = [
|
|
239
|
-
* [{ name: 'Alice', age: 25 }],
|
|
240
|
-
* { name: 'Bob', age: 30 }
|
|
241
|
-
* ]
|
|
242
|
-
*
|
|
243
|
-
* const result = Collection.flattenObjectArray(objects)
|
|
244
|
-
* // result: { name: ['Alice', 'Bob'], age: [25, 30] }
|
|
245
|
-
* ```
|
|
246
|
-
*/
|
|
247
|
-
static flattenObjectArray(
|
|
248
|
-
input: Array<Record<string, unknown> | Array<Record<string, unknown>>>
|
|
249
|
-
): Record<string, Array<unknown>>
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Transposes an array of plain objects into an object of arrays, keyed by the
|
|
253
|
-
* original object keys.
|
|
254
|
-
*
|
|
255
|
-
* @param objects - Array of plain objects to transpose
|
|
256
|
-
* @returns Object with keys mapped to arrays of values from the input objects
|
|
257
|
-
*
|
|
258
|
-
* @throws {Sass} If objects is not an Array or if any element is not a plain object
|
|
259
|
-
*/
|
|
260
|
-
static transposeObjects(objects: Array<Record<string, unknown>>): Record<string, Array<unknown>>
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Trims falsy values from both ends of an array.
|
|
264
|
-
*
|
|
265
|
-
* @param arr - The array to trim
|
|
266
|
-
* @param except - Array of values to exclude from trimming (default: [])
|
|
267
|
-
* @returns The trimmed array (modified in place)
|
|
268
|
-
*
|
|
269
|
-
* @throws {Sass} If arr or except is not an Array
|
|
270
|
-
*
|
|
271
|
-
* @example
|
|
272
|
-
* ```typescript
|
|
273
|
-
* import { Collection } from '@gesslar/toolkit'
|
|
274
|
-
*
|
|
275
|
-
* const arr = [null, 0, 1, 2, "", undefined]
|
|
276
|
-
* Collection.trimArray(arr)
|
|
277
|
-
* console.log(arr) // [1, 2]
|
|
278
|
-
* ```
|
|
279
|
-
*/
|
|
280
|
-
static trimArray<T>(arr: Array<T>, except?: Array<T>): Array<T>
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* Trims falsy values from the right end of an array.
|
|
284
|
-
*
|
|
285
|
-
* @param arr - The array to trim
|
|
286
|
-
* @param except - Array of values to exclude from trimming (default: [])
|
|
287
|
-
* @returns The trimmed array (modified in place)
|
|
288
|
-
*
|
|
289
|
-
* @throws {Sass} If arr or except is not an Array
|
|
290
|
-
*
|
|
291
|
-
* @example
|
|
292
|
-
* ```typescript
|
|
293
|
-
* import { Collection } from '@gesslar/toolkit'
|
|
294
|
-
*
|
|
295
|
-
* const arr = [1, "", undefined]
|
|
296
|
-
* Collection.trimArrayRight(arr)
|
|
297
|
-
* console.log(arr) // [1]
|
|
298
|
-
* ```
|
|
299
|
-
*/
|
|
300
|
-
static trimArrayRight<T>(arr: Array<T>, except?: Array<T>): Array<T>
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* Trims falsy values from the left end of an array.
|
|
304
|
-
*
|
|
305
|
-
* @param arr - The array to trim
|
|
306
|
-
* @param except - Array of values to exclude from trimming (default: [])
|
|
307
|
-
* @returns The trimmed array (modified in place)
|
|
308
|
-
*
|
|
309
|
-
* @throws {Sass} If arr or except is not an Array
|
|
310
|
-
*
|
|
311
|
-
* @example
|
|
312
|
-
* ```typescript
|
|
313
|
-
* import { Collection } from '@gesslar/toolkit'
|
|
314
|
-
*
|
|
315
|
-
* const arr = [null, undefined, "value"]
|
|
316
|
-
* Collection.trimArrayLeft(arr)
|
|
317
|
-
* console.log(arr) // ["value"]
|
|
318
|
-
* ```
|
|
319
|
-
*/
|
|
320
|
-
static trimArrayLeft<T>(arr: Array<T>, except?: Array<T>): Array<T>
|
|
321
|
-
}
|