es-toolkit 1.22.0-dev.693 → 1.22.0-dev.695
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/dropWhile.d.mts +20 -0
- package/dist/compat/array/dropWhile.d.ts +20 -0
- package/dist/compat/array/filter.d.mts +10 -11
- package/dist/compat/array/filter.d.ts +10 -11
- package/dist/compat/array/filter.mjs +13 -0
- package/dist/compat/index.js +13 -0
- package/package.json +1 -1
|
@@ -7,6 +7,11 @@
|
|
|
7
7
|
* whether to continue dropping elements. The function is called with each element, index, and array, and dropping
|
|
8
8
|
* continues as long as it returns true.
|
|
9
9
|
* @returns {T[]} A new array with the elements remaining after the predicate returns false.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const array = [1, 2, 3, 4, 5];
|
|
13
|
+
* const result = dropWhile(array, x => x < 3);
|
|
14
|
+
* result will be [3, 4, 5] since elements less than 3 are dropped.
|
|
10
15
|
*/
|
|
11
16
|
declare function dropWhile<T>(arr: readonly T[], canContinueDropping: (item: T, index: number, arr: readonly T[]) => unknown): T[];
|
|
12
17
|
/**
|
|
@@ -16,6 +21,11 @@ declare function dropWhile<T>(arr: readonly T[], canContinueDropping: (item: T,
|
|
|
16
21
|
* @param {T[]} arr - The array from which to drop elements.
|
|
17
22
|
* @param {Partial<T>} objectToDrop - An object specifying the properties to match for dropping elements.
|
|
18
23
|
* @returns {T[]} A new array with the elements remaining after the predicate returns false.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* const array = [{ a: 1 }, { a: 2 }, { a: 3 }];
|
|
27
|
+
* const result = dropWhile(array, { a: 1 });
|
|
28
|
+
* result will be [{ a: 2 }, { a: 3 }] since the first object matches the properties of the provided object.
|
|
19
29
|
*/
|
|
20
30
|
declare function dropWhile<T>(arr: readonly T[], objectToDrop: Partial<T>): T[];
|
|
21
31
|
/**
|
|
@@ -25,6 +35,11 @@ declare function dropWhile<T>(arr: readonly T[], objectToDrop: Partial<T>): T[];
|
|
|
25
35
|
* @param {T[]} arr - The array from which to drop elements.
|
|
26
36
|
* @param {[keyof T, unknown]} propertyToDrop - A tuple containing the property key and the value to match for dropping elements.
|
|
27
37
|
* @returns {T[]} A new array with the elements remaining after the predicate returns false.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* const array = [{ id: 1 }, { id: 2 }, { id: 3 }];
|
|
41
|
+
* const result = dropWhile(array, ['id', 1]);
|
|
42
|
+
* result will be [{ id: 2 }, { id: 3 }] since the first object has the id property matching the value 1.
|
|
28
43
|
*/
|
|
29
44
|
declare function dropWhile<T>(arr: readonly T[], propertyToDrop: [keyof T, unknown]): T[];
|
|
30
45
|
/**
|
|
@@ -34,6 +49,11 @@ declare function dropWhile<T>(arr: readonly T[], propertyToDrop: [keyof T, unkno
|
|
|
34
49
|
* @param {T[]} arr - The array from which to drop elements.
|
|
35
50
|
* @param {string} propertyToDrop - The name of the property to match for dropping elements.
|
|
36
51
|
* @returns {T[]} A new array with the elements remaining after the predicate returns false.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* const array = [{ isActive: true }, { isActive: true }, { isActive: false }];
|
|
55
|
+
* const result = dropWhile(array, 'isActive');
|
|
56
|
+
* result will be [{ isActive: false }] since it drops elements until it finds one with a falsy isActive property.
|
|
37
57
|
*/
|
|
38
58
|
declare function dropWhile<T>(arr: readonly T[], propertyToDrop: string): T[];
|
|
39
59
|
|
|
@@ -7,6 +7,11 @@
|
|
|
7
7
|
* whether to continue dropping elements. The function is called with each element, index, and array, and dropping
|
|
8
8
|
* continues as long as it returns true.
|
|
9
9
|
* @returns {T[]} A new array with the elements remaining after the predicate returns false.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const array = [1, 2, 3, 4, 5];
|
|
13
|
+
* const result = dropWhile(array, x => x < 3);
|
|
14
|
+
* result will be [3, 4, 5] since elements less than 3 are dropped.
|
|
10
15
|
*/
|
|
11
16
|
declare function dropWhile<T>(arr: readonly T[], canContinueDropping: (item: T, index: number, arr: readonly T[]) => unknown): T[];
|
|
12
17
|
/**
|
|
@@ -16,6 +21,11 @@ declare function dropWhile<T>(arr: readonly T[], canContinueDropping: (item: T,
|
|
|
16
21
|
* @param {T[]} arr - The array from which to drop elements.
|
|
17
22
|
* @param {Partial<T>} objectToDrop - An object specifying the properties to match for dropping elements.
|
|
18
23
|
* @returns {T[]} A new array with the elements remaining after the predicate returns false.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* const array = [{ a: 1 }, { a: 2 }, { a: 3 }];
|
|
27
|
+
* const result = dropWhile(array, { a: 1 });
|
|
28
|
+
* result will be [{ a: 2 }, { a: 3 }] since the first object matches the properties of the provided object.
|
|
19
29
|
*/
|
|
20
30
|
declare function dropWhile<T>(arr: readonly T[], objectToDrop: Partial<T>): T[];
|
|
21
31
|
/**
|
|
@@ -25,6 +35,11 @@ declare function dropWhile<T>(arr: readonly T[], objectToDrop: Partial<T>): T[];
|
|
|
25
35
|
* @param {T[]} arr - The array from which to drop elements.
|
|
26
36
|
* @param {[keyof T, unknown]} propertyToDrop - A tuple containing the property key and the value to match for dropping elements.
|
|
27
37
|
* @returns {T[]} A new array with the elements remaining after the predicate returns false.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* const array = [{ id: 1 }, { id: 2 }, { id: 3 }];
|
|
41
|
+
* const result = dropWhile(array, ['id', 1]);
|
|
42
|
+
* result will be [{ id: 2 }, { id: 3 }] since the first object has the id property matching the value 1.
|
|
28
43
|
*/
|
|
29
44
|
declare function dropWhile<T>(arr: readonly T[], propertyToDrop: [keyof T, unknown]): T[];
|
|
30
45
|
/**
|
|
@@ -34,6 +49,11 @@ declare function dropWhile<T>(arr: readonly T[], propertyToDrop: [keyof T, unkno
|
|
|
34
49
|
* @param {T[]} arr - The array from which to drop elements.
|
|
35
50
|
* @param {string} propertyToDrop - The name of the property to match for dropping elements.
|
|
36
51
|
* @returns {T[]} A new array with the elements remaining after the predicate returns false.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* const array = [{ isActive: true }, { isActive: true }, { isActive: false }];
|
|
55
|
+
* const result = dropWhile(array, 'isActive');
|
|
56
|
+
* result will be [{ isActive: false }] since it drops elements until it finds one with a falsy isActive property.
|
|
37
57
|
*/
|
|
38
58
|
declare function dropWhile<T>(arr: readonly T[], propertyToDrop: string): T[];
|
|
39
59
|
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
* @param {T[]} arr - The array to iterate over.
|
|
6
6
|
* @param {(item: T, index: number, arr: T[]) => unknown} doesMatch - The function invoked per iteration.
|
|
7
7
|
* @returns {T[]} - Returns a new array of elements that satisfy the given doesMatch function.
|
|
8
|
-
|
|
9
8
|
*
|
|
10
9
|
* @example
|
|
11
10
|
* filter([1, 2, 3], n => n % 2 === 0)
|
|
@@ -30,7 +29,7 @@ declare function filter<T>(arr: readonly T[], doesMatch: Partial<T>): T[];
|
|
|
30
29
|
* Filters elements in a arr that match the given key-value pair.
|
|
31
30
|
*
|
|
32
31
|
* @template T
|
|
33
|
-
* @param {
|
|
32
|
+
* @param {T[]} arr - The array to iterate over.
|
|
34
33
|
* @param {[keyof T, unknown]} doesMatchProperty - The key-value pair to match.
|
|
35
34
|
* @returns {T[]} - Returns a new array of elements that match the given key-value pair.
|
|
36
35
|
*
|
|
@@ -44,7 +43,7 @@ declare function filter<T>(arr: readonly T[], doesMatchProperty: [keyof T, unkno
|
|
|
44
43
|
* Filters the arr, returning elements that contain the given property name.
|
|
45
44
|
*
|
|
46
45
|
* @template T
|
|
47
|
-
* @param {
|
|
46
|
+
* @param {T[]} arr - The array to iterate over.
|
|
48
47
|
* @param {string} propertyToCheck - The property name to check.
|
|
49
48
|
* @returns {T[]} - Returns a new array of elements that match the given property name.
|
|
50
49
|
*
|
|
@@ -58,25 +57,25 @@ declare function filter<T>(arr: readonly T[], propertyToCheck: string): T[];
|
|
|
58
57
|
* Filters items from a object and returns an array of elements that match the given predicate function.
|
|
59
58
|
*
|
|
60
59
|
* @template T
|
|
61
|
-
* @param {T
|
|
62
|
-
* @param {(
|
|
60
|
+
* @param {T} object - The object to iterate over.
|
|
61
|
+
* @param {(value: T[keyof T], key: keyof T, object: T) => unknown} doesMatch - The function invoked per iteration.
|
|
63
62
|
* @returns {T[]} - Returns a new array of elements that satisfy the given predicate function.
|
|
64
63
|
*
|
|
65
64
|
* @example
|
|
66
65
|
* const obj = { item1: { a: 0 }, item2: { a: 1 }, item3: { a: 0 } }
|
|
67
|
-
* filter(obj,
|
|
66
|
+
* filter(obj, value => value.a)
|
|
68
67
|
* // => [{ a: 1 }]
|
|
69
68
|
*
|
|
70
69
|
* const obj = { a: 1, b: 2, c: 3 };
|
|
71
|
-
* filter(obj,
|
|
70
|
+
* filter(obj, value => value > 2)
|
|
72
71
|
* // => [3]
|
|
73
72
|
*/
|
|
74
|
-
declare function filter<T extends Record<string, unknown>>(object: T, doesMatch: (
|
|
73
|
+
declare function filter<T extends Record<string, unknown>>(object: T, doesMatch: (value: T[keyof T], key: keyof T, object: T) => unknown): T[];
|
|
75
74
|
/**
|
|
76
75
|
* Filters elements in a object that match the properties of the given partial object.
|
|
77
76
|
*
|
|
78
77
|
* @template T
|
|
79
|
-
* @param {T
|
|
78
|
+
* @param {T} object - The object to iterate over.
|
|
80
79
|
* @param {Partial<T[keyof T]>} doesMatch - The partial object to match
|
|
81
80
|
* @returns {T[]} - Returns a new array of elements that match the given properties.pair.
|
|
82
81
|
*
|
|
@@ -90,7 +89,7 @@ declare function filter<T extends Record<string, unknown>>(object: T, doesMatch:
|
|
|
90
89
|
* Filters elements in a arr that match the given key-value pair.
|
|
91
90
|
*
|
|
92
91
|
* @template T
|
|
93
|
-
* @param {T
|
|
92
|
+
* @param {T} object - The object to iterate over.
|
|
94
93
|
* @param {[keyof T, unknown]} doesMatchProperty - The key-value pair to match.
|
|
95
94
|
* @returns {T[]} - Returns a new array of elements that match the given key-value pair.
|
|
96
95
|
*
|
|
@@ -104,7 +103,7 @@ declare function filter<T extends Record<string, unknown>>(object: T, doesMatchP
|
|
|
104
103
|
* Filters the object, returning elements that contain the given property name.
|
|
105
104
|
*
|
|
106
105
|
* @template T
|
|
107
|
-
* @param {T
|
|
106
|
+
* @param {T} object - The object to iterate over.
|
|
108
107
|
* @param {string} propertyToCheck - The property name to check.
|
|
109
108
|
* @returns {T[]} - Returns a new array of elements that match the given property name.
|
|
110
109
|
*
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
* @param {T[]} arr - The array to iterate over.
|
|
6
6
|
* @param {(item: T, index: number, arr: T[]) => unknown} doesMatch - The function invoked per iteration.
|
|
7
7
|
* @returns {T[]} - Returns a new array of elements that satisfy the given doesMatch function.
|
|
8
|
-
|
|
9
8
|
*
|
|
10
9
|
* @example
|
|
11
10
|
* filter([1, 2, 3], n => n % 2 === 0)
|
|
@@ -30,7 +29,7 @@ declare function filter<T>(arr: readonly T[], doesMatch: Partial<T>): T[];
|
|
|
30
29
|
* Filters elements in a arr that match the given key-value pair.
|
|
31
30
|
*
|
|
32
31
|
* @template T
|
|
33
|
-
* @param {
|
|
32
|
+
* @param {T[]} arr - The array to iterate over.
|
|
34
33
|
* @param {[keyof T, unknown]} doesMatchProperty - The key-value pair to match.
|
|
35
34
|
* @returns {T[]} - Returns a new array of elements that match the given key-value pair.
|
|
36
35
|
*
|
|
@@ -44,7 +43,7 @@ declare function filter<T>(arr: readonly T[], doesMatchProperty: [keyof T, unkno
|
|
|
44
43
|
* Filters the arr, returning elements that contain the given property name.
|
|
45
44
|
*
|
|
46
45
|
* @template T
|
|
47
|
-
* @param {
|
|
46
|
+
* @param {T[]} arr - The array to iterate over.
|
|
48
47
|
* @param {string} propertyToCheck - The property name to check.
|
|
49
48
|
* @returns {T[]} - Returns a new array of elements that match the given property name.
|
|
50
49
|
*
|
|
@@ -58,25 +57,25 @@ declare function filter<T>(arr: readonly T[], propertyToCheck: string): T[];
|
|
|
58
57
|
* Filters items from a object and returns an array of elements that match the given predicate function.
|
|
59
58
|
*
|
|
60
59
|
* @template T
|
|
61
|
-
* @param {T
|
|
62
|
-
* @param {(
|
|
60
|
+
* @param {T} object - The object to iterate over.
|
|
61
|
+
* @param {(value: T[keyof T], key: keyof T, object: T) => unknown} doesMatch - The function invoked per iteration.
|
|
63
62
|
* @returns {T[]} - Returns a new array of elements that satisfy the given predicate function.
|
|
64
63
|
*
|
|
65
64
|
* @example
|
|
66
65
|
* const obj = { item1: { a: 0 }, item2: { a: 1 }, item3: { a: 0 } }
|
|
67
|
-
* filter(obj,
|
|
66
|
+
* filter(obj, value => value.a)
|
|
68
67
|
* // => [{ a: 1 }]
|
|
69
68
|
*
|
|
70
69
|
* const obj = { a: 1, b: 2, c: 3 };
|
|
71
|
-
* filter(obj,
|
|
70
|
+
* filter(obj, value => value > 2)
|
|
72
71
|
* // => [3]
|
|
73
72
|
*/
|
|
74
|
-
declare function filter<T extends Record<string, unknown>>(object: T, doesMatch: (
|
|
73
|
+
declare function filter<T extends Record<string, unknown>>(object: T, doesMatch: (value: T[keyof T], key: keyof T, object: T) => unknown): T[];
|
|
75
74
|
/**
|
|
76
75
|
* Filters elements in a object that match the properties of the given partial object.
|
|
77
76
|
*
|
|
78
77
|
* @template T
|
|
79
|
-
* @param {T
|
|
78
|
+
* @param {T} object - The object to iterate over.
|
|
80
79
|
* @param {Partial<T[keyof T]>} doesMatch - The partial object to match
|
|
81
80
|
* @returns {T[]} - Returns a new array of elements that match the given properties.pair.
|
|
82
81
|
*
|
|
@@ -90,7 +89,7 @@ declare function filter<T extends Record<string, unknown>>(object: T, doesMatch:
|
|
|
90
89
|
* Filters elements in a arr that match the given key-value pair.
|
|
91
90
|
*
|
|
92
91
|
* @template T
|
|
93
|
-
* @param {T
|
|
92
|
+
* @param {T} object - The object to iterate over.
|
|
94
93
|
* @param {[keyof T, unknown]} doesMatchProperty - The key-value pair to match.
|
|
95
94
|
* @returns {T[]} - Returns a new array of elements that match the given key-value pair.
|
|
96
95
|
*
|
|
@@ -104,7 +103,7 @@ declare function filter<T extends Record<string, unknown>>(object: T, doesMatchP
|
|
|
104
103
|
* Filters the object, returning elements that contain the given property name.
|
|
105
104
|
*
|
|
106
105
|
* @template T
|
|
107
|
-
* @param {T
|
|
106
|
+
* @param {T} object - The object to iterate over.
|
|
108
107
|
* @param {string} propertyToCheck - The property name to check.
|
|
109
108
|
* @returns {T[]} - Returns a new array of elements that match the given property name.
|
|
110
109
|
*
|
|
@@ -11,6 +11,19 @@ function filter(source, predicate) {
|
|
|
11
11
|
const collection = isArray(source) ? source : Object.values(source);
|
|
12
12
|
switch (typeof predicate) {
|
|
13
13
|
case 'function': {
|
|
14
|
+
if (!Array.isArray(source)) {
|
|
15
|
+
const result = [];
|
|
16
|
+
const entries = Object.entries(source);
|
|
17
|
+
for (let i = 0; i < entries.length; i++) {
|
|
18
|
+
const entry = entries[i];
|
|
19
|
+
const key = entry[0];
|
|
20
|
+
const value = entry[1];
|
|
21
|
+
if (predicate(value, key, source)) {
|
|
22
|
+
result.push(value);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
14
27
|
return collection.filter(predicate);
|
|
15
28
|
}
|
|
16
29
|
case 'object': {
|
package/dist/compat/index.js
CHANGED
|
@@ -872,6 +872,19 @@ function filter(source, predicate) {
|
|
|
872
872
|
const collection = isArray(source) ? source : Object.values(source);
|
|
873
873
|
switch (typeof predicate) {
|
|
874
874
|
case 'function': {
|
|
875
|
+
if (!Array.isArray(source)) {
|
|
876
|
+
const result = [];
|
|
877
|
+
const entries = Object.entries(source);
|
|
878
|
+
for (let i = 0; i < entries.length; i++) {
|
|
879
|
+
const entry = entries[i];
|
|
880
|
+
const key = entry[0];
|
|
881
|
+
const value = entry[1];
|
|
882
|
+
if (predicate(value, key, source)) {
|
|
883
|
+
result.push(value);
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
return result;
|
|
887
|
+
}
|
|
875
888
|
return collection.filter(predicate);
|
|
876
889
|
}
|
|
877
890
|
case 'object': {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "es-toolkit",
|
|
3
3
|
"description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
|
|
4
|
-
"version": "1.22.0-dev.
|
|
4
|
+
"version": "1.22.0-dev.695+a093c732",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|