es-toolkit 1.3.1-dev.76 → 1.3.1-dev.79

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.
Files changed (60) hide show
  1. package/dist/chunk-AL3GJBEI.mjs +26 -0
  2. package/dist/chunk-AL3GJBEI.mjs.map +1 -0
  3. package/dist/chunk-FZEZH22H.mjs +1 -0
  4. package/dist/chunk-LJHSPVPM.mjs +12 -0
  5. package/dist/chunk-LJHSPVPM.mjs.map +1 -0
  6. package/dist/{chunk-GOXQV6DX.mjs → chunk-MKETZ2RP.mjs} +2 -3
  7. package/dist/{chunk-GOXQV6DX.mjs.map → chunk-MKETZ2RP.mjs.map} +1 -1
  8. package/dist/chunk-NNIW65CD.mjs +1 -0
  9. package/dist/chunk-NNIW65CD.mjs.map +1 -0
  10. package/dist/chunk-VP2LXY75.mjs +12 -0
  11. package/dist/chunk-VP2LXY75.mjs.map +1 -0
  12. package/dist/error/AbortError.d.mts +5 -0
  13. package/dist/error/AbortError.d.ts +5 -0
  14. package/dist/error/AbortError.js +36 -0
  15. package/dist/error/AbortError.js.map +1 -0
  16. package/dist/error/AbortError.mjs +8 -0
  17. package/dist/error/AbortError.mjs.map +1 -0
  18. package/dist/error/index.d.mts +1 -0
  19. package/dist/error/index.d.ts +1 -0
  20. package/dist/error/index.js +38 -0
  21. package/dist/error/index.js.map +1 -0
  22. package/dist/error/index.mjs +9 -0
  23. package/dist/error/index.mjs.map +1 -0
  24. package/dist/function/debounce.js +1 -2
  25. package/dist/function/debounce.js.map +1 -1
  26. package/dist/function/debounce.mjs +1 -1
  27. package/dist/function/index.js +1 -2
  28. package/dist/function/index.js.map +1 -1
  29. package/dist/function/index.mjs +4 -4
  30. package/dist/index.d.mts +2 -0
  31. package/dist/index.d.ts +2 -0
  32. package/dist/index.js +35 -5
  33. package/dist/index.js.map +1 -1
  34. package/dist/index.mjs +35 -26
  35. package/dist/math/index.d.mts +1 -0
  36. package/dist/math/index.d.ts +1 -0
  37. package/dist/math/index.js +10 -0
  38. package/dist/math/index.js.map +1 -1
  39. package/dist/math/index.mjs +7 -3
  40. package/dist/math/random.d.mts +15 -0
  41. package/dist/math/random.d.ts +15 -0
  42. package/dist/math/random.js +36 -0
  43. package/dist/math/random.js.map +1 -0
  44. package/dist/math/random.mjs +8 -0
  45. package/dist/math/random.mjs.map +1 -0
  46. package/dist/object/index.mjs +3 -3
  47. package/dist/predicate/index.mjs +3 -3
  48. package/dist/promise/delay.d.mts +18 -1
  49. package/dist/promise/delay.d.ts +18 -1
  50. package/dist/promise/delay.js +24 -3
  51. package/dist/promise/delay.js.map +1 -1
  52. package/dist/promise/delay.mjs +2 -1
  53. package/dist/promise/index.js +22 -3
  54. package/dist/promise/index.js.map +1 -1
  55. package/dist/promise/index.mjs +2 -1
  56. package/package.json +1 -1
  57. package/dist/chunk-IJLQVGW4.mjs +0 -1
  58. package/dist/chunk-ZBG3EYM3.mjs +0 -11
  59. package/dist/chunk-ZBG3EYM3.mjs.map +0 -1
  60. /package/dist/{chunk-IJLQVGW4.mjs.map → chunk-FZEZH22H.mjs.map} +0 -0
