es-toolkit 1.33.0 → 1.34.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/invariant-BfGFfr.js +21 -0
- package/dist/_chunk/{isWeakSet-TIM260.js → isWeakSet-CQZSI-.js} +10 -0
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/_internal/assignValue.mjs +10 -0
- package/dist/compat/_internal/isKey.mjs +1 -1
- package/dist/compat/_internal/toKey.mjs +4 -1
- package/dist/compat/array/filter.mjs +14 -31
- package/dist/compat/array/intersectionWith.mjs +0 -1
- package/dist/compat/array/map.d.mts +1 -1
- package/dist/compat/array/map.d.ts +1 -1
- package/dist/compat/array/reject.d.mts +117 -0
- package/dist/compat/array/reject.d.ts +117 -0
- package/dist/compat/array/reject.mjs +9 -0
- package/dist/compat/array/sortedIndexOf.d.mts +34 -0
- package/dist/compat/array/sortedIndexOf.d.ts +34 -0
- package/dist/compat/array/sortedIndexOf.mjs +15 -0
- package/dist/compat/index.d.mts +9 -3
- package/dist/compat/index.d.ts +9 -3
- package/dist/compat/index.js +176 -93
- package/dist/compat/index.mjs +9 -3
- package/dist/compat/math/add.mjs +17 -0
- package/dist/compat/math/divide.mjs +0 -1
- package/dist/compat/math/mean.d.mts +16 -0
- package/dist/compat/math/mean.d.ts +16 -0
- package/dist/compat/math/mean.mjs +8 -0
- package/dist/compat/math/meanBy.d.mts +25 -0
- package/dist/compat/math/meanBy.d.ts +25 -0
- package/dist/compat/math/meanBy.mjs +11 -0
- package/dist/compat/math/minBy.d.mts +31 -0
- package/dist/compat/math/minBy.d.ts +31 -0
- package/dist/compat/math/minBy.mjs +11 -0
- package/dist/compat/math/subtract.mjs +17 -0
- package/dist/compat/object/functionsIn.d.mts +20 -0
- package/dist/compat/object/functionsIn.d.ts +20 -0
- package/dist/compat/object/functionsIn.mjs +16 -0
- package/dist/compat/object/set.mjs +21 -8
- package/dist/compat/util/invoke.mjs +1 -1
- package/dist/compat/util/stubObject.d.mts +1 -1
- package/dist/compat/util/stubObject.d.ts +1 -1
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +7 -2
- package/dist/index.mjs +4 -0
- package/dist/predicate/index.d.mts +2 -0
- package/dist/predicate/index.d.ts +2 -0
- package/dist/predicate/index.js +3 -1
- package/dist/predicate/index.mjs +2 -0
- package/dist/predicate/isBrowser.d.mts +17 -0
- package/dist/predicate/isBrowser.d.ts +17 -0
- package/dist/predicate/isBrowser.mjs +5 -0
- package/dist/predicate/isNode.d.mts +17 -0
- package/dist/predicate/isNode.d.ts +17 -0
- package/dist/predicate/isNode.mjs +5 -0
- package/dist/util/attempt.d.mts +42 -0
- package/dist/util/attempt.d.ts +42 -0
- package/dist/util/attempt.mjs +10 -0
- package/dist/util/attemptAsync.d.mts +35 -0
- package/dist/util/attemptAsync.d.ts +35 -0
- package/dist/util/attemptAsync.mjs +11 -0
- package/dist/util/index.d.mts +2 -0
- package/dist/util/index.d.ts +2 -0
- package/dist/util/index.js +11 -5
- package/dist/util/index.mjs +2 -0
- package/package.json +7 -5
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { eq } from '../util/eq.mjs';
|
|
2
|
+
|
|
3
|
+
const assignValue = (object, key, value) => {
|
|
4
|
+
const objValue = object[key];
|
|
5
|
+
if (!(Object.hasOwn(object, key) && eq(objValue, value)) || (value === undefined && !(key in object))) {
|
|
6
|
+
object[key] = value;
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export { assignValue };
|
|
@@ -10,7 +10,7 @@ function isKey(value, object) {
|
|
|
10
10
|
return true;
|
|
11
11
|
}
|
|
12
12
|
return ((typeof value === 'string' && (regexIsPlainProp.test(value) || !regexIsDeepProp.test(value))) ||
|
|
13
|
-
(object != null));
|
|
13
|
+
(object != null && Object.hasOwn(object, value)));
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export { isKey };
|
|
@@ -1,44 +1,27 @@
|
|
|
1
|
-
import { identity } from '../../function/identity.mjs';
|
|
2
|
-
import { property } from '../object/property.mjs';
|
|
3
1
|
import { isArray } from '../predicate/isArray.mjs';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
3
|
+
import { iteratee } from '../util/iteratee.mjs';
|
|
6
4
|
|
|
7
5
|
function filter(source, predicate) {
|
|
8
6
|
if (!source) {
|
|
9
7
|
return [];
|
|
10
8
|
}
|
|
11
|
-
if (!predicate) {
|
|
12
|
-
predicate = identity;
|
|
13
|
-
}
|
|
14
9
|
const collection = isArray(source) ? source : Object.values(source);
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return result;
|
|
10
|
+
predicate = iteratee(predicate);
|
|
11
|
+
if (!Array.isArray(source)) {
|
|
12
|
+
const result = [];
|
|
13
|
+
const keys = Object.keys(source);
|
|
14
|
+
const length = isArrayLike(source) ? source.length : keys.length;
|
|
15
|
+
for (let i = 0; i < length; i++) {
|
|
16
|
+
const key = keys[i];
|
|
17
|
+
const value = source[key];
|
|
18
|
+
if (predicate(value, key, source)) {
|
|
19
|
+
result.push(value);
|
|
28
20
|
}
|
|
29
|
-
return collection.filter(predicate);
|
|
30
|
-
}
|
|
31
|
-
case 'object': {
|
|
32
|
-
return isArray(predicate)
|
|
33
|
-
? collection.filter(matchesProperty(predicate[0], predicate[1]))
|
|
34
|
-
: collection.filter(matches(predicate));
|
|
35
|
-
}
|
|
36
|
-
case 'symbol':
|
|
37
|
-
case 'number':
|
|
38
|
-
case 'string': {
|
|
39
|
-
return collection.filter(property(predicate));
|
|
40
21
|
}
|
|
22
|
+
return result;
|
|
41
23
|
}
|
|
24
|
+
return collection.filter(predicate);
|
|
42
25
|
}
|
|
43
26
|
|
|
44
27
|
export { filter };
|
|
@@ -117,7 +117,7 @@ declare function map<T, K extends keyof T>(collection: ArrayLike<T>, iteratee: K
|
|
|
117
117
|
* const arrayLike = {0: 1, 1: 2, 2: 3, length: 3};
|
|
118
118
|
* map(arrayLike); // => {0: 1, 1: 2, 2: 3, length: 3}
|
|
119
119
|
*/
|
|
120
|
-
declare function map<T
|
|
120
|
+
declare function map<T>(collection: ArrayLike<T>, iteratee?: null | undefined): ArrayLike<T>;
|
|
121
121
|
/**
|
|
122
122
|
* Maps each value in an object to a new array of values using an iteratee function.
|
|
123
123
|
*
|
|
@@ -117,7 +117,7 @@ declare function map<T, K extends keyof T>(collection: ArrayLike<T>, iteratee: K
|
|
|
117
117
|
* const arrayLike = {0: 1, 1: 2, 2: 3, length: 3};
|
|
118
118
|
* map(arrayLike); // => {0: 1, 1: 2, 2: 3, length: 3}
|
|
119
119
|
*/
|
|
120
|
-
declare function map<T
|
|
120
|
+
declare function map<T>(collection: ArrayLike<T>, iteratee?: null | undefined): ArrayLike<T>;
|
|
121
121
|
/**
|
|
122
122
|
* Maps each value in an object to a new array of values using an iteratee function.
|
|
123
123
|
*
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rejects items from a array and returns an array of elements.
|
|
3
|
+
*
|
|
4
|
+
* @template T
|
|
5
|
+
* @param {ArrayLike<T> | null | undefined} arr - The array to iterate over.
|
|
6
|
+
* @param {(item: T, index: number, arr: T[]) => unknown} doesMatch - The function invoked per iteration.
|
|
7
|
+
* @returns {T[]} - Returns a new array of elements that do not satisfy the given doesMatch function.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* reject([1, 2, 3], n => n % 2 === 0)
|
|
11
|
+
* // => [1, 3]
|
|
12
|
+
*/
|
|
13
|
+
declare function reject<T>(arr: ArrayLike<T> | null | undefined, doesMatch?: (item: T, index: number, arr: readonly T[]) => unknown): T[];
|
|
14
|
+
/**
|
|
15
|
+
* Rejects elements in a arr that match the properties of the given partial object.
|
|
16
|
+
*
|
|
17
|
+
* @template T
|
|
18
|
+
* @param {ArrayLike<T> | null | undefined} arr - The array to iterate over.
|
|
19
|
+
* @param {Partial<T>} doesMatch - A partial object that specifies the properties to match.
|
|
20
|
+
* @returns {T[]} - Returns a new array of elements that do not match the given properties.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* const arr = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
|
|
24
|
+
* reject(arr, { name: 'Bob' });
|
|
25
|
+
* // => [{ id: 1, name: 'Alice' }]
|
|
26
|
+
*/
|
|
27
|
+
declare function reject<T>(arr: ArrayLike<T> | null | undefined, doesMatch: Partial<T>): T[];
|
|
28
|
+
/**
|
|
29
|
+
* Rejects elements in a arr that match the given key-value pair.
|
|
30
|
+
*
|
|
31
|
+
* @template T
|
|
32
|
+
* @param {ArrayLike<T> | null | undefined} arr - The array to iterate over.
|
|
33
|
+
* @param {[keyof T, unknown]} doesMatchProperty - The key-value pair to match.
|
|
34
|
+
* @returns {T[]} - Returns a new array of elements that do not match the given key-value pair.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* const arr = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
|
|
38
|
+
* reject(arr, ['name', 'Alice']);
|
|
39
|
+
* // => [{ id: 2, name: 'Bob' }]
|
|
40
|
+
*/
|
|
41
|
+
declare function reject<T>(arr: ArrayLike<T> | null | undefined, doesMatchProperty: [keyof T, unknown]): T[];
|
|
42
|
+
/**
|
|
43
|
+
* Rejects the arr, returning elements that do not contain the given property name.
|
|
44
|
+
*
|
|
45
|
+
* @template T
|
|
46
|
+
* @param {ArrayLike<T> | null | undefined} arr - The array to iterate over.
|
|
47
|
+
* @param {PropertyKey} propertyToCheck - The property name to check.
|
|
48
|
+
* @returns {T[]} - Returns a new array of elements that do not have the given property name.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* const arr = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }, { id: 3, age: 28 }];
|
|
52
|
+
* reject(arr, 'name');
|
|
53
|
+
* // => [{ id: 3, age: 28 }]
|
|
54
|
+
*/
|
|
55
|
+
declare function reject<T>(arr: ArrayLike<T> | null | undefined, propertyToCheck: PropertyKey): T[];
|
|
56
|
+
/**
|
|
57
|
+
* Rejects items from a object and returns an array of elements that match the given predicate function.
|
|
58
|
+
*
|
|
59
|
+
* @template T
|
|
60
|
+
* @param {T | null | undefined} object - The object to iterate over.
|
|
61
|
+
* @param {(value: T[keyof T], key: keyof T, object: T) => unknown} doesMatch - The function invoked per iteration.
|
|
62
|
+
* @returns {T[]} - Returns a new array of elements that do not satisfy the given predicate function.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* const obj = { item1: { a: 0 }, item2: { a: 1 }, item3: { a: 0 } }
|
|
66
|
+
* reject(obj, value => value.a)
|
|
67
|
+
* // => [{ a: 0 }, { a: 0 }]
|
|
68
|
+
*
|
|
69
|
+
* const obj = { a: 1, b: 2, c: 3 };
|
|
70
|
+
* reject(obj, value => value > 2)
|
|
71
|
+
* // => [1, 2]
|
|
72
|
+
*/
|
|
73
|
+
declare function reject<T extends Record<string, unknown>>(object: T | null | undefined, doesMatch: (value: T[keyof T], key: keyof T, object: T) => unknown): T[];
|
|
74
|
+
/**
|
|
75
|
+
* Rejects elements in a object that match the properties of the given partial object.
|
|
76
|
+
*
|
|
77
|
+
* @template T
|
|
78
|
+
* @param {T | null | undefined} object - The object to iterate over.
|
|
79
|
+
* @param {Partial<T[keyof T]>} doesMatch - The partial object to match
|
|
80
|
+
* @returns {T[]} - Returns a new array of elements that do not match the given properties.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* const obj = { a: { id: 1, name: 'Alice' }, b: { id: 2, name: 'Bob' } };
|
|
84
|
+
* reject(obj, { name: 'Bob' });
|
|
85
|
+
* // => [{ id: 1, name: 'Alice' }]
|
|
86
|
+
*/
|
|
87
|
+
declare function reject<T extends Record<string, unknown>>(object: T | null | undefined, doesMatch: Partial<T[keyof T]>): T[];
|
|
88
|
+
/**
|
|
89
|
+
* Rejects elements in a arr that match the given key-value pair.
|
|
90
|
+
*
|
|
91
|
+
* @template T
|
|
92
|
+
* @param {T | null | undefined} object - The object to iterate over.
|
|
93
|
+
* @param {[keyof T[keyof T], unknown]} doesMatchProperty - The key-value pair to match.
|
|
94
|
+
* @returns {T[]} - Returns a new array of elements that do not match the given key-value pair.
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* const obj = { alice: { id: 1, name: 'Alice' }, bob: { id: 2, name: 'Bob' } };
|
|
98
|
+
* reject(obj, ['name', 'Alice']);
|
|
99
|
+
* // => [{ id: 2, name: 'Bob' }]
|
|
100
|
+
*/
|
|
101
|
+
declare function reject<T extends Record<string, unknown>>(object: T | null | undefined, doesMatchProperty: [keyof T[keyof T], unknown]): T[];
|
|
102
|
+
/**
|
|
103
|
+
* Rejects the object, returning elements that do not contain the given property name.
|
|
104
|
+
*
|
|
105
|
+
* @template T
|
|
106
|
+
* @param {T | null | undefined} object - The object to iterate over.
|
|
107
|
+
* @param {PropertyKey} propertyToCheck - The property name to check.
|
|
108
|
+
* @returns {T[]} - Returns a new array of elements that do not have the given property name.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* const obj = { a: { id: 1, name: 'Alice' }, b: { id: 2, name: 'Bob' }, c: { id: 3, age: 28 } };
|
|
112
|
+
* reject(obj, 'name');
|
|
113
|
+
* // => [{ id: 3, age: 28 }]
|
|
114
|
+
*/
|
|
115
|
+
declare function reject<T extends Record<string, unknown>>(object: T | null | undefined, propertyToCheck: PropertyKey): T[];
|
|
116
|
+
|
|
117
|
+
export { reject };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rejects items from a array and returns an array of elements.
|
|
3
|
+
*
|
|
4
|
+
* @template T
|
|
5
|
+
* @param {ArrayLike<T> | null | undefined} arr - The array to iterate over.
|
|
6
|
+
* @param {(item: T, index: number, arr: T[]) => unknown} doesMatch - The function invoked per iteration.
|
|
7
|
+
* @returns {T[]} - Returns a new array of elements that do not satisfy the given doesMatch function.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* reject([1, 2, 3], n => n % 2 === 0)
|
|
11
|
+
* // => [1, 3]
|
|
12
|
+
*/
|
|
13
|
+
declare function reject<T>(arr: ArrayLike<T> | null | undefined, doesMatch?: (item: T, index: number, arr: readonly T[]) => unknown): T[];
|
|
14
|
+
/**
|
|
15
|
+
* Rejects elements in a arr that match the properties of the given partial object.
|
|
16
|
+
*
|
|
17
|
+
* @template T
|
|
18
|
+
* @param {ArrayLike<T> | null | undefined} arr - The array to iterate over.
|
|
19
|
+
* @param {Partial<T>} doesMatch - A partial object that specifies the properties to match.
|
|
20
|
+
* @returns {T[]} - Returns a new array of elements that do not match the given properties.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* const arr = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
|
|
24
|
+
* reject(arr, { name: 'Bob' });
|
|
25
|
+
* // => [{ id: 1, name: 'Alice' }]
|
|
26
|
+
*/
|
|
27
|
+
declare function reject<T>(arr: ArrayLike<T> | null | undefined, doesMatch: Partial<T>): T[];
|
|
28
|
+
/**
|
|
29
|
+
* Rejects elements in a arr that match the given key-value pair.
|
|
30
|
+
*
|
|
31
|
+
* @template T
|
|
32
|
+
* @param {ArrayLike<T> | null | undefined} arr - The array to iterate over.
|
|
33
|
+
* @param {[keyof T, unknown]} doesMatchProperty - The key-value pair to match.
|
|
34
|
+
* @returns {T[]} - Returns a new array of elements that do not match the given key-value pair.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* const arr = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
|
|
38
|
+
* reject(arr, ['name', 'Alice']);
|
|
39
|
+
* // => [{ id: 2, name: 'Bob' }]
|
|
40
|
+
*/
|
|
41
|
+
declare function reject<T>(arr: ArrayLike<T> | null | undefined, doesMatchProperty: [keyof T, unknown]): T[];
|
|
42
|
+
/**
|
|
43
|
+
* Rejects the arr, returning elements that do not contain the given property name.
|
|
44
|
+
*
|
|
45
|
+
* @template T
|
|
46
|
+
* @param {ArrayLike<T> | null | undefined} arr - The array to iterate over.
|
|
47
|
+
* @param {PropertyKey} propertyToCheck - The property name to check.
|
|
48
|
+
* @returns {T[]} - Returns a new array of elements that do not have the given property name.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* const arr = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }, { id: 3, age: 28 }];
|
|
52
|
+
* reject(arr, 'name');
|
|
53
|
+
* // => [{ id: 3, age: 28 }]
|
|
54
|
+
*/
|
|
55
|
+
declare function reject<T>(arr: ArrayLike<T> | null | undefined, propertyToCheck: PropertyKey): T[];
|
|
56
|
+
/**
|
|
57
|
+
* Rejects items from a object and returns an array of elements that match the given predicate function.
|
|
58
|
+
*
|
|
59
|
+
* @template T
|
|
60
|
+
* @param {T | null | undefined} object - The object to iterate over.
|
|
61
|
+
* @param {(value: T[keyof T], key: keyof T, object: T) => unknown} doesMatch - The function invoked per iteration.
|
|
62
|
+
* @returns {T[]} - Returns a new array of elements that do not satisfy the given predicate function.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* const obj = { item1: { a: 0 }, item2: { a: 1 }, item3: { a: 0 } }
|
|
66
|
+
* reject(obj, value => value.a)
|
|
67
|
+
* // => [{ a: 0 }, { a: 0 }]
|
|
68
|
+
*
|
|
69
|
+
* const obj = { a: 1, b: 2, c: 3 };
|
|
70
|
+
* reject(obj, value => value > 2)
|
|
71
|
+
* // => [1, 2]
|
|
72
|
+
*/
|
|
73
|
+
declare function reject<T extends Record<string, unknown>>(object: T | null | undefined, doesMatch: (value: T[keyof T], key: keyof T, object: T) => unknown): T[];
|
|
74
|
+
/**
|
|
75
|
+
* Rejects elements in a object that match the properties of the given partial object.
|
|
76
|
+
*
|
|
77
|
+
* @template T
|
|
78
|
+
* @param {T | null | undefined} object - The object to iterate over.
|
|
79
|
+
* @param {Partial<T[keyof T]>} doesMatch - The partial object to match
|
|
80
|
+
* @returns {T[]} - Returns a new array of elements that do not match the given properties.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* const obj = { a: { id: 1, name: 'Alice' }, b: { id: 2, name: 'Bob' } };
|
|
84
|
+
* reject(obj, { name: 'Bob' });
|
|
85
|
+
* // => [{ id: 1, name: 'Alice' }]
|
|
86
|
+
*/
|
|
87
|
+
declare function reject<T extends Record<string, unknown>>(object: T | null | undefined, doesMatch: Partial<T[keyof T]>): T[];
|
|
88
|
+
/**
|
|
89
|
+
* Rejects elements in a arr that match the given key-value pair.
|
|
90
|
+
*
|
|
91
|
+
* @template T
|
|
92
|
+
* @param {T | null | undefined} object - The object to iterate over.
|
|
93
|
+
* @param {[keyof T[keyof T], unknown]} doesMatchProperty - The key-value pair to match.
|
|
94
|
+
* @returns {T[]} - Returns a new array of elements that do not match the given key-value pair.
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* const obj = { alice: { id: 1, name: 'Alice' }, bob: { id: 2, name: 'Bob' } };
|
|
98
|
+
* reject(obj, ['name', 'Alice']);
|
|
99
|
+
* // => [{ id: 2, name: 'Bob' }]
|
|
100
|
+
*/
|
|
101
|
+
declare function reject<T extends Record<string, unknown>>(object: T | null | undefined, doesMatchProperty: [keyof T[keyof T], unknown]): T[];
|
|
102
|
+
/**
|
|
103
|
+
* Rejects the object, returning elements that do not contain the given property name.
|
|
104
|
+
*
|
|
105
|
+
* @template T
|
|
106
|
+
* @param {T | null | undefined} object - The object to iterate over.
|
|
107
|
+
* @param {PropertyKey} propertyToCheck - The property name to check.
|
|
108
|
+
* @returns {T[]} - Returns a new array of elements that do not have the given property name.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* const obj = { a: { id: 1, name: 'Alice' }, b: { id: 2, name: 'Bob' }, c: { id: 3, age: 28 } };
|
|
112
|
+
* reject(obj, 'name');
|
|
113
|
+
* // => [{ id: 3, age: 28 }]
|
|
114
|
+
*/
|
|
115
|
+
declare function reject<T extends Record<string, unknown>>(object: T | null | undefined, propertyToCheck: PropertyKey): T[];
|
|
116
|
+
|
|
117
|
+
export { reject };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds the index of the first occurrence of a value in a sorted array, similar to how `Array#indexOf` works, but specifically for sorted arrays.
|
|
3
|
+
*
|
|
4
|
+
* Make sure to provide a sorted array to this function, as it uses a binary search to quickly find the index.
|
|
5
|
+
*
|
|
6
|
+
* @param {ArrayLike<T> | null | undefined} array The sorted array to inspect.
|
|
7
|
+
* @param {T} value The value to search for.
|
|
8
|
+
* @returns {number} Returns the index of the matched value, else -1.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const numbers = [1, 2, 3, 4, 5];
|
|
12
|
+
* sortedIndexOf(numbers, 11); // Return value: 0
|
|
13
|
+
* sortedIndexOf(numbers, 30); // Return value: -1
|
|
14
|
+
*
|
|
15
|
+
* // If the value is duplicated, it returns the first index of the value.
|
|
16
|
+
* const duplicateNumbers = [1, 2, 2, 3, 3, 3, 4];
|
|
17
|
+
* sortedIndexOf(duplicateNumbers, 3); // Return value: 3
|
|
18
|
+
*
|
|
19
|
+
* // If the array is unsorted, it can return the wrong index.
|
|
20
|
+
* const unSortedArray = [55, 33, 22, 11, 44];
|
|
21
|
+
* sortedIndexOf(unSortedArray, 11); // Return value: -1
|
|
22
|
+
*
|
|
23
|
+
* // -0 and 0 are treated the same
|
|
24
|
+
* const mixedZeroArray = [-0, 0];
|
|
25
|
+
* sortedIndexOf(mixedZeroArray, 0); // Return value: 0
|
|
26
|
+
* sortedIndexOf(mixedZeroArray, -0); // Return value: 0
|
|
27
|
+
*
|
|
28
|
+
* // It works with array-like objects
|
|
29
|
+
* const arrayLike = { length: 3, 0: 10, 1: 20, 2: 30 };
|
|
30
|
+
* sortedIndexOf(arrayLike, 20); // Return value: 1
|
|
31
|
+
*/
|
|
32
|
+
declare function sortedIndexOf<T>(array: ArrayLike<T> | null | undefined, value: T): number;
|
|
33
|
+
|
|
34
|
+
export { sortedIndexOf };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds the index of the first occurrence of a value in a sorted array, similar to how `Array#indexOf` works, but specifically for sorted arrays.
|
|
3
|
+
*
|
|
4
|
+
* Make sure to provide a sorted array to this function, as it uses a binary search to quickly find the index.
|
|
5
|
+
*
|
|
6
|
+
* @param {ArrayLike<T> | null | undefined} array The sorted array to inspect.
|
|
7
|
+
* @param {T} value The value to search for.
|
|
8
|
+
* @returns {number} Returns the index of the matched value, else -1.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const numbers = [1, 2, 3, 4, 5];
|
|
12
|
+
* sortedIndexOf(numbers, 11); // Return value: 0
|
|
13
|
+
* sortedIndexOf(numbers, 30); // Return value: -1
|
|
14
|
+
*
|
|
15
|
+
* // If the value is duplicated, it returns the first index of the value.
|
|
16
|
+
* const duplicateNumbers = [1, 2, 2, 3, 3, 3, 4];
|
|
17
|
+
* sortedIndexOf(duplicateNumbers, 3); // Return value: 3
|
|
18
|
+
*
|
|
19
|
+
* // If the array is unsorted, it can return the wrong index.
|
|
20
|
+
* const unSortedArray = [55, 33, 22, 11, 44];
|
|
21
|
+
* sortedIndexOf(unSortedArray, 11); // Return value: -1
|
|
22
|
+
*
|
|
23
|
+
* // -0 and 0 are treated the same
|
|
24
|
+
* const mixedZeroArray = [-0, 0];
|
|
25
|
+
* sortedIndexOf(mixedZeroArray, 0); // Return value: 0
|
|
26
|
+
* sortedIndexOf(mixedZeroArray, -0); // Return value: 0
|
|
27
|
+
*
|
|
28
|
+
* // It works with array-like objects
|
|
29
|
+
* const arrayLike = { length: 3, 0: 10, 1: 20, 2: 30 };
|
|
30
|
+
* sortedIndexOf(arrayLike, 20); // Return value: 1
|
|
31
|
+
*/
|
|
32
|
+
declare function sortedIndexOf<T>(array: ArrayLike<T> | null | undefined, value: T): number;
|
|
33
|
+
|
|
34
|
+
export { sortedIndexOf };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { sortedIndex } from './sortedIndex.mjs';
|
|
2
|
+
import { eq } from '../util/eq.mjs';
|
|
3
|
+
|
|
4
|
+
function sortedIndexOf(array, value) {
|
|
5
|
+
if (!array?.length) {
|
|
6
|
+
return -1;
|
|
7
|
+
}
|
|
8
|
+
const index = sortedIndex(array, value);
|
|
9
|
+
if (index < array.length && eq(array[index], value)) {
|
|
10
|
+
return index;
|
|
11
|
+
}
|
|
12
|
+
return -1;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { sortedIndexOf };
|
package/dist/compat/index.d.mts
CHANGED
|
@@ -8,7 +8,6 @@ export { initial } from '../array/initial.mjs';
|
|
|
8
8
|
export { isSubset } from '../array/isSubset.mjs';
|
|
9
9
|
export { isSubsetWith } from '../array/isSubsetWith.mjs';
|
|
10
10
|
export { keyBy } from '../array/keyBy.mjs';
|
|
11
|
-
export { minBy } from '../array/minBy.mjs';
|
|
12
11
|
export { partition } from '../array/partition.mjs';
|
|
13
12
|
export { pullAt } from '../array/pullAt.mjs';
|
|
14
13
|
export { sampleSize } from '../array/sampleSize.mjs';
|
|
@@ -37,8 +36,6 @@ export { partialRight } from '../function/partialRight.mjs';
|
|
|
37
36
|
export { retry } from '../function/retry.mjs';
|
|
38
37
|
export { ThrottledFunction } from '../function/throttle.mjs';
|
|
39
38
|
export { unary } from '../function/unary.mjs';
|
|
40
|
-
export { mean } from '../math/mean.mjs';
|
|
41
|
-
export { meanBy } from '../math/meanBy.mjs';
|
|
42
39
|
export { median } from '../math/median.mjs';
|
|
43
40
|
export { medianBy } from '../math/medianBy.mjs';
|
|
44
41
|
export { randomInt } from '../math/randomInt.mjs';
|
|
@@ -48,12 +45,14 @@ export { invert } from '../object/invert.mjs';
|
|
|
48
45
|
export { omitBy } from '../object/omitBy.mjs';
|
|
49
46
|
export { toMerged } from '../object/toMerged.mjs';
|
|
50
47
|
export { isBlob } from '../predicate/isBlob.mjs';
|
|
48
|
+
export { isBrowser } from '../predicate/isBrowser.mjs';
|
|
51
49
|
export { isEqual } from '../predicate/isEqual.mjs';
|
|
52
50
|
export { isFile } from '../predicate/isFile.mjs';
|
|
53
51
|
export { isFunction } from '../predicate/isFunction.mjs';
|
|
54
52
|
export { isJSON } from '../predicate/isJSON.mjs';
|
|
55
53
|
export { isJSONArray, isJSONObject, isJSONValue } from '../predicate/isJSONValue.mjs';
|
|
56
54
|
export { isLength } from '../predicate/isLength.mjs';
|
|
55
|
+
export { isNode } from '../predicate/isNode.mjs';
|
|
57
56
|
export { isNotNil } from '../predicate/isNotNil.mjs';
|
|
58
57
|
export { isNull } from '../predicate/isNull.mjs';
|
|
59
58
|
export { isPrimitive } from '../predicate/isPrimitive.mjs';
|
|
@@ -67,6 +66,7 @@ export { capitalize } from '../string/capitalize.mjs';
|
|
|
67
66
|
export { constantCase } from '../string/constantCase.mjs';
|
|
68
67
|
export { pascalCase } from '../string/pascalCase.mjs';
|
|
69
68
|
export { reverseString } from '../string/reverseString.mjs';
|
|
69
|
+
export { attemptAsync } from '../util/attemptAsync.mjs';
|
|
70
70
|
export { invariant } from '../util/invariant.mjs';
|
|
71
71
|
export { castArray } from './array/castArray.mjs';
|
|
72
72
|
export { chunk } from './array/chunk.mjs';
|
|
@@ -107,6 +107,7 @@ export { pullAll } from './array/pullAll.mjs';
|
|
|
107
107
|
export { pullAllBy } from './array/pullAllBy.mjs';
|
|
108
108
|
export { reduce } from './array/reduce.mjs';
|
|
109
109
|
export { reduceRight } from './array/reduceRight.mjs';
|
|
110
|
+
export { reject } from './array/reject.mjs';
|
|
110
111
|
export { remove } from './array/remove.mjs';
|
|
111
112
|
export { reverse } from './array/reverse.mjs';
|
|
112
113
|
export { sample } from './array/sample.mjs';
|
|
@@ -116,6 +117,7 @@ export { some } from './array/some.mjs';
|
|
|
116
117
|
export { sortBy } from './array/sortBy.mjs';
|
|
117
118
|
export { sortedIndex } from './array/sortedIndex.mjs';
|
|
118
119
|
export { sortedIndexBy } from './array/sortedIndexBy.mjs';
|
|
120
|
+
export { sortedIndexOf } from './array/sortedIndexOf.mjs';
|
|
119
121
|
export { tail } from './array/tail.mjs';
|
|
120
122
|
export { take } from './array/take.mjs';
|
|
121
123
|
export { takeRight } from './array/takeRight.mjs';
|
|
@@ -155,7 +157,10 @@ export { floor } from './math/floor.mjs';
|
|
|
155
157
|
export { inRange } from './math/inRange.mjs';
|
|
156
158
|
export { max } from './math/max.mjs';
|
|
157
159
|
export { maxBy } from './math/maxBy.mjs';
|
|
160
|
+
export { mean } from './math/mean.mjs';
|
|
161
|
+
export { meanBy } from './math/meanBy.mjs';
|
|
158
162
|
export { min } from './math/min.mjs';
|
|
163
|
+
export { minBy } from './math/minBy.mjs';
|
|
159
164
|
export { multiply } from './math/multiply.mjs';
|
|
160
165
|
export { parseInt } from './math/parseInt.mjs';
|
|
161
166
|
export { random } from './math/random.mjs';
|
|
@@ -171,6 +176,7 @@ export { cloneDeepWith } from './object/cloneDeepWith.mjs';
|
|
|
171
176
|
export { defaults } from './object/defaults.mjs';
|
|
172
177
|
export { findKey } from './object/findKey.mjs';
|
|
173
178
|
export { fromPairs } from './object/fromPairs.mjs';
|
|
179
|
+
export { functionsIn } from './object/functionsIn.mjs';
|
|
174
180
|
export { get } from './object/get.mjs';
|
|
175
181
|
export { has } from './object/has.mjs';
|
|
176
182
|
export { invertBy } from './object/invertBy.mjs';
|
package/dist/compat/index.d.ts
CHANGED
|
@@ -8,7 +8,6 @@ export { initial } from '../array/initial.js';
|
|
|
8
8
|
export { isSubset } from '../array/isSubset.js';
|
|
9
9
|
export { isSubsetWith } from '../array/isSubsetWith.js';
|
|
10
10
|
export { keyBy } from '../array/keyBy.js';
|
|
11
|
-
export { minBy } from '../array/minBy.js';
|
|
12
11
|
export { partition } from '../array/partition.js';
|
|
13
12
|
export { pullAt } from '../array/pullAt.js';
|
|
14
13
|
export { sampleSize } from '../array/sampleSize.js';
|
|
@@ -37,8 +36,6 @@ export { partialRight } from '../function/partialRight.js';
|
|
|
37
36
|
export { retry } from '../function/retry.js';
|
|
38
37
|
export { ThrottledFunction } from '../function/throttle.js';
|
|
39
38
|
export { unary } from '../function/unary.js';
|
|
40
|
-
export { mean } from '../math/mean.js';
|
|
41
|
-
export { meanBy } from '../math/meanBy.js';
|
|
42
39
|
export { median } from '../math/median.js';
|
|
43
40
|
export { medianBy } from '../math/medianBy.js';
|
|
44
41
|
export { randomInt } from '../math/randomInt.js';
|
|
@@ -48,12 +45,14 @@ export { invert } from '../object/invert.js';
|
|
|
48
45
|
export { omitBy } from '../object/omitBy.js';
|
|
49
46
|
export { toMerged } from '../object/toMerged.js';
|
|
50
47
|
export { isBlob } from '../predicate/isBlob.js';
|
|
48
|
+
export { isBrowser } from '../predicate/isBrowser.js';
|
|
51
49
|
export { isEqual } from '../predicate/isEqual.js';
|
|
52
50
|
export { isFile } from '../predicate/isFile.js';
|
|
53
51
|
export { isFunction } from '../predicate/isFunction.js';
|
|
54
52
|
export { isJSON } from '../predicate/isJSON.js';
|
|
55
53
|
export { isJSONArray, isJSONObject, isJSONValue } from '../predicate/isJSONValue.js';
|
|
56
54
|
export { isLength } from '../predicate/isLength.js';
|
|
55
|
+
export { isNode } from '../predicate/isNode.js';
|
|
57
56
|
export { isNotNil } from '../predicate/isNotNil.js';
|
|
58
57
|
export { isNull } from '../predicate/isNull.js';
|
|
59
58
|
export { isPrimitive } from '../predicate/isPrimitive.js';
|
|
@@ -67,6 +66,7 @@ export { capitalize } from '../string/capitalize.js';
|
|
|
67
66
|
export { constantCase } from '../string/constantCase.js';
|
|
68
67
|
export { pascalCase } from '../string/pascalCase.js';
|
|
69
68
|
export { reverseString } from '../string/reverseString.js';
|
|
69
|
+
export { attemptAsync } from '../util/attemptAsync.js';
|
|
70
70
|
export { invariant } from '../util/invariant.js';
|
|
71
71
|
export { castArray } from './array/castArray.js';
|
|
72
72
|
export { chunk } from './array/chunk.js';
|
|
@@ -107,6 +107,7 @@ export { pullAll } from './array/pullAll.js';
|
|
|
107
107
|
export { pullAllBy } from './array/pullAllBy.js';
|
|
108
108
|
export { reduce } from './array/reduce.js';
|
|
109
109
|
export { reduceRight } from './array/reduceRight.js';
|
|
110
|
+
export { reject } from './array/reject.js';
|
|
110
111
|
export { remove } from './array/remove.js';
|
|
111
112
|
export { reverse } from './array/reverse.js';
|
|
112
113
|
export { sample } from './array/sample.js';
|
|
@@ -116,6 +117,7 @@ export { some } from './array/some.js';
|
|
|
116
117
|
export { sortBy } from './array/sortBy.js';
|
|
117
118
|
export { sortedIndex } from './array/sortedIndex.js';
|
|
118
119
|
export { sortedIndexBy } from './array/sortedIndexBy.js';
|
|
120
|
+
export { sortedIndexOf } from './array/sortedIndexOf.js';
|
|
119
121
|
export { tail } from './array/tail.js';
|
|
120
122
|
export { take } from './array/take.js';
|
|
121
123
|
export { takeRight } from './array/takeRight.js';
|
|
@@ -155,7 +157,10 @@ export { floor } from './math/floor.js';
|
|
|
155
157
|
export { inRange } from './math/inRange.js';
|
|
156
158
|
export { max } from './math/max.js';
|
|
157
159
|
export { maxBy } from './math/maxBy.js';
|
|
160
|
+
export { mean } from './math/mean.js';
|
|
161
|
+
export { meanBy } from './math/meanBy.js';
|
|
158
162
|
export { min } from './math/min.js';
|
|
163
|
+
export { minBy } from './math/minBy.js';
|
|
159
164
|
export { multiply } from './math/multiply.js';
|
|
160
165
|
export { parseInt } from './math/parseInt.js';
|
|
161
166
|
export { random } from './math/random.js';
|
|
@@ -171,6 +176,7 @@ export { cloneDeepWith } from './object/cloneDeepWith.js';
|
|
|
171
176
|
export { defaults } from './object/defaults.js';
|
|
172
177
|
export { findKey } from './object/findKey.js';
|
|
173
178
|
export { fromPairs } from './object/fromPairs.js';
|
|
179
|
+
export { functionsIn } from './object/functionsIn.js';
|
|
174
180
|
export { get } from './object/get.js';
|
|
175
181
|
export { has } from './object/has.js';
|
|
176
182
|
export { invertBy } from './object/invertBy.js';
|