@gesslar/toolkit 3.5.0 → 3.6.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 -0
- package/package.json +17 -14
- package/src/browser/index.js +1 -0
- package/src/browser/lib/Time.js +54 -0
- package/src/index.js +1 -0
- package/src/types/browser/index.d.ts +1 -0
- package/src/types/browser/lib/Time.d.ts +42 -0
- package/src/types/browser/lib/Time.d.ts.map +1 -0
- package/src/types/index.d.ts +1 -0
package/README.md
CHANGED
|
@@ -21,6 +21,7 @@ a Tauri app.
|
|
|
21
21
|
| Promised | Promise utilities for settling, filtering, and extracting values from promise results |
|
|
22
22
|
| Sass | Custom Error class with enhanced features |
|
|
23
23
|
| Tantrum | AggregateError implementation |
|
|
24
|
+
| Time | Timing operations and promise-based delays with cancellation support |
|
|
24
25
|
| Type | String-based type management (exported as TypeSpec in browser) |
|
|
25
26
|
| Util | General utility functions |
|
|
26
27
|
| Valid | Validation and assertion methods |
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"email": "bmw@gesslar.dev",
|
|
7
7
|
"url": "https://gesslar.dev"
|
|
8
8
|
},
|
|
9
|
-
"version": "3.
|
|
9
|
+
"version": "3.6.1",
|
|
10
10
|
"license": "Unlicense",
|
|
11
11
|
"homepage": "https://github.com/gesslar/toolkit#readme",
|
|
12
12
|
"repository": {
|
|
@@ -52,25 +52,28 @@
|
|
|
52
52
|
"engines": {
|
|
53
53
|
"node": ">=22"
|
|
54
54
|
},
|
|
55
|
-
"scripts": {
|
|
56
|
-
"types:build": "node -e \"require('fs').rmSync('src/types',{recursive:true,force:true});\" && tsc -p tsconfig.types.json",
|
|
57
|
-
"prepublishOnly": "npm run types:build",
|
|
58
|
-
"lint": "eslint src/",
|
|
59
|
-
"lint:fix": "eslint src/ --fix",
|
|
60
|
-
"submit": "npm publish --access public --//registry.npmjs.org/:_authToken=\"${NPM_ACCESS_TOKEN}\"",
|
|
61
|
-
"update": "npx npm-check-updates -u && npm install",
|
|
62
|
-
"test": "node --test tests/**/*.test.js",
|
|
63
|
-
"pr": "gt submit -p --ai"
|
|
64
|
-
},
|
|
65
55
|
"dependencies": {
|
|
66
|
-
"@gesslar/colours": "^0.
|
|
56
|
+
"@gesslar/colours": "^0.5.0",
|
|
67
57
|
"ajv": "^8.17.1",
|
|
68
58
|
"globby": "^16.1.0",
|
|
69
59
|
"json5": "^2.2.3",
|
|
70
60
|
"yaml": "^2.8.2"
|
|
71
61
|
},
|
|
72
62
|
"devDependencies": {
|
|
73
|
-
"@gesslar/uglier": "^0.
|
|
63
|
+
"@gesslar/uglier": "^0.4.0",
|
|
64
|
+
"eslint": "^9.39.2",
|
|
74
65
|
"typescript": "^5.9.3"
|
|
66
|
+
},
|
|
67
|
+
"scripts": {
|
|
68
|
+
"types:build": "node -e \"require('fs').rmSync('src/types',{recursive:true,force:true});\" && tsc -p tsconfig.types.json",
|
|
69
|
+
"lint": "eslint src/",
|
|
70
|
+
"lint:fix": "eslint src/ --fix",
|
|
71
|
+
"submit": "pnpm publish --access public --//registry.npmjs.org/:_authToken=\"${NPM_ACCESS_TOKEN}\"",
|
|
72
|
+
"update": "pnpm up --latest --recursive",
|
|
73
|
+
"test": "node --test tests/**/*.test.js",
|
|
74
|
+
"pr": "gt submit -p --ai",
|
|
75
|
+
"patch": "pnpm version patch",
|
|
76
|
+
"minor": "pnpm version minor",
|
|
77
|
+
"major": "pnpm version major"
|
|
75
78
|
}
|
|
76
|
-
}
|
|
79
|
+
}
|
package/src/browser/index.js
CHANGED
|
@@ -11,6 +11,7 @@ export {default as Notify} from "./lib/Notify.js"
|
|
|
11
11
|
export {default as Promised} from "./lib/Promised.js"
|
|
12
12
|
export {default as Sass} from "./lib/Sass.js"
|
|
13
13
|
export {default as Tantrum} from "./lib/Tantrum.js"
|
|
14
|
+
export {default as Time} from "./lib/Time.js"
|
|
14
15
|
export {default as Type} from "./lib/TypeSpec.js"
|
|
15
16
|
export {default as Util} from "./lib/Util.js"
|
|
16
17
|
export {default as Valid} from "./lib/Valid.js"
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import Valid from "./Valid.js"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Utility class for timing operations and promise-based delays.
|
|
5
|
+
* Provides methods for creating cancellable timeout promises.
|
|
6
|
+
*/
|
|
7
|
+
export default class Time {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a promise that resolves after a specified delay.
|
|
10
|
+
* The returned promise includes a timerId property that can be used with cancel().
|
|
11
|
+
*
|
|
12
|
+
* @param {number} delay - Delay in milliseconds before resolving (must be >= 0)
|
|
13
|
+
* @param {unknown} [value] - Optional value to resolve with after the delay
|
|
14
|
+
* @returns {Promise<unknown> & {timerId: number}} Promise that resolves with the value after delay, extended with timerId property
|
|
15
|
+
* @throws {Sass} If delay is not a number or is negative
|
|
16
|
+
* @example
|
|
17
|
+
* // Wait 1 second then continue
|
|
18
|
+
* await Time.after(1000)
|
|
19
|
+
*
|
|
20
|
+
* // Wait 1 second then get a value
|
|
21
|
+
* const result = await Time.after(1000, 'done')
|
|
22
|
+
*
|
|
23
|
+
* // Create a cancellable delay
|
|
24
|
+
* const promise = Time.after(5000, 'data')
|
|
25
|
+
* Time.cancel(promise) // Cancel before it resolves
|
|
26
|
+
*/
|
|
27
|
+
static after(delay, value) {
|
|
28
|
+
Valid.type(delay, "Number", "delay")
|
|
29
|
+
Valid.assert(delay >= 0, "delay must be non-negative", delay)
|
|
30
|
+
|
|
31
|
+
let timerId
|
|
32
|
+
const promise = new Promise(resolve => {
|
|
33
|
+
timerId = setTimeout(() => resolve(value), delay)
|
|
34
|
+
})
|
|
35
|
+
promise.timerId = timerId
|
|
36
|
+
|
|
37
|
+
return promise
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Cancels a promise created by Time.after() by clearing its timeout.
|
|
42
|
+
* If the promise has already resolved or is not a Time.after() promise, this is a no-op.
|
|
43
|
+
*
|
|
44
|
+
* @param {Promise<unknown> & {timerId?: number}} promise - Promise returned from Time.after() to cancel
|
|
45
|
+
* @returns {void}
|
|
46
|
+
* @example
|
|
47
|
+
* const promise = Time.after(5000, 'data')
|
|
48
|
+
* Time.cancel(promise) // Prevents the promise from resolving
|
|
49
|
+
*/
|
|
50
|
+
static cancel(promise) {
|
|
51
|
+
if(promise && typeof promise === "object" && "timerId" in promise)
|
|
52
|
+
clearTimeout(promise.timerId)
|
|
53
|
+
}
|
|
54
|
+
}
|
package/src/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export {default as Data} from "./browser/lib/Data.js"
|
|
|
4
4
|
export {default as Disposer} from "./browser/lib/Disposer.js"
|
|
5
5
|
export {Disposer as DisposerClass} from "./browser/lib/Disposer.js"
|
|
6
6
|
export {default as Promised} from "./browser/lib/Promised.js"
|
|
7
|
+
export {default as Time} from "./browser/lib/Time.js"
|
|
7
8
|
export {default as Type} from "./browser/lib/TypeSpec.js"
|
|
8
9
|
export {default as Valid} from "./lib/Valid.js"
|
|
9
10
|
|
|
@@ -4,6 +4,7 @@ export { default as Notify } from "./lib/Notify.js";
|
|
|
4
4
|
export { default as Promised } from "./lib/Promised.js";
|
|
5
5
|
export { default as Sass } from "./lib/Sass.js";
|
|
6
6
|
export { default as Tantrum } from "./lib/Tantrum.js";
|
|
7
|
+
export { default as Time } from "./lib/Time.js";
|
|
7
8
|
export { default as Type } from "./lib/TypeSpec.js";
|
|
8
9
|
export { default as Util } from "./lib/Util.js";
|
|
9
10
|
export { default as Valid } from "./lib/Valid.js";
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility class for timing operations and promise-based delays.
|
|
3
|
+
* Provides methods for creating cancellable timeout promises.
|
|
4
|
+
*/
|
|
5
|
+
export default class Time {
|
|
6
|
+
/**
|
|
7
|
+
* Creates a promise that resolves after a specified delay.
|
|
8
|
+
* The returned promise includes a timerId property that can be used with cancel().
|
|
9
|
+
*
|
|
10
|
+
* @param {number} delay - Delay in milliseconds before resolving (must be >= 0)
|
|
11
|
+
* @param {unknown} [value] - Optional value to resolve with after the delay
|
|
12
|
+
* @returns {Promise<unknown> & {timerId: number}} Promise that resolves with the value after delay, extended with timerId property
|
|
13
|
+
* @throws {Sass} If delay is not a number or is negative
|
|
14
|
+
* @example
|
|
15
|
+
* // Wait 1 second then continue
|
|
16
|
+
* await Time.after(1000)
|
|
17
|
+
*
|
|
18
|
+
* // Wait 1 second then get a value
|
|
19
|
+
* const result = await Time.after(1000, 'done')
|
|
20
|
+
*
|
|
21
|
+
* // Create a cancellable delay
|
|
22
|
+
* const promise = Time.after(5000, 'data')
|
|
23
|
+
* Time.cancel(promise) // Cancel before it resolves
|
|
24
|
+
*/
|
|
25
|
+
static after(delay: number, value?: unknown): Promise<unknown> & {
|
|
26
|
+
timerId: number;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Cancels a promise created by Time.after() by clearing its timeout.
|
|
30
|
+
* If the promise has already resolved or is not a Time.after() promise, this is a no-op.
|
|
31
|
+
*
|
|
32
|
+
* @param {Promise<unknown> & {timerId?: number}} promise - Promise returned from Time.after() to cancel
|
|
33
|
+
* @returns {void}
|
|
34
|
+
* @example
|
|
35
|
+
* const promise = Time.after(5000, 'data')
|
|
36
|
+
* Time.cancel(promise) // Prevents the promise from resolving
|
|
37
|
+
*/
|
|
38
|
+
static cancel(promise: Promise<unknown> & {
|
|
39
|
+
timerId?: number;
|
|
40
|
+
}): void;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=Time.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Time.d.ts","sourceRoot":"","sources":["../../../browser/lib/Time.js"],"names":[],"mappings":"AAEA;;;GAGG;AACH;IACE;;;;;;;;;;;;;;;;;;OAkBG;IACH,oBAfW,MAAM,UACN,OAAO,GACL,OAAO,CAAC,OAAO,CAAC,GAAG;QAAC,OAAO,EAAE,MAAM,CAAA;KAAC,CAwBhD;IAED;;;;;;;;;OASG;IACH,uBANW,OAAO,CAAC,OAAO,CAAC,GAAG;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAC,GACnC,IAAI,CAQhB;CACF"}
|
package/src/types/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { default as Collection } from "./browser/lib/Collection.js";
|
|
2
2
|
export { default as Data } from "./browser/lib/Data.js";
|
|
3
3
|
export { default as Promised } from "./browser/lib/Promised.js";
|
|
4
|
+
export { default as Time } from "./browser/lib/Time.js";
|
|
4
5
|
export { default as Type } from "./browser/lib/TypeSpec.js";
|
|
5
6
|
export { default as Valid } from "./lib/Valid.js";
|
|
6
7
|
export { default as Sass } from "./lib/Sass.js";
|