es-toolkit 1.29.0 → 1.30.0
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/CHANGELOG.md +9 -0
- package/dist/_chunk/{rangeRight-w3WrXN.js → range-HnEIT7.js} +0 -17
- package/dist/_chunk/{zipWith-Bb2eZI.js → zipWith-nbzldx.js} +11 -10
- package/dist/array/index.d.mts +1 -0
- package/dist/array/index.d.ts +1 -0
- package/dist/array/index.js +12 -2
- package/dist/array/index.mjs +1 -0
- package/dist/array/pull.d.mts +19 -0
- package/dist/array/pull.d.ts +19 -0
- package/dist/array/pull.mjs +11 -0
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/_internal/isIndex.mjs +2 -2
- package/dist/compat/_internal/isPrototype.mjs +1 -1
- package/dist/compat/array/differenceWith.d.mts +91 -0
- package/dist/compat/array/differenceWith.d.ts +91 -0
- package/dist/compat/array/differenceWith.mjs +19 -0
- package/dist/compat/array/map.d.mts +182 -0
- package/dist/compat/array/map.d.ts +182 -0
- package/dist/compat/array/map.mjs +21 -0
- package/dist/compat/array/nth.d.mts +14 -0
- package/dist/compat/array/nth.d.ts +14 -0
- package/dist/compat/array/nth.mjs +15 -0
- package/dist/compat/array/pull.d.mts +19 -0
- package/dist/compat/array/pull.d.ts +19 -0
- package/dist/compat/array/pull.mjs +8 -0
- package/dist/compat/array/takeRightWhile.d.mts +84 -0
- package/dist/compat/array/takeRightWhile.d.ts +84 -0
- package/dist/compat/array/takeRightWhile.mjs +15 -0
- 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/function/delay.d.mts +29 -0
- package/dist/compat/function/delay.d.ts +29 -0
- package/dist/compat/function/delay.mjs +10 -0
- package/dist/compat/function/nthArg.d.mts +22 -0
- package/dist/compat/function/nthArg.d.ts +22 -0
- package/dist/compat/function/nthArg.mjs +9 -0
- package/dist/compat/index.d.mts +30 -13
- package/dist/compat/index.d.ts +30 -13
- package/dist/compat/index.js +369 -56
- package/dist/compat/index.mjs +31 -13
- package/dist/compat/math/range.d.mts +47 -0
- package/dist/compat/math/range.d.ts +47 -0
- package/dist/compat/math/range.mjs +26 -0
- package/dist/compat/math/rangeRight.d.mts +47 -0
- package/dist/compat/math/rangeRight.d.ts +47 -0
- package/dist/compat/math/rangeRight.mjs +26 -0
- package/dist/compat/math/sumBy.d.mts +2 -2
- package/dist/compat/math/sumBy.d.ts +2 -2
- package/dist/compat/object/findKey.d.mts +58 -0
- package/dist/compat/object/findKey.d.ts +58 -0
- package/dist/compat/object/findKey.mjs +30 -0
- package/dist/compat/object/keys.d.mts +22 -0
- package/dist/compat/object/keys.d.ts +22 -0
- package/dist/compat/object/keys.mjs +32 -0
- package/dist/compat/object/propertyOf.d.mts +22 -0
- package/dist/compat/object/propertyOf.d.ts +22 -0
- package/dist/compat/object/propertyOf.mjs +9 -0
- package/dist/compat/predicate/isArrayLike.d.mts +1 -1
- package/dist/compat/predicate/isArrayLike.d.ts +1 -1
- package/dist/compat/predicate/isArrayLikeObject.d.mts +1 -1
- package/dist/compat/predicate/isArrayLikeObject.d.ts +1 -1
- package/dist/compat/predicate/isElement.d.mts +1 -1
- package/dist/compat/predicate/isElement.d.ts +1 -1
- package/dist/compat/predicate/isFinite.d.mts +1 -1
- package/dist/compat/predicate/isFinite.d.ts +1 -1
- package/dist/compat/predicate/isNaN.d.mts +1 -1
- package/dist/compat/predicate/isNaN.d.ts +1 -1
- package/dist/compat/predicate/isObject.d.mts +1 -1
- package/dist/compat/predicate/isObject.d.ts +1 -1
- package/dist/compat/predicate/isObjectLike.d.mts +1 -1
- package/dist/compat/predicate/isObjectLike.d.ts +1 -1
- package/dist/compat/string/deburr.d.mts +22 -0
- package/dist/compat/string/deburr.d.ts +22 -0
- package/dist/compat/string/deburr.mjs +8 -0
- package/dist/compat/string/escapeRegExp.d.mts +14 -0
- package/dist/compat/string/escapeRegExp.d.ts +14 -0
- package/dist/compat/string/escapeRegExp.mjs +8 -0
- package/dist/compat/string/lowerFirst.d.mts +14 -0
- package/dist/compat/string/lowerFirst.d.ts +14 -0
- package/dist/compat/string/lowerFirst.mjs +8 -0
- package/dist/compat/string/toLower.d.mts +20 -0
- package/dist/compat/string/toLower.d.ts +20 -0
- package/dist/compat/string/toLower.mjs +7 -0
- package/dist/compat/string/unescape.d.mts +16 -0
- package/dist/compat/string/unescape.d.ts +16 -0
- package/dist/compat/string/unescape.mjs +8 -0
- package/dist/compat/string/upperFirst.d.mts +14 -0
- package/dist/compat/string/upperFirst.d.ts +14 -0
- package/dist/compat/string/upperFirst.mjs +8 -0
- package/dist/compat/util/invoke.d.mts +23 -0
- package/dist/compat/util/invoke.d.ts +23 -0
- package/dist/compat/util/invoke.mjs +48 -0
- package/dist/compat/util/lt.d.mts +15 -0
- package/dist/compat/util/lt.d.ts +15 -0
- package/dist/compat/util/lt.mjs +10 -0
- package/dist/compat/util/lte.d.mts +15 -0
- package/dist/compat/util/lte.d.ts +15 -0
- package/dist/compat/util/lte.mjs +10 -0
- package/dist/compat/util/method.d.mts +22 -0
- package/dist/compat/util/method.d.ts +22 -0
- package/dist/compat/util/method.mjs +9 -0
- package/dist/compat/util/now.d.mts +18 -0
- package/dist/compat/util/now.d.ts +18 -0
- package/dist/compat/util/now.mjs +5 -0
- package/dist/compat/util/stubArray.d.mts +10 -0
- package/dist/compat/util/stubArray.d.ts +10 -0
- package/dist/compat/util/stubArray.mjs +5 -0
- package/dist/compat/util/stubFalse.d.mts +10 -0
- package/dist/compat/util/stubFalse.d.ts +10 -0
- package/dist/compat/util/stubFalse.mjs +5 -0
- package/dist/compat/util/stubObject.d.mts +10 -0
- package/dist/compat/util/stubObject.d.ts +10 -0
- package/dist/compat/util/stubObject.mjs +5 -0
- package/dist/compat/util/stubString.d.mts +10 -0
- package/dist/compat/util/stubString.d.ts +10 -0
- package/dist/compat/util/stubString.mjs +5 -0
- package/dist/compat/util/stubTrue.d.mts +10 -0
- package/dist/compat/util/stubTrue.d.ts +10 -0
- package/dist/compat/util/stubTrue.mjs +5 -0
- package/dist/compat/util/toArray.mjs +0 -3
- package/dist/compat/util/toPlainObject.d.mts +16 -0
- package/dist/compat/util/toPlainObject.d.ts +16 -0
- package/dist/compat/util/toPlainObject.mjs +24 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +13 -12
- package/dist/index.mjs +1 -0
- package/dist/math/index.js +26 -10
- package/package.json +1 -1
- package/dist/compat/util/uniqueId.d.mts +0 -25
- package/dist/compat/util/uniqueId.d.ts +0 -25
- package/dist/compat/util/uniqueId.mjs +0 -7
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes all specified values from an array.
|
|
3
|
+
*
|
|
4
|
+
* This function changes `arr` in place.
|
|
5
|
+
* If you want to remove values without modifying the original array, use `difference`.
|
|
6
|
+
*
|
|
7
|
+
* @template T, U
|
|
8
|
+
* @param {T[]} arr - The array to modify.
|
|
9
|
+
* @param {...unknown[]} valuesToRemove - The values to remove from the array.
|
|
10
|
+
* @returns {T[]} The modified array with the specified values removed.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const numbers = [1, 2, 3, 4, 5, 2, 4];
|
|
14
|
+
* pull(numbers, [2, 4]);
|
|
15
|
+
* console.log(numbers); // [1, 3, 5]
|
|
16
|
+
*/
|
|
17
|
+
declare function pull<T>(arr: T[], ...valuesToRemove: readonly unknown[][]): T[];
|
|
18
|
+
|
|
19
|
+
export { pull };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes all specified values from an array.
|
|
3
|
+
*
|
|
4
|
+
* This function changes `arr` in place.
|
|
5
|
+
* If you want to remove values without modifying the original array, use `difference`.
|
|
6
|
+
*
|
|
7
|
+
* @template T, U
|
|
8
|
+
* @param {T[]} arr - The array to modify.
|
|
9
|
+
* @param {...unknown[]} valuesToRemove - The values to remove from the array.
|
|
10
|
+
* @returns {T[]} The modified array with the specified values removed.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const numbers = [1, 2, 3, 4, 5, 2, 4];
|
|
14
|
+
* pull(numbers, [2, 4]);
|
|
15
|
+
* console.log(numbers); // [1, 3, 5]
|
|
16
|
+
*/
|
|
17
|
+
declare function pull<T>(arr: T[], ...valuesToRemove: readonly unknown[][]): T[];
|
|
18
|
+
|
|
19
|
+
export { pull };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a slice of array.
|
|
3
|
+
*
|
|
4
|
+
* If the array is `null` or `undefined`, returns an empty array.
|
|
5
|
+
*
|
|
6
|
+
* @template T
|
|
7
|
+
* @param {ArrayLike<T> | null | undefined} array - The array to process.
|
|
8
|
+
* @returns {T[]} - A slice of the array or an empty array if `array` is `null` or `undefined`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const items = [1, 2, 3];
|
|
12
|
+
* const result = takeRightWhile(items);
|
|
13
|
+
* console.log(result); // [1, 2, 3]
|
|
14
|
+
*
|
|
15
|
+
* const result2 = takeRightWhile(null);
|
|
16
|
+
* console.log(result2); // []
|
|
17
|
+
*/
|
|
18
|
+
declare function takeRightWhile<T>(array: ArrayLike<T> | null | undefined): T[];
|
|
19
|
+
/**
|
|
20
|
+
* Creates a slice of array with elements taken from the end until the predicate function returns falsey.
|
|
21
|
+
*
|
|
22
|
+
* If the array is `null` or `undefined`, returns an empty array.
|
|
23
|
+
*
|
|
24
|
+
* @template T
|
|
25
|
+
* @param {ArrayLike<T> | null | undefined} array - The array to process.
|
|
26
|
+
* @param {(item: T, index: number, array: T[]) => unknown} predicate - A function invoked per iteration. Returns a truthy value to continue taking elements.
|
|
27
|
+
* @returns {T[]} - A slice of the array with elements taken from the end or an empty array if `array` is `null` or `undefined`.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* const items = [1, 2, 3, 4, 5];
|
|
31
|
+
* const result = takeRightWhile(items, (item) => item > 3);
|
|
32
|
+
* console.log(result); // [4, 5]
|
|
33
|
+
*/
|
|
34
|
+
declare function takeRightWhile<T>(array: ArrayLike<T> | null | undefined, predicate: (item: T, index: number, array: T[]) => unknown): T[];
|
|
35
|
+
/**
|
|
36
|
+
* Creates a slice of array with elements taken from the end until the element does not match the given object.
|
|
37
|
+
*
|
|
38
|
+
* If the array is `null` or `undefined`, returns an empty array.
|
|
39
|
+
*
|
|
40
|
+
* @template T
|
|
41
|
+
* @param {ArrayLike<T> | null | undefined} array - The array to process.
|
|
42
|
+
* @param {Partial<T>} matches - A partial object that specifies the properties to match.
|
|
43
|
+
* @returns {T[]} - A slice of the array with elements taken from the end or an empty array if `array` is `null` or `undefined`.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* const items = [{ id: 10 }, { id: 20 }, { id: 30 }];
|
|
47
|
+
* const result = takeRightWhile(items, { id: 30 });
|
|
48
|
+
* console.log(result); // [{ id: 30 }]
|
|
49
|
+
*/
|
|
50
|
+
declare function takeRightWhile<T>(array: ArrayLike<T> | null | undefined, matches: Partial<T>): T[];
|
|
51
|
+
/**
|
|
52
|
+
* Creates a slice of array with elements taken from the end until the element does not match the given property key and value.
|
|
53
|
+
*
|
|
54
|
+
* If the array is `null` or `undefined`, returns an empty array.
|
|
55
|
+
*
|
|
56
|
+
* @template T
|
|
57
|
+
* @param {ArrayLike<T> | null | undefined} array - The array to process.
|
|
58
|
+
* @param {[keyof T, unknown]} matchesProperty - An array where the first element is the property key and the second element is the value to match.
|
|
59
|
+
* @returns {T[]} - A slice of the array with elements taken from the end or an empty array if `array` is `null` or `undefined`.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* const items = [{ name: 'Alice' }, { name: 'Bob' }, { name: 'Alice' }];
|
|
63
|
+
* const result = takeRightWhile(items, ['name', 'Alice']);
|
|
64
|
+
* console.log(result); // [{ name: 'Alice' }]
|
|
65
|
+
*/
|
|
66
|
+
declare function takeRightWhile<T>(array: ArrayLike<T> | null | undefined, matchesProperty: [keyof T, unknown]): T[];
|
|
67
|
+
/**
|
|
68
|
+
* Creates a slice of array with elements taken from the end until the element does not have a truthy value for the given property key.
|
|
69
|
+
*
|
|
70
|
+
* If the array is `null` or `undefined`, returns an empty array.
|
|
71
|
+
*
|
|
72
|
+
* @template T
|
|
73
|
+
* @param {ArrayLike<T> | null | undefined} array - The array to process.
|
|
74
|
+
* @param {PropertyKey} property - A property key. Elements are included if they have a truthy value for this key.
|
|
75
|
+
* @returns {T[]} - A slice of the array with elements taken from the end or an empty array if `array` is `null` or `undefined`.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* const items = [{ valid: false }, { valid: true }, { valid: true }];
|
|
79
|
+
* const result = takeRightWhile(items, 'valid');
|
|
80
|
+
* console.log(result); // [{ valid: true }, { valid: true }]
|
|
81
|
+
*/
|
|
82
|
+
declare function takeRightWhile<T>(array: ArrayLike<T> | null | undefined, property: PropertyKey): T[];
|
|
83
|
+
|
|
84
|
+
export { takeRightWhile };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a slice of array.
|
|
3
|
+
*
|
|
4
|
+
* If the array is `null` or `undefined`, returns an empty array.
|
|
5
|
+
*
|
|
6
|
+
* @template T
|
|
7
|
+
* @param {ArrayLike<T> | null | undefined} array - The array to process.
|
|
8
|
+
* @returns {T[]} - A slice of the array or an empty array if `array` is `null` or `undefined`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const items = [1, 2, 3];
|
|
12
|
+
* const result = takeRightWhile(items);
|
|
13
|
+
* console.log(result); // [1, 2, 3]
|
|
14
|
+
*
|
|
15
|
+
* const result2 = takeRightWhile(null);
|
|
16
|
+
* console.log(result2); // []
|
|
17
|
+
*/
|
|
18
|
+
declare function takeRightWhile<T>(array: ArrayLike<T> | null | undefined): T[];
|
|
19
|
+
/**
|
|
20
|
+
* Creates a slice of array with elements taken from the end until the predicate function returns falsey.
|
|
21
|
+
*
|
|
22
|
+
* If the array is `null` or `undefined`, returns an empty array.
|
|
23
|
+
*
|
|
24
|
+
* @template T
|
|
25
|
+
* @param {ArrayLike<T> | null | undefined} array - The array to process.
|
|
26
|
+
* @param {(item: T, index: number, array: T[]) => unknown} predicate - A function invoked per iteration. Returns a truthy value to continue taking elements.
|
|
27
|
+
* @returns {T[]} - A slice of the array with elements taken from the end or an empty array if `array` is `null` or `undefined`.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* const items = [1, 2, 3, 4, 5];
|
|
31
|
+
* const result = takeRightWhile(items, (item) => item > 3);
|
|
32
|
+
* console.log(result); // [4, 5]
|
|
33
|
+
*/
|
|
34
|
+
declare function takeRightWhile<T>(array: ArrayLike<T> | null | undefined, predicate: (item: T, index: number, array: T[]) => unknown): T[];
|
|
35
|
+
/**
|
|
36
|
+
* Creates a slice of array with elements taken from the end until the element does not match the given object.
|
|
37
|
+
*
|
|
38
|
+
* If the array is `null` or `undefined`, returns an empty array.
|
|
39
|
+
*
|
|
40
|
+
* @template T
|
|
41
|
+
* @param {ArrayLike<T> | null | undefined} array - The array to process.
|
|
42
|
+
* @param {Partial<T>} matches - A partial object that specifies the properties to match.
|
|
43
|
+
* @returns {T[]} - A slice of the array with elements taken from the end or an empty array if `array` is `null` or `undefined`.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* const items = [{ id: 10 }, { id: 20 }, { id: 30 }];
|
|
47
|
+
* const result = takeRightWhile(items, { id: 30 });
|
|
48
|
+
* console.log(result); // [{ id: 30 }]
|
|
49
|
+
*/
|
|
50
|
+
declare function takeRightWhile<T>(array: ArrayLike<T> | null | undefined, matches: Partial<T>): T[];
|
|
51
|
+
/**
|
|
52
|
+
* Creates a slice of array with elements taken from the end until the element does not match the given property key and value.
|
|
53
|
+
*
|
|
54
|
+
* If the array is `null` or `undefined`, returns an empty array.
|
|
55
|
+
*
|
|
56
|
+
* @template T
|
|
57
|
+
* @param {ArrayLike<T> | null | undefined} array - The array to process.
|
|
58
|
+
* @param {[keyof T, unknown]} matchesProperty - An array where the first element is the property key and the second element is the value to match.
|
|
59
|
+
* @returns {T[]} - A slice of the array with elements taken from the end or an empty array if `array` is `null` or `undefined`.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* const items = [{ name: 'Alice' }, { name: 'Bob' }, { name: 'Alice' }];
|
|
63
|
+
* const result = takeRightWhile(items, ['name', 'Alice']);
|
|
64
|
+
* console.log(result); // [{ name: 'Alice' }]
|
|
65
|
+
*/
|
|
66
|
+
declare function takeRightWhile<T>(array: ArrayLike<T> | null | undefined, matchesProperty: [keyof T, unknown]): T[];
|
|
67
|
+
/**
|
|
68
|
+
* Creates a slice of array with elements taken from the end until the element does not have a truthy value for the given property key.
|
|
69
|
+
*
|
|
70
|
+
* If the array is `null` or `undefined`, returns an empty array.
|
|
71
|
+
*
|
|
72
|
+
* @template T
|
|
73
|
+
* @param {ArrayLike<T> | null | undefined} array - The array to process.
|
|
74
|
+
* @param {PropertyKey} property - A property key. Elements are included if they have a truthy value for this key.
|
|
75
|
+
* @returns {T[]} - A slice of the array with elements taken from the end or an empty array if `array` is `null` or `undefined`.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* const items = [{ valid: false }, { valid: true }, { valid: true }];
|
|
79
|
+
* const result = takeRightWhile(items, 'valid');
|
|
80
|
+
* console.log(result); // [{ valid: true }, { valid: true }]
|
|
81
|
+
*/
|
|
82
|
+
declare function takeRightWhile<T>(array: ArrayLike<T> | null | undefined, property: PropertyKey): T[];
|
|
83
|
+
|
|
84
|
+
export { takeRightWhile };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { negate } from '../../function/negate.mjs';
|
|
2
|
+
import { toArray } from '../_internal/toArray.mjs';
|
|
3
|
+
import { isArrayLikeObject } from '../predicate/isArrayLikeObject.mjs';
|
|
4
|
+
import { iteratee } from '../util/iteratee.mjs';
|
|
5
|
+
|
|
6
|
+
function takeRightWhile(_array, predicate) {
|
|
7
|
+
if (!isArrayLikeObject(_array)) {
|
|
8
|
+
return [];
|
|
9
|
+
}
|
|
10
|
+
const array = toArray(_array);
|
|
11
|
+
const index = array.findLastIndex(negate(iteratee(predicate)));
|
|
12
|
+
return array.slice(index + 1);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { takeRightWhile };
|
|
@@ -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 };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Invokes the specified function after a delay of the given number of milliseconds.
|
|
3
|
+
* Any additional arguments are passed to the function when it is invoked.
|
|
4
|
+
*
|
|
5
|
+
* @param {(...args: any[]) => any} func - The function to delay.
|
|
6
|
+
* @param {number} wait - The number of milliseconds to delay the invocation.
|
|
7
|
+
* @param {...any[]} args - The arguments to pass to the function when it is invoked.
|
|
8
|
+
* @returns {number} Returns the timer id.
|
|
9
|
+
* @throws {TypeError} If the first argument is not a function.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* // Example 1: Delayed function execution
|
|
13
|
+
* const timerId = delay(
|
|
14
|
+
* (greeting, recipient) => {
|
|
15
|
+
* console.log(`${greeting}, ${recipient}!`);
|
|
16
|
+
* },
|
|
17
|
+
* 1000,
|
|
18
|
+
* 'Hello',
|
|
19
|
+
* 'Alice'
|
|
20
|
+
* );
|
|
21
|
+
* // => 'Hello, Alice!' will be logged after one second.
|
|
22
|
+
*
|
|
23
|
+
* // Example 2: Clearing the timeout before execution
|
|
24
|
+
* clearTimeout(timerId);
|
|
25
|
+
* // The function will not be executed because the timeout was cleared.
|
|
26
|
+
*/
|
|
27
|
+
declare function delay(func: (...args: any[]) => any, wait: number, ...args: any[]): number;
|
|
28
|
+
|
|
29
|
+
export { delay };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Invokes the specified function after a delay of the given number of milliseconds.
|
|
3
|
+
* Any additional arguments are passed to the function when it is invoked.
|
|
4
|
+
*
|
|
5
|
+
* @param {(...args: any[]) => any} func - The function to delay.
|
|
6
|
+
* @param {number} wait - The number of milliseconds to delay the invocation.
|
|
7
|
+
* @param {...any[]} args - The arguments to pass to the function when it is invoked.
|
|
8
|
+
* @returns {number} Returns the timer id.
|
|
9
|
+
* @throws {TypeError} If the first argument is not a function.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* // Example 1: Delayed function execution
|
|
13
|
+
* const timerId = delay(
|
|
14
|
+
* (greeting, recipient) => {
|
|
15
|
+
* console.log(`${greeting}, ${recipient}!`);
|
|
16
|
+
* },
|
|
17
|
+
* 1000,
|
|
18
|
+
* 'Hello',
|
|
19
|
+
* 'Alice'
|
|
20
|
+
* );
|
|
21
|
+
* // => 'Hello, Alice!' will be logged after one second.
|
|
22
|
+
*
|
|
23
|
+
* // Example 2: Clearing the timeout before execution
|
|
24
|
+
* clearTimeout(timerId);
|
|
25
|
+
* // The function will not be executed because the timeout was cleared.
|
|
26
|
+
*/
|
|
27
|
+
declare function delay(func: (...args: any[]) => any, wait: number, ...args: any[]): number;
|
|
28
|
+
|
|
29
|
+
export { delay };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a function that retrieves the argument at the specified index `n`.
|
|
3
|
+
*
|
|
4
|
+
* If `n` is negative, the nth argument from the end is returned.
|
|
5
|
+
*
|
|
6
|
+
* @param {number} [n=0] - The index of the argument to retrieve.
|
|
7
|
+
* If negative, counts from the end of the arguments list.
|
|
8
|
+
* @returns {(args: any[]) => unknown} A new function that returns the argument at the specified index.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const getSecondArg = nthArg(1);
|
|
12
|
+
* const result = getSecondArg('a', 'b', 'c');
|
|
13
|
+
* console.log(result); // => 'b'
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const getLastArg = nthArg(-1);
|
|
17
|
+
* const result = getLastArg('a', 'b', 'c');
|
|
18
|
+
* console.log(result); // => 'c'
|
|
19
|
+
*/
|
|
20
|
+
declare function nthArg(n?: number): (...args: any[]) => unknown;
|
|
21
|
+
|
|
22
|
+
export { nthArg };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a function that retrieves the argument at the specified index `n`.
|
|
3
|
+
*
|
|
4
|
+
* If `n` is negative, the nth argument from the end is returned.
|
|
5
|
+
*
|
|
6
|
+
* @param {number} [n=0] - The index of the argument to retrieve.
|
|
7
|
+
* If negative, counts from the end of the arguments list.
|
|
8
|
+
* @returns {(args: any[]) => unknown} A new function that returns the argument at the specified index.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const getSecondArg = nthArg(1);
|
|
12
|
+
* const result = getSecondArg('a', 'b', 'c');
|
|
13
|
+
* console.log(result); // => 'b'
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const getLastArg = nthArg(-1);
|
|
17
|
+
* const result = getLastArg('a', 'b', 'c');
|
|
18
|
+
* console.log(result); // => 'c'
|
|
19
|
+
*/
|
|
20
|
+
declare function nthArg(n?: number): (...args: any[]) => unknown;
|
|
21
|
+
|
|
22
|
+
export { nthArg };
|
package/dist/compat/index.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { at } from '../array/at.mjs';
|
|
2
2
|
export { countBy } from '../array/countBy.mjs';
|
|
3
|
-
export { differenceWith } from '../array/differenceWith.mjs';
|
|
4
3
|
export { flatMap } from '../array/flatMap.mjs';
|
|
5
4
|
export { flatMapDeep } from '../array/flatMapDeep.mjs';
|
|
6
5
|
export { forEachRight } from '../array/forEachRight.mjs';
|
|
@@ -16,7 +15,6 @@ export { partition } from '../array/partition.mjs';
|
|
|
16
15
|
export { pullAt } from '../array/pullAt.mjs';
|
|
17
16
|
export { sampleSize } from '../array/sampleSize.mjs';
|
|
18
17
|
export { shuffle } from '../array/shuffle.mjs';
|
|
19
|
-
export { takeRightWhile } from '../array/takeRightWhile.mjs';
|
|
20
18
|
export { takeWhile } from '../array/takeWhile.mjs';
|
|
21
19
|
export { toFilled } from '../array/toFilled.mjs';
|
|
22
20
|
export { unionBy } from '../array/unionBy.mjs';
|
|
@@ -30,7 +28,6 @@ export { zipObject } from '../array/zipObject.mjs';
|
|
|
30
28
|
export { zipWith } from '../array/zipWith.mjs';
|
|
31
29
|
export { AbortError } from '../error/AbortError.mjs';
|
|
32
30
|
export { TimeoutError } from '../error/TimeoutError.mjs';
|
|
33
|
-
export { after } from '../function/after.mjs';
|
|
34
31
|
export { identity } from '../function/identity.mjs';
|
|
35
32
|
export { MemoizeCache, memoize } from '../function/memoize.mjs';
|
|
36
33
|
export { negate } from '../function/negate.mjs';
|
|
@@ -45,10 +42,7 @@ export { meanBy } from '../math/meanBy.mjs';
|
|
|
45
42
|
export { median } from '../math/median.mjs';
|
|
46
43
|
export { medianBy } from '../math/medianBy.mjs';
|
|
47
44
|
export { randomInt } from '../math/randomInt.mjs';
|
|
48
|
-
export { range } from '../math/range.mjs';
|
|
49
|
-
export { rangeRight } from '../math/rangeRight.mjs';
|
|
50
45
|
export { clone } from '../object/clone.mjs';
|
|
51
|
-
export { findKey } from '../object/findKey.mjs';
|
|
52
46
|
export { flattenObject } from '../object/flattenObject.mjs';
|
|
53
47
|
export { invert } from '../object/invert.mjs';
|
|
54
48
|
export { omitBy } from '../object/omitBy.mjs';
|
|
@@ -65,17 +59,11 @@ export { isNotNil } from '../predicate/isNotNil.mjs';
|
|
|
65
59
|
export { isNull } from '../predicate/isNull.mjs';
|
|
66
60
|
export { isPrimitive } from '../predicate/isPrimitive.mjs';
|
|
67
61
|
export { isUndefined } from '../predicate/isUndefined.mjs';
|
|
68
|
-
export { delay } from '../promise/delay.mjs';
|
|
69
62
|
export { timeout } from '../promise/timeout.mjs';
|
|
70
63
|
export { withTimeout } from '../promise/withTimeout.mjs';
|
|
71
64
|
export { capitalize } from '../string/capitalize.mjs';
|
|
72
65
|
export { constantCase } from '../string/constantCase.mjs';
|
|
73
|
-
export { deburr } from '../string/deburr.mjs';
|
|
74
|
-
export { escapeRegExp } from '../string/escapeRegExp.mjs';
|
|
75
|
-
export { lowerFirst } from '../string/lowerFirst.mjs';
|
|
76
66
|
export { pascalCase } from '../string/pascalCase.mjs';
|
|
77
|
-
export { unescape } from '../string/unescape.mjs';
|
|
78
|
-
export { upperFirst } from '../string/upperFirst.mjs';
|
|
79
67
|
export { invariant } from '../util/invariant.mjs';
|
|
80
68
|
export { castArray } from './array/castArray.mjs';
|
|
81
69
|
export { chunk } from './array/chunk.mjs';
|
|
@@ -83,6 +71,7 @@ export { compact } from './array/compact.mjs';
|
|
|
83
71
|
export { concat } from './array/concat.mjs';
|
|
84
72
|
export { difference } from './array/difference.mjs';
|
|
85
73
|
export { differenceBy } from './array/differenceBy.mjs';
|
|
74
|
+
export { differenceWith } from './array/differenceWith.mjs';
|
|
86
75
|
export { drop } from './array/drop.mjs';
|
|
87
76
|
export { dropRight } from './array/dropRight.mjs';
|
|
88
77
|
export { dropRightWhile } from './array/dropRightWhile.mjs';
|
|
@@ -105,7 +94,10 @@ export { intersectionBy } from './array/intersectionBy.mjs';
|
|
|
105
94
|
export { join } from './array/join.mjs';
|
|
106
95
|
export { last } from './array/last.mjs';
|
|
107
96
|
export { lastIndexOf } from './array/lastIndexOf.mjs';
|
|
97
|
+
export { map } from './array/map.mjs';
|
|
98
|
+
export { nth } from './array/nth.mjs';
|
|
108
99
|
export { orderBy } from './array/orderBy.mjs';
|
|
100
|
+
export { pull } from './array/pull.mjs';
|
|
109
101
|
export { sample } from './array/sample.mjs';
|
|
110
102
|
export { size } from './array/size.mjs';
|
|
111
103
|
export { slice } from './array/slice.mjs';
|
|
@@ -114,6 +106,7 @@ export { sortBy } from './array/sortBy.mjs';
|
|
|
114
106
|
export { tail } from './array/tail.mjs';
|
|
115
107
|
export { take } from './array/take.mjs';
|
|
116
108
|
export { takeRight } from './array/takeRight.mjs';
|
|
109
|
+
export { takeRightWhile } from './array/takeRightWhile.mjs';
|
|
117
110
|
export { union } from './array/union.mjs';
|
|
118
111
|
export { uniq } from './array/uniq.mjs';
|
|
119
112
|
export { uniqBy } from './array/uniqBy.mjs';
|
|
@@ -121,6 +114,7 @@ export { unzip } from './array/unzip.mjs';
|
|
|
121
114
|
export { without } from './array/without.mjs';
|
|
122
115
|
export { zip } from './array/zip.mjs';
|
|
123
116
|
export { zipObjectDeep } from './array/zipObjectDeep.mjs';
|
|
117
|
+
export { after } from './function/after.mjs';
|
|
124
118
|
export { ary } from './function/ary.mjs';
|
|
125
119
|
export { attempt } from './function/attempt.mjs';
|
|
126
120
|
export { before } from './function/before.mjs';
|
|
@@ -130,9 +124,11 @@ export { curry } from './function/curry.mjs';
|
|
|
130
124
|
export { curryRight } from './function/curryRight.mjs';
|
|
131
125
|
export { DebouncedFunction as DebouncedFunc, DebouncedFunction, debounce } from './function/debounce.mjs';
|
|
132
126
|
export { defer } from './function/defer.mjs';
|
|
127
|
+
export { delay } from './function/delay.mjs';
|
|
133
128
|
export { flip } from './function/flip.mjs';
|
|
134
129
|
export { flow } from './function/flow.mjs';
|
|
135
130
|
export { flowRight } from './function/flowRight.mjs';
|
|
131
|
+
export { nthArg } from './function/nthArg.mjs';
|
|
136
132
|
export { rearg } from './function/rearg.mjs';
|
|
137
133
|
export { rest } from './function/rest.mjs';
|
|
138
134
|
export { spread } from './function/spread.mjs';
|
|
@@ -146,6 +142,8 @@ export { max } from './math/max.mjs';
|
|
|
146
142
|
export { min } from './math/min.mjs';
|
|
147
143
|
export { parseInt } from './math/parseInt.mjs';
|
|
148
144
|
export { random } from './math/random.mjs';
|
|
145
|
+
export { range } from './math/range.mjs';
|
|
146
|
+
export { rangeRight } from './math/rangeRight.mjs';
|
|
149
147
|
export { round } from './math/round.mjs';
|
|
150
148
|
export { sum } from './math/sum.mjs';
|
|
151
149
|
export { sumBy } from './math/sumBy.mjs';
|
|
@@ -153,10 +151,12 @@ export { assignIn, assignIn as extend } from './object/assignIn.mjs';
|
|
|
153
151
|
export { cloneDeep } from './object/cloneDeep.mjs';
|
|
154
152
|
export { cloneDeepWith } from './object/cloneDeepWith.mjs';
|
|
155
153
|
export { defaults } from './object/defaults.mjs';
|
|
154
|
+
export { findKey } from './object/findKey.mjs';
|
|
156
155
|
export { fromPairs } from './object/fromPairs.mjs';
|
|
157
156
|
export { get } from './object/get.mjs';
|
|
158
157
|
export { has } from './object/has.mjs';
|
|
159
158
|
export { invertBy } from './object/invertBy.mjs';
|
|
159
|
+
export { keys } from './object/keys.mjs';
|
|
160
160
|
export { keysIn } from './object/keysIn.mjs';
|
|
161
161
|
export { mapKeys } from './object/mapKeys.mjs';
|
|
162
162
|
export { mapValues } from './object/mapValues.mjs';
|
|
@@ -165,6 +165,7 @@ export { mergeWith } from './object/mergeWith.mjs';
|
|
|
165
165
|
export { omit } from './object/omit.mjs';
|
|
166
166
|
export { pick } from './object/pick.mjs';
|
|
167
167
|
export { property } from './object/property.mjs';
|
|
168
|
+
export { propertyOf } from './object/propertyOf.mjs';
|
|
168
169
|
export { set } from './object/set.mjs';
|
|
169
170
|
export { toDefaulted } from './object/toDefaulted.mjs';
|
|
170
171
|
export { unset } from './object/unset.mjs';
|
|
@@ -202,10 +203,13 @@ export { isWeakSet } from './predicate/isWeakSet.mjs';
|
|
|
202
203
|
export { matches } from './predicate/matches.mjs';
|
|
203
204
|
export { matchesProperty } from './predicate/matchesProperty.mjs';
|
|
204
205
|
export { camelCase } from './string/camelCase.mjs';
|
|
206
|
+
export { deburr } from './string/deburr.mjs';
|
|
205
207
|
export { endsWith } from './string/endsWith.mjs';
|
|
206
208
|
export { escape } from './string/escape.mjs';
|
|
209
|
+
export { escapeRegExp } from './string/escapeRegExp.mjs';
|
|
207
210
|
export { kebabCase } from './string/kebabCase.mjs';
|
|
208
211
|
export { lowerCase } from './string/lowerCase.mjs';
|
|
212
|
+
export { lowerFirst } from './string/lowerFirst.mjs';
|
|
209
213
|
export { pad } from './string/pad.mjs';
|
|
210
214
|
export { padEnd } from './string/padEnd.mjs';
|
|
211
215
|
export { padStart } from './string/padStart.mjs';
|
|
@@ -215,18 +219,31 @@ export { snakeCase } from './string/snakeCase.mjs';
|
|
|
215
219
|
export { startCase } from './string/startCase.mjs';
|
|
216
220
|
export { startsWith } from './string/startsWith.mjs';
|
|
217
221
|
export { template, templateSettings } from './string/template.mjs';
|
|
222
|
+
export { toLower } from './string/toLower.mjs';
|
|
218
223
|
export { toUpper } from './string/toUpper.mjs';
|
|
219
224
|
export { trim } from './string/trim.mjs';
|
|
220
225
|
export { trimEnd } from './string/trimEnd.mjs';
|
|
221
226
|
export { trimStart } from './string/trimStart.mjs';
|
|
227
|
+
export { unescape } from './string/unescape.mjs';
|
|
222
228
|
export { upperCase } from './string/upperCase.mjs';
|
|
229
|
+
export { upperFirst } from './string/upperFirst.mjs';
|
|
223
230
|
export { words } from './string/words.mjs';
|
|
224
231
|
export { constant } from './util/constant.mjs';
|
|
225
232
|
export { defaultTo } from './util/defaultTo.mjs';
|
|
226
233
|
export { eq } from './util/eq.mjs';
|
|
227
234
|
export { gt } from './util/gt.mjs';
|
|
228
235
|
export { gte } from './util/gte.mjs';
|
|
236
|
+
export { invoke } from './util/invoke.mjs';
|
|
229
237
|
export { iteratee } from './util/iteratee.mjs';
|
|
238
|
+
export { lt } from './util/lt.mjs';
|
|
239
|
+
export { lte } from './util/lte.mjs';
|
|
240
|
+
export { method } from './util/method.mjs';
|
|
241
|
+
export { now } from './util/now.mjs';
|
|
242
|
+
export { stubArray } from './util/stubArray.mjs';
|
|
243
|
+
export { stubFalse } from './util/stubFalse.mjs';
|
|
244
|
+
export { stubObject } from './util/stubObject.mjs';
|
|
245
|
+
export { stubString } from './util/stubString.mjs';
|
|
246
|
+
export { stubTrue } from './util/stubTrue.mjs';
|
|
230
247
|
export { times } from './util/times.mjs';
|
|
231
248
|
export { toArray } from './util/toArray.mjs';
|
|
232
249
|
export { toFinite } from './util/toFinite.mjs';
|
|
@@ -234,6 +251,6 @@ export { toInteger } from './util/toInteger.mjs';
|
|
|
234
251
|
export { toLength } from './util/toLength.mjs';
|
|
235
252
|
export { toNumber } from './util/toNumber.mjs';
|
|
236
253
|
export { toPath } from './util/toPath.mjs';
|
|
254
|
+
export { toPlainObject } from './util/toPlainObject.mjs';
|
|
237
255
|
export { toSafeInteger } from './util/toSafeInteger.mjs';
|
|
238
256
|
export { toString } from './util/toString.mjs';
|
|
239
|
-
export { uniqueId } from './util/uniqueId.mjs';
|