es-toolkit 1.10.1 → 1.11.0-dev.263

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 (220) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/compat.d.ts +1 -0
  3. package/dist/array/chunk.mjs +1 -1
  4. package/dist/array/compact.mjs +1 -1
  5. package/dist/array/countBy.mjs +1 -1
  6. package/dist/array/difference.mjs +1 -1
  7. package/dist/array/differenceBy.mjs +1 -1
  8. package/dist/array/differenceWith.mjs +1 -1
  9. package/dist/array/drop.js +1 -0
  10. package/dist/array/drop.js.map +1 -1
  11. package/dist/array/drop.mjs +2 -2
  12. package/dist/array/dropRight.js +5 -1
  13. package/dist/array/dropRight.js.map +1 -1
  14. package/dist/array/dropRight.mjs +2 -2
  15. package/dist/array/dropRightWhile.js +6 -14
  16. package/dist/array/dropRightWhile.js.map +1 -1
  17. package/dist/array/dropRightWhile.mjs +2 -3
  18. package/dist/array/dropWhile.mjs +1 -1
  19. package/dist/array/fill.d.mts +10 -7
  20. package/dist/array/fill.d.ts +10 -7
  21. package/dist/array/fill.js +7 -6
  22. package/dist/array/fill.js.map +1 -1
  23. package/dist/array/fill.mjs +2 -2
  24. package/dist/array/flatMap.d.mts +23 -0
  25. package/dist/array/flatMap.d.ts +23 -0
  26. package/dist/array/flatMap.js +52 -0
  27. package/dist/array/flatMap.js.map +1 -0
  28. package/dist/array/flatMap.mjs +9 -0
  29. package/dist/array/flatten.mjs +1 -1
  30. package/dist/array/flattenDeep.mjs +1 -1
  31. package/dist/array/forEachRight.mjs +1 -1
  32. package/dist/array/groupBy.mjs +1 -1
  33. package/dist/array/head.mjs +1 -1
  34. package/dist/array/index.d.mts +1 -0
  35. package/dist/array/index.d.ts +1 -0
  36. package/dist/array/index.js +30 -14
  37. package/dist/array/index.js.map +1 -1
  38. package/dist/array/index.mjs +41 -37
  39. package/dist/array/initial.mjs +1 -1
  40. package/dist/array/intersection.mjs +1 -1
  41. package/dist/array/intersectionBy.mjs +1 -1
  42. package/dist/array/intersectionWith.mjs +1 -1
  43. package/dist/array/keyBy.mjs +1 -1
  44. package/dist/array/last.mjs +1 -1
  45. package/dist/array/maxBy.mjs +1 -1
  46. package/dist/array/minBy.mjs +1 -1
  47. package/dist/array/orderBy.mjs +1 -1
  48. package/dist/array/partition.mjs +1 -1
  49. package/dist/array/sample.mjs +1 -1
  50. package/dist/array/sampleSize.mjs +1 -1
  51. package/dist/array/shuffle.mjs +1 -1
  52. package/dist/array/tail.mjs +1 -1
  53. package/dist/array/take.mjs +1 -1
  54. package/dist/array/takeRight.mjs +1 -1
  55. package/dist/array/takeRightWhile.mjs +1 -1
  56. package/dist/array/takeWhile.mjs +1 -1
  57. package/dist/array/toFilled.mjs +1 -1
  58. package/dist/array/union.mjs +1 -1
  59. package/dist/array/unionBy.mjs +1 -1
  60. package/dist/array/unionWith.mjs +1 -1
  61. package/dist/array/uniq.mjs +1 -1
  62. package/dist/array/uniqBy.d.mts +1 -1
  63. package/dist/array/uniqBy.d.ts +1 -1
  64. package/dist/array/uniqBy.js.map +1 -1
  65. package/dist/array/uniqBy.mjs +2 -2
  66. package/dist/array/uniqWith.mjs +1 -1
  67. package/dist/array/unzip.mjs +1 -1
  68. package/dist/array/unzipWith.mjs +1 -1
  69. package/dist/array/without.mjs +1 -1
  70. package/dist/array/xor.mjs +1 -1
  71. package/dist/array/xorBy.mjs +1 -1
  72. package/dist/array/xorWith.mjs +1 -1
  73. package/dist/array/zip.mjs +1 -1
  74. package/dist/array/zipObject.mjs +1 -1
  75. package/dist/array/zipWith.mjs +1 -1
  76. package/dist/{chunk-S3CORED5.mjs → chunk-3EZAFZG3.mjs} +2 -1
  77. package/dist/{chunk-S3CORED5.mjs.map → chunk-3EZAFZG3.mjs.map} +1 -1
  78. package/dist/{chunk-2MM5EJJX.mjs → chunk-424M7IR7.mjs} +23 -2
  79. package/dist/chunk-4OIZM4HS.mjs +1 -0
  80. package/dist/{chunk-GDC64SYJ.mjs → chunk-5ASRKEB4.mjs} +1 -1
  81. package/dist/{chunk-GDC64SYJ.mjs.map → chunk-5ASRKEB4.mjs.map} +1 -1
  82. package/dist/{chunk-OXAZEEGP.mjs → chunk-B4COTK4K.mjs} +1 -1
  83. package/dist/{chunk-OXAZEEGP.mjs.map → chunk-B4COTK4K.mjs.map} +1 -1
  84. package/dist/chunk-DDH7K4QM.mjs +1 -0
  85. package/dist/chunk-F47GLYUU.mjs +1 -0
  86. package/dist/chunk-J3GE7DEU.mjs +22 -0
  87. package/dist/chunk-J3GE7DEU.mjs.map +1 -0
  88. package/dist/chunk-KIOYQRMQ.mjs +12 -0
  89. package/dist/chunk-KIOYQRMQ.mjs.map +1 -0
  90. package/dist/chunk-M7SBBYV2.mjs +14 -0
  91. package/dist/chunk-M7SBBYV2.mjs.map +1 -0
  92. package/dist/{chunk-IZAD2S7R.mjs → chunk-MY4G7R3I.mjs} +2 -2
  93. package/dist/{chunk-74WWMNZS.mjs → chunk-OLX53VEF.mjs} +4 -2
  94. package/dist/{chunk-74WWMNZS.mjs.map → chunk-OLX53VEF.mjs.map} +1 -1
  95. package/dist/chunk-OXZCMC5I.mjs +13 -0
  96. package/dist/{chunk-JEKUA56R.mjs.map → chunk-OXZCMC5I.mjs.map} +1 -1
  97. package/dist/chunk-QXTNZR7B.mjs +25 -0
  98. package/dist/chunk-QXTNZR7B.mjs.map +1 -0
  99. package/dist/{chunk-QZITBKWX.mjs → chunk-U7V3G7CR.mjs} +2 -2
  100. package/dist/chunk-UY76KTPE.mjs +13 -0
  101. package/dist/chunk-UY76KTPE.mjs.map +1 -0
  102. package/dist/chunk-XT74R35S.mjs +1 -0
  103. package/dist/chunk-XT74R35S.mjs.map +1 -0
  104. package/dist/chunk-XWPCDIFC.mjs +18 -0
  105. package/dist/chunk-XWPCDIFC.mjs.map +1 -0
  106. package/dist/chunk-YFN6KOC4.mjs +15 -0
  107. package/dist/chunk-YFN6KOC4.mjs.map +1 -0
  108. package/dist/compat/index.d.mts +392 -1
  109. package/dist/compat/index.d.ts +392 -1
  110. package/dist/compat/index.js +276 -21
  111. package/dist/compat/index.js.map +1 -1
  112. package/dist/compat/index.mjs +268 -87
  113. package/dist/compat/index.mjs.map +1 -1
  114. package/dist/error/AbortError.mjs +1 -1
  115. package/dist/error/TimeoutError.d.mts +9 -0
  116. package/dist/error/TimeoutError.d.ts +9 -0
  117. package/dist/error/TimeoutError.js +36 -0
  118. package/dist/error/TimeoutError.js.map +1 -0
  119. package/dist/error/TimeoutError.mjs +8 -0
  120. package/dist/error/TimeoutError.mjs.map +1 -0
  121. package/dist/error/index.d.mts +1 -0
  122. package/dist/error/index.d.ts +1 -0
  123. package/dist/error/index.js +12 -2
  124. package/dist/error/index.js.map +1 -1
  125. package/dist/error/index.mjs +7 -3
  126. package/dist/function/debounce.mjs +1 -1
  127. package/dist/function/index.mjs +7 -7
  128. package/dist/function/negate.mjs +1 -1
  129. package/dist/function/noop.mjs +1 -1
  130. package/dist/function/once.mjs +1 -1
  131. package/dist/function/throttle.mjs +1 -1
  132. package/dist/index.d.mts +4 -0
  133. package/dist/index.d.ts +4 -0
  134. package/dist/index.js +99 -15
  135. package/dist/index.js.map +1 -1
  136. package/dist/index.mjs +104 -87
  137. package/dist/math/clamp.mjs +1 -1
  138. package/dist/math/inRange.mjs +1 -1
  139. package/dist/math/index.js.map +1 -1
  140. package/dist/math/index.mjs +12 -12
  141. package/dist/math/mean.d.mts +1 -1
  142. package/dist/math/mean.d.ts +1 -1
  143. package/dist/math/mean.js.map +1 -1
  144. package/dist/math/mean.mjs +2 -2
  145. package/dist/math/meanBy.js.map +1 -1
  146. package/dist/math/meanBy.mjs +3 -3
  147. package/dist/math/random.mjs +1 -1
  148. package/dist/math/randomInt.mjs +1 -1
  149. package/dist/math/range.mjs +1 -1
  150. package/dist/math/round.mjs +1 -1
  151. package/dist/math/sum.mjs +1 -1
  152. package/dist/math/sumBy.mjs +1 -1
  153. package/dist/object/clone.mjs +1 -1
  154. package/dist/object/index.js +3 -1
  155. package/dist/object/index.js.map +1 -1
  156. package/dist/object/index.mjs +6 -6
  157. package/dist/object/invert.js +3 -1
  158. package/dist/object/invert.js.map +1 -1
  159. package/dist/object/invert.mjs +2 -2
  160. package/dist/object/omit.mjs +2 -2
  161. package/dist/object/omitBy.mjs +1 -1
  162. package/dist/object/pick.mjs +1 -1
  163. package/dist/object/pickBy.mjs +1 -1
  164. package/dist/predicate/index.mjs +1 -1
  165. package/dist/predicate/isEqual.mjs +1 -1
  166. package/dist/predicate/isNil.mjs +1 -1
  167. package/dist/predicate/isNotNil.mjs +1 -1
  168. package/dist/predicate/isNull.mjs +1 -1
  169. package/dist/predicate/isUndefined.mjs +1 -1
  170. package/dist/promise/delay.mjs +1 -1
  171. package/dist/promise/index.d.mts +1 -0
  172. package/dist/promise/index.d.ts +1 -0
  173. package/dist/promise/index.js +47 -2
  174. package/dist/promise/index.js.map +1 -1
  175. package/dist/promise/index.mjs +9 -3
  176. package/dist/promise/timeout.d.mts +10 -0
  177. package/dist/promise/timeout.d.ts +10 -0
  178. package/dist/promise/timeout.js +92 -0
  179. package/dist/promise/timeout.js.map +1 -0
  180. package/dist/promise/timeout.mjs +11 -0
  181. package/dist/promise/timeout.mjs.map +1 -0
  182. package/dist/promise/withTimeout.d.mts +22 -0
  183. package/dist/promise/withTimeout.d.ts +22 -0
  184. package/dist/promise/withTimeout.js +99 -0
  185. package/dist/promise/withTimeout.js.map +1 -0
  186. package/dist/promise/withTimeout.mjs +12 -0
  187. package/dist/promise/withTimeout.mjs.map +1 -0
  188. package/dist/string/camelCase.mjs +1 -1
  189. package/dist/string/capitalize.mjs +1 -1
  190. package/dist/string/index.d.mts +1 -0
  191. package/dist/string/index.d.ts +1 -0
  192. package/dist/string/index.js +21 -2
  193. package/dist/string/index.js.map +1 -1
  194. package/dist/string/index.mjs +13 -9
  195. package/dist/string/kebabCase.mjs +1 -1
  196. package/dist/string/lowerCase.mjs +1 -1
  197. package/dist/string/snakeCase.mjs +1 -1
  198. package/dist/string/startCase.d.mts +16 -0
  199. package/dist/string/startCase.d.ts +16 -0
  200. package/dist/string/startCase.js +54 -0
  201. package/dist/string/startCase.js.map +1 -0
  202. package/dist/string/startCase.mjs +9 -0
  203. package/dist/string/startCase.mjs.map +1 -0
  204. package/package.json +3 -5
  205. package/dist/chunk-2MRZANXZ.mjs +0 -1
  206. package/dist/chunk-ARZ5BDR6.mjs +0 -1
  207. package/dist/chunk-C4WE4GLC.mjs +0 -14
  208. package/dist/chunk-C4WE4GLC.mjs.map +0 -1
  209. package/dist/chunk-FZEZH22H.mjs +0 -1
  210. package/dist/chunk-JE6JKZU3.mjs +0 -15
  211. package/dist/chunk-JE6JKZU3.mjs.map +0 -1
  212. package/dist/chunk-JEKUA56R.mjs +0 -9
  213. package/dist/chunk-QKYYOLJ6.mjs +0 -1
  214. /package/dist/{chunk-2MM5EJJX.mjs.map → array/flatMap.mjs.map} +0 -0
  215. /package/dist/{chunk-2MRZANXZ.mjs.map → chunk-424M7IR7.mjs.map} +0 -0
  216. /package/dist/{chunk-ARZ5BDR6.mjs.map → chunk-4OIZM4HS.mjs.map} +0 -0
  217. /package/dist/{chunk-FZEZH22H.mjs.map → chunk-DDH7K4QM.mjs.map} +0 -0
  218. /package/dist/{chunk-QKYYOLJ6.mjs.map → chunk-F47GLYUU.mjs.map} +0 -0
  219. /package/dist/{chunk-IZAD2S7R.mjs.map → chunk-MY4G7R3I.mjs.map} +0 -0
  220. /package/dist/{chunk-QZITBKWX.mjs.map → chunk-U7V3G7CR.mjs.map} +0 -0
