@terrygonguet/utils 0.2.0 → 0.2.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/dist/index.d.ts +2 -1
- package/dist/index.js +7 -2
- package/package.json +4 -7
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ declare function noop(): void;
|
|
|
7
7
|
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
|
-
declare function safe<T, Err =
|
|
10
|
+
declare function safe<T, Err = Error>(f: () => Promise<T>): Promise<[null, T] | [Err, null]>;
|
|
11
|
+
declare function safe<T, Err = Error>(f: () => T): [null, T] | [Err, null];
|
|
11
12
|
|
|
12
13
|
export { clamp, createNoopProxy, exhaustive, hash, noop, range, safe };
|
package/dist/index.js
CHANGED
|
@@ -37,8 +37,13 @@ function* range(start, end, step = 1) {
|
|
|
37
37
|
}
|
|
38
38
|
function safe(f) {
|
|
39
39
|
try {
|
|
40
|
-
const
|
|
41
|
-
|
|
40
|
+
const promiseOrResult = f();
|
|
41
|
+
if (promiseOrResult instanceof Promise)
|
|
42
|
+
return promiseOrResult.then(
|
|
43
|
+
(result) => [null, result],
|
|
44
|
+
(error) => [error, null]
|
|
45
|
+
);
|
|
46
|
+
else return [null, promiseOrResult];
|
|
42
47
|
} catch (error) {
|
|
43
48
|
return [error, null];
|
|
44
49
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@terrygonguet/utils",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "vite",
|
|
8
8
|
"build": "tsup",
|
|
9
|
-
"test": "vitest test --update"
|
|
10
|
-
"coverage": "vitest run --coverage"
|
|
9
|
+
"test": "vitest test --update"
|
|
11
10
|
},
|
|
12
11
|
"files": [
|
|
13
12
|
"dist"
|
|
@@ -31,13 +30,11 @@
|
|
|
31
30
|
}
|
|
32
31
|
},
|
|
33
32
|
"devDependencies": {
|
|
34
|
-
"@vitest/coverage-v8": "^0.32.0",
|
|
35
|
-
"@vitest/ui": "^0.32.0",
|
|
36
33
|
"prettier": "^2.8.8",
|
|
37
34
|
"tsup": "^8.1.0",
|
|
38
35
|
"typescript": "^5.0.2",
|
|
39
|
-
"vite": "^4.
|
|
40
|
-
"vitest": "^
|
|
36
|
+
"vite": "^5.4.8",
|
|
37
|
+
"vitest": "^2.1.2"
|
|
41
38
|
},
|
|
42
39
|
"author": {
|
|
43
40
|
"email": "terry@gonguet.com",
|