@mkvlrn/result 6.0.0 → 6.0.2
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 +22 -0
- package/build/index.js +35 -0
- package/build/index.js.map +1 -0
- package/package.json +4 -1
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
type ResultSync<T, E extends Error> = {
|
|
3
|
+
readonly isError: false;
|
|
4
|
+
readonly value: T;
|
|
5
|
+
} | {
|
|
6
|
+
readonly isError: true;
|
|
7
|
+
readonly error: E;
|
|
8
|
+
};
|
|
9
|
+
declare const ResultSync: {
|
|
10
|
+
readonly ok: typeof ok;
|
|
11
|
+
readonly err: typeof err;
|
|
12
|
+
};
|
|
13
|
+
type ResultAsync<T, E extends Error> = Promise<ResultSync<T, E>>;
|
|
14
|
+
declare const ResultAsync: {
|
|
15
|
+
readonly ok: typeof ok;
|
|
16
|
+
readonly err: typeof err;
|
|
17
|
+
};
|
|
18
|
+
declare function ok<T>(value: T): ResultSync<T, never>;
|
|
19
|
+
declare function err<E extends Error>(error: E): ResultSync<never, E>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { ResultAsync, ResultSync };
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
package/build/index.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/index.ts
|
|
2
|
+
const ResultSync = {
|
|
3
|
+
ok,
|
|
4
|
+
err
|
|
5
|
+
};
|
|
6
|
+
const ResultAsync = {
|
|
7
|
+
ok,
|
|
8
|
+
err
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Creates a successful Result with the given value.
|
|
12
|
+
* @param value The success value
|
|
13
|
+
* @returns A Result object representing success
|
|
14
|
+
*/
|
|
15
|
+
function ok(value) {
|
|
16
|
+
return {
|
|
17
|
+
isError: false,
|
|
18
|
+
value
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Creates an error Result with the given error.
|
|
23
|
+
* @param error The error value
|
|
24
|
+
* @returns A Result object representing error
|
|
25
|
+
*/
|
|
26
|
+
function err(error) {
|
|
27
|
+
return {
|
|
28
|
+
isError: true,
|
|
29
|
+
error
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { ResultAsync, ResultSync };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * Result type to represent the synchronous outcome of an operation.\n * It can either be a success with a value or an error.\n *\n * It is also an object containing the ok and err functions to\n * make it easier to create Result objects.\n */\nexport type ResultSync<T, E extends Error> =\n | { readonly isError: false; readonly value: T }\n | { readonly isError: true; readonly error: E };\n\nexport const ResultSync = { ok, err } as const;\n\n/**\n * Async version of Result type that wraps a Result in a Promise.\n *\n * It is also an object containing the ok and err functions to\n * make it easier to create Result objects for async workflows.\n */\nexport type ResultAsync<T, E extends Error> = Promise<ResultSync<T, E>>;\n\nexport const ResultAsync = { ok, err } as const;\n\n/**\n * Creates a successful Result with the given value.\n * @param value The success value\n * @returns A Result object representing success\n */\nfunction ok<T>(value: T): ResultSync<T, never> {\n return { isError: false, value };\n}\n\n/**\n * Creates an error Result with the given error.\n * @param error The error value\n * @returns A Result object representing error\n */\nfunction err<E extends Error>(error: E): ResultSync<never, E> {\n return { isError: true, error };\n}\n"],"mappings":";AAWA,MAAa,aAAa;CAAE;CAAI;AAAI;AAUpC,MAAa,cAAc;CAAE;CAAI;AAAI;;;;;;AAOrC,SAAS,GAAM,OAAgC;CAC7C,OAAO;EAAE,SAAS;EAAO;CAAM;AACjC;;;;;;AAOA,SAAS,IAAqB,OAAgC;CAC5D,OAAO;EAAE,SAAS;EAAM;CAAM;AAChC"}
|
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": "6.0.
|
|
4
|
+
"version": "6.0.2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"author": "Mike Valeriano <mkvlrn@gmail.com>",
|
|
@@ -34,5 +34,8 @@
|
|
|
34
34
|
"tsdown": "0.22.14",
|
|
35
35
|
"typescript": "^7.0.2",
|
|
36
36
|
"vitest": "^4.1.10"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsdown"
|
|
37
40
|
}
|
|
38
41
|
}
|