@@ -1,23 +1,23 @@
1
1
  import "../chunk-OSOLEQLZ.mjs";
2
+ import {
3
+ pickBy
4
+ } from "../chunk-6CLH5YZ2.mjs";
2
5
  import {
3
6
  clone
4
7
  } from "../chunk-U4JGKZ56.mjs";
5
8
  import {
6
9
  invert
7
- } from "../chunk-74WWMNZS.mjs";
10
+ } from "../chunk-OLX53VEF.mjs";
8
11
  import {
9
12
  omit
10
- } from "../chunk-QZITBKWX.mjs";
13
+ } from "../chunk-U7V3G7CR.mjs";
11
14
  import {
12
15
  omitBy
13
16
  } from "../chunk-BCTYOXT7.mjs";
14
17
  import {
15
18
  pick
16
19
  } from "../chunk-HPFDYUGP.mjs";
17
- import {
18
- pickBy
19
- } from "../chunk-6CLH5YZ2.mjs";
20
- import "../chunk-2MM5EJJX.mjs";
20
+ import "../chunk-424M7IR7.mjs";
21
21
  export {
22
22
  clone,
23
23
  invert,
@@ -25,7 +25,9 @@ __export(invert_exports, {
25
25
  module.exports = __toCommonJS(invert_exports);
26
26
  function invert(obj) {
27
27
  const result = {};
28
- for (const key in obj) {
28
+ const keys = Object.keys(obj);
29
+ for (let i = 0; i < keys.length; i++) {
30
+ const key = keys[i];
29
31
  const value = obj[key];
30
32
  result[value] = key;
31
33
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/object/invert.ts"],"sourcesContent":["/**\n * Inverts the keys and values of an object. The keys of the input object become the values of the output object and vice versa.\n *\n * This function takes an object and creates a new object by inverting its keys and values. If the input object has duplicate values,\n * the key of the last occurrence will be used as the value for the new key in the output object. It effectively creates a reverse mapping\n * of the input object's key-value pairs.\n *\n * @template K - Type of the keys in the input object (string, number, symbol)\n * @template V - Type of the values in the input object (string, number, symbol)\n * @param {Record<K, V>} obj - The input object whose keys and values are to be inverted\n * @returns {{ [key in V]: K }} - A new object with keys and values inverted\n *\n * @example\n * invert({ a: 1, b: 2, c: 3 }); // { 1: 'a', 2: 'b', 3: 'c' }\n * invert({ 1: 'a', 2: 'b', 3: 'c' }); // { a: '1', b: '2', c: '3' }\n * invert({ a: 1, 2: 'b', c: 3, 4: 'd' }); // { 1: 'a', b: '2', 3: 'c', d: '4' }\n * invert({ a: Symbol('sym1'), b: Symbol('sym2') }); // { [Symbol('sym1')]: 'a', [Symbol('sym2')]: 'b' }\n */\nexport function invert<K extends PropertyKey, V extends PropertyKey>(obj: Record<K, V>): { [key in V]: K } {\n const result = {} as { [key in V]: K };\n\n for (const key in obj) {\n const value = obj[key as K] as V;\n result[value] = key;\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBO,SAAS,OAAqD,KAAsC;AACzG,QAAM,SAAS,CAAC;AAEhB,aAAW,OAAO,KAAK;AACrB,UAAM,QAAQ,IAAI,GAAQ;AAC1B,WAAO,KAAK,IAAI;AAAA,EAClB;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/object/invert.ts"],"sourcesContent":["/**\n * Inverts the keys and values of an object. The keys of the input object become the values of the output object and vice versa.\n *\n * This function takes an object and creates a new object by inverting its keys and values. If the input object has duplicate values,\n * the key of the last occurrence will be used as the value for the new key in the output object. It effectively creates a reverse mapping\n * of the input object's key-value pairs.\n *\n * @template K - Type of the keys in the input object (string, number, symbol)\n * @template V - Type of the values in the input object (string, number, symbol)\n * @param {Record<K, V>} obj - The input object whose keys and values are to be inverted\n * @returns {{ [key in V]: K }} - A new object with keys and values inverted\n *\n * @example\n * invert({ a: 1, b: 2, c: 3 }); // { 1: 'a', 2: 'b', 3: 'c' }\n * invert({ 1: 'a', 2: 'b', 3: 'c' }); // { a: '1', b: '2', c: '3' }\n * invert({ a: 1, 2: 'b', c: 3, 4: 'd' }); // { 1: 'a', b: '2', 3: 'c', d: '4' }\n * invert({ a: Symbol('sym1'), b: Symbol('sym2') }); // { [Symbol('sym1')]: 'a', [Symbol('sym2')]: 'b' }\n */\nexport function invert<K extends PropertyKey, V extends PropertyKey>(obj: Record<K, V>): { [key in V]: K } {\n const result = {} as { [key in V]: K };\n\n const keys = Object.keys(obj) as K[];\n \n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const value = obj[key];\n result[value] = key;\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBO,SAAS,OAAqD,KAAsC;AACzG,QAAM,SAAS,CAAC;AAEhB,QAAM,OAAO,OAAO,KAAK,GAAG;AAE5B,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,UAAM,MAAM,KAAK,CAAC;AAClB,UAAM,QAAQ,IAAI,GAAG;AACrB,WAAO,KAAK,IAAI;AAAA,EAClB;AAEA,SAAO;AACT;","names":[]}
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  invert
3
- } from "../chunk-74WWMNZS.mjs";
4
- import "../chunk-2MM5EJJX.mjs";
3
+ } from "../chunk-OLX53VEF.mjs";
4
+ import "../chunk-424M7IR7.mjs";
5
5
  export {
6
6
  invert
7
7
  };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  omit
3
- } from "../chunk-QZITBKWX.mjs";
4
- import "../chunk-2MM5EJJX.mjs";
3
+ } from "../chunk-U7V3G7CR.mjs";
4
+ import "../chunk-424M7IR7.mjs";
5
5
  export {
6
6
  omit
7
7
  };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  omitBy
3
3
  } from "../chunk-BCTYOXT7.mjs";
4
- import "../chunk-2MM5EJJX.mjs";
4
+ import "../chunk-424M7IR7.mjs";
5
5
  export {
6
6
  omitBy
7
7
  };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  pick
3
3
  } from "../chunk-HPFDYUGP.mjs";
4
- import "../chunk-2MM5EJJX.mjs";
4
+ import "../chunk-424M7IR7.mjs";
5
5
  export {
6
6
  pick
7
7
  };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  pickBy
3
3
  } from "../chunk-6CLH5YZ2.mjs";
4
- import "../chunk-2MM5EJJX.mjs";
4
+ import "../chunk-424M7IR7.mjs";
5
5
  export {
6
6
  pickBy
7
7
  };
@@ -16,7 +16,7 @@ import {
16
16
  } from "../chunk-VH2PV426.mjs";
17
17
  import "../chunk-R6QA7PLZ.mjs";
18
18
  import "../chunk-DVK2N4KC.mjs";
19
- import "../chunk-2MM5EJJX.mjs";
19
+ import "../chunk-424M7IR7.mjs";
20
20
  export {
21
21
  isEqual,
22
22
  isNil,
@@ -3,7 +3,7 @@ import {
3
3
  } from "../chunk-JYSV56US.mjs";
4
4
  import "../chunk-R6QA7PLZ.mjs";
5
5
  import "../chunk-DVK2N4KC.mjs";
6
- import "../chunk-2MM5EJJX.mjs";
6
+ import "../chunk-424M7IR7.mjs";
7
7
  export {
8
8
  isEqual
9
9
  };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  isNil
3
3
  } from "../chunk-WMM7TZLG.mjs";
4
- import "../chunk-2MM5EJJX.mjs";
4
+ import "../chunk-424M7IR7.mjs";
5
5
  export {
6
6
  isNil
7
7
  };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  isNotNil
3
3
  } from "../chunk-BMRTZMRE.mjs";
4
- import "../chunk-2MM5EJJX.mjs";
4
+ import "../chunk-424M7IR7.mjs";
5
5
  export {
6
6
  isNotNil
7
7
  };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  isNull
3
3
  } from "../chunk-AIRSKN47.mjs";
