es-toolkit 1.10.1-dev.250 → 1.10.1-dev.252

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 (168) hide show
  1. package/dist/array/chunk.mjs +1 -1
  2. package/dist/array/compact.mjs +1 -1
  3. package/dist/array/countBy.mjs +1 -1
  4. package/dist/array/difference.mjs +1 -1
  5. package/dist/array/differenceBy.mjs +1 -1
  6. package/dist/array/differenceWith.mjs +1 -1
  7. package/dist/array/drop.mjs +1 -1
  8. package/dist/array/dropRight.mjs +1 -1
  9. package/dist/array/dropRightWhile.mjs +1 -1
  10. package/dist/array/dropWhile.mjs +1 -1
  11. package/dist/array/fill.mjs +1 -1
  12. package/dist/array/flatMap.mjs +1 -1
  13. package/dist/array/flatten.mjs +1 -1
  14. package/dist/array/flattenDeep.mjs +1 -1
  15. package/dist/array/forEachRight.mjs +1 -1
  16. package/dist/array/groupBy.mjs +1 -1
  17. package/dist/array/head.mjs +1 -1
  18. package/dist/array/index.mjs +20 -20
  19. package/dist/array/initial.mjs +1 -1
  20. package/dist/array/intersection.mjs +1 -1
  21. package/dist/array/intersectionBy.mjs +1 -1
  22. package/dist/array/intersectionWith.mjs +1 -1
  23. package/dist/array/keyBy.mjs +1 -1
  24. package/dist/array/last.mjs +1 -1
  25. package/dist/array/maxBy.mjs +1 -1
  26. package/dist/array/minBy.mjs +1 -1
  27. package/dist/array/orderBy.mjs +1 -1
  28. package/dist/array/partition.mjs +1 -1
  29. package/dist/array/sample.mjs +1 -1
  30. package/dist/array/sampleSize.mjs +1 -1
  31. package/dist/array/shuffle.mjs +1 -1
  32. package/dist/array/tail.mjs +1 -1
  33. package/dist/array/take.mjs +1 -1
  34. package/dist/array/takeRight.mjs +1 -1
  35. package/dist/array/takeRightWhile.mjs +1 -1
  36. package/dist/array/takeWhile.mjs +1 -1
  37. package/dist/array/toFilled.mjs +1 -1
  38. package/dist/array/union.mjs +1 -1
  39. package/dist/array/unionBy.mjs +1 -1
  40. package/dist/array/unionWith.mjs +1 -1
  41. package/dist/array/uniq.mjs +1 -1
  42. package/dist/array/uniqBy.mjs +1 -1
  43. package/dist/array/uniqWith.mjs +1 -1
  44. package/dist/array/unzip.mjs +1 -1
  45. package/dist/array/unzipWith.mjs +1 -1
  46. package/dist/array/without.mjs +1 -1
  47. package/dist/array/xor.mjs +1 -1
  48. package/dist/array/xorBy.mjs +1 -1
  49. package/dist/array/xorWith.mjs +1 -1
  50. package/dist/array/zip.mjs +1 -1
  51. package/dist/array/zipObject.mjs +1 -1
  52. package/dist/array/zipWith.mjs +1 -1
  53. package/dist/{chunk-2MM5EJJX.mjs → chunk-424M7IR7.mjs} +23 -2
  54. package/dist/chunk-4OIZM4HS.mjs +1 -0
  55. package/dist/chunk-F47GLYUU.mjs +1 -0
  56. package/dist/chunk-J3GE7DEU.mjs +22 -0
  57. package/dist/chunk-J3GE7DEU.mjs.map +1 -0
  58. package/dist/chunk-KIOYQRMQ.mjs +12 -0
  59. package/dist/chunk-KIOYQRMQ.mjs.map +1 -0
  60. package/dist/{chunk-QZITBKWX.mjs → chunk-U7V3G7CR.mjs} +2 -2
  61. package/dist/chunk-XT74R35S.mjs +1 -0
  62. package/dist/chunk-XWPCDIFC.mjs +18 -0
  63. package/dist/chunk-XWPCDIFC.mjs.map +1 -0
  64. package/dist/compat/index.d.mts +41 -3
  65. package/dist/compat/index.d.ts +41 -3
  66. package/dist/compat/index.js +57 -10
  67. package/dist/compat/index.js.map +1 -1
  68. package/dist/compat/index.mjs +68 -55
  69. package/dist/compat/index.mjs.map +1 -1
  70. package/dist/error/AbortError.mjs +1 -1
  71. package/dist/error/TimeoutError.d.mts +9 -0
  72. package/dist/error/TimeoutError.d.ts +9 -0
  73. package/dist/{string/startsWith.js → error/TimeoutError.js} +12 -9
  74. package/dist/error/TimeoutError.js.map +1 -0
  75. package/dist/error/TimeoutError.mjs +8 -0
  76. package/dist/error/index.d.mts +1 -0
  77. package/dist/error/index.d.ts +1 -0
  78. package/dist/error/index.js +12 -2
  79. package/dist/error/index.js.map +1 -1
  80. package/dist/error/index.mjs +7 -3
  81. package/dist/function/debounce.mjs +1 -1
  82. package/dist/function/index.mjs +4 -4
  83. package/dist/function/negate.mjs +1 -1
  84. package/dist/function/noop.mjs +1 -1
  85. package/dist/function/once.mjs +1 -1
  86. package/dist/function/throttle.mjs +1 -1
  87. package/dist/index.d.mts +2 -2
  88. package/dist/index.d.ts +2 -2
  89. package/dist/index.js +47 -14
  90. package/dist/index.js.map +1 -1
  91. package/dist/index.mjs +58 -57
  92. package/dist/math/clamp.mjs +1 -1
  93. package/dist/math/inRange.mjs +1 -1
  94. package/dist/math/index.mjs +7 -7
  95. package/dist/math/mean.mjs +1 -1
  96. package/dist/math/meanBy.mjs +1 -1
  97. package/dist/math/random.mjs +1 -1
  98. package/dist/math/randomInt.mjs +1 -1
  99. package/dist/math/range.mjs +1 -1
  100. package/dist/math/round.mjs +1 -1
  101. package/dist/math/sum.mjs +1 -1
  102. package/dist/math/sumBy.mjs +1 -1
  103. package/dist/object/clone.mjs +1 -1
  104. package/dist/object/get.mjs +1 -1
  105. package/dist/object/index.mjs +5 -5
  106. package/dist/object/invert.mjs +1 -1
  107. package/dist/object/omit.mjs +2 -2
  108. package/dist/object/omitBy.mjs +1 -1
  109. package/dist/object/pick.mjs +1 -1
  110. package/dist/object/pickBy.mjs +1 -1
  111. package/dist/predicate/index.mjs +1 -1
  112. package/dist/predicate/isEqual.mjs +1 -1
  113. package/dist/predicate/isNil.mjs +1 -1
  114. package/dist/predicate/isNotNil.mjs +1 -1
  115. package/dist/predicate/isNull.mjs +1 -1
  116. package/dist/predicate/isUndefined.mjs +1 -1
  117. package/dist/promise/delay.mjs +1 -1
  118. package/dist/promise/index.d.mts +1 -0
  119. package/dist/promise/index.d.ts +1 -0
  120. package/dist/promise/index.js +47 -2
  121. package/dist/promise/index.js.map +1 -1
  122. package/dist/promise/index.mjs +9 -3
  123. package/dist/promise/timeout.d.mts +10 -0
  124. package/dist/promise/timeout.d.ts +10 -0
  125. package/dist/promise/timeout.js +92 -0
  126. package/dist/promise/timeout.js.map +1 -0
  127. package/dist/promise/timeout.mjs +11 -0
  128. package/dist/promise/withTimeout.d.mts +22 -0
  129. package/dist/promise/withTimeout.d.ts +22 -0
  130. package/dist/promise/withTimeout.js +99 -0
  131. package/dist/promise/withTimeout.js.map +1 -0
  132. package/dist/promise/withTimeout.mjs +12 -0
  133. package/dist/promise/withTimeout.mjs.map +1 -0
  134. package/dist/string/camelCase.mjs +1 -1
  135. package/dist/string/capitalize.mjs +1 -1
  136. package/dist/string/index.d.mts +0 -2
  137. package/dist/string/index.d.ts +0 -2
  138. package/dist/string/index.js +2 -16
  139. package/dist/string/index.js.map +1 -1
  140. package/dist/string/index.mjs +9 -17
  141. package/dist/string/kebabCase.mjs +1 -1
  142. package/dist/string/lowerCase.mjs +1 -1
  143. package/dist/string/snakeCase.mjs +1 -1
  144. package/dist/string/startCase.mjs +1 -1
  145. package/package.json +1 -1
  146. package/dist/chunk-ARZ5BDR6.mjs +0 -1
  147. package/dist/chunk-FZEZH22H.mjs +0 -1
  148. package/dist/chunk-SR5RPVRM.mjs +0 -9
  149. package/dist/chunk-SR5RPVRM.mjs.map +0 -1
  150. package/dist/chunk-YCTGSM4S.mjs +0 -1
  151. package/dist/chunk-ZFRI6VS4.mjs +0 -9
  152. package/dist/chunk-ZFRI6VS4.mjs.map +0 -1
  153. package/dist/string/endsWith.d.mts +0 -20
  154. package/dist/string/endsWith.d.ts +0 -20
  155. package/dist/string/endsWith.js +0 -33
  156. package/dist/string/endsWith.js.map +0 -1
  157. package/dist/string/endsWith.mjs +0 -8
  158. package/dist/string/startsWith.d.mts +0 -20
  159. package/dist/string/startsWith.d.ts +0 -20
  160. package/dist/string/startsWith.js.map +0 -1
  161. package/dist/string/startsWith.mjs +0 -8
  162. /package/dist/{chunk-2MM5EJJX.mjs.map → chunk-424M7IR7.mjs.map} +0 -0
  163. /package/dist/{chunk-ARZ5BDR6.mjs.map → chunk-4OIZM4HS.mjs.map} +0 -0
  164. /package/dist/{chunk-FZEZH22H.mjs.map → chunk-F47GLYUU.mjs.map} +0 -0
  165. /package/dist/{chunk-QZITBKWX.mjs.map → chunk-U7V3G7CR.mjs.map} +0 -0
  166. /package/dist/{chunk-YCTGSM4S.mjs.map → chunk-XT74R35S.mjs.map} +0 -0
  167. /package/dist/{string/endsWith.mjs.map → error/TimeoutError.mjs.map} +0 -0
  168. /package/dist/{string/startsWith.mjs.map → promise/timeout.mjs.map} +0 -0
