@tempots/std 0.24.0 → 0.25.1
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 +2 -0
- package/array.cjs +1 -1
- package/array.js +95 -95
- package/async-result.cjs +1 -1
- package/async-result.d.ts +102 -0
- package/async-result.js +214 -32
- package/index.cjs +1 -1
- package/index.js +1 -1
- package/json.cjs +1 -1
- package/json.js +1 -1
- package/object.cjs +1 -1
- package/object.js +21 -18
- package/package.json +1 -1
- package/regexp.cjs +1 -1
- package/regexp.js +12 -10
- package/result-7Po2Mxhx.js +486 -0
- package/result-bSKKrSLB.cjs +1 -0
- package/result.cjs +1 -1
- package/result.d.ts +111 -0
- package/result.js +1 -1
- package/string.cjs +4 -4
- package/string.js +44 -43
- package/timer.cjs +1 -1
- package/timer.d.ts +3 -3
- package/timer.js +37 -23
- package/validation.cjs +1 -1
- package/validation.d.ts +89 -0
- package/validation.js +1 -1
- package/result-CGd0jCdl.js +0 -265
- package/result-CdwVhaAc.cjs +0 -1
package/string.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MissingImplementationError as
|
|
1
|
+
import { MissingImplementationError as h } from "./error.js";
|
|
2
2
|
import { mapRegExp as l } from "./regexp.js";
|
|
3
3
|
const Z = (t, n) => {
|
|
4
4
|
const e = t.indexOf(n);
|
|
@@ -12,68 +12,69 @@ const Z = (t, n) => {
|
|
|
12
12
|
}, R = (t, n) => {
|
|
13
13
|
const e = t.lastIndexOf(n);
|
|
14
14
|
return e < 0 ? "" : t.substring(0, e);
|
|
15
|
-
}, g = (t) => t.substring(0, 1).toUpperCase() + t.substring(1),
|
|
16
|
-
`), Q = (t, n) => t == null && n == null ? 0 : t == null ? -1 : n == null ? 1 :
|
|
15
|
+
}, g = (t) => t.substring(0, 1).toUpperCase() + t.substring(1), a = (t) => t.toUpperCase(), F = (t, n = !1) => n ? l(g(t), _, a) : l(g(t), z, a), G = (t) => t.replace($, `
|
|
16
|
+
`), Q = (t, n) => t == null && n == null ? 0 : t == null ? -1 : n == null ? 1 : S(t.toLowerCase(), n.toLowerCase()), K = (t, n) => t.substring(t.length - n.length).toLowerCase() === n.toLowerCase(), q = (t, n) => t.substring(0, n.length).toLowerCase() === n.toLowerCase(), J = (t, n) => A(
|
|
17
17
|
t.toLowerCase(),
|
|
18
18
|
n.map((e) => e.toLowerCase())
|
|
19
19
|
), V = (t, n) => y(
|
|
20
20
|
t.toLowerCase(),
|
|
21
21
|
n.map((e) => e.toLowerCase())
|
|
22
|
-
), X = (t) => t.trim().replace(d, " "),
|
|
22
|
+
), X = (t) => t.trim().replace(d, " "), S = (t, n) => t < n ? -1 : t > n ? 1 : 0, p = (t, n) => t.toLowerCase().includes(n.toLowerCase()), Y = (t, n) => t.split(n).length - 1, v = (t, n) => n.some((e) => p(t, e)), tt = (t, n) => n.some((e) => t.includes(e)), nt = (t, n) => n.every((e) => p(t, e)), et = (t, n) => n.every((e) => t.includes(e)), rt = (t) => t.replace(/_/g, "-"), st = (t, n) => {
|
|
23
23
|
if (t === n) return -1;
|
|
24
24
|
const e = Math.min(t.length, n.length);
|
|
25
25
|
for (let r = 0; r < e; r++)
|
|
26
26
|
if (t.substring(r, r + 1) !== n.substring(r, r + 1)) return r;
|
|
27
27
|
return e;
|
|
28
|
-
},
|
|
28
|
+
}, b = (t, n = 20, e = "…") => {
|
|
29
29
|
const r = t.length, s = e.length;
|
|
30
30
|
return r > n ? n < s ? e.slice(s - n, n) : t.slice(0, n - s) + e : t;
|
|
31
31
|
}, it = (t, n = 20, e = "…") => {
|
|
32
32
|
const r = t.length, s = e.length;
|
|
33
33
|
if (r > n) {
|
|
34
34
|
if (n <= s)
|
|
35
|
-
return
|
|
35
|
+
return b(t, n, e);
|
|
36
36
|
const c = Math.ceil((n - s) / 2), u = Math.floor((n - s) / 2);
|
|
37
37
|
return t.slice(0, c) + e + t.slice(r - u);
|
|
38
38
|
} else return t;
|
|
39
|
-
},
|
|
39
|
+
}, A = (t, n) => n.some((e) => t.endsWith(e)), ot = (t, n) => Array.from(t).filter(n).join(""), ct = (t, n) => x(t).filter(n).map((r) => String.fromCharCode(r)).join(""), ut = (t, n = 2166136261) => {
|
|
40
40
|
let e = n;
|
|
41
41
|
for (let r = 0, s = t.length; r < s; r++)
|
|
42
42
|
e ^= t.charCodeAt(r), e += (e << 1) + (e << 4) + (e << 7) + (e << 8) + (e << 24);
|
|
43
43
|
return e >>> 0;
|
|
44
|
-
}, lt = (t) => t != null && t.length > 0, gt = (t) => E(t).split("_").join(" "),
|
|
44
|
+
}, lt = (t) => t != null && t.length > 0, gt = (t) => E(t).split("_").join(" "), at = (t) => t.length > 0 && !N.test(t), ft = (t) => M.test(t), ht = (t) => !T.test(t), pt = (t) => t.toLowerCase() === t, dt = (t) => t.toUpperCase() === t, Ct = (t, n) => t != null && t !== "" ? t : n, St = (t) => U.test(t), bt = (t) => t == null || t === "", At = (t) => t.substring(0, 1).toLowerCase() + t.substring(1), L = (t, n = 1) => {
|
|
45
45
|
const e = Math.floor((t.length - n + 1) * Math.random());
|
|
46
46
|
return t.substring(e, e + n);
|
|
47
|
-
},
|
|
47
|
+
}, w = (t, n) => Array.from({ length: n }, () => L(t)).join(""), Lt = (t) => w(j, t), wt = (t, n) => Array.from(n).map(t), mt = (t, n) => t.split(n).join(""), It = (t, n) => t.endsWith(n) ? t.substring(0, t.length - n.length) : t, yt = (t, n, e) => t.substring(0, n) + t.substring(n + e), xt = (t, n) => t.startsWith(n) ? t.substring(n.length) : t, Ot = (t, n) => {
|
|
48
48
|
const e = t.indexOf(n);
|
|
49
49
|
return e < 0 ? t : t.substring(0, e) + t.substring(e + n.length);
|
|
50
50
|
}, Wt = (t) => {
|
|
51
51
|
const n = Array.from(t);
|
|
52
52
|
return n.reverse(), n.join("");
|
|
53
|
-
},
|
|
54
|
-
`) >= 0 ? I(t, "`") :
|
|
53
|
+
}, m = (t, n = "'") => n === "'" ? t.includes("'") ? t.includes('"') ? "'" + t.split("'").join("\\'") + "'" : '"' + t + '"' : "'" + t + "'" : t.includes('"') ? t.includes("'") ? '"' + t.split('"').join('\\"') + '"' : "'" + t + "'" : '"' + t + '"', I = (t, n = "'") => n + t.split(n).join("\\" + n) + n, Et = (t, n = "'") => t.indexOf(`
|
|
54
|
+
`) >= 0 ? I(t, "`") : m(t, n), Bt = (t, n) => {
|
|
55
55
|
const e = t.indexOf(n);
|
|
56
56
|
return e < 0 ? [t] : [t.substring(0, e), t.substring(e + n.length)];
|
|
57
57
|
}, y = (t, n) => n.some((e) => t.startsWith(e)), jt = (t, n, e = n) => `${n}${t}${e}`, x = (t) => Array.from({ length: t.length }, (n, e) => t.charCodeAt(e)), zt = (t, n) => {
|
|
58
58
|
const e = [];
|
|
59
|
-
for (; t.length
|
|
60
|
-
e.push(t.substring(
|
|
59
|
+
for (let r = 0; r < t.length; r += n)
|
|
60
|
+
e.push(t.substring(r, r + n));
|
|
61
61
|
return e;
|
|
62
62
|
}, Tt = (t) => t.split(C), Nt = (t, n) => W(O(t, n), n), O = (t, n) => {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
const e = new Set(n);
|
|
64
|
+
let r = 0;
|
|
65
|
+
for (let s = 0; s < t.length && e.has(t.charAt(s)); s++)
|
|
66
|
+
r++;
|
|
67
|
+
return t.substring(r);
|
|
67
68
|
}, W = (t, n) => {
|
|
68
|
-
const e = t.length;
|
|
69
|
-
let
|
|
70
|
-
for (let
|
|
71
|
-
|
|
72
|
-
return t.substring(0,
|
|
69
|
+
const e = new Set(n), r = t.length;
|
|
70
|
+
let s = r, c;
|
|
71
|
+
for (let u = 0; u < r && (c = r - u - 1, e.has(t.charAt(c))); u++)
|
|
72
|
+
s = c;
|
|
73
|
+
return t.substring(0, s);
|
|
73
74
|
}, E = (t) => (t = t.replace(/::/g, "/"), t = t.replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2"), t = t.replace(/([a-z\d])([A-Z])/g, "$1_$2"), t = t.replace(/-/g, "_"), t.toLowerCase()), _t = (t) => t.substring(0, 1).toUpperCase() + t.substring(1), Mt = (t, n = 78, e = "", r = `
|
|
74
75
|
`) => t.split(C).map(
|
|
75
76
|
(s) => B(s.replace(d, " ").trim(), n, e, r)
|
|
76
|
-
).join(r),
|
|
77
|
+
).join(r), f = (t, n) => {
|
|
77
78
|
if (n < 0 || n >= t.length) return !1;
|
|
78
79
|
const e = t.charCodeAt(n);
|
|
79
80
|
return e === 9 || e === 10 || e === 11 || e === 12 || e === 13 || e === 32;
|
|
@@ -82,7 +83,7 @@ const Z = (t, n) => {
|
|
|
82
83
|
return Buffer.from(t).toString("base64");
|
|
83
84
|
if (typeof btoa < "u")
|
|
84
85
|
return btoa(t);
|
|
85
|
-
throw new
|
|
86
|
+
throw new h(
|
|
86
87
|
"No implementation found for base64 encoding"
|
|
87
88
|
);
|
|
88
89
|
}, $t = (t) => {
|
|
@@ -90,7 +91,7 @@ const Z = (t, n) => {
|
|
|
90
91
|
return Buffer.from(t, "base64").toString("utf8");
|
|
91
92
|
if (typeof atob < "u")
|
|
92
93
|
return atob(t);
|
|
93
|
-
throw new
|
|
94
|
+
throw new h(
|
|
94
95
|
"No implementation found for base64 decoding"
|
|
95
96
|
);
|
|
96
97
|
}, B = (t, n, e, r) => {
|
|
@@ -102,9 +103,9 @@ const Z = (t, n) => {
|
|
|
102
103
|
break;
|
|
103
104
|
}
|
|
104
105
|
let i = 0;
|
|
105
|
-
for (; !
|
|
106
|
+
for (; !f(t, o + n - i) && i < n; ) i++;
|
|
106
107
|
if (i === n) {
|
|
107
|
-
for (i = 0; !
|
|
108
|
+
for (i = 0; !f(t, o + n + i) && o + n + i < c; ) i++;
|
|
108
109
|
s.push(t.substring(o, o + n + i)), o += n + i + 1;
|
|
109
110
|
} else
|
|
110
111
|
s.push(t.substring(o, o + n - i)), o += n - i + 1;
|
|
@@ -130,7 +131,7 @@ export {
|
|
|
130
131
|
zt as chunkString,
|
|
131
132
|
X as collapseText,
|
|
132
133
|
Q as compareCaseInsensitive,
|
|
133
|
-
|
|
134
|
+
S as compareStrings,
|
|
134
135
|
et as containsAllText,
|
|
135
136
|
nt as containsAllTextCaseInsensitive,
|
|
136
137
|
tt as containsAnyText,
|
|
@@ -141,37 +142,37 @@ export {
|
|
|
141
142
|
Ot as deleteFirstFromString,
|
|
142
143
|
It as deleteStringAfter,
|
|
143
144
|
xt as deleteStringBefore,
|
|
144
|
-
|
|
145
|
-
|
|
145
|
+
mt as deleteSubstring,
|
|
146
|
+
b as ellipsis,
|
|
146
147
|
it as ellipsisMiddle,
|
|
147
148
|
Ut as encodeBase64,
|
|
148
149
|
ct as filterCharcodes,
|
|
149
150
|
ot as filterChars,
|
|
150
151
|
gt as humanize,
|
|
151
152
|
Ct as ifEmptyString,
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
153
|
+
at as isAlpha,
|
|
154
|
+
ft as isAlphaNum,
|
|
155
|
+
ht as isBreakingWhitespace,
|
|
156
|
+
St as isDigitsOnly,
|
|
157
|
+
bt as isEmptyString,
|
|
158
|
+
pt as isLowerCase,
|
|
159
|
+
f as isSpaceAt,
|
|
159
160
|
dt as isUpperCase,
|
|
160
161
|
Et as jsQuote,
|
|
161
|
-
|
|
162
|
+
At as lowerCaseFirst,
|
|
162
163
|
kt as lpad,
|
|
163
|
-
|
|
164
|
+
wt as mapChars,
|
|
164
165
|
I as quote,
|
|
165
|
-
|
|
166
|
+
w as randomStringSequence,
|
|
166
167
|
Lt as randomStringSequenceBase64,
|
|
167
168
|
L as randomSubString,
|
|
168
169
|
Wt as reverseString,
|
|
169
170
|
Ht as rpad,
|
|
170
|
-
|
|
171
|
+
m as smartQuote,
|
|
171
172
|
Dt as splitStringOnFirst,
|
|
172
173
|
Zt as splitStringOnLast,
|
|
173
174
|
Bt as splitStringOnce,
|
|
174
|
-
|
|
175
|
+
A as stringEndsWithAny,
|
|
175
176
|
lt as stringHasContent,
|
|
176
177
|
ut as stringHashCode,
|
|
177
178
|
y as stringStartsWithAny,
|
|
@@ -182,7 +183,7 @@ export {
|
|
|
182
183
|
P as substringBefore,
|
|
183
184
|
R as substringBeforeLast,
|
|
184
185
|
jt as surroundString,
|
|
185
|
-
|
|
186
|
+
p as textContainsCaseInsensitive,
|
|
186
187
|
J as textEndsWithAnyCaseInsensitive,
|
|
187
188
|
K as textEndsWithCaseInsensitive,
|
|
188
189
|
V as textStartsWithAnyCaseInsensitive,
|
package/timer.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=(n,e)=>{
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=(n,e)=>{let t=()=>{};const i=setTimeout(()=>{const l=n();l!=null&&(t=l)},e);return()=>{clearTimeout(i),t()}},I=(n,e)=>{let t=()=>{};const i=setInterval(()=>{const l=n();l!=null&&(t=l)},e);return()=>{clearInterval(i),t()}};function A(n,e,t={}){const{noTrailing:i=!1,noLeading:l=!1,debounceMode:o}=t;let a,f=!1,c=0;function m(){a&&clearTimeout(a)}function T(u){const{upcomingOnly:s=!1}=u||{};m(),f=!s}function d(...u){if(f)return;const s=this,v=Date.now()-c;function r(){c=Date.now(),e.apply(s,u)}function F(){a=void 0}!l&&o&&!a&&r(),m(),o===void 0&&v>n?l?(c=Date.now(),i||(a=setTimeout(o?F:r,n))):r():i||(a=setTimeout(o?F:r,o===void 0?Math.max(0,n-v):n))}return d.cancel=T,d}function b(n,e,{atBegin:t=!1}={}){return A(n,e,{debounceMode:t!==!1})}const g=n=>{let e=null;const t=l=>{e=null,n(l)};return(()=>{e==null&&(e=requestAnimationFrame(t))})(),()=>{e!=null&&(cancelAnimationFrame(e),e=null)}},y=n=>{let e=null;const t=l=>{e=requestAnimationFrame(t),n(l)};return(()=>{e==null&&(e=requestAnimationFrame(t))})(),()=>{e!=null&&(cancelAnimationFrame(e),e=null)}};exports.debounce=b;exports.delayed=p;exports.delayedAnimationFrame=g;exports.interval=I;exports.intervalAnimationFrame=y;exports.throttle=A;
|
package/timer.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Delays the execution of a function by the given number of milliseconds.
|
|
3
|
-
* @param fn - The function to delay.
|
|
3
|
+
* @param fn - The function to delay. The function can optionally return a callback that will be invoked when the delay is cancelled.
|
|
4
4
|
* @param ms - The number of milliseconds to delay the function.
|
|
5
5
|
* @returns A function that, when called, will cancel the delay and prevent the original function from being executed.
|
|
6
6
|
* @example
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
* ```
|
|
14
14
|
* @public
|
|
15
15
|
*/
|
|
16
|
-
export declare const delayed: (fn: () => void, ms: number) => () => void;
|
|
16
|
+
export declare const delayed: (fn: () => (() => void) | void, ms: number) => () => void;
|
|
17
17
|
/**
|
|
18
18
|
* Executes a function repeatedly at a fixed interval.
|
|
19
|
-
* @param fn - The function to execute periodically.
|
|
19
|
+
* @param fn - The function to execute periodically. The function can optionally return a callback that will be invoked when the delay is cancelled.
|
|
20
20
|
* @param ms - The number of milliseconds between each execution.
|
|
21
21
|
* @returns A function that, when called, will cancel the interval and stop future executions.
|
|
22
22
|
* @example
|
package/timer.js
CHANGED
|
@@ -1,38 +1,52 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
const I = (n, e) => {
|
|
2
|
+
let t = () => {
|
|
3
|
+
};
|
|
4
|
+
const i = setTimeout(() => {
|
|
5
|
+
const l = n();
|
|
6
|
+
l != null && (t = l);
|
|
7
|
+
}, e);
|
|
8
|
+
return () => {
|
|
9
|
+
clearTimeout(i), t();
|
|
10
|
+
};
|
|
11
|
+
}, T = (n, e) => {
|
|
12
|
+
let t = () => {
|
|
13
|
+
};
|
|
14
|
+
const i = setInterval(() => {
|
|
15
|
+
const l = n();
|
|
16
|
+
l != null && (t = l);
|
|
17
|
+
}, e);
|
|
18
|
+
return () => {
|
|
19
|
+
clearInterval(i), t();
|
|
20
|
+
};
|
|
7
21
|
};
|
|
8
|
-
function
|
|
9
|
-
const { noTrailing:
|
|
10
|
-
let
|
|
22
|
+
function A(n, e, t = {}) {
|
|
23
|
+
const { noTrailing: i = !1, noLeading: l = !1, debounceMode: a } = t;
|
|
24
|
+
let o, f = !1, c = 0;
|
|
11
25
|
function m() {
|
|
12
|
-
|
|
26
|
+
o && clearTimeout(o);
|
|
13
27
|
}
|
|
14
|
-
function
|
|
28
|
+
function p(u) {
|
|
15
29
|
const { upcomingOnly: s = !1 } = u || {};
|
|
16
30
|
m(), f = !s;
|
|
17
31
|
}
|
|
18
32
|
function d(...u) {
|
|
19
33
|
if (f) return;
|
|
20
|
-
const s = this,
|
|
34
|
+
const s = this, F = Date.now() - c;
|
|
21
35
|
function r() {
|
|
22
36
|
c = Date.now(), e.apply(s, u);
|
|
23
37
|
}
|
|
24
38
|
function v() {
|
|
25
|
-
|
|
39
|
+
o = void 0;
|
|
26
40
|
}
|
|
27
|
-
!l &&
|
|
28
|
-
|
|
29
|
-
|
|
41
|
+
!l && a && !o && r(), m(), a === void 0 && F > n ? l ? (c = Date.now(), i || (o = setTimeout(a ? v : r, n))) : r() : i || (o = setTimeout(
|
|
42
|
+
a ? v : r,
|
|
43
|
+
a === void 0 ? Math.max(0, n - F) : n
|
|
30
44
|
));
|
|
31
45
|
}
|
|
32
|
-
return d.cancel =
|
|
46
|
+
return d.cancel = p, d;
|
|
33
47
|
}
|
|
34
|
-
function
|
|
35
|
-
return
|
|
48
|
+
function x(n, e, { atBegin: t = !1 } = {}) {
|
|
49
|
+
return A(n, e, { debounceMode: t !== !1 });
|
|
36
50
|
}
|
|
37
51
|
const g = (n) => {
|
|
38
52
|
let e = null;
|
|
@@ -56,10 +70,10 @@ const g = (n) => {
|
|
|
56
70
|
};
|
|
57
71
|
};
|
|
58
72
|
export {
|
|
59
|
-
|
|
60
|
-
|
|
73
|
+
x as debounce,
|
|
74
|
+
I as delayed,
|
|
61
75
|
g as delayedAnimationFrame,
|
|
62
|
-
|
|
76
|
+
T as interval,
|
|
63
77
|
w as intervalAnimationFrame,
|
|
64
|
-
|
|
78
|
+
A as throttle
|
|
65
79
|
};
|
package/validation.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./result-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./result-bSKKrSLB.cjs");exports.Validation=i.Validation;
|
package/validation.d.ts
CHANGED
|
@@ -72,6 +72,18 @@ export declare const Validation: {
|
|
|
72
72
|
* @returns A new `Validation` with the mapped value.
|
|
73
73
|
*/
|
|
74
74
|
toResult: <T, E>(validation: Validation<E>, value: T) => Result<T, E>;
|
|
75
|
+
/**
|
|
76
|
+
* Executes side effects based on the state of the validation.
|
|
77
|
+
* Unlike `match`, all handlers are optional, allowing you to react only to specific states.
|
|
78
|
+
* @param v - The validation.
|
|
79
|
+
* @param handlers - An object with optional handlers for each state.
|
|
80
|
+
* @returns The validation that was passed in, allowing for chaining.
|
|
81
|
+
* @public
|
|
82
|
+
*/
|
|
83
|
+
effect: <E>(v: Validation<E>, handlers: {
|
|
84
|
+
valid?: () => void;
|
|
85
|
+
invalid?: (error: E) => void;
|
|
86
|
+
}) => Validation<E>;
|
|
75
87
|
/**
|
|
76
88
|
* Execute a function when the `Validation` is valid.
|
|
77
89
|
*
|
|
@@ -88,4 +100,81 @@ export declare const Validation: {
|
|
|
88
100
|
* @returns The `Validation` object.
|
|
89
101
|
*/
|
|
90
102
|
whenInvalid: <E>(r: Validation<E>, apply: (e: E) => void) => Validation<E>;
|
|
103
|
+
/**
|
|
104
|
+
* Maps the error of an invalid `Validation` to a new error using the provided function.
|
|
105
|
+
* For valid validations, the validation is preserved unchanged.
|
|
106
|
+
* @param v - The `Validation` to map the error of.
|
|
107
|
+
* @param f - The mapping function to apply to the error.
|
|
108
|
+
* @returns A new `Validation` with the mapped error if invalid, otherwise the original valid.
|
|
109
|
+
* @public
|
|
110
|
+
*/
|
|
111
|
+
mapError: <E, F>(v: Validation<E>, f: (error: E) => F) => Validation<F>;
|
|
112
|
+
/**
|
|
113
|
+
* Maps the error of an invalid `Validation` to a new `Validation` using the provided function.
|
|
114
|
+
* This allows recovery from errors by returning a valid validation.
|
|
115
|
+
* @param v - The `Validation` to recover from.
|
|
116
|
+
* @param f - The recovery function that returns a new `Validation`.
|
|
117
|
+
* @returns The result of the recovery function if invalid, otherwise the original valid.
|
|
118
|
+
* @public
|
|
119
|
+
*/
|
|
120
|
+
flatMapError: <E, F>(v: Validation<E>, f: (error: E) => Validation<F>) => Validation<F>;
|
|
121
|
+
/**
|
|
122
|
+
* Combines two validations. Both must be valid for the result to be valid.
|
|
123
|
+
* If both are invalid, errors are combined using the provided function.
|
|
124
|
+
* @param v1 - The first validation.
|
|
125
|
+
* @param v2 - The second validation.
|
|
126
|
+
* @param combineErrors - The function to combine two errors.
|
|
127
|
+
* @returns A combined validation.
|
|
128
|
+
* @public
|
|
129
|
+
*/
|
|
130
|
+
combine: <E>(v1: Validation<E>, v2: Validation<E>, combineErrors: (e1: E, e2: E) => E) => Validation<E>;
|
|
131
|
+
/**
|
|
132
|
+
* Combines multiple validations into a single validation.
|
|
133
|
+
* All must be valid for the result to be valid.
|
|
134
|
+
* Returns the first invalid validation if any.
|
|
135
|
+
* @param validations - The validations to combine.
|
|
136
|
+
* @returns A single validation that is valid only if all inputs are valid.
|
|
137
|
+
* @public
|
|
138
|
+
*/
|
|
139
|
+
all: <E>(validations: Validation<E>[]) => Validation<E>;
|
|
140
|
+
/**
|
|
141
|
+
* Combines multiple validations, accumulating all errors.
|
|
142
|
+
* All must be valid for the result to be valid.
|
|
143
|
+
* If any are invalid, all errors are collected into an array.
|
|
144
|
+
* @param validations - The validations to combine.
|
|
145
|
+
* @returns A validation that is valid only if all inputs are valid, otherwise contains all errors.
|
|
146
|
+
* @public
|
|
147
|
+
*/
|
|
148
|
+
allErrors: <E>(validations: Validation<E>[]) => Validation<E[]>;
|
|
149
|
+
/**
|
|
150
|
+
* Compares two validations for equality.
|
|
151
|
+
* @param v1 - The first validation.
|
|
152
|
+
* @param v2 - The second validation.
|
|
153
|
+
* @param errorEquals - Optional custom equality function for errors. Defaults to strict equality.
|
|
154
|
+
* @returns `true` if the validations are equal, `false` otherwise.
|
|
155
|
+
* @public
|
|
156
|
+
*/
|
|
157
|
+
equals: <E>(v1: Validation<E>, v2: Validation<E>, errorEquals?: (e1: E, e2: E) => boolean) => boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Recovers from an invalid validation by returning a valid validation.
|
|
160
|
+
* @param v - The `Validation` to recover from.
|
|
161
|
+
* @returns A valid validation regardless of the input.
|
|
162
|
+
* @public
|
|
163
|
+
*/
|
|
164
|
+
recover: <E>(_v: Validation<E>) => Validation<never>;
|
|
165
|
+
/**
|
|
166
|
+
* Gets the error if the validation is invalid, otherwise returns undefined.
|
|
167
|
+
* @param v - The validation to get the error from.
|
|
168
|
+
* @returns The error if invalid, otherwise undefined.
|
|
169
|
+
* @public
|
|
170
|
+
*/
|
|
171
|
+
getError: <E>(v: Validation<E>) => E | undefined;
|
|
172
|
+
/**
|
|
173
|
+
* Gets the error if the validation is invalid, otherwise returns the default value.
|
|
174
|
+
* @param v - The validation to get the error from.
|
|
175
|
+
* @param defaultError - The default error to return if valid.
|
|
176
|
+
* @returns The error if invalid, otherwise the default error.
|
|
177
|
+
* @public
|
|
178
|
+
*/
|
|
179
|
+
getErrorOrElse: <E>(v: Validation<E>, defaultError: E) => E;
|
|
91
180
|
};
|
package/validation.js
CHANGED