@@ -0,0 +1,26 @@
1
+ import {
2
+ AbortError
3
+ } from "./chunk-VP2LXY75.mjs";
4
+
5
+ // src/promise/delay.ts
6
+ function delay(ms, { signal } = {}) {
7
+ return new Promise((resolve, reject) => {
8
+ const abortError = () => {
9
+ reject(new AbortError());
10
+ };
11
+ const abortHandler = () => {
12
+ clearTimeout(timeoutId);
13
+ abortError();
14
+ };
15
+ if (signal == null ? void 0 : signal.aborted) {
16
+ return abortError();
17
+ }
18
+ const timeoutId = setTimeout(resolve, ms);
19
+ signal == null ? void 0 : signal.addEventListener("abort", abortHandler, { once: true });
20
+ });
21
+ }
22
+
23
+ export {
24
+ delay
25
+ };
26
+ //# sourceMappingURL=chunk-AL3GJBEI.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/promise/delay.ts"],"sourcesContent":["import { AbortError } from '../error/AbortError';\n\ninterface DelayOptions {\n signal?: AbortSignal;\n}\n\n/**\n * Delays the execution of code for a specified number of milliseconds.\n *\n * This function returns a Promise that resolves after the specified delay, allowing you to use it\n * with async/await to pause execution.\n *\n * @param {number} ms - The number of milliseconds to delay.\n * @param {DelayOptions} options - The options object.\n * @param {AbortSignal} options.signal - An optional AbortSignal to cancel the delay.\n * @returns {Promise<void>} A Promise that resolves after the specified delay.\n *\n * @example\n * async function foo() {\n * console.log('Start');\n * await delay(1000); // Delays execution for 1 second\n * console.log('End');\n * }\n *\n * foo();\n *\n * // With AbortSignal\n * const controller = new AbortController();\n * const { signal } = controller;\n *\n * setTimeout(() => controller.abort(), 50); // Will cancel the delay after 50ms\n * try {\n * await delay(100, { signal });\n * } catch (error) {\n * console.error(error); // Will log 'AbortError'\n * }\n * }\n */\nexport function delay(ms: number, { signal }: DelayOptions = {}): Promise<void> {\n return new Promise((resolve, reject) => {\n const abortError = () => {\n reject(new AbortError());\n };\n\n const abortHandler = () => {\n clearTimeout(timeoutId);\n abortError();\n };\n\n if (signal?.aborted) {\n return abortError();\n }\n\n const timeoutId = setTimeout(resolve, ms);\n\n signal?.addEventListener('abort', abortHandler, { once: true });\n });\n}\n"],"mappings":";;;;;AAsCO,SAAS,MAAM,IAAY,EAAE,OAAO,IAAkB,CAAC,GAAkB;AAC9E,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,UAAM,aAAa,MAAM;AACvB,aAAO,IAAI,WAAW,CAAC;AAAA,IACzB;AAEA,UAAM,eAAe,MAAM;AACzB,mBAAa,SAAS;AACtB,iBAAW;AAAA,IACb;AAEA,QAAI,iCAAQ,SAAS;AACnB,aAAO,WAAW;AAAA,IACpB;AAEA,UAAM,YAAY,WAAW,SAAS,EAAE;AAExC,qCAAQ,iBAAiB,SAAS,cAAc,EAAE,MAAM,KAAK;AAAA,EAC/D,CAAC;AACH;","names":[]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-FZEZH22H.mjs.map
@@ -0,0 +1,12 @@
1
+ // src/math/random.ts
2
+ function random(minimum, maximum) {
3
+ if (minimum >= maximum) {
4
+ throw new Error("Invalid input: The maximum value must be greater than the minimum value.");
5
+ }
6
+ return Math.random() * (maximum - minimum) + minimum;
7
+ }
8
+
9
+ export {
10
+ random
11
+ };
12
+ //# sourceMappingURL=chunk-LJHSPVPM.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/math/random.ts"],"sourcesContent":["/**\n * Generates a random floating-point number between minimum (inclusive) and maximum (exclusive).\n * If min is greater than maximum, the values are swapped.\n *\n * @param {number} minimum - The lower bound (inclusive).\n * @param {number} maximum - The upper bound (exclusive).\n * @returns {number} A random integer between minimum (inclusive) and maximum (exclusive).\n *\n * @example\n * const result = random(0, 5); // result will be a random floating-point number between 0 (inclusive) and 5 (exclusive)\n * const result2 = random(5, 0); // This will throw an error\n */\nexport function random(minimum: number, maximum: number): number {\n if (minimum >= maximum) {\n throw new Error('Invalid input: The maximum value must be greater than the minimum value.');\n }\n\n return Math.random() * (maximum - minimum) + minimum;\n}\n"],"mappings":";AAYO,SAAS,OAAO,SAAiB,SAAyB;AAC/D,MAAI,WAAW,SAAS;AACtB,UAAM,IAAI,MAAM,0EAA0E;AAAA,EAC5F;AAEA,SAAO,KAAK,OAAO,KAAK,UAAU,WAAW;AAC/C;","names":[]}
@@ -21,13 +21,12 @@ function debounce(func, debounceMs, { signal } = {}) {
21
21
  clearTimeout(timeoutId);
22
22
  timeoutId = null;
23
23
  }
24
- signal == null ? void 0 : signal.removeEventListener("abort", onAbort);
25
24
  };
26
- signal == null ? void 0 : signal.addEventListener("abort", onAbort);
25
+ signal == null ? void 0 : signal.addEventListener("abort", onAbort, { once: true });
27
26
  return debounced;
28
27
  }
29
28
 
30
29
  export {
31
30
  debounce
32
31
  };