4
- import "../chunk-2MM5EJJX.mjs";
4
+ import "../chunk-424M7IR7.mjs";
5
5
  export {
6
6
  isNull
7
7
  };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  isUndefined
3
3
  } from "../chunk-VH2PV426.mjs";
4
- import "../chunk-2MM5EJJX.mjs";
4
+ import "../chunk-424M7IR7.mjs";
5
5
  export {
6
6
  isUndefined
7
7
  };
@@ -2,7 +2,7 @@ import {
2
2
  delay
3
3
  } from "../chunk-O64NE2P4.mjs";
4
4
  import "../chunk-DXB7EZUQ.mjs";
5
- import "../chunk-2MM5EJJX.mjs";
5
+ import "../chunk-424M7IR7.mjs";
6
6
  export {
7
7
  delay
8
8
  };
@@ -1 +1,2 @@
1
1
  export { delay } from './delay.mjs';
2
+ export { withTimeout } from './withTimeout.mjs';
@@ -1 +1,2 @@
1
1
  export { delay } from './delay.js';
2
+ export { withTimeout } from './withTimeout.js';
@@ -16,11 +16,32 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var __async = (__this, __arguments, generator) => {
20
+ return new Promise((resolve, reject) => {
21
+ var fulfilled = (value) => {
22
+ try {
23
+ step(generator.next(value));
24
+ } catch (e) {
25
+ reject(e);
26
+ }
27
+ };
28
+ var rejected = (value) => {
29
+ try {
30
+ step(generator.throw(value));
31
+ } catch (e) {
32
+ reject(e);
33
+ }
34
+ };
35
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
36
+ step((generator = generator.apply(__this, __arguments)).next());
37
+ });
38
+ };
19
39
 
