es-toolkit 1.3.1 → 1.4.0-dev.101

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 (183) 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.d.mts +2 -0
  13. package/dist/array/index.d.ts +2 -0
  14. package/dist/array/index.js +41 -2
  15. package/dist/array/index.js.map +1 -1
  16. package/dist/array/index.mjs +31 -23
  17. package/dist/array/intersectionWith.js.map +1 -1
  18. package/dist/array/intersectionWith.mjs +1 -1
  19. package/dist/array/maxBy.d.mts +21 -0
  20. package/dist/array/maxBy.d.ts +21 -0
  21. package/dist/array/maxBy.js +42 -0
  22. package/dist/array/maxBy.js.map +1 -0
  23. package/dist/array/maxBy.mjs +8 -0
  24. package/dist/array/minBy.d.mts +13 -0
  25. package/dist/array/minBy.d.ts +13 -0
  26. package/dist/array/minBy.js +42 -0
  27. package/dist/array/minBy.js.map +1 -0
  28. package/dist/array/minBy.mjs +8 -0
  29. package/dist/array/unionBy.js +1 -1
  30. package/dist/array/unionBy.js.map +1 -1
  31. package/dist/array/unionBy.mjs +1 -1
  32. package/dist/array/unionWith.js.map +1 -1
  33. package/dist/array/unionWith.mjs +1 -1
  34. package/dist/array/uniqBy.js +6 -13
  35. package/dist/array/uniqBy.js.map +1 -1
  36. package/dist/array/uniqBy.mjs +1 -2
  37. package/dist/array/xor.js.map +1 -1
  38. package/dist/array/xor.mjs +2 -2
  39. package/dist/array/xorBy.js +1 -1
  40. package/dist/array/xorBy.js.map +1 -1
  41. package/dist/array/xorBy.mjs +2 -2
  42. package/dist/array/xorWith.js.map +1 -1
  43. package/dist/array/xorWith.mjs +4 -4
  44. package/dist/array/zip.js.map +1 -1
  45. package/dist/array/zip.mjs +1 -1
  46. package/dist/array/zipWith.js.map +1 -1
  47. package/dist/array/zipWith.mjs +1 -1
  48. package/dist/{chunk-KLJRZJOR.mjs → chunk-2EFS3VA3.mjs} +1 -1
  49. package/dist/{chunk-KLJRZJOR.mjs.map → chunk-2EFS3VA3.mjs.map} +1 -1
  50. package/dist/{chunk-T5FDOBCA.mjs → chunk-4KYXHZ4R.mjs} +1 -1
  51. package/dist/{chunk-T5FDOBCA.mjs.map → chunk-4KYXHZ4R.mjs.map} +1 -1
  52. package/dist/{chunk-V7E5DGZP.mjs → chunk-5PMKOZ2F.mjs} +4 -1
  53. package/dist/chunk-5PMKOZ2F.mjs.map +1 -0
  54. package/dist/chunk-5UT77WON.mjs +13 -0
  55. package/dist/chunk-5UT77WON.mjs.map +1 -0
  56. package/dist/{chunk-3KHI4I2X.mjs → chunk-642SWVKJ.mjs} +1 -1
  57. package/dist/{chunk-3KHI4I2X.mjs.map → chunk-642SWVKJ.mjs.map} +1 -1
  58. package/dist/{chunk-FQ4K36VD.mjs → chunk-6NVQAHXP.mjs} +1 -1
  59. package/dist/{chunk-FQ4K36VD.mjs.map → chunk-6NVQAHXP.mjs.map} +1 -1
  60. package/dist/chunk-7LAMAYGN.mjs +1 -0
  61. package/dist/chunk-7LAMAYGN.mjs.map +1 -0
  62. package/dist/{chunk-SF3V7XXM.mjs → chunk-A67NF2C7.mjs} +1 -1
  63. package/dist/chunk-A67NF2C7.mjs.map +1 -0
  64. package/dist/chunk-AL3GJBEI.mjs +26 -0
  65. package/dist/chunk-AL3GJBEI.mjs.map +1 -0
  66. package/dist/{chunk-EW3RT4QW.mjs → chunk-AM2EGFCU.mjs} +2 -2
  67. package/dist/chunk-FZEZH22H.mjs +1 -0
  68. package/dist/chunk-FZEZH22H.mjs.map +1 -0
  69. package/dist/{chunk-WXIBCOES.mjs → chunk-G2TTBLLJ.mjs} +2 -2
  70. package/dist/chunk-H23GUJVF.mjs +18 -0
  71. package/dist/chunk-H23GUJVF.mjs.map +1 -0
  72. package/dist/{chunk-DD73BULA.mjs → chunk-IDCUZVJL.mjs} +1 -1
  73. package/dist/{chunk-DD73BULA.mjs.map → chunk-IDCUZVJL.mjs.map} +1 -1
  74. package/dist/{chunk-M7UI5ETO.mjs → chunk-JPUKH67K.mjs} +1 -1
  75. package/dist/{chunk-M7UI5ETO.mjs.map → chunk-JPUKH67K.mjs.map} +1 -1
  76. package/dist/{chunk-JFHM6EY2.mjs → chunk-K2BAFL2T.mjs} +1 -1
  77. package/dist/{chunk-JFHM6EY2.mjs.map → chunk-K2BAFL2T.mjs.map} +1 -1
  78. package/dist/chunk-KZ5JY7J3.mjs +18 -0
  79. package/dist/chunk-KZ5JY7J3.mjs.map +1 -0
  80. package/dist/chunk-LCP6FOCX.mjs +12 -0
  81. package/dist/chunk-LCP6FOCX.mjs.map +1 -0
  82. package/dist/{chunk-GOXQV6DX.mjs → chunk-MKETZ2RP.mjs} +2 -3
  83. package/dist/{chunk-GOXQV6DX.mjs.map → chunk-MKETZ2RP.mjs.map} +1 -1
  84. package/dist/{chunk-T2C2WVFL.mjs → chunk-MQWVBKUT.mjs} +1 -1
  85. package/dist/chunk-MQWVBKUT.mjs.map +1 -0
  86. package/dist/chunk-NP6PDX3E.mjs +1 -0
  87. package/dist/chunk-NP6PDX3E.mjs.map +1 -0
  88. package/dist/{chunk-JBDGK6X4.mjs → chunk-NRNKP6JF.mjs} +2 -2
  89. package/dist/{chunk-JBDGK6X4.mjs.map → chunk-NRNKP6JF.mjs.map} +1 -1
  90. package/dist/{chunk-CIRFWC7Y.mjs → chunk-RNJM5BHX.mjs} +2 -2
  91. package/dist/{chunk-FCF2RHPW.mjs → chunk-UMDNWTJC.mjs} +4 -4
  92. package/dist/{chunk-FCF2RHPW.mjs.map → chunk-UMDNWTJC.mjs.map} +1 -1
  93. package/dist/chunk-UNLX2F2Y.mjs +24 -0
  94. package/dist/chunk-UNLX2F2Y.mjs.map +1 -0
  95. package/dist/chunk-VP2LXY75.mjs +12 -0
  96. package/dist/chunk-VP2LXY75.mjs.map +1 -0
  97. package/dist/chunk-WPDDOUQT.mjs +16 -0
  98. package/dist/chunk-WPDDOUQT.mjs.map +1 -0
  99. package/dist/error/AbortError.d.mts +5 -0
  100. package/dist/error/AbortError.d.ts +5 -0
  101. package/dist/error/AbortError.js +36 -0
  102. package/dist/error/AbortError.js.map +1 -0
  103. package/dist/error/AbortError.mjs +8 -0
  104. package/dist/error/AbortError.mjs.map +1 -0
  105. package/dist/error/index.d.mts +1 -0
  106. package/dist/error/index.d.ts +1 -0
  107. package/dist/error/index.js +38 -0
  108. package/dist/error/index.js.map +1 -0
  109. package/dist/error/index.mjs +9 -0
  110. package/dist/error/index.mjs.map +1 -0
  111. package/dist/function/debounce.js +1 -2
  112. package/dist/function/debounce.js.map +1 -1
  113. package/dist/function/debounce.mjs +1 -1
  114. package/dist/function/index.js +1 -2
  115. package/dist/function/index.js.map +1 -1
  116. package/dist/function/index.mjs +4 -4
  117. package/dist/index.d.mts +6 -0
  118. package/dist/index.d.ts +6 -0
  119. package/dist/index.js +108 -7
  120. package/dist/index.js.map +1 -1
  121. package/dist/index.mjs +68 -43
  122. package/dist/math/index.d.mts +3 -0
  123. package/dist/math/index.d.ts +3 -0
  124. package/dist/math/index.js +42 -0
  125. package/dist/math/index.js.map +1 -1
  126. package/dist/math/index.mjs +14 -2
  127. package/dist/math/random.d.mts +16 -0
  128. package/dist/math/random.d.ts +16 -0
  129. package/dist/math/random.js +36 -0
  130. package/dist/math/random.js.map +1 -0
  131. package/dist/math/random.mjs +8 -0
  132. package/dist/math/random.mjs.map +1 -0
  133. package/dist/math/randomInt.d.mts +15 -0
  134. package/dist/math/randomInt.d.ts +15 -0
  135. package/dist/math/randomInt.js +43 -0
  136. package/dist/math/randomInt.js.map +1 -0
  137. package/dist/math/randomInt.mjs +9 -0
  138. package/dist/math/randomInt.mjs.map +1 -0
  139. package/dist/math/range.d.mts +32 -0
  140. package/dist/math/range.d.ts +32 -0
  141. package/dist/math/range.js +48 -0
  142. package/dist/math/range.js.map +1 -0
  143. package/dist/math/range.mjs +8 -0
  144. package/dist/math/range.mjs.map +1 -0
  145. package/dist/math/round.d.mts +2 -0
  146. package/dist/math/round.d.ts +2 -0
  147. package/dist/math/round.js +3 -0
  148. package/dist/math/round.js.map +1 -1
  149. package/dist/math/round.mjs +1 -1
  150. package/dist/object/index.js.map +1 -1
  151. package/dist/object/index.mjs +2 -2
  152. package/dist/object/omitBy.d.mts +2 -2
  153. package/dist/object/omitBy.d.ts +2 -2
  154. package/dist/object/omitBy.js.map +1 -1
  155. package/dist/object/omitBy.mjs +1 -1
  156. package/dist/object/pickBy.d.mts +2 -2
  157. package/dist/object/pickBy.d.ts +2 -2
  158. package/dist/object/pickBy.js.map +1 -1
  159. package/dist/object/pickBy.mjs +1 -1
  160. package/dist/predicate/index.mjs +3 -3
  161. package/dist/promise/delay.d.mts +18 -1
  162. package/dist/promise/delay.d.ts +18 -1
  163. package/dist/promise/delay.js +24 -3
  164. package/dist/promise/delay.js.map +1 -1
  165. package/dist/promise/delay.mjs +2 -1
  166. package/dist/promise/index.js +22 -3
  167. package/dist/promise/index.js.map +1 -1
  168. package/dist/promise/index.mjs +2 -1
  169. package/package.json +3 -1
  170. package/dist/chunk-ASFOKYTY.mjs +0 -13
  171. package/dist/chunk-ASFOKYTY.mjs.map +0 -1
  172. package/dist/chunk-EJGAXTF7.mjs +0 -1
  173. package/dist/chunk-IJLQVGW4.mjs +0 -1
  174. package/dist/chunk-SF3V7XXM.mjs.map +0 -1
  175. package/dist/chunk-T2C2WVFL.mjs.map +0 -1
  176. package/dist/chunk-V7E5DGZP.mjs.map +0 -1
  177. package/dist/chunk-ZBG3EYM3.mjs +0 -11
  178. package/dist/chunk-ZBG3EYM3.mjs.map +0 -1
  179. /package/dist/{chunk-EJGAXTF7.mjs.map → array/maxBy.mjs.map} +0 -0
  180. /package/dist/{chunk-IJLQVGW4.mjs.map → array/minBy.mjs.map} +0 -0
  181. /package/dist/{chunk-EW3RT4QW.mjs.map → chunk-AM2EGFCU.mjs.map} +0 -0
  182. /package/dist/{chunk-WXIBCOES.mjs.map → chunk-G2TTBLLJ.mjs.map} +0 -0
  183. /package/dist/{chunk-CIRFWC7Y.mjs.map → chunk-RNJM5BHX.mjs.map} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -7,11 +7,13 @@
