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
@@ -1,4 +1,6 @@
1
1
  //#region src/compat/_internal/isDeepKey.ts
2
+ /** Matches any deep property path. Examples: `a.b`, `a[0]`, `a["b"]` */
3
+ const regexIsDeepProp = /\.|(\[(?:[^[\]]*|(["'])(?:(?!\2)[^\\]|\\.)*?\2)\])/;
2
4
  /**
3
5
  * Checks if a given key is a deep key.
4
6
  *
@@ -15,12 +17,23 @@
15
17
  * isDeepKey(123) // false
16
18
  * isDeepKey('a.b.c') // true
17
19
  * isDeepKey('a[b][c]') // true
20
+ * isDeepKey('a.') // false
21
+ * isDeepKey('.a') // false
22
+ * isDeepKey('a[b') // false
23
+ * isDeepKey('a]b]') // false
24
+ * isDeepKey('a][b') // false
25
+ * isDeepKey('') // false
26
+ * isDeepKey('a[0]') // true
27
+ *
18
28
  */
19
29
  function isDeepKey(key) {
20
30
  switch (typeof key) {
21
31
  case "number":
22
32
  case "symbol": return false;
23
- case "string": return key.includes(".") || key.includes("[") || key.includes("]");
33
+ case "string":
34
+ if (key === "" || key.startsWith(".") || key.endsWith(".")) return false;
35
+ return regexIsDeepProp.test(key);
36
+ default: return false;
24
37
  }
25
38
  }
26
39
  //#endregion
@@ -1,4 +1,6 @@
1
1
  //#region src/compat/_internal/isDeepKey.ts
2
+ /** Matches any deep property path. Examples: `a.b`, `a[0]`, `a["b"]` */
3
+ const regexIsDeepProp = /\.|(\[(?:[^[\]]*|(["'])(?:(?!\2)[^\\]|\\.)*?\2)\])/;
2
4
  /**
3
5
  * Checks if a given key is a deep key.
4
6
  *
@@ -15,12 +17,23 @@
15
17
  * isDeepKey(123) // false
16
18
  * isDeepKey('a.b.c') // true
17
19
  * isDeepKey('a[b][c]') // true
20
+ * isDeepKey('a.') // false
21
+ * isDeepKey('.a') // false
22
+ * isDeepKey('a[b') // false
23
+ * isDeepKey('a]b]') // false
24
+ * isDeepKey('a][b') // false
25
+ * isDeepKey('') // false
26
+ * isDeepKey('a[0]') // true
27
+ *
18
28
  */
19
29
  function isDeepKey(key) {
20
30
  switch (typeof key) {
21
31
  case "number":
22
32
  case "symbol": return false;
23
- case "string": return key.includes(".") || key.includes("[") || key.includes("]");
33
+ case "string":
34
+ if (key === "" || key.startsWith(".") || key.endsWith(".")) return false;
35
+ return regexIsDeepProp.test(key);
36
+ default: return false;
24
37
  }
25
38
  }
26
39
  //#endregion
@@ -1,12 +1,11 @@
1
- const require_isEqualsSameValueZero = require("../../_internal/isEqualsSameValueZero.js");
2
- require("../util/eq.js");
1
+ const require_eq = require("../util/eq.js");
3
2
  const require_isArrayLike = require("../predicate/isArrayLike.js");
4
3
  const require_isObject = require("../predicate/isObject.js");
5
4
  const require_isIndex = require("./isIndex.js");
6
5
  //#region src/compat/_internal/isIterateeCall.ts
7
6
  function isIterateeCall(value, index, object) {
8
7
  if (!require_isObject.isObject(object)) return false;
9
- if (typeof index === "number" && require_isArrayLike.isArrayLike(object) && require_isIndex.isIndex(index) && index < object.length || typeof index === "string" && index in object) return require_isEqualsSameValueZero.isEqualsSameValueZero(object[index], value);
8
+ if (typeof index === "number" && require_isArrayLike.isArrayLike(object) && require_isIndex.isIndex(index) && index < object.length || typeof index === "string" && index in object) return require_eq.eq(object[index], value);
10
9
  return false;
11
10
  }
12
11
  //#endregion
@@ -1,12 +1,11 @@
1
- import { isEqualsSameValueZero } from "../../_internal/isEqualsSameValueZero.mjs";
2
- import "../util/eq.mjs";
1
+ import { eq } from "../util/eq.mjs";
3
2
  import { isArrayLike } from "../predicate/isArrayLike.mjs";
4
3
  import { isObject } from "../predicate/isObject.mjs";
5
4
  import { isIndex } from "./isIndex.mjs";
6
5
  //#region src/compat/_internal/isIterateeCall.ts
7
6
  function isIterateeCall(value, index, object) {
8
7
  if (!isObject(object)) return false;
9
- if (typeof index === "number" && isArrayLike(object) && isIndex(index) && index < object.length || typeof index === "string" && index in object) return isEqualsSameValueZero(object[index], value);
8
+ if (typeof index === "number" && isArrayLike(object) && isIndex(index) && index < object.length || typeof index === "string" && index in object) return eq(object[index], value);
10
9
  return false;
11
10
  }
12
11
  //#endregion
@@ -0,0 +1,11 @@
1
+ //#region src/compat/_internal/regexMultiByte.ts
2
+ /**
3
+ * Used to compose unicode character classes.
4
+ * @link https://github.com/lodash/lodash/blob/4.17.21-es/_hasUnicode.js
5
+ *
6
+ * Used to detect strings with zero-width joiners or code points from the astral planes.
7
+ * @link http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/
8
+ */
9
+ const regexMultiByte = /* @__PURE__ */ new RegExp("[\\u200d\\ud800-\\udfff\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff\\ufe0e\\ufe0f]");
10
+ //#endregion
11
+ exports.regexMultiByte = regexMultiByte;
@@ -0,0 +1,11 @@
1
+ //#region src/compat/_internal/regexMultiByte.ts
2
+ /**
3
+ * Used to compose unicode character classes.
4
+ * @link https://github.com/lodash/lodash/blob/4.17.21-es/_hasUnicode.js
5
+ *
6
+ * Used to detect strings with zero-width joiners or code points from the astral planes.
7
+ * @link http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/
8
+ */
9
+ const regexMultiByte = /* @__PURE__ */ new RegExp("[\\u200d\\ud800-\\udfff\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff\\ufe0e\\ufe0f]");
10
+ //#endregion
11
+ export { regexMultiByte };
@@ -1,19 +1,16 @@
1
1
  const require_identity = require("../../function/identity.js");
2
2
  const require_isArrayLike = require("../predicate/isArrayLike.js");
3
- const require_property = require("../object/property.js");
4
- const require_matches = require("../predicate/matches.js");
5
- const require_matchesProperty = require("../predicate/matchesProperty.js");
3
+ const require_iteratee = require("../util/iteratee.js");
6
4
  const require_isIterateeCall = require("../_internal/isIterateeCall.js");
5
+ require("../compat.js");
7
6
  //#region src/compat/array/every.ts
8
7
  /**
9
8
  * Checks if every item in an object has a specific property, where the property name is provided as a PropertyKey.
10
9
  *
11
10
  * @template T
12
- * @param object - The object to check through.
13
11
  * @param source - The source array or object to check through.
14
- * @param doesMatch - The criteria to match. It can be a function, a partial object, a key-value pair, or a property name.
15
- * @param propertyToCheck - The property name to check.
16
- * @param guard - Enables use as an iteratee for methods like `_.map`.
12
+ * @param [doesMatch] - The criteria to match. It can be a function, a partial object, a key-value pair, or a property name.
13
+ * @param [guard] - Enables use as an iteratee for methods like `_.map`.
17
14
  * @returns `true` if every property value has the specified property, or `false` if at least one does not match.
18
15
  *
19
16
  * @example
@@ -25,23 +22,7 @@ const require_isIterateeCall = require("../_internal/isIterateeCall.js");
25
22
  function every(source, doesMatch, guard) {
26
23
  if (!source) return true;
27
24
  if (guard && require_isIterateeCall.isIterateeCall(source, doesMatch, guard)) doesMatch = void 0;
28
- if (!doesMatch) doesMatch = require_identity.identity;
29
- let predicate;
30
- switch (typeof doesMatch) {
31
- case "function":
32
- predicate = doesMatch;
33
- break;
34
- case "object":
35
- if (Array.isArray(doesMatch) && doesMatch.length === 2) {
36
- const key = doesMatch[0];
37
- const value = doesMatch[1];
38
- predicate = require_matchesProperty.matchesProperty(key, value);
39
- } else predicate = require_matches.matches(doesMatch);
40
- break;
41
- case "symbol":
42
- case "number":
43
- case "string": predicate = require_property.property(doesMatch);
44
- }
25
+ const predicate = require_iteratee.iteratee(doesMatch ?? require_identity.identity);
45
26
  if (!require_isArrayLike.isArrayLike(source)) {
46
27
  const keys = Object.keys(source);
47
28
  for (let i = 0; i < keys.length; i++) {
@@ -1,19 +1,16 @@
1
1
  import { identity } from "../../function/identity.mjs";
2
2
  import { isArrayLike } from "../predicate/isArrayLike.mjs";
3
- import { property } from "../object/property.mjs";
4
- import { matches } from "../predicate/matches.mjs";
5
- import { matchesProperty } from "../predicate/matchesProperty.mjs";
3
+ import { iteratee } from "../util/iteratee.mjs";
6
4
  import { isIterateeCall } from "../_internal/isIterateeCall.mjs";
5
+ import "../compat.mjs";
7
6
  //#region src/compat/array/every.ts
8
7
  /**
9
8
  * Checks if every item in an object has a specific property, where the property name is provided as a PropertyKey.
10
9
  *
11
10
  * @template T
12
- * @param object - The object to check through.
13
11
  * @param source - The source array or object to check through.
14
- * @param doesMatch - The criteria to match. It can be a function, a partial object, a key-value pair, or a property name.
15
- * @param propertyToCheck - The property name to check.
16
- * @param guard - Enables use as an iteratee for methods like `_.map`.
12
+ * @param [doesMatch] - The criteria to match. It can be a function, a partial object, a key-value pair, or a property name.
13
+ * @param [guard] - Enables use as an iteratee for methods like `_.map`.
17
14
  * @returns `true` if every property value has the specified property, or `false` if at least one does not match.
18
15
  *
19
16
  * @example
@@ -25,23 +22,7 @@ import { isIterateeCall } from "../_internal/isIterateeCall.mjs";
25
22
  function every(source, doesMatch, guard) {
26
23
  if (!source) return true;
27
24
  if (guard && isIterateeCall(source, doesMatch, guard)) doesMatch = void 0;
28
- if (!doesMatch) doesMatch = identity;
29
- let predicate;
30
- switch (typeof doesMatch) {
31
- case "function":
32
- predicate = doesMatch;
33
- break;
34
- case "object":
35
- if (Array.isArray(doesMatch) && doesMatch.length === 2) {
36
- const key = doesMatch[0];
37
- const value = doesMatch[1];
38
- predicate = matchesProperty(key, value);
39
- } else predicate = matches(doesMatch);
40
- break;
41
- case "symbol":
42
- case "number":
43
- case "string": predicate = property(doesMatch);
44
- }
25
+ const predicate = iteratee(doesMatch ?? identity);
45
26
  if (!isArrayLike(source)) {
46
27
  const keys = Object.keys(source);
47
28
  for (let i = 0; i < keys.length; i++) {
@@ -9,7 +9,7 @@ import { ListIteratorTypeGuard } from "../_internal/ListIteratorTypeGuard.mjs";
9
9
  * Filters characters in a string based on the predicate function.
10
10
  *
11
11
  * @param collection - The string to filter
12
- * @param predicate - The function to test each character
12
+ * @param [predicate] - The function to test each character
13
13
  * @returns An array of characters that pass the predicate test
14
14
  *
15
15
  * @example
@@ -20,6 +20,7 @@ declare function filter(collection: string | null | undefined, predicate?: Strin
20
20
  /**
21
21
  * Filters elements in an array-like object using a type guard predicate.
22
22
  *
23
+ * @template T, U
23
24
  * @param collection - The array-like object to filter
24
25
  * @param predicate - The type guard function to test each element
25
26
  * @returns An array of elements that are of type U
@@ -32,8 +33,9 @@ declare function filter<T, U extends T>(collection: ArrayLike<T> | null | undefi
32
33
  /**
33
34
  * Filters elements in an array-like object based on the predicate.
34
35
  *
36
+ * @template T
35
37
  * @param collection - The array-like object to filter
36
- * @param predicate - The function or shorthand to test each element
38
+ * @param [predicate] - The function or shorthand to test each element
37
39
  * @returns An array of elements that pass the predicate test
38
40
  *
39
41
  * @example
@@ -47,6 +49,7 @@ declare function filter<T>(collection: ArrayLike<T> | null | undefined, predicat
47
49
  /**
48
50
  * Filters values in an object using a type guard predicate.
49
51
  *
52
+ * @template T, U
50
53
  * @param collection - The object to filter
51
54
  * @param predicate - The type guard function to test each value
52
55
  * @returns An array of values that are of type U
@@ -59,8 +62,9 @@ declare function filter<T extends object, U extends T[keyof T]>(collection: T |
59
62
  /**
60
63
  * Filters values in an object based on the predicate.
61
64
  *
65
+ * @template T
62
66
  * @param collection - The object to filter
63
- * @param predicate - The function or shorthand to test each value
67
+ * @param [predicate] - The function or shorthand to test each value
64
68
  * @returns An array of values that pass the predicate test
65
69
  *
66
70
  * @example
@@ -9,7 +9,7 @@ import { ListIteratorTypeGuard } from "../_internal/ListIteratorTypeGuard.js";
9
9
  * Filters characters in a string based on the predicate function.
10
10
  *
11
11
  * @param collection - The string to filter
12
- * @param predicate - The function to test each character
12
+ * @param [predicate] - The function to test each character
13
13
  * @returns An array of characters that pass the predicate test
14
14
  *
15
15
  * @example
@@ -20,6 +20,7 @@ declare function filter(collection: string | null | undefined, predicate?: Strin
20
20
  /**
21
21
  * Filters elements in an array-like object using a type guard predicate.
22
22
  *
23
+ * @template T, U
23
24
  * @param collection - The array-like object to filter
24
25
  * @param predicate - The type guard function to test each element
25
26
  * @returns An array of elements that are of type U
@@ -32,8 +33,9 @@ declare function filter<T, U extends T>(collection: ArrayLike<T> | null | undefi
32
33
  /**
33
34
  * Filters elements in an array-like object based on the predicate.
34
35
  *
36
+ * @template T
35
37
  * @param collection - The array-like object to filter
36
- * @param predicate - The function or shorthand to test each element
38
+ * @param [predicate] - The function or shorthand to test each element
37
39
  * @returns An array of elements that pass the predicate test
38
40
  *
39
41
  * @example
@@ -47,6 +49,7 @@ declare function filter<T>(collection: ArrayLike<T> | null | undefined, predicat
47
49
  /**
48
50
  * Filters values in an object using a type guard predicate.
49
51
  *
52
+ * @template T, U
50
53
  * @param collection - The object to filter
51
54
  * @param predicate - The type guard function to test each value
52
55
  * @returns An array of values that are of type U
@@ -59,8 +62,9 @@ declare function filter<T extends object, U extends T[keyof T]>(collection: T |
59
62
  /**
60
63
  * Filters values in an object based on the predicate.
61
64
  *
65
+ * @template T
62
66
  * @param collection - The object to filter
63
- * @param predicate - The function or shorthand to test each value
67
+ * @param [predicate] - The function or shorthand to test each value
64
68
  * @returns An array of values that pass the predicate test
65
69
  *
66
70
  * @example
@@ -7,7 +7,7 @@ const require_iteratee = require("../util/iteratee.js");
7
7
  * If a function is provided, it is invoked for each element in the collection.
8
8
  *
9
9
  * @template T
10
- * @param source - The array or object to iterate over.
10
+ * @param collection - The array or object to iterate over.
11
11
  * @param [predicate=identity] - The function invoked per iteration.
12
12
  * @returns Returns a new array of filtered elements that satisfy the predicate.
13
13
  *
@@ -24,25 +24,25 @@ const require_iteratee = require("../util/iteratee.js");
24
24
  * filter([{ a: 1 }, { a: 2 }, { a: 3 }], ['a', 2]);
25
25
  * // => [{ a: 2 }]
26
26
  */
27
- function filter(source, predicate = require_identity.identity) {
28
- if (!source) return [];
27
+ function filter(collection, predicate = require_identity.identity) {
28
+ if (!collection) return [];
29
29
  predicate = require_iteratee.iteratee(predicate);
30
- if (!Array.isArray(source)) {
30
+ if (!Array.isArray(collection)) {
31
31
  const result = [];
32
- const keys = Object.keys(source);
33
- const length = require_isArrayLike.isArrayLike(source) ? source.length : keys.length;
32
+ const keys = Object.keys(collection);
33
+ const length = require_isArrayLike.isArrayLike(collection) ? collection.length : keys.length;
34
34
  for (let i = 0; i < length; i++) {
35
35
  const key = keys[i];
36
- const value = source[key];
37
- if (predicate(value, key, source)) result.push(value);
36
+ const value = collection[key];
37
+ if (predicate(value, key, collection)) result.push(value);
38
38
  }
39
39
  return result;
40
40
  }
41
41
  const result = [];
42
- const length = source.length;
42
+ const length = collection.length;
43
43
  for (let i = 0; i < length; i++) {
44
- const value = source[i];
45
- if (predicate(value, i, source)) result.push(value);
44
+ const value = collection[i];
45
+ if (predicate(value, i, collection)) result.push(value);
46
46
  }
47
47
  return result;
48
48
  }
@@ -7,7 +7,7 @@ import { iteratee } from "../util/iteratee.mjs";
7
7
  * If a function is provided, it is invoked for each element in the collection.
8
8
  *
9
9
  * @template T
10
- * @param source - The array or object to iterate over.
10
+ * @param collection - The array or object to iterate over.
11
11
  * @param [predicate=identity] - The function invoked per iteration.
12
12
  * @returns Returns a new array of filtered elements that satisfy the predicate.
13
13
  *
@@ -24,25 +24,25 @@ import { iteratee } from "../util/iteratee.mjs";
24
24
  * filter([{ a: 1 }, { a: 2 }, { a: 3 }], ['a', 2]);
25
25
  * // => [{ a: 2 }]
26
26
  */
27
- function filter(source, predicate = identity) {
28
- if (!source) return [];
27
+ function filter(collection, predicate = identity) {
28
+ if (!collection) return [];
29
29
  predicate = iteratee(predicate);
30
- if (!Array.isArray(source)) {
30
+ if (!Array.isArray(collection)) {
31
31
  const result = [];
32
- const keys = Object.keys(source);
33
- const length = isArrayLike(source) ? source.length : keys.length;
32
+ const keys = Object.keys(collection);
33
+ const length = isArrayLike(collection) ? collection.length : keys.length;
34
34
  for (let i = 0; i < length; i++) {
35
35
  const key = keys[i];
36
- const value = source[key];
37
- if (predicate(value, key, source)) result.push(value);
36
+ const value = collection[key];
37
+ if (predicate(value, key, collection)) result.push(value);
38
38
  }
39
39
  return result;
40
40
  }
41
41
  const result = [];
42
- const length = source.length;
42
+ const length = collection.length;
43
43
  for (let i = 0; i < length; i++) {
44
- const value = source[i];
45
- if (predicate(value, i, source)) result.push(value);
44
+ const value = collection[i];
45
+ if (predicate(value, i, collection)) result.push(value);
46
46
  }
47
47
  return result;
48
48
  }
@@ -7,9 +7,10 @@ import { ListIteratorTypeGuard } from "../_internal/ListIteratorTypeGuard.mjs";
7
7
  /**
8
8
  * Finds the first element in an array-like object that matches a type guard predicate.
9
9
  *
10
+ * @template T, U
10
11
  * @param collection - The array-like object to search
11
12
  * @param predicate - The type guard function to test each element
12
- * @param fromIndex - The index to start searching from
13
+ * @param [fromIndex] - The index to start searching from
13
14
  * @returns The first element that matches the type guard, or undefined if none found
14
15
  *
15
16
  * @example
@@ -20,9 +21,10 @@ declare function find<T, U extends T>(collection: ArrayLike<T> | null | undefine
20
21
  /**
21
22
  * Finds the first element in an array-like object that matches a predicate.
22
23
  *
24
+ * @template T
23
25
  * @param collection - The array-like object to search
24
- * @param predicate - The function or shorthand to test each element
25
- * @param fromIndex - The index to start searching from
26
+ * @param [predicate] - The function or shorthand to test each element
27
+ * @param [fromIndex] - The index to start searching from
26
28
  * @returns The first matching element, or undefined if none found
27
29
  *
28
30
  * @example
@@ -36,9 +38,10 @@ declare function find<T>(collection: ArrayLike<T> | null | undefined, predicate?
36
38
  /**
37
39
  * Finds the first value in an object that matches a type guard predicate.
38
40
  *
41
+ * @template T, U
39
42
  * @param collection - The object to search
40
43
  * @param predicate - The type guard function to test each value
41
- * @param fromIndex - The index to start searching from
44
+ * @param [fromIndex] - The index to start searching from
42
45
  * @returns The first value that matches the type guard, or undefined if none found
43
46
  *
44
47
  * @example
@@ -49,9 +52,10 @@ declare function find<T extends object, U extends T[keyof T]>(collection: T | nu
49
52
  /**
50
53
  * Finds the first value in an object that matches a predicate.
51
54
  *
55
+ * @template T
52
56
  * @param collection - The object to search
53
- * @param predicate - The function or shorthand to test each value
54
- * @param fromIndex - The index to start searching from
57
+ * @param [predicate] - The function or shorthand to test each value
58
+ * @param [fromIndex] - The index to start searching from
55
59
  * @returns The first matching value, or undefined if none found
56
60
  *
57
61
  * @example
@@ -7,9 +7,10 @@ import { ListIteratorTypeGuard } from "../_internal/ListIteratorTypeGuard.js";
7
7
  /**
8
8
  * Finds the first element in an array-like object that matches a type guard predicate.
9
9
  *
10
+ * @template T, U
10
11
  * @param collection - The array-like object to search
11
12
  * @param predicate - The type guard function to test each element
12
- * @param fromIndex - The index to start searching from
13
+ * @param [fromIndex] - The index to start searching from
13
14
  * @returns The first element that matches the type guard, or undefined if none found
14
15
  *
15
16
  * @example
@@ -20,9 +21,10 @@ declare function find<T, U extends T>(collection: ArrayLike<T> | null | undefine
20
21
  /**
21
22
  * Finds the first element in an array-like object that matches a predicate.
22
23
  *
24
+ * @template T
23
25
  * @param collection - The array-like object to search
24
- * @param predicate - The function or shorthand to test each element
25
- * @param fromIndex - The index to start searching from
26
+ * @param [predicate] - The function or shorthand to test each element
27
+ * @param [fromIndex] - The index to start searching from
26
28
  * @returns The first matching element, or undefined if none found
27
29
  *
28
30
  * @example
@@ -36,9 +38,10 @@ declare function find<T>(collection: ArrayLike<T> | null | undefined, predicate?
36
38
  /**
37
39
  * Finds the first value in an object that matches a type guard predicate.
38
40
  *
41
+ * @template T, U
39
42
  * @param collection - The object to search
40
43
  * @param predicate - The type guard function to test each value
41
- * @param fromIndex - The index to start searching from
44
+ * @param [fromIndex] - The index to start searching from
42
45
  * @returns The first value that matches the type guard, or undefined if none found
43
46
  *
44
47
  * @example
@@ -49,9 +52,10 @@ declare function find<T extends object, U extends T[keyof T]>(collection: T | nu
49
52
  /**
50
53
  * Finds the first value in an object that matches a predicate.
51
54
  *
55
+ * @template T
52
56
  * @param collection - The object to search
53
- * @param predicate - The function or shorthand to test each value
54
- * @param fromIndex - The index to start searching from
57
+ * @param [predicate] - The function or shorthand to test each value
58
+ * @param [fromIndex] - The index to start searching from
55
59
  * @returns The first matching value, or undefined if none found
56
60
  *
57
61
  * @example
@@ -6,7 +6,7 @@ const require_iteratee = require("../util/iteratee.js");
6
6
  *
7
7
  * @template T
8
8
  * @param source - The source array or object to search through.
9
- * @param doesMatch - The criteria to match. It can be a function, a partial object, a key-value pair, or a property name.
9
+ * @param [doesMatch=identity] - The criteria to match. It can be a function, a partial object, a key-value pair, or a property name.
10
10
  * @param [fromIndex=0] - The index to start the search from, defaults to 0.
11
11
  * @returns The first property value that has the specified property, or `undefined` if no match is found.
12
12
  *
@@ -6,7 +6,7 @@ import { iteratee } from "../util/iteratee.mjs";
6
6
  *
7
7
  * @template T
8
8
  * @param source - The source array or object to search through.
9
- * @param doesMatch - The criteria to match. It can be a function, a partial object, a key-value pair, or a property name.
9
+ * @param [doesMatch=identity] - The criteria to match. It can be a function, a partial object, a key-value pair, or a property name.
10
10
  * @param [fromIndex=0] - The index to start the search from, defaults to 0.
11
11
  * @returns The first property value that has the specified property, or `undefined` if no match is found.
12
12
  *
@@ -7,7 +7,6 @@ import { ListIterateeCustom } from "../_internal/ListIterateeCustom.mjs";
7
7
  * @template T
8
8
  * @param arr - The array to search through.
9
9
  * @param doesMatch - The criteria to match against the items in the array. This can be a function, a partial object, a key-value pair, or a property name.
10
- * @param propertyToCheck - The property name to check for in the items of the array.
11
10
  * @param [fromIndex=0] - The index to start the search from, defaults to 0.
12
11
  * @returns The index of the first item that has the specified property, or `-1` if no match is found.
13
12
  *
@@ -7,7 +7,6 @@ import { ListIterateeCustom } from "../_internal/ListIterateeCustom.js";
7
7
  * @template T
8
8
  * @param arr - The array to search through.
9
9
  * @param doesMatch - The criteria to match against the items in the array. This can be a function, a partial object, a key-value pair, or a property name.
10
- * @param propertyToCheck - The property name to check for in the items of the array.
11
10
  * @param [fromIndex=0] - The index to start the search from, defaults to 0.
12
11
  * @returns The index of the first item that has the specified property, or `-1` if no match is found.
13
12
  *
@@ -1,6 +1,7 @@
1
1
  const require_property = require("../object/property.js");
2
2
  const require_matches = require("../predicate/matches.js");
3
3
  const require_matchesProperty = require("../predicate/matchesProperty.js");
4
+ const require_toInteger = require("../util/toInteger.js");
4
5
  const require_identity = require("../function/identity.js");
5
6
  //#region src/compat/array/findIndex.ts
6
7
  /**
@@ -9,7 +10,6 @@ const require_identity = require("../function/identity.js");
9
10
  * @template T
10
11
  * @param arr - The array to search through.
11
12
  * @param doesMatch - The criteria to match against the items in the array. This can be a function, a partial object, a key-value pair, or a property name.
12
- * @param propertyToCheck - The property name to check for in the items of the array.
13
13
  * @param [fromIndex=0] - The index to start the search from, defaults to 0.
14
14
  * @returns The index of the first item that has the specified property, or `-1` if no match is found.
15
15
  *
@@ -21,6 +21,7 @@ const require_identity = require("../function/identity.js");
21
21
  */
22
22
  function findIndex(arr, doesMatch = require_identity.identity, fromIndex = 0) {
23
23
  if (!arr) return -1;
24
+ fromIndex = require_toInteger.toInteger(fromIndex);
24
25
  if (fromIndex < 0) fromIndex = Math.max(arr.length + fromIndex, 0);
25
26
  const subArray = Array.from(arr).slice(fromIndex);
26
27
  let index = -1;
@@ -1,6 +1,7 @@
1
1
  import { property } from "../object/property.mjs";
2
2
  import { matches } from "../predicate/matches.mjs";
3
3
  import { matchesProperty } from "../predicate/matchesProperty.mjs";
4
+ import { toInteger } from "../util/toInteger.mjs";
4
5
  import { identity } from "../function/identity.mjs";
5
6
  //#region src/compat/array/findIndex.ts
6
7
  /**
@@ -9,7 +10,6 @@ import { identity } from "../function/identity.mjs";
9
10
  * @template T
10
11
  * @param arr - The array to search through.
11
12
  * @param doesMatch - The criteria to match against the items in the array. This can be a function, a partial object, a key-value pair, or a property name.
12
- * @param propertyToCheck - The property name to check for in the items of the array.
13
13
  * @param [fromIndex=0] - The index to start the search from, defaults to 0.
14
14
  * @returns The index of the first item that has the specified property, or `-1` if no match is found.
15
15
  *
@@ -21,6 +21,7 @@ import { identity } from "../function/identity.mjs";
21
21
  */
22
22
  function findIndex(arr, doesMatch = identity, fromIndex = 0) {
23
23
  if (!arr) return -1;
24
+ fromIndex = toInteger(fromIndex);
24
25
  if (fromIndex < 0) fromIndex = Math.max(arr.length + fromIndex, 0);
25
26
  const subArray = Array.from(arr).slice(fromIndex);
26
27
  let index = -1;
@@ -40,7 +40,7 @@ declare function findLast<T, S extends T>(collection: ArrayLike<T> | null | unde
40
40
  * // => { user: 'pebbles', age: 18 }
41
41
  *
42
42
  * findLast(users, 'age');
43
- * // => { user: 'fred', age: 40 }
43
+ * // => { user: 'pebbles', age: 18 }
44
44
  */
45
45
  declare function findLast<T>(collection: ArrayLike<T> | null | undefined, predicate?: ListIterateeCustom<T, boolean>, fromIndex?: number): T | undefined;
46
46
  /**
@@ -40,7 +40,7 @@ declare function findLast<T, S extends T>(collection: ArrayLike<T> | null | unde
40
40
  * // => { user: 'pebbles', age: 18 }
41
41
  *
42
42
  * findLast(users, 'age');
43
- * // => { user: 'fred', age: 40 }
43
+ * // => { user: 'pebbles', age: 18 }
44
44
  */
45
45
  declare function findLast<T>(collection: ArrayLike<T> | null | undefined, predicate?: ListIterateeCustom<T, boolean>, fromIndex?: number): T | undefined;
46
46
  /**