utilful 3.0.2 → 3.2.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/README.md +157 -24
- package/dist/_virtual/_rolldown/runtime.mjs +13 -0
- package/dist/cli/args.d.mts +44 -0
- package/dist/cli/args.mjs +109 -0
- package/dist/cli/command.d.mts +33 -0
- package/dist/cli/command.mjs +76 -0
- package/dist/cli/errors.d.mts +20 -0
- package/dist/cli/errors.mjs +43 -0
- package/dist/cli/index.d.mts +5 -0
- package/dist/cli/index.mjs +5 -0
- package/dist/cli/log.d.mts +10 -0
- package/dist/cli/log.mjs +28 -0
- package/dist/cli/style.mjs +7 -0
- package/dist/cli/testing.d.mts +29 -0
- package/dist/cli/testing.mjs +120 -0
- package/dist/cli/usage.mjs +65 -0
- package/dist/csv.d.mts +2 -2
- package/dist/csv.mjs +3 -3
- package/dist/emitter.d.mts +3 -3
- package/dist/emitter.mjs +0 -6
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +2 -2
- package/dist/object.d.mts +7 -2
- package/dist/object.mjs +6 -1
- package/dist/path.d.mts +20 -3
- package/dist/path.mjs +73 -13
- package/dist/result.d.mts +2 -4
- package/dist/result.mjs +7 -5
- package/dist/types.d.mts +1 -3
- package/package.json +27 -1
package/dist/result.d.mts
CHANGED
|
@@ -24,11 +24,10 @@ declare class Ok<T, E = never> {
|
|
|
24
24
|
mapError<E2>(_fn: (error: E) => E2): Ok<T, E2>;
|
|
25
25
|
/** Chains a `Result`-returning function. */
|
|
26
26
|
andThen<U, E2>(fn: (value: T) => Result<U, E2>): Result<U, E | E2>;
|
|
27
|
-
/** Extracts the value. */
|
|
28
27
|
unwrap(_message?: string): T;
|
|
28
|
+
unwrapErr(message?: string): never;
|
|
29
29
|
/** Returns the value, ignoring the fallback. */
|
|
30
30
|
unwrapOr<U>(_fallback: U): T;
|
|
31
|
-
/** Pattern matches on the `Result`. */
|
|
32
31
|
match<R>(handlers: {
|
|
33
32
|
ok: (value: T) => R;
|
|
34
33
|
err: (error: E) => R;
|
|
@@ -49,11 +48,10 @@ declare class Err<T, E> {
|
|
|
49
48
|
mapError<E2>(fn: (error: E) => E2): Err<T, E2>;
|
|
50
49
|
/** Returns this `Err` unchanged, with a widened error type. */
|
|
51
50
|
andThen<U, E2>(_fn: (value: T) => Result<U, E2>): Err<U, E | E2>;
|
|
52
|
-
/** Throws an error with the given message. */
|
|
53
51
|
unwrap(message?: string): never;
|
|
52
|
+
unwrapErr(_message?: string): E;
|
|
54
53
|
/** Returns the fallback value. */
|
|
55
54
|
unwrapOr<U>(fallback: U): T | U;
|
|
56
|
-
/** Pattern matches on the `Result`. */
|
|
57
55
|
match<R>(handlers: {
|
|
58
56
|
ok: (value: T) => R;
|
|
59
57
|
err: (error: E) => R;
|
package/dist/result.mjs
CHANGED
|
@@ -21,15 +21,16 @@ var Ok = class Ok {
|
|
|
21
21
|
andThen(fn) {
|
|
22
22
|
return fn(this.value);
|
|
23
23
|
}
|
|
24
|
-
/** Extracts the value. */
|
|
25
24
|
unwrap(_message) {
|
|
26
25
|
return this.value;
|
|
27
26
|
}
|
|
27
|
+
unwrapErr(message) {
|
|
28
|
+
throw new Error(message ?? `unwrapErr called on Ok: ${String(this.value)}`);
|
|
29
|
+
}
|
|
28
30
|
/** Returns the value, ignoring the fallback. */
|
|
29
31
|
unwrapOr(_fallback) {
|
|
30
32
|
return this.value;
|
|
31
33
|
}
|
|
32
|
-
/** Pattern matches on the `Result`. */
|
|
33
34
|
match(handlers) {
|
|
34
35
|
return handlers.ok(this.value);
|
|
35
36
|
}
|
|
@@ -56,15 +57,16 @@ var Err = class Err {
|
|
|
56
57
|
andThen(_fn) {
|
|
57
58
|
return this;
|
|
58
59
|
}
|
|
59
|
-
/** Throws an error with the given message. */
|
|
60
60
|
unwrap(message) {
|
|
61
|
-
throw new Error(message ?? `
|
|
61
|
+
throw new Error(message ?? `unwrap called on Err: ${String(this.error)}`);
|
|
62
|
+
}
|
|
63
|
+
unwrapErr(_message) {
|
|
64
|
+
return this.error;
|
|
62
65
|
}
|
|
63
66
|
/** Returns the fallback value. */
|
|
64
67
|
unwrapOr(fallback) {
|
|
65
68
|
return fallback;
|
|
66
69
|
}
|
|
67
|
-
/** Pattern matches on the `Result`. */
|
|
68
70
|
match(handlers) {
|
|
69
71
|
return handlers.err(this.error);
|
|
70
72
|
}
|
package/dist/types.d.mts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
//#region src/types.d.ts
|
|
2
|
-
type AutocompletableString = string & {};
|
|
3
|
-
type LooseAutocomplete<T extends string> = T | AutocompletableString;
|
|
4
2
|
/** Also commonly referred to as `Prettify`. */
|
|
5
3
|
type UnifyIntersection<T> = { [K in keyof T]: T[K]; } & {};
|
|
6
4
|
declare const brand: unique symbol;
|
|
@@ -8,4 +6,4 @@ type BrandedType<T, B> = T & {
|
|
|
8
6
|
[brand]: B;
|
|
9
7
|
};
|
|
10
8
|
//#endregion
|
|
11
|
-
export {
|
|
9
|
+
export { BrandedType, UnifyIntersection };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "utilful",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.0
|
|
4
|
+
"version": "3.2.0",
|
|
5
5
|
"packageManager": "pnpm@11.15.1",
|
|
6
6
|
"description": "A collection of TypeScript utilities",
|
|
7
7
|
"author": "Johann Schopplich <hello@johannschopplich.com>",
|
|
@@ -14,6 +14,16 @@
|
|
|
14
14
|
"bugs": {
|
|
15
15
|
"url": "https://github.com/johannschopplich/utilful/issues"
|
|
16
16
|
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"cli",
|
|
19
|
+
"csv",
|
|
20
|
+
"defu",
|
|
21
|
+
"emitter",
|
|
22
|
+
"result",
|
|
23
|
+
"typescript",
|
|
24
|
+
"url",
|
|
25
|
+
"utilities"
|
|
26
|
+
],
|
|
17
27
|
"sideEffects": false,
|
|
18
28
|
"exports": {
|
|
19
29
|
".": {
|
|
@@ -24,6 +34,14 @@
|
|
|
24
34
|
"types": "./dist/array.d.mts",
|
|
25
35
|
"default": "./dist/array.mjs"
|
|
26
36
|
},
|
|
37
|
+
"./cli": {
|
|
38
|
+
"types": "./dist/cli/index.d.mts",
|
|
39
|
+
"default": "./dist/cli/index.mjs"
|
|
40
|
+
},
|
|
41
|
+
"./cli/testing": {
|
|
42
|
+
"types": "./dist/cli/testing.d.mts",
|
|
43
|
+
"default": "./dist/cli/testing.mjs"
|
|
44
|
+
},
|
|
27
45
|
"./csv": {
|
|
28
46
|
"types": "./dist/csv.d.mts",
|
|
29
47
|
"default": "./dist/csv.mjs"
|
|
@@ -77,6 +95,14 @@
|
|
|
77
95
|
"test:types": "tsc --noEmit",
|
|
78
96
|
"release": "bumpp"
|
|
79
97
|
},
|
|
98
|
+
"peerDependencies": {
|
|
99
|
+
"vitest": ">=4"
|
|
100
|
+
},
|
|
101
|
+
"peerDependenciesMeta": {
|
|
102
|
+
"vitest": {
|
|
103
|
+
"optional": true
|
|
104
|
+
}
|
|
105
|
+
},
|
|
80
106
|
"devDependencies": {
|
|
81
107
|
"@antfu/eslint-config": "^9.1.0",
|
|
82
108
|
"@types/node": "^26.1.1",
|