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.
Files changed (208) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/{compat/util/eq.d.mts → _internal/isEqualsSameValueZero.d.mts} +2 -2
  3. package/dist/{compat/util/eq.d.ts → _internal/isEqualsSameValueZero.d.ts} +2 -2
  4. package/dist/{compat/util/eq.js → _internal/isEqualsSameValueZero.js} +2 -2
  5. package/dist/_internal/isEqualsSameValueZero.mjs +5 -0
  6. package/dist/array/countBy.d.mts +8 -2
  7. package/dist/array/countBy.d.ts +8 -2
  8. package/dist/array/countBy.js +1 -1
  9. package/dist/array/countBy.mjs +1 -1
  10. package/dist/array/flatMap.d.mts +2 -2
  11. package/dist/array/flatMap.d.ts +2 -2
  12. package/dist/array/flatMap.js +1 -1
  13. package/dist/array/flatMap.mjs +1 -1
  14. package/dist/array/flatMapDeep.d.mts +2 -2
  15. package/dist/array/flatMapDeep.d.ts +2 -2
  16. package/dist/array/flatMapDeep.js +1 -1
  17. package/dist/array/flatMapDeep.mjs +1 -1
  18. package/dist/array/groupBy.d.mts +8 -2
  19. package/dist/array/groupBy.d.ts +8 -2
  20. package/dist/array/groupBy.js +1 -1
  21. package/dist/array/groupBy.mjs +1 -1
  22. package/dist/array/intersection.js +1 -3
  23. package/dist/array/intersection.mjs +1 -3
  24. package/dist/array/keyBy.d.mts +8 -2
  25. package/dist/array/keyBy.d.ts +8 -2
  26. package/dist/array/keyBy.js +1 -1
  27. package/dist/array/keyBy.mjs +1 -1
  28. package/dist/array/maxBy.d.mts +3 -3
  29. package/dist/array/maxBy.d.ts +3 -3
  30. package/dist/array/maxBy.js +2 -2
  31. package/dist/array/maxBy.mjs +2 -2
  32. package/dist/array/minBy.d.mts +3 -3
  33. package/dist/array/minBy.d.ts +3 -3
  34. package/dist/array/minBy.js +2 -2
  35. package/dist/array/minBy.mjs +2 -2
  36. package/dist/array/partition.d.mts +6 -6
  37. package/dist/array/partition.d.ts +6 -6
  38. package/dist/array/partition.js +1 -1
  39. package/dist/array/partition.mjs +1 -1
  40. package/dist/array/takeRightWhile.d.mts +7 -2
  41. package/dist/array/takeRightWhile.d.ts +7 -2
  42. package/dist/array/takeRightWhile.js +1 -1
  43. package/dist/array/takeRightWhile.mjs +1 -1
  44. package/dist/array/takeWhile.d.mts +7 -2
  45. package/dist/array/takeWhile.d.ts +7 -2
  46. package/dist/array/takeWhile.js +1 -1
  47. package/dist/array/takeWhile.mjs +1 -1
  48. package/dist/array/uniqBy.d.mts +1 -1
  49. package/dist/array/uniqBy.d.ts +1 -1
  50. package/dist/array/uniqBy.js +1 -1
  51. package/dist/array/uniqBy.mjs +1 -1
  52. package/dist/array/zipWith.d.mts +8 -8
  53. package/dist/array/zipWith.d.ts +8 -8
  54. package/dist/array/zipWith.js +1 -1
  55. package/dist/array/zipWith.mjs +1 -1
  56. package/dist/browser.global.js +1 -1
  57. package/dist/compat/_internal/assignValue.js +2 -2
  58. package/dist/compat/_internal/assignValue.mjs +2 -2
  59. package/dist/compat/_internal/isIterateeCall.js +2 -2
  60. package/dist/compat/_internal/isIterateeCall.mjs +2 -2
  61. package/dist/compat/array/includes.js +2 -2
  62. package/dist/compat/array/includes.mjs +2 -2
  63. package/dist/compat/array/intersectionWith.js +2 -2
  64. package/dist/compat/array/intersectionWith.mjs +2 -2
  65. package/dist/compat/array/pullAllWith.js +2 -2
  66. package/dist/compat/array/pullAllWith.mjs +2 -2
  67. package/dist/compat/array/sortedIndexOf.js +2 -2
  68. package/dist/compat/array/sortedIndexOf.mjs +2 -2
  69. package/dist/compat/array/sortedLastIndexOf.js +2 -2
  70. package/dist/compat/array/sortedLastIndexOf.mjs +2 -2
  71. package/dist/compat/array/unionBy.js +2 -1
  72. package/dist/compat/array/unionBy.mjs +2 -1
  73. package/dist/compat/array/uniqBy.js +2 -1
  74. package/dist/compat/array/uniqBy.mjs +2 -1
  75. package/dist/compat/compat.d.mts +1 -1
  76. package/dist/compat/compat.d.ts +1 -1
  77. package/dist/compat/compat.js +2 -2
  78. package/dist/compat/compat.mjs +1 -1
  79. package/dist/compat/index.d.mts +1 -1
  80. package/dist/compat/index.d.ts +1 -1
  81. package/dist/compat/index.js +2 -2
  82. package/dist/compat/index.mjs +1 -1
  83. package/dist/compat/math/clamp.js +12 -6
  84. package/dist/compat/math/clamp.mjs +12 -6
  85. package/dist/compat/object/assign.js +2 -2
  86. package/dist/compat/object/assign.mjs +2 -2
  87. package/dist/compat/object/assignIn.js +2 -2
  88. package/dist/compat/object/assignIn.mjs +2 -2
  89. package/dist/compat/object/assignInWith.js +2 -2
  90. package/dist/compat/object/assignInWith.mjs +2 -2
  91. package/dist/compat/object/assignWith.js +2 -2
  92. package/dist/compat/object/assignWith.mjs +2 -2
  93. package/dist/compat/object/cloneDeepWith.js +7 -0
  94. package/dist/compat/object/cloneDeepWith.mjs +8 -1
  95. package/dist/compat/object/defaults.js +2 -2
  96. package/dist/compat/object/defaults.mjs +2 -2
  97. package/dist/compat/predicate/isMatchWith.js +3 -3
  98. package/dist/compat/predicate/isMatchWith.mjs +3 -3
  99. package/dist/function/retry.d.mts +13 -0
  100. package/dist/function/retry.d.ts +13 -0
  101. package/dist/function/retry.js +7 -0
  102. package/dist/function/retry.mjs +7 -0
  103. package/dist/index.d.mts +2 -0
  104. package/dist/index.d.ts +2 -0
  105. package/dist/index.js +4 -0
  106. package/dist/index.mjs +2 -0
  107. package/dist/map/every.d.mts +28 -0
  108. package/dist/map/every.d.ts +28 -0
  109. package/dist/map/every.js +14 -0
  110. package/dist/map/every.mjs +10 -0
  111. package/dist/map/filter.d.mts +29 -0
  112. package/dist/map/filter.d.ts +29 -0
  113. package/dist/map/filter.js +15 -0
  114. package/dist/map/filter.mjs +11 -0
  115. package/dist/map/findKey.d.mts +25 -0
  116. package/dist/map/findKey.d.ts +25 -0
  117. package/dist/map/findKey.js +16 -0
  118. package/dist/map/findKey.mjs +12 -0
  119. package/dist/map/findValue.d.mts +25 -0
  120. package/dist/map/findValue.d.ts +25 -0
  121. package/dist/map/findValue.js +16 -0
  122. package/dist/map/findValue.mjs +12 -0
  123. package/dist/map/hasValue.d.mts +28 -0
  124. package/dist/map/hasValue.d.ts +28 -0
  125. package/dist/map/hasValue.js +16 -0
  126. package/dist/map/hasValue.mjs +12 -0
  127. package/dist/map/index.d.mts +9 -0
  128. package/dist/map/index.d.ts +9 -0
  129. package/dist/map/index.js +25 -0
  130. package/dist/map/index.mjs +9 -0
  131. package/dist/map/mapKeys.d.mts +30 -0
  132. package/dist/map/mapKeys.d.ts +30 -0
  133. package/dist/map/mapKeys.js +14 -0
  134. package/dist/map/mapKeys.mjs +10 -0
  135. package/dist/map/mapValues.d.mts +30 -0
  136. package/dist/map/mapValues.d.ts +30 -0
  137. package/dist/map/mapValues.js +14 -0
  138. package/dist/map/mapValues.mjs +10 -0
  139. package/dist/map/reduce.d.mts +35 -0
  140. package/dist/map/reduce.d.ts +35 -0
  141. package/dist/map/reduce.js +21 -0
  142. package/dist/map/reduce.mjs +17 -0
  143. package/dist/map/some.d.mts +28 -0
  144. package/dist/map/some.d.ts +28 -0
  145. package/dist/map/some.js +14 -0
  146. package/dist/map/some.mjs +10 -0
  147. package/dist/object/clone.js +11 -3
  148. package/dist/object/clone.mjs +11 -3
  149. package/dist/object/cloneDeep.d.mts +6 -6
  150. package/dist/object/cloneDeep.d.ts +6 -6
  151. package/dist/object/flattenObject.js +1 -1
  152. package/dist/object/flattenObject.mjs +1 -1
  153. package/dist/predicate/index.d.mts +2 -0
  154. package/dist/predicate/index.d.ts +2 -0
  155. package/dist/predicate/index.js +4 -0
  156. package/dist/predicate/index.mjs +2 -0
  157. package/dist/predicate/isEmptyObject.d.mts +15 -0
  158. package/dist/predicate/isEmptyObject.d.ts +15 -0
  159. package/dist/predicate/isEmptyObject.js +11 -0
  160. package/dist/predicate/isEmptyObject.mjs +7 -0
  161. package/dist/predicate/isEqualWith.js +2 -2
  162. package/dist/predicate/isEqualWith.mjs +2 -2
  163. package/dist/predicate/isNumber.d.mts +25 -0
  164. package/dist/predicate/isNumber.d.ts +25 -0
  165. package/dist/predicate/isNumber.js +9 -0
  166. package/dist/predicate/isNumber.mjs +5 -0
  167. package/dist/set/countBy.d.mts +26 -0
  168. package/dist/set/countBy.d.ts +26 -0
  169. package/dist/set/countBy.js +14 -0
  170. package/dist/set/countBy.mjs +10 -0
  171. package/dist/set/every.d.mts +23 -0
  172. package/dist/set/every.d.ts +23 -0
  173. package/dist/set/every.js +14 -0
  174. package/dist/set/every.mjs +10 -0
  175. package/dist/set/filter.d.mts +20 -0
  176. package/dist/set/filter.d.ts +20 -0
  177. package/dist/set/filter.js +15 -0
  178. package/dist/set/filter.mjs +11 -0
  179. package/dist/set/find.d.mts +24 -0
  180. package/dist/set/find.d.ts +24 -0
  181. package/dist/set/find.js +14 -0
  182. package/dist/set/find.mjs +10 -0
  183. package/dist/set/index.d.mts +8 -0
  184. package/dist/set/index.d.ts +8 -0
  185. package/dist/set/index.js +23 -0
  186. package/dist/set/index.mjs +8 -0
  187. package/dist/set/keyBy.d.mts +30 -0
  188. package/dist/set/keyBy.d.ts +30 -0
  189. package/dist/set/keyBy.js +14 -0
  190. package/dist/set/keyBy.mjs +10 -0
  191. package/dist/set/map.d.mts +21 -0
  192. package/dist/set/map.d.ts +21 -0
  193. package/dist/set/map.js +14 -0
  194. package/dist/set/map.mjs +10 -0
  195. package/dist/set/reduce.d.mts +28 -0
  196. package/dist/set/reduce.d.ts +28 -0
  197. package/dist/set/reduce.js +21 -0
  198. package/dist/set/reduce.mjs +17 -0
  199. package/dist/set/some.d.mts +23 -0
  200. package/dist/set/some.d.ts +23 -0
  201. package/dist/set/some.js +14 -0
  202. package/dist/set/some.mjs +10 -0
  203. package/map.d.ts +1 -0
  204. package/map.js +1 -0
  205. package/package.json +4 -1
  206. package/set.d.ts +1 -0
  207. package/set.js +1 -0
  208. 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.
