@consolidados/results 0.1.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/.release-it.json +20 -0
- package/README.md +361 -0
- package/dist/err-B7LUEZ0f.d.cts +128 -0
- package/dist/err-B7LUEZ0f.d.ts +128 -0
- package/dist/helpers/match.cjs +27 -0
- package/dist/helpers/match.cjs.map +1 -0
- package/dist/helpers/match.d.cts +13 -0
- package/dist/helpers/match.d.ts +13 -0
- package/dist/helpers/match.js +25 -0
- package/dist/helpers/match.js.map +1 -0
- package/dist/index.cjs +301 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +295 -0
- package/dist/index.js.map +1 -0
- package/dist/option/index.cjs +126 -0
- package/dist/option/index.cjs.map +1 -0
- package/dist/option/index.d.cts +2 -0
- package/dist/option/index.d.ts +2 -0
- package/dist/option/index.js +123 -0
- package/dist/option/index.js.map +1 -0
- package/dist/option/option.cjs +126 -0
- package/dist/option/option.cjs.map +1 -0
- package/dist/option/option.d.cts +25 -0
- package/dist/option/option.d.ts +25 -0
- package/dist/option/option.js +123 -0
- package/dist/option/option.js.map +1 -0
- package/dist/option-DpT8KCGE.d.cts +96 -0
- package/dist/option-DpT8KCGE.d.ts +96 -0
- package/dist/result/index.cjs +156 -0
- package/dist/result/index.cjs.map +1 -0
- package/dist/result/index.d.cts +2 -0
- package/dist/result/index.d.ts +2 -0
- package/dist/result/index.js +153 -0
- package/dist/result/index.js.map +1 -0
- package/dist/result/result.cjs +158 -0
- package/dist/result/result.cjs.map +1 -0
- package/dist/result/result.d.cts +27 -0
- package/dist/result/result.d.ts +27 -0
- package/dist/result/result.js +153 -0
- package/dist/result/result.js.map +1 -0
- package/dist/types/globals.cjs +4 -0
- package/dist/types/globals.cjs.map +1 -0
- package/dist/types/globals.d.cts +64 -0
- package/dist/types/globals.d.ts +64 -0
- package/dist/types/globals.js +3 -0
- package/dist/types/globals.js.map +1 -0
- package/index.ts +3 -0
- package/package.json +66 -0
- package/vite.config.ts +16 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { O as Option, S as Some, N as None } from '../option-DpT8KCGE.cjs';
|
|
2
|
+
import { R as Result, O as Ok, E as Err } from '../err-B7LUEZ0f.cjs';
|
|
3
|
+
|
|
4
|
+
declare global {
|
|
5
|
+
function match<T, E extends Error, R>(matcher: Result<T, E>, cases: {
|
|
6
|
+
Ok: (value: T) => R;
|
|
7
|
+
Err: (error: E) => R;
|
|
8
|
+
}): R;
|
|
9
|
+
function match<T, R>(matcher: Option<T>, cases: {
|
|
10
|
+
Some: (value: T) => R;
|
|
11
|
+
None: () => R;
|
|
12
|
+
}): R;
|
|
13
|
+
function match<T, E extends Error>(matcher: Result<T, E>, cases: {
|
|
14
|
+
Ok: (value: T) => Option<T>;
|
|
15
|
+
Err: (error: E) => Option<T>;
|
|
16
|
+
}): Option<T>;
|
|
17
|
+
function match<T, E extends Error = Error>(matcher: Option<T>, cases: {
|
|
18
|
+
Some: (value: T) => Result<T, E>;
|
|
19
|
+
None: () => Result<T, E>;
|
|
20
|
+
}): Result<T, E>;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new `Ok` instance, representing a successful result.
|
|
23
|
+
* @template T The type of the value contained in the `Ok`.
|
|
24
|
+
* @param value The value to wrap in the `Ok` instance.
|
|
25
|
+
* @returns An `Ok` instance containing the given value.
|
|
26
|
+
* @example
|
|
27
|
+
* const result = Ok(42);
|
|
28
|
+
* console.log(result.isOk()); // true
|
|
29
|
+
* console.log(result.unwrap()); // 42
|
|
30
|
+
*/
|
|
31
|
+
function Ok<T>(value: T): Ok<T>;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a new `Err` instance, representing a failed result.
|
|
34
|
+
* @template E The type of the error contained in the `Err`.
|
|
35
|
+
* @param error The error to wrap in the `Err` instance.
|
|
36
|
+
* @returns An `Err` instance containing the given error.
|
|
37
|
+
* @example
|
|
38
|
+
* const result = Err("Something went wrong");
|
|
39
|
+
* console.log(result.isErr()); // true
|
|
40
|
+
* console.log(result.unwrapErr()); // "Something went wrong"
|
|
41
|
+
*/
|
|
42
|
+
function Err<E extends Error>(error: E | string): Err<E>;
|
|
43
|
+
/**
|
|
44
|
+
* creates a new `Some` instance, representing some value.
|
|
45
|
+
* @template T the type of the value contained in the `Some`.
|
|
46
|
+
* @param value the value to wrap in the `some` instance.
|
|
47
|
+
* @returns an `Some` instance containing the given value.
|
|
48
|
+
* @example
|
|
49
|
+
* const option = Some("some value");
|
|
50
|
+
* console.log(option.isSome()); // true
|
|
51
|
+
* console.log(option.unwrap()); // "some value"
|
|
52
|
+
*/
|
|
53
|
+
function Some<T>(value: T): Some<T>;
|
|
54
|
+
/**
|
|
55
|
+
* creates a new `None` instance, representing no value.
|
|
56
|
+
* @param `` There are no paramaters in the `None` instance.
|
|
57
|
+
* @returns an `None` instance containing no value.
|
|
58
|
+
* @example
|
|
59
|
+
* const option = None();
|
|
60
|
+
* console.log(option.isNone()); // true
|
|
61
|
+
* console.log(option.unwrap()); // throws
|
|
62
|
+
*/
|
|
63
|
+
function None(): None;
|
|
64
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { O as Option, S as Some, N as None } from '../option-DpT8KCGE.js';
|
|
2
|
+
import { R as Result, O as Ok, E as Err } from '../err-B7LUEZ0f.js';
|
|
3
|
+
|
|
4
|
+
declare global {
|
|
5
|
+
function match<T, E extends Error, R>(matcher: Result<T, E>, cases: {
|
|
6
|
+
Ok: (value: T) => R;
|
|
7
|
+
Err: (error: E) => R;
|
|
8
|
+
}): R;
|
|
9
|
+
function match<T, R>(matcher: Option<T>, cases: {
|
|
10
|
+
Some: (value: T) => R;
|
|
11
|
+
None: () => R;
|
|
12
|
+
}): R;
|
|
13
|
+
function match<T, E extends Error>(matcher: Result<T, E>, cases: {
|
|
14
|
+
Ok: (value: T) => Option<T>;
|
|
15
|
+
Err: (error: E) => Option<T>;
|
|
16
|
+
}): Option<T>;
|
|
17
|
+
function match<T, E extends Error = Error>(matcher: Option<T>, cases: {
|
|
18
|
+
Some: (value: T) => Result<T, E>;
|
|
19
|
+
None: () => Result<T, E>;
|
|
20
|
+
}): Result<T, E>;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new `Ok` instance, representing a successful result.
|
|
23
|
+
* @template T The type of the value contained in the `Ok`.
|
|
24
|
+
* @param value The value to wrap in the `Ok` instance.
|
|
25
|
+
* @returns An `Ok` instance containing the given value.
|
|
26
|
+
* @example
|
|
27
|
+
* const result = Ok(42);
|
|
28
|
+
* console.log(result.isOk()); // true
|
|
29
|
+
* console.log(result.unwrap()); // 42
|
|
30
|
+
*/
|
|
31
|
+
function Ok<T>(value: T): Ok<T>;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a new `Err` instance, representing a failed result.
|
|
34
|
+
* @template E The type of the error contained in the `Err`.
|
|
35
|
+
* @param error The error to wrap in the `Err` instance.
|
|
36
|
+
* @returns An `Err` instance containing the given error.
|
|
37
|
+
* @example
|
|
38
|
+
* const result = Err("Something went wrong");
|
|
39
|
+
* console.log(result.isErr()); // true
|
|
40
|
+
* console.log(result.unwrapErr()); // "Something went wrong"
|
|
41
|
+
*/
|
|
42
|
+
function Err<E extends Error>(error: E | string): Err<E>;
|
|
43
|
+
/**
|
|
44
|
+
* creates a new `Some` instance, representing some value.
|
|
45
|
+
* @template T the type of the value contained in the `Some`.
|
|
46
|
+
* @param value the value to wrap in the `some` instance.
|
|
47
|
+
* @returns an `Some` instance containing the given value.
|
|
48
|
+
* @example
|
|
49
|
+
* const option = Some("some value");
|
|
50
|
+
* console.log(option.isSome()); // true
|
|
51
|
+
* console.log(option.unwrap()); // "some value"
|
|
52
|
+
*/
|
|
53
|
+
function Some<T>(value: T): Some<T>;
|
|
54
|
+
/**
|
|
55
|
+
* creates a new `None` instance, representing no value.
|
|
56
|
+
* @param `` There are no paramaters in the `None` instance.
|
|
57
|
+
* @returns an `None` instance containing no value.
|
|
58
|
+
* @example
|
|
59
|
+
* const option = None();
|
|
60
|
+
* console.log(option.isNone()); // true
|
|
61
|
+
* console.log(option.unwrap()); // throws
|
|
62
|
+
*/
|
|
63
|
+
function None(): None;
|
|
64
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"globals.js"}
|
package/index.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@consolidados/results",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Result types, ease and simple",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"homepage": "https://github.com/consolidados/results",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/consolidados/results"
|
|
13
|
+
},
|
|
14
|
+
"exports": {
|
|
15
|
+
"./option": {
|
|
16
|
+
"types": "./dist/option/index.d.ts",
|
|
17
|
+
"require": "./dist/option/index.cjs",
|
|
18
|
+
"default": "./dist/option/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./result": {
|
|
21
|
+
"types": "./dist/result/index.d.ts",
|
|
22
|
+
"require": "./dist/result/index.cjs",
|
|
23
|
+
"default": "./dist/result/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./helpers": {
|
|
26
|
+
"types": "./dist/helpers/match.d.ts",
|
|
27
|
+
"require": "./dist/helpers/match.cjs",
|
|
28
|
+
"default": "./dist/helpers/match.js"
|
|
29
|
+
},
|
|
30
|
+
"./globals": {
|
|
31
|
+
"types": "./dist/types/globals.d.ts"
|
|
32
|
+
},
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"require": "./dist/index.cjs",
|
|
36
|
+
"default": "./dist/index.js"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "rm -rf dist && tsup",
|
|
41
|
+
"test": "vitest run",
|
|
42
|
+
"release": "release-it"
|
|
43
|
+
},
|
|
44
|
+
"keywords": [
|
|
45
|
+
"Rust",
|
|
46
|
+
"Result",
|
|
47
|
+
"Option",
|
|
48
|
+
"Some",
|
|
49
|
+
"None",
|
|
50
|
+
"Ok",
|
|
51
|
+
"Err",
|
|
52
|
+
"Match"
|
|
53
|
+
],
|
|
54
|
+
"author": "Johnny Carreiro",
|
|
55
|
+
"license": "ISC",
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@types/node": "^22.13.13",
|
|
58
|
+
"release-it": "^18.1.2",
|
|
59
|
+
"tsup": "^8.4.0",
|
|
60
|
+
"typescript": "^5.8.2",
|
|
61
|
+
"vitest": "^3.0.9"
|
|
62
|
+
},
|
|
63
|
+
"publishConfig": {
|
|
64
|
+
"access": "public"
|
|
65
|
+
}
|
|
66
|
+
}
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="vitest" />
|
|
2
|
+
import { defineConfig } from "vitest/config";
|
|
3
|
+
import path from "path";
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
resolve: {
|
|
7
|
+
alias: {
|
|
8
|
+
"@": path.resolve(__dirname, "./src"),
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
plugins: [],
|
|
12
|
+
test: {
|
|
13
|
+
globals: true,
|
|
14
|
+
setupFiles: "./test/setup-tests.ts",
|
|
15
|
+
},
|
|
16
|
+
});
|