es-toolkit 1.31.0 → 1.32.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.
- package/CHANGELOG.md +10 -0
- package/dist/_chunk/AbortError-Cg4ZQ1.js +10 -0
- package/dist/_chunk/delay-_VMfFa.js +25 -0
- package/dist/_chunk/isPlainObject-Xaozpc.js +93 -0
- package/dist/_chunk/{isWeakSet-CvIdTA.js → isWeakSet-DoHqUM.js} +42 -71
- package/dist/_chunk/{toMerged-DGFrN7.js → toMerged-BQTfB8.js} +39 -8
- package/dist/_chunk/{unary-B6qG7C.js → unary-c1NFA5.js} +35 -0
- package/dist/array/at.d.mts +1 -1
- package/dist/array/at.d.ts +1 -1
- package/dist/array/pullAt.d.mts +1 -1
- package/dist/array/pullAt.d.ts +1 -1
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/array/find.d.mts +16 -8
- package/dist/compat/array/find.d.ts +16 -8
- package/dist/compat/array/find.mjs +5 -2
- package/dist/compat/array/sortedIndex.d.mts +16 -0
- package/dist/compat/array/sortedIndex.d.ts +16 -0
- package/dist/compat/array/sortedIndex.mjs +30 -0
- package/dist/compat/array/sortedIndexBy.d.mts +19 -0
- package/dist/compat/array/sortedIndexBy.d.ts +19 -0
- package/dist/compat/array/sortedIndexBy.mjs +56 -0
- package/dist/compat/index.d.mts +7 -0
- package/dist/compat/index.d.ts +7 -0
- package/dist/compat/index.js +145 -43
- package/dist/compat/index.mjs +7 -0
- package/dist/compat/math/multiply.d.mts +18 -0
- package/dist/compat/math/multiply.d.ts +18 -0
- package/dist/compat/math/multiply.mjs +21 -0
- package/dist/error/index.d.mts +2 -0
- package/dist/error/index.d.ts +2 -0
- package/dist/error/index.js +15 -0
- package/dist/error/index.mjs +2 -0
- package/dist/function/index.d.mts +1 -0
- package/dist/function/index.d.ts +1 -0
- package/dist/function/index.js +2 -1
- package/dist/function/index.mjs +1 -0
- package/dist/function/retry.d.mts +59 -0
- package/dist/function/retry.d.ts +59 -0
- package/dist/function/retry.mjs +35 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +18 -11
- package/dist/index.mjs +4 -0
- package/dist/object/cloneDeepWith.mjs +34 -1
- package/dist/object/flattenObject.d.mts +10 -2
- package/dist/object/flattenObject.d.ts +10 -2
- package/dist/object/flattenObject.mjs +6 -6
- package/dist/object/index.js +1 -1
- package/dist/predicate/index.d.mts +1 -0
- package/dist/predicate/index.d.ts +1 -0
- package/dist/predicate/index.js +4 -7
- package/dist/predicate/index.mjs +1 -0
- package/dist/predicate/isPromise.d.mts +20 -0
- package/dist/predicate/isPromise.d.ts +20 -0
- package/dist/predicate/isPromise.mjs +5 -0
- package/dist/promise/index.d.mts +2 -0
- package/dist/promise/index.d.ts +2 -0
- package/dist/promise/index.js +56 -4
- package/dist/promise/index.mjs +2 -0
- package/dist/promise/mutex.d.mts +64 -0
- package/dist/promise/mutex.d.ts +64 -0
- package/dist/promise/mutex.mjs +16 -0
- package/dist/promise/semaphore.d.mts +81 -0
- package/dist/promise/semaphore.d.ts +81 -0
- package/dist/promise/semaphore.mjs +30 -0
- package/error.d.ts +1 -0
- package/package.json +42 -21
- package/dist/_chunk/index-BGZDR9.js +0 -50
- package/dist/_chunk/isPlainObject-octpoD.js +0 -32
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* @template T
|
|
5
5
|
* @param {ArrayLike<T> | null | undefined} 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=0] - The index to start the search from, defaults to 0.
|
|
7
8
|
* @returns {T | undefined} - 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 = find(items, (item) => item > 3);
|
|
13
14
|
* console.log(result); // 4
|
|
14
15
|
*/
|
|
15
|
-
declare function find<T>(arr: ArrayLike<T> | null | undefined, doesMatch: (item: T, index: number, arr: readonly T[]) => unknown): T | undefined;
|
|
16
|
+
declare function find<T>(arr: ArrayLike<T> | null | undefined, doesMatch: (item: T, index: number, arr: readonly T[]) => unknown, fromIndex?: number): T | undefined;
|
|
16
17
|
/**
|
|
17
18
|
* Finds the first item in an array that matches the given partial object.
|
|
18
19
|
*
|
|
19
20
|
* @template T
|
|
20
21
|
* @param {ArrayLike<T> | null | undefined} 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=0] - The index to start the search from, defaults to 0.
|
|
22
24
|
* @returns {T | undefined} - 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 find<T>(arr: ArrayLike<T> | null | undefined, doesMatch: (item:
|
|
|
27
29
|
* const result = find(items, { name: 'Bob' });
|
|
28
30
|
* console.log(result); // { id: 2, name: 'Bob' }
|
|
29
31
|
*/
|
|
30
|
-
declare function find<T>(arr: ArrayLike<T> | null | undefined, doesMatch: Partial<T
|
|
32
|
+
declare function find<T>(arr: ArrayLike<T> | null | undefined, doesMatch: Partial<T>, fromIndex?: number): T | undefined;
|
|
31
33
|
/**
|
|
32
34
|
* Finds the first item in an array that matches a property with a specific value.
|
|
33
35
|
*
|
|
34
36
|
* @template T
|
|
35
37
|
* @param {ArrayLike<T> | null | undefined} 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=0] - The index to start the search from, defaults to 0.
|
|
37
40
|
* @returns {T | undefined} - 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 find<T>(arr: ArrayLike<T> | null | undefined, doesMatch: Partia
|
|
|
42
45
|
* const result = find(items, ['name', 'Alice']);
|
|
43
46
|
* console.log(result); // { id: 1, name: 'Alice' }
|
|
44
47
|
*/
|
|
45
|
-
declare function find<T>(arr: ArrayLike<T> | null | undefined, doesMatchProperty: [keyof T, unknown]): T | undefined;
|
|
48
|
+
declare function find<T>(arr: ArrayLike<T> | null | undefined, doesMatchProperty: [keyof T, unknown], fromIndex?: number): T | undefined;
|
|
46
49
|
/**
|
|
47
50
|
* Finds the first item in an array that has a specific property, where the property name is provided as a PropertyKey.
|
|
48
51
|
*
|
|
49
52
|
* @template T
|
|
50
53
|
* @param {ArrayLike<T> | null | undefined} arr - The array to search through.
|
|
51
54
|
* @param {PropertyKey} propertyToCheck - The property name to check.
|
|
55
|
+
* @param {number} [fromIndex=0] - The index to start the search from, defaults to 0.
|
|
52
56
|
* @returns {T | undefined} - The first item that has the specified property, or `undefined` if no match is found.
|
|
53
57
|
*
|
|
54
58
|
* @example
|
|
@@ -57,13 +61,14 @@ declare function find<T>(arr: ArrayLike<T> | null | undefined, doesMatchProperty
|
|
|
57
61
|
* const result = find(items, 'name');
|
|
58
62
|
* console.log(result); // { id: 1, name: 'Alice' }
|
|
59
63
|
*/
|
|
60
|
-
declare function find<T>(arr: ArrayLike<T> | null | undefined, propertyToCheck: PropertyKey): T | undefined;
|
|
64
|
+
declare function find<T>(arr: ArrayLike<T> | null | undefined, propertyToCheck: PropertyKey, fromIndex?: number): T | undefined;
|
|
61
65
|
/**
|
|
62
66
|
* Finds the first item in an object that matches the given predicate function.
|
|
63
67
|
*
|
|
64
68
|
* @template T
|
|
65
69
|
* @param {T | null | undefined} object - The object to search through.
|
|
66
70
|
* @param {(item: T[keyof T], index: number, arr: T) => unknown} doesMatch - A function that takes an item, its key, and the object, and returns a truthy value if the item matches the criteria.
|
|
71
|
+
* @param {number} [fromIndex=0] - The index to start the search from, defaults to 0.
|
|
67
72
|
* @returns {T | undefined} - The first property value that matches the predicate, or `undefined` if no match is found.
|
|
68
73
|
*
|
|
69
74
|
* @example
|
|
@@ -72,13 +77,14 @@ declare function find<T>(arr: ArrayLike<T> | null | undefined, propertyToCheck:
|
|
|
72
77
|
* const result = find(obj, (item) => item > 2);
|
|
73
78
|
* console.log(result); // 3
|
|
74
79
|
*/
|
|
75
|
-
declare function find<T extends Record<string, unknown>>(object: T | null | undefined, doesMatch: (item: T[keyof T], index: keyof T, object: T) => unknown): T | undefined;
|
|
80
|
+
declare function find<T extends Record<string, unknown>>(object: T | null | undefined, doesMatch: (item: T[keyof T], index: keyof T, object: T) => unknown, fromIndex?: number): T | undefined;
|
|
76
81
|
/**
|
|
77
82
|
* Finds the first item in an object that matches the given partial value.
|
|
78
83
|
*
|
|
79
84
|
* @template T
|
|
80
85
|
* @param {T | null | undefined} object - The object to search through.
|
|
81
86
|
* @param {Partial<T[keyof T]>} doesMatch - A partial value to match against the values of the object.
|
|
87
|
+
* @param {number} [fromIndex=0] - The index to start the search from, defaults to 0.
|
|
82
88
|
* @returns {T | undefined} - The first property value that matches the partial value, or `undefined` if no match is found.
|
|
83
89
|
*
|
|
84
90
|
* @example
|
|
@@ -87,13 +93,14 @@ declare function find<T extends Record<string, unknown>>(object: T | null | unde
|
|
|
87
93
|
* const result = find(obj, { name: 'Bob' });
|
|
88
94
|
* console.log(result); // { id: 2, name: 'Bob' }
|
|
89
95
|
*/
|
|
90
|
-
declare function find<T extends Record<string, unknown>>(object: T | null | undefined, doesMatch: Partial<T[keyof T]
|
|
96
|
+
declare function find<T extends Record<string, unknown>>(object: T | null | undefined, doesMatch: Partial<T[keyof T]>, fromIndex?: number): T | undefined;
|
|
91
97
|
/**
|
|
92
98
|
* Finds the first item in an object that matches a property with a specific value.
|
|
93
99
|
*
|
|
94
100
|
* @template T
|
|
95
101
|
* @param {T | null | undefined} object - The object to search through.
|
|
96
102
|
* @param {[keyof T[keyof T], unknown]} doesMatchProperty - An array where the first element is the property key and the second element is the value to match.
|
|
103
|
+
* @param {number} [fromIndex=0] - The index to start the search from, defaults to 0.
|
|
97
104
|
* @returns {T | undefined} - The first item that has the specified property value, or `undefined` if no match is found.
|
|
98
105
|
*
|
|
99
106
|
* @example
|
|
@@ -102,13 +109,14 @@ declare function find<T extends Record<string, unknown>>(object: T | null | unde
|
|
|
102
109
|
* const result = find(items, ['name', 'Alice']);
|
|
103
110
|
* console.log(result); // { id: 1, name: 'Alice' }
|
|
104
111
|
*/
|
|
105
|
-
declare function find<T extends Record<string, unknown>>(object: T | null | undefined, doesMatchProperty: [keyof T[keyof T], unknown]): T | undefined;
|
|
112
|
+
declare function find<T extends Record<string, unknown>>(object: T | null | undefined, doesMatchProperty: [keyof T[keyof T], unknown], fromIndex?: number): T | undefined;
|
|
106
113
|
/**
|
|
107
114
|
* Finds the first item in an object that has a specific property, where the property name is provided as a PropertyKey.
|
|
108
115
|
*
|
|
109
116
|
* @template T
|
|
110
117
|
* @param {T | null | undefined} object - The object to search through.
|
|
111
118
|
* @param {PropertyKey} propertyToCheck - The property name to check.
|
|
119
|
+
* @param {number} [fromIndex=0] - The index to start the search from, defaults to 0.
|
|
112
120
|
* @returns {T | undefined} - The first property value that has the specified property, or `undefined` if no match is found.
|
|
113
121
|
*
|
|
114
122
|
* @example
|
|
@@ -117,6 +125,6 @@ declare function find<T extends Record<string, unknown>>(object: T | null | unde
|
|
|
117
125
|
* const result = find(obj, 'name');
|
|
118
126
|
* console.log(result); // { id: 1, name: 'Alice' }
|
|
119
127
|
*/
|
|
120
|
-
declare function find<T extends Record<string, unknown>>(object: T | null | undefined, propertyToCheck: PropertyKey): T | undefined;
|
|
128
|
+
declare function find<T extends Record<string, unknown>>(object: T | null | undefined, propertyToCheck: PropertyKey, fromIndex?: number): T | undefined;
|
|
121
129
|
|
|
122
130
|
export { find };
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* @template T
|
|
5
5
|
* @param {ArrayLike<T> | null | undefined} 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=0] - The index to start the search from, defaults to 0.
|
|
7
8
|
* @returns {T | undefined} - 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 = find(items, (item) => item > 3);
|
|
13
14
|
* console.log(result); // 4
|
|
14
15
|
*/
|
|
15
|
-
declare function find<T>(arr: ArrayLike<T> | null | undefined, doesMatch: (item: T, index: number, arr: readonly T[]) => unknown): T | undefined;
|
|
16
|
+
declare function find<T>(arr: ArrayLike<T> | null | undefined, doesMatch: (item: T, index: number, arr: readonly T[]) => unknown, fromIndex?: number): T | undefined;
|
|
16
17
|
/**
|
|
17
18
|
* Finds the first item in an array that matches the given partial object.
|
|
18
19
|
*
|
|
19
20
|
* @template T
|
|
20
21
|
* @param {ArrayLike<T> | null | undefined} 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=0] - The index to start the search from, defaults to 0.
|
|
22
24
|
* @returns {T | undefined} - 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 find<T>(arr: ArrayLike<T> | null | undefined, doesMatch: (item:
|
|
|
27
29
|
* const result = find(items, { name: 'Bob' });
|
|
28
30
|
* console.log(result); // { id: 2, name: 'Bob' }
|
|
29
31
|
*/
|
|
30
|
-
declare function find<T>(arr: ArrayLike<T> | null | undefined, doesMatch: Partial<T
|
|
32
|
+
declare function find<T>(arr: ArrayLike<T> | null | undefined, doesMatch: Partial<T>, fromIndex?: number): T | undefined;
|
|
31
33
|
/**
|
|
32
34
|
* Finds the first item in an array that matches a property with a specific value.
|
|
33
35
|
*
|
|
34
36
|
* @template T
|
|
35
37
|
* @param {ArrayLike<T> | null | undefined} 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=0] - The index to start the search from, defaults to 0.
|
|
37
40
|
* @returns {T | undefined} - 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 find<T>(arr: ArrayLike<T> | null | undefined, doesMatch: Partia
|
|
|
42
45
|
* const result = find(items, ['name', 'Alice']);
|
|
43
46
|
* console.log(result); // { id: 1, name: 'Alice' }
|
|
44
47
|
*/
|
|
45
|
-
declare function find<T>(arr: ArrayLike<T> | null | undefined, doesMatchProperty: [keyof T, unknown]): T | undefined;
|
|
48
|
+
declare function find<T>(arr: ArrayLike<T> | null | undefined, doesMatchProperty: [keyof T, unknown], fromIndex?: number): T | undefined;
|
|
46
49
|
/**
|
|
47
50
|
* Finds the first item in an array that has a specific property, where the property name is provided as a PropertyKey.
|
|
48
51
|
*
|
|
49
52
|
* @template T
|
|
50
53
|
* @param {ArrayLike<T> | null | undefined} arr - The array to search through.
|
|
51
54
|
* @param {PropertyKey} propertyToCheck - The property name to check.
|
|
55
|
+
* @param {number} [fromIndex=0] - The index to start the search from, defaults to 0.
|
|
52
56
|
* @returns {T | undefined} - The first item that has the specified property, or `undefined` if no match is found.
|
|
53
57
|
*
|
|
54
58
|
* @example
|
|
@@ -57,13 +61,14 @@ declare function find<T>(arr: ArrayLike<T> | null | undefined, doesMatchProperty
|
|
|
57
61
|
* const result = find(items, 'name');
|
|
58
62
|
* console.log(result); // { id: 1, name: 'Alice' }
|
|
59
63
|
*/
|
|
60
|
-
declare function find<T>(arr: ArrayLike<T> | null | undefined, propertyToCheck: PropertyKey): T | undefined;
|
|
64
|
+
declare function find<T>(arr: ArrayLike<T> | null | undefined, propertyToCheck: PropertyKey, fromIndex?: number): T | undefined;
|
|
61
65
|
/**
|
|
62
66
|
* Finds the first item in an object that matches the given predicate function.
|
|
63
67
|
*
|
|
64
68
|
* @template T
|
|
65
69
|
* @param {T | null | undefined} object - The object to search through.
|
|
66
70
|
* @param {(item: T[keyof T], index: number, arr: T) => unknown} doesMatch - A function that takes an item, its key, and the object, and returns a truthy value if the item matches the criteria.
|
|
71
|
+
* @param {number} [fromIndex=0] - The index to start the search from, defaults to 0.
|
|
67
72
|
* @returns {T | undefined} - The first property value that matches the predicate, or `undefined` if no match is found.
|
|
68
73
|
*
|
|
69
74
|
* @example
|
|
@@ -72,13 +77,14 @@ declare function find<T>(arr: ArrayLike<T> | null | undefined, propertyToCheck:
|
|
|
72
77
|
* const result = find(obj, (item) => item > 2);
|
|
73
78
|
* console.log(result); // 3
|
|
74
79
|
*/
|
|
75
|
-
declare function find<T extends Record<string, unknown>>(object: T | null | undefined, doesMatch: (item: T[keyof T], index: keyof T, object: T) => unknown): T | undefined;
|
|
80
|
+
declare function find<T extends Record<string, unknown>>(object: T | null | undefined, doesMatch: (item: T[keyof T], index: keyof T, object: T) => unknown, fromIndex?: number): T | undefined;
|
|
76
81
|
/**
|
|
77
82
|
* Finds the first item in an object that matches the given partial value.
|
|
78
83
|
*
|
|
79
84
|
* @template T
|
|
80
85
|
* @param {T | null | undefined} object - The object to search through.
|
|
81
86
|
* @param {Partial<T[keyof T]>} doesMatch - A partial value to match against the values of the object.
|
|
87
|
+
* @param {number} [fromIndex=0] - The index to start the search from, defaults to 0.
|
|
82
88
|
* @returns {T | undefined} - The first property value that matches the partial value, or `undefined` if no match is found.
|
|
83
89
|
*
|
|
84
90
|
* @example
|
|
@@ -87,13 +93,14 @@ declare function find<T extends Record<string, unknown>>(object: T | null | unde
|
|
|
87
93
|
* const result = find(obj, { name: 'Bob' });
|
|
88
94
|
* console.log(result); // { id: 2, name: 'Bob' }
|
|
89
95
|
*/
|
|
90
|
-
declare function find<T extends Record<string, unknown>>(object: T | null | undefined, doesMatch: Partial<T[keyof T]
|
|
96
|
+
declare function find<T extends Record<string, unknown>>(object: T | null | undefined, doesMatch: Partial<T[keyof T]>, fromIndex?: number): T | undefined;
|
|
91
97
|
/**
|
|
92
98
|
* Finds the first item in an object that matches a property with a specific value.
|
|
93
99
|
*
|
|
94
100
|
* @template T
|
|
95
101
|
* @param {T | null | undefined} object - The object to search through.
|
|
96
102
|
* @param {[keyof T[keyof T], unknown]} doesMatchProperty - An array where the first element is the property key and the second element is the value to match.
|
|
103
|
+
* @param {number} [fromIndex=0] - The index to start the search from, defaults to 0.
|
|
97
104
|
* @returns {T | undefined} - The first item that has the specified property value, or `undefined` if no match is found.
|
|
98
105
|
*
|
|
99
106
|
* @example
|
|
@@ -102,13 +109,14 @@ declare function find<T extends Record<string, unknown>>(object: T | null | unde
|
|
|
102
109
|
* const result = find(items, ['name', 'Alice']);
|
|
103
110
|
* console.log(result); // { id: 1, name: 'Alice' }
|
|
104
111
|
*/
|
|
105
|
-
declare function find<T extends Record<string, unknown>>(object: T | null | undefined, doesMatchProperty: [keyof T[keyof T], unknown]): T | undefined;
|
|
112
|
+
declare function find<T extends Record<string, unknown>>(object: T | null | undefined, doesMatchProperty: [keyof T[keyof T], unknown], fromIndex?: number): T | undefined;
|
|
106
113
|
/**
|
|
107
114
|
* Finds the first item in an object that has a specific property, where the property name is provided as a PropertyKey.
|
|
108
115
|
*
|
|
109
116
|
* @template T
|
|
110
117
|
* @param {T | null | undefined} object - The object to search through.
|
|
111
118
|
* @param {PropertyKey} propertyToCheck - The property name to check.
|
|
119
|
+
* @param {number} [fromIndex=0] - The index to start the search from, defaults to 0.
|
|
112
120
|
* @returns {T | undefined} - The first property value that has the specified property, or `undefined` if no match is found.
|
|
113
121
|
*
|
|
114
122
|
* @example
|
|
@@ -117,6 +125,6 @@ declare function find<T extends Record<string, unknown>>(object: T | null | unde
|
|
|
117
125
|
* const result = find(obj, 'name');
|
|
118
126
|
* console.log(result); // { id: 1, name: 'Alice' }
|
|
119
127
|
*/
|
|
120
|
-
declare function find<T extends Record<string, unknown>>(object: T | null | undefined, propertyToCheck: PropertyKey): T | undefined;
|
|
128
|
+
declare function find<T extends Record<string, unknown>>(object: T | null | undefined, propertyToCheck: PropertyKey, fromIndex?: number): T | undefined;
|
|
121
129
|
|
|
122
130
|
export { find };
|
|
@@ -2,11 +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 find(source, doesMatch) {
|
|
5
|
+
function find(source, doesMatch, fromIndex = 0) {
|
|
6
6
|
if (!source) {
|
|
7
7
|
return undefined;
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
if (fromIndex < 0) {
|
|
10
|
+
fromIndex = Math.max(source.length + fromIndex, 0);
|
|
11
|
+
}
|
|
12
|
+
const values = Array.isArray(source) ? source.slice(fromIndex) : Object.values(source).slice(fromIndex);
|
|
10
13
|
switch (typeof doesMatch) {
|
|
11
14
|
case 'function': {
|
|
12
15
|
if (!Array.isArray(source)) {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Uses a binary search to determine the lowest index at which `value`
|
|
3
|
+
* should be inserted into `array` in order to maintain its sort order.
|
|
4
|
+
*
|
|
5
|
+
* @category Array
|
|
6
|
+
* @param {ArrayLike<T> | null | undefined} array The sorted array to inspect.
|
|
7
|
+
* @param {T} value The value to evaluate.
|
|
8
|
+
* @returns {number} Returns the index at which `value` should be inserted
|
|
9
|
+
* into `array`.
|
|
10
|
+
* @example
|
|
11
|
+
* sortedIndex([30, 50], 40)
|
|
12
|
+
* // => 1
|
|
13
|
+
*/
|
|
14
|
+
declare function sortedIndex<T>(array: ArrayLike<T> | null | undefined, value: T): number;
|
|
15
|
+
|
|
16
|
+
export { sortedIndex };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Uses a binary search to determine the lowest index at which `value`
|
|
3
|
+
* should be inserted into `array` in order to maintain its sort order.
|
|
4
|
+
*
|
|
5
|
+
* @category Array
|
|
6
|
+
* @param {ArrayLike<T> | null | undefined} array The sorted array to inspect.
|
|
7
|
+
* @param {T} value The value to evaluate.
|
|
8
|
+
* @returns {number} Returns the index at which `value` should be inserted
|
|
9
|
+
* into `array`.
|
|
10
|
+
* @example
|
|
11
|
+
* sortedIndex([30, 50], 40)
|
|
12
|
+
* // => 1
|
|
13
|
+
*/
|
|
14
|
+
declare function sortedIndex<T>(array: ArrayLike<T> | null | undefined, value: T): number;
|
|
15
|
+
|
|
16
|
+
export { sortedIndex };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { sortedIndexBy } from './sortedIndexBy.mjs';
|
|
2
|
+
import { isNil } from '../../predicate/isNil.mjs';
|
|
3
|
+
import { isNull } from '../../predicate/isNull.mjs';
|
|
4
|
+
import { isSymbol } from '../../predicate/isSymbol.mjs';
|
|
5
|
+
import { isNumber } from '../predicate/isNumber.mjs';
|
|
6
|
+
|
|
7
|
+
const MAX_ARRAY_LENGTH = 4294967295;
|
|
8
|
+
const HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
|
|
9
|
+
function sortedIndex(array, value) {
|
|
10
|
+
if (isNil(array)) {
|
|
11
|
+
return 0;
|
|
12
|
+
}
|
|
13
|
+
let low = 0, high = isNil(array) ? low : array.length;
|
|
14
|
+
if (isNumber(value) && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
|
|
15
|
+
while (low < high) {
|
|
16
|
+
const mid = (low + high) >>> 1;
|
|
17
|
+
const compute = array[mid];
|
|
18
|
+
if (!isNull(compute) && !isSymbol(compute) && compute < value) {
|
|
19
|
+
low = mid + 1;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
high = mid;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return high;
|
|
26
|
+
}
|
|
27
|
+
return sortedIndexBy(array, value, value => value);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { sortedIndex };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type Iteratee<T, R> = (value: T) => R;
|
|
2
|
+
/**
|
|
3
|
+
* This method is like `sortedIndex` except that it accepts `iteratee`
|
|
4
|
+
* which is invoked for `value` and each element of `array` to compute their
|
|
5
|
+
* sort ranking. The iteratee is invoked with one argument: (value).
|
|
6
|
+
*
|
|
7
|
+
* @param {ArrayLike<T> | null | undefined} array The sorted array to inspect.
|
|
8
|
+
* @param {T} value The value to evaluate.
|
|
9
|
+
* @param {(value: T) => R} iteratee The iteratee invoked per element.
|
|
10
|
+
* @returns {number} Returns the index at which `value` should be inserted
|
|
11
|
+
* into `array`.
|
|
12
|
+
* @example
|
|
13
|
+
* const objects = [{ 'n': 4 }, { 'n': 5 }]
|
|
14
|
+
* sortedIndexBy(objects, { 'n': 4 }, ({ n }) => n)
|
|
15
|
+
* // => 0
|
|
16
|
+
*/
|
|
17
|
+
declare function sortedIndexBy<T, R>(array: ArrayLike<T> | null | undefined, value: T, iteratee?: Iteratee<T, R>, retHighest?: boolean): number;
|
|
18
|
+
|
|
19
|
+
export { sortedIndexBy };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type Iteratee<T, R> = (value: T) => R;
|
|
2
|
+
/**
|
|
3
|
+
* This method is like `sortedIndex` except that it accepts `iteratee`
|
|
4
|
+
* which is invoked for `value` and each element of `array` to compute their
|
|
5
|
+
* sort ranking. The iteratee is invoked with one argument: (value).
|
|
6
|
+
*
|
|
7
|
+
* @param {ArrayLike<T> | null | undefined} array The sorted array to inspect.
|
|
8
|
+
* @param {T} value The value to evaluate.
|
|
9
|
+
* @param {(value: T) => R} iteratee The iteratee invoked per element.
|
|
10
|
+
* @returns {number} Returns the index at which `value` should be inserted
|
|
11
|
+
* into `array`.
|
|
12
|
+
* @example
|
|
13
|
+
* const objects = [{ 'n': 4 }, { 'n': 5 }]
|
|
14
|
+
* sortedIndexBy(objects, { 'n': 4 }, ({ n }) => n)
|
|
15
|
+
* // => 0
|
|
16
|
+
*/
|
|
17
|
+
declare function sortedIndexBy<T, R>(array: ArrayLike<T> | null | undefined, value: T, iteratee?: Iteratee<T, R>, retHighest?: boolean): number;
|
|
18
|
+
|
|
19
|
+
export { sortedIndexBy };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { isNull } from '../../predicate/isNull.mjs';
|
|
2
|
+
import { isUndefined } from '../../predicate/isUndefined.mjs';
|
|
3
|
+
import { isNaN } from '../predicate/isNaN.mjs';
|
|
4
|
+
import { isNil } from '../predicate/isNil.mjs';
|
|
5
|
+
import { isSymbol } from '../predicate/isSymbol.mjs';
|
|
6
|
+
|
|
7
|
+
const MAX_ARRAY_LENGTH = 4294967295;
|
|
8
|
+
const MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1;
|
|
9
|
+
function sortedIndexBy(array, value, iteratee, retHighest) {
|
|
10
|
+
let low = 0;
|
|
11
|
+
let high = array == null ? 0 : array.length;
|
|
12
|
+
if (high === 0 || isNil(array)) {
|
|
13
|
+
return 0;
|
|
14
|
+
}
|
|
15
|
+
const transformedValue = iteratee?.(value);
|
|
16
|
+
const valIsNaN = isNaN(transformedValue);
|
|
17
|
+
const valIsNull = isNull(transformedValue);
|
|
18
|
+
const valIsSymbol = isSymbol(transformedValue);
|
|
19
|
+
const valIsUndefined = isUndefined(transformedValue);
|
|
20
|
+
while (low < high) {
|
|
21
|
+
let setLow;
|
|
22
|
+
const mid = Math.floor((low + high) / 2);
|
|
23
|
+
const computed = iteratee?.(array[mid]);
|
|
24
|
+
const othIsDefined = !isUndefined(computed);
|
|
25
|
+
const othIsNull = isNull(computed);
|
|
26
|
+
const othIsReflexive = !isNaN(computed);
|
|
27
|
+
const othIsSymbol = isSymbol(computed);
|
|
28
|
+
if (valIsNaN) {
|
|
29
|
+
setLow = retHighest || othIsReflexive;
|
|
30
|
+
}
|
|
31
|
+
else if (valIsUndefined) {
|
|
32
|
+
setLow = othIsReflexive && (retHighest || othIsDefined);
|
|
33
|
+
}
|
|
34
|
+
else if (valIsNull) {
|
|
35
|
+
setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
|
|
36
|
+
}
|
|
37
|
+
else if (valIsSymbol) {
|
|
38
|
+
setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
|
|
39
|
+
}
|
|
40
|
+
else if (othIsNull || othIsSymbol) {
|
|
41
|
+
setLow = false;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
setLow = retHighest ? computed <= transformedValue : computed < transformedValue;
|
|
45
|
+
}
|
|
46
|
+
if (setLow) {
|
|
47
|
+
low = mid + 1;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
high = mid;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return Math.min(high, MAX_ARRAY_INDEX);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export { sortedIndexBy };
|
package/dist/compat/index.d.mts
CHANGED
|
@@ -36,6 +36,7 @@ export { noop } from '../function/noop.mjs';
|
|
|
36
36
|
export { once } from '../function/once.mjs';
|
|
37
37
|
export { partial } from '../function/partial.mjs';
|
|
38
38
|
export { partialRight } from '../function/partialRight.mjs';
|
|
39
|
+
export { retry } from '../function/retry.mjs';
|
|
39
40
|
export { ThrottledFunction } from '../function/throttle.mjs';
|
|
40
41
|
export { unary } from '../function/unary.mjs';
|
|
41
42
|
export { mean } from '../math/mean.mjs';
|
|
@@ -58,7 +59,10 @@ export { isLength } from '../predicate/isLength.mjs';
|
|
|
58
59
|
export { isNotNil } from '../predicate/isNotNil.mjs';
|
|
59
60
|
export { isNull } from '../predicate/isNull.mjs';
|
|
60
61
|
export { isPrimitive } from '../predicate/isPrimitive.mjs';
|
|
62
|
+
export { isPromise } from '../predicate/isPromise.mjs';
|
|
61
63
|
export { isUndefined } from '../predicate/isUndefined.mjs';
|
|
64
|
+
export { Mutex } from '../promise/mutex.mjs';
|
|
65
|
+
export { Semaphore } from '../promise/semaphore.mjs';
|
|
62
66
|
export { timeout } from '../promise/timeout.mjs';
|
|
63
67
|
export { withTimeout } from '../promise/withTimeout.mjs';
|
|
64
68
|
export { capitalize } from '../string/capitalize.mjs';
|
|
@@ -106,6 +110,8 @@ export { size } from './array/size.mjs';
|
|
|
106
110
|
export { slice } from './array/slice.mjs';
|
|
107
111
|
export { some } from './array/some.mjs';
|
|
108
112
|
export { sortBy } from './array/sortBy.mjs';
|
|
113
|
+
export { sortedIndex } from './array/sortedIndex.mjs';
|
|
114
|
+
export { sortedIndexBy } from './array/sortedIndexBy.mjs';
|
|
109
115
|
export { tail } from './array/tail.mjs';
|
|
110
116
|
export { take } from './array/take.mjs';
|
|
111
117
|
export { takeRight } from './array/takeRight.mjs';
|
|
@@ -144,6 +150,7 @@ export { floor } from './math/floor.mjs';
|
|
|
144
150
|
export { inRange } from './math/inRange.mjs';
|
|
145
151
|
export { max } from './math/max.mjs';
|
|
146
152
|
export { min } from './math/min.mjs';
|
|
153
|
+
export { multiply } from './math/multiply.mjs';
|
|
147
154
|
export { parseInt } from './math/parseInt.mjs';
|
|
148
155
|
export { random } from './math/random.mjs';
|
|
149
156
|
export { range } from './math/range.mjs';
|
package/dist/compat/index.d.ts
CHANGED
|
@@ -36,6 +36,7 @@ export { noop } from '../function/noop.js';
|
|
|
36
36
|
export { once } from '../function/once.js';
|
|
37
37
|
export { partial } from '../function/partial.js';
|
|
38
38
|
export { partialRight } from '../function/partialRight.js';
|
|
39
|
+
export { retry } from '../function/retry.js';
|
|
39
40
|
export { ThrottledFunction } from '../function/throttle.js';
|
|
40
41
|
export { unary } from '../function/unary.js';
|
|
41
42
|
export { mean } from '../math/mean.js';
|
|
@@ -58,7 +59,10 @@ export { isLength } from '../predicate/isLength.js';
|
|
|
58
59
|
export { isNotNil } from '../predicate/isNotNil.js';
|
|
59
60
|
export { isNull } from '../predicate/isNull.js';
|
|
60
61
|
export { isPrimitive } from '../predicate/isPrimitive.js';
|
|
62
|
+
export { isPromise } from '../predicate/isPromise.js';
|
|
61
63
|
export { isUndefined } from '../predicate/isUndefined.js';
|
|
64
|
+
export { Mutex } from '../promise/mutex.js';
|
|
65
|
+
export { Semaphore } from '../promise/semaphore.js';
|
|
62
66
|
export { timeout } from '../promise/timeout.js';
|
|
63
67
|
export { withTimeout } from '../promise/withTimeout.js';
|
|
64
68
|
export { capitalize } from '../string/capitalize.js';
|
|
@@ -106,6 +110,8 @@ export { size } from './array/size.js';
|
|
|
106
110
|
export { slice } from './array/slice.js';
|
|
107
111
|
export { some } from './array/some.js';
|
|
108
112
|
export { sortBy } from './array/sortBy.js';
|
|
113
|
+
export { sortedIndex } from './array/sortedIndex.js';
|
|
114
|
+
export { sortedIndexBy } from './array/sortedIndexBy.js';
|
|
109
115
|
export { tail } from './array/tail.js';
|
|
110
116
|
export { take } from './array/take.js';
|
|
111
117
|
export { takeRight } from './array/takeRight.js';
|
|
@@ -144,6 +150,7 @@ export { floor } from './math/floor.js';
|
|
|
144
150
|
export { inRange } from './math/inRange.js';
|
|
145
151
|
export { max } from './math/max.js';
|
|
146
152
|
export { min } from './math/min.js';
|
|
153
|
+
export { multiply } from './math/multiply.js';
|
|
147
154
|
export { parseInt } from './math/parseInt.js';
|
|
148
155
|
export { random } from './math/random.js';
|
|
149
156
|
export { range } from './math/range.js';
|