es-toolkit 1.17.0-dev.566 → 1.17.0-dev.567
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.
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* @template T
|
|
5
5
|
* @param {T[]} arr - The array to search through.
|
|
6
6
|
* @param {(item: T, index: number, arr: T[]) => unknown} doesMatch - A function that takes an item, its index, and the array, and returns a truthy value if the item matches the criteria.
|
|
7
|
+
* @param {number} [fromIndex=arr.length - 1] - The index to start the search from, defaults to the last index of the array.
|
|
7
8
|
* @returns {number} - The index of the first item that matches the predicate, or `undefined` if no match is found.
|
|
8
9
|
*
|
|
9
10
|
* @example
|
|
@@ -12,13 +13,14 @@
|
|
|
12
13
|
* const result = findLastIndex(items, (item) => item > 3)
|
|
13
14
|
* console.log(result); // 4
|
|
14
15
|
*/
|
|
15
|
-
declare function findLastIndex<T>(arr: readonly T[], doesMatch: (item: T, index: number, arr: readonly T[]) => unknown): number;
|
|
16
|
+
declare function findLastIndex<T>(arr: readonly T[], doesMatch: (item: T, index: number, arr: readonly T[]) => unknown, fromIndex?: number): number;
|
|
16
17
|
/**
|
|
17
18
|
* Finds the index of the first item in an array that matches the given partial object.
|
|
18
19
|
*
|
|
19
20
|
* @template T
|
|
20
21
|
* @param {readonly T[]} arr - The array to search through.
|
|
21
22
|
* @param {Partial<T>} doesMatch - A partial object that specifies the properties to match.
|
|
23
|
+
* @param {number} [fromIndex=arr.length - 1] - The index to start the search from, defaults to the last index of the array.
|
|
22
24
|
* @returns {number} - The index of the first item that matches the partial object, or `undefined` if no match is found.
|
|
23
25
|
*
|
|
24
26
|
* @example
|
|
@@ -27,13 +29,14 @@ declare function findLastIndex<T>(arr: readonly T[], doesMatch: (item: T, index:
|
|
|
27
29
|
* const result = findLastIndex(items, { name: 'Bob' });
|
|
28
30
|
* console.log(result); // 1
|
|
29
31
|
*/
|
|
30
|
-
declare function findLastIndex<T>(arr: readonly T[], doesMatch: Partial<T
|
|
32
|
+
declare function findLastIndex<T>(arr: readonly T[], doesMatch: Partial<T>, fromIndex?: number): number;
|
|
31
33
|
/**
|
|
32
34
|
* Finds the index of the first item in an array that matches a property with a specific value.
|
|
33
35
|
*
|
|
34
36
|
* @template T
|
|
35
37
|
* @param {readonly T[]} arr - The array to search through.
|
|
36
38
|
* @param {[keyof T, unknown]} doesMatchProperty - An array where the first element is the property key and the second element is the value to match.
|
|
39
|
+
* @param {number} [fromIndex=arr.length - 1] - The index to start the search from, defaults to the last index of the array.
|
|
37
40
|
* @returns {number} - The index of the first item that has the specified property value, or `undefined` if no match is found.
|
|
38
41
|
*
|
|
39
42
|
* @example
|
|
@@ -42,13 +45,14 @@ declare function findLastIndex<T>(arr: readonly T[], doesMatch: Partial<T>): num
|
|
|
42
45
|
* const result = findLastIndex(items, ['name', 'Alice']);
|
|
43
46
|
* console.log(result); // 0
|
|
44
47
|
*/
|
|
45
|
-
declare function findLastIndex<T>(arr: readonly T[], doesMatchProperty: [keyof T, unknown]): number;
|
|
48
|
+
declare function findLastIndex<T>(arr: readonly T[], doesMatchProperty: [keyof T, unknown], fromIndex?: number): number;
|
|
46
49
|
/**
|
|
47
50
|
* Finds the index of the first item in an array that has a specific property, where the property name is provided as a string.
|
|
48
51
|
*
|
|
49
52
|
* @template T
|
|
50
53
|
* @param {readonly T[]} arr - The array to search through.
|
|
51
54
|
* @param {string} propertyToCheck - The property name to check.
|
|
55
|
+
* @param {number} [fromIndex=arr.length - 1] - The index to start the search from, defaults to the last index of the array.
|
|
52
56
|
* @returns {number} - The index of the first item that has the specified property, or `undefined` if no match is found.
|
|
53
57
|
*
|
|
54
58
|
* @example
|
|
@@ -57,6 +61,6 @@ declare function findLastIndex<T>(arr: readonly T[], doesMatchProperty: [keyof T
|
|
|
57
61
|
* const result = findLastIndex(items, 'name');
|
|
58
62
|
* console.log(result); // 1
|
|
59
63
|
*/
|
|
60
|
-
declare function findLastIndex<T>(arr: readonly T[], propertyToCheck: string): number;
|
|
64
|
+
declare function findLastIndex<T>(arr: readonly T[], propertyToCheck: string, fromIndex?: number): number;
|
|
61
65
|
|
|
62
66
|
export { findLastIndex };
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* @template T
|
|
5
5
|
* @param {T[]} arr - The array to search through.
|
|
6
6
|
* @param {(item: T, index: number, arr: T[]) => unknown} doesMatch - A function that takes an item, its index, and the array, and returns a truthy value if the item matches the criteria.
|
|
7
|
+
* @param {number} [fromIndex=arr.length - 1] - The index to start the search from, defaults to the last index of the array.
|
|
7
8
|
* @returns {number} - The index of the first item that matches the predicate, or `undefined` if no match is found.
|
|
8
9
|
*
|
|
9
10
|
* @example
|
|
@@ -12,13 +13,14 @@
|
|
|
12
13
|
* const result = findLastIndex(items, (item) => item > 3)
|
|
13
14
|
* console.log(result); // 4
|
|
14
15
|
*/
|
|
15
|
-
declare function findLastIndex<T>(arr: readonly T[], doesMatch: (item: T, index: number, arr: readonly T[]) => unknown): number;
|
|
16
|
+
declare function findLastIndex<T>(arr: readonly T[], doesMatch: (item: T, index: number, arr: readonly T[]) => unknown, fromIndex?: number): number;
|
|
16
17
|
/**
|
|
17
18
|
* Finds the index of the first item in an array that matches the given partial object.
|
|
18
19
|
*
|
|
19
20
|
* @template T
|
|
20
21
|
* @param {readonly T[]} arr - The array to search through.
|
|
21
22
|
* @param {Partial<T>} doesMatch - A partial object that specifies the properties to match.
|
|
23
|
+
* @param {number} [fromIndex=arr.length - 1] - The index to start the search from, defaults to the last index of the array.
|
|
22
24
|
* @returns {number} - The index of the first item that matches the partial object, or `undefined` if no match is found.
|
|
23
25
|
*
|
|
24
26
|
* @example
|
|
@@ -27,13 +29,14 @@ declare function findLastIndex<T>(arr: readonly T[], doesMatch: (item: T, index:
|
|
|
27
29
|
* const result = findLastIndex(items, { name: 'Bob' });
|
|
28
30
|
* console.log(result); // 1
|
|
29
31
|
*/
|
|
30
|
-
declare function findLastIndex<T>(arr: readonly T[], doesMatch: Partial<T
|
|
32
|
+
declare function findLastIndex<T>(arr: readonly T[], doesMatch: Partial<T>, fromIndex?: number): number;
|
|
31
33
|
/**
|
|
32
34
|
* Finds the index of the first item in an array that matches a property with a specific value.
|
|
33
35
|
*
|
|
34
36
|
* @template T
|
|
35
37
|
* @param {readonly T[]} arr - The array to search through.
|
|
36
38
|
* @param {[keyof T, unknown]} doesMatchProperty - An array where the first element is the property key and the second element is the value to match.
|
|
39
|
+
* @param {number} [fromIndex=arr.length - 1] - The index to start the search from, defaults to the last index of the array.
|
|
37
40
|
* @returns {number} - The index of the first item that has the specified property value, or `undefined` if no match is found.
|
|
38
41
|
*
|
|
39
42
|
* @example
|
|
@@ -42,13 +45,14 @@ declare function findLastIndex<T>(arr: readonly T[], doesMatch: Partial<T>): num
|
|
|
42
45
|
* const result = findLastIndex(items, ['name', 'Alice']);
|
|
43
46
|
* console.log(result); // 0
|
|
44
47
|
*/
|
|
45
|
-
declare function findLastIndex<T>(arr: readonly T[], doesMatchProperty: [keyof T, unknown]): number;
|
|
48
|
+
declare function findLastIndex<T>(arr: readonly T[], doesMatchProperty: [keyof T, unknown], fromIndex?: number): number;
|
|
46
49
|
/**
|
|
47
50
|
* Finds the index of the first item in an array that has a specific property, where the property name is provided as a string.
|
|
48
51
|
*
|
|
49
52
|
* @template T
|
|
50
53
|
* @param {readonly T[]} arr - The array to search through.
|
|
51
54
|
* @param {string} propertyToCheck - The property name to check.
|
|
55
|
+
* @param {number} [fromIndex=arr.length - 1] - The index to start the search from, defaults to the last index of the array.
|
|
52
56
|
* @returns {number} - The index of the first item that has the specified property, or `undefined` if no match is found.
|
|
53
57
|
*
|
|
54
58
|
* @example
|
|
@@ -57,6 +61,6 @@ declare function findLastIndex<T>(arr: readonly T[], doesMatchProperty: [keyof T
|
|
|
57
61
|
* const result = findLastIndex(items, 'name');
|
|
58
62
|
* console.log(result); // 1
|
|
59
63
|
*/
|
|
60
|
-
declare function findLastIndex<T>(arr: readonly T[], propertyToCheck: string): number;
|
|
64
|
+
declare function findLastIndex<T>(arr: readonly T[], propertyToCheck: string, fromIndex?: number): number;
|
|
61
65
|
|
|
62
66
|
export { findLastIndex };
|
|
@@ -2,7 +2,14 @@ import { property } from '../object/property.mjs';
|
|
|
2
2
|
import { matches } from '../predicate/matches.mjs';
|
|
3
3
|
import { matchesProperty } from '../predicate/matchesProperty.mjs';
|
|
4
4
|
|
|
5
|
-
function findLastIndex(source, doesMatch) {
|
|
5
|
+
function findLastIndex(source, doesMatch, fromIndex = source.length - 1) {
|
|
6
|
+
if (fromIndex < 0) {
|
|
7
|
+
fromIndex = Math.max(source.length + fromIndex, 0);
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
fromIndex = Math.min(fromIndex, source.length - 1);
|
|
11
|
+
}
|
|
12
|
+
source = source.slice(0, fromIndex + 1);
|
|
6
13
|
switch (typeof doesMatch) {
|
|
7
14
|
case 'function': {
|
|
8
15
|
return source.findLastIndex(doesMatch);
|
package/dist/compat/index.js
CHANGED
|
@@ -397,7 +397,14 @@ function findIndex(source, doesMatch) {
|
|
|
397
397
|
}
|
|
398
398
|
}
|
|
399
399
|
|
|
400
|
-
function findLastIndex(source, doesMatch) {
|
|
400
|
+
function findLastIndex(source, doesMatch, fromIndex = source.length - 1) {
|
|
401
|
+
if (fromIndex < 0) {
|
|
402
|
+
fromIndex = Math.max(source.length + fromIndex, 0);
|
|
403
|
+
}
|
|
404
|
+
else {
|
|
405
|
+
fromIndex = Math.min(fromIndex, source.length - 1);
|
|
406
|
+
}
|
|
407
|
+
source = source.slice(0, fromIndex + 1);
|
|
401
408
|
switch (typeof doesMatch) {
|
|
402
409
|
case 'function': {
|
|
403
410
|
return source.findLastIndex(doesMatch);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "es-toolkit",
|
|
3
3
|
"description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
|
|
4
|
-
"version": "1.17.0-dev.
|
|
4
|
+
"version": "1.17.0-dev.567+5d4b59e8",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|