20
40
  // src/promise/index.ts
21
41
  var promise_exports = {};
22
42
  __export(promise_exports, {
23
- delay: () => delay
43
+ delay: () => delay,
44
+ withTimeout: () => withTimeout
24
45
  });
25
46
  module.exports = __toCommonJS(promise_exports);
26
47
 
@@ -49,8 +70,32 @@ function delay(ms, { signal } = {}) {
49
70
  signal == null ? void 0 : signal.addEventListener("abort", abortHandler, { once: true });
50
71
  });
51
72
  }
73
+
74
+ // src/error/TimeoutError.ts
75
+ var TimeoutError = class extends Error {
76
+ constructor(message = "The operation was timed out") {
77
+ super(message);
78
+ this.name = "TimeoutError";
79
+ }
80
+ };
81
+
82
+ // src/promise/timeout.ts
83
+ function timeout(ms) {
84
+ return __async(this, null, function* () {
85
+ yield delay(ms);
86
+ throw new TimeoutError();
87
+ });
88
+ }
89
+
90
+ // src/promise/withTimeout.ts
91
+ function withTimeout(run, ms) {
92
+ return __async(this, null, function* () {
93
+ return Promise.race([run(), timeout(ms)]);
94
+ });
95
+ }
52
96
  // Annotate the CommonJS export names for ESM import in node:
