@tempots/std 0.23.0 → 0.25.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,4 +1,4 @@
1
- import { MissingImplementationError as p } from "./error.js";
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), f = (t) => t.toUpperCase(), F = (t, n = !1) => n ? l(g(t), _, f) : l(g(t), z, f), G = (t) => t.replace($, `
16
- `), Q = (t, n) => t == null && n == null ? 0 : t == null ? -1 : n == null ? 1 : b(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) => S(
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, " "), b = (t, n) => t < n ? -1 : t > n ? 1 : 0, h = (t, n) => t.toLowerCase().includes(n.toLowerCase()), Y = (t, n) => t.split(n).length - 1, v = (t, n) => n.some((e) => h(t, e)), tt = (t, n) => n.some((e) => t.includes(e)), nt = (t, n) => n.every((e) => h(t, e)), et = (t, n) => n.every((e) => t.includes(e)), rt = (t) => t.replace(/_/g, "-"), st = (t, n) => {
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
- }, A = (t, n = 20, e = "…") => {
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 A(t, n, e);
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
- }, S = (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) => {
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(" "), ft = (t) => t.length > 0 && !N.test(t), at = (t) => M.test(t), pt = (t) => !T.test(t), ht = (t) => t.toLowerCase() === t, dt = (t) => t.toUpperCase() === t, Ct = (t, n) => t != null && t !== "" ? t : n, bt = (t) => U.test(t), At = (t) => t == null || t === "", St = (t) => t.substring(0, 1).toLowerCase() + t.substring(1), L = (t, n = 1) => {
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
- }, m = (t, n) => Array.from({ length: n }, () => L(t)).join(""), Lt = (t) => m(j, t), mt = (t, n) => Array.from(n).map(t), wt = (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) => {
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
- }, w = (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, "`") : w(t, n), Bt = (t, n) => {
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 > 0; )
60
- e.push(t.substring(0, n)), t = t.substring(n);
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
- let e = 0;
64
- for (let r = 0; r < t.length && n.includes(t.charAt(r)); r++)
65
- e++;
66
- return t.substring(e);
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 r = e, s;
70
- for (let c = 0; c < e && (s = e - c - 1, n.includes(t.charAt(s))); c++)
71
- r = s;
72
- return t.substring(0, r);
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), a = (t, n) => {
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 p(
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 p(
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 (; !a(t, o + n - i) && i < n; ) i++;
106
+ for (; !f(t, o + n - i) && i < n; ) i++;
106
107
  if (i === n) {
107
- for (i = 0; !a(t, o + n + i) && o + n + i < c; ) i++;
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
- b as compareStrings,
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
- wt as deleteSubstring,
145
- A as ellipsis,
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
- ft as isAlpha,
153
- at as isAlphaNum,
154
- pt as isBreakingWhitespace,
155
- bt as isDigitsOnly,
156
- At as isEmptyString,
157
- ht as isLowerCase,
158
- a as isSpaceAt,
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
- St as lowerCaseFirst,
162
+ At as lowerCaseFirst,
162
163
  kt as lpad,
163
- mt as mapChars,
164
+ wt as mapChars,
164
165
  I as quote,
165
- m as randomStringSequence,
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
- w as smartQuote,
171
+ m as smartQuote,
171
172
  Dt as splitStringOnFirst,
172
173
  Zt as splitStringOnLast,
173
174
  Bt as splitStringOnce,
174
- S as stringEndsWithAny,
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
- h as textContainsCaseInsensitive,
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)=>{const t=setTimeout(n,e);return()=>clearTimeout(t)},b=(n,e)=>{const t=setInterval(n,e);return()=>clearInterval(t)},F=(n,e,t={})=>{const{noTrailing:o=!1,noLeading:l=!1,debounceMode:i}=t;let a,m=!1,c=0;function f(){a&&clearTimeout(a)}function T(u){const{upcomingOnly:s=!1}=u||{};f(),m=!s}function d(...u){if(m)return;const s=this,v=Date.now()-c;function r(){c=Date.now(),e.apply(s,u)}function A(){a=void 0}!l&&i&&!a&&r(),f(),i===void 0&&v>n?l?(c=Date.now(),o||(a=setTimeout(i?A:r,n))):r():o||(a=setTimeout(i?A:r,i===void 0?n-v:n))}return d.cancel=T,d},g=(n,e,{atBegin:t=!1}={})=>F(n,e,{debounceMode:t!==!1}),y=n=>{let e=null;const t=l=>{e=null,n(l)};return(()=>{e==null&&(e=requestAnimationFrame(t))})(),()=>{e!=null&&(cancelAnimationFrame(e),e=null)}},I=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=g;exports.delayed=p;exports.delayedAnimationFrame=y;exports.interval=b;exports.intervalAnimationFrame=I;exports.throttle=F;
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
@@ -69,10 +69,26 @@ export interface CancelOptions {
69
69
  * Represents a throttled function with a cancel method.
70
70
  * @public
71
71
  */
72
- export interface ThrottledFunction<T extends unknown[]> {
73
- (...args: T): void;
72
+ export interface ThrottledFunction<TArgs extends any[], This = unknown> {
73
+ (this: This, ...args: TArgs): void;
74
74
  cancel: (options?: CancelOptions) => void;
75
75
  }
76
+ export interface ThrottleOptions {
77
+ noTrailing?: boolean;
78
+ noLeading?: boolean;
79
+ debounceMode?: boolean;
80
+ }
81
+ /**
82
+ * Options for debouncing a function.
83
+ * @public
84
+ */
85
+ export type DebounceOptions = {
86
+ /**
87
+ * If true, the callback is executed immediately before the delay.
88
+ * @default false
89
+ */
90
+ atBegin?: boolean;
91
+ };
76
92
  /**
77
93
  * Copyright (c) Ivan Nikolić http://ivannikolic.com
78
94
  *
@@ -117,18 +133,7 @@ export interface ThrottledFunction<T extends unknown[]> {
117
133
  * Common delay values are 100-250ms for UI updates and 1000ms+ for API calls.
118
134
  * @public
119
135
  */
120
- export declare const throttle: <FN extends (...args: unknown[]) => void>(delay: number, callback: FN, options?: ThrottleOptions) => ThrottledFunction<Parameters<FN>>;
121
- /**
122
- * Options for debouncing a function.
123
- * @public
124
- */
125
- export type DebounceOptions = {
126
- /**
127
- * If true, the callback is executed immediately before the delay.
128
- * @default false
129
- */
130
- atBegin?: boolean;
131
- };
136
+ export declare function throttle<This, F extends (this: This, ...args: any[]) => any>(delay: number, callback: F, options?: ThrottleOptions): ThrottledFunction<Parameters<F>, This>;
132
137
  /**
133
138
  * Copyright (c) Ivan Nikolić http://ivannikolic.com
134
139
  *
@@ -153,16 +158,16 @@ export type DebounceOptions = {
153
158
  *
154
159
  * @param {number} delay - A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
155
160
  * @param {Function} callback - A function to be executed after delay milliseconds. The `this` context and all arguments are passed through, as-is,
156
- * to `callback` when the debounced-function is executed.
161
+ * to `callback` when the debounced-function is executed.
157
162
  * @param {object} [options] - An object to configure options.
158
163
  * @param {boolean} [options.atBegin] - Optional, defaults to false. If atBegin is false or unspecified, callback will only be executed `delay` milliseconds
159
- * after the last debounced-function call. If atBegin is true, callback will be executed only at the first debounced-function call.
160
- * (After the throttled-function has not been called for `delay` milliseconds, the internal counter is reset).
164
+ * after the last debounced-function call. If atBegin is true, callback will be executed only at the first debounced-function call.
165
+ * (After the throttled-function has not been called for `delay` milliseconds, the internal counter is reset).
161
166
  *
162
167
  * @returns {Function} A new, debounced function.
163
168
  * @public
164
169
  */
165
- export declare const debounce: <FN extends (...args: unknown[]) => void>(delay: number, callback: FN, { atBegin }?: DebounceOptions) => ThrottledFunction<Parameters<FN>>;
170
+ export declare function debounce<This, F extends (this: This, ...args: any[]) => any>(delay: number, callback: F, { atBegin }?: DebounceOptions): ThrottledFunction<Parameters<F>, This>;
166
171
  /**
167
172
  * Delays the execution of a function using requestAnimationFrame.
168
173
  *
package/timer.js CHANGED
@@ -1,35 +1,54 @@
1
- const T = (n, e) => {
2
- const t = setTimeout(n, e);
3
- return () => clearTimeout(t);
4
- }, I = (n, e) => {
5
- const t = setInterval(n, e);
6
- return () => clearInterval(t);
7
- }, F = (n, e, t = {}) => {
8
- const { noTrailing: a = !1, noLeading: l = !1, debounceMode: i } = t;
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
+ };
21
+ };
22
+ function A(n, e, t = {}) {
23
+ const { noTrailing: i = !1, noLeading: l = !1, debounceMode: a } = t;
9
24
  let o, f = !1, c = 0;
10
25
  function m() {
11
26
  o && clearTimeout(o);
12
27
  }
13
- function A(u) {
28
+ function p(u) {
14
29
  const { upcomingOnly: s = !1 } = u || {};
15
30
  m(), f = !s;
16
31
  }
17
32
  function d(...u) {
18
33
  if (f) return;
19
- const s = this, p = Date.now() - c;
34
+ const s = this, F = Date.now() - c;
20
35
  function r() {
21
36
  c = Date.now(), e.apply(s, u);
22
37
  }
23
38
  function v() {
24
39
  o = void 0;
25
40
  }
26
- !l && i && !o && r(), m(), i === void 0 && p > n ? l ? (c = Date.now(), a || (o = setTimeout(i ? v : r, n))) : r() : a || (o = setTimeout(
27
- i ? v : r,
28
- i === void 0 ? n - p : n
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
29
44
  ));
30
45
  }
31
- return d.cancel = A, d;
32
- }, g = (n, e, { atBegin: t = !1 } = {}) => F(n, e, { debounceMode: t !== !1 }), w = (n) => {
46
+ return d.cancel = p, d;
47
+ }
48
+ function x(n, e, { atBegin: t = !1 } = {}) {
49
+ return A(n, e, { debounceMode: t !== !1 });
50
+ }
51
+ const g = (n) => {
33
52
  let e = null;
34
53
  const t = (l) => {
35
54
  e = null, n(l);
@@ -39,7 +58,7 @@ const T = (n, e) => {
39
58
  })(), () => {
40
59
  e != null && (cancelAnimationFrame(e), e = null);
41
60
  };
42
- }, x = (n) => {
61
+ }, w = (n) => {
43
62
  let e = null;
44
63
  const t = (l) => {
45
64
  e = requestAnimationFrame(t), n(l);
@@ -51,10 +70,10 @@ const T = (n, e) => {
51
70
  };
52
71
  };
53
72
  export {
54
- g as debounce,
55
- T as delayed,
56
- w as delayedAnimationFrame,
57
- I as interval,
58
- x as intervalAnimationFrame,
59
- F as throttle
73
+ x as debounce,
74
+ I as delayed,
75
+ g as delayedAnimationFrame,
76
+ T as interval,
77
+ w as intervalAnimationFrame,
78
+ A as throttle
60
79
  };
package/validation.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./result-CdwVhaAc.cjs");exports.Validation=i.Validation;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./result-cY1uEC-G.cjs");exports.Validation=i.Validation;
package/validation.d.ts CHANGED
@@ -88,4 +88,81 @@ export declare const Validation: {
88
88
  * @returns The `Validation` object.
89
89
  */
90
90
  whenInvalid: <E>(r: Validation<E>, apply: (e: E) => void) => Validation<E>;
91
+ /**
92
+ * Maps the error of an invalid `Validation` to a new error using the provided function.
93
+ * For valid validations, the validation is preserved unchanged.
94
+ * @param v - The `Validation` to map the error of.
95
+ * @param f - The mapping function to apply to the error.
96
+ * @returns A new `Validation` with the mapped error if invalid, otherwise the original valid.
97
+ * @public
98
+ */
99
+ mapError: <E, F>(v: Validation<E>, f: (error: E) => F) => Validation<F>;
100
+ /**
101
+ * Maps the error of an invalid `Validation` to a new `Validation` using the provided function.
102
+ * This allows recovery from errors by returning a valid validation.
103
+ * @param v - The `Validation` to recover from.
104
+ * @param f - The recovery function that returns a new `Validation`.
105
+ * @returns The result of the recovery function if invalid, otherwise the original valid.
106
+ * @public
107
+ */
108
+ flatMapError: <E, F>(v: Validation<E>, f: (error: E) => Validation<F>) => Validation<F>;
109
+ /**
110
+ * Combines two validations. Both must be valid for the result to be valid.
111
+ * If both are invalid, errors are combined using the provided function.
112
+ * @param v1 - The first validation.
113
+ * @param v2 - The second validation.
114
+ * @param combineErrors - The function to combine two errors.
115
+ * @returns A combined validation.
116
+ * @public
117
+ */
118
+ combine: <E>(v1: Validation<E>, v2: Validation<E>, combineErrors: (e1: E, e2: E) => E) => Validation<E>;
119
+ /**
120
+ * Combines multiple validations into a single validation.
121
+ * All must be valid for the result to be valid.
122
+ * Returns the first invalid validation if any.
123
+ * @param validations - The validations to combine.
124
+ * @returns A single validation that is valid only if all inputs are valid.
125
+ * @public
126
+ */
127
+ all: <E>(validations: Validation<E>[]) => Validation<E>;
128
+ /**
129
+ * Combines multiple validations, accumulating all errors.
130
+ * All must be valid for the result to be valid.
131
+ * If any are invalid, all errors are collected into an array.
132
+ * @param validations - The validations to combine.
133
+ * @returns A validation that is valid only if all inputs are valid, otherwise contains all errors.
134
+ * @public
135
+ */
136
+ allErrors: <E>(validations: Validation<E>[]) => Validation<E[]>;
137
+ /**
138
+ * Compares two validations for equality.
139
+ * @param v1 - The first validation.
140
+ * @param v2 - The second validation.
141
+ * @param errorEquals - Optional custom equality function for errors. Defaults to strict equality.
142
+ * @returns `true` if the validations are equal, `false` otherwise.
143
+ * @public
144
+ */
145
+ equals: <E>(v1: Validation<E>, v2: Validation<E>, errorEquals?: (e1: E, e2: E) => boolean) => boolean;
146
+ /**
147
+ * Recovers from an invalid validation by returning a valid validation.
148
+ * @param v - The `Validation` to recover from.
149
+ * @returns A valid validation regardless of the input.
150
+ * @public
151
+ */
152
+ recover: <E>(_v: Validation<E>) => Validation<never>;
153
+ /**
154
+ * Gets the error if the validation is invalid, otherwise returns undefined.
155
+ * @param v - The validation to get the error from.
156
+ * @returns The error if invalid, otherwise undefined.
157
+ * @public
158
+ */
159
+ getError: <E>(v: Validation<E>) => E | undefined;
160
+ /**
161
+ * Gets the error if the validation is invalid, otherwise returns the default value.
162
+ * @param v - The validation to get the error from.
163
+ * @param defaultError - The default error to return if valid.
164
+ * @returns The error if invalid, otherwise the default error.
165
+ * @public
166
+ */
167
+ getErrorOrElse: <E>(v: Validation<E>, defaultError: E) => E;
91
168
  };
package/validation.js CHANGED
@@ -1,4 +1,4 @@
1
- import { V as i } from "./result-CGd0jCdl.js";
1
+ import { V as i } from "./result-BrVFeaNO.js";
2
2
  export {
3
3
  i as Validation
4
4
  };