@@ -11,6 +11,6 @@
11
11
  * eq(NaN, NaN); // true
12
12
  * eq('a', Object('a')); // false
13
13
  */
14
- declare function eq(value: any, other: any): boolean;
14
+ declare function isEqualsSameValueZero(value: any, other: any): boolean;
15
15
 
16
- export { eq };
16
+ export { isEqualsSameValueZero };
@@ -11,6 +11,6 @@
11
11
  * eq(NaN, NaN); // true
12
12
  * eq('a', Object('a')); // false
13
13
  */
14
- declare function eq(value: any, other: any): boolean;
14
+ declare function isEqualsSameValueZero(value: any, other: any): boolean;
15
15
 
16
- export { eq };
16
+ export { isEqualsSameValueZero };
@@ -2,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- function eq(value, other) {
5
+ function isEqualsSameValueZero(value, other) {
6
6
  return value === other || (Number.isNaN(value) && Number.isNaN(other));
7
7
  }
8
8
 
9
- exports.eq = eq;
9
+ exports.isEqualsSameValueZero = isEqualsSameValueZero;
@@ -0,0 +1,5 @@
1
+ function isEqualsSameValueZero(value, other) {
2
+ return value === other || (Number.isNaN(value) && Number.isNaN(other));
3
+ }
4
+
5
+ export { isEqualsSameValueZero };
@@ -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 };
@@ -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 };
@@ -6,7 +6,7 @@ function countBy(arr, mapper) {
6
6
  const result = {};
7
7
  for (let i = 0; i < arr.length; i++) {
8
8
  const item = arr[i];
9
- const key = mapper(item);
9
+ const key = mapper(item, i, arr);
10
10
  result[key] = (result[key] ?? 0) + 1;
11
11
  }
12
12
  return result;
@@ -2,7 +2,7 @@ function countBy(arr, mapper) {
2
2
  const result = {};
3
3
  for (let i = 0; i < arr.length; i++) {
4
4
  const item = arr[i];
5
- const key = mapper(item);
5
+ const key = mapper(item, i, arr);
6
6
  result[key] = (result[key] ?? 0) + 1;
7
7
  }
8
8
  return result;
@@ -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 };
@@ -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 };
@@ -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;
@@ -1,7 +1,7 @@
1
1
  import { flatten } from './flatten.mjs';