53
97
  0 && (module.exports = {
54
- delay
98
+ delay,
99
+ withTimeout
55
100
  });
56
101
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/promise/index.ts","../../src/error/AbortError.ts","../../src/promise/delay.ts"],"sourcesContent":["export { delay } from './delay.ts';\n","/**\n * An error class representing an aborted operation.\n * @augments Error\n */\nexport 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.ts';\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;;;ACIO,IAAM,aAAN,cAAyB,MAAM;AAAA,EACpC,YAAY,UAAU,6BAA6B;AACjD,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;;;AC6BO,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
+ {"version":3,"sources":["../../src/promise/index.ts","../../src/error/AbortError.ts","../../src/promise/delay.ts","../../src/error/TimeoutError.ts","../../src/promise/timeout.ts","../../src/promise/withTimeout.ts"],"sourcesContent":["export { delay } from './delay.ts';\nexport { withTimeout } from './withTimeout.ts';\n","/**\n * An error class representing an aborted operation.\n * @augments Error\n */\nexport 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.ts';\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","/**\n * An error class representing an timeout operation.\n * @augments Error\n */\nexport class TimeoutError extends Error {\n constructor(message = 'The operation was timed out') {\n super(message);\n this.name = 'TimeoutError';\n }\n}\n","import { delay } from './delay.ts';\nimport { TimeoutError } from '../error/TimeoutError.ts';\n\n/**\n * Returns a promise that rejects with a `TimeoutError` after a specified delay.\n *\n * @param {number} ms - The delay duration in milliseconds.\n * @returns {Promise<void>} A promise that rejects with a `TimeoutError` after the specified delay.\n * @throws {TimeoutError} Throws a `TimeoutError` after the specified delay.\n */\nexport async function timeout(ms: number): Promise<never> {\n await delay(ms);\n throw new TimeoutError();\n}\n","import { timeout } from './timeout.ts';\n\n/**\n * Executes an async function and enforces a timeout. \n * \n * If the promise does not resolve within the specified time,\n * the timeout will trigger and the returned promise will be rejected.\n *\n *\n * @template T \n * @param {() => Promise<T>} run - A function that returns a promise to be executed.\n * @param {number} ms - The timeout duration in milliseconds.\n * @returns {Promise<T>} A promise that resolves with the result of the `run` function or rejects if the timeout is reached.\n *\n * @example\n * try {\n * await withTimeout(() => {}, 1000); // Timeout exception after 1 second\n * } catch (error) {\n * console.error(error); // Will log 'TimeoutError'\n * }\n */\nexport async function withTimeout<T>(run: () => Promise<T>, ms: number): Promise<T> {\n return Promise.race([run(), timeout(ms) as T]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIO,IAAM,aAAN,cAAyB,MAAM;AAAA,EACpC,YAAY,UAAU,6BAA6B;AACjD,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;;;AC6BO,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;;;ACrDO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtC,YAAY,UAAU,+BAA+B;AACnD,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;;;ACCA,SAAsB,QAAQ,IAA4B;AAAA;AACxD,UAAM,MAAM,EAAE;AACd,UAAM,IAAI,aAAa;AAAA,EACzB;AAAA;;;ACQA,SAAsB,YAAe,KAAuB,IAAwB;AAAA;AAClF,WAAO,QAAQ,KAAK,CAAC,IAAI,GAAG,QAAQ,EAAE,CAAM,CAAC;AAAA,EAC/C;AAAA;","names":[]}
@@ -1,10 +1,16 @@
1
- import "../chunk-ARZ5BDR6.mjs";
1
+ import "../chunk-4OIZM4HS.mjs";
2
+ import {
3
+ withTimeout
4
+ } from "../chunk-XWPCDIFC.mjs";
5
+ import "../chunk-J3GE7DEU.mjs";
2
6
  import {
3
7
  delay
4
8
  } from "../chunk-O64NE2P4.mjs";
5
9
  import "../chunk-DXB7EZUQ.mjs";
6
- import "../chunk-2MM5EJJX.mjs";
10
+ import "../chunk-KIOYQRMQ.mjs";
11
+ import "../chunk-424M7IR7.mjs";
7
12
  export {
8
- delay
13
+ delay,
14
+ withTimeout
9
15
  };
10
16
  //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Returns a promise that rejects with a `TimeoutError` after a specified delay.
3
+ *
4
+ * @param {number} ms - The delay duration in milliseconds.
5
+ * @returns {Promise<void>} A promise that rejects with a `TimeoutError` after the specified delay.
6
+ * @throws {TimeoutError} Throws a `TimeoutError` after the specified delay.
7
+ */
8
+ declare function timeout(ms: number): Promise<never>;
9
+
10
+ export { timeout };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Returns a promise that rejects with a `TimeoutError` after a specified delay.
3
+ *
4
+ * @param {number} ms - The delay duration in milliseconds.
5
+ * @returns {Promise<void>} A promise that rejects with a `TimeoutError` after the specified delay.
6
+ * @throws {TimeoutError} Throws a `TimeoutError` after the specified delay.
7
+ */
8
+ declare function timeout(ms: number): Promise<never>;
9
+
10
+ export { timeout };
@@ -0,0 +1,92 @@
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
+ var __async = (__this, __arguments, generator) => {
20
+ return new Promise((resolve, reject) => {
21
+ var fulfilled = (value) => {
22
+ try {
23
+ step(generator.next(value));
24
+ } catch (e) {
25
+ reject(e);
26
+ }
27
+ };
28
+ var rejected = (value) => {
29
+ try {
30
+ step(generator.throw(value));
31
+ } catch (e) {
32
+ reject(e);
33
+ }
34
+ };
35
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
36
+ step((generator = generator.apply(__this, __arguments)).next());
37
+ });
38
+ };
39
+
40
+ // src/promise/timeout.ts
41
+ var timeout_exports = {};
42
+ __export(timeout_exports, {
43
+ timeout: () => timeout
44
+ });
45
+ module.exports = __toCommonJS(timeout_exports);
46
+
47
+ // src/error/AbortError.ts
48
+ var AbortError = class extends Error {
49
+ constructor(message = "The operation was aborted") {
50
+ super(message);
51
+ this.name = "AbortError";
52
+ }
53
+ };
54
+
55
+ // src/promise/delay.ts
56
+ function delay(ms, { signal } = {}) {
57
+ return new Promise((resolve, reject) => {
58
+ const abortError = () => {
59
+ reject(new AbortError());
60
+ };
61
+ const abortHandler = () => {
62
+ clearTimeout(timeoutId);
63
+ abortError();
64
+ };
65
+ if (signal == null ? void 0 : signal.aborted) {
66
+ return abortError();
67
+ }
68
+ const timeoutId = setTimeout(resolve, ms);
69
+ signal == null ? void 0 : signal.addEventListener("abort", abortHandler, { once: true });
70
+ });
71
+ }
72
+
73
+ // src/error/TimeoutError.ts
74
+ var TimeoutError = class extends Error {
75
+ constructor(message = "The operation was timed out") {
76
+ super(message);
77
+ this.name = "TimeoutError";
78
+ }
79
+ };
80
+
81
+ // src/promise/timeout.ts
82
+ function timeout(ms) {
83
+ return __async(this, null, function* () {
84
+ yield delay(ms);
85
+ throw new TimeoutError();
86
+ });
87
+ }
88
+ // Annotate the CommonJS export names for ESM import in node:
89
+ 0 && (module.exports = {
90
+ timeout
91
+ });
92
+ //# sourceMappingURL=timeout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/promise/timeout.ts","../../src/error/AbortError.ts","../../src/promise/delay.ts","../../src/error/TimeoutError.ts"],"sourcesContent":["import { delay } from './delay.ts';\nimport { TimeoutError } from '../error/TimeoutError.ts';\n\n/**\n * Returns a promise that rejects with a `TimeoutError` after a specified delay.\n *\n * @param {number} ms - The delay duration in milliseconds.\n * @returns {Promise<void>} A promise that rejects with a `TimeoutError` after the specified delay.\n * @throws {TimeoutError} Throws a `TimeoutError` after the specified delay.\n */\nexport async function timeout(ms: number): Promise<never> {\n await delay(ms);\n throw new TimeoutError();\n}\n","/**\n * An error class representing an aborted operation.\n * @augments Error\n */\nexport 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.ts';\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","/**\n * An error class representing an timeout operation.\n * @augments Error\n */\nexport class TimeoutError extends Error {\n constructor(message = 'The operation was timed out') {\n super(message);\n this.name = 'TimeoutError';\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIO,IAAM,aAAN,cAAyB,MAAM;AAAA,EACpC,YAAY,UAAU,6BAA6B;AACjD,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;;;AC6BO,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;;;ACrDO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtC,YAAY,UAAU,+BAA+B;AACnD,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;;;AHCA,SAAsB,QAAQ,IAA4B;AAAA;AACxD,UAAM,MAAM,EAAE;AACd,UAAM,IAAI,aAAa;AAAA,EACzB;AAAA;","names":[]}
@@ -0,0 +1,11 @@
1
+ import {
2
+ timeout
3
+ } from "../chunk-J3GE7DEU.mjs";
4
+ import "../chunk-O64NE2P4.mjs";
5
+ import "../chunk-DXB7EZUQ.mjs";
6
+ import "../chunk-KIOYQRMQ.mjs";
7
+ import "../chunk-424M7IR7.mjs";
8
+ export {
9
+ timeout
10
+ };
11
+ //# sourceMappingURL=timeout.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Executes an async function and enforces a timeout.
3
+ *
4
+ * If the promise does not resolve within the specified time,
5
+ * the timeout will trigger and the returned promise will be rejected.
6
+ *
7
+ *
8
+ * @template T
9
+ * @param {() => Promise<T>} run - A function that returns a promise to be executed.
10
+ * @param {number} ms - The timeout duration in milliseconds.
11
+ * @returns {Promise<T>} A promise that resolves with the result of the `run` function or rejects if the timeout is reached.
12
+ *
13
+ * @example
14
+ * try {
15
+ * await withTimeout(() => {}, 1000); // Timeout exception after 1 second
16
+ * } catch (error) {
17
+ * console.error(error); // Will log 'TimeoutError'
18
+ * }
19
+ */
20
+ declare function withTimeout<T>(run: () => Promise<T>, ms: number): Promise<T>;
21
+
22
+ export { withTimeout };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Executes an async function and enforces a timeout.
3
+ *
4
+ * If the promise does not resolve within the specified time,
5
+ * the timeout will trigger and the returned promise will be rejected.
6
+ *
7
+ *
8
+ * @template T
9
+ * @param {() => Promise<T>} run - A function that returns a promise to be executed.
10
+ * @param {number} ms - The timeout duration in milliseconds.
11
+ * @returns {Promise<T>} A promise that resolves with the result of the `run` function or rejects if the timeout is reached.
12
+ *
13
+ * @example
14
+ * try {
15
+ * await withTimeout(() => {}, 1000); // Timeout exception after 1 second
16
+ * } catch (error) {
17
+ * console.error(error); // Will log 'TimeoutError'
18
+ * }
19
+ */
20
+ declare function withTimeout<T>(run: () => Promise<T>, ms: number): Promise<T>;
21
+
22
+ export { withTimeout };
@@ -0,0 +1,99 @@
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
+ var __async = (__this, __arguments, generator) => {
20
+ return new Promise((resolve, reject) => {
21
+ var fulfilled = (value) => {
22
+ try {
23
+ step(generator.next(value));
24
+ } catch (e) {
25
+ reject(e);
26
+ }
27
+ };
28
+ var rejected = (value) => {
29
+ try {
30
+ step(generator.throw(value));
31
+ } catch (e) {
32
+ reject(e);
33
+ }
34
+ };
35
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
36
+ step((generator = generator.apply(__this, __arguments)).next());
37
+ });
38
+ };
39
+
40
+ // src/promise/withTimeout.ts
41
+ var withTimeout_exports = {};
42
+ __export(withTimeout_exports, {
43
+ withTimeout: () => withTimeout
44
+ });
45
+ module.exports = __toCommonJS(withTimeout_exports);
46
+
47
+ // src/error/AbortError.ts
48
+ var AbortError = class extends Error {
49
+ constructor(message = "The operation was aborted") {
50
+ super(message);
51
+ this.name = "AbortError";
52
+ }
53
+ };
54
+
55
+ // src/promise/delay.ts
56
+ function delay(ms, { signal } = {}) {
57
+ return new Promise((resolve, reject) => {
58
+ const abortError = () => {
59
+ reject(new AbortError());
60
+ };
61
+ const abortHandler = () => {
62
+ clearTimeout(timeoutId);
63
+ abortError();
64
+ };
65
+ if (signal == null ? void 0 : signal.aborted) {
66
+ return abortError();
67
+ }
68
+ const timeoutId = setTimeout(resolve, ms);
69
+ signal == null ? void 0 : signal.addEventListener("abort", abortHandler, { once: true });
70
+ });
71
+ }
72
+
73
+ // src/error/TimeoutError.ts
74
+ var TimeoutError = class extends Error {
75
+ constructor(message = "The operation was timed out") {
76
+ super(message);
77
+ this.name = "TimeoutError";
78
+ }
79
+ };
80
+
81
+ // src/promise/timeout.ts
82
+ function timeout(ms) {
83
+ return __async(this, null, function* () {
84
+ yield delay(ms);
85
+ throw new TimeoutError();
86
+ });
87
+ }
88
+
89
+ // src/promise/withTimeout.ts
90
+ function withTimeout(run, ms) {
91
+ return __async(this, null, function* () {
92
+ return Promise.race([run(), timeout(ms)]);
93
+ });
94
+ }
95
+ // Annotate the CommonJS export names for ESM import in node:
96
+ 0 && (module.exports = {
97
+ withTimeout
98
+ });
99
+ //# sourceMappingURL=withTimeout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/promise/withTimeout.ts","../../src/error/AbortError.ts","../../src/promise/delay.ts","../../src/error/TimeoutError.ts","../../src/promise/timeout.ts"],"sourcesContent":["import { timeout } from './timeout.ts';\n\n/**\n * Executes an async function and enforces a timeout. \n * \n * If the promise does not resolve within the specified time,\n * the timeout will trigger and the returned promise will be rejected.\n *\n *\n * @template T \n * @param {() => Promise<T>} run - A function that returns a promise to be executed.\n * @param {number} ms - The timeout duration in milliseconds.\n * @returns {Promise<T>} A promise that resolves with the result of the `run` function or rejects if the timeout is reached.\n *\n * @example\n * try {\n * await withTimeout(() => {}, 1000); // Timeout exception after 1 second\n * } catch (error) {\n * console.error(error); // Will log 'TimeoutError'\n * }\n */\nexport async function withTimeout<T>(run: () => Promise<T>, ms: number): Promise<T> {\n return Promise.race([run(), timeout(ms) as T]);\n}\n","/**\n * An error class representing an aborted operation.\n * @augments Error\n */\nexport 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.ts';\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","/**\n * An error class representing an timeout operation.\n * @augments Error\n */\nexport class TimeoutError extends Error {\n constructor(message = 'The operation was timed out') {\n super(message);\n this.name = 'TimeoutError';\n }\n}\n","import { delay } from './delay.ts';\nimport { TimeoutError } from '../error/TimeoutError.ts';\n\n/**\n * Returns a promise that rejects with a `TimeoutError` after a specified delay.\n *\n * @param {number} ms - The delay duration in milliseconds.\n * @returns {Promise<void>} A promise that rejects with a `TimeoutError` after the specified delay.\n * @throws {TimeoutError} Throws a `TimeoutError` after the specified delay.\n */\nexport async function timeout(ms: number): Promise<never> {\n await delay(ms);\n throw new TimeoutError();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIO,IAAM,aAAN,cAAyB,MAAM;AAAA,EACpC,YAAY,UAAU,6BAA6B;AACjD,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;;;AC6BO,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;;;ACrDO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtC,YAAY,UAAU,+BAA+B;AACnD,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;;;ACCA,SAAsB,QAAQ,IAA4B;AAAA;AACxD,UAAM,MAAM,EAAE;AACd,UAAM,IAAI,aAAa;AAAA,EACzB;AAAA;;;AJQA,SAAsB,YAAe,KAAuB,IAAwB;AAAA;AAClF,WAAO,QAAQ,KAAK,CAAC,IAAI,GAAG,QAAQ,EAAE,CAAM,CAAC;AAAA,EAC/C;AAAA;","names":[]}
@@ -0,0 +1,12 @@
1
+ import {
2
+ withTimeout
3
+ } from "../chunk-XWPCDIFC.mjs";
4
+ import "../chunk-J3GE7DEU.mjs";
5
+ import "../chunk-O64NE2P4.mjs";
6
+ import "../chunk-DXB7EZUQ.mjs";
7
+ import "../chunk-KIOYQRMQ.mjs";
8
+ import "../chunk-424M7IR7.mjs";
9
+ export {
10
+ withTimeout
11
+ };
12
+ //# sourceMappingURL=withTimeout.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -3,7 +3,7 @@ import {
3
3
  } from "../chunk-Y5V7UAZZ.mjs";
