es-toolkit 1.49.0 → 1.50.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (184) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/dist/array/partition.d.mts +5 -4
  3. package/dist/array/partition.d.ts +5 -4
  4. package/dist/array/unzipWith.js +1 -1
  5. package/dist/array/unzipWith.mjs +1 -1
  6. package/dist/browser.global.js +3 -3
  7. package/dist/compat/_internal/ListIterateeCustom.d.mts +3 -2
  8. package/dist/compat/_internal/ListIterateeCustom.d.ts +3 -2
  9. package/dist/compat/_internal/assignValue.js +2 -3
  10. package/dist/compat/_internal/assignValue.mjs +2 -3
  11. package/dist/compat/_internal/createPadding.js +14 -0
  12. package/dist/compat/_internal/createPadding.mjs +13 -0
  13. package/dist/compat/_internal/isDeepKey.js +14 -1
  14. package/dist/compat/_internal/isDeepKey.mjs +14 -1
  15. package/dist/compat/_internal/isIterateeCall.js +2 -3
  16. package/dist/compat/_internal/isIterateeCall.mjs +2 -3
  17. package/dist/compat/_internal/regexMultiByte.js +11 -0
  18. package/dist/compat/_internal/regexMultiByte.mjs +11 -0
  19. package/dist/compat/array/every.js +5 -24
  20. package/dist/compat/array/every.mjs +5 -24
  21. package/dist/compat/array/filter.d.mts +7 -3
  22. package/dist/compat/array/filter.d.ts +7 -3
  23. package/dist/compat/array/filter.js +11 -11
  24. package/dist/compat/array/filter.mjs +11 -11
  25. package/dist/compat/array/find.d.mts +10 -6
  26. package/dist/compat/array/find.d.ts +10 -6
  27. package/dist/compat/array/find.js +1 -1
  28. package/dist/compat/array/find.mjs +1 -1
  29. package/dist/compat/array/findIndex.d.mts +0 -1
  30. package/dist/compat/array/findIndex.d.ts +0 -1
  31. package/dist/compat/array/findIndex.js +2 -1
  32. package/dist/compat/array/findIndex.mjs +2 -1
  33. package/dist/compat/array/findLast.d.mts +1 -1
  34. package/dist/compat/array/findLast.d.ts +1 -1
  35. package/dist/compat/array/findLast.js +12 -12
  36. package/dist/compat/array/findLast.mjs +12 -12
  37. package/dist/compat/array/findLastIndex.js +1 -0
  38. package/dist/compat/array/findLastIndex.mjs +1 -0
  39. package/dist/compat/array/flatMap.js +3 -2
  40. package/dist/compat/array/flatMap.mjs +3 -2
  41. package/dist/compat/array/flatMapDepth.js +2 -2
  42. package/dist/compat/array/flatMapDepth.mjs +2 -2
  43. package/dist/compat/array/flatten.d.mts +4 -5
  44. package/dist/compat/array/flatten.d.ts +4 -5
  45. package/dist/compat/array/flatten.js +14 -15
  46. package/dist/compat/array/flatten.mjs +14 -15
  47. package/dist/compat/array/flattenDeep.d.mts +1 -1
  48. package/dist/compat/array/flattenDeep.d.ts +1 -1
  49. package/dist/compat/array/flattenDeep.js +2 -2
  50. package/dist/compat/array/flattenDeep.mjs +2 -2
  51. package/dist/compat/array/flattenDepth.js +18 -2
  52. package/dist/compat/array/flattenDepth.mjs +18 -2
  53. package/dist/compat/array/groupBy.js +5 -4
  54. package/dist/compat/array/groupBy.mjs +4 -3
  55. package/dist/compat/array/includes.js +8 -3
  56. package/dist/compat/array/includes.mjs +8 -3
  57. package/dist/compat/array/intersectionBy.js +12 -5
  58. package/dist/compat/array/intersectionBy.mjs +12 -5
  59. package/dist/compat/array/intersectionWith.js +2 -3
  60. package/dist/compat/array/intersectionWith.mjs +2 -3
  61. package/dist/compat/array/invokeMap.js +3 -7
  62. package/dist/compat/array/invokeMap.mjs +3 -4
  63. package/dist/compat/array/lastIndexOf.js +3 -2
  64. package/dist/compat/array/lastIndexOf.mjs +3 -2
  65. package/dist/compat/array/nth.js +2 -2
  66. package/dist/compat/array/nth.mjs +2 -2
  67. package/dist/compat/array/pullAllWith.js +2 -3
  68. package/dist/compat/array/pullAllWith.mjs +2 -3
  69. package/dist/compat/array/size.js +2 -0
  70. package/dist/compat/array/size.mjs +2 -0
  71. package/dist/compat/array/sortedIndexOf.js +2 -3
  72. package/dist/compat/array/sortedIndexOf.mjs +2 -3
  73. package/dist/compat/array/sortedLastIndexOf.js +2 -3
  74. package/dist/compat/array/sortedLastIndexOf.mjs +2 -3
  75. package/dist/compat/compat.d.mts +4 -3
  76. package/dist/compat/compat.d.ts +4 -3
  77. package/dist/compat/compat.js +10 -11
  78. package/dist/compat/compat.mjs +10 -11
  79. package/dist/compat/index.d.mts +4 -3
  80. package/dist/compat/index.d.ts +4 -3
  81. package/dist/compat/index.js +10 -9
  82. package/dist/compat/index.mjs +10 -9
  83. package/dist/compat/math/inRange.d.mts +5 -2
  84. package/dist/compat/math/inRange.d.ts +5 -2
  85. package/dist/compat/math/inRange.js +14 -11
  86. package/dist/compat/math/inRange.mjs +14 -11
  87. package/dist/compat/math/maxBy.d.mts +1 -1
  88. package/dist/compat/math/maxBy.d.ts +1 -1
  89. package/dist/compat/math/maxBy.js +18 -4
  90. package/dist/compat/math/maxBy.mjs +18 -4
  91. package/dist/compat/math/minBy.d.mts +1 -1
  92. package/dist/compat/math/minBy.d.ts +1 -1
  93. package/dist/compat/math/minBy.js +18 -4
  94. package/dist/compat/math/minBy.mjs +18 -4
  95. package/dist/compat/object/assign.js +2 -3
  96. package/dist/compat/object/assign.mjs +2 -3
  97. package/dist/compat/object/assignIn.js +2 -3
  98. package/dist/compat/object/assignIn.mjs +2 -3
  99. package/dist/compat/object/assignInWith.js +2 -3
  100. package/dist/compat/object/assignInWith.mjs +2 -3
  101. package/dist/compat/object/assignWith.js +2 -3
  102. package/dist/compat/object/assignWith.mjs +2 -3
  103. package/dist/compat/object/create.js +1 -1
  104. package/dist/compat/object/create.mjs +1 -1
  105. package/dist/compat/object/defaults.js +2 -3
  106. package/dist/compat/object/defaults.mjs +2 -3
  107. package/dist/compat/object/has.js +1 -1
  108. package/dist/compat/object/has.mjs +1 -1
  109. package/dist/compat/object/hasIn.js +1 -1
  110. package/dist/compat/object/hasIn.mjs +1 -1
  111. package/dist/compat/object/unset.js +1 -1
  112. package/dist/compat/object/unset.mjs +1 -1
  113. package/dist/compat/object/values.js +5 -1
  114. package/dist/compat/object/values.mjs +5 -1
  115. package/dist/compat/predicate/isMatchWith.js +4 -5
  116. package/dist/compat/predicate/isMatchWith.mjs +4 -5
  117. package/dist/compat/string/camelCase.js +6 -2
  118. package/dist/compat/string/camelCase.mjs +6 -2
  119. package/dist/compat/string/kebabCase.js +2 -2
  120. package/dist/compat/string/kebabCase.mjs +2 -2
  121. package/dist/compat/string/lowerCase.js +2 -2
  122. package/dist/compat/string/lowerCase.mjs +2 -2
  123. package/dist/compat/string/pad.js +10 -3
  124. package/dist/compat/string/pad.mjs +10 -3
  125. package/dist/compat/string/padEnd.js +7 -1
  126. package/dist/compat/string/padEnd.mjs +7 -1
  127. package/dist/compat/string/padStart.js +7 -1
  128. package/dist/compat/string/padStart.mjs +7 -1
  129. package/dist/compat/string/snakeCase.js +2 -2
  130. package/dist/compat/string/snakeCase.mjs +2 -2
  131. package/dist/compat/string/startCase.js +1 -1
  132. package/dist/compat/string/startCase.mjs +1 -1
  133. package/dist/compat/string/template.d.mts +1 -1
  134. package/dist/compat/string/template.d.ts +1 -1
  135. package/dist/compat/string/templateSettings.d.mts +18 -1
  136. package/dist/compat/string/templateSettings.d.ts +18 -1
  137. package/dist/compat/string/templateSettings.js +4 -1
  138. package/dist/compat/string/templateSettings.mjs +5 -1
  139. package/dist/compat/string/truncate.js +2 -9
  140. package/dist/compat/string/truncate.mjs +1 -8
  141. package/dist/compat/string/upperCase.js +2 -2
  142. package/dist/compat/string/upperCase.mjs +2 -2
  143. package/dist/compat/util/eq.d.mts +17 -1
  144. package/dist/compat/util/eq.d.ts +17 -1
  145. package/dist/compat/util/eq.js +19 -1
  146. package/dist/compat/util/eq.mjs +19 -1
  147. package/dist/compat/util/toArray.js +2 -1
  148. package/dist/compat/util/toArray.mjs +2 -1
  149. package/dist/fp/flow.d.mts +213 -0
  150. package/dist/fp/flow.d.ts +213 -0
  151. package/dist/fp/flow.js +50 -0
  152. package/dist/fp/flow.mjs +50 -0
  153. package/dist/fp/index.d.mts +2 -1
  154. package/dist/fp/index.d.ts +2 -1
  155. package/dist/fp/index.js +3 -1
  156. package/dist/fp/index.mjs +3 -2
  157. package/dist/fp/pipe.js +8 -12
  158. package/dist/fp/pipe.mjs +8 -12
  159. package/dist/map/hasValue.js +2 -2
  160. package/dist/map/hasValue.mjs +2 -2
  161. package/dist/predicate/isEqualWith.js +2 -3
  162. package/dist/predicate/isEqualWith.mjs +2 -3
  163. package/dist/string/deburr.js +1 -1
  164. package/dist/string/deburr.mjs +1 -1
  165. package/dist/types/DeepPartial.d.mts +21 -0
  166. package/dist/types/DeepPartial.d.ts +21 -0
  167. package/dist/types/DeepReadonly.d.mts +22 -0
  168. package/dist/types/DeepReadonly.d.ts +22 -0
  169. package/dist/types/NonEmptyArray.d.mts +14 -0
  170. package/dist/types/NonEmptyArray.d.ts +14 -0
  171. package/dist/types/Simplify.d.mts +18 -0
  172. package/dist/types/Simplify.d.ts +18 -0
  173. package/dist/types/ValueOf.d.mts +14 -0
  174. package/dist/types/ValueOf.d.ts +14 -0
  175. package/dist/types/Writable.d.mts +15 -0
  176. package/dist/types/Writable.d.ts +15 -0
  177. package/dist/types/index.d.mts +7 -0
  178. package/dist/types/index.d.ts +7 -0
  179. package/package.json +23 -7
  180. package/types.d.ts +1 -0
  181. package/dist/_internal/isEqualsSameValueZero.d.mts +0 -17
  182. package/dist/_internal/isEqualsSameValueZero.d.ts +0 -17
  183. package/dist/_internal/isEqualsSameValueZero.js +0 -19
  184. package/dist/_internal/isEqualsSameValueZero.mjs +0 -19
