es-toolkit 1.25.2-dev.802 → 1.25.2-dev.804
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/array/drop.d.mts +2 -1
- package/dist/compat/array/drop.d.ts +2 -1
- package/dist/compat/array/drop.mjs +3 -1
- package/dist/compat/array/dropRight.d.mts +2 -1
- package/dist/compat/array/dropRight.d.ts +2 -1
- package/dist/compat/array/dropRight.mjs +3 -1
- package/dist/compat/array/every.mjs +5 -1
- package/dist/compat/array/some.d.mts +73 -21
- package/dist/compat/array/some.d.ts +73 -21
- package/dist/compat/array/some.mjs +20 -8
- package/dist/compat/array/take.d.mts +2 -1
- package/dist/compat/array/take.d.ts +2 -1
- package/dist/compat/array/take.mjs +3 -1
- package/dist/compat/array/takeRight.d.mts +2 -1
- package/dist/compat/array/takeRight.d.ts +2 -1
- package/dist/compat/array/takeRight.mjs +3 -1
- package/dist/compat/index.js +72 -53
- package/package.json +1 -1
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* @template T - The type of elements in the array.
|
|
8
8
|
* @param {ArrayLike<T> | null | undefined} collection - The array from which to drop elements.
|
|
9
9
|
* @param {number} itemsCount - The number of elements to drop from the beginning of the array.
|
|
10
|
+
* @param {unknown} [guard] - Enables use as an iteratee for methods like `_.map`.
|
|
10
11
|
* @returns {T[]} A new array with the specified number of elements removed from the start.
|
|
11
12
|
*
|
|
12
13
|
* @example
|
|
@@ -14,6 +15,6 @@
|
|
|
14
15
|
* const result = drop(array, 2);
|
|
15
16
|
* result will be [3, 4, 5] since the first two elements are dropped.
|
|
16
17
|
*/
|
|
17
|
-
declare function drop<T>(collection: ArrayLike<T> | null | undefined, itemsCount
|
|
18
|
+
declare function drop<T>(collection: ArrayLike<T> | null | undefined, itemsCount?: number, guard?: unknown): T[];
|
|
18
19
|
|
|
19
20
|
export { drop };
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* @template T - The type of elements in the array.
|
|
8
8
|
* @param {ArrayLike<T> | null | undefined} collection - The array from which to drop elements.
|
|
9
9
|
* @param {number} itemsCount - The number of elements to drop from the beginning of the array.
|
|
10
|
+
* @param {unknown} [guard] - Enables use as an iteratee for methods like `_.map`.
|
|
10
11
|
* @returns {T[]} A new array with the specified number of elements removed from the start.
|
|
11
12
|
*
|
|
12
13
|
* @example
|
|
@@ -14,6 +15,6 @@
|
|
|
14
15
|
* const result = drop(array, 2);
|
|
15
16
|
* result will be [3, 4, 5] since the first two elements are dropped.
|
|
16
17
|
*/
|
|
17
|
-
declare function drop<T>(collection: ArrayLike<T> | null | undefined, itemsCount
|
|
18
|
+
declare function drop<T>(collection: ArrayLike<T> | null | undefined, itemsCount?: number, guard?: unknown): T[];
|
|
18
19
|
|
|
19
20
|
export { drop };
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { drop as drop$1 } from '../../array/drop.mjs';
|
|
2
2
|
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
3
|
+
import { toInteger } from '../util/toInteger.mjs';
|
|
3
4
|
|
|
4
|
-
function drop(collection, itemsCount) {
|
|
5
|
+
function drop(collection, itemsCount = 1, guard) {
|
|
5
6
|
if (!isArrayLike(collection)) {
|
|
6
7
|
return [];
|
|
7
8
|
}
|
|
9
|
+
itemsCount = guard ? 1 : toInteger(itemsCount);
|
|
8
10
|
return drop$1(Array.from(collection), itemsCount);
|
|
9
11
|
}
|
|
10
12
|
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* @template T - The type of elements in the array.
|
|
8
8
|
* @param {ArrayLike<T> | null | undefined} collection - The array from which to drop elements.
|
|
9
9
|
* @param {number} itemsCount - The number of elements to drop from the end of the array.
|
|
10
|
+
* @param {unknown} [guard] - Enables use as an iteratee for methods like `_.map`.
|
|
10
11
|
* @returns {T[]} A new array with the specified number of elements removed from the end.
|
|
11
12
|
*
|
|
12
13
|
* @example
|
|
@@ -14,6 +15,6 @@
|
|
|
14
15
|
* const result = dropRight(array, 2);
|
|
15
16
|
* // result will be [1, 2, 3] since the last two elements are dropped.
|
|
16
17
|
*/
|
|
17
|
-
declare function dropRight<T>(collection: ArrayLike<T> | null | undefined, itemsCount
|
|
18
|
+
declare function dropRight<T>(collection: ArrayLike<T> | null | undefined, itemsCount?: number, guard?: unknown): T[];
|
|
18
19
|
|
|
19
20
|
export { dropRight };
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* @template T - The type of elements in the array.
|
|
8
8
|
* @param {ArrayLike<T> | null | undefined} collection - The array from which to drop elements.
|
|
9
9
|
* @param {number} itemsCount - The number of elements to drop from the end of the array.
|
|
10
|
+
* @param {unknown} [guard] - Enables use as an iteratee for methods like `_.map`.
|
|
10
11
|
* @returns {T[]} A new array with the specified number of elements removed from the end.
|
|
11
12
|
*
|
|
12
13
|
* @example
|
|
@@ -14,6 +15,6 @@
|
|
|
14
15
|
* const result = dropRight(array, 2);
|
|
15
16
|
* // result will be [1, 2, 3] since the last two elements are dropped.
|
|
16
17
|
*/
|
|
17
|
-
declare function dropRight<T>(collection: ArrayLike<T> | null | undefined, itemsCount
|
|
18
|
+
declare function dropRight<T>(collection: ArrayLike<T> | null | undefined, itemsCount?: number, guard?: unknown): T[];
|
|
18
19
|
|
|
19
20
|
export { dropRight };
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { dropRight as dropRight$1 } from '../../array/dropRight.mjs';
|
|
2
2
|
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
3
|
+
import { toInteger } from '../util/toInteger.mjs';
|
|
3
4
|
|
|
4
|
-
function dropRight(collection, itemsCount) {
|
|
5
|
+
function dropRight(collection, itemsCount = 1, guard) {
|
|
5
6
|
if (!isArrayLike(collection)) {
|
|
6
7
|
return [];
|
|
7
8
|
}
|
|
9
|
+
itemsCount = guard ? 1 : toInteger(itemsCount);
|
|
8
10
|
return dropRight$1(Array.from(collection), itemsCount);
|
|
9
11
|
}
|
|
10
12
|
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { identity } from '../_internal/identity.mjs';
|
|
2
|
+
import { isIterateeCall } from '../_internal/isIterateeCall.mjs';
|
|
2
3
|
import { property } from '../object/property.mjs';
|
|
3
4
|
import { matches } from '../predicate/matches.mjs';
|
|
4
5
|
import { matchesProperty } from '../predicate/matchesProperty.mjs';
|
|
5
6
|
|
|
6
|
-
function every(source, doesMatch) {
|
|
7
|
+
function every(source, doesMatch, guard) {
|
|
7
8
|
if (!source) {
|
|
8
9
|
return true;
|
|
9
10
|
}
|
|
10
11
|
const values = Array.isArray(source) ? source : Object.values(source);
|
|
12
|
+
if (guard && isIterateeCall(source, doesMatch, guard)) {
|
|
13
|
+
doesMatch = undefined;
|
|
14
|
+
}
|
|
11
15
|
if (!doesMatch) {
|
|
12
16
|
doesMatch = identity;
|
|
13
17
|
}
|
|
@@ -1,30 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Checks if there is an element in an array that is truthy.
|
|
3
3
|
*
|
|
4
|
-
* @
|
|
4
|
+
* @template T
|
|
5
|
+
* @param {ArrayLike<T> | null | undefined} arr The array to iterate over.
|
|
5
6
|
* @returns {boolean} Returns `true` if any element is truthy, else `false`.
|
|
6
7
|
*
|
|
7
8
|
* @example
|
|
8
9
|
* some([1, 2, 3, 4]);
|
|
9
10
|
* // => true
|
|
10
11
|
*/
|
|
11
|
-
declare function some<T>(arr:
|
|
12
|
+
declare function some<T>(arr: ArrayLike<T> | null | undefined): boolean;
|
|
12
13
|
/**
|
|
13
14
|
* Checks if there is an element in an array that matches the given predicate function.
|
|
14
15
|
*
|
|
15
|
-
* @
|
|
16
|
-
* @param {
|
|
16
|
+
* @template T
|
|
17
|
+
* @param {ArrayLike<T> | null | undefined} arr The array to iterate over.
|
|
18
|
+
* @param {(item: T, index: number, arr: readonly T[]) => unknown} predicate The function invoked per iteration.
|
|
17
19
|
* @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
|
|
18
20
|
*
|
|
19
21
|
* @example
|
|
20
22
|
* some([1, 2, 3, 4], n => n % 2 === 0);
|
|
21
23
|
* // => true
|
|
22
24
|
*/
|
|
23
|
-
declare function some<T>(arr:
|
|
25
|
+
declare function some<T>(arr: ArrayLike<T> | null | undefined, predicate: (item: T, index: number, arr: readonly T[]) => unknown): boolean;
|
|
24
26
|
/**
|
|
25
27
|
* Checks if there is an element in an array that matches the given key-value pair.
|
|
26
28
|
*
|
|
27
|
-
* @
|
|
29
|
+
* @template T
|
|
30
|
+
* @param {ArrayLike<T> | null | undefined} arr The array to iterate over.
|
|
28
31
|
* @param {[keyof T, unknown]} predicate The key-value pair to match.
|
|
29
32
|
* @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
|
|
30
33
|
*
|
|
@@ -32,11 +35,12 @@ declare function some<T>(arr: readonly T[], predicate: (item: T, index: number,
|
|
|
32
35
|
* some([{ a: 1 }, { a: 2 }, { a: 3 }], ['a', 2]);
|
|
33
36
|
* // => true
|
|
34
37
|
*/
|
|
35
|
-
declare function some<T>(arr:
|
|
38
|
+
declare function some<T>(arr: ArrayLike<T> | null | undefined, predicate: [keyof T, unknown]): boolean;
|
|
36
39
|
/**
|
|
37
40
|
* Checks if there is an element in an array that has a truthy value for the given property name.
|
|
38
41
|
*
|
|
39
|
-
* @
|
|
42
|
+
* @template T
|
|
43
|
+
* @param {ArrayLike<T> | null | undefined} arr The array to iterate over.
|
|
40
44
|
* @param {string} propertyToCheck The property name to check.
|
|
41
45
|
* @returns {boolean} Returns `true` if any element has a truthy value for the property, else `false`.
|
|
42
46
|
*
|
|
@@ -44,11 +48,12 @@ declare function some<T>(arr: readonly T[], predicate: [keyof T, unknown]): bool
|
|
|
44
48
|
* some([{ a: 1 }, { a: 2 }, { a: 3 }], 'a');
|
|
45
49
|
* // => true
|
|
46
50
|
*/
|
|
47
|
-
declare function some<T>(arr:
|
|
51
|
+
declare function some<T>(arr: ArrayLike<T> | null | undefined, propertyToCheck: string): boolean;
|
|
48
52
|
/**
|
|
49
53
|
* Checks if there is an element in an array that matches the given partial object.
|
|
50
54
|
*
|
|
51
|
-
* @
|
|
55
|
+
* @template T
|
|
56
|
+
* @param {ArrayLike<T> | null | undefined} arr The array to iterate over.
|
|
52
57
|
* @param {Partial<T>} doesMatch The partial object to match.
|
|
53
58
|
* @returns {boolean} Returns `true` if any element matches the partial object, else `false`.
|
|
54
59
|
*
|
|
@@ -56,30 +61,77 @@ declare function some<T>(arr: readonly T[], propertyToCheck: string): boolean;
|
|
|
56
61
|
* some([{ a: 1 }, { a: 2 }, { a: 3 }], { a: 2 });
|
|
57
62
|
* // => true
|
|
58
63
|
*/
|
|
59
|
-
declare function some<T>(arr:
|
|
64
|
+
declare function some<T>(arr: ArrayLike<T> | null | undefined, doesMatch: Partial<T>): boolean;
|
|
60
65
|
/**
|
|
61
|
-
* Checks if there is an element in an array that matches the given predicate.
|
|
62
66
|
*
|
|
63
|
-
*
|
|
67
|
+
* Checks if there is an element in an object that matches the given predicate function.
|
|
64
68
|
*
|
|
65
|
-
* @
|
|
66
|
-
* @param {
|
|
67
|
-
*
|
|
69
|
+
* @template T
|
|
70
|
+
* @param {T | null | undefined} object The object to iterate over.
|
|
71
|
+
* @returns {boolean} Returns `true` if any element is truthy, else `false`.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* some({ a: 1, b: 2, c: 3 });
|
|
75
|
+
* // => true
|
|
76
|
+
*/
|
|
77
|
+
declare function some<T extends Record<string, unknown>>(object: T | null | undefined): boolean;
|
|
78
|
+
/**
|
|
79
|
+
*
|
|
80
|
+
* Checks if there is an element in an object that matches the given predicate function.
|
|
81
|
+
*
|
|
82
|
+
* @template T
|
|
83
|
+
* @param {T | null | undefined} object The object to iterate over.
|
|
84
|
+
* @param {(value: T[keyof T], key: keyof T, object: T) => unknown} doesMatch A function that takes an value, its key, and the object, and returns a truthy value if the item matches the criteria.
|
|
68
85
|
* @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
|
|
69
86
|
*
|
|
70
87
|
* @example
|
|
71
|
-
* some(
|
|
88
|
+
* some({ a: 1, b: 2, c: 3 }, n => n % 2 === 0);
|
|
72
89
|
* // => true
|
|
90
|
+
*/
|
|
91
|
+
declare function some<T extends Record<string, unknown>>(object: T | null | undefined, doesMatch: (value: T[keyof T], key: keyof T, object: T) => unknown): boolean;
|
|
92
|
+
/**
|
|
73
93
|
*
|
|
74
|
-
*
|
|
94
|
+
* Checks if there is an element in an object that matches the given partial value.
|
|
95
|
+
*
|
|
96
|
+
* @template T
|
|
97
|
+
* @param {T | null | undefined} object The object to iterate over.
|
|
98
|
+
* @param {Partial<T[keyof T]>} doesMatch A partial value to match against the values of the object.
|
|
99
|
+
* @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* some({ a: { id: 1, name: 'Alice' }, b: { id: 2, name: 'Bob' } }, { name: 'Bob' });
|
|
75
103
|
* // => true
|
|
104
|
+
*/
|
|
105
|
+
declare function some<T extends Record<string, unknown>>(object: T | null | undefined, doesMatch: Partial<T[keyof T]>): boolean;
|
|
106
|
+
/**
|
|
76
107
|
*
|
|
77
|
-
*
|
|
108
|
+
* Checks if there is an element in an object that matches a property with a specific value.
|
|
109
|
+
*
|
|
110
|
+
* @template T
|
|
111
|
+
* @param {T | null | undefined} object The object to iterate over.
|
|
112
|
+
* @param {[keyof T, unknown]} doesMatchProperty An array where the first element is the property key and the second element is the value to match.
|
|
113
|
+
* @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* const obj = { alice: { id: 1, name: 'Alice' }, bob: { id: 2, name: 'Bob' } };
|
|
117
|
+
* const result = some(obj, ['name', 'Alice']);
|
|
78
118
|
* // => true
|
|
119
|
+
*/
|
|
120
|
+
declare function some<T extends Record<string, unknown>>(object: T | null | undefined, doesMatchProperty: [keyof T[keyof T], unknown]): boolean;
|
|
121
|
+
/**
|
|
79
122
|
*
|
|
80
|
-
*
|
|
123
|
+
* Checks if there is an element in an object that has a specific property, where the property name is provided as a string.
|
|
124
|
+
*
|
|
125
|
+
* @template T
|
|
126
|
+
* @param {T | null | undefined} object The object to iterate over.
|
|
127
|
+
* @param {string} propertyToCheck The property name to check.
|
|
128
|
+
* @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* const obj = { alice: { id: 1, name: 'Alice' }, bob: { id: 2, name: 'Bob' } };
|
|
132
|
+
* const result = some(obj, 'name');
|
|
81
133
|
* // => true
|
|
82
134
|
*/
|
|
83
|
-
declare function some<T
|
|
135
|
+
declare function some<T extends Record<string, unknown>>(object: T | null | undefined, propertyToCheck: string): boolean;
|
|
84
136
|
|
|
85
137
|
export { some };
|
|
@@ -1,30 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Checks if there is an element in an array that is truthy.
|
|
3
3
|
*
|
|
4
|
-
* @
|
|
4
|
+
* @template T
|
|
5
|
+
* @param {ArrayLike<T> | null | undefined} arr The array to iterate over.
|
|
5
6
|
* @returns {boolean} Returns `true` if any element is truthy, else `false`.
|
|
6
7
|
*
|
|
7
8
|
* @example
|
|
8
9
|
* some([1, 2, 3, 4]);
|
|
9
10
|
* // => true
|
|
10
11
|
*/
|
|
11
|
-
declare function some<T>(arr:
|
|
12
|
+
declare function some<T>(arr: ArrayLike<T> | null | undefined): boolean;
|
|
12
13
|
/**
|
|
13
14
|
* Checks if there is an element in an array that matches the given predicate function.
|
|
14
15
|
*
|
|
15
|
-
* @
|
|
16
|
-
* @param {
|
|
16
|
+
* @template T
|
|
17
|
+
* @param {ArrayLike<T> | null | undefined} arr The array to iterate over.
|
|
18
|
+
* @param {(item: T, index: number, arr: readonly T[]) => unknown} predicate The function invoked per iteration.
|
|
17
19
|
* @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
|
|
18
20
|
*
|
|
19
21
|
* @example
|
|
20
22
|
* some([1, 2, 3, 4], n => n % 2 === 0);
|
|
21
23
|
* // => true
|
|
22
24
|
*/
|
|
23
|
-
declare function some<T>(arr:
|
|
25
|
+
declare function some<T>(arr: ArrayLike<T> | null | undefined, predicate: (item: T, index: number, arr: readonly T[]) => unknown): boolean;
|
|
24
26
|
/**
|
|
25
27
|
* Checks if there is an element in an array that matches the given key-value pair.
|
|
26
28
|
*
|
|
27
|
-
* @
|
|
29
|
+
* @template T
|
|
30
|
+
* @param {ArrayLike<T> | null | undefined} arr The array to iterate over.
|
|
28
31
|
* @param {[keyof T, unknown]} predicate The key-value pair to match.
|
|
29
32
|
* @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
|
|
30
33
|
*
|
|
@@ -32,11 +35,12 @@ declare function some<T>(arr: readonly T[], predicate: (item: T, index: number,
|
|
|
32
35
|
* some([{ a: 1 }, { a: 2 }, { a: 3 }], ['a', 2]);
|
|
33
36
|
* // => true
|
|
34
37
|
*/
|
|
35
|
-
declare function some<T>(arr:
|
|
38
|
+
declare function some<T>(arr: ArrayLike<T> | null | undefined, predicate: [keyof T, unknown]): boolean;
|
|
36
39
|
/**
|
|
37
40
|
* Checks if there is an element in an array that has a truthy value for the given property name.
|
|
38
41
|
*
|
|
39
|
-
* @
|
|
42
|
+
* @template T
|
|
43
|
+
* @param {ArrayLike<T> | null | undefined} arr The array to iterate over.
|
|
40
44
|
* @param {string} propertyToCheck The property name to check.
|
|
41
45
|
* @returns {boolean} Returns `true` if any element has a truthy value for the property, else `false`.
|
|
42
46
|
*
|
|
@@ -44,11 +48,12 @@ declare function some<T>(arr: readonly T[], predicate: [keyof T, unknown]): bool
|
|
|
44
48
|
* some([{ a: 1 }, { a: 2 }, { a: 3 }], 'a');
|
|
45
49
|
* // => true
|
|
46
50
|
*/
|
|
47
|
-
declare function some<T>(arr:
|
|
51
|
+
declare function some<T>(arr: ArrayLike<T> | null | undefined, propertyToCheck: string): boolean;
|
|
48
52
|
/**
|
|
49
53
|
* Checks if there is an element in an array that matches the given partial object.
|
|
50
54
|
*
|
|
51
|
-
* @
|
|
55
|
+
* @template T
|
|
56
|
+
* @param {ArrayLike<T> | null | undefined} arr The array to iterate over.
|
|
52
57
|
* @param {Partial<T>} doesMatch The partial object to match.
|
|
53
58
|
* @returns {boolean} Returns `true` if any element matches the partial object, else `false`.
|
|
54
59
|
*
|
|
@@ -56,30 +61,77 @@ declare function some<T>(arr: readonly T[], propertyToCheck: string): boolean;
|
|
|
56
61
|
* some([{ a: 1 }, { a: 2 }, { a: 3 }], { a: 2 });
|
|
57
62
|
* // => true
|
|
58
63
|
*/
|
|
59
|
-
declare function some<T>(arr:
|
|
64
|
+
declare function some<T>(arr: ArrayLike<T> | null | undefined, doesMatch: Partial<T>): boolean;
|
|
60
65
|
/**
|
|
61
|
-
* Checks if there is an element in an array that matches the given predicate.
|
|
62
66
|
*
|
|
63
|
-
*
|
|
67
|
+
* Checks if there is an element in an object that matches the given predicate function.
|
|
64
68
|
*
|
|
65
|
-
* @
|
|
66
|
-
* @param {
|
|
67
|
-
*
|
|
69
|
+
* @template T
|
|
70
|
+
* @param {T | null | undefined} object The object to iterate over.
|
|
71
|
+
* @returns {boolean} Returns `true` if any element is truthy, else `false`.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* some({ a: 1, b: 2, c: 3 });
|
|
75
|
+
* // => true
|
|
76
|
+
*/
|
|
77
|
+
declare function some<T extends Record<string, unknown>>(object: T | null | undefined): boolean;
|
|
78
|
+
/**
|
|
79
|
+
*
|
|
80
|
+
* Checks if there is an element in an object that matches the given predicate function.
|
|
81
|
+
*
|
|
82
|
+
* @template T
|
|
83
|
+
* @param {T | null | undefined} object The object to iterate over.
|
|
84
|
+
* @param {(value: T[keyof T], key: keyof T, object: T) => unknown} doesMatch A function that takes an value, its key, and the object, and returns a truthy value if the item matches the criteria.
|
|
68
85
|
* @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
|
|
69
86
|
*
|
|
70
87
|
* @example
|
|
71
|
-
* some(
|
|
88
|
+
* some({ a: 1, b: 2, c: 3 }, n => n % 2 === 0);
|
|
72
89
|
* // => true
|
|
90
|
+
*/
|
|
91
|
+
declare function some<T extends Record<string, unknown>>(object: T | null | undefined, doesMatch: (value: T[keyof T], key: keyof T, object: T) => unknown): boolean;
|
|
92
|
+
/**
|
|
73
93
|
*
|
|
74
|
-
*
|
|
94
|
+
* Checks if there is an element in an object that matches the given partial value.
|
|
95
|
+
*
|
|
96
|
+
* @template T
|
|
97
|
+
* @param {T | null | undefined} object The object to iterate over.
|
|
98
|
+
* @param {Partial<T[keyof T]>} doesMatch A partial value to match against the values of the object.
|
|
99
|
+
* @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* some({ a: { id: 1, name: 'Alice' }, b: { id: 2, name: 'Bob' } }, { name: 'Bob' });
|
|
75
103
|
* // => true
|
|
104
|
+
*/
|
|
105
|
+
declare function some<T extends Record<string, unknown>>(object: T | null | undefined, doesMatch: Partial<T[keyof T]>): boolean;
|
|
106
|
+
/**
|
|
76
107
|
*
|
|
77
|
-
*
|
|
108
|
+
* Checks if there is an element in an object that matches a property with a specific value.
|
|
109
|
+
*
|
|
110
|
+
* @template T
|
|
111
|
+
* @param {T | null | undefined} object The object to iterate over.
|
|
112
|
+
* @param {[keyof T, unknown]} doesMatchProperty An array where the first element is the property key and the second element is the value to match.
|
|
113
|
+
* @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* const obj = { alice: { id: 1, name: 'Alice' }, bob: { id: 2, name: 'Bob' } };
|
|
117
|
+
* const result = some(obj, ['name', 'Alice']);
|
|
78
118
|
* // => true
|
|
119
|
+
*/
|
|
120
|
+
declare function some<T extends Record<string, unknown>>(object: T | null | undefined, doesMatchProperty: [keyof T[keyof T], unknown]): boolean;
|
|
121
|
+
/**
|
|
79
122
|
*
|
|
80
|
-
*
|
|
123
|
+
* Checks if there is an element in an object that has a specific property, where the property name is provided as a string.
|
|
124
|
+
*
|
|
125
|
+
* @template T
|
|
126
|
+
* @param {T | null | undefined} object The object to iterate over.
|
|
127
|
+
* @param {string} propertyToCheck The property name to check.
|
|
128
|
+
* @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* const obj = { alice: { id: 1, name: 'Alice' }, bob: { id: 2, name: 'Bob' } };
|
|
132
|
+
* const result = some(obj, 'name');
|
|
81
133
|
* // => true
|
|
82
134
|
*/
|
|
83
|
-
declare function some<T
|
|
135
|
+
declare function some<T extends Record<string, unknown>>(object: T | null | undefined, propertyToCheck: string): boolean;
|
|
84
136
|
|
|
85
137
|
export { some };
|
|
@@ -3,32 +3,44 @@ import { property } from '../object/property.mjs';
|
|
|
3
3
|
import { matches } from '../predicate/matches.mjs';
|
|
4
4
|
import { matchesProperty } from '../predicate/matchesProperty.mjs';
|
|
5
5
|
|
|
6
|
-
function some(
|
|
6
|
+
function some(source, predicate, guard) {
|
|
7
|
+
if (!source) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
7
10
|
if (guard != null) {
|
|
8
11
|
predicate = undefined;
|
|
9
12
|
}
|
|
10
13
|
if (!predicate) {
|
|
11
14
|
predicate = identity;
|
|
12
15
|
}
|
|
13
|
-
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
+
const values = Array.isArray(source) ? source : Object.values(source);
|
|
16
17
|
switch (typeof predicate) {
|
|
17
18
|
case 'function': {
|
|
18
|
-
|
|
19
|
+
if (!Array.isArray(source)) {
|
|
20
|
+
const keys = Object.keys(source);
|
|
21
|
+
for (let i = 0; i < keys.length; i++) {
|
|
22
|
+
const key = keys[i];
|
|
23
|
+
const value = source[key];
|
|
24
|
+
if (predicate(value, key, source)) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
return values.some(predicate);
|
|
19
31
|
}
|
|
20
32
|
case 'object': {
|
|
21
33
|
if (Array.isArray(predicate) && predicate.length === 2) {
|
|
22
34
|
const key = predicate[0];
|
|
23
35
|
const value = predicate[1];
|
|
24
|
-
return
|
|
36
|
+
return values.some(matchesProperty(key, value));
|
|
25
37
|
}
|
|
26
38
|
else {
|
|
27
|
-
return
|
|
39
|
+
return values.some(matches(predicate));
|
|
28
40
|
}
|
|
29
41
|
}
|
|
30
42
|
case 'string': {
|
|
31
|
-
return
|
|
43
|
+
return values.some(property(predicate));
|
|
32
44
|
}
|
|
33
45
|
}
|
|
34
46
|
}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @param {ArrayLike<T> | null | undefined} arr - The array to take elements from.
|
|
8
8
|
* @param {number} [count=1] - The number of elements to take.
|
|
9
|
+
* @param {unknown} [guard] - Enables use as an iteratee for methods like `_.map`.
|
|
9
10
|
* @returns {T[]} A new array containing the first `count` elements from `arr`.
|
|
10
11
|
*
|
|
11
12
|
* @example
|
|
@@ -20,6 +21,6 @@
|
|
|
20
21
|
* // Returns [1, 2, 3]
|
|
21
22
|
* take([1, 2, 3], 5);
|
|
22
23
|
*/
|
|
23
|
-
declare function take<T>(arr: ArrayLike<T> | null | undefined, count?: number): T[];
|
|
24
|
+
declare function take<T>(arr: ArrayLike<T> | null | undefined, count?: number, guard?: unknown): T[];
|
|
24
25
|
|
|
25
26
|
export { take };
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @param {ArrayLike<T> | null | undefined} arr - The array to take elements from.
|
|
8
8
|
* @param {number} [count=1] - The number of elements to take.
|
|
9
|
+
* @param {unknown} [guard] - Enables use as an iteratee for methods like `_.map`.
|
|
9
10
|
* @returns {T[]} A new array containing the first `count` elements from `arr`.
|
|
10
11
|
*
|
|
11
12
|
* @example
|
|
@@ -20,6 +21,6 @@
|
|
|
20
21
|
* // Returns [1, 2, 3]
|
|
21
22
|
* take([1, 2, 3], 5);
|
|
22
23
|
*/
|
|
23
|
-
declare function take<T>(arr: ArrayLike<T> | null | undefined, count?: number): T[];
|
|
24
|
+
declare function take<T>(arr: ArrayLike<T> | null | undefined, count?: number, guard?: unknown): T[];
|
|
24
25
|
|
|
25
26
|
export { take };
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { take as take$1 } from '../../array/take.mjs';
|
|
2
2
|
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
3
|
+
import { toInteger } from '../util/toInteger.mjs';
|
|
3
4
|
|
|
4
|
-
function take(arr, count = 1) {
|
|
5
|
+
function take(arr, count = 1, guard) {
|
|
6
|
+
count = guard ? 1 : toInteger(count);
|
|
5
7
|
if (count < 1 || !isArrayLike(arr)) {
|
|
6
8
|
return [];
|
|
7
9
|
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* @template T - The type of elements in the array.
|
|
6
6
|
* @param {ArrayLike<T> | null | undefined} arr - The array to take elements from.
|
|
7
7
|
* @param {number} [count=1] - The number of elements to take.
|
|
8
|
+
* @param {unknown} [guard] - Enables use as an iteratee for methods like `_.map`.
|
|
8
9
|
* @returns {T[]} A new array containing the last `count` elements from `arr`.
|
|
9
10
|
*
|
|
10
11
|
* @example
|
|
@@ -19,6 +20,6 @@
|
|
|
19
20
|
* // Returns [1, 2, 3]
|
|
20
21
|
* takeRight([1, 2, 3], 5);
|
|
21
22
|
*/
|
|
22
|
-
declare function takeRight<T>(arr: ArrayLike<T> | null | undefined, count?: number): T[];
|
|
23
|
+
declare function takeRight<T>(arr: ArrayLike<T> | null | undefined, count?: number, guard?: unknown): T[];
|
|
23
24
|
|
|
24
25
|
export { takeRight };
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* @template T - The type of elements in the array.
|
|
6
6
|
* @param {ArrayLike<T> | null | undefined} arr - The array to take elements from.
|
|
7
7
|
* @param {number} [count=1] - The number of elements to take.
|
|
8
|
+
* @param {unknown} [guard] - Enables use as an iteratee for methods like `_.map`.
|
|
8
9
|
* @returns {T[]} A new array containing the last `count` elements from `arr`.
|
|
9
10
|
*
|
|
10
11
|
* @example
|
|
@@ -19,6 +20,6 @@
|
|
|
19
20
|
* // Returns [1, 2, 3]
|
|
20
21
|
* takeRight([1, 2, 3], 5);
|
|
21
22
|
*/
|
|
22
|
-
declare function takeRight<T>(arr: ArrayLike<T> | null | undefined, count?: number): T[];
|
|
23
|
+
declare function takeRight<T>(arr: ArrayLike<T> | null | undefined, count?: number, guard?: unknown): T[];
|
|
23
24
|
|
|
24
25
|
export { takeRight };
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { takeRight as takeRight$1 } from '../../array/takeRight.mjs';
|
|
2
2
|
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
3
|
+
import { toInteger } from '../util/toInteger.mjs';
|
|
3
4
|
|
|
4
|
-
function takeRight(arr, count = 1) {
|
|
5
|
+
function takeRight(arr, count = 1, guard) {
|
|
6
|
+
count = guard ? 1 : toInteger(count);
|
|
5
7
|
if (count <= 0 || !isArrayLike(arr)) {
|
|
6
8
|
return [];
|
|
7
9
|
}
|