@mkvlrn/result 1.1.3 → 2.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 +4 -5
- package/build/index.js +12 -19
- package/package.json +2 -2
package/build/index.d.ts
CHANGED
|
@@ -3,17 +3,16 @@
|
|
|
3
3
|
* It can either be a success with a value or an error with an error message.
|
|
4
4
|
* This is a generic type that can be used with any type of value and error.
|
|
5
5
|
*
|
|
6
|
-
* It also
|
|
7
|
-
* Result objects.
|
|
6
|
+
* It is also an alias object containing the ok and error functions to
|
|
7
|
+
* make it easier to create Result objects.
|
|
8
8
|
*/
|
|
9
9
|
export type Result<T, E = Error> = {
|
|
10
|
-
readonly
|
|
10
|
+
readonly error: undefined;
|
|
11
11
|
readonly value: T;
|
|
12
12
|
} | {
|
|
13
|
-
readonly ok: false;
|
|
14
13
|
readonly error: E;
|
|
15
14
|
};
|
|
16
15
|
export declare const Result: {
|
|
17
|
-
|
|
16
|
+
ok<T>(value: T): Result<T, never>;
|
|
18
17
|
error<E = Error>(error: E): Result<never, E>;
|
|
19
18
|
};
|
package/build/index.js
CHANGED
|
@@ -1,21 +1,14 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Creates a successful Result with the given value.
|
|
3
|
-
* @param value The success value
|
|
4
|
-
* @returns A Result object representing success
|
|
5
|
-
*/
|
|
6
|
-
function resultSuccess(value) {
|
|
7
|
-
return { ok: true, value: value };
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Creates a successful Result with the given value.
|
|
11
|
-
* @param value The success value
|
|
12
|
-
* @returns A Result object representing success
|
|
13
|
-
*/
|
|
14
|
-
function resultError(error) {
|
|
15
|
-
return { ok: false, error: error };
|
|
16
|
-
}
|
|
17
|
-
// biome-ignore lint/nursery/useExplicitType: https://github.com/biomejs/biome/issues/5932
|
|
18
1
|
export const Result = {
|
|
19
|
-
|
|
20
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Creates a successful Result with the given value.
|
|
4
|
+
* @param value The success value
|
|
5
|
+
* @returns A Result object representing success
|
|
6
|
+
*/
|
|
7
|
+
ok: (value) => ({ error: undefined, value }),
|
|
8
|
+
/**
|
|
9
|
+
* Creates an error Result with the given error.
|
|
10
|
+
* @param error The error value
|
|
11
|
+
* @returns A Result object representing error
|
|
12
|
+
*/
|
|
13
|
+
error: (error) => ({ error }),
|
|
21
14
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mkvlrn/result",
|
|
3
3
|
"description": "Result type for TypeScript",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"publishConfig": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"build": "rm -rf build && tsc"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@biomejs/biome": "^2.0.
|
|
22
|
+
"@biomejs/biome": "^2.0.6",
|
|
23
23
|
"typescript": "^5.8.3"
|
|
24
24
|
}
|
|
25
25
|
}
|