@@ -0,0 +1,22 @@
1
+ import {
2
+ delay
3
+ } from "./chunk-O64NE2P4.mjs";
4
+ import {
5
+ TimeoutError
6
+ } from "./chunk-KIOYQRMQ.mjs";
7
+ import {
8
+ __async
9
+ } from "./chunk-424M7IR7.mjs";
10
+
11
+ // src/promise/timeout.ts
12
+ function timeout(ms) {
13
+ return __async(this, null, function* () {
14
+ yield delay(ms);
15
+ throw new TimeoutError();
16
+ });
17
+ }
18
+
19
+ export {
20
+ timeout
21
+ };
22
+ //# sourceMappingURL=chunk-J3GE7DEU.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/promise/timeout.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"],"mappings":";;;;;;;;;;;AAUA,SAAsB,QAAQ,IAA4B;AAAA;AACxD,UAAM,MAAM,EAAE;AACd,UAAM,IAAI,aAAa;AAAA,EACzB;AAAA;","names":[]}
@@ -0,0 +1,12 @@
1
+ // src/error/TimeoutError.ts
2
+ var TimeoutError = class extends Error {
3
+ constructor(message = "The operation was timed out") {
4
+ super(message);
5
+ this.name = "TimeoutError";
6
+ }
7
+ };
8
+
9
+ export {
10
+ TimeoutError
11
+ };
12
+ //# sourceMappingURL=chunk-KIOYQRMQ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/error/TimeoutError.ts"],"sourcesContent":["/**\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":";AAIO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtC,YAAY,UAAU,+BAA+B;AACnD,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  __spreadValues
3
- } from "./chunk-2MM5EJJX.mjs";
3
+ } from "./chunk-424M7IR7.mjs";
4
4
 