4
4
  import "../chunk-U56ZOM7L.mjs";
5
5
  import "../chunk-WVQ7YVRK.mjs";
6
- import "../chunk-2MM5EJJX.mjs";
6
+ import "../chunk-424M7IR7.mjs";
7
7
  export {
8
8
  camelCase
9
9
  };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  capitalize
3
3
  } from "../chunk-U56ZOM7L.mjs";
4
- import "../chunk-2MM5EJJX.mjs";
4
+ import "../chunk-424M7IR7.mjs";
5
5
  export {
6
6
  capitalize
7
7
  };
@@ -2,4 +2,5 @@ export { camelCase } from './camelCase.mjs';
2
2
  export { snakeCase } from './snakeCase.mjs';
3
3
  export { kebabCase } from './kebabCase.mjs';
4
4
  export { lowerCase } from './lowerCase.mjs';
5
+ export { startCase } from './startCase.mjs';
5
6
  export { capitalize } from './capitalize.mjs';
@@ -2,4 +2,5 @@ export { camelCase } from './camelCase.js';
2
2
  export { snakeCase } from './snakeCase.js';
3
3
  export { kebabCase } from './kebabCase.js';
4
4
  export { lowerCase } from './lowerCase.js';
5
+ export { startCase } from './startCase.js';
5
6
  export { capitalize } from './capitalize.js';