2
2
 
3
3
  function flatMap(arr, iteratee, depth = 1) {
4
- return flatten(arr.map(item => iteratee(item)), depth);
4
+ return flatten(arr.map((item, index) => iteratee(item, index, arr)), depth);
5
5
  }
6
6
 
7
7
  export { flatMap };
@@ -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;
@@ -1,7 +1,7 @@
1
1
  import { flattenDeep } from './flattenDeep.mjs';
2
2
 
3
3
  function flatMapDeep(arr, iteratee) {
4
- return flattenDeep(arr.map((item) => iteratee(item)));
4
+ return flattenDeep(arr.map((item, index) => iteratee(item, index, arr)));
5
5
  }
6
6
 
7
7
  export { flatMapDeep };
@@ -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 };
@@ -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 };
@@ -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
  }
@@ -2,7 +2,7 @@ function groupBy(arr, getKeyFromItem) {
2
2
  const result = {};
3
3
  for (let i = 0; i < arr.length; i++) {
4
4
  const item = arr[i];
5
- const key = getKeyFromItem(item);
5
+ const key = getKeyFromItem(item, i, arr);
6
6
  if (!Object.hasOwn(result, key)) {
7
7
  result[key] = [];
8
8
  }
@@ -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;
@@ -1,8 +1,6 @@
1
1
  function intersection(firstArr, secondArr) {
2
2
  const secondSet = new Set(secondArr);
3
- return firstArr.filter(item => {
4
- return secondSet.has(item);
5
- });
3
+ return firstArr.filter(item => secondSet.has(item));
6
4
  }
7
5
 
8
6
  export { intersection };
@@ -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 };
@@ -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 };
@@ -6,7 +6,7 @@ function keyBy(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
  result[key] = item;
11
11
  }
12
12
  return result;
@@ -2,7 +2,7 @@ function keyBy(arr, getKeyFromItem) {
2
2
  const result = {};
3
3
  for (let i = 0; i < arr.length; i++) {
4
4
  const item = arr[i];
5
- const key = getKeyFromItem(item);
5
+ const key = getKeyFromItem(item, i, arr);
6
6
  result[key] = item;
7
7
  }
8
8
  return result;
@@ -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 };
@@ -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 };
@@ -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;
@@ -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;
@@ -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 };
@@ -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 };
@@ -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;
@@ -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 };