es-toolkit 1.30.1 → 1.31.0-dev.1000
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 +13 -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-BW79-8.js} +37 -71
- package/dist/_chunk/{toMerged-DGFrN7.js → toMerged-BQTfB8.js} +39 -8
- package/dist/_chunk/{unary-CcTNuC.js → unary-c1NFA5.js} +38 -0
- package/dist/_chunk/{zipWith-nbzldx.js → zipWith-Bdyzuy.js} +47 -4
- package/dist/array/groupBy.mjs +2 -2
- package/dist/array/index.d.mts +2 -0
- package/dist/array/index.d.ts +2 -0
- package/dist/array/index.js +3 -1
- package/dist/array/index.mjs +2 -0
- package/dist/array/pull.mjs +9 -2
- package/dist/array/remove.d.mts +19 -0
- package/dist/array/remove.d.ts +19 -0
- package/dist/array/remove.mjs +20 -0
- package/dist/array/windowed.d.mts +50 -0
- package/dist/array/windowed.d.ts +50 -0
- package/dist/array/windowed.mjs +16 -0
- 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/pull.d.mts +1 -1
- package/dist/compat/array/pull.d.ts +1 -1
- package/dist/compat/array/pull.mjs +1 -2
- package/dist/compat/array/pullAll.d.mts +19 -0
- package/dist/compat/array/pullAll.d.ts +19 -0
- package/dist/compat/array/pullAll.mjs +7 -0
- package/dist/compat/array/remove.d.mts +50 -0
- package/dist/compat/array/remove.d.ts +50 -0
- package/dist/compat/array/remove.mjs +8 -0
- package/dist/compat/array/reverse.d.mts +24 -0
- package/dist/compat/array/reverse.d.ts +24 -0
- package/dist/compat/array/reverse.mjs +8 -0
- package/dist/compat/function/negate.d.mts +16 -0
- package/dist/compat/function/negate.d.ts +16 -0
- package/dist/compat/function/negate.mjs +10 -0
- package/dist/compat/index.d.mts +14 -2
- package/dist/compat/index.d.ts +14 -2
- package/dist/compat/index.js +114 -41
- package/dist/compat/index.mjs +14 -2
- 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/compat/math/subtract.d.mts +17 -0
- package/dist/compat/math/subtract.d.ts +17 -0
- package/dist/compat/math/subtract.mjs +5 -0
- package/dist/compat/object/mergeWith.mjs +6 -2
- package/dist/compat/predicate/isBuffer.d.mts +21 -0
- package/dist/compat/predicate/isBuffer.d.ts +21 -0
- package/dist/compat/predicate/isBuffer.mjs +7 -0
- package/dist/compat/predicate/isMatch.mjs +1 -4
- package/dist/compat/util/methodOf.d.mts +22 -0
- package/dist/compat/util/methodOf.d.ts +22 -0
- package/dist/compat/util/methodOf.mjs +9 -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/asyncNoop.d.mts +12 -0
- package/dist/function/asyncNoop.d.ts +12 -0
- package/dist/function/asyncNoop.mjs +3 -0
- package/dist/function/index.d.mts +2 -0
- package/dist/function/index.d.ts +2 -0
- package/dist/function/index.js +3 -1
- package/dist/function/index.mjs +2 -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 +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +21 -11
- package/dist/index.mjs +7 -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 +3 -2
- 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)) {
|
|
@@ -14,6 +14,6 @@
|
|
|
14
14
|
* pull(numbers, [2, 4]);
|
|
15
15
|
* console.log(numbers); // [1, 3, 5]
|
|
16
16
|
*/
|
|
17
|
-
declare function pull<T>(arr: T[], ...valuesToRemove: readonly unknown[]
|
|
17
|
+
declare function pull<T>(arr: T[], ...valuesToRemove: readonly unknown[]): T[];
|
|
18
18
|
|
|
19
19
|
export { pull };
|
|
@@ -14,6 +14,6 @@
|
|
|
14
14
|
* pull(numbers, [2, 4]);
|
|
15
15
|
* console.log(numbers); // [1, 3, 5]
|
|
16
16
|
*/
|
|
17
|
-
declare function pull<T>(arr: T[], ...valuesToRemove: readonly unknown[]
|
|
17
|
+
declare function pull<T>(arr: T[], ...valuesToRemove: readonly unknown[]): T[];
|
|
18
18
|
|
|
19
19
|
export { pull };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes all specified values from an array.
|
|
3
|
+
*
|
|
4
|
+
* This function changes `arr` in place.
|
|
5
|
+
* If you want to remove values without modifying the original array, use `difference`.
|
|
6
|
+
*
|
|
7
|
+
* @template T
|
|
8
|
+
* @param {T[]} arr - The array to modify.
|
|
9
|
+
* @param {ArrayLike<T>} valuesToRemove - The values to remove from the array.
|
|
10
|
+
* @returns {T[]} The modified array with the specified values removed.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const numbers = [1, 2, 3, 4, 5, 2, 4];
|
|
14
|
+
* pullAll(numbers, [2, 4]);
|
|
15
|
+
* console.log(numbers); // [1, 3, 5]
|
|
16
|
+
*/
|
|
17
|
+
declare function pullAll<T>(arr: T[], valuesToRemove?: ArrayLike<T>): T[];
|
|
18
|
+
|
|
19
|
+
export { pullAll };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes all specified values from an array.
|
|
3
|
+
*
|
|
4
|
+
* This function changes `arr` in place.
|
|
5
|
+
* If you want to remove values without modifying the original array, use `difference`.
|
|
6
|
+
*
|
|
7
|
+
* @template T
|
|
8
|
+
* @param {T[]} arr - The array to modify.
|
|
9
|
+
* @param {ArrayLike<T>} valuesToRemove - The values to remove from the array.
|
|
10
|
+
* @returns {T[]} The modified array with the specified values removed.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const numbers = [1, 2, 3, 4, 5, 2, 4];
|
|
14
|
+
* pullAll(numbers, [2, 4]);
|
|
15
|
+
* console.log(numbers); // [1, 3, 5]
|
|
16
|
+
*/
|
|
17
|
+
declare function pullAll<T>(arr: T[], valuesToRemove?: ArrayLike<T>): T[];
|
|
18
|
+
|
|
19
|
+
export { pullAll };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes elements from an array based on a predicate function.
|
|
3
|
+
*
|
|
4
|
+
* @param {ArrayLike<T>} arr - The array to iterate over.
|
|
5
|
+
* @param {(value: T, index: number, arr: ArrayLike<T>) => boolean} shouldRemoveElement - The function invoked per iteration.
|
|
6
|
+
* @returns {T[]} - Returns the modified array with the specified elements removed.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const array = [1, 2, 3];
|
|
10
|
+
* remove(array, value => value % 2 === 0); // => [1, 3]
|
|
11
|
+
*/
|
|
12
|
+
declare function remove<T>(arr: ArrayLike<T>, shouldRemoveElement: (value: T, index: number, arr: ArrayLike<T>) => boolean): T[];
|
|
13
|
+
/**
|
|
14
|
+
* Removes elements from an array based on a partial object match.
|
|
15
|
+
*
|
|
16
|
+
* @param {ArrayLike<T>} arr - The array to iterate over.
|
|
17
|
+
* @param {Partial<T>} shouldRemoveElement - The partial object to match against each element.
|
|
18
|
+
* @returns {T[]} - Returns the modified array with the specified elements removed.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* const objects = [{ a: 1 }, { a: 2 }, { a: 3 }];
|
|
22
|
+
* remove(objects, { a: 1 }); // => [{ a: 2 }, { a: 3 }]
|
|
23
|
+
*/
|
|
24
|
+
declare function remove<T>(arr: ArrayLike<T>, shouldRemoveElement: Partial<T>): T[];
|
|
25
|
+
/**
|
|
26
|
+
* Removes elements from an array based on a property-value pair match.
|
|
27
|
+
*
|
|
28
|
+
* @param {ArrayLike<T>} arr - The array to iterate over.
|
|
29
|
+
* @param {[keyof T, unknown]} shouldRemoveElement - The property-value pair to match against each element.
|
|
30
|
+
* @returns {T[]} - Returns the modified array with the specified elements removed.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* const objects = [{ a: 1 }, { a: 2 }, { a: 3 }];
|
|
34
|
+
* remove(objects, ['a', 1]); // => [{ a: 2 }, { a: 3 }]
|
|
35
|
+
*/
|
|
36
|
+
declare function remove<T>(arr: ArrayLike<T>, shouldRemoveElement: [keyof T, unknown]): T[];
|
|
37
|
+
/**
|
|
38
|
+
* Removes elements from an array based on a property key.
|
|
39
|
+
*
|
|
40
|
+
* @param {ArrayLike<T>} arr - The array to iterate over.
|
|
41
|
+
* @param {keyof T} shouldRemoveElement - The key of the property to match against each element.
|
|
42
|
+
* @returns {T[]} - Returns the modified array with the specified elements removed.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* const objects = [{ a: 0 }, { a: 1 }];
|
|
46
|
+
* remove(objects, 'a'); // => [{ a: 0 }]
|
|
47
|
+
*/
|
|
48
|
+
declare function remove<T, K extends keyof T>(arr: ArrayLike<T>, shouldRemoveElement: K): T[];
|
|
49
|
+
|
|
50
|
+
export { remove };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes elements from an array based on a predicate function.
|
|
3
|
+
*
|
|
4
|
+
* @param {ArrayLike<T>} arr - The array to iterate over.
|
|
5
|
+
* @param {(value: T, index: number, arr: ArrayLike<T>) => boolean} shouldRemoveElement - The function invoked per iteration.
|
|
6
|
+
* @returns {T[]} - Returns the modified array with the specified elements removed.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const array = [1, 2, 3];
|
|
10
|
+
* remove(array, value => value % 2 === 0); // => [1, 3]
|
|
11
|
+
*/
|
|
12
|
+
declare function remove<T>(arr: ArrayLike<T>, shouldRemoveElement: (value: T, index: number, arr: ArrayLike<T>) => boolean): T[];
|
|
13
|
+
/**
|
|
14
|
+
* Removes elements from an array based on a partial object match.
|
|
15
|
+
*
|
|
16
|
+
* @param {ArrayLike<T>} arr - The array to iterate over.
|
|
17
|
+
* @param {Partial<T>} shouldRemoveElement - The partial object to match against each element.
|
|
18
|
+
* @returns {T[]} - Returns the modified array with the specified elements removed.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* const objects = [{ a: 1 }, { a: 2 }, { a: 3 }];
|
|
22
|
+
* remove(objects, { a: 1 }); // => [{ a: 2 }, { a: 3 }]
|
|
23
|
+
*/
|
|
24
|
+
declare function remove<T>(arr: ArrayLike<T>, shouldRemoveElement: Partial<T>): T[];
|
|
25
|
+
/**
|
|
26
|
+
* Removes elements from an array based on a property-value pair match.
|
|
27
|
+
*
|
|
28
|
+
* @param {ArrayLike<T>} arr - The array to iterate over.
|
|
29
|
+
* @param {[keyof T, unknown]} shouldRemoveElement - The property-value pair to match against each element.
|
|
30
|
+
* @returns {T[]} - Returns the modified array with the specified elements removed.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* const objects = [{ a: 1 }, { a: 2 }, { a: 3 }];
|
|
34
|
+
* remove(objects, ['a', 1]); // => [{ a: 2 }, { a: 3 }]
|
|
35
|
+
*/
|
|
36
|
+
declare function remove<T>(arr: ArrayLike<T>, shouldRemoveElement: [keyof T, unknown]): T[];
|
|
37
|
+
/**
|
|
38
|
+
* Removes elements from an array based on a property key.
|
|
39
|
+
*
|
|
40
|
+
* @param {ArrayLike<T>} arr - The array to iterate over.
|
|
41
|
+
* @param {keyof T} shouldRemoveElement - The key of the property to match against each element.
|
|
42
|
+
* @returns {T[]} - Returns the modified array with the specified elements removed.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* const objects = [{ a: 0 }, { a: 1 }];
|
|
46
|
+
* remove(objects, 'a'); // => [{ a: 0 }]
|
|
47
|
+
*/
|
|
48
|
+
declare function remove<T, K extends keyof T>(arr: ArrayLike<T>, shouldRemoveElement: K): T[];
|
|
49
|
+
|
|
50
|
+
export { remove };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reverses the elements of an array in place.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an array and reverses its elements in place, modifying the original array.
|
|
5
|
+
* If the input is `null` or `undefined`, it returns the input as is.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type of elements in the array.
|
|
8
|
+
* @param {T[] | null | undefined} array - The array to reverse. If `null` or `undefined`, the input is returned as is.
|
|
9
|
+
* @returns {T[] | null | undefined} The reversed array, or `null`/`undefined` if the input was `null`/`undefined`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const array = [1, 2, 3, 4, 5];
|
|
13
|
+
* const reversedArray = reverse(array);
|
|
14
|
+
* // reversedArray is [5, 4, 3, 2, 1], and array is also modified to [5, 4, 3, 2, 1].
|
|
15
|
+
*
|
|
16
|
+
* const emptyArray = reverse([]);
|
|
17
|
+
* // emptyArray is [].
|
|
18
|
+
*
|
|
19
|
+
* const nullArray = reverse(null);
|
|
20
|
+
* // nullArray is null.
|
|
21
|
+
*/
|
|
22
|
+
declare function reverse<T>(array: T[] | null | undefined): T[] | null | undefined;
|
|
23
|
+
|
|
24
|
+
export { reverse };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reverses the elements of an array in place.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an array and reverses its elements in place, modifying the original array.
|
|
5
|
+
* If the input is `null` or `undefined`, it returns the input as is.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type of elements in the array.
|
|
8
|
+
* @param {T[] | null | undefined} array - The array to reverse. If `null` or `undefined`, the input is returned as is.
|
|
9
|
+
* @returns {T[] | null | undefined} The reversed array, or `null`/`undefined` if the input was `null`/`undefined`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const array = [1, 2, 3, 4, 5];
|
|
13
|
+
* const reversedArray = reverse(array);
|
|
14
|
+
* // reversedArray is [5, 4, 3, 2, 1], and array is also modified to [5, 4, 3, 2, 1].
|
|
15
|
+
*
|
|
16
|
+
* const emptyArray = reverse([]);
|
|
17
|
+
* // emptyArray is [].
|
|
18
|
+
*
|
|
19
|
+
* const nullArray = reverse(null);
|
|
20
|
+
* // nullArray is null.
|
|
21
|
+
*/
|
|
22
|
+
declare function reverse<T>(array: T[] | null | undefined): T[] | null | undefined;
|
|
23
|
+
|
|
24
|
+
export { reverse };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a function that negates the result of the predicate function.
|
|
3
|
+
*
|
|
4
|
+
* @template F - The type of the function to negate.
|
|
5
|
+
* @param {F} func - The function to negate.
|
|
6
|
+
* @returns {F} The new negated function, which negates the boolean result of `func`.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const array = [1, 2, 3, 4, 5, 6];
|
|
10
|
+
* const isEven = (n: number) => n % 2 === 0;
|
|
11
|
+
* const result = array.filter(negate(isEven));
|
|
12
|
+
* // result will be [1, 3, 5]
|
|
13
|
+
*/
|
|
14
|
+
declare function negate<F extends (...args: any[]) => boolean>(func: F): F;
|
|
15
|
+
|
|
16
|
+
export { negate };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a function that negates the result of the predicate function.
|
|
3
|
+
*
|
|
4
|
+
* @template F - The type of the function to negate.
|
|
5
|
+
* @param {F} func - The function to negate.
|
|
6
|
+
* @returns {F} The new negated function, which negates the boolean result of `func`.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const array = [1, 2, 3, 4, 5, 6];
|
|
10
|
+
* const isEven = (n: number) => n % 2 === 0;
|
|
11
|
+
* const result = array.filter(negate(isEven));
|
|
12
|
+
* // result will be [1, 3, 5]
|
|
13
|
+
*/
|
|
14
|
+
declare function negate<F extends (...args: any[]) => boolean>(func: F): F;
|
|
15
|
+
|
|
16
|
+
export { negate };
|