5
5
  // src/object/omit.ts
6
6
  function omit(obj, keys) {
@@ -14,4 +14,4 @@ function omit(obj, keys) {
14
14
  export {
15
15
  omit
16
16
  };
17
- //# sourceMappingURL=chunk-QZITBKWX.mjs.map
17
+ //# sourceMappingURL=chunk-U7V3G7CR.mjs.map
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-XT74R35S.mjs.map
@@ -0,0 +1,18 @@
1
+ import {
2
+ timeout
3
+ } from "./chunk-J3GE7DEU.mjs";
4
+ import {
5
+ __async
6
+ } from "./chunk-424M7IR7.mjs";
7
+
8
+ // src/promise/withTimeout.ts
9
+ function withTimeout(run, ms) {
10
+ return __async(this, null, function* () {
11
+ return Promise.race([run(), timeout(ms)]);
12
+ });
13
+ }
14
+
15
+ export {
16
+ withTimeout
17
+ };
18
+ //# sourceMappingURL=chunk-XWPCDIFC.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/promise/withTimeout.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"],"mappings":";;;;;;;;AAqBA,SAAsB,YAAe,KAAuB,IAAwB;AAAA;AAClF,WAAO,QAAQ,KAAK,CAAC,IAAI,GAAG,QAAQ,EAAE,CAAM,CAAC;AAAA,EAC/C;AAAA;","names":[]}
@@ -49,6 +49,7 @@ export { toFilled } from '../array/toFilled.mjs';
49
49
  export { last } from '../array/last.mjs';
50
50
  export { initial } from '../array/initial.mjs';
51
51
  export { AbortError } from '../error/AbortError.mjs';
52
+ export { TimeoutError } from '../error/TimeoutError.mjs';
52
53
  export { debounce } from '../function/debounce.mjs';
53
54
  export { noop } from '../function/noop.mjs';
54
55
  export { once } from '../function/once.mjs';
@@ -77,13 +78,12 @@ export { isNotNil } from '../predicate/isNotNil.mjs';
77
78
  export { isNull } from '../predicate/isNull.mjs';
78
79
  export { isUndefined } from '../predicate/isUndefined.mjs';
79
80
  export { delay } from '../promise/delay.mjs';
81
+ export { withTimeout } from '../promise/withTimeout.mjs';
80
82
  export { camelCase } from '../string/camelCase.mjs';
81
83
  export { snakeCase } from '../string/snakeCase.mjs';
82
84
  export { kebabCase } from '../string/kebabCase.mjs';
83
85
  export { lowerCase } from '../string/lowerCase.mjs';
84
86
  export { startCase } from '../string/startCase.mjs';
85
- export { startsWith } from '../string/startsWith.mjs';
86
- export { endsWith } from '../string/endsWith.mjs';
87
87
  export { capitalize } from '../string/capitalize.mjs';
88
88
 
89
89
  /**
@@ -176,4 +176,42 @@ declare function zipObjectDeep<P extends string | number | symbol, V>(keys: P[],
176
176
  */
177
177
  declare function set<T>(obj: object, path: PropertyKey | readonly PropertyKey[], value: unknown): T;
178
178
 
179
- export { chunk, set, zipObjectDeep };
179
+ /**
180
+ * Checks if a string contains another string at the beginning of the string.
181
+ *
182
+ * Checks if one string startsWith another string. Optional position parameter to start searching from a certain index.
183
+ *
184
+ * @param {string} str - The string that might contain the target string.
185
+ * @param {string} target - The string to search for.
186
+ * @param {number} position - An optional offset to start searching in the str string
187
+ * @returns {boolean} - True if the str string starts with the target string.
188
+ *
189
+ * @example
190
+ * const isPrefix = startsWith('fooBar', 'foo') // returns true
191
+ * const isPrefix = startsWith('fooBar', 'bar') // returns false
192
+ * const isPrefix = startsWith('fooBar', 'abc') // returns false
193
+ * const isPrefix = startsWith('fooBar', 'Bar', 2) // returns true
194
+ * const isPrefix = startsWith('fooBar', 'Bar', 5) // returns false
195
+ */
196
+ declare const startsWith: (str: string, target: string, position?: number) => boolean;
197
+
198
+ /**
199
+ * Checks if a string contains another string at the end of the string.
200
+ *
201
+ * Checks if one string endsWith another string. Optional position parameter to offset searching before a certain index.
202
+ *
203
+ * @param {string} str - The string that might contain the target string.
204
+ * @param {string} target - The string to search for.
205
+ * @param {number} position - An optional position from the start to search up to this index
206
+ * @returns {boolean} - True if the str string ends with the target string.
207
+ *
208
+ * @example
209
+ * const isPrefix = endsWith('fooBar', 'foo') // returns true
210
+ * const isPrefix = endsWith('fooBar', 'bar') // returns false
211
+ * const isPrefix = endsWith('fooBar', 'abc') // returns false
212
+ * const isPrefix = endsWith('fooBar', 'foo', 3) // returns true
213
+ * const isPrefix = endsWith('fooBar', 'abc', 5) // returns false
214
+ */
215
+ declare const endsWith: (str: string, target: string, position?: number) => boolean;
216
+
217
+ export { chunk, endsWith, set, startsWith, zipObjectDeep };
@@ -49,6 +49,7 @@ export { toFilled } from '../array/toFilled.js';
49
49
  export { last } from '../array/last.js';
50
50
  export { initial } from '../array/initial.js';
51
51
  export { AbortError } from '../error/AbortError.js';
52
+ export { TimeoutError } from '../error/TimeoutError.js';
52
53
  export { debounce } from '../function/debounce.js';
53
54
  export { noop } from '../function/noop.js';
54
55
  export { once } from '../function/once.js';
@@ -77,13 +78,12 @@ export { isNotNil } from '../predicate/isNotNil.js';
77
78
  export { isNull } from '../predicate/isNull.js';
78
79
  export { isUndefined } from '../predicate/isUndefined.js';
79
80
  export { delay } from '../promise/delay.js';
81
+ export { withTimeout } from '../promise/withTimeout.js';
80
82
  export { camelCase } from '../string/camelCase.js';
81
83
  export { snakeCase } from '../string/snakeCase.js';
82
84
  export { kebabCase } from '../string/kebabCase.js';
83
85
  export { lowerCase } from '../string/lowerCase.js';
84
86
  export { startCase } from '../string/startCase.js';
85
- export { startsWith } from '../string/startsWith.js';
86
- export { endsWith } from '../string/endsWith.js';
87
87
  export { capitalize } from '../string/capitalize.js';
88
88
 
89
89
  /**
@@ -176,4 +176,42 @@ declare function zipObjectDeep<P extends string | number | symbol, V>(keys: P[],
176
176
  */
177
177
  declare function set<T>(obj: object, path: PropertyKey | readonly PropertyKey[], value: unknown): T;
178
178
 
179
- export { chunk, set, zipObjectDeep };
179
+ /**
180
+ * Checks if a string contains another string at the beginning of the string.
181
+ *
182
+ * Checks if one string startsWith another string. Optional position parameter to start searching from a certain index.
183
+ *
184
+ * @param {string} str - The string that might contain the target string.
185
+ * @param {string} target - The string to search for.
186
+ * @param {number} position - An optional offset to start searching in the str string
187
+ * @returns {boolean} - True if the str string starts with the target string.
188
+ *
189
+ * @example
190
+ * const isPrefix = startsWith('fooBar', 'foo') // returns true
191
+ * const isPrefix = startsWith('fooBar', 'bar') // returns false
192
+ * const isPrefix = startsWith('fooBar', 'abc') // returns false
193
+ * const isPrefix = startsWith('fooBar', 'Bar', 2) // returns true
194
+ * const isPrefix = startsWith('fooBar', 'Bar', 5) // returns false
195
+ */
196
+ declare const startsWith: (str: string, target: string, position?: number) => boolean;
197
+
198
+ /**
199
+ * Checks if a string contains another string at the end of the string.
200
+ *
201
+ * Checks if one string endsWith another string. Optional position parameter to offset searching before a certain index.
202
+ *
203
+ * @param {string} str - The string that might contain the target string.
204
+ * @param {string} target - The string to search for.
205
+ * @param {number} position - An optional position from the start to search up to this index
206
+ * @returns {boolean} - True if the str string ends with the target string.
207
+ *
208
+ * @example
209
+ * const isPrefix = endsWith('fooBar', 'foo') // returns true
210
+ * const isPrefix = endsWith('fooBar', 'bar') // returns false
211
+ * const isPrefix = endsWith('fooBar', 'abc') // returns false
212
+ * const isPrefix = endsWith('fooBar', 'foo', 3) // returns true
213
+ * const isPrefix = endsWith('fooBar', 'abc', 5) // returns false
214
+ */
215
+ declare const endsWith: (str: string, target: string, position?: number) => boolean;
216
+
217
+ export { chunk, endsWith, set, startsWith, zipObjectDeep };
@@ -30,11 +30,32 @@ var __copyProps = (to, from, except, desc) => {
30
30
  return to;
31
31
  };
32
32
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
33
+ var __async = (__this, __arguments, generator) => {
34
+ return new Promise((resolve, reject) => {
35
+ var fulfilled = (value) => {
36
+ try {
37
+ step(generator.next(value));
38
+ } catch (e) {
39
+ reject(e);
40
+ }
41
+ };
42
+ var rejected = (value) => {
43
+ try {
44
+ step(generator.throw(value));
45
+ } catch (e) {
46
+ reject(e);
47
+ }
48
+ };
49
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
50
+ step((generator = generator.apply(__this, __arguments)).next());
51
+ });
52
+ };
33
53
 
34
54
  // src/compat/index.ts
35
55
  var compat_exports = {};
36
56
  __export(compat_exports, {
37
57
  AbortError: () => AbortError,
58
+ TimeoutError: () => TimeoutError,
38
59
  camelCase: () => camelCase,
39
60
  capitalize: () => capitalize,
40
61
  chunk: () => chunk2,
@@ -116,6 +137,7 @@ __export(compat_exports, {
116
137
  uniqWith: () => uniqWith,
117
138
  unzip: () => unzip,
118
139
  unzipWith: () => unzipWith,
140
+ withTimeout: () => withTimeout,
119
141
  without: () => without,
120
142
  xor: () => xor,
121
143
  xorBy: () => xorBy,
@@ -656,6 +678,14 @@ var AbortError = class extends Error {
656
678
  }
657
679
  };
658
680
 
681
+ // src/error/TimeoutError.ts
682
+ var TimeoutError = class extends Error {
683
+ constructor(message = "The operation was timed out") {
684
+ super(message);
685
+ this.name = "TimeoutError";
686
+ }
687
+ };
688
+
659
689
  // src/function/debounce.ts
660
690
  function debounce(func, debounceMs, { signal } = {}) {
661
691
  let timeoutId = null;
@@ -988,6 +1018,21 @@ function delay(ms, { signal } = {}) {
988
1018
  });
989
1019
  }
990
1020
 
1021
+ // src/promise/timeout.ts
1022
+ function timeout(ms) {
1023
+ return __async(this, null, function* () {
1024
+ yield delay(ms);
1025
+ throw new TimeoutError();
1026
+ });
1027
+ }
1028
+
1029
+ // src/promise/withTimeout.ts
1030
+ function withTimeout(run, ms) {
1031
+ return __async(this, null, function* () {
1032
+ return Promise.race([run(), timeout(ms)]);
1033
+ });
1034
+ }
1035
+
991
1036
  // src/string/capitalize.ts
992
1037
  var capitalize = (str) => {
993
1038
  return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
@@ -1045,16 +1090,6 @@ function startCase(str) {
1045
1090
  return result;
1046
1091
  }
1047
1092
 
1048
- // src/string/startsWith.ts
1049
- var startsWith = (str, target, position = 0) => {
1050
- return str.startsWith(target, position);
1051
- };
1052
-
1053
- // src/string/endsWith.ts
1054
- var endsWith = (str, target, position = str.length) => {
1055
- return str.endsWith(target, position);
1056
- };
1057
-
1058
1093
  // src/compat/array/chunk.ts
1059
1094
  function chunk2(arr, size = 1) {
1060
1095
  size = Math.max(Math.floor(size), 0);
@@ -1134,9 +1169,20 @@ function zipObjectDeep(keys, values) {
1134
1169
  }
1135
1170
  return result;
1136
1171
  }
1172
+
1173
+ // src/compat/string/startsWith.ts
1174
+ var startsWith = (str, target, position = 0) => {
1175
+ return str.startsWith(target, position);
1176
+ };
1177
+
1178
+ // src/compat/string/endsWith.ts
1179
+ var endsWith = (str, target, position = str.length) => {
1180
+ return str.endsWith(target, position);
1181
+ };
1137
1182
  // Annotate the CommonJS export names for ESM import in node:
1138
1183
  0 && (module.exports = {
1139
1184
  AbortError,
1185
+ TimeoutError,
1140
1186
  camelCase,
1141
1187
  capitalize,
1142
1188
  chunk,
@@ -1218,6 +1264,7 @@ function zipObjectDeep(keys, values) {
1218
1264
  uniqWith,
1219
1265
  unzip,
1220
1266
  unzipWith,
1267
+ withTimeout,
1221
1268
  without,
1222
1269
  xor,
1223
1270
  xorBy,