es-toolkit 1.3.1 → 1.4.0-dev.100

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 (178) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/array/difference.d.mts +1 -1
  3. package/dist/array/difference.d.ts +1 -1
  4. package/dist/array/difference.js.map +1 -1
  5. package/dist/array/difference.mjs +1 -1
  6. package/dist/array/differenceWith.js.map +1 -1
  7. package/dist/array/differenceWith.mjs +1 -1
  8. package/dist/array/dropRightWhile.js.map +1 -1
  9. package/dist/array/dropRightWhile.mjs +2 -2
  10. package/dist/array/dropWhile.js.map +1 -1
  11. package/dist/array/dropWhile.mjs +1 -1
  12. package/dist/array/index.js +9 -2
  13. package/dist/array/index.js.map +1 -1
  14. package/dist/array/index.mjs +13 -13
  15. package/dist/array/intersectionWith.js.map +1 -1
  16. package/dist/array/intersectionWith.mjs +1 -1
  17. package/dist/array/unionBy.js +1 -1
  18. package/dist/array/unionBy.js.map +1 -1
  19. package/dist/array/unionBy.mjs +1 -1
  20. package/dist/array/unionWith.js.map +1 -1
  21. package/dist/array/unionWith.mjs +1 -1
  22. package/dist/array/uniqBy.js +6 -13
  23. package/dist/array/uniqBy.js.map +1 -1
  24. package/dist/array/uniqBy.mjs +1 -2
  25. package/dist/array/xor.js.map +1 -1
  26. package/dist/array/xor.mjs +2 -2
  27. package/dist/array/xorBy.js +1 -1
  28. package/dist/array/xorBy.js.map +1 -1
  29. package/dist/array/xorBy.mjs +2 -2
  30. package/dist/array/xorWith.js.map +1 -1
  31. package/dist/array/xorWith.mjs +4 -4
  32. package/dist/array/zip.js.map +1 -1
  33. package/dist/array/zip.mjs +1 -1
  34. package/dist/array/zipWith.js.map +1 -1
  35. package/dist/array/zipWith.mjs +1 -1
  36. package/dist/{chunk-KLJRZJOR.mjs → chunk-2EFS3VA3.mjs} +1 -1
  37. package/dist/{chunk-KLJRZJOR.mjs.map → chunk-2EFS3VA3.mjs.map} +1 -1
  38. package/dist/{chunk-T5FDOBCA.mjs → chunk-4KYXHZ4R.mjs} +1 -1
  39. package/dist/{chunk-T5FDOBCA.mjs.map → chunk-4KYXHZ4R.mjs.map} +1 -1
  40. package/dist/{chunk-V7E5DGZP.mjs → chunk-5PMKOZ2F.mjs} +4 -1
  41. package/dist/chunk-5PMKOZ2F.mjs.map +1 -0
  42. package/dist/chunk-5UT77WON.mjs +13 -0
  43. package/dist/chunk-5UT77WON.mjs.map +1 -0
  44. package/dist/{chunk-3KHI4I2X.mjs → chunk-642SWVKJ.mjs} +1 -1
  45. package/dist/{chunk-3KHI4I2X.mjs.map → chunk-642SWVKJ.mjs.map} +1 -1
  46. package/dist/chunk-6E6PBLFK.mjs +18 -0
  47. package/dist/chunk-6E6PBLFK.mjs.map +1 -0
  48. package/dist/{chunk-FQ4K36VD.mjs → chunk-6NVQAHXP.mjs} +1 -1
  49. package/dist/{chunk-FQ4K36VD.mjs.map → chunk-6NVQAHXP.mjs.map} +1 -1
  50. package/dist/{chunk-SF3V7XXM.mjs → chunk-A67NF2C7.mjs} +1 -1
  51. package/dist/chunk-A67NF2C7.mjs.map +1 -0
  52. package/dist/chunk-AL3GJBEI.mjs +26 -0
  53. package/dist/chunk-AL3GJBEI.mjs.map +1 -0
  54. package/dist/{chunk-EW3RT4QW.mjs → chunk-AM2EGFCU.mjs} +2 -2
  55. package/dist/chunk-FZEZH22H.mjs +1 -0
  56. package/dist/{chunk-WXIBCOES.mjs → chunk-G2TTBLLJ.mjs} +2 -2
  57. package/dist/{chunk-DD73BULA.mjs → chunk-IDCUZVJL.mjs} +1 -1
  58. package/dist/{chunk-DD73BULA.mjs.map → chunk-IDCUZVJL.mjs.map} +1 -1
  59. package/dist/{chunk-M7UI5ETO.mjs → chunk-JPUKH67K.mjs} +1 -1
  60. package/dist/{chunk-M7UI5ETO.mjs.map → chunk-JPUKH67K.mjs.map} +1 -1
  61. package/dist/chunk-JQUZTDPN.mjs +24 -0
  62. package/dist/chunk-JQUZTDPN.mjs.map +1 -0
  63. package/dist/{chunk-JFHM6EY2.mjs → chunk-K2BAFL2T.mjs} +1 -1
  64. package/dist/{chunk-JFHM6EY2.mjs.map → chunk-K2BAFL2T.mjs.map} +1 -1
  65. package/dist/chunk-LCP6FOCX.mjs +12 -0
  66. package/dist/chunk-LCP6FOCX.mjs.map +1 -0
  67. package/dist/{chunk-GOXQV6DX.mjs → chunk-MKETZ2RP.mjs} +2 -3
  68. package/dist/{chunk-GOXQV6DX.mjs.map → chunk-MKETZ2RP.mjs.map} +1 -1
  69. package/dist/{chunk-T2C2WVFL.mjs → chunk-MQWVBKUT.mjs} +1 -1
  70. package/dist/chunk-MQWVBKUT.mjs.map +1 -0
  71. package/dist/{chunk-JBDGK6X4.mjs → chunk-NRNKP6JF.mjs} +2 -2
  72. package/dist/{chunk-JBDGK6X4.mjs.map → chunk-NRNKP6JF.mjs.map} +1 -1
  73. package/dist/{chunk-CIRFWC7Y.mjs → chunk-RNJM5BHX.mjs} +2 -2
  74. package/dist/chunk-SAL5OUAE.mjs +18 -0
  75. package/dist/chunk-SAL5OUAE.mjs.map +1 -0
  76. package/dist/chunk-TZE6EDCX.mjs +1 -0
  77. package/dist/chunk-TZE6EDCX.mjs.map +1 -0
  78. package/dist/{chunk-FCF2RHPW.mjs → chunk-UMDNWTJC.mjs} +4 -4
  79. package/dist/{chunk-FCF2RHPW.mjs.map → chunk-UMDNWTJC.mjs.map} +1 -1
  80. package/dist/chunk-VP2LXY75.mjs +12 -0
  81. package/dist/chunk-VP2LXY75.mjs.map +1 -0
  82. package/dist/chunk-WPDDOUQT.mjs +16 -0
  83. package/dist/chunk-WPDDOUQT.mjs.map +1 -0
  84. package/dist/error/AbortError.d.mts +5 -0
  85. package/dist/error/AbortError.d.ts +5 -0
  86. package/dist/error/AbortError.js +36 -0
  87. package/dist/error/AbortError.js.map +1 -0
  88. package/dist/error/AbortError.mjs +8 -0
  89. package/dist/error/AbortError.mjs.map +1 -0
  90. package/dist/error/index.d.mts +1 -0
  91. package/dist/error/index.d.ts +1 -0
  92. package/dist/error/index.js +38 -0
  93. package/dist/error/index.js.map +1 -0
  94. package/dist/error/index.mjs +9 -0
  95. package/dist/error/index.mjs.map +1 -0
  96. package/dist/function/debounce.js +1 -2
  97. package/dist/function/debounce.js.map +1 -1
  98. package/dist/function/debounce.mjs +1 -1
  99. package/dist/function/index.js +1 -2
  100. package/dist/function/index.js.map +1 -1
  101. package/dist/function/index.mjs +4 -4
  102. package/dist/index.d.mts +6 -0
  103. package/dist/index.d.ts +6 -0
  104. package/dist/index.js +108 -7
  105. package/dist/index.js.map +1 -1
  106. package/dist/index.mjs +52 -27
  107. package/dist/math/index.d.mts +5 -0
  108. package/dist/math/index.d.ts +5 -0
  109. package/dist/math/index.js +74 -0
  110. package/dist/math/index.js.map +1 -1
  111. package/dist/math/index.mjs +24 -4
  112. package/dist/math/maxBy.d.mts +21 -0
  113. package/dist/math/maxBy.d.ts +21 -0
  114. package/dist/math/maxBy.js +42 -0
  115. package/dist/math/maxBy.js.map +1 -0
  116. package/dist/math/maxBy.mjs +8 -0
  117. package/dist/math/maxBy.mjs.map +1 -0
  118. package/dist/math/minBy.d.mts +13 -0
  119. package/dist/math/minBy.d.ts +13 -0
  120. package/dist/math/minBy.js +42 -0
  121. package/dist/math/minBy.js.map +1 -0
  122. package/dist/math/minBy.mjs +8 -0
  123. package/dist/math/minBy.mjs.map +1 -0
  124. package/dist/math/random.d.mts +16 -0
  125. package/dist/math/random.d.ts +16 -0
  126. package/dist/math/random.js +36 -0
  127. package/dist/math/random.js.map +1 -0
  128. package/dist/math/random.mjs +8 -0
  129. package/dist/math/random.mjs.map +1 -0
  130. package/dist/math/randomInt.d.mts +15 -0
  131. package/dist/math/randomInt.d.ts +15 -0
  132. package/dist/math/randomInt.js +43 -0
  133. package/dist/math/randomInt.js.map +1 -0
  134. package/dist/math/randomInt.mjs +9 -0
  135. package/dist/math/randomInt.mjs.map +1 -0
  136. package/dist/math/range.d.mts +32 -0
  137. package/dist/math/range.d.ts +32 -0
  138. package/dist/math/range.js +48 -0
  139. package/dist/math/range.js.map +1 -0
  140. package/dist/math/range.mjs +8 -0
  141. package/dist/math/range.mjs.map +1 -0
  142. package/dist/math/round.d.mts +2 -0
  143. package/dist/math/round.d.ts +2 -0
  144. package/dist/math/round.js +3 -0
  145. package/dist/math/round.js.map +1 -1
  146. package/dist/math/round.mjs +1 -1
  147. package/dist/object/index.js.map +1 -1
  148. package/dist/object/index.mjs +2 -2
  149. package/dist/object/omitBy.d.mts +2 -2
  150. package/dist/object/omitBy.d.ts +2 -2
  151. package/dist/object/omitBy.js.map +1 -1
  152. package/dist/object/omitBy.mjs +1 -1
  153. package/dist/object/pickBy.d.mts +2 -2
  154. package/dist/object/pickBy.d.ts +2 -2
  155. package/dist/object/pickBy.js.map +1 -1
  156. package/dist/object/pickBy.mjs +1 -1
  157. package/dist/predicate/index.mjs +3 -3
  158. package/dist/promise/delay.d.mts +18 -1
  159. package/dist/promise/delay.d.ts +18 -1
  160. package/dist/promise/delay.js +24 -3
  161. package/dist/promise/delay.js.map +1 -1
  162. package/dist/promise/delay.mjs +2 -1
  163. package/dist/promise/index.js +22 -3
  164. package/dist/promise/index.js.map +1 -1
  165. package/dist/promise/index.mjs +2 -1
  166. package/package.json +3 -1
  167. package/dist/chunk-ASFOKYTY.mjs +0 -13
  168. package/dist/chunk-ASFOKYTY.mjs.map +0 -1
  169. package/dist/chunk-IJLQVGW4.mjs +0 -1
  170. package/dist/chunk-SF3V7XXM.mjs.map +0 -1
  171. package/dist/chunk-T2C2WVFL.mjs.map +0 -1
  172. package/dist/chunk-V7E5DGZP.mjs.map +0 -1
  173. package/dist/chunk-ZBG3EYM3.mjs +0 -11
  174. package/dist/chunk-ZBG3EYM3.mjs.map +0 -1
  175. /package/dist/{chunk-EW3RT4QW.mjs.map → chunk-AM2EGFCU.mjs.map} +0 -0
  176. /package/dist/{chunk-IJLQVGW4.mjs.map → chunk-FZEZH22H.mjs.map} +0 -0
  177. /package/dist/{chunk-WXIBCOES.mjs.map → chunk-G2TTBLLJ.mjs.map} +0 -0
  178. /package/dist/{chunk-CIRFWC7Y.mjs.map → chunk-RNJM5BHX.mjs.map} +0 -0
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  dropWhile
3
- } from "./chunk-JFHM6EY2.mjs";
3
+ } from "./chunk-K2BAFL2T.mjs";
4
4
 