33
- //# sourceMappingURL=chunk-GOXQV6DX.mjs.map
32
+ //# sourceMappingURL=chunk-MKETZ2RP.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/function/debounce.ts"],"sourcesContent":["interface DebounceOptions {\n signal?: AbortSignal;\n}\n\n/**\n * Creates a debounced function that delays invoking the provided function until after `debounceMs` milliseconds\n * have elapsed since the last time the debounced function was invoked. The debounced function also has a `cancel`\n * method to cancel any pending execution.\n *\n * @param {F} func - The function to debounce.\n * @param {number} debounceMs - The number of milliseconds to delay.\n * @param {DebounceOptions} options - The options object.\n * @param {AbortSignal} options.signal - An optional AbortSignal to cancel the debounced function.\n * @returns {F & { cancel: () => void }} A new debounced function with a `cancel` method.\n *\n * @example\n * const debouncedFunction = debounce(() => {\n * console.log('Function executed');\n * }, 1000);\n *\n * // Will log 'Function executed' after 1 second if not called again in that time\n * debouncedFunction();\n *\n * // Will not log anything as the previous call is canceled\n * debouncedFunction.cancel();\n *\n * // With AbortSignal\n * const controller = new AbortController();\n * const signal = controller.signal;\n * const debouncedWithSignal = debounce(() => {\n * console.log('Function executed');\n * }, 1000, { signal });\n *\n * debouncedWithSignal();\n *\n * // Will cancel the debounced function call\n * controller.abort();\n */\nexport function debounce<F extends (...args: any[]) => void>(\n func: F,\n debounceMs: number,\n { signal }: DebounceOptions = {}\n): F & { cancel: () => void } {\n let timeoutId: number | NodeJS.Timeout | null = null;\n\n const debounced = function (...args: Parameters<F>) {\n if (timeoutId !== null) {\n clearTimeout(timeoutId);\n }\n\n if (signal?.aborted) {\n return;\n }\n\n timeoutId = setTimeout(() => {\n func(...args);\n timeoutId = null;\n }, debounceMs);\n } as F & { cancel: () => void };\n\n const onAbort = function () {\n debounced.cancel();\n };\n\n debounced.cancel = function () {\n if (timeoutId !== null) {\n clearTimeout(timeoutId);\n timeoutId = null;\n }\n\n signal?.removeEventListener('abort', onAbort);\n };\n\n signal?.addEventListener('abort', onAbort);\n\n return debounced;\n}\n"],"mappings":";AAsCO,SAAS,SACd,MACA,YACA,EAAE,OAAO,IAAqB,CAAC,GACH;AAC5B,MAAI,YAA4C;AAEhD,QAAM,YAAY,YAAa,MAAqB;AAClD,QAAI,cAAc,MAAM;AACtB,mBAAa,SAAS;AAAA,IACxB;AAEA,QAAI,iCAAQ,SAAS;AACnB;AAAA,IACF;AAEA,gBAAY,WAAW,MAAM;AAC3B,WAAK,GAAG,IAAI;AACZ,kBAAY;AAAA,IACd,GAAG,UAAU;AAAA,EACf;AAEA,QAAM,UAAU,WAAY;AAC1B,cAAU,OAAO;AAAA,EACnB;AAEA,YAAU,SAAS,WAAY;AAC7B,QAAI,cAAc,MAAM;AACtB,mBAAa,SAAS;AACtB,kBAAY;AAAA,IACd;AAEA,qCAAQ,oBAAoB,SAAS;AAAA,EACvC;AAEA,mCAAQ,iBAAiB,SAAS;AAElC,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/function/debounce.ts"],"sourcesContent":["interface DebounceOptions {\n signal?: AbortSignal;\n}\n\n/**\n * Creates a debounced function that delays invoking the provided function until after `debounceMs` milliseconds\n * have elapsed since the last time the debounced function was invoked. The debounced function also has a `cancel`\n * method to cancel any pending execution.\n *\n * @param {F} func - The function to debounce.\n * @param {number} debounceMs - The number of milliseconds to delay.\n * @param {DebounceOptions} options - The options object.\n * @param {AbortSignal} options.signal - An optional AbortSignal to cancel the debounced function.\n * @returns {F & { cancel: () => void }} A new debounced function with a `cancel` method.\n *\n * @example\n * const debouncedFunction = debounce(() => {\n * console.log('Function executed');\n * }, 1000);\n *\n * // Will log 'Function executed' after 1 second if not called again in that time\n * debouncedFunction();\n *\n * // Will not log anything as the previous call is canceled\n * debouncedFunction.cancel();\n *\n * // With AbortSignal\n * const controller = new AbortController();\n * const signal = controller.signal;\n * const debouncedWithSignal = debounce(() => {\n * console.log('Function executed');\n * }, 1000, { signal });\n *\n * debouncedWithSignal();\n *\n * // Will cancel the debounced function call\n * controller.abort();\n */\nexport function debounce<F extends (...args: any[]) => void>(\n func: F,\n debounceMs: number,\n { signal }: DebounceOptions = {}\n): F & { cancel: () => void } {\n let timeoutId: number | NodeJS.Timeout | null = null;\n\n const debounced = function (...args: Parameters<F>) {\n if (timeoutId !== null) {\n clearTimeout(timeoutId);\n }\n\n if (signal?.aborted) {\n return;\n }\n\n timeoutId = setTimeout(() => {\n func(...args);\n timeoutId = null;\n }, debounceMs);\n } as F & { cancel: () => void };\n\n const onAbort = function () {\n debounced.cancel();\n };\n\n debounced.cancel = function () {\n if (timeoutId !== null) {\n clearTimeout(timeoutId);\n timeoutId = null;\n }\n };\n\n signal?.addEventListener('abort', onAbort, { once: true });\n\n return debounced;\n}\n"],"mappings":";AAsCO,SAAS,SACd,MACA,YACA,EAAE,OAAO,IAAqB,CAAC,GACH;AAC5B,MAAI,YAA4C;AAEhD,QAAM,YAAY,YAAa,MAAqB;AAClD,QAAI,cAAc,MAAM;AACtB,mBAAa,SAAS;AAAA,IACxB;AAEA,QAAI,iCAAQ,SAAS;AACnB;AAAA,IACF;AAEA,gBAAY,WAAW,MAAM;AAC3B,WAAK,GAAG,IAAI;AACZ,kBAAY;AAAA,IACd,GAAG,UAAU;AAAA,EACf;AAEA,QAAM,UAAU,WAAY;AAC1B,cAAU,OAAO;AAAA,EACnB;AAEA,YAAU,SAAS,WAAY;AAC7B,QAAI,cAAc,MAAM;AACtB,mBAAa,SAAS;AACtB,kBAAY;AAAA,IACd;AAAA,EACF;AAEA,mCAAQ,iBAAiB,SAAS,SAAS,EAAE,MAAM,KAAK;AAExD,SAAO;AACT;","names":[]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-NNIW65CD.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,12 @@
1
+ // src/error/AbortError.ts
2
+ var AbortError = class extends Error {
3
+ constructor(message = "The operation was aborted") {
4
+ super(message);
5
+ this.name = "AbortError";
6
+ }
7
+ };
8
+
9
+ export {
10
+ AbortError
11
+ };
12
+ //# sourceMappingURL=chunk-VP2LXY75.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/error/AbortError.ts"],"sourcesContent":["export class AbortError extends Error {\n constructor(message = 'The operation was aborted') {\n super(message);\n this.name = 'AbortError';\n }\n}\n"],"mappings":";AAAO,IAAM,aAAN,cAAyB,MAAM;AAAA,EACpC,YAAY,UAAU,6BAA6B;AACjD,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;","names":[]}
@@ -0,0 +1,5 @@
1
+ declare class AbortError extends Error {
2
+ constructor(message?: string);
3
+ }
4
+
5
+ export { AbortError };
@@ -0,0 +1,5 @@
1
+ declare class AbortError extends Error {
2
+ constructor(message?: string);
3
+ }
4
+
5
+ export { AbortError };
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/error/AbortError.ts
21
+ var AbortError_exports = {};
22
+ __export(AbortError_exports, {
23
+ AbortError: () => AbortError
24
+ });
25
+ module.exports = __toCommonJS(AbortError_exports);
26
+ var AbortError = class extends Error {
27
+ constructor(message = "The operation was aborted") {
28
+ super(message);
29
+ this.name = "AbortError";
30
+ }
31
+ };
32
+ // Annotate the CommonJS export names for ESM import in node:
33
+ 0 && (module.exports = {
34
+ AbortError
35
+ });
36
+ //# sourceMappingURL=AbortError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/error/AbortError.ts"],"sourcesContent":["export class AbortError extends Error {\n constructor(message = 'The operation was aborted') {\n super(message);\n this.name = 'AbortError';\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,IAAM,aAAN,cAAyB,MAAM;AAAA,EACpC,YAAY,UAAU,6BAA6B;AACjD,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;","names":[]}
@@ -0,0 +1,8 @@
1
+ import {
2
+ AbortError
3
+ } from "../chunk-VP2LXY75.mjs";
4
+ import "../chunk-2MM5EJJX.mjs";
5
+ export {
6
+ AbortError
7
+ };
8
+ //# sourceMappingURL=AbortError.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1 @@
1
+ export { AbortError } from './AbortError.mjs';
@@ -0,0 +1 @@
1
+ export { AbortError } from './AbortError.js';
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/error/index.ts
21
+ var error_exports = {};
22
+ __export(error_exports, {
23
+ AbortError: () => AbortError
24
+ });
25
+ module.exports = __toCommonJS(error_exports);
26
+
27
+ // src/error/AbortError.ts
28
+ var AbortError = class extends Error {
29
+ constructor(message = "The operation was aborted") {
30
+ super(message);
31
+ this.name = "AbortError";
32
+ }
33
+ };
34
+ // Annotate the CommonJS export names for ESM import in node:
35
+ 0 && (module.exports = {
36
+ AbortError
37
+ });
38
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/error/index.ts","../../src/error/AbortError.ts"],"sourcesContent":["export { AbortError } from './AbortError';\n","export class AbortError extends Error {\n constructor(message = 'The operation was aborted') {\n super(message);\n this.name = 'AbortError';\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,aAAN,cAAyB,MAAM;AAAA,EACpC,YAAY,UAAU,6BAA6B;AACjD,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;","names":[]}
@@ -0,0 +1,9 @@
1
+ import "../chunk-FZEZH22H.mjs";
2
+ import {
3
+ AbortError
4
+ } from "../chunk-VP2LXY75.mjs";
5
+ import "../chunk-2MM5EJJX.mjs";
6
+ export {
7
+ AbortError
8
+ };
9
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -45,9 +45,8 @@ function debounce(func, debounceMs, { signal } = {}) {
45
45
  clearTimeout(timeoutId);
46
46
  timeoutId = null;
47
47
  }
48
- signal == null ? void 0 : signal.removeEventListener("abort", onAbort);
49
48
  };
50
- signal == null ? void 0 : signal.addEventListener("abort", onAbort);
49
+ signal == null ? void 0 : signal.addEventListener("abort", onAbort, { once: true });
51
50
  return debounced;
52
51
  }
