@mkvlrn/result 1.1.1 → 1.1.3
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 +3 -3
- package/build/index.js +17 -17
- package/package.json +1 -1
package/build/index.d.ts
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
* Result type to represent the outcome of an operation.
|
|
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
|
+
*
|
|
6
|
+
* It also aliases the success and error functions to make it easier to create
|
|
7
|
+
* Result objects.
|
|
5
8
|
*/
|
|
6
9
|
export type Result<T, E = Error> = {
|
|
7
10
|
readonly ok: true;
|
|
@@ -10,9 +13,6 @@ export type Result<T, E = Error> = {
|
|
|
10
13
|
readonly ok: false;
|
|
11
14
|
readonly error: E;
|
|
12
15
|
};
|
|
13
|
-
/**
|
|
14
|
-
* Helper functions to create Result objects.
|
|
15
|
-
*/
|
|
16
16
|
export declare const Result: {
|
|
17
17
|
success<T>(value: T): Result<T, never>;
|
|
18
18
|
error<E = Error>(error: E): Result<never, E>;
|
package/build/index.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Creates a successful Result with the given value.
|
|
3
|
+
* @param value The success value
|
|
4
|
+
* @returns A Result object representing success
|
|
3
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
|
|
4
18
|
export const Result = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* @param value The success value
|
|
8
|
-
* @returns A Result object representing success
|
|
9
|
-
*/
|
|
10
|
-
success: function (value) {
|
|
11
|
-
return { ok: true, value: value };
|
|
12
|
-
},
|
|
13
|
-
/**
|
|
14
|
-
* Creates a successful Result with the given value.
|
|
15
|
-
* @param value The success value
|
|
16
|
-
* @returns A Result object representing success
|
|
17
|
-
*/
|
|
18
|
-
error: function (error) {
|
|
19
|
-
return { ok: false, error: error };
|
|
20
|
-
},
|
|
19
|
+
success: resultSuccess,
|
|
20
|
+
error: resultError,
|
|
21
21
|
};
|