7
7
  * @param {number} value - The number to round.
8
8
  * @param {number} [precision=0] - The number of decimal places to round to. Defaults to 0.
9
9
  * @returns {number} The rounded number.
10
+ * @throws {Error} Throws an error if `Precision` is not integer.
10
11
  *
11
12
  * @example
12
13
  * const result1 = round(1.2345); // result1 will be 1
13
14
  * const result2 = round(1.2345, 2); // result2 will be 1.23
14
15
  * const result3 = round(1.2345, 3); // result3 will be 1.235
16
+ * const result4 = round(1.2345, 3.1); // This will throw an error
15
17
  */
16
18
  declare function round(value: number, precision?: number): number;
17
19
 
@@ -7,11 +7,13 @@
7
7
  * @param {number} value - The number to round.
8
8
  * @param {number} [precision=0] - The number of decimal places to round to. Defaults to 0.
9
9
  * @returns {number} The rounded number.
10
+ * @throws {Error} Throws an error if `Precision` is not integer.
10
11
  *
11
12
  * @example
12
13
  * const result1 = round(1.2345); // result1 will be 1
13
14
  * const result2 = round(1.2345, 2); // result2 will be 1.23
14
15
  * const result3 = round(1.2345, 3); // result3 will be 1.235
16
+ * const result4 = round(1.2345, 3.1); // This will throw an error
15
17
  */