53
52
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/function/debounce.ts"],"sourcesContent":["interface DebounceOptions {\n signal?: AbortSignal;\n}\n\n/**\n * Creates a debounced function that delays invoking the provided function until after `debounceMs` milliseconds\n * have elapsed since the last time the debounced function was invoked. The debounced function also has a `cancel`\n * method to cancel any pending execution.\n *\n * @param {F} func - The function to debounce.\n * @param {number} debounceMs - The number of milliseconds to delay.\n * @param {DebounceOptions} options - The options object.\n * @param {AbortSignal} options.signal - An optional AbortSignal to cancel the debounced function.\n * @returns {F & { cancel: () => void }} A new debounced function with a `cancel` method.\n *\n * @example\n * const debouncedFunction = debounce(() => {\n * console.log('Function executed');\n * }, 1000);\n *\n * // Will log 'Function executed' after 1 second if not called again in that time\n * debouncedFunction();\n *\n * // Will not log anything as the previous call is canceled\n * debouncedFunction.cancel();\n *\n * // With AbortSignal\n * const controller = new AbortController();\n * const signal = controller.signal;\n * const debouncedWithSignal = debounce(() => {\n * console.log('Function executed');\n * }, 1000, { signal });\n *\n * debouncedWithSignal();\n *\n * // Will cancel the debounced function call\n * controller.abort();\n */\nexport function debounce<F extends (...args: any[]) => void>(\n func: F,\n debounceMs: number,\n { signal }: DebounceOptions = {}\n): F & { cancel: () => void } {\n let timeoutId: number | NodeJS.Timeout | null = null;\n\n const debounced = function (...args: Parameters<F>) {\n if (timeoutId !== null) {\n clearTimeout(timeoutId);\n }\n\n if (signal?.aborted) {\n return;\n }\n\n timeoutId = setTimeout(() => {\n func(...args);\n timeoutId = null;\n }, debounceMs);\n } as F & { cancel: () => void };\n\n const onAbort = function () {\n debounced.cancel();\n };\n\n debounced.cancel = function () {\n if (timeoutId !== null) {\n clearTimeout(timeoutId);\n timeoutId = null;\n }\n\n signal?.removeEventListener('abort', onAbort);\n };\n\n signal?.addEventListener('abort', onAbort);\n\n return debounced;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAsCO,SAAS,SACd,MACA,YACA,EAAE,OAAO,IAAqB,CAAC,GACH;AAC5B,MAAI,YAA4C;AAEhD,QAAM,YAAY,YAAa,MAAqB;AAClD,QAAI,cAAc,MAAM;AACtB,mBAAa,SAAS;AAAA,IACxB;AAEA,QAAI,iCAAQ,SAAS;AACnB;AAAA,IACF;AAEA,gBAAY,WAAW,MAAM;AAC3B,WAAK,GAAG,IAAI;AACZ,kBAAY;AAAA,IACd,GAAG,UAAU;AAAA,EACf;AAEA,QAAM,UAAU,WAAY;AAC1B,cAAU,OAAO;AAAA,EACnB;AAEA,YAAU,SAAS,WAAY;AAC7B,QAAI,cAAc,MAAM;AACtB,mBAAa,SAAS;AACtB,kBAAY;AAAA,IACd;AAEA,qCAAQ,oBAAoB,SAAS;AAAA,EACvC;AAEA,mCAAQ,iBAAiB,SAAS;AAElC,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/function/debounce.ts"],"sourcesContent":["interface DebounceOptions {\n signal?: AbortSignal;\n}\n\n/**\n * Creates a debounced function that delays invoking the provided function until after `debounceMs` milliseconds\n * have elapsed since the last time the debounced function was invoked. The debounced function also has a `cancel`\n * method to cancel any pending execution.\n *\n * @param {F} func - The function to debounce.\n * @param {number} debounceMs - The number of milliseconds to delay.\n * @param {DebounceOptions} options - The options object.\n * @param {AbortSignal} options.signal - An optional AbortSignal to cancel the debounced function.\n * @returns {F & { cancel: () => void }} A new debounced function with a `cancel` method.\n *\n * @example\n * const debouncedFunction = debounce(() => {\n * console.log('Function executed');\n * }, 1000);\n *\n * // Will log 'Function executed' after 1 second if not called again in that time\n * debouncedFunction();\n *\n * // Will not log anything as the previous call is canceled\n * debouncedFunction.cancel();\n *\n * // With AbortSignal\n * const controller = new AbortController();\n * const signal = controller.signal;\n * const debouncedWithSignal = debounce(() => {\n * console.log('Function executed');\n * }, 1000, { signal });\n *\n * debouncedWithSignal();\n *\n * // Will cancel the debounced function call\n * controller.abort();\n */\nexport function debounce<F extends (...args: any[]) => void>(\n func: F,\n debounceMs: number,\n { signal }: DebounceOptions = {}\n): F & { cancel: () => void } {\n let timeoutId: number | NodeJS.Timeout | null = null;\n\n const debounced = function (...args: Parameters<F>) {\n if (timeoutId !== null) {\n clearTimeout(timeoutId);\n }\n\n if (signal?.aborted) {\n return;\n }\n\n timeoutId = setTimeout(() => {\n func(...args);\n timeoutId = null;\n }, debounceMs);\n } as F & { cancel: () => void };\n\n const onAbort = function () {\n debounced.cancel();\n };\n\n debounced.cancel = function () {\n if (timeoutId !== null) {\n clearTimeout(timeoutId);\n timeoutId = null;\n }\n };\n\n signal?.addEventListener('abort', onAbort, { once: true });\n\n return debounced;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAsCO,SAAS,SACd,MACA,YACA,EAAE,OAAO,IAAqB,CAAC,GACH;AAC5B,MAAI,YAA4C;AAEhD,QAAM,YAAY,YAAa,MAAqB;AAClD,QAAI,cAAc,MAAM;AACtB,mBAAa,SAAS;AAAA,IACxB;AAEA,QAAI,iCAAQ,SAAS;AACnB;AAAA,IACF;AAEA,gBAAY,WAAW,MAAM;AAC3B,WAAK,GAAG,IAAI;AACZ,kBAAY;AAAA,IACd,GAAG,UAAU;AAAA,EACf;AAEA,QAAM,UAAU,WAAY;AAC1B,cAAU,OAAO;AAAA,EACnB;AAEA,YAAU,SAAS,WAAY;AAC7B,QAAI,cAAc,MAAM;AACtB,mBAAa,SAAS;AACtB,kBAAY;AAAA,IACd;AAAA,EACF;AAEA,mCAAQ,iBAAiB,SAAS,SAAS,EAAE,MAAM,KAAK;AAExD,SAAO;AACT;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  debounce
3
- } from "../chunk-GOXQV6DX.mjs";
3
+ } from "../chunk-MKETZ2RP.mjs";
4
4
  import "../chunk-2MM5EJJX.mjs";
