@terrygonguet/utils 0.7.1 → 0.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/dist/index.d.ts +3 -1
- package/dist/index.js +13 -0
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -8,8 +8,10 @@ declare function exhaustive(_: never): never;
|
|
|
8
8
|
declare function hash(message: string): Promise<ArrayBuffer>;
|
|
9
9
|
declare function range(start: number, end: number, step?: number): Generator<number, void, unknown>;
|
|
10
10
|
declare function yesno(value?: string): boolean;
|
|
11
|
+
declare function mapListPush<Key, T>(map: Map<Key, T[]>, key: Key, value: T): Map<Key, T[]>;
|
|
12
|
+
declare function recordListPush<Key extends string, T>(record: Record<Key, T[]>, key: Key, value: T): Record<Key, T[]>;
|
|
11
13
|
type ExecResult<T, Err = Error> = [null, T] | [Err, null];
|
|
12
14
|
declare function tryCatch<F extends (...args: any) => any>(f: F, ...args: Parameters<F>): ReturnType<F> extends Promise<any> ? Promise<ExecResult<Awaited<ReturnType<F>>>> : ExecResult<ReturnType<F>>;
|
|
13
15
|
declare function tryCatch<Err, F extends (...args: any) => any>(f: F, ...args: Parameters<F>): ReturnType<F> extends Promise<any> ? Promise<ExecResult<Awaited<ReturnType<F>>, Err>> : ExecResult<ReturnType<F>, Err>;
|
|
14
16
|
|
|
15
|
-
export { type ExecResult, clamp, createNoopProxy, exhaustive, hash, noop, range, tryCatch, yesno };
|
|
17
|
+
export { type ExecResult, clamp, createNoopProxy, exhaustive, hash, mapListPush, noop, range, recordListPush, tryCatch, yesno };
|
package/dist/index.js
CHANGED
|
@@ -47,6 +47,17 @@ function yesno(value) {
|
|
|
47
47
|
return false;
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
+
function mapListPush(map, key, value) {
|
|
51
|
+
const arr = map.get(key) ?? [];
|
|
52
|
+
arr.push(value);
|
|
53
|
+
return map.set(key, arr);
|
|
54
|
+
}
|
|
55
|
+
function recordListPush(record, key, value) {
|
|
56
|
+
const arr = record[key] ?? [];
|
|
57
|
+
arr.push(value);
|
|
58
|
+
record[key] = arr;
|
|
59
|
+
return record;
|
|
60
|
+
}
|
|
50
61
|
function tryCatch(f, ...args) {
|
|
51
62
|
try {
|
|
52
63
|
const promiseOrResult = f(...args);
|
|
@@ -65,8 +76,10 @@ export {
|
|
|
65
76
|
createNoopProxy,
|
|
66
77
|
exhaustive,
|
|
67
78
|
hash,
|
|
79
|
+
mapListPush,
|
|
68
80
|
noop,
|
|
69
81
|
range,
|
|
82
|
+
recordListPush,
|
|
70
83
|
tryCatch,
|
|
71
84
|
yesno
|
|
72
85
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@terrygonguet/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"scripts": {
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"prettier": "^3.
|
|
42
|
-
"tsup": "^8.
|
|
43
|
-
"typescript": "^5.
|
|
44
|
-
"vite": "^6.3.
|
|
45
|
-
"vitest": "^3.
|
|
41
|
+
"prettier": "^3.6.2",
|
|
42
|
+
"tsup": "^8.5.0",
|
|
43
|
+
"typescript": "^5.9.3",
|
|
44
|
+
"vite": "^6.3.6",
|
|
45
|
+
"vitest": "^3.2.4"
|
|
46
46
|
},
|
|
47
47
|
"author": {
|
|
48
48
|
"email": "terry@gonguet.com",
|