5
5
  // src/array/dropRightWhile.ts
6
6
  function dropRightWhile(arr, canContinueDropping) {
@@ -12,4 +12,4 @@ function dropRightWhile(arr, canContinueDropping) {
12
12
  export {
13
13
  dropRightWhile
14
14
  };
15
- //# sourceMappingURL=chunk-CIRFWC7Y.mjs.map
15
+ //# sourceMappingURL=chunk-RNJM5BHX.mjs.map
@@ -0,0 +1,18 @@
1
+ // src/math/minBy.ts
2
+ function minBy(elements, selector) {
3
+ let minElement = elements[0];
4
+ let min = Infinity;
5
+ for (const element of elements) {
6
+ const value = selector(element);
7
+ if (value < min) {
8
+ min = value;
9
+ minElement = element;
10
+ }
11
+ }
12
+ return minElement;
13
+ }
14
+
15
+ export {
16
+ minBy
17
+ };
18
+ //# sourceMappingURL=chunk-SAL5OUAE.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/math/minBy.ts"],"sourcesContent":["/**\n * Returns the minimum value in an array of numbers.\n *\n * This function takes an array of elements and a selector function, and returns the element with the minimum value according to the selector.\n *\n * If the array is empty, the function returns `undefined`.\n *\n * @param elements An array of elements.\n * @param selector A function that selects a number from an element.\n */\nexport function minBy<T>(elements: T[], selector: (element: T) => number): T {\n let minElement = elements[0];\n let min = Infinity;\n\n for (const element of elements) {\n const value = selector(element);\n if (value < min) {\n min = value;\n minElement = element;\n }\n }\n\n return minElement;\n}\n"],"mappings":";AAUO,SAAS,MAAS,UAAe,UAAqC;AAC3E,MAAI,aAAa,SAAS,CAAC;AAC3B,MAAI,MAAM;AAEV,aAAW,WAAW,UAAU;AAC9B,UAAM,QAAQ,SAAS,OAAO;AAC9B,QAAI,QAAQ,KAAK;AACf,YAAM;AACN,mBAAa;AAAA,IACf;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-TZE6EDCX.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  unionWith
3
- } from "./chunk-3KHI4I2X.mjs";
3
+ } from "./chunk-642SWVKJ.mjs";
4
4
  import {
5
5
  intersectionWith
6
- } from "./chunk-KLJRZJOR.mjs";
6
+ } from "./chunk-2EFS3VA3.mjs";
7
7
  import {
8
8
  differenceWith
9
- } from "./chunk-FQ4K36VD.mjs";
9
+ } from "./chunk-6NVQAHXP.mjs";
10
10
 
