@mkvlrn/result 4.0.19 → 5.0.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/build/index.d.ts +21 -23
- package/build/index.js +1 -7
- package/package.json +10 -8
package/build/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Result type to represent the outcome of an operation.
|
|
3
4
|
* It can either be a success with a value or an error.
|
|
@@ -6,33 +7,30 @@
|
|
|
6
7
|
* It is also an alias object containing the ok and error functions to
|
|
7
8
|
* make it easier to create Result objects.
|
|
8
9
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
type Result<T, E extends Error> = {
|
|
11
|
+
readonly isError: false;
|
|
12
|
+
readonly isOk: true;
|
|
13
|
+
readonly value: T;
|
|
13
14
|
} | {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
readonly isError: true;
|
|
16
|
+
readonly isOk: false;
|
|
17
|
+
readonly error: E;
|
|
17
18
|
};
|
|
18
19
|
/**
|
|
19
20
|
* Async version of Result type that wraps a Result in a Promise.
|
|
20
21
|
*/
|
|
21
|
-
|
|
22
|
+
type AsyncResult<T, E extends Error> = Promise<Result<T, E>>;
|
|
22
23
|
/**
|
|
23
|
-
*
|
|
24
|
+
* Creates a successful Result with the given value.
|
|
25
|
+
* @param value The success value
|
|
26
|
+
* @returns A Result object representing success
|
|
24
27
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
* @param error The error value
|
|
35
|
-
* @returns A Result object representing error
|
|
36
|
-
*/
|
|
37
|
-
error<E extends Error>(error: E): Result<never, E>;
|
|
38
|
-
};
|
|
28
|
+
declare function ok<T>(value: T): Result<T, never>;
|
|
29
|
+
/**
|
|
30
|
+
* Creates an error Result with the given error.
|
|
31
|
+
* @param error The error value
|
|
32
|
+
* @returns A Result object representing error
|
|
33
|
+
*/
|
|
34
|
+
declare function err<E extends Error>(error: E): Result<never, E>;
|
|
35
|
+
//#endregion
|
|
36
|
+
export { AsyncResult, Result, err, ok };
|
package/build/index.js
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Result utility functions for creating Result objects.
|
|
3
|
-
*/
|
|
4
|
-
export const R = {
|
|
5
|
-
ok: (value) => ({ isError: false, isOk: true, value }),
|
|
6
|
-
error: (error) => ({ isError: true, isOk: false, error }),
|
|
7
|
-
};
|
|
1
|
+
function e(e){return{isError:!1,isOk:!0,value:e}}function t(e){return{isError:!0,isOk:!1,error:e}}export{t as err,e as ok};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mkvlrn/result",
|
|
3
3
|
"description": "Simple Result type/pattern for TypeScript",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "5.0.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"author": "Mike Valeriano <mkvlrn@proton.me>",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"result"
|
|
16
16
|
],
|
|
17
17
|
"engines": {
|
|
18
|
-
"node": "
|
|
18
|
+
"node": "24"
|
|
19
19
|
},
|
|
20
20
|
"files": [
|
|
21
21
|
"build"
|
|
@@ -25,18 +25,20 @@
|
|
|
25
25
|
"default": "./build/index.js"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@types/node": "^24.
|
|
29
|
-
"lint-staged": "^16.2.
|
|
30
|
-
"rimraf": "^6.0
|
|
28
|
+
"@types/node": "^24.10.0",
|
|
29
|
+
"lint-staged": "^16.2.6",
|
|
30
|
+
"rimraf": "^6.1.0",
|
|
31
31
|
"tsc-files": "^1.1.4",
|
|
32
|
+
"tsdown": "^0.16.1",
|
|
32
33
|
"tsx": "^4.20.6",
|
|
33
|
-
"typescript": "^5.9.3"
|
|
34
|
+
"typescript": "^5.9.3",
|
|
35
|
+
"vite-tsconfig-paths": "^5.1.4"
|
|
34
36
|
},
|
|
35
37
|
"dependencies": {
|
|
36
|
-
"vitest": "^
|
|
38
|
+
"vitest": "^4.0.8"
|
|
37
39
|
},
|
|
38
40
|
"scripts": {
|
|
39
|
-
"build": "
|
|
41
|
+
"build": "tsdown",
|
|
40
42
|
"typecheck": "tsc"
|
|
41
43
|
}
|
|
42
44
|
}
|