es-toolkit 1.43.0 → 1.44.0-dev.1722
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 +21 -0
- package/dist/{compat/util/eq.d.mts → _internal/isEqualsSameValueZero.d.mts} +2 -2
- package/dist/{compat/util/eq.d.ts → _internal/isEqualsSameValueZero.d.ts} +2 -2
- package/dist/{compat/util/eq.js → _internal/isEqualsSameValueZero.js} +2 -2
- package/dist/_internal/isEqualsSameValueZero.mjs +5 -0
- package/dist/array/countBy.d.mts +8 -2
- package/dist/array/countBy.d.ts +8 -2
- package/dist/array/countBy.js +1 -1
- package/dist/array/countBy.mjs +1 -1
- package/dist/array/flatMap.d.mts +2 -2
- package/dist/array/flatMap.d.ts +2 -2
- package/dist/array/flatMap.js +1 -1
- package/dist/array/flatMap.mjs +1 -1
- package/dist/array/flatMapDeep.d.mts +2 -2
- package/dist/array/flatMapDeep.d.ts +2 -2
- package/dist/array/flatMapDeep.js +1 -1
- package/dist/array/flatMapDeep.mjs +1 -1
- package/dist/array/groupBy.d.mts +8 -2
- package/dist/array/groupBy.d.ts +8 -2
- package/dist/array/groupBy.js +1 -1
- package/dist/array/groupBy.mjs +1 -1
- package/dist/array/intersection.js +1 -3
- package/dist/array/intersection.mjs +1 -3
- package/dist/array/keyBy.d.mts +8 -2
- package/dist/array/keyBy.d.ts +8 -2
- package/dist/array/keyBy.js +1 -1
- package/dist/array/keyBy.mjs +1 -1
- package/dist/array/maxBy.d.mts +3 -3
- package/dist/array/maxBy.d.ts +3 -3
- package/dist/array/maxBy.js +2 -2
- package/dist/array/maxBy.mjs +2 -2
- package/dist/array/minBy.d.mts +3 -3
- package/dist/array/minBy.d.ts +3 -3
- package/dist/array/minBy.js +2 -2
- package/dist/array/minBy.mjs +2 -2
- package/dist/array/partition.d.mts +6 -6
- package/dist/array/partition.d.ts +6 -6
- package/dist/array/partition.js +1 -1
- package/dist/array/partition.mjs +1 -1
- package/dist/array/takeRightWhile.d.mts +7 -2
- package/dist/array/takeRightWhile.d.ts +7 -2
- package/dist/array/takeRightWhile.js +1 -1
- package/dist/array/takeRightWhile.mjs +1 -1
- package/dist/array/takeWhile.d.mts +7 -2
- package/dist/array/takeWhile.d.ts +7 -2
- package/dist/array/takeWhile.js +1 -1
- package/dist/array/takeWhile.mjs +1 -1
- package/dist/array/uniqBy.d.mts +1 -1
- package/dist/array/uniqBy.d.ts +1 -1
- package/dist/array/uniqBy.js +1 -1
- package/dist/array/uniqBy.mjs +1 -1
- package/dist/array/zipWith.d.mts +8 -8
- package/dist/array/zipWith.d.ts +8 -8
- package/dist/array/zipWith.js +1 -1
- package/dist/array/zipWith.mjs +1 -1
- package/dist/browser.global.js +1 -1
- package/dist/compat/_internal/assignValue.js +2 -2
- package/dist/compat/_internal/assignValue.mjs +2 -2
- package/dist/compat/_internal/isIterateeCall.js +2 -2
- package/dist/compat/_internal/isIterateeCall.mjs +2 -2
- package/dist/compat/array/includes.js +2 -2
- package/dist/compat/array/includes.mjs +2 -2
- package/dist/compat/array/intersectionWith.js +2 -2
- package/dist/compat/array/intersectionWith.mjs +2 -2
- package/dist/compat/array/pullAllWith.js +2 -2
- package/dist/compat/array/pullAllWith.mjs +2 -2
- package/dist/compat/array/sortedIndexOf.js +2 -2
- package/dist/compat/array/sortedIndexOf.mjs +2 -2
- package/dist/compat/array/sortedLastIndexOf.js +2 -2
- package/dist/compat/array/sortedLastIndexOf.mjs +2 -2
- package/dist/compat/array/unionBy.js +2 -1
- package/dist/compat/array/unionBy.mjs +2 -1
- package/dist/compat/array/uniqBy.js +2 -1
- package/dist/compat/array/uniqBy.mjs +2 -1
- package/dist/compat/compat.d.mts +1 -1
- package/dist/compat/compat.d.ts +1 -1
- package/dist/compat/compat.js +2 -2
- package/dist/compat/compat.mjs +1 -1
- package/dist/compat/index.d.mts +1 -1
- package/dist/compat/index.d.ts +1 -1
- package/dist/compat/index.js +2 -2
- package/dist/compat/index.mjs +1 -1
- package/dist/compat/math/clamp.js +12 -6
- package/dist/compat/math/clamp.mjs +12 -6
- package/dist/compat/object/assign.js +2 -2
- package/dist/compat/object/assign.mjs +2 -2
- package/dist/compat/object/assignIn.js +2 -2
- package/dist/compat/object/assignIn.mjs +2 -2
- package/dist/compat/object/assignInWith.js +2 -2
- package/dist/compat/object/assignInWith.mjs +2 -2
- package/dist/compat/object/assignWith.js +2 -2
- package/dist/compat/object/assignWith.mjs +2 -2
- package/dist/compat/object/cloneDeepWith.js +7 -0
- package/dist/compat/object/cloneDeepWith.mjs +8 -1
- package/dist/compat/object/defaults.js +2 -2
- package/dist/compat/object/defaults.mjs +2 -2
- package/dist/compat/predicate/isMatchWith.js +3 -3
- package/dist/compat/predicate/isMatchWith.mjs +3 -3
- package/dist/function/retry.d.mts +13 -0
- package/dist/function/retry.d.ts +13 -0
- package/dist/function/retry.js +7 -0
- package/dist/function/retry.mjs +7 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -0
- package/dist/index.mjs +2 -0
- package/dist/map/every.d.mts +28 -0
- package/dist/map/every.d.ts +28 -0
- package/dist/map/every.js +14 -0
- package/dist/map/every.mjs +10 -0
- package/dist/map/filter.d.mts +29 -0
- package/dist/map/filter.d.ts +29 -0
- package/dist/map/filter.js +15 -0
- package/dist/map/filter.mjs +11 -0
- package/dist/map/findKey.d.mts +25 -0
- package/dist/map/findKey.d.ts +25 -0
- package/dist/map/findKey.js +16 -0
- package/dist/map/findKey.mjs +12 -0
- package/dist/map/findValue.d.mts +25 -0
- package/dist/map/findValue.d.ts +25 -0
- package/dist/map/findValue.js +16 -0
- package/dist/map/findValue.mjs +12 -0
- package/dist/map/hasValue.d.mts +28 -0
- package/dist/map/hasValue.d.ts +28 -0
- package/dist/map/hasValue.js +16 -0
- package/dist/map/hasValue.mjs +12 -0
- package/dist/map/index.d.mts +9 -0
- package/dist/map/index.d.ts +9 -0
- package/dist/map/index.js +25 -0
- package/dist/map/index.mjs +9 -0
- package/dist/map/mapKeys.d.mts +30 -0
- package/dist/map/mapKeys.d.ts +30 -0
- package/dist/map/mapKeys.js +14 -0
- package/dist/map/mapKeys.mjs +10 -0
- package/dist/map/mapValues.d.mts +30 -0
- package/dist/map/mapValues.d.ts +30 -0
- package/dist/map/mapValues.js +14 -0
- package/dist/map/mapValues.mjs +10 -0
- package/dist/map/reduce.d.mts +35 -0
- package/dist/map/reduce.d.ts +35 -0
- package/dist/map/reduce.js +21 -0
- package/dist/map/reduce.mjs +17 -0
- package/dist/map/some.d.mts +28 -0
- package/dist/map/some.d.ts +28 -0
- package/dist/map/some.js +14 -0
- package/dist/map/some.mjs +10 -0
- package/dist/object/clone.js +11 -3
- package/dist/object/clone.mjs +11 -3
- package/dist/object/cloneDeep.d.mts +6 -6
- package/dist/object/cloneDeep.d.ts +6 -6
- package/dist/object/flattenObject.js +1 -1
- package/dist/object/flattenObject.mjs +1 -1
- package/dist/predicate/index.d.mts +2 -0
- package/dist/predicate/index.d.ts +2 -0
- package/dist/predicate/index.js +4 -0
- package/dist/predicate/index.mjs +2 -0
- package/dist/predicate/isEmptyObject.d.mts +15 -0
- package/dist/predicate/isEmptyObject.d.ts +15 -0
- package/dist/predicate/isEmptyObject.js +11 -0
- package/dist/predicate/isEmptyObject.mjs +7 -0
- package/dist/predicate/isEqualWith.js +2 -2
- package/dist/predicate/isEqualWith.mjs +2 -2
- package/dist/predicate/isNumber.d.mts +25 -0
- package/dist/predicate/isNumber.d.ts +25 -0
- package/dist/predicate/isNumber.js +9 -0
- package/dist/predicate/isNumber.mjs +5 -0
- package/dist/set/countBy.d.mts +26 -0
- package/dist/set/countBy.d.ts +26 -0
- package/dist/set/countBy.js +14 -0
- package/dist/set/countBy.mjs +10 -0
- package/dist/set/every.d.mts +23 -0
- package/dist/set/every.d.ts +23 -0
- package/dist/set/every.js +14 -0
- package/dist/set/every.mjs +10 -0
- package/dist/set/filter.d.mts +20 -0
- package/dist/set/filter.d.ts +20 -0
- package/dist/set/filter.js +15 -0
- package/dist/set/filter.mjs +11 -0
- package/dist/set/find.d.mts +24 -0
- package/dist/set/find.d.ts +24 -0
- package/dist/set/find.js +14 -0
- package/dist/set/find.mjs +10 -0
- package/dist/set/index.d.mts +8 -0
- package/dist/set/index.d.ts +8 -0
- package/dist/set/index.js +23 -0
- package/dist/set/index.mjs +8 -0
- package/dist/set/keyBy.d.mts +30 -0
- package/dist/set/keyBy.d.ts +30 -0
- package/dist/set/keyBy.js +14 -0
- package/dist/set/keyBy.mjs +10 -0
- package/dist/set/map.d.mts +21 -0
- package/dist/set/map.d.ts +21 -0
- package/dist/set/map.js +14 -0
- package/dist/set/map.mjs +10 -0
- package/dist/set/reduce.d.mts +28 -0
- package/dist/set/reduce.d.ts +28 -0
- package/dist/set/reduce.js +21 -0
- package/dist/set/reduce.mjs +17 -0
- package/dist/set/some.d.mts +23 -0
- package/dist/set/some.d.ts +23 -0
- package/dist/set/some.js +14 -0
- package/dist/set/some.mjs +10 -0
- package/map.d.ts +1 -0
- package/map.js +1 -0
- package/package.json +4 -1
- package/set.d.ts +1 -0
- package/set.js +1 -0
- package/dist/compat/util/eq.mjs +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# es-toolkit Changelog
|
|
2
2
|
|
|
3
|
+
## Version v1.44.0
|
|
4
|
+
|
|
5
|
+
Released on January 16th, 2026.
|
|
6
|
+
|
|
7
|
+
- Added `shouldRetry` option to `retry` function. ([#1585])
|
|
8
|
+
- Added `isEmptyObject` predicate function. ([#1584])
|
|
9
|
+
- Added `isNumber` predicate function.
|
|
10
|
+
- Enhanced error cloning to support `AggregateError`. ([#1563])
|
|
11
|
+
- Implemented collection methods for Maps and Sets.
|
|
12
|
+
- Added bundle size analysis and visualization components to docs. ([#1564])
|
|
13
|
+
- Fixed `flattenObject` to retain empty objects and arrays.
|
|
14
|
+
- Enhanced type safety for `clone` function.
|
|
15
|
+
- Fixed `clone` error when cloning object with null prototype. ([#1570])
|
|
16
|
+
- Fixed array function callbacks to include index and array parameters. ([#1561])
|
|
17
|
+
- Fixed `compat/cloneDeep` and `cloneDeepWith` to clone null-prototype objects as regular objects. ([#1562])
|
|
18
|
+
- Fixed `compat/clamp` to ensure consistency with lodash. ([#1555])
|
|
19
|
+
- Simplified `intersection` filter callback for consistency. ([#1582])
|
|
20
|
+
- Fixed incorrect function names and output in `cloneDeep` JSDoc examples. ([#1583])
|
|
21
|
+
|
|
22
|
+
We sincerely thank @raon0211, @dayongkr, @eunwoo-levi, @matt-oakes, @T3sT3ro, and @D-Sketon for their contributions. We appreciate your great efforts!
|
|
23
|
+
|
|
3
24
|
## Version v1.43.0
|
|
4
25
|
|
|
5
26
|
Released on December 12th, 2025.
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
function
|
|
5
|
+
function isEqualsSameValueZero(value, other) {
|
|
6
6
|
return value === other || (Number.isNaN(value) && Number.isNaN(other));
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
exports.
|
|
9
|
+
exports.isEqualsSameValueZero = isEqualsSameValueZero;
|
package/dist/array/countBy.d.mts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* @template T - The type of the items in the input array.
|
|
12
12
|
* @template K - The type of keys.
|
|
13
13
|
* @param {T[]} arr - The input array to count occurrences.
|
|
14
|
-
* @param {(item: T) => K} mapper - The transformation function that maps each item to a key.
|
|
14
|
+
* @param {(item: T, index: number, array: readonly T[]) => K} mapper - The transformation function that maps each item, its index, and the array to a key.
|
|
15
15
|
* @returns {Record<K, number>} An object containing the transformed items as keys and the
|
|
16
16
|
* counts as values.
|
|
17
17
|
*
|
|
@@ -24,7 +24,13 @@
|
|
|
24
24
|
* const array = [1, 2, 3, 4, 5];
|
|
25
25
|
* const result = countBy(array, item => item % 2 === 0 ? 'even' : 'odd');
|
|
26
26
|
* // result will be { odd: 3, even: 2 }
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // Using index parameter
|
|
30
|
+
* const array = ['a', 'b', 'c', 'd'];
|
|
31
|
+
* const result = countBy(array, (item, index) => index < 2 ? 'first' : 'rest');
|
|
32
|
+
* // result will be { first: 2, rest: 2 }
|
|
27
33
|
*/
|
|
28
|
-
declare function countBy<T, K extends PropertyKey>(arr: readonly T[], mapper: (item: T) => K): Record<K, number>;
|
|
34
|
+
declare function countBy<T, K extends PropertyKey>(arr: readonly T[], mapper: (item: T, index: number, array: readonly T[]) => K): Record<K, number>;
|
|
29
35
|
|
|
30
36
|
export { countBy };
|
package/dist/array/countBy.d.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* @template T - The type of the items in the input array.
|
|
12
12
|
* @template K - The type of keys.
|
|
13
13
|
* @param {T[]} arr - The input array to count occurrences.
|
|
14
|
-
* @param {(item: T) => K} mapper - The transformation function that maps each item to a key.
|
|
14
|
+
* @param {(item: T, index: number, array: readonly T[]) => K} mapper - The transformation function that maps each item, its index, and the array to a key.
|
|
15
15
|
* @returns {Record<K, number>} An object containing the transformed items as keys and the
|
|
16
16
|
* counts as values.
|
|
17
17
|
*
|
|
@@ -24,7 +24,13 @@
|
|
|
24
24
|
* const array = [1, 2, 3, 4, 5];
|
|
25
25
|
* const result = countBy(array, item => item % 2 === 0 ? 'even' : 'odd');
|
|
26
26
|
* // result will be { odd: 3, even: 2 }
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // Using index parameter
|
|
30
|
+
* const array = ['a', 'b', 'c', 'd'];
|
|
31
|
+
* const result = countBy(array, (item, index) => index < 2 ? 'first' : 'rest');
|
|
32
|
+
* // result will be { first: 2, rest: 2 }
|
|
27
33
|
*/
|
|
28
|
-
declare function countBy<T, K extends PropertyKey>(arr: readonly T[], mapper: (item: T) => K): Record<K, number>;
|
|
34
|
+
declare function countBy<T, K extends PropertyKey>(arr: readonly T[], mapper: (item: T, index: number, array: readonly T[]) => K): Record<K, number>;
|
|
29
35
|
|
|
30
36
|
export { countBy };
|
package/dist/array/countBy.js
CHANGED
package/dist/array/countBy.mjs
CHANGED
package/dist/array/flatMap.d.mts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @template U - The type of elements within the returned array from the iteratee function.
|
|
6
6
|
* @template D - The depth to which the array should be flattened.
|
|
7
7
|
* @param {T[]} arr - The array to flatten.
|
|
8
|
-
* @param {(item: T) => U} iteratee - The function that produces the new array elements.
|
|
8
|
+
* @param {(item: T, index: number, array: readonly T[]) => U} iteratee - The function that produces the new array elements. It receives the element, its index, and the array.
|
|
9
9
|
* @param {D} depth - The depth level specifying how deep a nested array structure should be flattened. Defaults to 1.
|
|
10
10
|
* @returns {Array<FlatArray<U[], D>>} The new array with the mapped and flattened elements.
|
|
11
11
|
*
|
|
@@ -18,6 +18,6 @@
|
|
|
18
18
|
* flatMap(arr, (item: number) => [[item, item]], 2);
|
|
19
19
|
* // [1, 1, 2, 2, 3, 3]
|
|
20
20
|
*/
|
|
21
|
-
declare function flatMap<T, U, D extends number = 1>(arr: readonly T[], iteratee: (item: T) => U, depth?: D): Array<FlatArray<U[], D>>;
|
|
21
|
+
declare function flatMap<T, U, D extends number = 1>(arr: readonly T[], iteratee: (item: T, index: number, array: readonly T[]) => U, depth?: D): Array<FlatArray<U[], D>>;
|
|
22
22
|
|
|
23
23
|
export { flatMap };
|
package/dist/array/flatMap.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @template U - The type of elements within the returned array from the iteratee function.
|
|
6
6
|
* @template D - The depth to which the array should be flattened.
|
|
7
7
|
* @param {T[]} arr - The array to flatten.
|
|
8
|
-
* @param {(item: T) => U} iteratee - The function that produces the new array elements.
|
|
8
|
+
* @param {(item: T, index: number, array: readonly T[]) => U} iteratee - The function that produces the new array elements. It receives the element, its index, and the array.
|
|
9
9
|
* @param {D} depth - The depth level specifying how deep a nested array structure should be flattened. Defaults to 1.
|
|
10
10
|
* @returns {Array<FlatArray<U[], D>>} The new array with the mapped and flattened elements.
|
|
11
11
|
*
|
|
@@ -18,6 +18,6 @@
|
|
|
18
18
|
* flatMap(arr, (item: number) => [[item, item]], 2);
|
|
19
19
|
* // [1, 1, 2, 2, 3, 3]
|
|
20
20
|
*/
|
|
21
|
-
declare function flatMap<T, U, D extends number = 1>(arr: readonly T[], iteratee: (item: T) => U, depth?: D): Array<FlatArray<U[], D>>;
|
|
21
|
+
declare function flatMap<T, U, D extends number = 1>(arr: readonly T[], iteratee: (item: T, index: number, array: readonly T[]) => U, depth?: D): Array<FlatArray<U[], D>>;
|
|
22
22
|
|
|
23
23
|
export { flatMap };
|
package/dist/array/flatMap.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
5
5
|
const flatten = require('./flatten.js');
|
|
6
6
|
|
|
7
7
|
function flatMap(arr, iteratee, depth = 1) {
|
|
8
|
-
return flatten.flatten(arr.map(item => iteratee(item)), depth);
|
|
8
|
+
return flatten.flatten(arr.map((item, index) => iteratee(item, index, arr)), depth);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
exports.flatMap = flatMap;
|
package/dist/array/flatMap.mjs
CHANGED
|
@@ -6,13 +6,13 @@ import { ExtractNestedArrayType } from './flattenDeep.mjs';
|
|
|
6
6
|
* @template T - The type of elements within the array.
|
|
7
7
|
* @template U - The type of elements within the returned array from the iteratee function.
|
|
8
8
|
* @param {T[]} arr - The array to flatten.
|
|
9
|
-
* @param {(item: T) => U} iteratee - The function that produces the new array elements.
|
|
9
|
+
* @param {(item: T, index: number, array: readonly T[]) => U} iteratee - The function that produces the new array elements. It receives the element, its index, and the array.
|
|
10
10
|
* @returns {Array<ExtractNestedArrayType<U>>} A new array that has been flattened.
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* const result = flatMapDeep([1, 2, 3], n => [[n, n]]);
|
|
14
14
|
* // [1, 1, 2, 2, 3, 3]
|
|
15
15
|
*/
|
|
16
|
-
declare function flatMapDeep<T, U>(arr: readonly T[], iteratee: (item: T) => U): Array<ExtractNestedArrayType<U>>;
|
|
16
|
+
declare function flatMapDeep<T, U>(arr: readonly T[], iteratee: (item: T, index: number, array: readonly T[]) => U): Array<ExtractNestedArrayType<U>>;
|
|
17
17
|
|
|
18
18
|
export { flatMapDeep };
|
|
@@ -6,13 +6,13 @@ import { ExtractNestedArrayType } from './flattenDeep.js';
|
|
|
6
6
|
* @template T - The type of elements within the array.
|
|
7
7
|
* @template U - The type of elements within the returned array from the iteratee function.
|
|
8
8
|
* @param {T[]} arr - The array to flatten.
|
|
9
|
-
* @param {(item: T) => U} iteratee - The function that produces the new array elements.
|
|
9
|
+
* @param {(item: T, index: number, array: readonly T[]) => U} iteratee - The function that produces the new array elements. It receives the element, its index, and the array.
|
|
10
10
|
* @returns {Array<ExtractNestedArrayType<U>>} A new array that has been flattened.
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* const result = flatMapDeep([1, 2, 3], n => [[n, n]]);
|
|
14
14
|
* // [1, 1, 2, 2, 3, 3]
|
|
15
15
|
*/
|
|
16
|
-
declare function flatMapDeep<T, U>(arr: readonly T[], iteratee: (item: T) => U): Array<ExtractNestedArrayType<U>>;
|
|
16
|
+
declare function flatMapDeep<T, U>(arr: readonly T[], iteratee: (item: T, index: number, array: readonly T[]) => U): Array<ExtractNestedArrayType<U>>;
|
|
17
17
|
|
|
18
18
|
export { flatMapDeep };
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
5
5
|
const flattenDeep = require('./flattenDeep.js');
|
|
6
6
|
|
|
7
7
|
function flatMapDeep(arr, iteratee) {
|
|
8
|
-
return flattenDeep.flattenDeep(arr.map((item) => iteratee(item)));
|
|
8
|
+
return flattenDeep.flattenDeep(arr.map((item, index) => iteratee(item, index, arr)));
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
exports.flatMapDeep = flatMapDeep;
|
package/dist/array/groupBy.d.mts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* @template T - The type of elements in the array.
|
|
9
9
|
* @template K - The type of keys.
|
|
10
10
|
* @param {T[]} arr - The array to group.
|
|
11
|
-
* @param {(item: T) => K} getKeyFromItem - A function that generates a key from an element.
|
|
11
|
+
* @param {(item: T, index: number, array: readonly T[]) => K} getKeyFromItem - A function that generates a key from an element, its index, and the array.
|
|
12
12
|
* @returns {Record<K, T[]>} An object where each key is associated with an array of elements that
|
|
13
13
|
* share that key.
|
|
14
14
|
*
|
|
@@ -29,7 +29,13 @@
|
|
|
29
29
|
* // { category: 'vegetable', name: 'carrot' }
|
|
30
30
|
* // ]
|
|
31
31
|
* // }
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* // Using index parameter
|
|
35
|
+
* const items = ['a', 'b', 'c', 'd'];
|
|
36
|
+
* const result = groupBy(items, (item, index) => index % 2 === 0 ? 'even' : 'odd');
|
|
37
|
+
* // result will be: { even: ['a', 'c'], odd: ['b', 'd'] }
|
|
32
38
|
*/
|
|
33
|
-
declare function groupBy<T, K extends PropertyKey>(arr: readonly T[], getKeyFromItem: (item: T) => K): Record<K, T[]>;
|
|
39
|
+
declare function groupBy<T, K extends PropertyKey>(arr: readonly T[], getKeyFromItem: (item: T, index: number, array: readonly T[]) => K): Record<K, T[]>;
|
|
34
40
|
|
|
35
41
|
export { groupBy };
|
package/dist/array/groupBy.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* @template T - The type of elements in the array.
|
|
9
9
|
* @template K - The type of keys.
|
|
10
10
|
* @param {T[]} arr - The array to group.
|
|
11
|
-
* @param {(item: T) => K} getKeyFromItem - A function that generates a key from an element.
|
|
11
|
+
* @param {(item: T, index: number, array: readonly T[]) => K} getKeyFromItem - A function that generates a key from an element, its index, and the array.
|
|
12
12
|
* @returns {Record<K, T[]>} An object where each key is associated with an array of elements that
|
|
13
13
|
* share that key.
|
|
14
14
|
*
|
|
@@ -29,7 +29,13 @@
|
|
|
29
29
|
* // { category: 'vegetable', name: 'carrot' }
|
|
30
30
|
* // ]
|
|
31
31
|
* // }
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* // Using index parameter
|
|
35
|
+
* const items = ['a', 'b', 'c', 'd'];
|
|
36
|
+
* const result = groupBy(items, (item, index) => index % 2 === 0 ? 'even' : 'odd');
|
|
37
|
+
* // result will be: { even: ['a', 'c'], odd: ['b', 'd'] }
|
|
32
38
|
*/
|
|
33
|
-
declare function groupBy<T, K extends PropertyKey>(arr: readonly T[], getKeyFromItem: (item: T) => K): Record<K, T[]>;
|
|
39
|
+
declare function groupBy<T, K extends PropertyKey>(arr: readonly T[], getKeyFromItem: (item: T, index: number, array: readonly T[]) => K): Record<K, T[]>;
|
|
34
40
|
|
|
35
41
|
export { groupBy };
|
package/dist/array/groupBy.js
CHANGED
|
@@ -6,7 +6,7 @@ function groupBy(arr, getKeyFromItem) {
|
|
|
6
6
|
const result = {};
|
|
7
7
|
for (let i = 0; i < arr.length; i++) {
|
|
8
8
|
const item = arr[i];
|
|
9
|
-
const key = getKeyFromItem(item);
|
|
9
|
+
const key = getKeyFromItem(item, i, arr);
|
|
10
10
|
if (!Object.hasOwn(result, key)) {
|
|
11
11
|
result[key] = [];
|
|
12
12
|
}
|
package/dist/array/groupBy.mjs
CHANGED
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4
4
|
|
|
5
5
|
function intersection(firstArr, secondArr) {
|
|
6
6
|
const secondSet = new Set(secondArr);
|
|
7
|
-
return firstArr.filter(item =>
|
|
8
|
-
return secondSet.has(item);
|
|
9
|
-
});
|
|
7
|
+
return firstArr.filter(item => secondSet.has(item));
|
|
10
8
|
}
|
|
11
9
|
|
|
12
10
|
exports.intersection = intersection;
|
package/dist/array/keyBy.d.mts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* @template T - The type of elements in the array.
|
|
10
10
|
* @template K - The type of keys.
|
|
11
11
|
* @param {T[]} arr - The array of elements to be mapped.
|
|
12
|
-
* @param {(item: T) => K} getKeyFromItem - A function that generates a key from an element.
|
|
12
|
+
* @param {(item: T, index: number, array: readonly T[]) => K} getKeyFromItem - A function that generates a key from an element, its index, and the array.
|
|
13
13
|
* @returns {Record<K, T>} An object where keys are mapped to each element of an array.
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
@@ -24,7 +24,13 @@
|
|
|
24
24
|
* // fruit: { category: 'fruit', name: 'banana' },
|
|
25
25
|
* // vegetable: { category: 'vegetable', name: 'carrot' }
|
|
26
26
|
* // }
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // Using index parameter
|
|
30
|
+
* const items = ['a', 'b', 'c'];
|
|
31
|
+
* const result = keyBy(items, (item, index) => index);
|
|
32
|
+
* // result will be: { 0: 'a', 1: 'b', 2: 'c' }
|
|
27
33
|
*/
|
|
28
|
-
declare function keyBy<T, K extends PropertyKey>(arr: readonly T[], getKeyFromItem: (item: T) => K): Record<K, T>;
|
|
34
|
+
declare function keyBy<T, K extends PropertyKey>(arr: readonly T[], getKeyFromItem: (item: T, index: number, array: readonly T[]) => K): Record<K, T>;
|
|
29
35
|
|
|
30
36
|
export { keyBy };
|
package/dist/array/keyBy.d.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* @template T - The type of elements in the array.
|
|
10
10
|
* @template K - The type of keys.
|
|
11
11
|
* @param {T[]} arr - The array of elements to be mapped.
|
|
12
|
-
* @param {(item: T) => K} getKeyFromItem - A function that generates a key from an element.
|
|
12
|
+
* @param {(item: T, index: number, array: readonly T[]) => K} getKeyFromItem - A function that generates a key from an element, its index, and the array.
|
|
13
13
|
* @returns {Record<K, T>} An object where keys are mapped to each element of an array.
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
@@ -24,7 +24,13 @@
|
|
|
24
24
|
* // fruit: { category: 'fruit', name: 'banana' },
|
|
25
25
|
* // vegetable: { category: 'vegetable', name: 'carrot' }
|
|
26
26
|
* // }
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // Using index parameter
|
|
30
|
+
* const items = ['a', 'b', 'c'];
|
|
31
|
+
* const result = keyBy(items, (item, index) => index);
|
|
32
|
+
* // result will be: { 0: 'a', 1: 'b', 2: 'c' }
|
|
27
33
|
*/
|
|
28
|
-
declare function keyBy<T, K extends PropertyKey>(arr: readonly T[], getKeyFromItem: (item: T) => K): Record<K, T>;
|
|
34
|
+
declare function keyBy<T, K extends PropertyKey>(arr: readonly T[], getKeyFromItem: (item: T, index: number, array: readonly T[]) => K): Record<K, T>;
|
|
29
35
|
|
|
30
36
|
export { keyBy };
|
package/dist/array/keyBy.js
CHANGED
package/dist/array/keyBy.mjs
CHANGED
package/dist/array/maxBy.d.mts
CHANGED
|
@@ -18,14 +18,14 @@
|
|
|
18
18
|
* x => x.age
|
|
19
19
|
* ); // Returns: { name: 'john', age: 30 }
|
|
20
20
|
*/
|
|
21
|
-
declare function maxBy<T>(items: readonly [T, ...T[]], getValue: (element: T) => number): T;
|
|
21
|
+
declare function maxBy<T>(items: readonly [T, ...T[]], getValue: (element: T, index: number, array: readonly T[]) => number): T;
|
|
22
22
|
/**
|
|
23
23
|
* Finds the element in an array that has the maximum value when applying
|
|
24
24
|
* the `getValue` function to each element.
|
|
25
25
|
*
|
|
26
26
|
* @template T - The type of elements in the array.
|
|
27
27
|
* @param {T[]} items The array of elements to search.
|
|
28
|
-
* @param {(element: T) => number} getValue A function that selects a numeric value from each element.
|
|
28
|
+
* @param {(element: T, index: number, array: readonly T[]) => number} getValue A function that selects a numeric value from each element.
|
|
29
29
|
* @returns {T | undefined} The element with the maximum value as determined by the `getValue` function,
|
|
30
30
|
* or `undefined` if the array is empty.
|
|
31
31
|
* @example
|
|
@@ -40,6 +40,6 @@ declare function maxBy<T>(items: readonly [T, ...T[]], getValue: (element: T) =>
|
|
|
40
40
|
* x => x.age
|
|
41
41
|
* ); // Returns: { name: 'john', age: 30 }
|
|
42
42
|
*/
|
|
43
|
-
declare function maxBy<T>(items: readonly T[], getValue: (element: T) => number): T | undefined;
|
|
43
|
+
declare function maxBy<T>(items: readonly T[], getValue: (element: T, index: number, array: readonly T[]) => number): T | undefined;
|
|
44
44
|
|
|
45
45
|
export { maxBy };
|
package/dist/array/maxBy.d.ts
CHANGED
|
@@ -18,14 +18,14 @@
|
|
|
18
18
|
* x => x.age
|
|
19
19
|
* ); // Returns: { name: 'john', age: 30 }
|
|
20
20
|
*/
|
|
21
|
-
declare function maxBy<T>(items: readonly [T, ...T[]], getValue: (element: T) => number): T;
|
|
21
|
+
declare function maxBy<T>(items: readonly [T, ...T[]], getValue: (element: T, index: number, array: readonly T[]) => number): T;
|
|
22
22
|
/**
|
|
23
23
|
* Finds the element in an array that has the maximum value when applying
|
|
24
24
|
* the `getValue` function to each element.
|
|
25
25
|
*
|
|
26
26
|
* @template T - The type of elements in the array.
|
|
27
27
|
* @param {T[]} items The array of elements to search.
|
|
28
|
-
* @param {(element: T) => number} getValue A function that selects a numeric value from each element.
|
|
28
|
+
* @param {(element: T, index: number, array: readonly T[]) => number} getValue A function that selects a numeric value from each element.
|
|
29
29
|
* @returns {T | undefined} The element with the maximum value as determined by the `getValue` function,
|
|
30
30
|
* or `undefined` if the array is empty.
|
|
31
31
|
* @example
|
|
@@ -40,6 +40,6 @@ declare function maxBy<T>(items: readonly [T, ...T[]], getValue: (element: T) =>
|
|
|
40
40
|
* x => x.age
|
|
41
41
|
* ); // Returns: { name: 'john', age: 30 }
|
|
42
42
|
*/
|
|
43
|
-
declare function maxBy<T>(items: readonly T[], getValue: (element: T) => number): T | undefined;
|
|
43
|
+
declare function maxBy<T>(items: readonly T[], getValue: (element: T, index: number, array: readonly T[]) => number): T | undefined;
|
|
44
44
|
|
|
45
45
|
export { maxBy };
|
package/dist/array/maxBy.js
CHANGED
|
@@ -7,10 +7,10 @@ function maxBy(items, getValue) {
|
|
|
7
7
|
return undefined;
|
|
8
8
|
}
|
|
9
9
|
let maxElement = items[0];
|
|
10
|
-
let max = getValue(maxElement);
|
|
10
|
+
let max = getValue(maxElement, 0, items);
|
|
11
11
|
for (let i = 1; i < items.length; i++) {
|
|
12
12
|
const element = items[i];
|
|
13
|
-
const value = getValue(element);
|
|
13
|
+
const value = getValue(element, i, items);
|
|
14
14
|
if (value > max) {
|
|
15
15
|
max = value;
|
|
16
16
|
maxElement = element;
|
package/dist/array/maxBy.mjs
CHANGED
|
@@ -3,10 +3,10 @@ function maxBy(items, getValue) {
|
|
|
3
3
|
return undefined;
|
|
4
4
|
}
|
|
5
5
|
let maxElement = items[0];
|
|
6
|
-
let max = getValue(maxElement);
|
|
6
|
+
let max = getValue(maxElement, 0, items);
|
|
7
7
|
for (let i = 1; i < items.length; i++) {
|
|
8
8
|
const element = items[i];
|
|
9
|
-
const value = getValue(element);
|
|
9
|
+
const value = getValue(element, i, items);
|
|
10
10
|
if (value > max) {
|
|
11
11
|
max = value;
|
|
12
12
|
maxElement = element;
|
package/dist/array/minBy.d.mts
CHANGED
|
@@ -18,14 +18,14 @@
|
|
|
18
18
|
* x => x.age
|
|
19
19
|
* ); // Returns: { name: 'joe', age: 26 }
|
|
20
20
|
*/
|
|
21
|
-
declare function minBy<T>(items: readonly [T, ...T[]], getValue: (element: T) => number): T;
|
|
21
|
+
declare function minBy<T>(items: readonly [T, ...T[]], getValue: (element: T, index: number, array: readonly T[]) => number): T;
|
|
22
22
|
/**
|
|
23
23
|
* Finds the element in an array that has the minimum value when applying
|
|
24
24
|
* the `getValue` function to each element.
|
|
25
25
|
*
|
|
26
26
|
* @template T - The type of elements in the array.
|
|
27
27
|
* @param {T[]} items The array of elements to search.
|
|
28
|
-
* @param {(element: T) => number} getValue A function that selects a numeric value from each element.
|
|
28
|
+
* @param {(element: T, index: number, array: readonly T[]) => number} getValue A function that selects a numeric value from each element.
|
|
29
29
|
* @returns {T | undefined} The element with the minimum value as determined by the `getValue` function,
|
|
30
30
|
* or `undefined` if the array is empty.
|
|
31
31
|
* @example
|
|
@@ -40,6 +40,6 @@ declare function minBy<T>(items: readonly [T, ...T[]], getValue: (element: T) =>
|
|
|
40
40
|
* x => x.age
|
|
41
41
|
* ); // Returns: { name: 'joe', age: 26 }
|
|
42
42
|
*/
|
|
43
|
-
declare function minBy<T>(items: readonly T[], getValue: (element: T) => number): T | undefined;
|
|
43
|
+
declare function minBy<T>(items: readonly T[], getValue: (element: T, index: number, array: readonly T[]) => number): T | undefined;
|
|
44
44
|
|
|
45
45
|
export { minBy };
|
package/dist/array/minBy.d.ts
CHANGED
|
@@ -18,14 +18,14 @@
|
|
|
18
18
|
* x => x.age
|
|
19
19
|
* ); // Returns: { name: 'joe', age: 26 }
|
|
20
20
|
*/
|
|
21
|
-
declare function minBy<T>(items: readonly [T, ...T[]], getValue: (element: T) => number): T;
|
|
21
|
+
declare function minBy<T>(items: readonly [T, ...T[]], getValue: (element: T, index: number, array: readonly T[]) => number): T;
|
|
22
22
|
/**
|
|
23
23
|
* Finds the element in an array that has the minimum value when applying
|
|
24
24
|
* the `getValue` function to each element.
|
|
25
25
|
*
|
|
26
26
|
* @template T - The type of elements in the array.
|
|
27
27
|
* @param {T[]} items The array of elements to search.
|
|
28
|
-
* @param {(element: T) => number} getValue A function that selects a numeric value from each element.
|
|
28
|
+
* @param {(element: T, index: number, array: readonly T[]) => number} getValue A function that selects a numeric value from each element.
|
|
29
29
|
* @returns {T | undefined} The element with the minimum value as determined by the `getValue` function,
|
|
30
30
|
* or `undefined` if the array is empty.
|
|
31
31
|
* @example
|
|
@@ -40,6 +40,6 @@ declare function minBy<T>(items: readonly [T, ...T[]], getValue: (element: T) =>
|
|
|
40
40
|
* x => x.age
|
|
41
41
|
* ); // Returns: { name: 'joe', age: 26 }
|
|
42
42
|
*/
|
|
43
|
-
declare function minBy<T>(items: readonly T[], getValue: (element: T) => number): T | undefined;
|
|
43
|
+
declare function minBy<T>(items: readonly T[], getValue: (element: T, index: number, array: readonly T[]) => number): T | undefined;
|
|
44
44
|
|
|
45
45
|
export { minBy };
|
package/dist/array/minBy.js
CHANGED
|
@@ -7,10 +7,10 @@ function minBy(items, getValue) {
|
|
|
7
7
|
return undefined;
|
|
8
8
|
}
|
|
9
9
|
let minElement = items[0];
|
|
10
|
-
let min = getValue(minElement);
|
|
10
|
+
let min = getValue(minElement, 0, items);
|
|
11
11
|
for (let i = 1; i < items.length; i++) {
|
|
12
12
|
const element = items[i];
|
|
13
|
-
const value = getValue(element);
|
|
13
|
+
const value = getValue(element, i, items);
|
|
14
14
|
if (value < min) {
|
|
15
15
|
min = value;
|
|
16
16
|
minElement = element;
|
package/dist/array/minBy.mjs
CHANGED
|
@@ -3,10 +3,10 @@ function minBy(items, getValue) {
|
|
|
3
3
|
return undefined;
|
|
4
4
|
}
|
|
5
5
|
let minElement = items[0];
|
|
6
|
-
let min = getValue(minElement);
|
|
6
|
+
let min = getValue(minElement, 0, items);
|
|
7
7
|
for (let i = 1; i < items.length; i++) {
|
|
8
8
|
const element = items[i];
|
|
9
|
-
const value = getValue(element);
|
|
9
|
+
const value = getValue(element, i, items);
|
|
10
10
|
if (value < min) {
|
|
11
11
|
min = value;
|
|
12
12
|
minElement = element;
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
* @template T - The type of elements in the array.
|
|
9
9
|
* @template {T} U - The type being filtered for.
|
|
10
10
|
* @param {T[]} arr - The array to partition.
|
|
11
|
-
* @param {(value: T) => value is U} isInTruthy - A type guard that determines whether an
|
|
11
|
+
* @param {(value: T, index: number, array: readonly T[]) => value is U} isInTruthy - A type guard that determines whether an
|
|
12
12
|
* element should be placed in the truthy array. The function is called with each element
|
|
13
|
-
* of the array.
|
|
13
|
+
* of the array and its index.
|
|
14
14
|
* @returns {[U[], Exclude<T, U>[]]} A tuple containing two arrays: the first array contains elements for
|
|
15
15
|
* which the predicate returned true, and the second array contains elements for which the
|
|
16
16
|
* predicate returned false.
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* const [even, odd]: [(2 | 4)[], (2 | 4)[]] = partition(array, isEven);
|
|
22
22
|
* // even will be [2, 4], and odd will be [1, 3]
|
|
23
23
|
*/
|
|
24
|
-
declare function partition<T, U extends T>(arr: readonly T[], isInTruthy: (value: T) => value is U): [truthy: U[], falsy: Array<Exclude<T, U>>];
|
|
24
|
+
declare function partition<T, U extends T>(arr: readonly T[], isInTruthy: (value: T, index: number, array: readonly T[]) => value is U): [truthy: U[], falsy: Array<Exclude<T, U>>];
|
|
25
25
|
/**
|
|
26
26
|
* Splits an array into two groups based on a predicate function.
|
|
27
27
|
*
|
|
@@ -31,9 +31,9 @@ declare function partition<T, U extends T>(arr: readonly T[], isInTruthy: (value
|
|
|
31
31
|
*
|
|
32
32
|
* @template T - The type of elements in the array.
|
|
33
33
|
* @param {T[]} arr - The array to partition.
|
|
34
|
-
* @param {(value: T) => boolean} isInTruthy - A predicate function that determines
|
|
34
|
+
* @param {(value: T, index: number) => boolean} isInTruthy - A predicate function that determines
|
|
35
35
|
* whether an element should be placed in the truthy array. The function is called with each
|
|
36
|
-
* element of the array.
|
|
36
|
+
* element of the array and its index.
|
|
37
37
|
* @returns {[T[], T[]]} A tuple containing two arrays: the first array contains elements for
|
|
38
38
|
* which the predicate returned true, and the second array contains elements for which the
|
|
39
39
|
* predicate returned false.
|
|
@@ -44,6 +44,6 @@ declare function partition<T, U extends T>(arr: readonly T[], isInTruthy: (value
|
|
|
44
44
|
* const [even, odd] = partition(array, isEven);
|
|
45
45
|
* // even will be [2, 4], and odd will be [1, 3, 5]
|
|
46
46
|
*/
|
|
47
|
-
declare function partition<T>(arr: readonly T[], isInTruthy: (value: T) => boolean): [truthy: T[], falsy: T[]];
|
|
47
|
+
declare function partition<T>(arr: readonly T[], isInTruthy: (value: T, index: number, array: readonly T[]) => boolean): [truthy: T[], falsy: T[]];
|
|
48
48
|
|
|
49
49
|
export { partition };
|