11
11
  // src/array/xorWith.ts
12
12
  function xorWith(arr1, arr2, areElementsEqual) {
@@ -18,4 +18,4 @@ function xorWith(arr1, arr2, areElementsEqual) {
18
18
  export {
19
19
  xorWith
20
20
  };
21
- //# sourceMappingURL=chunk-FCF2RHPW.mjs.map
21
+ //# sourceMappingURL=chunk-UMDNWTJC.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/array/xorWith.ts"],"sourcesContent":["import { differenceWith } from './differenceWith';\nimport { intersectionWith } from './intersectionWith';\nimport { unionWith } from './unionWith';\n\n/**\n * Computes the symmetric difference between two arrays using a custom equality function.\n * The symmetric difference is the set of elements which are in either of the arrays,\n * but not in their intersection.\n *\n * @template T - Type of elements in the input arrays.\n *\n * @param {T[]} arr1 - The first array.\n * @param {T[]} arr2 - The second array.\n * @param {(item1: T, item2: T) => boolean} areElementsEqual - The custom equality function to compare elements.\n * @returns {T[]} An array containing the elements that are present in either `arr1` or `arr2` but not in both, based on the custom equality function.\n *\n * @example\n * // Custom equality function for objects with an 'id' property\n * const areObjectsEqual = (a, b) => a.id === b.id;\n * xorWith([{ id: 1 }, { id: 2 }], [{ id: 2 }, { id: 3 }], areObjectsEqual);\n * // Returns [{ id: 1 }, { id: 3 }]\n */\nexport function xorWith<T>(arr1: readonly T[], arr2: readonly T[], areElementsEqual: (item1: T, item2: T) => boolean): T[] {\n const union = unionWith(arr1, arr2, areElementsEqual);\n const intersection = intersectionWith(arr1, arr2, areElementsEqual);\n\n return differenceWith(union, intersection, areElementsEqual);\n}\n"],"mappings":";;;;;;;;;;;AAsBO,SAAS,QAAW,MAAoB,MAAoB,kBAAwD;AACzH,QAAM,QAAQ,UAAU,MAAM,MAAM,gBAAgB;AACpD,QAAM,eAAe,iBAAiB,MAAM,MAAM,gBAAgB;AAElE,SAAO,eAAe,OAAO,cAAc,gBAAgB;AAC7D;","names":[]}
1
+ {"version":3,"sources":["../src/array/xorWith.ts"],"sourcesContent":["import { differenceWith } from './differenceWith';\nimport { intersectionWith } from './intersectionWith';\nimport { unionWith } from './unionWith';\n\n/**\n * Computes the symmetric difference between two arrays using a custom equality function.\n * The symmetric difference is the set of elements which are in either of the arrays,\n * but not in their intersection.\n *\n * @template T - Type of elements in the input arrays.\n *\n * @param {T[]} arr1 - The first array.\n * @param {T[]} arr2 - The second array.\n * @param {(item1: T, item2: T) => boolean} areElementsEqual - The custom equality function to compare elements.\n * @returns {T[]} An array containing the elements that are present in either `arr1` or `arr2` but not in both, based on the custom equality function.\n *\n * @example\n * // Custom equality function for objects with an 'id' property\n * const areObjectsEqual = (a, b) => a.id === b.id;\n * xorWith([{ id: 1 }, { id: 2 }], [{ id: 2 }, { id: 3 }], areObjectsEqual);\n * // Returns [{ id: 1 }, { id: 3 }]\n */\nexport function xorWith<T>(\n arr1: readonly T[],\n arr2: readonly T[],\n areElementsEqual: (item1: T, item2: T) => boolean\n): T[] {\n const union = unionWith(arr1, arr2, areElementsEqual);\n const intersection = intersectionWith(arr1, arr2, areElementsEqual);\n\n return differenceWith(union, intersection, areElementsEqual);\n}\n"],"mappings":";;;;;;;;;;;AAsBO,SAAS,QACd,MACA,MACA,kBACK;AACL,QAAM,QAAQ,UAAU,MAAM,MAAM,gBAAgB;AACpD,QAAM,eAAe,iBAAiB,MAAM,MAAM,gBAAgB;AAElE,SAAO,eAAe,OAAO,cAAc,gBAAgB;AAC7D;","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,16 @@
1
+ // src/array/uniqBy.ts
2
+ function uniqBy(arr, mapper) {
3
+ const map = /* @__PURE__ */ new Map();
4
+ for (const item of arr) {
5
+ const key = mapper(item);
6
+ if (!map.has(key)) {
7
+ map.set(key, item);
8
+ }
9
+ }
10
+ return Array.from(map.values());
11
+ }
12
+
13
+ export {
14
+ uniqBy
15
+ };
16
+ //# sourceMappingURL=chunk-WPDDOUQT.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/array/uniqBy.ts"],"sourcesContent":["/**\n * Returns a new array containing only the unique elements from the original array,\n * based on the values returned by the mapper function.\n *\n * @param {T[]} arr - The array to process.\n * @param {(item: T) => U} mapper - The function used to convert the array elements.\n * @returns {T[]} A new array containing only the unique elements from the original array, based on the values returned by the mapper function.\n *\n * @example\n * ```ts\n * uniqBy([1.2, 1.5, 2.1, 3.2, 5.7, 5.3, 7.19], Math.floor);\n * // [1.2, 2.1, 3.3, 5.7, 7.19]\n * ```\n */\nexport function uniqBy<T, U>(arr: readonly T[], mapper: (item: T) => U): T[] {\n const map = new Map<U, T>();\n\n for (const item of arr) {\n const key = mapper(item);\n\n if (!map.has(key)) {\n map.set(key, item);\n }\n }\n\n return Array.from(map.values());\n}\n"],"mappings":";AAcO,SAAS,OAAa,KAAmB,QAA6B;AAC3E,QAAM,MAAM,oBAAI,IAAU;AAE1B,aAAW,QAAQ,KAAK;AACtB,UAAM,MAAM,OAAO,IAAI;AAEvB,QAAI,CAAC,IAAI,IAAI,GAAG,GAAG;AACjB,UAAI,IAAI,KAAK,IAAI;AAAA,IACnB;AAAA,EACF;AAEA,SAAO,MAAM,KAAK,IAAI,OAAO,CAAC;AAChC;","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,13 +28,19 @@ 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';
38
+ export { randomInt } from './math/randomInt.mjs';
36
39
  export { round } from './math/round.mjs';
37
40
  export { sum } from './math/sum.mjs';
41
+ export { maxBy } from './math/maxBy.mjs';
42
+ export { minBy } from './math/minBy.mjs';
43
+ export { range } from './math/range.mjs';
38
44
  export { omit } from './object/omit.mjs';
39
45
  export { omitBy } from './object/omitBy.mjs';
40
46
  export { pick } from './object/pick.mjs';
package/dist/index.d.ts CHANGED
@@ -28,13 +28,19 @@ 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';
38
+ export { randomInt } from './math/randomInt.js';
36
39
  export { round } from './math/round.js';
37
40
  export { sum } from './math/sum.js';
41
+ export { maxBy } from './math/maxBy.js';
42
+ export { minBy } from './math/minBy.js';
43
+ export { range } from './math/range.js';
38
44
  export { omit } from './object/omit.js';
39
45
  export { omitBy } from './object/omitBy.js';
40
46
  export { pick } from './object/pick.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,
@@ -53,6 +54,8 @@ __export(src_exports, {
53
54
  isNotNil: () => isNotNil,
54
55
  isNull: () => isNull,
55
56
  isUndefined: () => isUndefined,
57
+ maxBy: () => maxBy,
58
+ minBy: () => minBy,
56
59
  noop: () => noop,
57
60
  omit: () => omit,
58
61
  omitBy: () => omitBy,
@@ -60,6 +63,9 @@ __export(src_exports, {
60
63
  partition: () => partition,
61
64
  pick: () => pick,
62
65
  pickBy: () => pickBy,
66
+ random: () => random,
67
+ randomInt: () => randomInt,
68
+ range: () => range,
63
69
  round: () => round,
64
70
  sample: () => sample,
65
71
  shuffle: () => shuffle,
@@ -267,7 +273,7 @@ function unionBy(arr1, arr2, mapper) {
267
273
  map.set(key, item);
268
274
  }
269
275
  }
270
- return [...map.values()];
276
+ return Array.from(map.values());
271
277
  }
272
278
 
273
279
  // src/array/uniqWith.ts
@@ -289,7 +295,14 @@ function unionWith(arr1, arr2, areItemsEqual) {
289
295
 
290
296
  // src/array/uniqBy.ts
291
297
  function uniqBy(arr, mapper) {
292
- return uniqWith(arr, (item1, item2) => mapper(item1) === mapper(item2));
298
+ const map = /* @__PURE__ */ new Map();
299
+ for (const item of arr) {
300
+ const key = mapper(item);
301
+ if (!map.has(key)) {
302
+ map.set(key, item);
303
+ }
304
+ }
305
+ return Array.from(map.values());
293
306
  }
294
307
 
295
308
  // src/array/xor.ts
@@ -338,6 +351,14 @@ function zipWith(arr1, ...rest) {
338
351
  return result;
339
352
  }
340
353
 
354
+ // src/error/AbortError.ts
355
+ var AbortError = class extends Error {
356
+ constructor(message = "The operation was aborted") {
357
+ super(message);
358
+ this.name = "AbortError";
359
+ }
360
+ };
361
+
341
362
  // src/function/debounce.ts
342
363
  function debounce(func, debounceMs, { signal } = {}) {
343
364
  let timeoutId = null;
@@ -361,9 +382,8 @@ function debounce(func, debounceMs, { signal } = {}) {
361
382
  clearTimeout(timeoutId);
362
383
  timeoutId = null;
363
384
  }
364
- signal == null ? void 0 : signal.removeEventListener("abort", onAbort);
365
385
  };
366
- signal == null ? void 0 : signal.addEventListener("abort", onAbort);
386
+ signal == null ? void 0 : signal.addEventListener("abort", onAbort, { once: true });
367
387
  return debounced;
368
388
  }
369
389
 
@@ -407,8 +427,24 @@ function clamp(value, bound1, bound2) {
407
427
  return Math.min(Math.max(value, bound1), bound2);
408
428
  }
409
429
 
430
+ // src/math/random.ts
431
+ function random(minimum, maximum) {
432
+ if (minimum >= maximum) {
433
+ throw new Error("Invalid input: The maximum value must be greater than the minimum value.");
434
+ }
435
+ return Math.random() * (maximum - minimum) + minimum;
436
+ }
437
+
438
+ // src/math/randomInt.ts
439
+ function randomInt(minimum, maximum) {
440
+ return Math.floor(random(minimum, maximum));
441
+ }
442
+
410
443
  // src/math/round.ts
411
444
  function round(value, precision = 0) {
445
+ if (!Number.isInteger(precision)) {
446
+ throw new Error("Precision must be an integer.");
447
+ }
412
448
  const multiplier = Math.pow(10, precision);
413
449
  return Math.round(value * multiplier) / multiplier;
414
450
  }
@@ -422,6 +458,54 @@ function sum(nums) {
422
458
  return result;
423
459
  }
424
460
 
461
+ // src/math/maxBy.ts
462
+ function maxBy(elements, selector) {
463
+ let maxElement = elements[0];
464
+ let max = -Infinity;
465
+ for (const element of elements) {
466
+ const value = selector(element);
467
+ if (value > max) {
468
+ max = value;
469
+ maxElement = element;
470
+ }
471
+ }
472
+ return maxElement;
473
+ }
474
+
475
+ // src/math/minBy.ts
476
+ function minBy(elements, selector) {
477
+ let minElement = elements[0];
478
+ let min = Infinity;
479
+ for (const element of elements) {
480
+ const value = selector(element);
481
+ if (value < min) {
482
+ min = value;
483
+ minElement = element;
484
+ }
485
+ }
486
+ return minElement;
487
+ }
488
+
489
+ // src/math/range.ts
490
+ function range(start, end, step) {
491
+ if (end == null) {
492
+ end = start;
493
+ start = 0;
494
+ }
495
+ if (step == null) {
496
+ step = 1;
497
+ }
498
+ if (!Number.isInteger(step) || step === 0) {
499
+ throw new Error(`The step value must be a non-zero integer.`);
500
+ }
501
+ const length = Math.max(Math.ceil((end - start) / (step || 1)), 0);
502
+ const result = new Array(length);
503
+ for (let i = 0; i < length; i++) {
504
+ result[i] = start + i * step;
505
+ }
506
+ return result;
507
+ }
508
+
425
509
  // src/object/omit.ts
426
510
  function omit(obj, keys) {
427
511
  const result = __spreadValues({}, obj);
@@ -485,13 +569,25 @@ function isUndefined(x) {
485
569
  }
486
570
 
487
571
  // src/promise/delay.ts
488
- function delay(ms) {
489
- return new Promise((resolve) => {
490
- setTimeout(resolve, ms);
572
+ function delay(ms, { signal } = {}) {
573
+ return new Promise((resolve, reject) => {
574
+ const abortError = () => {
575
+ reject(new AbortError());
576
+ };
577
+ const abortHandler = () => {
578
+ clearTimeout(timeoutId);
579
+ abortError();
580
+ };
581
+ if (signal == null ? void 0 : signal.aborted) {
582
+ return abortError();
583
+ }
584
+ const timeoutId = setTimeout(resolve, ms);
585
+ signal == null ? void 0 : signal.addEventListener("abort", abortHandler, { once: true });
491
586
  });
492
587
  }
493
588
  // Annotate the CommonJS export names for ESM import in node:
494
589
  0 && (module.exports = {
590
+ AbortError,
495
591
  chunk,
496
592
  clamp,
497
593
  debounce,
@@ -511,6 +607,8 @@ function delay(ms) {
511
607
  isNotNil,
512
608
  isNull,
513
609
  isUndefined,
610
+ maxBy,
611
+ minBy,
514
612
  noop,
515
613
  omit,
516
614
  omitBy,
@@ -518,6 +616,9 @@ function delay(ms) {
518
616
  partition,
519
617
  pick,
520
618
  pickBy,
619
+ random,
620
+ randomInt,
621
+ range,
521
622
  round,
522
623
  sample,
523
624
  shuffle,