es-toolkit 1.49.0-dev.1906 → 1.49.0-dev.1907

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.
@@ -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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-toolkit",
3
- "version": "1.49.0-dev.1906+60a8d3ec",
3
+ "version": "1.49.0-dev.1907+3851205e",
4
4
  "description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
5
5
  "homepage": "https://es-toolkit.dev",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",