es-toolkit 1.10.1-dev.251 → 1.10.1-dev.253
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.
- package/dist/array/chunk.mjs +1 -1
- package/dist/array/compact.mjs +1 -1
- package/dist/array/countBy.mjs +1 -1
- package/dist/array/difference.mjs +1 -1
- package/dist/array/differenceBy.mjs +1 -1
- package/dist/array/differenceWith.mjs +1 -1
- package/dist/array/drop.mjs +1 -1
- package/dist/array/dropRight.mjs +1 -1
- package/dist/array/dropRightWhile.mjs +1 -1
- package/dist/array/dropWhile.mjs +1 -1
- package/dist/array/fill.mjs +1 -1
- package/dist/array/flatMap.mjs +1 -1
- package/dist/array/flatten.mjs +1 -1
- package/dist/array/flattenDeep.mjs +1 -1
- package/dist/array/forEachRight.mjs +1 -1
- package/dist/array/groupBy.mjs +1 -1
- package/dist/array/head.mjs +1 -1
- package/dist/array/index.mjs +20 -20
- package/dist/array/initial.mjs +1 -1
- package/dist/array/intersection.mjs +1 -1
- package/dist/array/intersectionBy.mjs +1 -1
- package/dist/array/intersectionWith.mjs +1 -1
- package/dist/array/keyBy.mjs +1 -1
- package/dist/array/last.mjs +1 -1
- package/dist/array/maxBy.mjs +1 -1
- package/dist/array/minBy.mjs +1 -1
- package/dist/array/orderBy.mjs +1 -1
- package/dist/array/partition.mjs +1 -1
- package/dist/array/sample.mjs +1 -1
- package/dist/array/sampleSize.mjs +1 -1
- package/dist/array/shuffle.mjs +1 -1
- package/dist/array/tail.mjs +1 -1
- package/dist/array/take.mjs +1 -1
- package/dist/array/takeRight.mjs +1 -1
- package/dist/array/takeRightWhile.mjs +1 -1
- package/dist/array/takeWhile.mjs +1 -1
- package/dist/array/toFilled.mjs +1 -1
- package/dist/array/union.mjs +1 -1
- package/dist/array/unionBy.mjs +1 -1
- package/dist/array/unionWith.mjs +1 -1
- package/dist/array/uniq.mjs +1 -1
- package/dist/array/uniqBy.mjs +1 -1
- package/dist/array/uniqWith.mjs +1 -1
- package/dist/array/unzip.mjs +1 -1
- package/dist/array/unzipWith.mjs +1 -1
- package/dist/array/without.mjs +1 -1
- package/dist/array/xor.mjs +1 -1
- package/dist/array/xorBy.mjs +1 -1
- package/dist/array/xorWith.mjs +1 -1
- package/dist/array/zip.mjs +1 -1
- package/dist/array/zipObject.mjs +1 -1
- package/dist/array/zipWith.mjs +1 -1
- package/dist/{chunk-2MM5EJJX.mjs → chunk-424M7IR7.mjs} +23 -2
- package/dist/chunk-4OIZM4HS.mjs +1 -0
- package/dist/chunk-F47GLYUU.mjs +1 -0
- package/dist/chunk-J3GE7DEU.mjs +22 -0
- package/dist/chunk-J3GE7DEU.mjs.map +1 -0
- package/dist/chunk-KIOYQRMQ.mjs +12 -0
- package/dist/chunk-KIOYQRMQ.mjs.map +1 -0
- package/dist/{chunk-QZITBKWX.mjs → chunk-U7V3G7CR.mjs} +2 -2
- package/dist/chunk-XWPCDIFC.mjs +18 -0
- package/dist/chunk-XWPCDIFC.mjs.map +1 -0
- package/dist/compat/index.d.mts +2 -0
- package/dist/compat/index.d.ts +2 -0
- package/dist/compat/index.js +47 -0
- package/dist/compat/index.js.map +1 -1
- package/dist/compat/index.mjs +59 -50
- package/dist/compat/index.mjs.map +1 -1
- package/dist/error/AbortError.mjs +1 -1
- package/dist/error/TimeoutError.d.mts +9 -0
- package/dist/error/TimeoutError.d.ts +9 -0
- package/dist/error/TimeoutError.js +36 -0
- package/dist/error/TimeoutError.js.map +1 -0
- package/dist/error/TimeoutError.mjs +8 -0
- package/dist/error/TimeoutError.mjs.map +1 -0
- package/dist/error/index.d.mts +1 -0
- package/dist/error/index.d.ts +1 -0
- package/dist/error/index.js +12 -2
- package/dist/error/index.js.map +1 -1
- package/dist/error/index.mjs +7 -3
- package/dist/function/debounce.mjs +1 -1
- package/dist/function/index.mjs +4 -4
- package/dist/function/negate.mjs +1 -1
- package/dist/function/noop.mjs +1 -1
- package/dist/function/once.mjs +1 -1
- package/dist/function/throttle.mjs +1 -1
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +59 -50
- package/dist/math/clamp.mjs +1 -1
- package/dist/math/inRange.mjs +1 -1
- package/dist/math/index.mjs +7 -7
- package/dist/math/mean.mjs +1 -1
- package/dist/math/meanBy.mjs +1 -1
- package/dist/math/random.mjs +1 -1
- package/dist/math/randomInt.mjs +1 -1
- package/dist/math/range.mjs +1 -1
- package/dist/math/round.mjs +1 -1
- package/dist/math/sum.mjs +1 -1
- package/dist/math/sumBy.mjs +1 -1
- package/dist/object/clone.mjs +1 -1
- package/dist/object/get.mjs +1 -1
- package/dist/object/index.mjs +5 -5
- package/dist/object/invert.mjs +1 -1
- package/dist/object/omit.mjs +2 -2
- package/dist/object/omitBy.mjs +1 -1
- package/dist/object/pick.mjs +1 -1
- package/dist/object/pickBy.mjs +1 -1
- package/dist/predicate/index.mjs +1 -1
- package/dist/predicate/isEqual.mjs +1 -1
- package/dist/predicate/isNil.mjs +1 -1
- package/dist/predicate/isNotNil.mjs +1 -1
- package/dist/predicate/isNull.mjs +1 -1
- package/dist/predicate/isUndefined.mjs +1 -1
- package/dist/promise/delay.mjs +1 -1
- package/dist/promise/index.d.mts +1 -0
- package/dist/promise/index.d.ts +1 -0
- package/dist/promise/index.js +47 -2
- package/dist/promise/index.js.map +1 -1
- package/dist/promise/index.mjs +9 -3
- package/dist/promise/timeout.d.mts +10 -0
- package/dist/promise/timeout.d.ts +10 -0
- package/dist/promise/timeout.js +92 -0
- package/dist/promise/timeout.js.map +1 -0
- package/dist/promise/timeout.mjs +11 -0
- package/dist/promise/timeout.mjs.map +1 -0
- package/dist/promise/withTimeout.d.mts +22 -0
- package/dist/promise/withTimeout.d.ts +22 -0
- package/dist/promise/withTimeout.js +99 -0
- package/dist/promise/withTimeout.js.map +1 -0
- package/dist/promise/withTimeout.mjs +12 -0
- package/dist/promise/withTimeout.mjs.map +1 -0
- package/dist/string/camelCase.mjs +1 -1
- package/dist/string/capitalize.mjs +1 -1
- package/dist/string/index.mjs +10 -10
- package/dist/string/kebabCase.mjs +1 -1
- package/dist/string/lowerCase.mjs +1 -1
- package/dist/string/snakeCase.mjs +1 -1
- package/dist/string/startCase.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-ARZ5BDR6.mjs +0 -1
- package/dist/chunk-FZEZH22H.mjs +0 -1
- /package/dist/{chunk-2MM5EJJX.mjs.map → chunk-424M7IR7.mjs.map} +0 -0
- /package/dist/{chunk-ARZ5BDR6.mjs.map → chunk-4OIZM4HS.mjs.map} +0 -0
- /package/dist/{chunk-FZEZH22H.mjs.map → chunk-F47GLYUU.mjs.map} +0 -0
- /package/dist/{chunk-QZITBKWX.mjs.map → chunk-U7V3G7CR.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-
|
|
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-
|
|
17
|
+
//# sourceMappingURL=chunk-U7V3G7CR.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":[]}
|
package/dist/compat/index.d.mts
CHANGED
|
@@ -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,6 +78,7 @@ 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';
|
package/dist/compat/index.d.ts
CHANGED
|
@@ -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,6 +78,7 @@ 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';
|
package/dist/compat/index.js
CHANGED
|
@@ -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();
|
|
@@ -1137,6 +1182,7 @@ var endsWith = (str, target, position = str.length) => {
|
|
|
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 @@ var endsWith = (str, target, position = str.length) => {
|
|
|
1218
1264
|
uniqWith,
|
|
1219
1265
|
unzip,
|
|
1220
1266
|
unzipWith,
|
|
1267
|
+
withTimeout,
|
|
1221
1268
|
without,
|
|
1222
1269
|
xor,
|
|
1223
1270
|
xorBy,
|