@tempots/std 0.10.7 → 0.12.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/string.js CHANGED
@@ -1,58 +1,58 @@
1
- import { any as c, all as b, range as A, fill as O } from "./array.js";
2
- import { map as p } from "./regexp.js";
3
- function a(n, t, r) {
1
+ import { anyElement as l, allElements as C, generateArray as A, createFilledArray as S } from "./array.js";
2
+ import { mapRegExp as h } from "./regexp.js";
3
+ function c(n, t, r) {
4
4
  return n.split(t).join(r);
5
5
  }
6
6
  function J(n, t) {
7
7
  const r = n.indexOf(t);
8
8
  return r < 0 ? "" : n.substring(r + t.length);
9
9
  }
10
- function Q(n, t) {
10
+ function V(n, t) {
11
11
  const r = n.lastIndexOf(t);
12
12
  return r < 0 ? "" : n.substring(r + t.length);
13
13
  }
14
- function V(n, t) {
14
+ function X(n, t) {
15
15
  const r = n.indexOf(t);
16
16
  return r < 0 ? "" : n.substring(0, r);
17
17
  }
18
- function X(n, t) {
18
+ function Y(n, t) {
19
19
  const r = n.lastIndexOf(t);
20
20
  return r < 0 ? "" : n.substring(0, r);
21
21
  }
22
- function h(n) {
22
+ function p(n) {
23
23
  return n.substring(0, 1).toUpperCase() + n.substring(1);
24
24
  }
25
25
  const d = (n) => n.toUpperCase();
26
- function Y(n, t = !1) {
27
- return t ? p(h(n), R, d) : p(h(n), P, d);
26
+ function v(n, t = !1) {
27
+ return t ? h(p(n), H, d) : h(p(n), R, d);
28
28
  }
29
- function v(n) {
30
- return n.replace(q, `
29
+ function nn(n) {
30
+ return n.replace(Q, `
31
31
  `);
32
32
  }
33
- function nn(n, t) {
33
+ function tn(n, t) {
34
34
  return n == null && t == null ? 0 : n == null ? -1 : t == null ? 1 : y(n.toLowerCase(), t.toLowerCase());
35
35
  }
36
36
  function L(n, t) {
37
37
  return n.substring(0, n.length - t.length) === t;
38
38
  }
39
- function tn(n, t) {
39
+ function rn(n, t) {
40
40
  return n.substring(0, n.length - t.length).toLowerCase() === t.toLowerCase();
41
41
  }
42
42
  function W(n, t) {
43
43
  return n.substring(0, t.length) === t;
44
44
  }
45
- function rn(n, t) {
45
+ function en(n, t) {
46
46
  return n.substring(0, t.length).toLowerCase() === t.toLowerCase();
47
47
  }
48
- function en(n, t) {
49
- return E(
48
+ function on(n, t) {
49
+ return z(
50
50
  n.toLowerCase(),
51
51
  t.map((r) => r.toLowerCase())
52
52
  );
53
53
  }
54
- function on(n, t) {
55
- return _(
54
+ function un(n, t) {
55
+ return N(
56
56
  n.toLowerCase(),
57
57
  t.map((r) => r.toLowerCase())
58
58
  );
@@ -66,96 +66,97 @@ function y(n, t) {
66
66
  function w(n, t) {
67
67
  return n.toLowerCase().includes(t.toLowerCase());
68
68
  }
69
- function l(n, t) {
69
+ function a(n, t) {
70
70
  return n.includes(t);
71
71
  }
72
- function un(n, t) {
73
- return n.split(t).length - 1;
74
- }
75
72
  function fn(n, t) {
76
- return c(t, (r) => w(n, r));
73
+ return n.split(t).length - 1;
77
74
  }
78
75
  function cn(n, t) {
79
- return c(t, (r) => l(n, r));
76
+ return l(t, (r) => w(n, r));
80
77
  }
81
78
  function ln(n, t) {
82
- return b(t, (r) => w(n, r));
79
+ return l(t, (r) => a(n, r));
83
80
  }
84
81
  function an(n, t) {
85
- return b(t, (r) => l(n, r));
82
+ return C(t, (r) => w(n, r));
83
+ }
84
+ function gn(n, t) {
85
+ return C(t, (r) => a(n, r));
86
86
  }
87
- function gn(n) {
87
+ function hn(n) {
88
88
  return n.replace("_", "-");
89
89
  }
90
90
  function pn(n, t) {
91
+ if (n === t) return -1;
91
92
  const r = Math.min(n.length, t.length);
92
93
  for (let e = 0; e < r; e++)
93
94
  if (n.substring(e, e + 1) !== t.substring(e, e + 1)) return e;
94
95
  return r;
95
96
  }
96
- function z(n, t = 20, r = "…") {
97
+ function E(n, t = 20, r = "…") {
97
98
  const e = n.length, i = r.length;
98
99
  return e > t ? t < i ? r.substr(i - t, t) : n.substr(0, t - i) + r : n;
99
100
  }
100
- function hn(n, t = 20, r = "…") {
101
+ function dn(n, t = 20, r = "…") {
101
102
  const e = n.length, i = r.length;
102
103
  if (e > t) {
103
104
  if (t <= i)
104
- return z(n, t, r);
105
- const u = Math.ceil((t - i) / 2), f = Math.floor((t - i) / 2);
106
- return n.substr(0, u) + r + n.substr(e - f, f);
105
+ return E(n, t, r);
106
+ const s = Math.ceil((t - i) / 2), f = Math.floor((t - i) / 2);
107
+ return n.substr(0, s) + r + n.substr(e - f, f);
107
108
  } else return n;
108
109
  }
109
- function E(n, t) {
110
- return c(t, (r) => L(n, r));
110
+ function z(n, t) {
111
+ return l(t, (r) => L(n, r));
111
112
  }
112
- function dn(n, t) {
113
+ function bn(n, t) {
113
114
  return g(n).filter(t).join("");
114
115
  }
115
116
  function Cn(n, t) {
116
- return $(n).filter(t).map((e) => String.fromCharCode(e)).join("");
117
+ return U(n).filter(t).map((e) => String.fromCharCode(e)).join("");
117
118
  }
118
- function bn(n, t) {
119
+ function An(n, t) {
119
120
  const r = n.indexOf(t);
120
121
  return r < 0 ? "" : n.substring(r);
121
122
  }
122
- function An(n, t = 2166136261) {
123
+ function Ln(n, t = 2166136261) {
123
124
  let r = t;
124
125
  for (let e = 0, i = n.length; e < i; e++)
125
126
  r ^= n.charCodeAt(e), r += (r << 1) + (r << 4) + (r << 7) + (r << 8) + (r << 24);
126
127
  return r >>> 0;
127
128
  }
128
- function Ln(n) {
129
- return n != null && n.length > 0;
130
- }
131
129
  function wn(n) {
132
- return a(T(n), "_", " ");
130
+ return n != null && n.length > 0;
133
131
  }
134
132
  function In(n) {
135
- return n.length > 0 && !x.test(n);
133
+ return c(k(n), "_", " ");
136
134
  }
137
135
  function mn(n) {
138
- return D.test(n);
136
+ return n.length > 0 && !D.test(n);
137
+ }
138
+ function On(n) {
139
+ return G.test(n);
139
140
  }
140
141
  function Sn(n) {
141
- return !Z.test(n);
142
+ return !T.test(n);
142
143
  }
143
- function On(n) {
144
+ function Wn(n) {
144
145
  return n.toLowerCase() === n;
145
146
  }
146
- function Wn(n) {
147
+ function yn(n) {
147
148
  return n.toUpperCase() === n;
148
149
  }
149
- function yn(n, t) {
150
+ function En(n, t) {
150
151
  return n != null && n !== "" ? n : t;
151
152
  }
152
153
  function zn(n) {
153
- return G.test(n);
154
+ return F.test(n);
154
155
  }
155
- function En(n) {
156
+ function Bn(n) {
156
157
  return n == null || n === "";
157
158
  }
158
- function Bn(n) {
159
+ function jn(n) {
159
160
  return n.substring(0, 1).toLowerCase() + n.substring(1);
160
161
  }
161
162
  function B(n, t = 1) {
@@ -167,55 +168,59 @@ function B(n, t = 1) {
167
168
  function j(n, t) {
168
169
  return A(t, () => B(n)).join("");
169
170
  }
170
- function jn(n) {
171
- return j(k, n);
171
+ function _n(n) {
172
+ return j(P, n);
172
173
  }
173
- function _n(n, t) {
174
+ function Mn(n, t) {
174
175
  return g(t).map(n);
175
176
  }
176
- function $n(n, t) {
177
- return a(n, t, "");
177
+ function Nn(n, t) {
178
+ return c(n, t, "");
178
179
  }
179
- function Mn(n, t) {
180
+ function Un(n, t) {
180
181
  return L(n, t) ? n.substring(0, n.length - t.length) : n;
181
182
  }
182
- function Nn(n, t, r) {
183
+ function $n(n, t, r) {
183
184
  return n.substring(0, t) + n.substring(t + r);
184
185
  }
185
- function Tn(n, t) {
186
+ function xn(n, t) {
186
187
  return W(n, t) ? n.substring(t.length) : n;
187
188
  }
188
- function Un(n, t) {
189
+ function kn(n, t) {
189
190
  const r = n.indexOf(t);
190
191
  return r < 0 ? n : n.substring(0, r) + n.substring(r + t.length);
191
192
  }
192
193
  function I(n, t) {
193
- return O(t, n).join("");
194
+ return S(t, n).join("");
194
195
  }
195
- function kn(n) {
196
+ function Zn(n) {
196
197
  const t = g(n);
197
198
  return t.reverse(), t.join("");
198
199
  }
199
- function Pn(n) {
200
- return n.includes('"') ? n.includes("'") ? '"' + a(n, '"', '\\"') + '"' : "'" + n + "'" : '"' + n + '"';
200
+ function _(n, t = "'") {
201
+ return t === "'" ? n.includes("'") ? n.includes('"') ? "'" + c(n, "'", "\\'") + "'" : '"' + n + '"' : "'" + n + "'" : n.includes('"') ? n.includes("'") ? '"' + c(n, '"', '\\"') + '"' : "'" + n + "'" : '"' + n + '"';
202
+ }
203
+ function M(n, t = "'") {
204
+ return t + c(n, t, "\\" + t) + t;
201
205
  }
202
- function Zn(n, t) {
206
+ function Pn(n, t = "'") {
207
+ return n.indexOf(`
208
+ `) >= 0 ? M(n, "`") : _(n, t);
209
+ }
210
+ function Rn(n, t) {
203
211
  const r = n.indexOf(t);
204
212
  return r < 0 ? [n] : [n.substring(0, r), n.substring(r + t.length)];
205
213
  }
206
- function _(n, t) {
207
- return c(t, (r) => n.startsWith(r));
208
- }
209
- function xn(n) {
210
- return n.replace(H, "");
214
+ function N(n, t) {
215
+ return l(t, (r) => n.startsWith(r));
211
216
  }
212
- function Rn(n, t, r = t) {
217
+ function Tn(n, t, r = t) {
213
218
  return `${t}${n}${r}`;
214
219
  }
215
220
  function g(n) {
216
221
  return n.split("");
217
222
  }
218
- function $(n) {
223
+ function U(n) {
219
224
  return A(n.length, (t) => n.charCodeAt(t));
220
225
  }
221
226
  function Dn(n, t) {
@@ -224,75 +229,75 @@ function Dn(n, t) {
224
229
  r.push(n.substring(0, t)), n = n.substr(t, n.length - t);
225
230
  return r;
226
231
  }
227
- function Gn(n) {
228
- return n.split(S);
232
+ function Hn(n) {
233
+ return n.split(O);
229
234
  }
230
- function Hn(n, t) {
231
- return N(M(n, t), t);
235
+ function Gn(n, t) {
236
+ return x($(n, t), t);
232
237
  }
233
- function M(n, t) {
238
+ function $(n, t) {
234
239
  let r = 0;
235
- for (let e = 0; e < n.length && l(t, n.charAt(e)); e++)
240
+ for (let e = 0; e < n.length && a(t, n.charAt(e)); e++)
236
241
  r++;
237
242
  return n.substring(r);
238
243
  }
239
- function N(n, t) {
244
+ function x(n, t) {
240
245
  const r = n.length;
241
246
  let e = r, i;
242
- for (let u = 0; u < r && (i = r - u - 1, l(t, n.charAt(i))); u++)
247
+ for (let s = 0; s < r && (i = r - s - 1, a(t, n.charAt(i))); s++)
243
248
  e = i;
244
249
  return n.substring(0, e);
245
250
  }
246
- function T(n) {
251
+ function k(n) {
247
252
  return n = n.replace(/::/g, "/"), n = n.replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2"), n = n.replace(/([a-z\d])([A-Z])/g, "$1_$2"), n = n.replace(/-/g, "_"), n.toLowerCase();
248
253
  }
249
- function qn(n) {
254
+ function Fn(n) {
250
255
  return n.substring(0, 1).toUpperCase() + n.substring(1);
251
256
  }
252
- function Fn(n, t) {
257
+ function Qn(n, t) {
253
258
  const r = n.indexOf(t);
254
259
  return r < 0 ? n : n.substring(0, r);
255
260
  }
256
261
  function Kn(n, t = 78, r = "", e = `
257
262
  `) {
258
- return n.split(S).map(
259
- (i) => U(i.replace(m, " ").trim(), t, r, e)
263
+ return n.split(O).map(
264
+ (i) => Z(i.replace(m, " ").trim(), t, r, e)
260
265
  ).join(e);
261
266
  }
262
- function C(n, t) {
267
+ function b(n, t) {
263
268
  if (t < 0 || t >= n.length) return !1;
264
269
  const r = n.charCodeAt(t);
265
270
  return r === 9 || r === 10 || r === 11 || r === 12 || r === 13 || r === 32;
266
271
  }
267
- function Jn(n) {
272
+ function qn(n) {
268
273
  if (typeof Buffer < "u")
269
274
  return Buffer.from(n).toString("base64");
270
275
  if (typeof btoa < "u")
271
276
  return btoa(n);
272
- throw new Error("no implementation provided for base64 encoding");
277
+ throw new Error("no implementation found for base64 encoding");
273
278
  }
274
- function Qn(n) {
279
+ function Jn(n) {
275
280
  if (typeof Buffer < "u")
276
281
  return Buffer.from(n, "base64").toString("utf8");
277
282
  if (typeof atob < "u")
278
283
  return atob(n);
279
- throw new Error("no implementation provided for base64 decoding");
284
+ throw new Error("no implementation found for base64 decoding");
280
285
  }
281
- function U(n, t, r, e) {
282
- const i = [], u = n.length, f = r.length;
283
- let s = 0;
286
+ function Z(n, t, r, e) {
287
+ const i = [], s = n.length, f = r.length;
288
+ let u = 0;
284
289
  for (t -= f; ; ) {
285
- if (s + t >= u - f) {
286
- i.push(n.substring(s));
290
+ if (u + t >= s - f) {
291
+ i.push(n.substring(u));
287
292
  break;
288
293
  }
289
294
  let o = 0;
290
- for (; !C(n, s + t - o) && o < t; ) o++;
295
+ for (; !b(n, u + t - o) && o < t; ) o++;
291
296
  if (o === t) {
292
- for (o = 0; !C(n, s + t + o) && s + t + o < u; ) o++;
293
- i.push(n.substring(s, s + t + o)), s += t + o + 1;
297
+ for (o = 0; !b(n, u + t + o) && u + t + o < s; ) o++;
298
+ i.push(n.substring(u, u + t + o)), u += t + o + 1;
294
299
  } else
295
- i.push(n.substring(s, s + t - o)), s += t - o + 1;
300
+ i.push(n.substring(u, u + t - o)), u += t - o + 1;
296
301
  }
297
302
  return r + i.join(e + r);
298
303
  }
@@ -312,85 +317,86 @@ function vn(n, t) {
312
317
  const r = n.indexOf(t);
313
318
  return r >= 0 ? [n.substring(0, r), n.substring(r + t.length)] : [n];
314
319
  }
315
- const k = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", P = /[^a-zA-Z]([a-z])/g, Z = /[^\t\n\r ]/, x = /[^a-zA-Z]/, R = /[ \t\r\n][a-z]/g, D = /^[a-z0-9]+$/i, G = /^[0-9]+$/, H = /<\/?[a-z]+[^>]*>/gi, m = /[ \t\r\n]+/g, S = /\r\n|\n\r|\n|\r/g, q = /\r\n|\n\r|\r/g;
320
+ const P = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", R = /[^a-zA-Z]([a-z])/g, T = /[^\t\n\r ]/, D = /[^a-zA-Z]/, H = /[ \t\r\n][a-z]/g, G = /^[a-z0-9]+$/i, F = /^[0-9]+$/, m = /[ \t\r\n]+/g, O = /\r\n|\n\r|\n|\r/g, Q = /\r\n|\n\r|\r/g;
316
321
  export {
317
322
  J as after,
318
- Q as afterLast,
319
- V as before,
320
- X as beforeLast,
321
- v as canonicalizeNewlines,
322
- h as capitalize,
323
- Y as capitalizeWords,
323
+ V as afterLast,
324
+ X as before,
325
+ Y as beforeLast,
326
+ nn as canonicalizeNewlines,
327
+ p as capitalize,
328
+ v as capitalizeWords,
324
329
  sn as collapse,
325
- y as compare,
326
- nn as compareCaseInsensitive,
327
- l as contains,
328
- an as containsAll,
329
- ln as containsAllCaseInsensitive,
330
- cn as containsAny,
331
- fn as containsAnyCaseInsensitive,
330
+ tn as compareCaseInsensitive,
331
+ y as compareStrings,
332
+ a as contains,
333
+ gn as containsAll,
334
+ an as containsAllCaseInsensitive,
335
+ ln as containsAny,
336
+ cn as containsAnyCaseInsensitive,
332
337
  w as containsCaseInsensitive,
333
- un as count,
334
- gn as dasherize,
335
- Qn as decodeBase64,
338
+ fn as count,
339
+ hn as dasherize,
340
+ Jn as decodeBase64,
336
341
  pn as diffIndex,
337
- z as ellipsis,
338
- hn as ellipsisMiddle,
339
- Jn as encodeBase64,
342
+ E as ellipsis,
343
+ dn as ellipsisMiddle,
344
+ qn as encodeBase64,
340
345
  L as endsWith,
341
- E as endsWithAny,
342
- en as endsWithAnyCaseInsensitive,
343
- tn as endsWithCaseInsensitive,
344
- dn as filter,
346
+ z as endsWithAny,
347
+ on as endsWithAnyCaseInsensitive,
348
+ rn as endsWithCaseInsensitive,
349
+ bn as filter,
345
350
  Cn as filterCharcode,
346
- bn as from,
347
- Ln as hasContent,
348
- An as hashCode,
349
- wn as humanize,
350
- yn as ifEmpty,
351
- In as isAlpha,
352
- mn as isAlphaNum,
351
+ An as from,
352
+ wn as hasContent,
353
+ Ln as hashCode,
354
+ In as humanize,
355
+ En as ifEmpty,
356
+ mn as isAlpha,
357
+ On as isAlphaNum,
353
358
  Sn as isBreakingWhitespace,
354
359
  zn as isDigitsOnly,
355
- En as isEmpty,
356
- On as isLowerCase,
357
- C as isSpaceAt,
358
- Wn as isUpperCase,
359
- Bn as lowerCaseFirst,
360
+ Bn as isEmpty,
361
+ Wn as isLowerCase,
362
+ b as isSpaceAt,
363
+ yn as isUpperCase,
364
+ Pn as jsQuote,
365
+ jn as lowerCaseFirst,
360
366
  Vn as lpad,
361
- _n as map,
362
- Pn as quote,
367
+ Mn as map,
368
+ M as quote,
363
369
  B as random,
364
370
  j as randomSequence,
365
- jn as randomSequence64,
366
- $n as remove,
367
- Mn as removeAfter,
368
- Nn as removeAt,
369
- Tn as removeBefore,
370
- Un as removeOne,
371
+ _n as randomSequence64,
372
+ Nn as remove,
373
+ Un as removeAfter,
374
+ $n as removeAt,
375
+ xn as removeBefore,
376
+ kn as removeOne,
371
377
  I as repeat,
372
- a as replace,
373
- kn as reverse,
378
+ c as replace,
379
+ Zn as reverse,
374
380
  Xn as rpad,
381
+ _ as smartQuote,
375
382
  vn as splitOnFirst,
376
383
  Yn as splitOnLast,
377
- Zn as splitOnce,
384
+ Rn as splitOnce,
378
385
  W as startsWith,
379
- _ as startsWithAny,
380
- on as startsWithAnyCaseInsensitive,
381
- rn as startsWithCaseInsensitive,
382
- xn as stripTags,
383
- Rn as surround,
386
+ N as startsWithAny,
387
+ un as startsWithAnyCaseInsensitive,
388
+ en as startsWithCaseInsensitive,
389
+ Tn as surround,
384
390
  g as toArray,
385
- $ as toCharcodes,
391
+ U as toCharcodes,
386
392
  Dn as toChunks,
387
- Gn as toLines,
388
- Hn as trimChars,
389
- M as trimCharsLeft,
390
- N as trimCharsRight,
391
- T as underscore,
392
- Fn as upTo,
393
- qn as upperCaseFirst,
393
+ Hn as toLines,
394
+ Gn as trimChars,
395
+ $ as trimCharsLeft,
396
+ x as trimCharsRight,
397
+ k as underscore,
398
+ Qn as upTo,
399
+ Fn as upperCaseFirst,
394
400
  Kn as wrapColumns,
395
- U as wrapLine
401
+ Z as wrapLine
396
402
  };
package/validation.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./result.cjs"),t={valid:{type:"valid"},invalid(e){return{type:"invalid",error:e}},isValid(e){return e.type==="valid"},isInvalid(e){return e.type==="invalid"},cmatch:(e,i)=>r=>t.isValid(r)?e():i(r.error),match:(e,i,r)=>t.isValid(e)?i():r(e.error),toResult:e=>t.cmatch(()=>l.Result.success(e),i=>l.Result.failure(i)),whenValid:e=>i=>(t.isValid(i)&&e(),i),whenInvalid:e=>i=>(t.isInvalid(i)&&e(i.error),i)};exports.Validation=t;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./result-DzdZiQoR.cjs");exports.Validation=i.Validation;
package/validation.d.ts CHANGED
@@ -1,24 +1,92 @@
1
1
  import { Result } from './result';
2
2
 
3
+ /**
4
+ * Represents a valid result.
5
+ * @public
6
+ */
3
7
  export interface Valid {
4
8
  type: 'valid';
5
9
  }
10
+ /**
11
+ * Represents an invalid value with an associated error.
12
+ * @typeParam E - The type of the error.
13
+ * @public
14
+ */
6
15
  export interface Invalid<E> {
7
16
  type: 'invalid';
8
17
  error: E;
9
18
  }
19
+ /**
20
+ * Represents a type that can either be `Valid` or `Invalid`.
21
+ * @typeParam E - The type of the error associated with an `Invalid` value.
22
+ * @public
23
+ */
10
24
  export type Validation<E> = Valid | Invalid<E>;
25
+ /**
26
+ * Represents a promise that resolves to a `Validation` object.
27
+ * @typeParam E - The type of the error value in the `Validation` object.
28
+ * @public
29
+ */
11
30
  export type PromiseValidation<E> = PromiseLike<Validation<E>>;
31
+ /**
32
+ * Utility functions for working with `Validation` types.
33
+ * @public
34
+ */
12
35
  export declare const Validation: {
36
+ /**
37
+ * Creates a valid `Validation`.
38
+ * @returns A `Validation` that is `Valid`.
39
+ */
13
40
  valid: {
14
41
  type: "valid";
15
42
  };
43
+ /**
44
+ * Creates an invalid `Validation`.
45
+ * @param error - The error associated with the invalid value.
46
+ * @returns A `Validation` that is `Invalid`.
47
+ */
16
48
  invalid<E>(error: E): Validation<E>;
49
+ /**
50
+ * Checks if a `Validation` is `Valid`.
51
+ * @param r - The `Validation` to check.
52
+ * @returns `true` if the `Validation` is `Valid`, otherwise `false`.
53
+ */
17
54
  isValid<E>(r: Validation<E>): r is Valid;
55
+ /**
56
+ * Checks if a `Validation` is `Invalid`.
57
+ * @param r - The `Validation` to check.
58
+ * @returns `true` if the `Validation` is `Invalid`, otherwise `false`.
59
+ */
18
60
  isInvalid<E>(r: Validation<E>): r is Invalid<E>;
19
- cmatch: <V, E>(valid: () => V, invalid: (error: E) => V) => (r: Validation<E>) => V;
61
+ /**
62
+ * Maps the value of a `Validation` to a new value.
63
+ * @param r - The `Validation` to map.
64
+ * @param valid - The mapping function for a valid value.
65
+ * @param invalid - The mapping function for an invalid value.
66
+ * @returns The mapped value.
67
+ */
20
68
  match: <V, E>(r: Validation<E>, valid: () => V, invalid: (error: E) => V) => V;
21
- toResult: <T, E>(value: T) => ((validation: Validation<E>) => Result<T, E>);
22
- whenValid: <E>(apply: () => void) => (r: Validation<E>) => Validation<E>;
23
- whenInvalid: <E>(apply: (e: E) => void) => (r: Validation<E>) => Validation<E>;
69
+ /**
70
+ * Maps the value of a `Validation` to a new `Validation`.
71
+ * @param validation - The `Validation` to map.
72
+ * @param value - The value to map.
73
+ * @returns A new `Validation` with the mapped value.
74
+ */
75
+ toResult: <T, E>(validation: Validation<E>, value: T) => Result<T, E>;
76
+ /**
77
+ * Execute a function when the `Validation` is valid.
78
+ *
79
+ * @param r - The `Validation` to check.
80
+ * @param apply - The function to execute when the `Validation` is valid.
81
+ * @returns The `Validation` object.
82
+ */
83
+ whenValid: <E>(r: Validation<E>, apply: () => void) => Validation<E>;
84
+ /**
85
+ * Execute a function when the `Validation` is invalid.
86
+ *
87
+ * @param r - The `Validation` to check.
88
+ * @param apply - The function to execute when the `Validation` is invalid.
89
+ * @returns The `Validation` object.
90
+ */
91
+ whenInvalid: <E>(r: Validation<E>, apply: (e: E) => void) => Validation<E>;
24
92
  };
package/validation.js CHANGED
@@ -1,25 +1,4 @@
1
- import { Result as a } from "./result.js";
2
- const r = {
3
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
- valid: { type: "valid" },
5
- invalid(i) {
6
- return { type: "invalid", error: i };
7
- },
8
- isValid(i) {
9
- return i.type === "valid";
10
- },
11
- isInvalid(i) {
12
- return i.type === "invalid";
13
- },
14
- cmatch: (i, e) => (t) => r.isValid(t) ? i() : e(t.error),
15
- match: (i, e, t) => r.isValid(i) ? e() : t(i.error),
16
- toResult: (i) => r.cmatch(
17
- () => a.success(i),
18
- (e) => a.failure(e)
19
- ),
20
- whenValid: (i) => (e) => (r.isValid(e) && i(), e),
21
- whenInvalid: (i) => (e) => (r.isInvalid(e) && i(e.error), e)
22
- };
1
+ import { V as i } from "./result-Czm7RKNP.js";
23
2
  export {
24
- r as Validation
3
+ i as Validation
25
4
  };
package/maybe.cjs DELETED
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e={nothing:void 0,just:t=>t,isNothing:t=>t==null,isJust:t=>t!=null};exports.Maybe=e;
package/maybe.d.ts DELETED
@@ -1,9 +0,0 @@
1
- export type Maybe<T> = Just<T> | Nothing;
2
- export type Nothing = undefined | null;
3
- export type Just<T> = NonNullable<T>;
4
- export declare const Maybe: {
5
- nothing: Maybe<never>;
6
- just: <T>(value: T) => Maybe<T>;
7
- isNothing: <T>(maybe: Maybe<T>) => maybe is Nothing;
8
- isJust: <T>(maybe: Maybe<T>) => maybe is Just<T>;
9
- };