@@ -6,9 +6,9 @@ const require_toInteger = require("../util/toInteger.js");
6
6
  * Finds the last item in an object that has a specific property, where the property name is provided as a PropertyKey.
7
7
  *
8
8
  * @template T
9
- * @param source - The source array or object to search through.
10
- * @param doesMatch - The criteria to match. It can be a function, a partial object, a key-value pair, or a property name.
11
- * @param [fromIndex] - The index to start the search from, defaults to source.length-1 for arrays or Object.keys(source).length-1 for objects.
9
+ * @param collection - The array or object to search through.
10
+ * @param [predicate=identity] - The criteria to match. It can be a function, a partial object, a key-value pair, or a property name.
11
+ * @param [fromIndex] - The index to start the search from, defaults to collection.length-1 for arrays or Object.keys(collection).length-1 for objects.
12
12
  * @returns The last property value that has the specified property, or `undefined` if no match is found.
13
13
  *
14
14
  * @example
@@ -17,23 +17,23 @@ const require_toInteger = require("../util/toInteger.js");
17
17
  * const result = findLast(obj, 'name');
18
18
  * console.log(result); // { id: 3, name: 'Bob' }
19
19
  */
20
- function findLast(source, _doesMatch = require_identity.identity, fromIndex) {
21
- if (!source) return;
22
- const length = Array.isArray(source) ? source.length : Object.keys(source).length;
20
+ function findLast(collection, predicate = require_identity.identity, fromIndex) {
21
+ if (!collection) return;
22
+ const length = Array.isArray(collection) ? collection.length : Object.keys(collection).length;
23
23
  fromIndex = require_toInteger.toInteger(fromIndex ?? length - 1);
24
24
  if (fromIndex < 0) fromIndex = Math.max(length + fromIndex, 0);
25
25
  else fromIndex = Math.min(fromIndex, length - 1);
26
- const doesMatch = require_iteratee.iteratee(_doesMatch);
27
- if (!Array.isArray(source)) {
28
- const keys = Object.keys(source);
26
+ const doesMatch = require_iteratee.iteratee(predicate);
27
+ if (!Array.isArray(collection)) {
28
+ const keys = Object.keys(collection);
29
29
  for (let i = fromIndex; i >= 0; i--) {
30
30
  const key = keys[i];
31
- const value = source[key];
32
- if (doesMatch(value, key, source)) return value;
31
+ const value = collection[key];
32
+ if (doesMatch(value, key, collection)) return value;
33
33
  }
34
34
  return;
35
35
  }
36
- return source.slice(0, fromIndex + 1).findLast(doesMatch);
36
+ return collection.slice(0, fromIndex + 1).findLast(doesMatch);
37
37
  }
38
38
  //#endregion
39
39
  exports.findLast = findLast;
@@ -6,9 +6,9 @@ import { toInteger } from "../util/toInteger.mjs";
6
6
  * Finds the last item in an object that has a specific property, where the property name is provided as a PropertyKey.
7
7
  *
8
8
  * @template T
9
- * @param source - The source array or object to search through.
10
- * @param doesMatch - The criteria to match. It can be a function, a partial object, a key-value pair, or a property name.
11
- * @param [fromIndex] - The index to start the search from, defaults to source.length-1 for arrays or Object.keys(source).length-1 for objects.
9
+ * @param collection - The array or object to search through.
10
+ * @param [predicate=identity] - The criteria to match. It can be a function, a partial object, a key-value pair, or a property name.
11
+ * @param [fromIndex] - The index to start the search from, defaults to collection.length-1 for arrays or Object.keys(collection).length-1 for objects.
12
12
  * @returns The last property value that has the specified property, or `undefined` if no match is found.
13
13
  *
14
14
  * @example
@@ -17,23 +17,23 @@ import { toInteger } from "../util/toInteger.mjs";
17
17
  * const result = findLast(obj, 'name');
18
18
  * console.log(result); // { id: 3, name: 'Bob' }
19
19
  */
20
- function findLast(source, _doesMatch = identity, fromIndex) {
21
- if (!source) return;
22
- const length = Array.isArray(source) ? source.length : Object.keys(source).length;
20
+ function findLast(collection, predicate = identity, fromIndex) {
21
+ if (!collection) return;
22
+ const length = Array.isArray(collection) ? collection.length : Object.keys(collection).length;
23
23
  fromIndex = toInteger(fromIndex ?? length - 1);
24
24
  if (fromIndex < 0) fromIndex = Math.max(length + fromIndex, 0);
25
25
  else fromIndex = Math.min(fromIndex, length - 1);
26
- const doesMatch = iteratee(_doesMatch);
27
- if (!Array.isArray(source)) {
28
- const keys = Object.keys(source);
26
+ const doesMatch = iteratee(predicate);
27
+ if (!Array.isArray(collection)) {
28
+ const keys = Object.keys(collection);
29
29
  for (let i = fromIndex; i >= 0; i--) {
30
30
  const key = keys[i];
31
- const value = source[key];
32
- if (doesMatch(value, key, source)) return value;
31
+ const value = collection[key];
32
+ if (doesMatch(value, key, collection)) return value;
33
33
  }
34
34
  return;
35
35
  }
36
- return source.slice(0, fromIndex + 1).findLast(doesMatch);
36
+ return collection.slice(0, fromIndex + 1).findLast(doesMatch);
37
37
  }
38
38
  //#endregion
39
39
  export { findLast };
@@ -20,6 +20,7 @@ const require_matchesProperty = require("../predicate/matchesProperty.js");
20
20
  */
21
21
  function findLastIndex(arr, doesMatch = require_identity.identity, fromIndex = arr ? arr.length - 1 : 0) {
22
22
  if (!arr) return -1;
23
+ if (Number.isNaN(fromIndex)) fromIndex = 0;
23
24
  if (fromIndex < 0) fromIndex = Math.max(arr.length + fromIndex, 0);
24
25
  else fromIndex = Math.min(fromIndex, arr.length - 1);
25
26
  const subArray = require_toArray.toArray(arr).slice(0, fromIndex + 1);
@@ -20,6 +20,7 @@ import { matchesProperty } from "../predicate/matchesProperty.mjs";
20
20
  */
21
21
  function findLastIndex(arr, doesMatch = identity, fromIndex = arr ? arr.length - 1 : 0) {
22
22
  if (!arr) return -1;
23
+ if (Number.isNaN(fromIndex)) fromIndex = 0;
23
24
  if (fromIndex < 0) fromIndex = Math.max(arr.length + fromIndex, 0);
24
25
  else fromIndex = Math.min(fromIndex, arr.length - 1);
25
26
  const subArray = toArray(arr).slice(0, fromIndex + 1);
@@ -1,3 +1,4 @@
1
+ const require_identity = require("../../function/identity.js");
1
2
  const require_isNil = require("../../predicate/isNil.js");
2
3
  const require_flattenDepth = require("./flattenDepth.js");
3
4
  const require_map = require("./map.js");
@@ -7,14 +8,14 @@ const require_map = require("./map.js");
7
8
  *
8
9
  * @template R
9
10
  * @param collection - The collection to iterate over.
10
- * @param [iteratee] - The function invoked per iteration.
11
+ * @param [iteratee=identity] - The function invoked per iteration.
11
12
  * @returns Returns the new flattened array.
12
13
  *
13
14
  * @example
14
15
  * flatMap([1, 2], n => [n, n * 2]);
15
16
  * // => [1, 2, 2, 4]
16
17
  */
17
- function flatMap(collection, iteratee) {
18
+ function flatMap(collection, iteratee = require_identity.identity) {
18
19
  if (require_isNil.isNil(collection)) return [];
19
20
  const mapped = require_isNil.isNil(iteratee) ? require_map.map(collection) : require_map.map(collection, iteratee);
20
21
  return require_flattenDepth.flattenDepth(mapped, 1);
@@ -1,3 +1,4 @@
1
+ import { identity } from "../../function/identity.mjs";
1
2
  import { isNil } from "../../predicate/isNil.mjs";
2
3
  import { flattenDepth } from "./flattenDepth.mjs";
3
4
  import { map } from "./map.mjs";
@@ -7,14 +8,14 @@ import { map } from "./map.mjs";
7
8
  *
8
9
  * @template R
9
10
  * @param collection - The collection to iterate over.
10
- * @param [iteratee] - The function invoked per iteration.
11
+ * @param [iteratee=identity] - The function invoked per iteration.
11
12
  * @returns Returns the new flattened array.
12
13
  *
13
14
  * @example
14
15
  * flatMap([1, 2], n => [n, n * 2]);
15
16
  * // => [1, 2, 2, 4]
16
17
  */
17
- function flatMap(collection, iteratee) {
18
+ function flatMap(collection, iteratee = identity) {
18
19
  if (isNil(collection)) return [];
19
20
  return flattenDepth(isNil(iteratee) ? map(collection) : map(collection, iteratee), 1);
20
21
  }
@@ -1,6 +1,6 @@
1
1
  const require_identity = require("../../function/identity.js");
2
2
  const require_iteratee = require("../util/iteratee.js");
3
- const require_flatten = require("./flatten.js");
3
+ const require_flattenDepth = require("./flattenDepth.js");
4
4
  const require_map = require("./map.js");
5
5
  //#region src/compat/array/flatMapDepth.ts
6
6
  /**
@@ -20,7 +20,7 @@ function flatMapDepth(collection, iteratee$1 = require_identity.identity, depth
20
20
  if (collection == null) return [];
21
21
  const iterateeFn = require_iteratee.iteratee(iteratee$1);
22
22
  const mapped = require_map.map(collection, iterateeFn);
23
- return require_flatten.flatten(mapped, depth);
23
+ return require_flattenDepth.flattenDepth(mapped, depth);
24
24
  }
25
25
  //#endregion
26
26
  exports.flatMapDepth = flatMapDepth;
@@ -1,6 +1,6 @@
1
1
  import { identity } from "../../function/identity.mjs";
2
2
  import { iteratee } from "../util/iteratee.mjs";
3
- import { flatten } from "./flatten.mjs";
3
+ import { flattenDepth } from "./flattenDepth.mjs";
4
4
  import { map } from "./map.mjs";
5
5
  //#region src/compat/array/flatMapDepth.ts
6
6
  /**
@@ -18,7 +18,7 @@ import { map } from "./map.mjs";
18
18
  */
19
19
  function flatMapDepth(collection, iteratee$1 = identity, depth = 1) {
20
20
  if (collection == null) return [];
21
- return flatten(map(collection, iteratee(iteratee$1)), depth);
21
+ return flattenDepth(map(collection, iteratee(iteratee$1)), depth);
22
22
  }
23
23
  //#endregion
24
24
  export { flatMapDepth };
@@ -3,14 +3,13 @@
3
3
  * Flattens array up to depth times.
4
4
  *
5
5
  * @template T
6
- * @param value - The array to flatten.
7
- * @param depth - The maximum recursion depth.
6
+ * @param array - The array to flatten.
8
7
  * @returns Returns the new flattened array.
9
8
  *
10
9
  * @example
11
- * flatten([1, [2, [3, [4]], 5]], 2);
12
- * // => [1, 2, 3, [4], 5]
10
+ * flatten([1, [2, [3, [4]], 5]]);
11
+ * // => [1, 2, [3, [4]], 5]
13
12
  */
14
- declare function flatten<T>(value: ArrayLike<T | readonly T[]> | null | undefined): T[];
13
+ declare function flatten<T>(array: ArrayLike<T | readonly T[]> | null | undefined): T[];
15
14
  //#endregion
16
15
  export { flatten };
@@ -3,14 +3,13 @@
3
3
  * Flattens array up to depth times.
4
4
  *
5
5
  * @template T
6
- * @param value - The array to flatten.
7
- * @param depth - The maximum recursion depth.
6
+ * @param array - The array to flatten.
8
7
  * @returns Returns the new flattened array.
9
8
  *
10
9
  * @example
11
- * flatten([1, [2, [3, [4]], 5]], 2);
12
- * // => [1, 2, 3, [4], 5]
10
+ * flatten([1, [2, [3, [4]], 5]]);
11
+ * // => [1, 2, [3, [4]], 5]
13
12
  */
14
- declare function flatten<T>(value: ArrayLike<T | readonly T[]> | null | undefined): T[];
13
+ declare function flatten<T>(array: ArrayLike<T | readonly T[]> | null | undefined): T[];
15
14
  //#endregion
16
15
  export { flatten };
@@ -1,19 +1,18 @@
1
- const require_isArrayLike = require("../predicate/isArrayLike.js");
1
+ const require_flattenDepth = require("./flattenDepth.js");
2
2
  //#region src/compat/array/flatten.ts
3
- function flatten(value, depth = 1) {
4
- const result = [];
5
- const flooredDepth = Math.floor(depth);
6
- if (!require_isArrayLike.isArrayLike(value)) return result;
7
- const recursive = (arr, currentDepth) => {
8
- for (let i = 0; i < arr.length; i++) {
9
- const item = arr[i];
10
- if (currentDepth < flooredDepth && (Array.isArray(item) || Boolean(item?.[Symbol.isConcatSpreadable]) || item !== null && typeof item === "object" && Object.prototype.toString.call(item) === "[object Arguments]")) if (Array.isArray(item)) recursive(item, currentDepth + 1);
11
- else recursive(Array.from(item), currentDepth + 1);
12
- else result.push(item);
13
- }
14
- };
15
- recursive(Array.from(value), 0);
16
- return result;
3
+ /**
4
+ * Flattens array up to depth times.
5
+ *
6
+ * @template T
7
+ * @param array - The array to flatten.
8
+ * @returns Returns the new flattened array.
9
+ *
10
+ * @example
11
+ * flatten([1, [2, [3, [4]], 5]]);
12
+ * // => [1, 2, [3, [4]], 5]
13
+ */
14
+ function flatten(array) {
15
+ return require_flattenDepth.flattenDepth(array, 1);
17
16
  }
18
17
  //#endregion
19
18
  exports.flatten = flatten;
@@ -1,19 +1,18 @@
1
- import { isArrayLike } from "../predicate/isArrayLike.mjs";
1
+ import { flattenDepth } from "./flattenDepth.mjs";
2
2
  //#region src/compat/array/flatten.ts
3
- function flatten(value, depth = 1) {
4
- const result = [];
5
- const flooredDepth = Math.floor(depth);
6
- if (!isArrayLike(value)) return result;
7
- const recursive = (arr, currentDepth) => {
8
- for (let i = 0; i < arr.length; i++) {
9
- const item = arr[i];
10
- if (currentDepth < flooredDepth && (Array.isArray(item) || Boolean(item?.[Symbol.isConcatSpreadable]) || item !== null && typeof item === "object" && Object.prototype.toString.call(item) === "[object Arguments]")) if (Array.isArray(item)) recursive(item, currentDepth + 1);
11
- else recursive(Array.from(item), currentDepth + 1);
12
- else result.push(item);
13
- }
14
- };
15
- recursive(Array.from(value), 0);
16
- return result;
3
+ /**
4
+ * Flattens array up to depth times.
5
+ *
6
+ * @template T
7
+ * @param array - The array to flatten.
8
+ * @returns Returns the new flattened array.
9
+ *
10
+ * @example
11
+ * flatten([1, [2, [3, [4]], 5]]);
12
+ * // => [1, 2, [3, [4]], 5]
13
+ */
14
+ function flatten(array) {
15
+ return flattenDepth(array, 1);
17
16
  }
18
17
  //#endregion
19
18
  export { flatten };
@@ -12,6 +12,6 @@ import { ListOfRecursiveArraysOrValues } from "../_internal/ListOfRecursiveArray
12
12
  * flattenDeep([1, [2, [3, [4]], 5]]);
13
13
  * // => [1, 2, 3, 4, 5]
14
14
  */
15
- declare function flattenDeep<T>(value: ListOfRecursiveArraysOrValues<T> | null | undefined): Array<T extends string ? T : T extends ArrayLike<any> ? never : T>;
15
+ declare function flattenDeep<T>(array: ListOfRecursiveArraysOrValues<T> | null | undefined): Array<T extends string ? T : T extends ArrayLike<any> ? never : T>;
16
16
  //#endregion
17
17
  export { flattenDeep };
@@ -12,6 +12,6 @@ import { ListOfRecursiveArraysOrValues } from "../_internal/ListOfRecursiveArray
12
12
  * flattenDeep([1, [2, [3, [4]], 5]]);
13
13
  * // => [1, 2, 3, 4, 5]
14
14
  */
15
- declare function flattenDeep<T>(value: ListOfRecursiveArraysOrValues<T> | null | undefined): Array<T extends string ? T : T extends ArrayLike<any> ? never : T>;
15
+ declare function flattenDeep<T>(array: ListOfRecursiveArraysOrValues<T> | null | undefined): Array<T extends string ? T : T extends ArrayLike<any> ? never : T>;
16
16
  //#endregion
17
17
  export { flattenDeep };
@@ -11,8 +11,8 @@ const require_flattenDepth = require("./flattenDepth.js");
11
11
  * flattenDeep([1, [2, [3, [4]], 5]]);
12
12
  * // => [1, 2, 3, 4, 5]
13
13
  */
14
- function flattenDeep(value) {
15
- return require_flattenDepth.flattenDepth(value, Infinity);
14
+ function flattenDeep(array) {
15
+ return require_flattenDepth.flattenDepth(array, Infinity);
16
16
  }
17
17
  //#endregion
18
18
  exports.flattenDeep = flattenDeep;
@@ -11,8 +11,8 @@ import { flattenDepth } from "./flattenDepth.mjs";
11
11
  * flattenDeep([1, [2, [3, [4]], 5]]);
12
12
  * // => [1, 2, 3, 4, 5]
13
13
  */
14
- function flattenDeep(value) {
15
- return flattenDepth(value, Infinity);
14
+ function flattenDeep(array) {
15
+ return flattenDepth(array, Infinity);
16
16
  }
17
17
  //#endregion
18
18
  export { flattenDeep };
@@ -1,4 +1,6 @@
1
- const require_flatten = require("./flatten.js");
1
+ const require_isArray = require("../predicate/isArray.js");
2
+ const require_isArrayLike = require("../predicate/isArrayLike.js");
3
+ const require_isArguments = require("../predicate/isArguments.js");
2
4
  //#region src/compat/array/flattenDepth.ts
3
5
  /**
4
6
  * Recursively flattens array up to depth times.
@@ -18,7 +20,21 @@ const require_flatten = require("./flatten.js");
18
20
  * // => [1, 2, 3, [4], 5]
19
21
  */
20
22
  function flattenDepth(array, depth = 1) {
21
- return require_flatten.flatten(array, depth);
23
+ if (!require_isArrayLike.isArrayLike(array)) return [];
24
+ const result = [];
25
+ const flooredDepth = Math.floor(depth);
26
+ const recursive = (arr, currentDepth) => {
27
+ for (let i = 0; i < arr.length; i++) {
28
+ const item = arr[i];
29
+ if (isFlattenable(item) && currentDepth < flooredDepth) recursive(item, currentDepth + 1);
30
+ else result.push(item);
31
+ }
32
+ };
33
+ recursive(Array.from(array), 0);
34
+ return result;
35
+ }
36
+ function isFlattenable(value) {
37
+ return require_isArray.isArray(value) || require_isArguments.isArguments(value) || Boolean(value && value[Symbol.isConcatSpreadable]);
22
38
  }
23
39
  //#endregion
24
40
  exports.flattenDepth = flattenDepth;
@@ -1,4 +1,6 @@
1
- import { flatten } from "./flatten.mjs";
1
+ import { isArray } from "../predicate/isArray.mjs";
2
+ import { isArrayLike } from "../predicate/isArrayLike.mjs";
3
+ import { isArguments } from "../predicate/isArguments.mjs";
2
4
  //#region src/compat/array/flattenDepth.ts
3
5
  /**
4
6
  * Recursively flattens array up to depth times.
@@ -18,7 +20,21 @@ import { flatten } from "./flatten.mjs";
18
20
  * // => [1, 2, 3, [4], 5]
19
21
  */
20
22
  function flattenDepth(array, depth = 1) {
21
- return flatten(array, depth);
23
+ if (!isArrayLike(array)) return [];
24
+ const result = [];
25
+ const flooredDepth = Math.floor(depth);
26
+ const recursive = (arr, currentDepth) => {
27
+ for (let i = 0; i < arr.length; i++) {
28
+ const item = arr[i];
29
+ if (isFlattenable(item) && currentDepth < flooredDepth) recursive(item, currentDepth + 1);
30
+ else result.push(item);
31
+ }
32
+ };
33
+ recursive(Array.from(array), 0);
34
+ return result;
35
+ }
36
+ function isFlattenable(value) {
37
+ return isArray(value) || isArguments(value) || Boolean(value && value[Symbol.isConcatSpreadable]);
22
38
  }
23
39
  //#endregion
24
40
  export { flattenDepth };
@@ -1,5 +1,6 @@
1
1
  const require_groupBy = require("../../array/groupBy.js");
2
2
  const require_identity = require("../../function/identity.js");
3
+ const require_toArray = require("../_internal/toArray.js");
3
4
  const require_isArrayLike = require("../predicate/isArrayLike.js");
4
5
  const require_iteratee = require("../util/iteratee.js");
5
6
  //#region src/compat/array/groupBy.ts
@@ -13,7 +14,7 @@ const require_iteratee = require("../util/iteratee.js");
13
14
  * @template T - The type of elements in the array or values in the object.
14
15
  * @template K - The type of keys.
15
16
  * @param source - The collection to group.
16
- * @param [_getKeyFromItem] - The iteratee to transform keys.
17
+ * @param [_getKeyFromItem=identity] - The iteratee to transform keys.
17
18
  * - If a function is provided, it's invoked for each element in the collection.
18
19
  * - If a property name (string) is provided, that property of each element is used as the key.
19
20
  * - If a property-value pair (array) is provided, elements with matching property values are used.
@@ -33,10 +34,10 @@ const require_iteratee = require("../util/iteratee.js");
33
34
  * const result = groupBy(array, 'length');
34
35
  * // => { 3: ['one', 'two'], 5: ['three'] }
35
36
  */
36
- function groupBy(source, _getKeyFromItem) {
37
+ function groupBy(source, _getKeyFromItem = require_identity.identity) {
37
38
  if (source == null) return {};
38
- const items = require_isArrayLike.isArrayLike(source) ? Array.from(source) : Object.values(source);
39
- const getKeyFromItem = require_iteratee.iteratee(_getKeyFromItem ?? require_identity.identity);
39
+ const items = require_isArrayLike.isArrayLike(source) ? require_toArray.toArray(source) : Object.values(source);
40
+ const getKeyFromItem = require_iteratee.iteratee(_getKeyFromItem);
40
41
  return require_groupBy.groupBy(items, getKeyFromItem);
41
42
  }
42
43
  //#endregion
@@ -1,5 +1,6 @@
1
1
  import { groupBy as groupBy$1 } from "../../array/groupBy.mjs";
2
2
  import { identity } from "../../function/identity.mjs";
3
+ import { toArray } from "../_internal/toArray.mjs";
3
4
  import { isArrayLike } from "../predicate/isArrayLike.mjs";
4
5
  import { iteratee } from "../util/iteratee.mjs";
5
6
  //#region src/compat/array/groupBy.ts
@@ -13,7 +14,7 @@ import { iteratee } from "../util/iteratee.mjs";
13
14
  * @template T - The type of elements in the array or values in the object.
14
15
  * @template K - The type of keys.
15
16
  * @param source - The collection to group.
16
- * @param [_getKeyFromItem] - The iteratee to transform keys.
17
+ * @param [_getKeyFromItem=identity] - The iteratee to transform keys.
17
18
  * - If a function is provided, it's invoked for each element in the collection.
18
19
  * - If a property name (string) is provided, that property of each element is used as the key.
19
20
  * - If a property-value pair (array) is provided, elements with matching property values are used.
@@ -33,9 +34,9 @@ import { iteratee } from "../util/iteratee.mjs";
33
34
  * const result = groupBy(array, 'length');
34
35
  * // => { 3: ['one', 'two'], 5: ['three'] }
35
36
  */
36
- function groupBy(source, _getKeyFromItem) {
37
+ function groupBy(source, _getKeyFromItem = identity) {
37
38
  if (source == null) return {};
38
- return groupBy$1(isArrayLike(source) ? Array.from(source) : Object.values(source), iteratee(_getKeyFromItem ?? identity));
39
+ return groupBy$1(isArrayLike(source) ? toArray(source) : Object.values(source), iteratee(_getKeyFromItem));
39
40
  }
40
41
  //#endregion
41
42
  export { groupBy };
@@ -1,5 +1,5 @@
1
- const require_isEqualsSameValueZero = require("../../_internal/isEqualsSameValueZero.js");
2
- require("../util/eq.js");
1
+ const require_eq = require("../util/eq.js");
2
+ const require_isArrayLike = require("../predicate/isArrayLike.js");
3
3
  const require_toInteger = require("../util/toInteger.js");
4
4
  const require_isString = require("../predicate/isString.js");
5
5
  //#region src/compat/array/includes.ts
@@ -29,11 +29,16 @@ function includes(source, target, fromIndex, guard) {
29
29
  return source.includes(target, fromIndex);
30
30
  }
31
31
  if (Array.isArray(source)) return source.includes(target, fromIndex);
32
+ if (require_isArrayLike.isArrayLike(source)) {
33
+ if (fromIndex < 0) fromIndex = Math.max(0, source.length + fromIndex);
34
+ for (let i = fromIndex; i < source.length; i++) if (require_eq.eq(source[i], target)) return true;
35
+ return false;
36
+ }
32
37
  const keys = Object.keys(source);
33
38
  if (fromIndex < 0) fromIndex = Math.max(0, keys.length + fromIndex);
34
39
  for (let i = fromIndex; i < keys.length; i++) {
35
40
  const value = Reflect.get(source, keys[i]);
36
- if (require_isEqualsSameValueZero.isEqualsSameValueZero(value, target)) return true;
41
+ if (require_eq.eq(value, target)) return true;
37
42
  }
38
43
  return false;
39
44
  }
@@ -1,5 +1,5 @@
1
- import { isEqualsSameValueZero } from "../../_internal/isEqualsSameValueZero.mjs";
2
- import "../util/eq.mjs";
1
+ import { eq } from "../util/eq.mjs";
2
+ import { isArrayLike } from "../predicate/isArrayLike.mjs";
3
3
  import { toInteger } from "../util/toInteger.mjs";
4
4
  import { isString } from "../predicate/isString.mjs";
5
5
  //#region src/compat/array/includes.ts
@@ -29,9 +29,14 @@ function includes(source, target, fromIndex, guard) {
29
29
  return source.includes(target, fromIndex);
30
30
  }
31
31
  if (Array.isArray(source)) return source.includes(target, fromIndex);
32
+ if (isArrayLike(source)) {
33
+ if (fromIndex < 0) fromIndex = Math.max(0, source.length + fromIndex);
34
+ for (let i = fromIndex; i < source.length; i++) if (eq(source[i], target)) return true;
35
+ return false;
36
+ }
32
37
  const keys = Object.keys(source);
33
38
  if (fromIndex < 0) fromIndex = Math.max(0, keys.length + fromIndex);
34
- for (let i = fromIndex; i < keys.length; i++) if (isEqualsSameValueZero(Reflect.get(source, keys[i]), target)) return true;
39
+ for (let i = fromIndex; i < keys.length; i++) if (eq(Reflect.get(source, keys[i]), target)) return true;
35
40
  return false;
36
41
  }
37
42
  //#endregion
@@ -1,7 +1,9 @@
1
1
  const require_intersectionBy = require("../../array/intersectionBy.js");
2
2
  const require_last = require("../../array/last.js");
3
3
  const require_uniq = require("../../array/uniq.js");
4
+ const require_uniqBy = require("../../array/uniqBy.js");
4
5
  const require_identity = require("../../function/identity.js");
6
+ const require_toArray = require("../_internal/toArray.js");
5
7
  const require_property = require("../object/property.js");
6
8
  const require_isArrayLikeObject = require("../predicate/isArrayLikeObject.js");
7
9
  //#region src/compat/array/intersectionBy.ts
@@ -36,17 +38,22 @@ const require_isArrayLikeObject = require("../predicate/isArrayLikeObject.js");
36
38
  function intersectionBy(array, ...values) {
37
39
  if (!require_isArrayLikeObject.isArrayLikeObject(array)) return [];
38
40
  const lastValue = require_last.last(values);
39
- if (lastValue === void 0) return Array.from(array);
40
- let result = require_uniq.uniq(Array.from(array));
41
41
  const count = require_isArrayLikeObject.isArrayLikeObject(lastValue) ? values.length : values.length - 1;
42
+ const iteratee = getIteratee(lastValue);
43
+ if (count <= 0) return require_uniqBy.uniqBy(require_toArray.toArray(array), iteratee ?? require_identity.identity);
44
+ let result = require_uniq.uniq(require_toArray.toArray(array));
42
45
  for (let i = 0; i < count; ++i) {
43
46
  const value = values[i];
44
47
  if (!require_isArrayLikeObject.isArrayLikeObject(value)) return [];
45
- if (require_isArrayLikeObject.isArrayLikeObject(lastValue)) result = require_intersectionBy.intersectionBy(result, Array.from(value), require_identity.identity);
46
- else if (typeof lastValue === "function") result = require_intersectionBy.intersectionBy(result, Array.from(value), (value) => lastValue(value));
47
- else if (typeof lastValue === "string") result = require_intersectionBy.intersectionBy(result, Array.from(value), require_property.property(lastValue));
48
+ if (iteratee) result = require_intersectionBy.intersectionBy(result, require_toArray.toArray(value), iteratee);
48
49
  }
49
50
  return result;
50
51
  }
52
+ function getIteratee(value) {
53
+ if (require_isArrayLikeObject.isArrayLikeObject(value)) return require_identity.identity;
54
+ if (typeof value === "function") return (item) => value(item);
55
+ if (typeof value === "string") return require_property.property(value);
56
+ return null;
57
+ }
51
58
  //#endregion
52
59
  exports.intersectionBy = intersectionBy;
@@ -1,7 +1,9 @@
1
1
  import { intersectionBy as intersectionBy$1 } from "../../array/intersectionBy.mjs";
2
2
  import { last } from "../../array/last.mjs";
3
3
  import { uniq } from "../../array/uniq.mjs";
4
+ import { uniqBy } from "../../array/uniqBy.mjs";
4
5
  import { identity } from "../../function/identity.mjs";
6
+ import { toArray } from "../_internal/toArray.mjs";
5
7
  import { property } from "../object/property.mjs";
6
8
  import { isArrayLikeObject } from "../predicate/isArrayLikeObject.mjs";
7
9
  //#region src/compat/array/intersectionBy.ts
@@ -36,17 +38,22 @@ import { isArrayLikeObject } from "../predicate/isArrayLikeObject.mjs";
36
38
  function intersectionBy(array, ...values) {
37
39
  if (!isArrayLikeObject(array)) return [];
38
40
  const lastValue = last(values);
39
- if (lastValue === void 0) return Array.from(array);
40
- let result = uniq(Array.from(array));
41
41
  const count = isArrayLikeObject(lastValue) ? values.length : values.length - 1;
42
+ const iteratee = getIteratee(lastValue);
43
+ if (count <= 0) return uniqBy(toArray(array), iteratee ?? identity);
44
+ let result = uniq(toArray(array));
42
45
  for (let i = 0; i < count; ++i) {
43
46
  const value = values[i];
44
47
  if (!isArrayLikeObject(value)) return [];
45
- if (isArrayLikeObject(lastValue)) result = intersectionBy$1(result, Array.from(value), identity);
46
- else if (typeof lastValue === "function") result = intersectionBy$1(result, Array.from(value), (value) => lastValue(value));
47
- else if (typeof lastValue === "string") result = intersectionBy$1(result, Array.from(value), property(lastValue));
48
+ if (iteratee) result = intersectionBy$1(result, toArray(value), iteratee);
48
49
  }
49
50
  return result;
50
51
  }
52
+ function getIteratee(value) {
53
+ if (isArrayLikeObject(value)) return identity;
54
+ if (typeof value === "function") return (item) => value(item);
55
+ if (typeof value === "string") return property(value);
56
+ return null;
57
+ }
51
58
  //#endregion
52
59
  export { intersectionBy };
@@ -1,6 +1,5 @@
1
1
  const require_intersectionWith = require("../../array/intersectionWith.js");
2
- const require_isEqualsSameValueZero = require("../../_internal/isEqualsSameValueZero.js");
3
- require("../util/eq.js");
2
+ const require_eq = require("../util/eq.js");
4
3
  const require_last = require("./last.js");
5
4
  const require_uniq = require("./uniq.js");
6
5
  //#region src/compat/array/intersectionWith.ts
@@ -21,7 +20,7 @@ const require_uniq = require("./uniq.js");
21
20
  function intersectionWith(firstArr, ...otherArrs) {
22
21
  if (firstArr == null) return [];
23
22
  const _comparator = require_last.last(otherArrs);
24
- let comparator = require_isEqualsSameValueZero.isEqualsSameValueZero;
23
+ let comparator = require_eq.eq;
25
24
  let uniq$1 = require_uniq.uniq;
26
25
  if (typeof _comparator === "function") {
27
26
  comparator = _comparator;
@@ -1,6 +1,5 @@
1
1
  import { intersectionWith as intersectionWith$1 } from "../../array/intersectionWith.mjs";
2
- import { isEqualsSameValueZero } from "../../_internal/isEqualsSameValueZero.mjs";
3
- import "../util/eq.mjs";
2
+ import { eq } from "../util/eq.mjs";
4
3
  import { last } from "./last.mjs";
5
4
  import { uniq } from "./uniq.mjs";
6
5
  //#region src/compat/array/intersectionWith.ts
@@ -21,7 +20,7 @@ import { uniq } from "./uniq.mjs";
21
20
  function intersectionWith(firstArr, ...otherArrs) {
22
21
  if (firstArr == null) return [];
23
22
  const _comparator = last(otherArrs);
24
- let comparator = isEqualsSameValueZero;
23
+ let comparator = eq;
25
24
  let uniq$1 = uniq;
26
25
  if (typeof _comparator === "function") {
27
26
  comparator = _comparator;