es-toolkit 1.26.1 → 1.27.0-dev.874
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 +12 -0
- package/dist/_chunk/{sumBy-RVppiV.js → rangeRight-w3WrXN.js} +2 -14
- package/dist/_chunk/{toMerged-wNz52b.js → toMerged-CPY8Ug.js} +7 -1
- package/dist/_chunk/{upperFirst-BUECmK.js → upperFirst-DK_rTF.js} +23 -23
- package/dist/_chunk/{zipWith-Dkv3D1.js → zipWith-Bb2eZI.js} +19 -5
- package/dist/array/at.mjs +7 -2
- package/dist/array/index.d.mts +1 -0
- package/dist/array/index.d.ts +1 -0
- package/dist/array/index.js +2 -1
- package/dist/array/index.mjs +1 -0
- package/dist/array/isSubsetWith.d.mts +33 -0
- package/dist/array/isSubsetWith.d.ts +33 -0
- package/dist/array/isSubsetWith.mjs +7 -0
- package/dist/array/without.mjs +3 -2
- package/dist/array/zip.mjs +6 -1
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/_internal/flattenArrayLike.mjs +17 -0
- package/dist/compat/_internal/isPrototype.mjs +7 -0
- package/dist/compat/_internal/toArray.mjs +5 -0
- package/dist/compat/array/chunk.mjs +2 -1
- package/dist/compat/array/difference.mjs +2 -1
- package/dist/compat/array/differenceBy.d.mts +82 -0
- package/dist/compat/array/differenceBy.d.ts +82 -0
- package/dist/compat/array/differenceBy.mjs +20 -0
- package/dist/compat/array/drop.mjs +2 -1
- package/dist/compat/array/dropRight.mjs +2 -1
- package/dist/compat/array/dropWhile.mjs +2 -1
- package/dist/compat/array/findLastIndex.mjs +2 -1
- package/dist/compat/array/forEach.d.mts +106 -0
- package/dist/compat/array/forEach.d.ts +106 -0
- package/dist/compat/array/forEach.mjs +21 -0
- package/dist/compat/array/head.mjs +2 -1
- package/dist/compat/array/last.mjs +2 -1
- package/dist/compat/array/sample.mjs +2 -1
- package/dist/compat/array/tail.mjs +2 -1
- package/dist/compat/array/take.mjs +2 -1
- package/dist/compat/array/takeRight.mjs +2 -1
- package/dist/compat/array/union.d.mts +30 -0
- package/dist/compat/array/union.d.ts +30 -0
- package/dist/compat/array/union.mjs +11 -0
- package/dist/compat/array/uniqBy.d.mts +60 -0
- package/dist/compat/array/uniqBy.d.ts +60 -0
- package/dist/compat/array/uniqBy.mjs +25 -0
- package/dist/compat/array/unzip.d.mts +16 -0
- package/dist/compat/array/unzip.d.ts +16 -0
- package/dist/compat/array/unzip.mjs +14 -0
- package/dist/compat/array/zip.d.mts +134 -0
- package/dist/compat/array/zip.d.ts +134 -0
- package/dist/compat/array/zip.mjs +11 -0
- package/dist/compat/index.d.mts +15 -8
- package/dist/compat/index.d.ts +15 -8
- package/dist/compat/index.js +312 -104
- package/dist/compat/index.mjs +15 -8
- package/dist/compat/math/sum.d.mts +37 -0
- package/dist/compat/math/sum.d.ts +37 -0
- package/dist/compat/math/sum.mjs +7 -0
- package/dist/compat/math/sumBy.d.mts +64 -0
- package/dist/compat/math/sumBy.d.ts +64 -0
- package/dist/compat/math/sumBy.mjs +20 -0
- package/dist/compat/predicate/isEmpty.d.mts +78 -0
- package/dist/compat/predicate/isEmpty.d.ts +78 -0
- package/dist/compat/predicate/isEmpty.mjs +33 -0
- package/dist/compat/string/replace.d.mts +17 -0
- package/dist/compat/string/replace.d.ts +17 -0
- package/dist/compat/string/replace.mjs +10 -0
- package/dist/compat/string/startCase.mjs +4 -4
- package/dist/compat/util/iteratee.d.mts +44 -0
- package/dist/compat/util/iteratee.d.ts +44 -0
- package/dist/compat/util/iteratee.mjs +28 -0
- package/dist/compat/util/toPath.mjs +56 -25
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +17 -14
- package/dist/index.mjs +3 -0
- package/dist/math/index.js +19 -11
- package/dist/math/range.mjs +1 -4
- package/dist/math/rangeRight.mjs +1 -4
- package/dist/math/sumBy.mjs +5 -4
- package/dist/object/cloneDeep.mjs +1 -1
- package/dist/object/findKey.d.mts +21 -0
- package/dist/object/findKey.d.ts +21 -0
- package/dist/object/findKey.mjs +6 -0
- package/dist/object/index.d.mts +1 -0
- package/dist/object/index.d.ts +1 -0
- package/dist/object/index.js +2 -1
- package/dist/object/index.mjs +1 -0
- package/dist/object/mapKeys.d.mts +4 -5
- package/dist/object/mapKeys.d.ts +4 -5
- package/dist/object/mergeWith.d.mts +1 -1
- package/dist/object/mergeWith.d.ts +1 -1
- package/dist/object/toMerged.d.mts +1 -1
- package/dist/object/toMerged.d.ts +1 -1
- package/dist/string/camelCase.mjs +4 -4
- package/dist/string/constantCase.mjs +3 -3
- package/dist/string/index.d.mts +1 -0
- package/dist/string/index.d.ts +1 -0
- package/dist/string/index.js +3 -2
- package/dist/string/index.mjs +1 -0
- package/dist/string/kebabCase.mjs +3 -3
- package/dist/string/lowerCase.mjs +3 -3
- package/dist/string/pascalCase.mjs +3 -3
- package/dist/string/snakeCase.mjs +3 -3
- package/dist/string/startCase.mjs +4 -4
- package/dist/string/upperCase.mjs +5 -5
- package/dist/string/words.d.mts +20 -0
- package/dist/string/words.d.ts +20 -0
- package/dist/string/{_internal/getWords.mjs → words.mjs} +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { isArrayLikeObject } from '../predicate/isArrayLikeObject.mjs';
|
|
2
|
+
|
|
3
|
+
function flattenArrayLike(values) {
|
|
4
|
+
const result = [];
|
|
5
|
+
for (let i = 0; i < values.length; i++) {
|
|
6
|
+
const arrayLike = values[i];
|
|
7
|
+
if (!isArrayLikeObject(arrayLike)) {
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
for (let j = 0; j < arrayLike.length; j++) {
|
|
11
|
+
result.push(arrayLike[j]);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { flattenArrayLike };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { chunk as chunk$1 } from '../../array/chunk.mjs';
|
|
2
|
+
import { toArray } from '../_internal/toArray.mjs';
|
|
2
3
|
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
3
4
|
|
|
4
5
|
function chunk(arr, size = 1) {
|
|
@@ -6,7 +7,7 @@ function chunk(arr, size = 1) {
|
|
|
6
7
|
if (size === 0 || !isArrayLike(arr)) {
|
|
7
8
|
return [];
|
|
8
9
|
}
|
|
9
|
-
return chunk$1(
|
|
10
|
+
return chunk$1(toArray(arr), size);
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
export { chunk };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { difference as difference$1 } from '../../array/difference.mjs';
|
|
2
|
+
import { toArray } from '../_internal/toArray.mjs';
|
|
2
3
|
import { isArrayLikeObject } from '../predicate/isArrayLikeObject.mjs';
|
|
3
4
|
|
|
4
5
|
function difference(arr, ...values) {
|
|
5
6
|
if (!isArrayLikeObject(arr)) {
|
|
6
7
|
return [];
|
|
7
8
|
}
|
|
8
|
-
const arr1 =
|
|
9
|
+
const arr1 = toArray(arr);
|
|
9
10
|
const arr2 = [];
|
|
10
11
|
for (let i = 0; i < values.length; i++) {
|
|
11
12
|
const value = values[i];
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
type Iteratee<T> = PropertyKey | Partial<T> | ((value: T) => unknown);
|
|
2
|
+
/**
|
|
3
|
+
* Computes the difference between an array and another array using an iteratee function.
|
|
4
|
+
*
|
|
5
|
+
* @template T1, T2
|
|
6
|
+
* @param {ArrayLike<T1> | null | undefined} array - The primary array from which to derive the difference.
|
|
7
|
+
* @param {ArrayLike<T2>} values - The array containing elements to be excluded from the primary array.
|
|
8
|
+
* @param {Iteratee<T1 | T2>} iteratee - The iteratee invoked per element.
|
|
9
|
+
* @returns {T1[]} A new array containing the elements that are present in the primary array but not in the values array.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const result = differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
|
|
13
|
+
* // result will be [1.2]
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const result = differenceBy([{ x: 2 }, { x: 1 }], [{ x: 1 }], 'x');
|
|
17
|
+
* // result will be [{ x: 2 }]
|
|
18
|
+
*/
|
|
19
|
+
declare function differenceBy<T1, T2>(array: ArrayLike<T1> | null | undefined, values: ArrayLike<T2>, iteratee: Iteratee<T1 | T2>): T1[];
|
|
20
|
+
/**
|
|
21
|
+
* Computes the difference between an array and two other arrays using an iteratee function.
|
|
22
|
+
*
|
|
23
|
+
* @template T1, T2, T3
|
|
24
|
+
* @param {ArrayLike<T1> | null | undefined} array - The primary array from which to derive the difference.
|
|
25
|
+
* @param {ArrayLike<T2>} values1 - The first array containing elements to be excluded from the primary array.
|
|
26
|
+
* @param {ArrayLike<T3>} values2 - The second array containing elements to be excluded from the primary array.
|
|
27
|
+
* @param {Iteratee<T1 | T2 | T3>} iteratee - The iteratee invoked per element.
|
|
28
|
+
* @returns {T1[]} A new array containing the elements that are present in the primary array but not in the values arrays.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* const result = differenceBy([2.1, 1.2], [2.3, 3.4], [1.2], Math.floor);
|
|
32
|
+
* // result will be []
|
|
33
|
+
*/
|
|
34
|
+
declare function differenceBy<T1, T2, T3>(array: ArrayLike<T1> | null | undefined, values1: ArrayLike<T2>, values2: ArrayLike<T3>, iteratee: Iteratee<T1 | T2 | T3>): T1[];
|
|
35
|
+
/**
|
|
36
|
+
* Computes the difference between an array and three other arrays using an iteratee function.
|
|
37
|
+
*
|
|
38
|
+
* @template T1, T2, T3, T4
|
|
39
|
+
* @param {ArrayLike<T1> | null | undefined} array - The primary array from which to derive the difference.
|
|
40
|
+
* @param {ArrayLike<T2>} values1 - The first array containing elements to be excluded from the primary array.
|
|
41
|
+
* @param {ArrayLike<T3>} values2 - The second array containing elements to be excluded from the primary array.
|
|
42
|
+
* @param {ArrayLike<T4>} values3 - The third array containing elements to be excluded from the primary array.
|
|
43
|
+
* @param {Iteratee<T1 | T2 | T3 | T4>} iteratee - The iteratee invoked per element.
|
|
44
|
+
* @returns {T1[]} A new array containing the elements that are present in the primary array but not in the values arrays.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* const result = differenceBy([2.1, 1.2], [2.3, 3.4], [1.2], [2.1], Math.floor);
|
|
48
|
+
* // result will be []
|
|
49
|
+
*/
|
|
50
|
+
declare function differenceBy<T1, T2, T3, T4>(array: ArrayLike<T1> | null | undefined, values1: ArrayLike<T2>, values2: ArrayLike<T3>, values3: ArrayLike<T4>, iteratee: Iteratee<T1 | T2 | T3 | T4>): T1[];
|
|
51
|
+
/**
|
|
52
|
+
* Computes the difference between an array and four other arrays using an iteratee function.
|
|
53
|
+
*
|
|
54
|
+
* @template T1, T2, T3, T4, T5
|
|
55
|
+
* @param {ArrayLike<T1> | null | undefined} array - The primary array from which to derive the difference.
|
|
56
|
+
* @param {ArrayLike<T2>} values1 - The first array containing elements to be excluded from the primary array.
|
|
57
|
+
* @param {ArrayLike<T3>} values2 - The second array containing elements to be excluded from the primary array.
|
|
58
|
+
* @param {ArrayLike<T4>} values3 - The third array containing elements to be excluded from the primary array.
|
|
59
|
+
* @param {ArrayLike<T5>} values4 - The fourth array containing elements to be excluded from the primary array.
|
|
60
|
+
* @param {Iteratee<T1 | T2 | T3 | T4 | T5>} iteratee - The iteratee invoked per element.
|
|
61
|
+
* @returns {T1[]} A new array containing the elements that are present in the primary array but not in the values arrays.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* const result = differenceBy([2.1, 1.2], [2.3, 3.4], [1.2], [2.1], [3.4], Math.floor);
|
|
65
|
+
* // result will be []
|
|
66
|
+
*/
|
|
67
|
+
declare function differenceBy<T1, T2, T3, T4, T5>(array: ArrayLike<T1> | null | undefined, values1: ArrayLike<T2>, values2: ArrayLike<T3>, values3: ArrayLike<T4>, values4: ArrayLike<T5>, iteratee: Iteratee<T1 | T2 | T3 | T4 | T5>): T1[];
|
|
68
|
+
/**
|
|
69
|
+
* Computes the difference between an array and multiple arrays using an iteratee function.
|
|
70
|
+
*
|
|
71
|
+
* @template T
|
|
72
|
+
* @param {ArrayLike<T> | null | undefined} array - The primary array from which to derive the difference.
|
|
73
|
+
* @param {...Array<ArrayLike<T>>} values - Multiple arrays containing elements to be excluded from the primary array.
|
|
74
|
+
* @returns {T[]} A new array containing the elements that are present in the primary array but not in the values arrays.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* const result = differenceBy([2.1, 1.2], [2.3, 3.4], [1.2], [2.1], [3.4], Math.floor);
|
|
78
|
+
* // result will be []
|
|
79
|
+
*/
|
|
80
|
+
declare function differenceBy<T>(array: ArrayLike<T> | null | undefined, ...values: Array<ArrayLike<T>>): T[];
|
|
81
|
+
|
|
82
|
+
export { differenceBy };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
type Iteratee<T> = PropertyKey | Partial<T> | ((value: T) => unknown);
|
|
2
|
+
/**
|
|
3
|
+
* Computes the difference between an array and another array using an iteratee function.
|
|
4
|
+
*
|
|
5
|
+
* @template T1, T2
|
|
6
|
+
* @param {ArrayLike<T1> | null | undefined} array - The primary array from which to derive the difference.
|
|
7
|
+
* @param {ArrayLike<T2>} values - The array containing elements to be excluded from the primary array.
|
|
8
|
+
* @param {Iteratee<T1 | T2>} iteratee - The iteratee invoked per element.
|
|
9
|
+
* @returns {T1[]} A new array containing the elements that are present in the primary array but not in the values array.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const result = differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
|
|
13
|
+
* // result will be [1.2]
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const result = differenceBy([{ x: 2 }, { x: 1 }], [{ x: 1 }], 'x');
|
|
17
|
+
* // result will be [{ x: 2 }]
|
|
18
|
+
*/
|
|
19
|
+
declare function differenceBy<T1, T2>(array: ArrayLike<T1> | null | undefined, values: ArrayLike<T2>, iteratee: Iteratee<T1 | T2>): T1[];
|
|
20
|
+
/**
|
|
21
|
+
* Computes the difference between an array and two other arrays using an iteratee function.
|
|
22
|
+
*
|
|
23
|
+
* @template T1, T2, T3
|
|
24
|
+
* @param {ArrayLike<T1> | null | undefined} array - The primary array from which to derive the difference.
|
|
25
|
+
* @param {ArrayLike<T2>} values1 - The first array containing elements to be excluded from the primary array.
|
|
26
|
+
* @param {ArrayLike<T3>} values2 - The second array containing elements to be excluded from the primary array.
|
|
27
|
+
* @param {Iteratee<T1 | T2 | T3>} iteratee - The iteratee invoked per element.
|
|
28
|
+
* @returns {T1[]} A new array containing the elements that are present in the primary array but not in the values arrays.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* const result = differenceBy([2.1, 1.2], [2.3, 3.4], [1.2], Math.floor);
|
|
32
|
+
* // result will be []
|
|
33
|
+
*/
|
|
34
|
+
declare function differenceBy<T1, T2, T3>(array: ArrayLike<T1> | null | undefined, values1: ArrayLike<T2>, values2: ArrayLike<T3>, iteratee: Iteratee<T1 | T2 | T3>): T1[];
|
|
35
|
+
/**
|
|
36
|
+
* Computes the difference between an array and three other arrays using an iteratee function.
|
|
37
|
+
*
|
|
38
|
+
* @template T1, T2, T3, T4
|
|
39
|
+
* @param {ArrayLike<T1> | null | undefined} array - The primary array from which to derive the difference.
|
|
40
|
+
* @param {ArrayLike<T2>} values1 - The first array containing elements to be excluded from the primary array.
|
|
41
|
+
* @param {ArrayLike<T3>} values2 - The second array containing elements to be excluded from the primary array.
|
|
42
|
+
* @param {ArrayLike<T4>} values3 - The third array containing elements to be excluded from the primary array.
|
|
43
|
+
* @param {Iteratee<T1 | T2 | T3 | T4>} iteratee - The iteratee invoked per element.
|
|
44
|
+
* @returns {T1[]} A new array containing the elements that are present in the primary array but not in the values arrays.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* const result = differenceBy([2.1, 1.2], [2.3, 3.4], [1.2], [2.1], Math.floor);
|
|
48
|
+
* // result will be []
|
|
49
|
+
*/
|
|
50
|
+
declare function differenceBy<T1, T2, T3, T4>(array: ArrayLike<T1> | null | undefined, values1: ArrayLike<T2>, values2: ArrayLike<T3>, values3: ArrayLike<T4>, iteratee: Iteratee<T1 | T2 | T3 | T4>): T1[];
|
|
51
|
+
/**
|
|
52
|
+
* Computes the difference between an array and four other arrays using an iteratee function.
|
|
53
|
+
*
|
|
54
|
+
* @template T1, T2, T3, T4, T5
|
|
55
|
+
* @param {ArrayLike<T1> | null | undefined} array - The primary array from which to derive the difference.
|
|
56
|
+
* @param {ArrayLike<T2>} values1 - The first array containing elements to be excluded from the primary array.
|
|
57
|
+
* @param {ArrayLike<T3>} values2 - The second array containing elements to be excluded from the primary array.
|
|
58
|
+
* @param {ArrayLike<T4>} values3 - The third array containing elements to be excluded from the primary array.
|
|
59
|
+
* @param {ArrayLike<T5>} values4 - The fourth array containing elements to be excluded from the primary array.
|
|
60
|
+
* @param {Iteratee<T1 | T2 | T3 | T4 | T5>} iteratee - The iteratee invoked per element.
|
|
61
|
+
* @returns {T1[]} A new array containing the elements that are present in the primary array but not in the values arrays.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* const result = differenceBy([2.1, 1.2], [2.3, 3.4], [1.2], [2.1], [3.4], Math.floor);
|
|
65
|
+
* // result will be []
|
|
66
|
+
*/
|
|
67
|
+
declare function differenceBy<T1, T2, T3, T4, T5>(array: ArrayLike<T1> | null | undefined, values1: ArrayLike<T2>, values2: ArrayLike<T3>, values3: ArrayLike<T4>, values4: ArrayLike<T5>, iteratee: Iteratee<T1 | T2 | T3 | T4 | T5>): T1[];
|
|
68
|
+
/**
|
|
69
|
+
* Computes the difference between an array and multiple arrays using an iteratee function.
|
|
70
|
+
*
|
|
71
|
+
* @template T
|
|
72
|
+
* @param {ArrayLike<T> | null | undefined} array - The primary array from which to derive the difference.
|
|
73
|
+
* @param {...Array<ArrayLike<T>>} values - Multiple arrays containing elements to be excluded from the primary array.
|
|
74
|
+
* @returns {T[]} A new array containing the elements that are present in the primary array but not in the values arrays.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* const result = differenceBy([2.1, 1.2], [2.3, 3.4], [1.2], [2.1], [3.4], Math.floor);
|
|
78
|
+
* // result will be []
|
|
79
|
+
*/
|
|
80
|
+
declare function differenceBy<T>(array: ArrayLike<T> | null | undefined, ...values: Array<ArrayLike<T>>): T[];
|
|
81
|
+
|
|
82
|
+
export { differenceBy };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { last } from './last.mjs';
|
|
2
|
+
import { difference } from '../../array/difference.mjs';
|
|
3
|
+
import { differenceBy as differenceBy$1 } from '../../array/differenceBy.mjs';
|
|
4
|
+
import { flattenArrayLike } from '../_internal/flattenArrayLike.mjs';
|
|
5
|
+
import { isArrayLikeObject } from '../predicate/isArrayLikeObject.mjs';
|
|
6
|
+
import { iteratee } from '../util/iteratee.mjs';
|
|
7
|
+
|
|
8
|
+
function differenceBy(arr, ..._values) {
|
|
9
|
+
if (!isArrayLikeObject(arr)) {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
const iteratee$1 = last(_values);
|
|
13
|
+
const values = flattenArrayLike(_values);
|
|
14
|
+
if (isArrayLikeObject(iteratee$1)) {
|
|
15
|
+
return difference(Array.from(arr), values);
|
|
16
|
+
}
|
|
17
|
+
return differenceBy$1(Array.from(arr), values, iteratee(iteratee$1));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { differenceBy };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { drop as drop$1 } from '../../array/drop.mjs';
|
|
2
|
+
import { toArray } from '../_internal/toArray.mjs';
|
|
2
3
|
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
3
4
|
import { toInteger } from '../util/toInteger.mjs';
|
|
4
5
|
|
|
@@ -7,7 +8,7 @@ function drop(collection, itemsCount = 1, guard) {
|
|
|
7
8
|
return [];
|
|
8
9
|
}
|
|
9
10
|
itemsCount = guard ? 1 : toInteger(itemsCount);
|
|
10
|
-
return drop$1(
|
|
11
|
+
return drop$1(toArray(collection), itemsCount);
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export { drop };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { dropRight as dropRight$1 } from '../../array/dropRight.mjs';
|
|
2
|
+
import { toArray } from '../_internal/toArray.mjs';
|
|
2
3
|
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
3
4
|
import { toInteger } from '../util/toInteger.mjs';
|
|
4
5
|
|
|
@@ -7,7 +8,7 @@ function dropRight(collection, itemsCount = 1, guard) {
|
|
|
7
8
|
return [];
|
|
8
9
|
}
|
|
9
10
|
itemsCount = guard ? 1 : toInteger(itemsCount);
|
|
10
|
-
return dropRight$1(
|
|
11
|
+
return dropRight$1(toArray(collection), itemsCount);
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export { dropRight };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { dropWhile as dropWhile$1 } from '../../array/dropWhile.mjs';
|
|
2
|
+
import { toArray } from '../_internal/toArray.mjs';
|
|
2
3
|
import { property } from '../object/property.mjs';
|
|
3
4
|
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
4
5
|
import { matches } from '../predicate/matches.mjs';
|
|
@@ -8,7 +9,7 @@ function dropWhile(arr, predicate) {
|
|
|
8
9
|
if (!isArrayLike(arr)) {
|
|
9
10
|
return [];
|
|
10
11
|
}
|
|
11
|
-
return dropWhileImpl(
|
|
12
|
+
return dropWhileImpl(toArray(arr), predicate);
|
|
12
13
|
}
|
|
13
14
|
function dropWhileImpl(arr, predicate) {
|
|
14
15
|
switch (typeof predicate) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { toArray } from '../_internal/toArray.mjs';
|
|
1
2
|
import { property } from '../object/property.mjs';
|
|
2
3
|
import { matches } from '../predicate/matches.mjs';
|
|
3
4
|
import { matchesProperty } from '../predicate/matchesProperty.mjs';
|
|
@@ -12,7 +13,7 @@ function findLastIndex(arr, doesMatch, fromIndex = arr ? arr.length - 1 : 0) {
|
|
|
12
13
|
else {
|
|
13
14
|
fromIndex = Math.min(fromIndex, arr.length - 1);
|
|
14
15
|
}
|
|
15
|
-
const subArray =
|
|
16
|
+
const subArray = toArray(arr).slice(0, fromIndex + 1);
|
|
16
17
|
switch (typeof doesMatch) {
|
|
17
18
|
case 'function': {
|
|
18
19
|
return subArray.findLastIndex(doesMatch);
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Iterates over each element of the array invoking the provided callback function for each element.
|
|
3
|
+
*
|
|
4
|
+
* @template K - The type of elements in the array.
|
|
5
|
+
* @template T - The type of the array.
|
|
6
|
+
* @param {T | null | undefined} array - The array to iterate over.
|
|
7
|
+
* @param {(value: K, index: number, array: T) => unknown} [callback] - The function invoked for each element.
|
|
8
|
+
* The callback function receives three arguments:
|
|
9
|
+
* - 'value': The current element being processed in the array.
|
|
10
|
+
* - 'index': The index of the current element being processed in the array.
|
|
11
|
+
* - 'array': The array 'forEach' was called upon.
|
|
12
|
+
* @returns {T} Returns the original array.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* forEach([1, 2, 3], (value, index, array) => console.log(value, index));
|
|
16
|
+
* // Output:
|
|
17
|
+
* // 1 0
|
|
18
|
+
* // 2 1
|
|
19
|
+
* // 3 2
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
declare function forEach<T>(array: T[], callback?: (value: T, index: number, array: T[]) => unknown): T[];
|
|
23
|
+
/**
|
|
24
|
+
* Iterates over each element of the array invoking the provided callback function for each element.
|
|
25
|
+
*
|
|
26
|
+
* @template K - The type of elements in the array.
|
|
27
|
+
* @template T - The type of the array.
|
|
28
|
+
* @param {T | null | undefined} array - The array to iterate over.
|
|
29
|
+
* @param {(value: K, index: number, array: T) => unknown} [callback] - The function invoked for each element.
|
|
30
|
+
* The callback function receives three arguments:
|
|
31
|
+
* - 'value': The current element being processed in the array.
|
|
32
|
+
* - 'index': The index of the current element being processed in the array.
|
|
33
|
+
* - 'array': The array 'forEach' was called upon.
|
|
34
|
+
* @returns {T} Returns the original array.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* forEach([1, 2, 3], (value, index, array) => console.log(value, index));
|
|
38
|
+
* // Output:
|
|
39
|
+
* // 1 0
|
|
40
|
+
* // 2 1
|
|
41
|
+
* // 3 2
|
|
42
|
+
*
|
|
43
|
+
*/
|
|
44
|
+
declare function forEach<T>(array: readonly T[], callback?: (value: T, index: number, array: T[]) => unknown): readonly T[];
|
|
45
|
+
/**
|
|
46
|
+
* Iterates over each element of the array invoking the provided callback function for each element.
|
|
47
|
+
*
|
|
48
|
+
* @template T - The type of string.
|
|
49
|
+
* @param {T | null | undefined} string - The string to iterate over
|
|
50
|
+
* @param {(value: T, index: number, string: T) => unknown} [callback] - The function invoked for each char.
|
|
51
|
+
* The callback function receives three arguments:
|
|
52
|
+
* - 'char': The current char being processed in the string.
|
|
53
|
+
* - 'index': The index of the current char being processed in the string.
|
|
54
|
+
* - 'string': The string 'forEach' was called upon.
|
|
55
|
+
* @returns {T} Returns the original string.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* forEach('abc', (char, index, string) => console.log(char, index));
|
|
59
|
+
* // Output:
|
|
60
|
+
* // 'a' 0
|
|
61
|
+
* // 'b' 1
|
|
62
|
+
* // 'c' 2
|
|
63
|
+
*/
|
|
64
|
+
declare function forEach<T extends string | null | undefined>(string: T, callback?: (char: string, index: number, string: string) => unknown): T;
|
|
65
|
+
/**
|
|
66
|
+
* Iterates over each element of the array invoking the provided callback function for each element.
|
|
67
|
+
*
|
|
68
|
+
* @template T - The type of elements in the array.
|
|
69
|
+
* @param { ArrayLike<T> } array - The array to iterate over.
|
|
70
|
+
* @param {(value: T, index: number, array: ArrayLike<T>) => unknown} [callback] - The function invoked for each element.
|
|
71
|
+
* The callback function receives three arguments:
|
|
72
|
+
* - 'value': The current element being processed in the array.
|
|
73
|
+
* - 'index': The index of the current element being processed in the array.
|
|
74
|
+
* - 'array': The array 'forEach' was called upon.
|
|
75
|
+
* @returns {T} Returns the original array.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* forEach([1, 2, 3], (value, index, array) => console.log(value, index));
|
|
79
|
+
* // Output:
|
|
80
|
+
* // 1 0
|
|
81
|
+
* // 2 1
|
|
82
|
+
* // 3 2
|
|
83
|
+
*
|
|
84
|
+
*/
|
|
85
|
+
declare function forEach<T>(array: ArrayLike<T>, callback?: (value: T, index: number, array: ArrayLike<T>) => unknown): ArrayLike<T>;
|
|
86
|
+
/**
|
|
87
|
+
* Iterates over each element of the object invoking the provided callback function for each property.
|
|
88
|
+
*
|
|
89
|
+
* @template T - The type of object.
|
|
90
|
+
* @param {T} object - The object to iterate over.
|
|
91
|
+
* @param {(value: T[keyof T], key: keyof T, object: T) => unknown} [callback] - The function invoked for each property.
|
|
92
|
+
* The callback function receives three arguments:
|
|
93
|
+
* - 'value': The current property being processed in the object.
|
|
94
|
+
* - 'key': The key of the current property being processed in the object.
|
|
95
|
+
* - 'object': The object 'forEach' was called upon.
|
|
96
|
+
* @returns {T} Returns the original object.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* forEach({'a': 1, 'b': 2 }, (value, key, object) => console.log(value, key));
|
|
100
|
+
* // Output:
|
|
101
|
+
* // 1 'a'
|
|
102
|
+
* // 2 'b'
|
|
103
|
+
*/
|
|
104
|
+
declare function forEach<T extends object | null | undefined>(object: T, callback?: (value: T[keyof T], key: keyof T, object: T) => unknown): T;
|
|
105
|
+
|
|
106
|
+
export { forEach };
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Iterates over each element of the array invoking the provided callback function for each element.
|
|
3
|
+
*
|
|
4
|
+
* @template K - The type of elements in the array.
|
|
5
|
+
* @template T - The type of the array.
|
|
6
|
+
* @param {T | null | undefined} array - The array to iterate over.
|
|
7
|
+
* @param {(value: K, index: number, array: T) => unknown} [callback] - The function invoked for each element.
|
|
8
|
+
* The callback function receives three arguments:
|
|
9
|
+
* - 'value': The current element being processed in the array.
|
|
10
|
+
* - 'index': The index of the current element being processed in the array.
|
|
11
|
+
* - 'array': The array 'forEach' was called upon.
|
|
12
|
+
* @returns {T} Returns the original array.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* forEach([1, 2, 3], (value, index, array) => console.log(value, index));
|
|
16
|
+
* // Output:
|
|
17
|
+
* // 1 0
|
|
18
|
+
* // 2 1
|
|
19
|
+
* // 3 2
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
declare function forEach<T>(array: T[], callback?: (value: T, index: number, array: T[]) => unknown): T[];
|
|
23
|
+
/**
|
|
24
|
+
* Iterates over each element of the array invoking the provided callback function for each element.
|
|
25
|
+
*
|
|
26
|
+
* @template K - The type of elements in the array.
|
|
27
|
+
* @template T - The type of the array.
|
|
28
|
+
* @param {T | null | undefined} array - The array to iterate over.
|
|
29
|
+
* @param {(value: K, index: number, array: T) => unknown} [callback] - The function invoked for each element.
|
|
30
|
+
* The callback function receives three arguments:
|
|
31
|
+
* - 'value': The current element being processed in the array.
|
|
32
|
+
* - 'index': The index of the current element being processed in the array.
|
|
33
|
+
* - 'array': The array 'forEach' was called upon.
|
|
34
|
+
* @returns {T} Returns the original array.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* forEach([1, 2, 3], (value, index, array) => console.log(value, index));
|
|
38
|
+
* // Output:
|
|
39
|
+
* // 1 0
|
|
40
|
+
* // 2 1
|
|
41
|
+
* // 3 2
|
|
42
|
+
*
|
|
43
|
+
*/
|
|
44
|
+
declare function forEach<T>(array: readonly T[], callback?: (value: T, index: number, array: T[]) => unknown): readonly T[];
|
|
45
|
+
/**
|
|
46
|
+
* Iterates over each element of the array invoking the provided callback function for each element.
|
|
47
|
+
*
|
|
48
|
+
* @template T - The type of string.
|
|
49
|
+
* @param {T | null | undefined} string - The string to iterate over
|
|
50
|
+
* @param {(value: T, index: number, string: T) => unknown} [callback] - The function invoked for each char.
|
|
51
|
+
* The callback function receives three arguments:
|
|
52
|
+
* - 'char': The current char being processed in the string.
|
|
53
|
+
* - 'index': The index of the current char being processed in the string.
|
|
54
|
+
* - 'string': The string 'forEach' was called upon.
|
|
55
|
+
* @returns {T} Returns the original string.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* forEach('abc', (char, index, string) => console.log(char, index));
|
|
59
|
+
* // Output:
|
|
60
|
+
* // 'a' 0
|
|
61
|
+
* // 'b' 1
|
|
62
|
+
* // 'c' 2
|
|
63
|
+
*/
|
|
64
|
+
declare function forEach<T extends string | null | undefined>(string: T, callback?: (char: string, index: number, string: string) => unknown): T;
|
|
65
|
+
/**
|
|
66
|
+
* Iterates over each element of the array invoking the provided callback function for each element.
|
|
67
|
+
*
|
|
68
|
+
* @template T - The type of elements in the array.
|
|
69
|
+
* @param { ArrayLike<T> } array - The array to iterate over.
|
|
70
|
+
* @param {(value: T, index: number, array: ArrayLike<T>) => unknown} [callback] - The function invoked for each element.
|
|
71
|
+
* The callback function receives three arguments:
|
|
72
|
+
* - 'value': The current element being processed in the array.
|
|
73
|
+
* - 'index': The index of the current element being processed in the array.
|
|
74
|
+
* - 'array': The array 'forEach' was called upon.
|
|
75
|
+
* @returns {T} Returns the original array.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* forEach([1, 2, 3], (value, index, array) => console.log(value, index));
|
|
79
|
+
* // Output:
|
|
80
|
+
* // 1 0
|
|
81
|
+
* // 2 1
|
|
82
|
+
* // 3 2
|
|
83
|
+
*
|
|
84
|
+
*/
|
|
85
|
+
declare function forEach<T>(array: ArrayLike<T>, callback?: (value: T, index: number, array: ArrayLike<T>) => unknown): ArrayLike<T>;
|
|
86
|
+
/**
|
|
87
|
+
* Iterates over each element of the object invoking the provided callback function for each property.
|
|
88
|
+
*
|
|
89
|
+
* @template T - The type of object.
|
|
90
|
+
* @param {T} object - The object to iterate over.
|
|
91
|
+
* @param {(value: T[keyof T], key: keyof T, object: T) => unknown} [callback] - The function invoked for each property.
|
|
92
|
+
* The callback function receives three arguments:
|
|
93
|
+
* - 'value': The current property being processed in the object.
|
|
94
|
+
* - 'key': The key of the current property being processed in the object.
|
|
95
|
+
* - 'object': The object 'forEach' was called upon.
|
|
96
|
+
* @returns {T} Returns the original object.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* forEach({'a': 1, 'b': 2 }, (value, key, object) => console.log(value, key));
|
|
100
|
+
* // Output:
|
|
101
|
+
* // 1 'a'
|
|
102
|
+
* // 2 'b'
|
|
103
|
+
*/
|
|
104
|
+
declare function forEach<T extends object | null | undefined>(object: T, callback?: (value: T[keyof T], key: keyof T, object: T) => unknown): T;
|
|
105
|
+
|
|
106
|
+
export { forEach };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { identity } from '../../function/identity.mjs';
|
|
2
|
+
import { range } from '../../math/range.mjs';
|
|
3
|
+
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
4
|
+
|
|
5
|
+
function forEach(collection, callback = identity) {
|
|
6
|
+
if (!collection) {
|
|
7
|
+
return collection;
|
|
8
|
+
}
|
|
9
|
+
const keys = isArrayLike(collection) || Array.isArray(collection) ? range(0, collection.length) : Object.keys(collection);
|
|
10
|
+
for (let i = 0; i < keys.length; i++) {
|
|
11
|
+
const key = keys[i];
|
|
12
|
+
const value = collection[key];
|
|
13
|
+
const result = callback(value, key, collection);
|
|
14
|
+
if (result === false) {
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return collection;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { forEach };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { head as head$1 } from '../../array/head.mjs';
|
|
2
|
+
import { toArray } from '../_internal/toArray.mjs';
|
|
2
3
|
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
3
4
|
|
|
4
5
|
function head(arr) {
|
|
5
6
|
if (!isArrayLike(arr)) {
|
|
6
7
|
return undefined;
|
|
7
8
|
}
|
|
8
|
-
return head$1(
|
|
9
|
+
return head$1(toArray(arr));
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
export { head };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { last as last$1 } from '../../array/last.mjs';
|
|
2
|
+
import { toArray } from '../_internal/toArray.mjs';
|
|
2
3
|
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
3
4
|
|
|
4
5
|
function last(array) {
|
|
5
6
|
if (!isArrayLike(array)) {
|
|
6
7
|
return undefined;
|
|
7
8
|
}
|
|
8
|
-
return last$1(
|
|
9
|
+
return last$1(toArray(array));
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
export { last };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { sample as sample$1 } from '../../array/sample.mjs';
|
|
2
|
+
import { toArray } from '../_internal/toArray.mjs';
|
|
2
3
|
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
3
4
|
|
|
4
5
|
function sample(collection) {
|
|
@@ -6,7 +7,7 @@ function sample(collection) {
|
|
|
6
7
|
return undefined;
|
|
7
8
|
}
|
|
8
9
|
if (isArrayLike(collection)) {
|
|
9
|
-
return sample$1(
|
|
10
|
+
return sample$1(toArray(collection));
|
|
10
11
|
}
|
|
11
12
|
return sample$1(Object.values(collection));
|
|
12
13
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { tail as tail$1 } from '../../array/tail.mjs';
|
|
2
|
+
import { toArray } from '../_internal/toArray.mjs';
|
|
2
3
|
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
3
4
|
|
|
4
5
|
function tail(arr) {
|
|
5
6
|
if (!isArrayLike(arr)) {
|
|
6
7
|
return [];
|
|
7
8
|
}
|
|
8
|
-
return tail$1(
|
|
9
|
+
return tail$1(toArray(arr));
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
export { tail };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { take as take$1 } from '../../array/take.mjs';
|
|
2
|
+
import { toArray } from '../_internal/toArray.mjs';
|
|
2
3
|
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
3
4
|
import { toInteger } from '../util/toInteger.mjs';
|
|
4
5
|
|
|
@@ -7,7 +8,7 @@ function take(arr, count = 1, guard) {
|
|
|
7
8
|
if (count < 1 || !isArrayLike(arr)) {
|
|
8
9
|
return [];
|
|
9
10
|
}
|
|
10
|
-
return take$1(
|
|
11
|
+
return take$1(toArray(arr), count);
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export { take };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { takeRight as takeRight$1 } from '../../array/takeRight.mjs';
|
|
2
|
+
import { toArray } from '../_internal/toArray.mjs';
|
|
2
3
|
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
3
4
|
import { toInteger } from '../util/toInteger.mjs';
|
|
4
5
|
|
|
@@ -7,7 +8,7 @@ function takeRight(arr, count = 1, guard) {
|
|
|
7
8
|
if (count <= 0 || !isArrayLike(arr)) {
|
|
8
9
|
return [];
|
|
9
10
|
}
|
|
10
|
-
return takeRight$1(
|
|
11
|
+
return takeRight$1(toArray(arr), count);
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export { takeRight };
|