es-toolkit 1.29.0-dev.946 → 1.29.0-dev.948
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/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/function/after.d.mts +31 -0
- package/dist/compat/function/after.d.ts +31 -0
- package/dist/compat/function/after.mjs +15 -0
- package/dist/compat/index.d.mts +1 -1
- package/dist/compat/index.d.ts +1 -1
- package/dist/compat/index.js +13 -1
- package/dist/compat/index.mjs +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a function that only executes starting from the `n`-th call.
|
|
3
|
+
* The provided function will be invoked starting from the `n`-th call.
|
|
4
|
+
*
|
|
5
|
+
* This is particularly useful for scenarios involving events or asynchronous operations
|
|
6
|
+
* where an action should occur only after a certain number of invocations.
|
|
7
|
+
*
|
|
8
|
+
* @template F - The type of the function to be invoked.
|
|
9
|
+
* @param {number} n - The number of calls required for `func` to execute.
|
|
10
|
+
* @param {F} func - The function to be invoked.
|
|
11
|
+
* @returns {(...args: Parameters<F>) => ReturnType<F> | undefined} - A new function that:
|
|
12
|
+
* - Tracks the number of calls.
|
|
13
|
+
* - Invokes `func` starting from the `n`-th call.
|
|
14
|
+
* - Returns `undefined` if fewer than `n` calls have been made.
|
|
15
|
+
* @throws {TypeError} - If `func` is not a function.
|
|
16
|
+
* @example
|
|
17
|
+
*
|
|
18
|
+
* const afterFn = after(3, () => {
|
|
19
|
+
* console.log("called")
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* // Will not log anything.
|
|
23
|
+
* afterFn()
|
|
24
|
+
* // Will not log anything.
|
|
25
|
+
* afterFn()
|
|
26
|
+
* // Will log 'called'.
|
|
27
|
+
* afterFn()
|
|
28
|
+
*/
|
|
29
|
+
declare function after<F extends (...args: any[]) => any>(n: number, func: F): (...args: Parameters<F>) => ReturnType<F> | undefined;
|
|
30
|
+
|
|
31
|
+
export { after };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a function that only executes starting from the `n`-th call.
|
|
3
|
+
* The provided function will be invoked starting from the `n`-th call.
|
|
4
|
+
*
|
|
5
|
+
* This is particularly useful for scenarios involving events or asynchronous operations
|
|
6
|
+
* where an action should occur only after a certain number of invocations.
|
|
7
|
+
*
|
|
8
|
+
* @template F - The type of the function to be invoked.
|
|
9
|
+
* @param {number} n - The number of calls required for `func` to execute.
|
|
10
|
+
* @param {F} func - The function to be invoked.
|
|
11
|
+
* @returns {(...args: Parameters<F>) => ReturnType<F> | undefined} - A new function that:
|
|
12
|
+
* - Tracks the number of calls.
|
|
13
|
+
* - Invokes `func` starting from the `n`-th call.
|
|
14
|
+
* - Returns `undefined` if fewer than `n` calls have been made.
|
|
15
|
+
* @throws {TypeError} - If `func` is not a function.
|
|
16
|
+
* @example
|
|
17
|
+
*
|
|
18
|
+
* const afterFn = after(3, () => {
|
|
19
|
+
* console.log("called")
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* // Will not log anything.
|
|
23
|
+
* afterFn()
|
|
24
|
+
* // Will not log anything.
|
|
25
|
+
* afterFn()
|
|
26
|
+
* // Will log 'called'.
|
|
27
|
+
* afterFn()
|
|
28
|
+
*/
|
|
29
|
+
declare function after<F extends (...args: any[]) => any>(n: number, func: F): (...args: Parameters<F>) => ReturnType<F> | undefined;
|
|
30
|
+
|
|
31
|
+
export { after };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { toInteger } from '../util/toInteger.mjs';
|
|
2
|
+
|
|
3
|
+
function after(n, func) {
|
|
4
|
+
if (typeof func !== 'function') {
|
|
5
|
+
throw new TypeError('Expected a function');
|
|
6
|
+
}
|
|
7
|
+
n = toInteger(n);
|
|
8
|
+
return function (...args) {
|
|
9
|
+
if (--n < 1) {
|
|
10
|
+
return func.apply(this, args);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { after };
|
package/dist/compat/index.d.mts
CHANGED
|
@@ -28,7 +28,6 @@ export { zipObject } from '../array/zipObject.mjs';
|
|
|
28
28
|
export { zipWith } from '../array/zipWith.mjs';
|
|
29
29
|
export { AbortError } from '../error/AbortError.mjs';
|
|
30
30
|
export { TimeoutError } from '../error/TimeoutError.mjs';
|
|
31
|
-
export { after } from '../function/after.mjs';
|
|
32
31
|
export { identity } from '../function/identity.mjs';
|
|
33
32
|
export { MemoizeCache, memoize } from '../function/memoize.mjs';
|
|
34
33
|
export { negate } from '../function/negate.mjs';
|
|
@@ -118,6 +117,7 @@ export { unzip } from './array/unzip.mjs';
|
|
|
118
117
|
export { without } from './array/without.mjs';
|
|
119
118
|
export { zip } from './array/zip.mjs';
|
|
120
119
|
export { zipObjectDeep } from './array/zipObjectDeep.mjs';
|
|
120
|
+
export { after } from './function/after.mjs';
|
|
121
121
|
export { ary } from './function/ary.mjs';
|
|
122
122
|
export { attempt } from './function/attempt.mjs';
|
|
123
123
|
export { before } from './function/before.mjs';
|
package/dist/compat/index.d.ts
CHANGED
|
@@ -28,7 +28,6 @@ export { zipObject } from '../array/zipObject.js';
|
|
|
28
28
|
export { zipWith } from '../array/zipWith.js';
|
|
29
29
|
export { AbortError } from '../error/AbortError.js';
|
|
30
30
|
export { TimeoutError } from '../error/TimeoutError.js';
|
|
31
|
-
export { after } from '../function/after.js';
|
|
32
31
|
export { identity } from '../function/identity.js';
|
|
33
32
|
export { MemoizeCache, memoize } from '../function/memoize.js';
|
|
34
33
|
export { negate } from '../function/negate.js';
|
|
@@ -118,6 +117,7 @@ export { unzip } from './array/unzip.js';
|
|
|
118
117
|
export { without } from './array/without.js';
|
|
119
118
|
export { zip } from './array/zip.js';
|
|
120
119
|
export { zipObjectDeep } from './array/zipObjectDeep.js';
|
|
120
|
+
export { after } from './function/after.js';
|
|
121
121
|
export { ary } from './function/ary.js';
|
|
122
122
|
export { attempt } from './function/attempt.js';
|
|
123
123
|
export { before } from './function/before.js';
|
package/dist/compat/index.js
CHANGED
|
@@ -1390,6 +1390,18 @@ function zipObjectDeep(keys, values) {
|
|
|
1390
1390
|
return result;
|
|
1391
1391
|
}
|
|
1392
1392
|
|
|
1393
|
+
function after(n, func) {
|
|
1394
|
+
if (typeof func !== 'function') {
|
|
1395
|
+
throw new TypeError('Expected a function');
|
|
1396
|
+
}
|
|
1397
|
+
n = toInteger(n);
|
|
1398
|
+
return function (...args) {
|
|
1399
|
+
if (--n < 1) {
|
|
1400
|
+
return func.apply(this, args);
|
|
1401
|
+
}
|
|
1402
|
+
};
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1393
1405
|
function ary(func, n = func.length, guard) {
|
|
1394
1406
|
if (guard) {
|
|
1395
1407
|
n = func.length;
|
|
@@ -2945,7 +2957,6 @@ exports.TimeoutError = promise_index.TimeoutError;
|
|
|
2945
2957
|
exports.delay = promise_index.delay;
|
|
2946
2958
|
exports.timeout = promise_index.timeout;
|
|
2947
2959
|
exports.withTimeout = promise_index.withTimeout;
|
|
2948
|
-
exports.after = unary.after;
|
|
2949
2960
|
exports.identity = unary.identity;
|
|
2950
2961
|
exports.memoize = unary.memoize;
|
|
2951
2962
|
exports.negate = unary.negate;
|
|
@@ -2987,6 +2998,7 @@ exports.constantCase = upperFirst$1.constantCase;
|
|
|
2987
2998
|
exports.pascalCase = upperFirst$1.pascalCase;
|
|
2988
2999
|
exports.invariant = util_index.invariant;
|
|
2989
3000
|
exports.add = add;
|
|
3001
|
+
exports.after = after;
|
|
2990
3002
|
exports.ary = ary;
|
|
2991
3003
|
exports.assignIn = assignIn;
|
|
2992
3004
|
exports.attempt = attempt;
|
package/dist/compat/index.mjs
CHANGED
|
@@ -28,7 +28,6 @@ export { zipObject } from '../array/zipObject.mjs';
|
|
|
28
28
|
export { zipWith } from '../array/zipWith.mjs';
|
|
29
29
|
export { AbortError } from '../error/AbortError.mjs';
|
|
30
30
|
export { TimeoutError } from '../error/TimeoutError.mjs';
|
|
31
|
-
export { after } from '../function/after.mjs';
|
|
32
31
|
export { identity } from '../function/identity.mjs';
|
|
33
32
|
export { memoize } from '../function/memoize.mjs';
|
|
34
33
|
export { negate } from '../function/negate.mjs';
|
|
@@ -120,6 +119,7 @@ export { unzip } from './array/unzip.mjs';
|
|
|
120
119
|
export { without } from './array/without.mjs';
|
|
121
120
|
export { zip } from './array/zip.mjs';
|
|
122
121
|
export { zipObjectDeep } from './array/zipObjectDeep.mjs';
|
|
122
|
+
export { after } from './function/after.mjs';
|
|
123
123
|
export { ary } from './function/ary.mjs';
|
|
124
124
|
export { attempt } from './function/attempt.mjs';
|
|
125
125
|
export { before } from './function/before.mjs';
|
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.29.0-dev.
|
|
4
|
+
"version": "1.29.0-dev.948+f7b12269",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|