5
5
  export {
6
6
  debounce
@@ -50,9 +50,8 @@ function debounce(func, debounceMs, { signal } = {}) {
50
50
  clearTimeout(timeoutId);
51
51
  timeoutId = null;
52
52
  }
53
- signal == null ? void 0 : signal.removeEventListener("abort", onAbort);
54
53
  };
55
- signal == null ? void 0 : signal.addEventListener("abort", onAbort);
54
+ signal == null ? void 0 : signal.addEventListener("abort", onAbort, { once: true });
56
55
  return debounced;
57
56
  }
58
57
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/function/index.ts","../../src/function/debounce.ts","../../src/function/noop.ts","../../src/function/once.ts","../../src/function/throttle.ts"],"sourcesContent":["export { debounce } from './debounce';\nexport { noop } from './noop';\nexport { once } from './once';\nexport { throttle } from './throttle';\n","interface DebounceOptions {\n signal?: AbortSignal;\n}\n\n/**\n * Creates a debounced function that delays invoking the provided function until after `debounceMs` milliseconds\n * have elapsed since the last time the debounced function was invoked. The debounced function also has a `cancel`\n * method to cancel any pending execution.\n *\n * @param {F} func - The function to debounce.\n * @param {number} debounceMs - The number of milliseconds to delay.\n * @param {DebounceOptions} options - The options object.\n * @param {AbortSignal} options.signal - An optional AbortSignal to cancel the debounced function.\n * @returns {F & { cancel: () => void }} A new debounced function with a `cancel` method.\n *\n * @example\n * const debouncedFunction = debounce(() => {\n * console.log('Function executed');\n * }, 1000);\n *\n * // Will log 'Function executed' after 1 second if not called again in that time\n * debouncedFunction();\n *\n * // Will not log anything as the previous call is canceled\n * debouncedFunction.cancel();\n *\n * // With AbortSignal\n * const controller = new AbortController();\n * const signal = controller.signal;\n * const debouncedWithSignal = debounce(() => {\n * console.log('Function executed');\n * }, 1000, { signal });\n *\n * debouncedWithSignal();\n *\n * // Will cancel the debounced function call\n * controller.abort();\n */\nexport function debounce<F extends (...args: any[]) => void>(\n func: F,\n debounceMs: number,\n { signal }: DebounceOptions = {}\n): F & { cancel: () => void } {\n let timeoutId: number | NodeJS.Timeout | null = null;\n\n const debounced = function (...args: Parameters<F>) {\n if (timeoutId !== null) {\n clearTimeout(timeoutId);\n }\n\n if (signal?.aborted) {\n return;\n }\n\n timeoutId = setTimeout(() => {\n func(...args);\n timeoutId = null;\n }, debounceMs);\n } as F & { cancel: () => void };\n\n const onAbort = function () {\n debounced.cancel();\n };\n\n debounced.cancel = function () {\n if (timeoutId !== null) {\n clearTimeout(timeoutId);\n timeoutId = null;\n }\n\n signal?.removeEventListener('abort', onAbort);\n };\n\n signal?.addEventListener('abort', onAbort);\n\n return debounced;\n}\n","/**\n * A no-operation function that does nothing.\n * This can be used as a placeholder or default function.\n *\n * @example\n * noop(); // Does nothing\n *\n * @returns {void} This function does not return anything.\n */\nexport function noop(): void {}\n","/**\n * Creates a function that is restricted to invoking the provided function `func` once.\n * Repeated calls to the function will return the value from the first invocation.\n *\n * @param {F} func - The function to restrict.\n * @returns {F} A new function that invokes `func` once and caches the result.\n *\n * @example\n * const initialize = once(() => {\n * console.log('Initialized!');\n * return true;\n * });\n *\n * initialize(); // Logs: 'Initialized!' and returns true\n * initialize(); // Returns true without logging\n */\nexport function once<F extends () => any>(func: F): F {\n let called = false;\n let cache: ReturnType<F> | undefined;\n\n return function () {\n if (called) {\n return cache;\n }\n\n const result = func();\n\n called = true;\n cache = result;\n\n return result;\n } as F;\n}\n","/**\n * Creates a throttled function that only invokes the provided function at most once\n * per every `throttleMs` milliseconds. Subsequent calls to the throttled function\n * within the wait time will not trigger the execution of the original function.\n *\n * @param {F} func - The function to throttle.\n * @param {number} throttleMs - The number of milliseconds to throttle executions to.\n * @returns {F} A new throttled function that accepts the same parameters as the original function.\n *\n * @example\n * const throttledFunction = throttle(() => {\n * console.log('Function executed');\n * }, 1000);\n *\n * // Will log 'Function executed' immediately\n * throttledFunction();\n *\n * // Will not log anything as it is within the throttle time\n * throttledFunction();\n *\n * // After 1 second\n * setTimeout(() => {\n * throttledFunction(); // Will log 'Function executed'\n * }, 1000);\n */\nexport function throttle<F extends (...args: any[]) => void>(func: F, throttleMs: number) {\n let lastCallTime: number | null;\n\n const throttledFunction = function (...args: Parameters<F>) {\n const now = Date.now();\n\n if (lastCallTime == null || now - lastCallTime >= throttleMs) {\n lastCallTime = now;\n func(...args);\n }\n } as F;\n\n return throttledFunction;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACsCO,SAAS,SACd,MACA,YACA,EAAE,OAAO,IAAqB,CAAC,GACH;AAC5B,MAAI,YAA4C;AAEhD,QAAM,YAAY,YAAa,MAAqB;AAClD,QAAI,cAAc,MAAM;AACtB,mBAAa,SAAS;AAAA,IACxB;AAEA,QAAI,iCAAQ,SAAS;AACnB;AAAA,IACF;AAEA,gBAAY,WAAW,MAAM;AAC3B,WAAK,GAAG,IAAI;AACZ,kBAAY;AAAA,IACd,GAAG,UAAU;AAAA,EACf;AAEA,QAAM,UAAU,WAAY;AAC1B,cAAU,OAAO;AAAA,EACnB;AAEA,YAAU,SAAS,WAAY;AAC7B,QAAI,cAAc,MAAM;AACtB,mBAAa,SAAS;AACtB,kBAAY;AAAA,IACd;AAEA,qCAAQ,oBAAoB,SAAS;AAAA,EACvC;AAEA,mCAAQ,iBAAiB,SAAS;AAElC,SAAO;AACT;;;ACnEO,SAAS,OAAa;AAAC;;;ACOvB,SAAS,KAA0B,MAAY;AACpD,MAAI,SAAS;AACb,MAAI;AAEJ,SAAO,WAAY;AACjB,QAAI,QAAQ;AACV,aAAO;AAAA,IACT;AAEA,UAAM,SAAS,KAAK;AAEpB,aAAS;AACT,YAAQ;AAER,WAAO;AAAA,EACT;AACF;;;ACPO,SAAS,SAA6C,MAAS,YAAoB;AACxF,MAAI;AAEJ,QAAM,oBAAoB,YAAa,MAAqB;AAC1D,UAAM,MAAM,KAAK,IAAI;AAErB,QAAI,gBAAgB,QAAQ,MAAM,gBAAgB,YAAY;AAC5D,qBAAe;AACf,WAAK,GAAG,IAAI;AAAA,IACd;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/function/index.ts","../../src/function/debounce.ts","../../src/function/noop.ts","../../src/function/once.ts","../../src/function/throttle.ts"],"sourcesContent":["export { debounce } from './debounce';\nexport { noop } from './noop';\nexport { once } from './once';\nexport { throttle } from './throttle';\n","interface DebounceOptions {\n signal?: AbortSignal;\n}\n\n/**\n * Creates a debounced function that delays invoking the provided function until after `debounceMs` milliseconds\n * have elapsed since the last time the debounced function was invoked. The debounced function also has a `cancel`\n * method to cancel any pending execution.\n *\n * @param {F} func - The function to debounce.\n * @param {number} debounceMs - The number of milliseconds to delay.\n * @param {DebounceOptions} options - The options object.\n * @param {AbortSignal} options.signal - An optional AbortSignal to cancel the debounced function.\n * @returns {F & { cancel: () => void }} A new debounced function with a `cancel` method.\n *\n * @example\n * const debouncedFunction = debounce(() => {\n * console.log('Function executed');\n * }, 1000);\n *\n * // Will log 'Function executed' after 1 second if not called again in that time\n * debouncedFunction();\n *\n * // Will not log anything as the previous call is canceled\n * debouncedFunction.cancel();\n *\n * // With AbortSignal\n * const controller = new AbortController();\n * const signal = controller.signal;\n * const debouncedWithSignal = debounce(() => {\n * console.log('Function executed');\n * }, 1000, { signal });\n *\n * debouncedWithSignal();\n *\n * // Will cancel the debounced function call\n * controller.abort();\n */\nexport function debounce<F extends (...args: any[]) => void>(\n func: F,\n debounceMs: number,\n { signal }: DebounceOptions = {}\n): F & { cancel: () => void } {\n let timeoutId: number | NodeJS.Timeout | null = null;\n\n const debounced = function (...args: Parameters<F>) {\n if (timeoutId !== null) {\n clearTimeout(timeoutId);\n }\n\n if (signal?.aborted) {\n return;\n }\n\n timeoutId = setTimeout(() => {\n func(...args);\n timeoutId = null;\n }, debounceMs);\n } as F & { cancel: () => void };\n\n const onAbort = function () {\n debounced.cancel();\n };\n\n debounced.cancel = function () {\n if (timeoutId !== null) {\n clearTimeout(timeoutId);\n timeoutId = null;\n }\n };\n\n signal?.addEventListener('abort', onAbort, { once: true });\n\n return debounced;\n}\n","/**\n * A no-operation function that does nothing.\n * This can be used as a placeholder or default function.\n *\n * @example\n * noop(); // Does nothing\n *\n * @returns {void} This function does not return anything.\n */\nexport function noop(): void {}\n","/**\n * Creates a function that is restricted to invoking the provided function `func` once.\n * Repeated calls to the function will return the value from the first invocation.\n *\n * @param {F} func - The function to restrict.\n * @returns {F} A new function that invokes `func` once and caches the result.\n *\n * @example\n * const initialize = once(() => {\n * console.log('Initialized!');\n * return true;\n * });\n *\n * initialize(); // Logs: 'Initialized!' and returns true\n * initialize(); // Returns true without logging\n */\nexport function once<F extends () => any>(func: F): F {\n let called = false;\n let cache: ReturnType<F> | undefined;\n\n return function () {\n if (called) {\n return cache;\n }\n\n const result = func();\n\n called = true;\n cache = result;\n\n return result;\n } as F;\n}\n","/**\n * Creates a throttled function that only invokes the provided function at most once\n * per every `throttleMs` milliseconds. Subsequent calls to the throttled function\n * within the wait time will not trigger the execution of the original function.\n *\n * @param {F} func - The function to throttle.\n * @param {number} throttleMs - The number of milliseconds to throttle executions to.\n * @returns {F} A new throttled function that accepts the same parameters as the original function.\n *\n * @example\n * const throttledFunction = throttle(() => {\n * console.log('Function executed');\n * }, 1000);\n *\n * // Will log 'Function executed' immediately\n * throttledFunction();\n *\n * // Will not log anything as it is within the throttle time\n * throttledFunction();\n *\n * // After 1 second\n * setTimeout(() => {\n * throttledFunction(); // Will log 'Function executed'\n * }, 1000);\n */\nexport function throttle<F extends (...args: any[]) => void>(func: F, throttleMs: number) {\n let lastCallTime: number | null;\n\n const throttledFunction = function (...args: Parameters<F>) {\n const now = Date.now();\n\n if (lastCallTime == null || now - lastCallTime >= throttleMs) {\n lastCallTime = now;\n func(...args);\n }\n } as F;\n\n return throttledFunction;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACsCO,SAAS,SACd,MACA,YACA,EAAE,OAAO,IAAqB,CAAC,GACH;AAC5B,MAAI,YAA4C;AAEhD,QAAM,YAAY,YAAa,MAAqB;AAClD,QAAI,cAAc,MAAM;AACtB,mBAAa,SAAS;AAAA,IACxB;AAEA,QAAI,iCAAQ,SAAS;AACnB;AAAA,IACF;AAEA,gBAAY,WAAW,MAAM;AAC3B,WAAK,GAAG,IAAI;AACZ,kBAAY;AAAA,IACd,GAAG,UAAU;AAAA,EACf;AAEA,QAAM,UAAU,WAAY;AAC1B,cAAU,OAAO;AAAA,EACnB;AAEA,YAAU,SAAS,WAAY;AAC7B,QAAI,cAAc,MAAM;AACtB,mBAAa,SAAS;AACtB,kBAAY;AAAA,IACd;AAAA,EACF;AAEA,mCAAQ,iBAAiB,SAAS,SAAS,EAAE,MAAM,KAAK;AAExD,SAAO;AACT;;;ACjEO,SAAS,OAAa;AAAC;;;ACOvB,SAAS,KAA0B,MAAY;AACpD,MAAI,SAAS;AACb,MAAI;AAEJ,SAAO,WAAY;AACjB,QAAI,QAAQ;AACV,aAAO;AAAA,IACT;AAEA,UAAM,SAAS,KAAK;AAEpB,aAAS;AACT,YAAQ;AAER,WAAO;AAAA,EACT;AACF;;;ACPO,SAAS,SAA6C,MAAS,YAAoB;AACxF,MAAI;AAEJ,QAAM,oBAAoB,YAAa,MAAqB;AAC1D,UAAM,MAAM,KAAK,IAAI;AAErB,QAAI,gBAAgB,QAAQ,MAAM,gBAAgB,YAAY;AAC5D,qBAAe;AACf,WAAK,GAAG,IAAI;AAAA,IACd;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -1,16 +1,16 @@
1
1
  import "../chunk-N6EM6ETS.mjs";
2
- import {
3
- throttle
4
- } from "../chunk-XLO3QZVY.mjs";
5
2
  import {
6
3
  debounce
7
- } from "../chunk-GOXQV6DX.mjs";
4
+ } from "../chunk-MKETZ2RP.mjs";
8
5
  import {
9
6
  noop
10
7
  } from "../chunk-LKXCOLNY.mjs";
11
8
  import {
12
9
  once
13
10
  } from "../chunk-UFAA5WKR.mjs";
11
+ import {
12
+ throttle
13
+ } from "../chunk-XLO3QZVY.mjs";
14
14
  import "../chunk-2MM5EJJX.mjs";
15
15
  export {
16
16
  debounce,
package/dist/index.d.mts CHANGED
@@ -28,11 +28,13 @@ export { xorBy } from './array/xorBy.mjs';
28
28
  export { xorWith } from './array/xorWith.mjs';
29
29
  export { zip } from './array/zip.mjs';
30
30
  export { zipWith } from './array/zipWith.mjs';
31
+ export { AbortError } from './error/AbortError.mjs';
31
32
  export { debounce } from './function/debounce.mjs';
32
33
  export { noop } from './function/noop.mjs';
33
34
  export { once } from './function/once.mjs';
34
35
  export { throttle } from './function/throttle.mjs';
35
36
  export { clamp } from './math/clamp.mjs';
37
+ export { random } from './math/random.mjs';
36
38
  export { round } from './math/round.mjs';
37
39
  export { sum } from './math/sum.mjs';
38
40
  export { omit } from './object/omit.mjs';
package/dist/index.d.ts CHANGED
@@ -28,11 +28,13 @@ export { xorBy } from './array/xorBy.js';
28
28
  export { xorWith } from './array/xorWith.js';
29
29
  export { zip } from './array/zip.js';
30
30
  export { zipWith } from './array/zipWith.js';
31
+ export { AbortError } from './error/AbortError.js';
31
32
  export { debounce } from './function/debounce.js';
32
33
  export { noop } from './function/noop.js';
33
34
  export { once } from './function/once.js';
34
35
  export { throttle } from './function/throttle.js';
35
36
  export { clamp } from './math/clamp.js';
37
+ export { random } from './math/random.js';
36
38
  export { round } from './math/round.js';
37
39
  export { sum } from './math/sum.js';
38
40
  export { omit } from './object/omit.js';
package/dist/index.js CHANGED
@@ -34,6 +34,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
34
34
  // src/index.ts
35
35
  var src_exports = {};
36
36
  __export(src_exports, {
37
+ AbortError: () => AbortError,
37
38
  chunk: () => chunk,
38
39
  clamp: () => clamp,
39
40
  debounce: () => debounce,
@@ -60,6 +61,7 @@ __export(src_exports, {
60
61
  partition: () => partition,
61
62
  pick: () => pick,
62
63
  pickBy: () => pickBy,
64
+ random: () => random,
63
65
  round: () => round,
64
66
  sample: () => sample,
65
67
  shuffle: () => shuffle,
@@ -338,6 +340,14 @@ function zipWith(arr1, ...rest) {
338
340
  return result;
339
341
  }
340
342
 
343
+ // src/error/AbortError.ts
344
+ var AbortError = class extends Error {
345
+ constructor(message = "The operation was aborted") {
346
+ super(message);
347
+ this.name = "AbortError";
348
+ }
349
+ };
350
+
341
351
  // src/function/debounce.ts
342
352
  function debounce(func, debounceMs, { signal } = {}) {
343
353
  let timeoutId = null;
@@ -361,9 +371,8 @@ function debounce(func, debounceMs, { signal } = {}) {
361
371
  clearTimeout(timeoutId);
362
372
  timeoutId = null;
363
373
  }
364
- signal == null ? void 0 : signal.removeEventListener("abort", onAbort);
365
374
  };
366
- signal == null ? void 0 : signal.addEventListener("abort", onAbort);
375
+ signal == null ? void 0 : signal.addEventListener("abort", onAbort, { once: true });
367
376
  return debounced;
368
377
  }
369
378
 
@@ -407,6 +416,14 @@ function clamp(value, bound1, bound2) {
407
416
  return Math.min(Math.max(value, bound1), bound2);
408
417
  }
409
418
 
419
+ // src/math/random.ts
420
+ function random(minimum, maximum) {
421
+ if (minimum >= maximum) {
422
+ throw new Error("Invalid input: The maximum value must be greater than the minimum value.");
423
+ }
424
+ return Math.random() * (maximum - minimum) + minimum;
425
+ }
426
+
410
427
  // src/math/round.ts
411
428
  function round(value, precision = 0) {
412
429
  const multiplier = Math.pow(10, precision);
@@ -485,13 +502,25 @@ function isUndefined(x) {
485
502
  }
486
503
 
487
504
  // src/promise/delay.ts
488
- function delay(ms) {
489
- return new Promise((resolve) => {
490
- setTimeout(resolve, ms);
505
+ function delay(ms, { signal } = {}) {
506
+ return new Promise((resolve, reject) => {
507
+ const abortError = () => {
508
+ reject(new AbortError());
509
+ };
510
+ const abortHandler = () => {
511
+ clearTimeout(timeoutId);
512
+ abortError();
513
+ };
514
+ if (signal == null ? void 0 : signal.aborted) {
515
+ return abortError();
516
+ }
517
+ const timeoutId = setTimeout(resolve, ms);
518
+ signal == null ? void 0 : signal.addEventListener("abort", abortHandler, { once: true });
491
519
  });
492
520
  }
493
521
  // Annotate the CommonJS export names for ESM import in node:
494
522
  0 && (module.exports = {
523
+ AbortError,
495
524
  chunk,
496
525
  clamp,
497
526
  debounce,
@@ -518,6 +547,7 @@ function delay(ms) {
518
547
  partition,
519
548
  pick,
520
549
  pickBy,
550
+ random,
521
551
  round,
522
552
  sample,
523
553
  shuffle,