es-toolkit 1.17.0-dev.566 → 1.17.0-dev.568
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.
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/array/findLastIndex.d.mts +8 -4
- package/dist/compat/array/findLastIndex.d.ts +8 -4
- package/dist/compat/array/findLastIndex.mjs +8 -1
- package/dist/compat/index.d.mts +1 -0
- package/dist/compat/index.d.ts +1 -0
- package/dist/compat/index.js +14 -1
- package/dist/compat/index.mjs +1 -0
- package/dist/compat/predicate/isObject.d.mts +26 -0
- package/dist/compat/predicate/isObject.d.ts +26 -0
- package/dist/compat/predicate/isObject.mjs +6 -0
- package/package.json +1 -1
|
@@ -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.d.mts
CHANGED
|
@@ -142,6 +142,7 @@ export { isArray } from './predicate/isArray.mjs';
|
|
|
142
142
|
export { isArguments } from './predicate/isArguments.mjs';
|
|
143
143
|
export { isArrayLike } from './predicate/isArrayLike.mjs';
|
|
144
144
|
export { isSymbol } from './predicate/isSymbol.mjs';
|
|
145
|
+
export { isObject } from './predicate/isObject.mjs';
|
|
145
146
|
export { isObjectLike } from './predicate/isObjectLike.mjs';
|
|
146
147
|
export { isBoolean } from './predicate/isBoolean.mjs';
|
|
147
148
|
export { isTypedArray } from './predicate/isTypedArray.mjs';
|
package/dist/compat/index.d.ts
CHANGED
|
@@ -142,6 +142,7 @@ export { isArray } from './predicate/isArray.js';
|
|
|
142
142
|
export { isArguments } from './predicate/isArguments.js';
|
|
143
143
|
export { isArrayLike } from './predicate/isArrayLike.js';
|
|
144
144
|
export { isSymbol } from './predicate/isSymbol.js';
|
|
145
|
+
export { isObject } from './predicate/isObject.js';
|
|
145
146
|
export { isObjectLike } from './predicate/isObjectLike.js';
|
|
146
147
|
export { isBoolean } from './predicate/isBoolean.js';
|
|
147
148
|
export { isTypedArray } from './predicate/isTypedArray.js';
|
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);
|
|
@@ -920,6 +927,11 @@ function isArray(value) {
|
|
|
920
927
|
return Array.isArray(value);
|
|
921
928
|
}
|
|
922
929
|
|
|
930
|
+
function isObject(value) {
|
|
931
|
+
const type = typeof value;
|
|
932
|
+
return value !== null && (type === 'object' || type === 'function');
|
|
933
|
+
}
|
|
934
|
+
|
|
923
935
|
function isBoolean(x) {
|
|
924
936
|
if (x === true || x === false) {
|
|
925
937
|
return true;
|
|
@@ -1175,6 +1187,7 @@ exports.isArray = isArray;
|
|
|
1175
1187
|
exports.isArrayLike = isArrayLike;
|
|
1176
1188
|
exports.isBoolean = isBoolean;
|
|
1177
1189
|
exports.isMatch = isMatch;
|
|
1190
|
+
exports.isObject = isObject;
|
|
1178
1191
|
exports.isPlainObject = isPlainObject;
|
|
1179
1192
|
exports.isRegExp = isRegExp;
|
|
1180
1193
|
exports.isString = isString;
|
package/dist/compat/index.mjs
CHANGED
|
@@ -143,6 +143,7 @@ export { isArray } from './predicate/isArray.mjs';
|
|
|
143
143
|
export { isArguments } from './predicate/isArguments.mjs';
|
|
144
144
|
export { isArrayLike } from './predicate/isArrayLike.mjs';
|
|
145
145
|
export { isSymbol } from './predicate/isSymbol.mjs';
|
|
146
|
+
export { isObject } from './predicate/isObject.mjs';
|
|
146
147
|
export { isBoolean } from './predicate/isBoolean.mjs';
|
|
147
148
|
export { isTypedArray } from './predicate/isTypedArray.mjs';
|
|
148
149
|
export { isMatch } from './predicate/isMatch.mjs';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the given value is the language type of Object.
|
|
3
|
+
* https://262.ecma-international.org/7.0/#sec-ecmascript-language-types
|
|
4
|
+
*
|
|
5
|
+
* This function tests whether the provided value is an object or not.
|
|
6
|
+
* It returns `true` if the value is an object, and `false` otherwise.
|
|
7
|
+
*
|
|
8
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to an object value.
|
|
9
|
+
*
|
|
10
|
+
* @param {unknown} value - The value to check if it is an object.
|
|
11
|
+
* @returns {value is object} `true` if the value is the language type of Object, `false` otherwise.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const value1 = {};
|
|
15
|
+
* const value2 = [1, 2, 3];
|
|
16
|
+
* const value3 = () => {};
|
|
17
|
+
* const value4 = null;
|
|
18
|
+
*
|
|
19
|
+
* console.log(isArray(value1)); // true
|
|
20
|
+
* console.log(isArray(value2)); // true
|
|
21
|
+
* console.log(isArray(value3)); // true
|
|
22
|
+
* console.log(isArray(value4)); // false
|
|
23
|
+
*/
|
|
24
|
+
declare function isObject(value: unknown): value is object;
|
|
25
|
+
|
|
26
|
+
export { isObject };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the given value is the language type of Object.
|
|
3
|
+
* https://262.ecma-international.org/7.0/#sec-ecmascript-language-types
|
|
4
|
+
*
|
|
5
|
+
* This function tests whether the provided value is an object or not.
|
|
6
|
+
* It returns `true` if the value is an object, and `false` otherwise.
|
|
7
|
+
*
|
|
8
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to an object value.
|
|
9
|
+
*
|
|
10
|
+
* @param {unknown} value - The value to check if it is an object.
|
|
11
|
+
* @returns {value is object} `true` if the value is the language type of Object, `false` otherwise.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const value1 = {};
|
|
15
|
+
* const value2 = [1, 2, 3];
|
|
16
|
+
* const value3 = () => {};
|
|
17
|
+
* const value4 = null;
|
|
18
|
+
*
|
|
19
|
+
* console.log(isArray(value1)); // true
|
|
20
|
+
* console.log(isArray(value2)); // true
|
|
21
|
+
* console.log(isArray(value3)); // true
|
|
22
|
+
* console.log(isArray(value4)); // false
|
|
23
|
+
*/
|
|
24
|
+
declare function isObject(value: unknown): value is object;
|
|
25
|
+
|
|
26
|
+
export { isObject };
|
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.568+40c9ab92",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|