@zokugun/xtry 0.12.0 → 0.12.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/lib/cjs/unwrap.cjs +5 -2
- package/lib/cjs/unwrap.d.cts +12 -4
- package/lib/esm/unwrap.d.mts +12 -4
- package/lib/esm/unwrap.mjs +5 -2
- package/package.json +2 -2
package/lib/cjs/unwrap.cjs
CHANGED
|
@@ -22,9 +22,12 @@ function match(result, handlers) {
|
|
|
22
22
|
return handlers.success(result.value);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
function unwrap(result) {
|
|
25
|
+
function unwrap(result, transform) {
|
|
26
26
|
if (result.fails) {
|
|
27
|
-
if (
|
|
27
|
+
if (transform) {
|
|
28
|
+
throw transform(result.error);
|
|
29
|
+
}
|
|
30
|
+
else if (result.error instanceof Error) {
|
|
28
31
|
throw result.error;
|
|
29
32
|
}
|
|
30
33
|
else {
|
package/lib/cjs/unwrap.d.cts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import type { Result } from './result.cjs';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
type LimitedResult<T, E> = {
|
|
3
|
+
error: E;
|
|
4
|
+
fails: true;
|
|
5
|
+
} | {
|
|
6
|
+
fails: false;
|
|
7
|
+
value: T;
|
|
8
|
+
};
|
|
9
|
+
export declare function map<T, E, U>(result: LimitedResult<T, E>, transform: (value: T) => U): Result<U, E>;
|
|
10
|
+
export declare function match<T, E, R>(result: LimitedResult<T, E>, handlers: {
|
|
4
11
|
failure: (error: E) => R;
|
|
5
12
|
success: (value: T) => R;
|
|
6
13
|
}): R;
|
|
7
|
-
export declare function unwrap<T, E>(result:
|
|
8
|
-
export declare function unwrapOr<T, E, F>(result:
|
|
14
|
+
export declare function unwrap<T, E>(result: LimitedResult<T, E>, transform?: (error: E) => Error): T;
|
|
15
|
+
export declare function unwrapOr<T, E, F>(result: LimitedResult<T, E>, fallback: F): F | T;
|
|
16
|
+
export {};
|
package/lib/esm/unwrap.d.mts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import type { Result } from './result.mjs';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
type LimitedResult<T, E> = {
|
|
3
|
+
error: E;
|
|
4
|
+
fails: true;
|
|
5
|
+
} | {
|
|
6
|
+
fails: false;
|
|
7
|
+
value: T;
|
|
8
|
+
};
|
|
9
|
+
export declare function map<T, E, U>(result: LimitedResult<T, E>, transform: (value: T) => U): Result<U, E>;
|
|
10
|
+
export declare function match<T, E, R>(result: LimitedResult<T, E>, handlers: {
|
|
4
11
|
failure: (error: E) => R;
|
|
5
12
|
success: (value: T) => R;
|
|
6
13
|
}): R;
|
|
7
|
-
export declare function unwrap<T, E>(result:
|
|
8
|
-
export declare function unwrapOr<T, E, F>(result:
|
|
14
|
+
export declare function unwrap<T, E>(result: LimitedResult<T, E>, transform?: (error: E) => Error): T;
|
|
15
|
+
export declare function unwrapOr<T, E, F>(result: LimitedResult<T, E>, fallback: F): F | T;
|
|
16
|
+
export {};
|
package/lib/esm/unwrap.mjs
CHANGED
|
@@ -16,9 +16,12 @@ export function match(result, handlers) {
|
|
|
16
16
|
return handlers.success(result.value);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
export function unwrap(result) {
|
|
19
|
+
export function unwrap(result, transform) {
|
|
20
20
|
if (result.fails) {
|
|
21
|
-
if (
|
|
21
|
+
if (transform) {
|
|
22
|
+
throw transform(result.error);
|
|
23
|
+
}
|
|
24
|
+
else if (result.error instanceof Error) {
|
|
22
25
|
throw result.error;
|
|
23
26
|
}
|
|
24
27
|
else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zokugun/xtry",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.1",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Baptiste Augrain",
|
|
6
6
|
"email": "daiyam@zokugun.org"
|
|
@@ -111,7 +111,7 @@
|
|
|
111
111
|
"@zokugun/eslint-config-test": "0.2.0",
|
|
112
112
|
"@zokugun/eslint-config-ts": "0.3.2",
|
|
113
113
|
"@zokugun/fs-extra-plus": "0.6.1",
|
|
114
|
-
"@zokugun/tsc-leda": "0.
|
|
114
|
+
"@zokugun/tsc-leda": "0.9.0",
|
|
115
115
|
"eslint": "10.8.1",
|
|
116
116
|
"fixpack": "4.0.0",
|
|
117
117
|
"fs-extra": "11.3.5",
|