16
18
  declare function round(value: number, precision?: number): number;
17
19
 
@@ -24,6 +24,9 @@ __export(round_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(round_exports);
26
26
  function round(value, precision = 0) {
27
+ if (!Number.isInteger(precision)) {
28
+ throw new Error("Precision must be an integer.");
29
+ }
27
30
  const multiplier = Math.pow(10, precision);
28
31
  return Math.round(value * multiplier) / multiplier;
29
32
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/math/round.ts"],"sourcesContent":["/**\n * Rounds a number to a specified precision.\n *\n * This function takes a number and an optional precision value, and returns the number rounded\n * to the specified number of decimal places.\n *\n * @param {number} value - The number to round.\n * @param {number} [precision=0] - The number of decimal places to round to. Defaults to 0.\n * @returns {number} The rounded number.\n *\n * @example\n * const result1 = round(1.2345); // result1 will be 1\n * const result2 = round(1.2345, 2); // result2 will be 1.23\n * const result3 = round(1.2345, 3); // result3 will be 1.235\n */\nexport function round(value: number, precision: number = 0): number {\n const multiplier = Math.pow(10, precision);\n return Math.round(value * multiplier) / multiplier;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAeO,SAAS,MAAM,OAAe,YAAoB,GAAW;AAClE,QAAM,aAAa,KAAK,IAAI,IAAI,SAAS;AACzC,SAAO,KAAK,MAAM,QAAQ,UAAU,IAAI;AAC1C;","names":[]}
1
+ {"version":3,"sources":["../../src/math/round.ts"],"sourcesContent":["/**\n * Rounds a number to a specified precision.\n *\n * This function takes a number and an optional precision value, and returns the number rounded\n * to the specified number of decimal places.\n *\n * @param {number} value - The number to round.\n * @param {number} [precision=0] - The number of decimal places to round to. Defaults to 0.\n * @returns {number} The rounded number.\n * @throws {Error} Throws an error if `Precision` is not integer.\n *\n * @example\n * const result1 = round(1.2345); // result1 will be 1\n * const result2 = round(1.2345, 2); // result2 will be 1.23\n * const result3 = round(1.2345, 3); // result3 will be 1.235\n * const result4 = round(1.2345, 3.1); // This will throw an error\n */\nexport function round(value: number, precision = 0): number {\n if (!Number.isInteger(precision)) {\n throw new Error('Precision must be an integer.');\n }\n const multiplier = Math.pow(10, precision);\n return Math.round(value * multiplier) / multiplier;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBO,SAAS,MAAM,OAAe,YAAY,GAAW;AAC1D,MAAI,CAAC,OAAO,UAAU,SAAS,GAAG;AAChC,UAAM,IAAI,MAAM,+BAA+B;AAAA,EACjD;AACA,QAAM,aAAa,KAAK,IAAI,IAAI,SAAS;AACzC,SAAO,KAAK,MAAM,QAAQ,UAAU,IAAI;AAC1C;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  round
3
- } from "../chunk-V7E5DGZP.mjs";
3
+ } from "../chunk-5PMKOZ2F.mjs";
4
4
  import "../chunk-2MM5EJJX.mjs";
5
5
  export {
6
6
  round
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/object/index.ts","../../src/object/omit.ts","../../src/object/omitBy.ts","../../src/object/pick.ts","../../src/object/pickBy.ts"],"sourcesContent":["export { omit } from './omit';\nexport { omitBy } from './omitBy';\nexport { pick } from './pick';\nexport { pickBy } from './pickBy';\n","/**\n * Creates a new object with specified keys omitted.\n *\n * This function takes an object and an array of keys, and returns a new object that\n * excludes the properties corresponding to the specified keys.\n *\n * @param {T} obj - The object to omit keys from.\n * @param {K[]} keys - An array of keys to be omitted from the object.\n * @returns {Omit<T, K>} A new object with the specified keys omitted.\n *\n * @example\n * const obj = { a: 1, b: 2, c: 3 };\n * const result = omit(obj, ['b', 'c']);\n * // result will be { a: 1 }\n */\nexport function omit<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Omit<T, K> {\n const result = { ...obj };\n\n for (const key of keys) {\n delete result[key];\n }\n\n return result as Omit<T, K>;\n}\n","/**\n * Creates a new object composed of the properties that do not satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns false.\n *\n * @param {T} obj - The object to omit properties from.\n * @param {(value: T[string], key: string) => boolean} shouldOmit - A predicate function that determines\n * whether a property should be omitted. It takes the property's key and value as arguments and returns `true`\n * if the property should be omitted, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that do not satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'omit', c: 3 };\n * const shouldOmit = (key, value) => typeof value === 'string';\n * const result = omitBy(obj, shouldOmit);\n * // result will be { a: 1, c: 3 }\n */\nexport function omitBy<T extends Record<string, any>>(\n obj: T,\n shouldOmit: (value: T[keyof T], key: string) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (shouldOmit(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n","/**\n * Creates a new object composed of the picked object properties.\n *\n * This function takes an object and an array of keys, and returns a new object that\n * includes only the properties corresponding to the specified keys.\n *\n * @param {T} obj - The object to pick keys from.\n * @param {K[]} keys - An array of keys to be picked from the object.\n * @returns {Pick<T, K>} A new object with the specified keys picked.\n *\n * @example\n * const obj = { a: 1, b: 2, c: 3 };\n * const result = pick(obj, ['a', 'c']);\n * // result will be { a: 1, c: 3 }\n */\nexport function pick<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K> {\n const result = {} as Pick<T, K>;\n\n for (const key of keys) {\n result[key] = obj[key];\n }\n\n return result;\n}\n","/**\n * Creates a new object composed of the properties that satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns true.\n *\n * @param {T} obj - The object to pick properties from.\n * @param {(value: T[keyof T], key: string) => boolean} shouldPick - A predicate function that determines\n * whether a property should be picked. It takes the property's key and value as arguments and returns `true`\n * if the property should be picked, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'pick', c: 3 };\n * const shouldPick = (value) => typeof value === 'string';\n * const result = pickBy(obj, shouldPick);\n * // result will be { b: 'pick' }\n */\nexport function pickBy<T extends Record<string, any>>(\n obj: T,\n shouldPick: (value: T[keyof T], key: string) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (!shouldPick(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACeO,SAAS,KAAuD,KAAQ,MAAuB;AACpG,QAAM,SAAS,mBAAK;AAEpB,aAAW,OAAO,MAAM;AACtB,WAAO,OAAO,GAAG;AAAA,EACnB;AAEA,SAAO;AACT;;;ACLO,SAAS,OACd,KACA,YACY;AACZ,QAAM,SAAqB,CAAC;AAE5B,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,WAAW,OAAO,GAAG,GAAG;AAC1B;AAAA,IACF;AAEA,IAAC,OAAe,GAAG,IAAI;AAAA,EACzB;AAEA,SAAO;AACT;;;AClBO,SAAS,KAAuD,KAAQ,MAAuB;AACpG,QAAM,SAAS,CAAC;AAEhB,aAAW,OAAO,MAAM;AACtB,WAAO,GAAG,IAAI,IAAI,GAAG;AAAA,EACvB;AAEA,SAAO;AACT;;;ACLO,SAAS,OACd,KACA,YACY;AACZ,QAAM,SAAqB,CAAC;AAE5B,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,CAAC,WAAW,OAAO,GAAG,GAAG;AAC3B;AAAA,IACF;AAEA,IAAC,OAAe,GAAG,IAAI;AAAA,EACzB;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/object/index.ts","../../src/object/omit.ts","../../src/object/omitBy.ts","../../src/object/pick.ts","../../src/object/pickBy.ts"],"sourcesContent":["export { omit } from './omit';\nexport { omitBy } from './omitBy';\nexport { pick } from './pick';\nexport { pickBy } from './pickBy';\n","/**\n * Creates a new object with specified keys omitted.\n *\n * This function takes an object and an array of keys, and returns a new object that\n * excludes the properties corresponding to the specified keys.\n *\n * @param {T} obj - The object to omit keys from.\n * @param {K[]} keys - An array of keys to be omitted from the object.\n * @returns {Omit<T, K>} A new object with the specified keys omitted.\n *\n * @example\n * const obj = { a: 1, b: 2, c: 3 };\n * const result = omit(obj, ['b', 'c']);\n * // result will be { a: 1 }\n */\nexport function omit<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Omit<T, K> {\n const result = { ...obj };\n\n for (const key of keys) {\n delete result[key];\n }\n\n return result as Omit<T, K>;\n}\n","/**\n * Creates a new object composed of the properties that do not satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns false.\n *\n * @param {T} obj - The object to omit properties from.\n * @param {(value: T[string], key: keyof T) => boolean} shouldOmit - A predicate function that determines\n * whether a property should be omitted. It takes the property's key and value as arguments and returns `true`\n * if the property should be omitted, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that do not satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'omit', c: 3 };\n * const shouldOmit = (key, value) => typeof value === 'string';\n * const result = omitBy(obj, shouldOmit);\n * // result will be { a: 1, c: 3 }\n */\nexport function omitBy<T extends Record<string, any>>(\n obj: T,\n shouldOmit: (value: T[keyof T], key: keyof T) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (shouldOmit(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n","/**\n * Creates a new object composed of the picked object properties.\n *\n * This function takes an object and an array of keys, and returns a new object that\n * includes only the properties corresponding to the specified keys.\n *\n * @param {T} obj - The object to pick keys from.\n * @param {K[]} keys - An array of keys to be picked from the object.\n * @returns {Pick<T, K>} A new object with the specified keys picked.\n *\n * @example\n * const obj = { a: 1, b: 2, c: 3 };\n * const result = pick(obj, ['a', 'c']);\n * // result will be { a: 1, c: 3 }\n */\nexport function pick<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K> {\n const result = {} as Pick<T, K>;\n\n for (const key of keys) {\n result[key] = obj[key];\n }\n\n return result;\n}\n","/**\n * Creates a new object composed of the properties that satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns true.\n *\n * @param {T} obj - The object to pick properties from.\n * @param {(value: T[keyof T], key: keyof T) => boolean} shouldPick - A predicate function that determines\n * whether a property should be picked. It takes the property's key and value as arguments and returns `true`\n * if the property should be picked, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'pick', c: 3 };\n * const shouldPick = (value) => typeof value === 'string';\n * const result = pickBy(obj, shouldPick);\n * // result will be { b: 'pick' }\n */\nexport function pickBy<T extends Record<string, any>>(\n obj: T,\n shouldPick: (value: T[keyof T], key: keyof T) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (!shouldPick(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACeO,SAAS,KAAuD,KAAQ,MAAuB;AACpG,QAAM,SAAS,mBAAK;AAEpB,aAAW,OAAO,MAAM;AACtB,WAAO,OAAO,GAAG;AAAA,EACnB;AAEA,SAAO;AACT;;;ACLO,SAAS,OACd,KACA,YACY;AACZ,QAAM,SAAqB,CAAC;AAE5B,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,WAAW,OAAO,GAAG,GAAG;AAC1B;AAAA,IACF;AAEA,IAAC,OAAe,GAAG,IAAI;AAAA,EACzB;AAEA,SAAO;AACT;;;AClBO,SAAS,KAAuD,KAAQ,MAAuB;AACpG,QAAM,SAAS,CAAC;AAEhB,aAAW,OAAO,MAAM;AACtB,WAAO,GAAG,IAAI,IAAI,GAAG;AAAA,EACvB;AAEA,SAAO;AACT;;;ACLO,SAAS,OACd,KACA,YACY;AACZ,QAAM,SAAqB,CAAC;AAE5B,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,CAAC,WAAW,OAAO,GAAG,GAAG;AAC3B;AAAA,IACF;AAEA,IAAC,OAAe,GAAG,IAAI;AAAA,EACzB;AAEA,SAAO;AACT;","names":[]}
@@ -4,13 +4,13 @@ import {
4
4
  } from "../chunk-PLTO44KM.mjs";
5
5
  import {
6
6
  omitBy
7
- } from "../chunk-SF3V7XXM.mjs";
7
+ } from "../chunk-A67NF2C7.mjs";
8
8
  import {
9
9
  pick
10
10
  } from "../chunk-OFWKFUFZ.mjs";
11
11
  import {
12
12
  pickBy
13
- } from "../chunk-T2C2WVFL.mjs";
13
+ } from "../chunk-MQWVBKUT.mjs";
14
14
  import "../chunk-2MM5EJJX.mjs";
15
15
  export {
16
16
  omit,
@@ -5,7 +5,7 @@
5
5
  * includes only the properties for which the predicate function returns false.
6
6
  *
7
7
  * @param {T} obj - The object to omit properties from.
8
- * @param {(value: T[string], key: string) => boolean} shouldOmit - A predicate function that determines
8
+ * @param {(value: T[string], key: keyof T) => boolean} shouldOmit - A predicate function that determines
9
9
  * whether a property should be omitted. It takes the property's key and value as arguments and returns `true`
10
10
  * if the property should be omitted, and `false` otherwise.
11
11
  * @returns {Partial<T>} A new object with the properties that do not satisfy the predicate function.
@@ -16,6 +16,6 @@
16
16
  * const result = omitBy(obj, shouldOmit);
17
17
  * // result will be { a: 1, c: 3 }
18
18
  */
19
- declare function omitBy<T extends Record<string, any>>(obj: T, shouldOmit: (value: T[keyof T], key: string) => boolean): Partial<T>;
19
+ declare function omitBy<T extends Record<string, any>>(obj: T, shouldOmit: (value: T[keyof T], key: keyof T) => boolean): Partial<T>;
20
20
 
21
21
  export { omitBy };
@@ -5,7 +5,7 @@
5
5
  * includes only the properties for which the predicate function returns false.
6
6
  *
7
7
  * @param {T} obj - The object to omit properties from.
8
- * @param {(value: T[string], key: string) => boolean} shouldOmit - A predicate function that determines
8
+ * @param {(value: T[string], key: keyof T) => boolean} shouldOmit - A predicate function that determines
9
9
  * whether a property should be omitted. It takes the property's key and value as arguments and returns `true`
10
10
  * if the property should be omitted, and `false` otherwise.
11
11
  * @returns {Partial<T>} A new object with the properties that do not satisfy the predicate function.
@@ -16,6 +16,6 @@
16
16
  * const result = omitBy(obj, shouldOmit);
17
17
  * // result will be { a: 1, c: 3 }
18
18
  */
19
- declare function omitBy<T extends Record<string, any>>(obj: T, shouldOmit: (value: T[keyof T], key: string) => boolean): Partial<T>;
19
+ declare function omitBy<T extends Record<string, any>>(obj: T, shouldOmit: (value: T[keyof T], key: keyof T) => boolean): Partial<T>;
20
20
 
21
21
  export { omitBy };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/object/omitBy.ts"],"sourcesContent":["/**\n * Creates a new object composed of the properties that do not satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns false.\n *\n * @param {T} obj - The object to omit properties from.\n * @param {(value: T[string], key: string) => boolean} shouldOmit - A predicate function that determines\n * whether a property should be omitted. It takes the property's key and value as arguments and returns `true`\n * if the property should be omitted, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that do not satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'omit', c: 3 };\n * const shouldOmit = (key, value) => typeof value === 'string';\n * const result = omitBy(obj, shouldOmit);\n * // result will be { a: 1, c: 3 }\n */\nexport function omitBy<T extends Record<string, any>>(\n obj: T,\n shouldOmit: (value: T[keyof T], key: string) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (shouldOmit(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBO,SAAS,OACd,KACA,YACY;AACZ,QAAM,SAAqB,CAAC;AAE5B,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,WAAW,OAAO,GAAG,GAAG;AAC1B;AAAA,IACF;AAEA,IAAC,OAAe,GAAG,IAAI;AAAA,EACzB;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/object/omitBy.ts"],"sourcesContent":["/**\n * Creates a new object composed of the properties that do not satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns false.\n *\n * @param {T} obj - The object to omit properties from.\n * @param {(value: T[string], key: keyof T) => boolean} shouldOmit - A predicate function that determines\n * whether a property should be omitted. It takes the property's key and value as arguments and returns `true`\n * if the property should be omitted, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that do not satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'omit', c: 3 };\n * const shouldOmit = (key, value) => typeof value === 'string';\n * const result = omitBy(obj, shouldOmit);\n * // result will be { a: 1, c: 3 }\n */\nexport function omitBy<T extends Record<string, any>>(\n obj: T,\n shouldOmit: (value: T[keyof T], key: keyof T) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (shouldOmit(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBO,SAAS,OACd,KACA,YACY;AACZ,QAAM,SAAqB,CAAC;AAE5B,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,WAAW,OAAO,GAAG,GAAG;AAC1B;AAAA,IACF;AAEA,IAAC,OAAe,GAAG,IAAI;AAAA,EACzB;AAEA,SAAO;AACT;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  omitBy
3
- } from "../chunk-SF3V7XXM.mjs";
3
+ } from "../chunk-A67NF2C7.mjs";
4
4
  import "../chunk-2MM5EJJX.mjs";
5
5
  export {
6
6
  omitBy
@@ -5,7 +5,7 @@
5
5
  * includes only the properties for which the predicate function returns true.
6
6
  *
7
7
  * @param {T} obj - The object to pick properties from.
8
- * @param {(value: T[keyof T], key: string) => boolean} shouldPick - A predicate function that determines
8
+ * @param {(value: T[keyof T], key: keyof T) => boolean} shouldPick - A predicate function that determines
9
9
  * whether a property should be picked. It takes the property's key and value as arguments and returns `true`
10
10
  * if the property should be picked, and `false` otherwise.
11
11
  * @returns {Partial<T>} A new object with the properties that satisfy the predicate function.
@@ -16,6 +16,6 @@
16
16
  * const result = pickBy(obj, shouldPick);
17
17
  * // result will be { b: 'pick' }
18
18
  */
19
- declare function pickBy<T extends Record<string, any>>(obj: T, shouldPick: (value: T[keyof T], key: string) => boolean): Partial<T>;
19
+ declare function pickBy<T extends Record<string, any>>(obj: T, shouldPick: (value: T[keyof T], key: keyof T) => boolean): Partial<T>;
20
20
 
21
21
  export { pickBy };
@@ -5,7 +5,7 @@
5
5
  * includes only the properties for which the predicate function returns true.
6
6
  *
7
7
  * @param {T} obj - The object to pick properties from.
8
- * @param {(value: T[keyof T], key: string) => boolean} shouldPick - A predicate function that determines
8
+ * @param {(value: T[keyof T], key: keyof T) => boolean} shouldPick - A predicate function that determines
9
9
  * whether a property should be picked. It takes the property's key and value as arguments and returns `true`
10
10
  * if the property should be picked, and `false` otherwise.
11
11
  * @returns {Partial<T>} A new object with the properties that satisfy the predicate function.
@@ -16,6 +16,6 @@
16
16
  * const result = pickBy(obj, shouldPick);
17
17
  * // result will be { b: 'pick' }
18
18
  */
19
- declare function pickBy<T extends Record<string, any>>(obj: T, shouldPick: (value: T[keyof T], key: string) => boolean): Partial<T>;
19
+ declare function pickBy<T extends Record<string, any>>(obj: T, shouldPick: (value: T[keyof T], key: keyof T) => boolean): Partial<T>;
20
20
 
21
21
  export { pickBy };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/object/pickBy.ts"],"sourcesContent":["/**\n * Creates a new object composed of the properties that satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns true.\n *\n * @param {T} obj - The object to pick properties from.\n * @param {(value: T[keyof T], key: string) => boolean} shouldPick - A predicate function that determines\n * whether a property should be picked. It takes the property's key and value as arguments and returns `true`\n * if the property should be picked, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'pick', c: 3 };\n * const shouldPick = (value) => typeof value === 'string';\n * const result = pickBy(obj, shouldPick);\n * // result will be { b: 'pick' }\n */\nexport function pickBy<T extends Record<string, any>>(\n obj: T,\n shouldPick: (value: T[keyof T], key: string) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (!shouldPick(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBO,SAAS,OACd,KACA,YACY;AACZ,QAAM,SAAqB,CAAC;AAE5B,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,CAAC,WAAW,OAAO,GAAG,GAAG;AAC3B;AAAA,IACF;AAEA,IAAC,OAAe,GAAG,IAAI;AAAA,EACzB;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/object/pickBy.ts"],"sourcesContent":["/**\n * Creates a new object composed of the properties that satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns true.\n *\n * @param {T} obj - The object to pick properties from.\n * @param {(value: T[keyof T], key: keyof T) => boolean} shouldPick - A predicate function that determines\n * whether a property should be picked. It takes the property's key and value as arguments and returns `true`\n * if the property should be picked, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'pick', c: 3 };\n * const shouldPick = (value) => typeof value === 'string';\n * const result = pickBy(obj, shouldPick);\n * // result will be { b: 'pick' }\n */\nexport function pickBy<T extends Record<string, any>>(\n obj: T,\n shouldPick: (value: T[keyof T], key: keyof T) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (!shouldPick(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBO,SAAS,OACd,KACA,YACY;AACZ,QAAM,SAAqB,CAAC;AAE5B,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,CAAC,WAAW,OAAO,GAAG,GAAG;AAC3B;AAAA,IACF;AAEA,IAAC,OAAe,GAAG,IAAI;AAAA,EACzB;AAEA,SAAO;AACT;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  pickBy
3
- } from "../chunk-T2C2WVFL.mjs";
3
+ } from "../chunk-MQWVBKUT.mjs";
4
4
  import "../chunk-2MM5EJJX.mjs";
5
5
  export {
6
6
  pickBy
@@ -1,7 +1,4 @@
1
1
  import "../chunk-MAJSPFA6.mjs";
2
- import {
3
- isNotNil
4
- } from "../chunk-ZQNAZPSK.mjs";
5
2
  import {
6
3
  isNull
7
4
  } from "../chunk-AIRSKN47.mjs";
@@ -11,6 +8,9 @@ import {
11
8
  import {
12
9
  isNil
13
10
  } from "../chunk-OHQAR5AU.mjs";
11
+ import {
12
+ isNotNil
13
+ } from "../chunk-ZQNAZPSK.mjs";
14
14
  import "../chunk-2MM5EJJX.mjs";
15
15
  export {
16
16
  isNil,
@@ -1,3 +1,6 @@
1
+ interface DelayOptions {
2
+ signal?: AbortSignal;
3
+ }
1
4
  /**
2
5
  * Delays the execution of code for a specified number of milliseconds.
3
6
  *
@@ -5,6 +8,8 @@
5
8
  * with async/await to pause execution.
6
9
  *
7
10
  * @param {number} ms - The number of milliseconds to delay.
11
+ * @param {DelayOptions} options - The options object.
12
+ * @param {AbortSignal} options.signal - An optional AbortSignal to cancel the delay.
8
13
  * @returns {Promise<void>} A Promise that resolves after the specified delay.
9
14
  *
10
15
  * @example
@@ -15,7 +20,19 @@
15
20
  * }
16
21
  *
17
22
  * foo();
23
+ *
24
+ * // With AbortSignal
25
+ * const controller = new AbortController();
26
+ * const { signal } = controller;
27
+ *
28
+ * setTimeout(() => controller.abort(), 50); // Will cancel the delay after 50ms
29
+ * try {
30
+ * await delay(100, { signal });
31
+ * } catch (error) {
32
+ * console.error(error); // Will log 'AbortError'
33
+ * }
34
+ * }
18
35
  */
19
- declare function delay(ms: number): Promise<void>;
36
+ declare function delay(ms: number, { signal }?: DelayOptions): Promise<void>;
20
37
 
21
38
  export { delay };
@@ -1,3 +1,6 @@
1
+ interface DelayOptions {
2
+ signal?: AbortSignal;
3
+ }
1
4
  /**
2
5
  * Delays the execution of code for a specified number of milliseconds.
3
6
  *
@@ -5,6 +8,8 @@
5
8
  * with async/await to pause execution.
6
9
  *
7
10
  * @param {number} ms - The number of milliseconds to delay.
11
+ * @param {DelayOptions} options - The options object.
12
+ * @param {AbortSignal} options.signal - An optional AbortSignal to cancel the delay.
8
13
  * @returns {Promise<void>} A Promise that resolves after the specified delay.
9
14
  *
10
15
  * @example
@@ -15,7 +20,19 @@
15
20
  * }
16
21
  *
17
22
  * foo();
23
+ *
24
+ * // With AbortSignal
25
+ * const controller = new AbortController();
26
+ * const { signal } = controller;
27
+ *
28
+ * setTimeout(() => controller.abort(), 50); // Will cancel the delay after 50ms
29
+ * try {
30
+ * await delay(100, { signal });
31
+ * } catch (error) {
32
+ * console.error(error); // Will log 'AbortError'
33
+ * }
34
+ * }
18
35
  */
19
- declare function delay(ms: number): Promise<void>;
36
+ declare function delay(ms: number, { signal }?: DelayOptions): Promise<void>;
20
37
 
21
38
  export { delay };
@@ -23,9 +23,30 @@ __export(delay_exports, {
23
23
  delay: () => delay
24
24
  });
25
25
  module.exports = __toCommonJS(delay_exports);
26
- function delay(ms) {
27
- return new Promise((resolve) => {
28
- setTimeout(resolve, ms);
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
+
35
+ // src/promise/delay.ts
36
+ function delay(ms, { signal } = {}) {
37
+ return new Promise((resolve, reject) => {
38
+ const abortError = () => {
39
+ reject(new AbortError());
40
+ };
41
+ const abortHandler = () => {
42
+ clearTimeout(timeoutId);
43
+ abortError();
44
+ };
45
+ if (signal == null ? void 0 : signal.aborted) {
46
+ return abortError();
47
+ }
48
+ const timeoutId = setTimeout(resolve, ms);
49
+ signal == null ? void 0 : signal.addEventListener("abort", abortHandler, { once: true });
29
50
  });
30
51
  }
31
52
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/promise/delay.ts"],"sourcesContent":["/**\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 * @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 */\nexport function delay(ms: number): Promise<void> {\n return new Promise(resolve => {\n setTimeout(resolve, ms);\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBO,SAAS,MAAM,IAA2B;AAC/C,SAAO,IAAI,QAAQ,aAAW;AAC5B,eAAW,SAAS,EAAE;AAAA,EACxB,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../src/promise/delay.ts","../../src/error/AbortError.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","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;;;ADiCO,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":[]}
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  delay
3
- } from "../chunk-ZBG3EYM3.mjs";
3
+ } from "../chunk-AL3GJBEI.mjs";
4
+ import "../chunk-VP2LXY75.mjs";
4
5
  import "../chunk-2MM5EJJX.mjs";
5
6
  export {
6
7
  delay
@@ -24,10 +24,29 @@ __export(promise_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(promise_exports);
26
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
+
27
35
  // src/promise/delay.ts
28
- function delay(ms) {
29
- return new Promise((resolve) => {
30
- setTimeout(resolve, ms);
36
+ function delay(ms, { signal } = {}) {
37
+ return new Promise((resolve, reject) => {
38
+ const abortError = () => {
39
+ reject(new AbortError());
40
+ };
41
+ const abortHandler = () => {
42
+ clearTimeout(timeoutId);
43
+ abortError();
44
+ };
45
+ if (signal == null ? void 0 : signal.aborted) {
46
+ return abortError();
47
+ }
48
+ const timeoutId = setTimeout(resolve, ms);
49
+ signal == null ? void 0 : signal.addEventListener("abort", abortHandler, { once: true });
31
50
  });
32
51
  }
33
52
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/promise/index.ts","../../src/promise/delay.ts"],"sourcesContent":["export { delay } from './delay';\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 * @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 */\nexport function delay(ms: number): Promise<void> {\n return new Promise(resolve => {\n setTimeout(resolve, ms);\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACkBO,SAAS,MAAM,IAA2B;AAC/C,SAAO,IAAI,QAAQ,aAAW;AAC5B,eAAW,SAAS,EAAE;AAAA,EACxB,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../src/promise/index.ts","../../src/error/AbortError.ts","../../src/promise/delay.ts"],"sourcesContent":["export { delay } from './delay';\n","export class AbortError extends Error {\n constructor(message = 'The operation was aborted') {\n super(message);\n this.name = 'AbortError';\n }\n}\n","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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,aAAN,cAAyB,MAAM;AAAA,EACpC,YAAY,UAAU,6BAA6B;AACjD,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;;;ACiCO,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":[]}
@@ -1,7 +1,8 @@
1
1
  import "../chunk-ARZ5BDR6.mjs";
2
2
  import {
3
3
  delay
4
- } from "../chunk-ZBG3EYM3.mjs";
4
+ } from "../chunk-AL3GJBEI.mjs";
5
+ import "../chunk-VP2LXY75.mjs";
5
6
  import "../chunk-2MM5EJJX.mjs";
6
7
  export {
7
8
  delay
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "es-toolkit",
3
3
  "description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
4
- "version": "1.3.1",
4
+ "version": "1.4.0-dev.101+ed145c50",
5
5
  "workspaces": [
6
6
  "docs"
7
7
  ],
@@ -168,6 +168,7 @@
168
168
  "@babel/preset-typescript": "^7.24.1",
169
169
  "@changesets/changelog-github": "^0.5.0",
170
170
  "@changesets/cli": "^2.27.1",
171
+ "@codspeed/vitest-plugin": "^3.1.0",
171
172
  "@types/babel__core": "^7",
172
173
  "@types/babel__preset-env": "^7",
173
174
  "@types/broken-link-checker": "^0",
@@ -190,6 +191,7 @@
190
191
  "prepack": "yarn build",
191
192
  "build": "tsup && ./.scripts/postbuild.sh",
192
193
  "test": "vitest run --coverage --typecheck",
194
+ "bench": "vitest bench",
193
195
  "lint": "eslint ./src --ext .ts",
194
196
  "format": "prettier --write ."
195
197
  },
@@ -1,13 +0,0 @@
1
- import {
2
- uniqWith
3
- } from "./chunk-2PFDLYQC.mjs";
4
-
5
- // src/array/uniqBy.ts
6
- function uniqBy(arr, mapper) {
7
- return uniqWith(arr, (item1, item2) => mapper(item1) === mapper(item2));
8
- }
9
-
10
- export {
11
- uniqBy
12
- };
13
- //# sourceMappingURL=chunk-ASFOKYTY.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/array/uniqBy.ts"],"sourcesContent":["import { uniqWith } from './uniqWith';\n\n/**\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 return uniqWith(arr, (item1, item2) => mapper(item1) === mapper(item2));\n}\n"],"mappings":";;;;;AAgBO,SAAS,OAAa,KAAmB,QAA6B;AAC3E,SAAO,SAAS,KAAK,CAAC,OAAO,UAAU,OAAO,KAAK,MAAM,OAAO,KAAK,CAAC;AACxE;","names":[]}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=chunk-EJGAXTF7.mjs.map
@@ -1 +0,0 @@
1
- //# sourceMappingURL=chunk-IJLQVGW4.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/object/omitBy.ts"],"sourcesContent":["/**\n * Creates a new object composed of the properties that do not satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns false.\n *\n * @param {T} obj - The object to omit properties from.\n * @param {(value: T[string], key: string) => boolean} shouldOmit - A predicate function that determines\n * whether a property should be omitted. It takes the property's key and value as arguments and returns `true`\n * if the property should be omitted, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that do not satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'omit', c: 3 };\n * const shouldOmit = (key, value) => typeof value === 'string';\n * const result = omitBy(obj, shouldOmit);\n * // result will be { a: 1, c: 3 }\n */\nexport function omitBy<T extends Record<string, any>>(\n obj: T,\n shouldOmit: (value: T[keyof T], key: string) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (shouldOmit(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n"],"mappings":";AAkBO,SAAS,OACd,KACA,YACY;AACZ,QAAM,SAAqB,CAAC;AAE5B,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,WAAW,OAAO,GAAG,GAAG;AAC1B;AAAA,IACF;AAEA,IAAC,OAAe,GAAG,IAAI;AAAA,EACzB;AAEA,SAAO;AACT;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/object/pickBy.ts"],"sourcesContent":["/**\n * Creates a new object composed of the properties that satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns true.\n *\n * @param {T} obj - The object to pick properties from.\n * @param {(value: T[keyof T], key: string) => boolean} shouldPick - A predicate function that determines\n * whether a property should be picked. It takes the property's key and value as arguments and returns `true`\n * if the property should be picked, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'pick', c: 3 };\n * const shouldPick = (value) => typeof value === 'string';\n * const result = pickBy(obj, shouldPick);\n * // result will be { b: 'pick' }\n */\nexport function pickBy<T extends Record<string, any>>(\n obj: T,\n shouldPick: (value: T[keyof T], key: string) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (!shouldPick(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n"],"mappings":";AAkBO,SAAS,OACd,KACA,YACY;AACZ,QAAM,SAAqB,CAAC;AAE5B,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,CAAC,WAAW,OAAO,GAAG,GAAG;AAC3B;AAAA,IACF;AAEA,IAAC,OAAe,GAAG,IAAI;AAAA,EACzB;AAEA,SAAO;AACT;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/math/round.ts"],"sourcesContent":["/**\n * Rounds a number to a specified precision.\n *\n * This function takes a number and an optional precision value, and returns the number rounded\n * to the specified number of decimal places.\n *\n * @param {number} value - The number to round.\n * @param {number} [precision=0] - The number of decimal places to round to. Defaults to 0.\n * @returns {number} The rounded number.\n *\n * @example\n * const result1 = round(1.2345); // result1 will be 1\n * const result2 = round(1.2345, 2); // result2 will be 1.23\n * const result3 = round(1.2345, 3); // result3 will be 1.235\n */\nexport function round(value: number, precision: number = 0): number {\n const multiplier = Math.pow(10, precision);\n return Math.round(value * multiplier) / multiplier;\n}\n"],"mappings":";AAeO,SAAS,MAAM,OAAe,YAAoB,GAAW;AAClE,QAAM,aAAa,KAAK,IAAI,IAAI,SAAS;AACzC,SAAO,KAAK,MAAM,QAAQ,UAAU,IAAI;AAC1C;","names":[]}
@@ -1,11 +0,0 @@
1
- // src/promise/delay.ts
2
- function delay(ms) {
3
- return new Promise((resolve) => {
4
- setTimeout(resolve, ms);
5
- });
6
- }
7
-
8
- export {
9
- delay
10
- };
11
- //# sourceMappingURL=chunk-ZBG3EYM3.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/promise/delay.ts"],"sourcesContent":["/**\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 * @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 */\nexport function delay(ms: number): Promise<void> {\n return new Promise(resolve => {\n setTimeout(resolve, ms);\n });\n}\n"],"mappings":";AAkBO,SAAS,MAAM,IAA2B;AAC/C,SAAO,IAAI,QAAQ,aAAW;AAC5B,eAAW,SAAS,EAAE;AAAA,EACxB,CAAC;AACH;","names":[]}