es-toolkit 1.31.0-dev.994 → 1.31.0-dev.996
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/_chunk/AbortError-Cg4ZQ1.js +10 -0
- package/dist/_chunk/delay-_VMfFa.js +25 -0
- package/dist/_chunk/{isWeakSet-CvIdTA.js → isWeakSet-BgjERb.js} +5 -0
- package/dist/_chunk/{unary-B6qG7C.js → unary-c1NFA5.js} +35 -0
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/index.d.mts +2 -0
- package/dist/compat/index.d.ts +2 -0
- package/dist/compat/index.js +6 -3
- package/dist/compat/index.mjs +2 -0
- package/dist/error/index.js +2 -7
- package/dist/function/index.d.mts +1 -0
- package/dist/function/index.d.ts +1 -0
- package/dist/function/index.js +2 -1
- package/dist/function/index.mjs +1 -0
- package/dist/function/retry.d.mts +59 -0
- package/dist/function/retry.d.ts +59 -0
- package/dist/function/retry.mjs +35 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +8 -4
- package/dist/index.mjs +2 -0
- package/dist/predicate/index.d.mts +1 -0
- package/dist/predicate/index.d.ts +1 -0
- package/dist/predicate/index.js +2 -1
- package/dist/predicate/index.mjs +1 -0
- package/dist/predicate/isPromise.d.mts +20 -0
- package/dist/predicate/isPromise.d.ts +20 -0
- package/dist/predicate/isPromise.mjs +5 -0
- package/dist/promise/index.js +3 -22
- package/package.json +1 -1
package/dist/compat/index.d.mts
CHANGED
|
@@ -36,6 +36,7 @@ export { noop } from '../function/noop.mjs';
|
|
|
36
36
|
export { once } from '../function/once.mjs';
|
|
37
37
|
export { partial } from '../function/partial.mjs';
|
|
38
38
|
export { partialRight } from '../function/partialRight.mjs';
|
|
39
|
+
export { retry } from '../function/retry.mjs';
|
|
39
40
|
export { ThrottledFunction } from '../function/throttle.mjs';
|
|
40
41
|
export { unary } from '../function/unary.mjs';
|
|
41
42
|
export { mean } from '../math/mean.mjs';
|
|
@@ -58,6 +59,7 @@ export { isLength } from '../predicate/isLength.mjs';
|
|
|
58
59
|
export { isNotNil } from '../predicate/isNotNil.mjs';
|
|
59
60
|
export { isNull } from '../predicate/isNull.mjs';
|
|
60
61
|
export { isPrimitive } from '../predicate/isPrimitive.mjs';
|
|
62
|
+
export { isPromise } from '../predicate/isPromise.mjs';
|
|
61
63
|
export { isUndefined } from '../predicate/isUndefined.mjs';
|
|
62
64
|
export { timeout } from '../promise/timeout.mjs';
|
|
63
65
|
export { withTimeout } from '../promise/withTimeout.mjs';
|
package/dist/compat/index.d.ts
CHANGED
|
@@ -36,6 +36,7 @@ export { noop } from '../function/noop.js';
|
|
|
36
36
|
export { once } from '../function/once.js';
|
|
37
37
|
export { partial } from '../function/partial.js';
|
|
38
38
|
export { partialRight } from '../function/partialRight.js';
|
|
39
|
+
export { retry } from '../function/retry.js';
|
|
39
40
|
export { ThrottledFunction } from '../function/throttle.js';
|
|
40
41
|
export { unary } from '../function/unary.js';
|
|
41
42
|
export { mean } from '../math/mean.js';
|
|
@@ -58,6 +59,7 @@ export { isLength } from '../predicate/isLength.js';
|
|
|
58
59
|
export { isNotNil } from '../predicate/isNotNil.js';
|
|
59
60
|
export { isNull } from '../predicate/isNull.js';
|
|
60
61
|
export { isPrimitive } from '../predicate/isPrimitive.js';
|
|
62
|
+
export { isPromise } from '../predicate/isPromise.js';
|
|
61
63
|
export { isUndefined } from '../predicate/isUndefined.js';
|
|
62
64
|
export { timeout } from '../promise/timeout.js';
|
|
63
65
|
export { withTimeout } from '../promise/withTimeout.js';
|
package/dist/compat/index.js
CHANGED
|
@@ -3,14 +3,15 @@
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
5
|
const zipWith = require('../_chunk/zipWith-Bdyzuy.js');
|
|
6
|
+
const AbortError = require('../_chunk/AbortError-Cg4ZQ1.js');
|
|
6
7
|
const error_index = require('../error/index.js');
|
|
7
|
-
const unary = require('../_chunk/unary-
|
|
8
|
+
const unary = require('../_chunk/unary-c1NFA5.js');
|
|
8
9
|
const noop = require('../_chunk/noop-2IwLUk.js');
|
|
9
10
|
const range$1 = require('../_chunk/range-HnEIT7.js');
|
|
10
11
|
const randomInt = require('../_chunk/randomInt-CF7bZK.js');
|
|
11
12
|
const toMerged = require('../_chunk/toMerged-DGFrN7.js');
|
|
12
13
|
const isPlainObject$1 = require('../_chunk/isPlainObject-octpoD.js');
|
|
13
|
-
const isWeakSet$1 = require('../_chunk/isWeakSet-
|
|
14
|
+
const isWeakSet$1 = require('../_chunk/isWeakSet-BgjERb.js');
|
|
14
15
|
const promise_index = require('../promise/index.js');
|
|
15
16
|
const upperFirst$1 = require('../_chunk/upperFirst-CorAVn.js');
|
|
16
17
|
const util_index = require('../util/index.js');
|
|
@@ -3103,7 +3104,7 @@ exports.xorBy = zipWith.xorBy;
|
|
|
3103
3104
|
exports.xorWith = zipWith.xorWith;
|
|
3104
3105
|
exports.zipObject = zipWith.zipObject;
|
|
3105
3106
|
exports.zipWith = zipWith.zipWith;
|
|
3106
|
-
exports.AbortError =
|
|
3107
|
+
exports.AbortError = AbortError.AbortError;
|
|
3107
3108
|
exports.TimeoutError = error_index.TimeoutError;
|
|
3108
3109
|
exports.asyncNoop = unary.asyncNoop;
|
|
3109
3110
|
exports.identity = unary.identity;
|
|
@@ -3111,6 +3112,7 @@ exports.memoize = unary.memoize;
|
|
|
3111
3112
|
exports.once = unary.once;
|
|
3112
3113
|
exports.partial = unary.partial;
|
|
3113
3114
|
exports.partialRight = unary.partialRight;
|
|
3115
|
+
exports.retry = unary.retry;
|
|
3114
3116
|
exports.unary = unary.unary;
|
|
3115
3117
|
exports.noop = noop.noop;
|
|
3116
3118
|
exports.mean = range$1.mean;
|
|
@@ -3137,6 +3139,7 @@ exports.isJSONValue = isWeakSet$1.isJSONValue;
|
|
|
3137
3139
|
exports.isLength = isWeakSet$1.isLength;
|
|
3138
3140
|
exports.isNotNil = isWeakSet$1.isNotNil;
|
|
3139
3141
|
exports.isNull = isWeakSet$1.isNull;
|
|
3142
|
+
exports.isPromise = isWeakSet$1.isPromise;
|
|
3140
3143
|
exports.isUndefined = isWeakSet$1.isUndefined;
|
|
3141
3144
|
exports.timeout = promise_index.timeout;
|
|
3142
3145
|
exports.withTimeout = promise_index.withTimeout;
|
package/dist/compat/index.mjs
CHANGED
|
@@ -36,6 +36,7 @@ export { noop } from '../function/noop.mjs';
|
|
|
36
36
|
export { once } from '../function/once.mjs';
|
|
37
37
|
export { partial } from '../function/partial.mjs';
|
|
38
38
|
export { partialRight } from '../function/partialRight.mjs';
|
|
39
|
+
export { retry } from '../function/retry.mjs';
|
|
39
40
|
export { unary } from '../function/unary.mjs';
|
|
40
41
|
export { mean } from '../math/mean.mjs';
|
|
41
42
|
export { meanBy } from '../math/meanBy.mjs';
|
|
@@ -59,6 +60,7 @@ export { isJSONArray, isJSONObject, isJSONValue } from '../predicate/isJSONValue
|
|
|
59
60
|
export { isLength } from '../predicate/isLength.mjs';
|
|
60
61
|
export { isNotNil } from '../predicate/isNotNil.mjs';
|
|
61
62
|
export { isNull } from '../predicate/isNull.mjs';
|
|
63
|
+
export { isPromise } from '../predicate/isPromise.mjs';
|
|
62
64
|
export { isUndefined } from '../predicate/isUndefined.mjs';
|
|
63
65
|
export { timeout } from '../promise/timeout.mjs';
|
|
64
66
|
export { withTimeout } from '../promise/withTimeout.mjs';
|
package/dist/error/index.js
CHANGED
|
@@ -2,12 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
constructor(message = 'The operation was aborted') {
|
|
7
|
-
super(message);
|
|
8
|
-
this.name = 'AbortError';
|
|
9
|
-
}
|
|
10
|
-
}
|
|
5
|
+
const AbortError = require('../_chunk/AbortError-Cg4ZQ1.js');
|
|
11
6
|
|
|
12
7
|
class TimeoutError extends Error {
|
|
13
8
|
constructor(message = 'The operation was timed out') {
|
|
@@ -16,5 +11,5 @@ class TimeoutError extends Error {
|
|
|
16
11
|
}
|
|
17
12
|
}
|
|
18
13
|
|
|
19
|
-
exports.AbortError = AbortError;
|
|
14
|
+
exports.AbortError = AbortError.AbortError;
|
|
20
15
|
exports.TimeoutError = TimeoutError;
|
|
@@ -15,6 +15,7 @@ export { once } from './once.mjs';
|
|
|
15
15
|
export { partial } from './partial.mjs';
|
|
16
16
|
export { partialRight } from './partialRight.mjs';
|
|
17
17
|
export { rest } from './rest.mjs';
|
|
18
|
+
export { retry } from './retry.mjs';
|
|
18
19
|
export { spread } from './spread.mjs';
|
|
19
20
|
export { ThrottledFunction, throttle } from './throttle.mjs';
|
|
20
21
|
export { unary } from './unary.mjs';
|
package/dist/function/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export { once } from './once.js';
|
|
|
15
15
|
export { partial } from './partial.js';
|
|
16
16
|
export { partialRight } from './partialRight.js';
|
|
17
17
|
export { rest } from './rest.js';
|
|
18
|
+
export { retry } from './retry.js';
|
|
18
19
|
export { spread } from './spread.js';
|
|
19
20
|
export { ThrottledFunction, throttle } from './throttle.js';
|
|
20
21
|
export { unary } from './unary.js';
|
package/dist/function/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const unary = require('../_chunk/unary-
|
|
5
|
+
const unary = require('../_chunk/unary-c1NFA5.js');
|
|
6
6
|
const noop = require('../_chunk/noop-2IwLUk.js');
|
|
7
7
|
|
|
8
8
|
function before(n, func) {
|
|
@@ -98,6 +98,7 @@ exports.once = unary.once;
|
|
|
98
98
|
exports.partial = unary.partial;
|
|
99
99
|
exports.partialRight = unary.partialRight;
|
|
100
100
|
exports.rest = unary.rest;
|
|
101
|
+
exports.retry = unary.retry;
|
|
101
102
|
exports.unary = unary.unary;
|
|
102
103
|
exports.noop = noop.noop;
|
|
103
104
|
exports.before = before;
|
package/dist/function/index.mjs
CHANGED
|
@@ -15,6 +15,7 @@ export { once } from './once.mjs';
|
|
|
15
15
|
export { partial } from './partial.mjs';
|
|
16
16
|
export { partialRight } from './partialRight.mjs';
|
|
17
17
|
export { rest } from './rest.mjs';
|
|
18
|
+
export { retry } from './retry.mjs';
|
|
18
19
|
export { spread } from './spread.mjs';
|
|
19
20
|
export { throttle } from './throttle.mjs';
|
|
20
21
|
export { unary } from './unary.mjs';
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
interface RetryOptions {
|
|
2
|
+
/**
|
|
3
|
+
* The number of milliseconds to interval delay.
|
|
4
|
+
* @default 0
|
|
5
|
+
*/
|
|
6
|
+
delay?: number;
|
|
7
|
+
/**
|
|
8
|
+
* The number of retries to attempt.
|
|
9
|
+
* @default Number.POSITIVE_INFINITY
|
|
10
|
+
*/
|
|
11
|
+
retries?: number;
|
|
12
|
+
/**
|
|
13
|
+
* An AbortSignal to cancel the retry operation.
|
|
14
|
+
*/
|
|
15
|
+
signal?: AbortSignal;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Retries a function that returns a promise until it resolves successfully.
|
|
19
|
+
*
|
|
20
|
+
* @template T
|
|
21
|
+
* @param {() => Promise<T>} func - The function to retry.
|
|
22
|
+
* @returns {Promise<T>} A promise that resolves with the value of the successful function call.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // Basic usage with default retry options
|
|
26
|
+
* retry(() => fetchData()).then(data => console.log(data));
|
|
27
|
+
*/
|
|
28
|
+
declare function retry<T>(func: () => Promise<T>): Promise<T>;
|
|
29
|
+
/**
|
|
30
|
+
* Retries a function that returns a promise a specified number of times.
|
|
31
|
+
*
|
|
32
|
+
* @template T
|
|
33
|
+
* @param {() => Promise<T>} func - The function to retry. It should return a promise.
|
|
34
|
+
* @param {number} retries - The number of retries to attempt. Default is Infinity.
|
|
35
|
+
* @returns {Promise<T>} A promise that resolves with the value of the successful function call.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* // Retry a function up to 3 times
|
|
39
|
+
* retry(() => fetchData(), 3).then(data => console.log(data));
|
|
40
|
+
*/
|
|
41
|
+
declare function retry<T>(func: () => Promise<T>, retries: number): Promise<T>;
|
|
42
|
+
/**
|
|
43
|
+
* Retries a function that returns a promise with specified options.
|
|
44
|
+
*
|
|
45
|
+
* @template T
|
|
46
|
+
* @param {() => Promise<T>} func - The function to retry. It should return a promise.
|
|
47
|
+
* @param {RetryOptions} options - Options to configure the retry behavior.
|
|
48
|
+
* @param {number} [options.delay=0] - The number of milliseconds to wait between retries.
|
|
49
|
+
* @param {number} [options.retries=Infinity] - The number of retries to attempt.
|
|
50
|
+
* @param {AbortSignal} [options.signal] - An AbortSignal to cancel the retry operation.
|
|
51
|
+
* @returns {Promise<T>} A promise that resolves with the value of the successful function call.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* // Retry a function with a delay of 1000ms between attempts
|
|
55
|
+
* retry(() => fetchData(), { delay: 1000, times: 5 }).then(data => console.log(data));
|
|
56
|
+
*/
|
|
57
|
+
declare function retry<T>(func: () => Promise<T>, options: RetryOptions): Promise<T>;
|
|
58
|
+
|
|
59
|
+
export { retry };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
interface RetryOptions {
|
|
2
|
+
/**
|
|
3
|
+
* The number of milliseconds to interval delay.
|
|
4
|
+
* @default 0
|
|
5
|
+
*/
|
|
6
|
+
delay?: number;
|
|
7
|
+
/**
|
|
8
|
+
* The number of retries to attempt.
|
|
9
|
+
* @default Number.POSITIVE_INFINITY
|
|
10
|
+
*/
|
|
11
|
+
retries?: number;
|
|
12
|
+
/**
|
|
13
|
+
* An AbortSignal to cancel the retry operation.
|
|
14
|
+
*/
|
|
15
|
+
signal?: AbortSignal;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Retries a function that returns a promise until it resolves successfully.
|
|
19
|
+
*
|
|
20
|
+
* @template T
|
|
21
|
+
* @param {() => Promise<T>} func - The function to retry.
|
|
22
|
+
* @returns {Promise<T>} A promise that resolves with the value of the successful function call.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // Basic usage with default retry options
|
|
26
|
+
* retry(() => fetchData()).then(data => console.log(data));
|
|
27
|
+
*/
|
|
28
|
+
declare function retry<T>(func: () => Promise<T>): Promise<T>;
|
|
29
|
+
/**
|
|
30
|
+
* Retries a function that returns a promise a specified number of times.
|
|
31
|
+
*
|
|
32
|
+
* @template T
|
|
33
|
+
* @param {() => Promise<T>} func - The function to retry. It should return a promise.
|
|
34
|
+
* @param {number} retries - The number of retries to attempt. Default is Infinity.
|
|
35
|
+
* @returns {Promise<T>} A promise that resolves with the value of the successful function call.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* // Retry a function up to 3 times
|
|
39
|
+
* retry(() => fetchData(), 3).then(data => console.log(data));
|
|
40
|
+
*/
|
|
41
|
+
declare function retry<T>(func: () => Promise<T>, retries: number): Promise<T>;
|
|
42
|
+
/**
|
|
43
|
+
* Retries a function that returns a promise with specified options.
|
|
44
|
+
*
|
|
45
|
+
* @template T
|
|
46
|
+
* @param {() => Promise<T>} func - The function to retry. It should return a promise.
|
|
47
|
+
* @param {RetryOptions} options - Options to configure the retry behavior.
|
|
48
|
+
* @param {number} [options.delay=0] - The number of milliseconds to wait between retries.
|
|
49
|
+
* @param {number} [options.retries=Infinity] - The number of retries to attempt.
|
|
50
|
+
* @param {AbortSignal} [options.signal] - An AbortSignal to cancel the retry operation.
|
|
51
|
+
* @returns {Promise<T>} A promise that resolves with the value of the successful function call.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* // Retry a function with a delay of 1000ms between attempts
|
|
55
|
+
* retry(() => fetchData(), { delay: 1000, times: 5 }).then(data => console.log(data));
|
|
56
|
+
*/
|
|
57
|
+
declare function retry<T>(func: () => Promise<T>, options: RetryOptions): Promise<T>;
|
|
58
|
+
|
|
59
|
+
export { retry };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { delay } from '../promise/delay.mjs';
|
|
2
|
+
|
|
3
|
+
const DEFAULT_DELAY = 0;
|
|
4
|
+
const DEFAULT_RETRIES = Number.POSITIVE_INFINITY;
|
|
5
|
+
async function retry(func, _options) {
|
|
6
|
+
let delay$1;
|
|
7
|
+
let retries;
|
|
8
|
+
let signal;
|
|
9
|
+
if (typeof _options === 'number') {
|
|
10
|
+
delay$1 = DEFAULT_DELAY;
|
|
11
|
+
retries = _options;
|
|
12
|
+
signal = undefined;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
delay$1 = _options?.delay ?? DEFAULT_DELAY;
|
|
16
|
+
retries = _options?.retries ?? DEFAULT_RETRIES;
|
|
17
|
+
signal = _options?.signal;
|
|
18
|
+
}
|
|
19
|
+
let error;
|
|
20
|
+
for (let i = 0; i < retries; i++) {
|
|
21
|
+
if (signal?.aborted) {
|
|
22
|
+
throw error ?? new Error(`The retry operation was aborted due to an abort signal.`);
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
return await func();
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
error = err;
|
|
29
|
+
await delay(delay$1);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { retry };
|
package/dist/index.d.mts
CHANGED
|
@@ -77,6 +77,7 @@ export { once } from './function/once.mjs';
|
|
|
77
77
|
export { partial } from './function/partial.mjs';
|
|
78
78
|
export { partialRight } from './function/partialRight.mjs';
|
|
79
79
|
export { rest } from './function/rest.mjs';
|
|
80
|
+
export { retry } from './function/retry.mjs';
|
|
80
81
|
export { spread } from './function/spread.mjs';
|
|
81
82
|
export { ThrottledFunction, throttle } from './function/throttle.mjs';
|
|
82
83
|
export { unary } from './function/unary.mjs';
|
|
@@ -126,6 +127,7 @@ export { isNotNil } from './predicate/isNotNil.mjs';
|
|
|
126
127
|
export { isNull } from './predicate/isNull.mjs';
|
|
127
128
|
export { isPlainObject } from './predicate/isPlainObject.mjs';
|
|
128
129
|
export { isPrimitive } from './predicate/isPrimitive.mjs';
|
|
130
|
+
export { isPromise } from './predicate/isPromise.mjs';
|
|
129
131
|
export { isRegExp } from './predicate/isRegExp.mjs';
|
|
130
132
|
export { isSet } from './predicate/isSet.mjs';
|
|
131
133
|
export { isString } from './predicate/isString.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -77,6 +77,7 @@ export { once } from './function/once.js';
|
|
|
77
77
|
export { partial } from './function/partial.js';
|
|
78
78
|
export { partialRight } from './function/partialRight.js';
|
|
79
79
|
export { rest } from './function/rest.js';
|
|
80
|
+
export { retry } from './function/retry.js';
|
|
80
81
|
export { spread } from './function/spread.js';
|
|
81
82
|
export { ThrottledFunction, throttle } from './function/throttle.js';
|
|
82
83
|
export { unary } from './function/unary.js';
|
|
@@ -126,6 +127,7 @@ export { isNotNil } from './predicate/isNotNil.js';
|
|
|
126
127
|
export { isNull } from './predicate/isNull.js';
|
|
127
128
|
export { isPlainObject } from './predicate/isPlainObject.js';
|
|
128
129
|
export { isPrimitive } from './predicate/isPrimitive.js';
|
|
130
|
+
export { isPromise } from './predicate/isPromise.js';
|
|
129
131
|
export { isRegExp } from './predicate/isRegExp.js';
|
|
130
132
|
export { isSet } from './predicate/isSet.js';
|
|
131
133
|
export { isString } from './predicate/isString.js';
|
package/dist/index.js
CHANGED
|
@@ -4,8 +4,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4
4
|
|
|
5
5
|
const zipWith = require('./_chunk/zipWith-Bdyzuy.js');
|
|
6
6
|
const array_index = require('./array/index.js');
|
|
7
|
+
const AbortError = require('./_chunk/AbortError-Cg4ZQ1.js');
|
|
7
8
|
const error_index = require('./error/index.js');
|
|
8
|
-
const unary = require('./_chunk/unary-
|
|
9
|
+
const unary = require('./_chunk/unary-c1NFA5.js');
|
|
9
10
|
const function_index = require('./function/index.js');
|
|
10
11
|
const noop = require('./_chunk/noop-2IwLUk.js');
|
|
11
12
|
const range = require('./_chunk/range-HnEIT7.js');
|
|
@@ -13,9 +14,10 @@ const randomInt = require('./_chunk/randomInt-CF7bZK.js');
|
|
|
13
14
|
const math_index = require('./math/index.js');
|
|
14
15
|
const toMerged = require('./_chunk/toMerged-DGFrN7.js');
|
|
15
16
|
const object_index = require('./object/index.js');
|
|
16
|
-
const isWeakSet = require('./_chunk/isWeakSet-
|
|
17
|
+
const isWeakSet = require('./_chunk/isWeakSet-BgjERb.js');
|
|
17
18
|
const predicate_index = require('./predicate/index.js');
|
|
18
19
|
const isPlainObject = require('./_chunk/isPlainObject-octpoD.js');
|
|
20
|
+
const delay = require('./_chunk/delay-_VMfFa.js');
|
|
19
21
|
const promise_index = require('./promise/index.js');
|
|
20
22
|
const upperFirst = require('./_chunk/upperFirst-CorAVn.js');
|
|
21
23
|
const string_index = require('./string/index.js');
|
|
@@ -83,7 +85,7 @@ exports.zipWith = zipWith.zipWith;
|
|
|
83
85
|
exports.orderBy = array_index.orderBy;
|
|
84
86
|
exports.sortBy = array_index.sortBy;
|
|
85
87
|
exports.takeRightWhile = array_index.takeRightWhile;
|
|
86
|
-
exports.AbortError =
|
|
88
|
+
exports.AbortError = AbortError.AbortError;
|
|
87
89
|
exports.TimeoutError = error_index.TimeoutError;
|
|
88
90
|
exports.after = unary.after;
|
|
89
91
|
exports.ary = unary.ary;
|
|
@@ -98,6 +100,7 @@ exports.once = unary.once;
|
|
|
98
100
|
exports.partial = unary.partial;
|
|
99
101
|
exports.partialRight = unary.partialRight;
|
|
100
102
|
exports.rest = unary.rest;
|
|
103
|
+
exports.retry = unary.retry;
|
|
101
104
|
exports.unary = unary.unary;
|
|
102
105
|
exports.before = function_index.before;
|
|
103
106
|
exports.curry = function_index.curry;
|
|
@@ -149,6 +152,7 @@ exports.isMap = isWeakSet.isMap;
|
|
|
149
152
|
exports.isNil = isWeakSet.isNil;
|
|
150
153
|
exports.isNotNil = isWeakSet.isNotNil;
|
|
151
154
|
exports.isNull = isWeakSet.isNull;
|
|
155
|
+
exports.isPromise = isWeakSet.isPromise;
|
|
152
156
|
exports.isRegExp = isWeakSet.isRegExp;
|
|
153
157
|
exports.isSet = isWeakSet.isSet;
|
|
154
158
|
exports.isUndefined = isWeakSet.isUndefined;
|
|
@@ -161,7 +165,7 @@ exports.isSymbol = predicate_index.isSymbol;
|
|
|
161
165
|
exports.isPlainObject = isPlainObject.isPlainObject;
|
|
162
166
|
exports.isPrimitive = isPlainObject.isPrimitive;
|
|
163
167
|
exports.isTypedArray = isPlainObject.isTypedArray;
|
|
164
|
-
exports.delay =
|
|
168
|
+
exports.delay = delay.delay;
|
|
165
169
|
exports.timeout = promise_index.timeout;
|
|
166
170
|
exports.withTimeout = promise_index.withTimeout;
|
|
167
171
|
exports.camelCase = upperFirst.camelCase;
|
package/dist/index.mjs
CHANGED
|
@@ -77,6 +77,7 @@ export { once } from './function/once.mjs';
|
|
|
77
77
|
export { partial } from './function/partial.mjs';
|
|
78
78
|
export { partialRight } from './function/partialRight.mjs';
|
|
79
79
|
export { rest } from './function/rest.mjs';
|
|
80
|
+
export { retry } from './function/retry.mjs';
|
|
80
81
|
export { spread } from './function/spread.mjs';
|
|
81
82
|
export { throttle } from './function/throttle.mjs';
|
|
82
83
|
export { unary } from './function/unary.mjs';
|
|
@@ -126,6 +127,7 @@ export { isNotNil } from './predicate/isNotNil.mjs';
|
|
|
126
127
|
export { isNull } from './predicate/isNull.mjs';
|
|
127
128
|
export { isPlainObject } from './predicate/isPlainObject.mjs';
|
|
128
129
|
export { isPrimitive } from './predicate/isPrimitive.mjs';
|
|
130
|
+
export { isPromise } from './predicate/isPromise.mjs';
|
|
129
131
|
export { isRegExp } from './predicate/isRegExp.mjs';
|
|
130
132
|
export { isSet } from './predicate/isSet.mjs';
|
|
131
133
|
export { isString } from './predicate/isString.mjs';
|
|
@@ -16,6 +16,7 @@ export { isNotNil } from './isNotNil.mjs';
|
|
|
16
16
|
export { isNull } from './isNull.mjs';
|
|
17
17
|
export { isPlainObject } from './isPlainObject.mjs';
|
|
18
18
|
export { isPrimitive } from './isPrimitive.mjs';
|
|
19
|
+
export { isPromise } from './isPromise.mjs';
|
|
19
20
|
export { isRegExp } from './isRegExp.mjs';
|
|
20
21
|
export { isSet } from './isSet.mjs';
|
|
21
22
|
export { isString } from './isString.mjs';
|
|
@@ -16,6 +16,7 @@ export { isNotNil } from './isNotNil.js';
|
|
|
16
16
|
export { isNull } from './isNull.js';
|
|
17
17
|
export { isPlainObject } from './isPlainObject.js';
|
|
18
18
|
export { isPrimitive } from './isPrimitive.js';
|
|
19
|
+
export { isPromise } from './isPromise.js';
|
|
19
20
|
export { isRegExp } from './isRegExp.js';
|
|
20
21
|
export { isSet } from './isSet.js';
|
|
21
22
|
export { isString } from './isString.js';
|
package/dist/predicate/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const isWeakSet = require('../_chunk/isWeakSet-
|
|
5
|
+
const isWeakSet = require('../_chunk/isWeakSet-BgjERb.js');
|
|
6
6
|
const isPlainObject = require('../_chunk/isPlainObject-octpoD.js');
|
|
7
7
|
|
|
8
8
|
function isBoolean(x) {
|
|
@@ -37,6 +37,7 @@ exports.isMap = isWeakSet.isMap;
|
|
|
37
37
|
exports.isNil = isWeakSet.isNil;
|
|
38
38
|
exports.isNotNil = isWeakSet.isNotNil;
|
|
39
39
|
exports.isNull = isWeakSet.isNull;
|
|
40
|
+
exports.isPromise = isWeakSet.isPromise;
|
|
40
41
|
exports.isRegExp = isWeakSet.isRegExp;
|
|
41
42
|
exports.isSet = isWeakSet.isSet;
|
|
42
43
|
exports.isUndefined = isWeakSet.isUndefined;
|
package/dist/predicate/index.mjs
CHANGED
|
@@ -16,6 +16,7 @@ export { isNotNil } from './isNotNil.mjs';
|
|
|
16
16
|
export { isNull } from './isNull.mjs';
|
|
17
17
|
export { isPlainObject } from './isPlainObject.mjs';
|
|
18
18
|
export { isPrimitive } from './isPrimitive.mjs';
|
|
19
|
+
export { isPromise } from './isPromise.mjs';
|
|
19
20
|
export { isRegExp } from './isRegExp.mjs';
|
|
20
21
|
export { isSet } from './isSet.mjs';
|
|
21
22
|
export { isString } from './isString.mjs';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a given value is `Promise`.
|
|
3
|
+
*
|
|
4
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `Promise`.
|
|
5
|
+
*
|
|
6
|
+
* @param {unknown} value The value to check if it is a `Promise`.
|
|
7
|
+
* @returns {value is Promise<any>} Returns `true` if `value` is a `Promise`, else `false`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const value1 = new Promise((resolve) => resolve());
|
|
11
|
+
* const value2 = {};
|
|
12
|
+
* const value3 = 123;
|
|
13
|
+
*
|
|
14
|
+
* console.log(isPromise(value1)); // true
|
|
15
|
+
* console.log(isPromise(value2)); // false
|
|
16
|
+
* console.log(isPromise(value3)); // false
|
|
17
|
+
*/
|
|
18
|
+
declare function isPromise(value: unknown): value is Promise<any>;
|
|
19
|
+
|
|
20
|
+
export { isPromise };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a given value is `Promise`.
|
|
3
|
+
*
|
|
4
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `Promise`.
|
|
5
|
+
*
|
|
6
|
+
* @param {unknown} value The value to check if it is a `Promise`.
|
|
7
|
+
* @returns {value is Promise<any>} Returns `true` if `value` is a `Promise`, else `false`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const value1 = new Promise((resolve) => resolve());
|
|
11
|
+
* const value2 = {};
|
|
12
|
+
* const value3 = 123;
|
|
13
|
+
*
|
|
14
|
+
* console.log(isPromise(value1)); // true
|
|
15
|
+
* console.log(isPromise(value2)); // false
|
|
16
|
+
* console.log(isPromise(value3)); // false
|
|
17
|
+
*/
|
|
18
|
+
declare function isPromise(value: unknown): value is Promise<any>;
|
|
19
|
+
|
|
20
|
+
export { isPromise };
|
package/dist/promise/index.js
CHANGED
|
@@ -2,30 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
+
const delay = require('../_chunk/delay-_VMfFa.js');
|
|
5
6
|
const error_index = require('../error/index.js');
|
|
6
7
|
|
|
7
|
-
function delay(ms, { signal } = {}) {
|
|
8
|
-
return new Promise((resolve, reject) => {
|
|
9
|
-
const abortError = () => {
|
|
10
|
-
reject(new error_index.AbortError());
|
|
11
|
-
};
|
|
12
|
-
const abortHandler = () => {
|
|
13
|
-
clearTimeout(timeoutId);
|
|
14
|
-
abortError();
|
|
15
|
-
};
|
|
16
|
-
if (signal?.aborted) {
|
|
17
|
-
return abortError();
|
|
18
|
-
}
|
|
19
|
-
const timeoutId = setTimeout(() => {
|
|
20
|
-
signal?.removeEventListener('abort', abortHandler);
|
|
21
|
-
resolve();
|
|
22
|
-
}, ms);
|
|
23
|
-
signal?.addEventListener('abort', abortHandler, { once: true });
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
8
|
async function timeout(ms) {
|
|
28
|
-
await delay(ms);
|
|
9
|
+
await delay.delay(ms);
|
|
29
10
|
throw new error_index.TimeoutError();
|
|
30
11
|
}
|
|
31
12
|
|
|
@@ -33,6 +14,6 @@ async function withTimeout(run, ms) {
|
|
|
33
14
|
return Promise.race([run(), timeout(ms)]);
|
|
34
15
|
}
|
|
35
16
|
|
|
36
|
-
exports.delay = delay;
|
|
17
|
+
exports.delay = delay.delay;
|
|
37
18
|
exports.timeout = timeout;
|
|
38
19
|
exports.withTimeout = withTimeout;
|
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.31.0-dev.
|
|
4
|
+
"version": "1.31.0-dev.996+9e5dd433",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|