es-toolkit 1.21.0-dev.678 → 1.21.0-dev.680
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/_chunk/{zipWith-Cz3jdk.js → zipWith-EOU_KZ.js} +0 -39
- package/dist/array/index.d.mts +0 -1
- package/dist/array/index.d.ts +0 -1
- package/dist/array/index.js +1 -2
- package/dist/array/index.mjs +0 -1
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/array/every.d.mts +139 -0
- package/dist/compat/array/every.d.ts +139 -0
- package/dist/compat/array/every.mjs +49 -0
- package/dist/compat/array/find.d.mts +1 -1
- package/dist/compat/array/find.d.ts +1 -1
- package/dist/compat/function/flip.d.mts +18 -0
- package/dist/compat/function/flip.d.ts +18 -0
- package/dist/compat/function/flip.mjs +7 -0
- package/dist/compat/index.d.mts +2 -1
- package/dist/compat/index.d.ts +2 -1
- package/dist/compat/index.js +56 -6
- package/dist/compat/index.mjs +2 -1
- package/dist/index.d.mts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1 -2
- package/dist/index.mjs +0 -1
- package/package.json +1 -1
- package/dist/array/every.d.mts +0 -27
- package/dist/array/every.d.ts +0 -27
- package/dist/array/every.mjs +0 -39
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if all elements in an array are truthy.
|
|
3
|
+
*
|
|
4
|
+
* @template T
|
|
5
|
+
* @param {T[]} arr - The array to check through.
|
|
6
|
+
* @returns {boolean} - `true` if all elements are truthy, or `false` if at least one element is falsy.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const items = [1, 2, 3, 4];
|
|
10
|
+
* const result = every(items);
|
|
11
|
+
* console.log(result); // true
|
|
12
|
+
*
|
|
13
|
+
* const itemsWithFalsy = [1, 0, 3, 4];
|
|
14
|
+
* const resultWithFalsy = every(itemsWithFalsy);
|
|
15
|
+
* console.log(resultWithFalsy); // false
|
|
16
|
+
*/
|
|
17
|
+
declare function every<T>(arr: readonly T[]): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Checks if every item in an array matches the given predicate function.
|
|
20
|
+
*
|
|
21
|
+
* @template T
|
|
22
|
+
* @param {T[]} arr - The array to check through.
|
|
23
|
+
* @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.
|
|
24
|
+
* @returns {boolean} - `true` if every item matches the predicate, or `false` if at least one item does not match.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* // Using a predicate function
|
|
28
|
+
* const items = [1, 2, 3, 4, 5];
|
|
29
|
+
* const result = every(items, (item) => item > 0);
|
|
30
|
+
* console.log(result); // true
|
|
31
|
+
*/
|
|
32
|
+
declare function every<T>(arr: readonly T[], doesMatch: (item: T, index: number, arr: readonly T[]) => unknown): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Checks if every item in an array matches the given partial object.
|
|
35
|
+
*
|
|
36
|
+
* @template T
|
|
37
|
+
* @param {T[]} arr - The array to check through.
|
|
38
|
+
* @param {Partial<T>} doesMatch - A partial object that specifies the properties to match.
|
|
39
|
+
* @returns {boolean} - `true` if every item matches the partial object, or `false` if at least one item does not match.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* // Using a partial object
|
|
43
|
+
* const items = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
|
|
44
|
+
* const result = every(items, { name: 'Bob' });
|
|
45
|
+
* console.log(result); // false
|
|
46
|
+
*/
|
|
47
|
+
declare function every<T>(arr: readonly T[], doesMatch: Partial<T>): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Checks if every item in an array matches a property with a specific value.
|
|
50
|
+
*
|
|
51
|
+
* @template T
|
|
52
|
+
* @param {readonly T[]} arr - The array to check through.
|
|
53
|
+
* @param {[keyof T, unknown]} doesMatchProperty - An array where the first element is the property key and the second element is the value to match.
|
|
54
|
+
* @returns {boolean} - `true` if every item has the specified property value, or `false` if at least one item does not match.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* // Using a property-value pair
|
|
58
|
+
* const items = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
|
|
59
|
+
* const result = every(items, ['name', 'Alice']);
|
|
60
|
+
* console.log(result); // false
|
|
61
|
+
*/
|
|
62
|
+
declare function every<T>(arr: readonly T[], doesMatchProperty: [keyof T, unknown]): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Checks if every item in an array has a specific property, where the property name is provided as a string.
|
|
65
|
+
*
|
|
66
|
+
* @template T
|
|
67
|
+
* @param {readonly T[]} arr - The array to check through.
|
|
68
|
+
* @param {string} propertyToCheck - The property name to check.
|
|
69
|
+
* @returns {boolean} - `true` if every item has the specified property, or `false` if at least one item does not match.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* // Using a property name
|
|
73
|
+
* const items = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
|
|
74
|
+
* const result = every(items, 'name');
|
|
75
|
+
* console.log(result); // true
|
|
76
|
+
*/
|
|
77
|
+
declare function every<T>(arr: readonly T[], propertyToCheck: string): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Checks if every item in an object matches the given predicate function.
|
|
80
|
+
*
|
|
81
|
+
* @template T
|
|
82
|
+
* @param {T extends Record<string, unknown> ? T : never} object - The object to check through.
|
|
83
|
+
* @param {(item: T[keyof T], index: keyof T, 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.
|
|
84
|
+
* @returns {boolean} - `true` if every property value matches the predicate, or `false` if at least one does not match.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* // Using a predicate function
|
|
88
|
+
* const obj = { a: 1, b: 2, c: 3 };
|
|
89
|
+
* const result = every(obj, (item) => item > 0);
|
|
90
|
+
* console.log(result); // true
|
|
91
|
+
*/
|
|
92
|
+
declare function every<T extends Record<string, unknown>>(object: T, doesMatch: (item: T[keyof T], index: keyof T, object: T) => unknown): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Checks if every item in an object matches the given partial value.
|
|
95
|
+
*
|
|
96
|
+
* @template T
|
|
97
|
+
* @param {T extends Record<string, unknown> ? T : never} object - The object to check through.
|
|
98
|
+
* @param {Partial<T[keyof T]>} doesMatch - A partial value to match against the values of the object.
|
|
99
|
+
* @returns {boolean} - `true` if every property value matches the partial value, or `false` if at least one does not match.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* // Using a partial value
|
|
103
|
+
* const obj = { a: { id: 1, name: 'Alice' }, b: { id: 2, name: 'Bob' } };
|
|
104
|
+
* const result = every(obj, { name: 'Bob' });
|
|
105
|
+
* console.log(result); // false
|
|
106
|
+
*/
|
|
107
|
+
declare function every<T extends Record<string, unknown>>(object: T, doesMatch: Partial<T[keyof T]>): boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Checks if every item in an object matches a property with a specific value.
|
|
110
|
+
*
|
|
111
|
+
* @template T
|
|
112
|
+
* @param {readonly T[]} object - The object to check through.
|
|
113
|
+
* @param {[keyof T, unknown]} doesMatchProperty - An array where the first element is the property key and the second element is the value to match.
|
|
114
|
+
* @returns {boolean} - `true` if every item has the specified property value, or `false` if at least one item does not match.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* // Using a property-value pair
|
|
118
|
+
* const items = { alice: { id: 1, name: 'Alice' }, bob: { id: 2, name: 'Bob' } };
|
|
119
|
+
* const result = every(items, ['name', 'Alice']);
|
|
120
|
+
* console.log(result); // false
|
|
121
|
+
*/
|
|
122
|
+
declare function every<T extends Record<string, unknown>>(object: T, doesMatchProperty: [keyof T, unknown]): boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Checks if every item in an object has a specific property, where the property name is provided as a string.
|
|
125
|
+
*
|
|
126
|
+
* @template T
|
|
127
|
+
* @param {T extends Record<string, unknown> ? T : never} object - The object to check through.
|
|
128
|
+
* @param {string} propertyToCheck - The property name to check.
|
|
129
|
+
* @returns {boolean} - `true` if every property value has the specified property, or `false` if at least one does not match.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* // Using a property name
|
|
133
|
+
* const obj = { a: { id: 1, name: 'Alice' }, b: { id: 2, name: 'Bob' } };
|
|
134
|
+
* const result = every(obj, 'name');
|
|
135
|
+
* console.log(result); // true
|
|
136
|
+
*/
|
|
137
|
+
declare function every<T extends Record<string, unknown>>(object: T, propertyToCheck: string): boolean;
|
|
138
|
+
|
|
139
|
+
export { every };
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if all elements in an array are truthy.
|
|
3
|
+
*
|
|
4
|
+
* @template T
|
|
5
|
+
* @param {T[]} arr - The array to check through.
|
|
6
|
+
* @returns {boolean} - `true` if all elements are truthy, or `false` if at least one element is falsy.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const items = [1, 2, 3, 4];
|
|
10
|
+
* const result = every(items);
|
|
11
|
+
* console.log(result); // true
|
|
12
|
+
*
|
|
13
|
+
* const itemsWithFalsy = [1, 0, 3, 4];
|
|
14
|
+
* const resultWithFalsy = every(itemsWithFalsy);
|
|
15
|
+
* console.log(resultWithFalsy); // false
|
|
16
|
+
*/
|
|
17
|
+
declare function every<T>(arr: readonly T[]): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Checks if every item in an array matches the given predicate function.
|
|
20
|
+
*
|
|
21
|
+
* @template T
|
|
22
|
+
* @param {T[]} arr - The array to check through.
|
|
23
|
+
* @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.
|
|
24
|
+
* @returns {boolean} - `true` if every item matches the predicate, or `false` if at least one item does not match.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* // Using a predicate function
|
|
28
|
+
* const items = [1, 2, 3, 4, 5];
|
|
29
|
+
* const result = every(items, (item) => item > 0);
|
|
30
|
+
* console.log(result); // true
|
|
31
|
+
*/
|
|
32
|
+
declare function every<T>(arr: readonly T[], doesMatch: (item: T, index: number, arr: readonly T[]) => unknown): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Checks if every item in an array matches the given partial object.
|
|
35
|
+
*
|
|
36
|
+
* @template T
|
|
37
|
+
* @param {T[]} arr - The array to check through.
|
|
38
|
+
* @param {Partial<T>} doesMatch - A partial object that specifies the properties to match.
|
|
39
|
+
* @returns {boolean} - `true` if every item matches the partial object, or `false` if at least one item does not match.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* // Using a partial object
|
|
43
|
+
* const items = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
|
|
44
|
+
* const result = every(items, { name: 'Bob' });
|
|
45
|
+
* console.log(result); // false
|
|
46
|
+
*/
|
|
47
|
+
declare function every<T>(arr: readonly T[], doesMatch: Partial<T>): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Checks if every item in an array matches a property with a specific value.
|
|
50
|
+
*
|
|
51
|
+
* @template T
|
|
52
|
+
* @param {readonly T[]} arr - The array to check through.
|
|
53
|
+
* @param {[keyof T, unknown]} doesMatchProperty - An array where the first element is the property key and the second element is the value to match.
|
|
54
|
+
* @returns {boolean} - `true` if every item has the specified property value, or `false` if at least one item does not match.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* // Using a property-value pair
|
|
58
|
+
* const items = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
|
|
59
|
+
* const result = every(items, ['name', 'Alice']);
|
|
60
|
+
* console.log(result); // false
|
|
61
|
+
*/
|
|
62
|
+
declare function every<T>(arr: readonly T[], doesMatchProperty: [keyof T, unknown]): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Checks if every item in an array has a specific property, where the property name is provided as a string.
|
|
65
|
+
*
|
|
66
|
+
* @template T
|
|
67
|
+
* @param {readonly T[]} arr - The array to check through.
|
|
68
|
+
* @param {string} propertyToCheck - The property name to check.
|
|
69
|
+
* @returns {boolean} - `true` if every item has the specified property, or `false` if at least one item does not match.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* // Using a property name
|
|
73
|
+
* const items = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
|
|
74
|
+
* const result = every(items, 'name');
|
|
75
|
+
* console.log(result); // true
|
|
76
|
+
*/
|
|
77
|
+
declare function every<T>(arr: readonly T[], propertyToCheck: string): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Checks if every item in an object matches the given predicate function.
|
|
80
|
+
*
|
|
81
|
+
* @template T
|
|
82
|
+
* @param {T extends Record<string, unknown> ? T : never} object - The object to check through.
|
|
83
|
+
* @param {(item: T[keyof T], index: keyof T, 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.
|
|
84
|
+
* @returns {boolean} - `true` if every property value matches the predicate, or `false` if at least one does not match.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* // Using a predicate function
|
|
88
|
+
* const obj = { a: 1, b: 2, c: 3 };
|
|
89
|
+
* const result = every(obj, (item) => item > 0);
|
|
90
|
+
* console.log(result); // true
|
|
91
|
+
*/
|
|
92
|
+
declare function every<T extends Record<string, unknown>>(object: T, doesMatch: (item: T[keyof T], index: keyof T, object: T) => unknown): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Checks if every item in an object matches the given partial value.
|
|
95
|
+
*
|
|
96
|
+
* @template T
|
|
97
|
+
* @param {T extends Record<string, unknown> ? T : never} object - The object to check through.
|
|
98
|
+
* @param {Partial<T[keyof T]>} doesMatch - A partial value to match against the values of the object.
|
|
99
|
+
* @returns {boolean} - `true` if every property value matches the partial value, or `false` if at least one does not match.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* // Using a partial value
|
|
103
|
+
* const obj = { a: { id: 1, name: 'Alice' }, b: { id: 2, name: 'Bob' } };
|
|
104
|
+
* const result = every(obj, { name: 'Bob' });
|
|
105
|
+
* console.log(result); // false
|
|
106
|
+
*/
|
|
107
|
+
declare function every<T extends Record<string, unknown>>(object: T, doesMatch: Partial<T[keyof T]>): boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Checks if every item in an object matches a property with a specific value.
|
|
110
|
+
*
|
|
111
|
+
* @template T
|
|
112
|
+
* @param {readonly T[]} object - The object to check through.
|
|
113
|
+
* @param {[keyof T, unknown]} doesMatchProperty - An array where the first element is the property key and the second element is the value to match.
|
|
114
|
+
* @returns {boolean} - `true` if every item has the specified property value, or `false` if at least one item does not match.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* // Using a property-value pair
|
|
118
|
+
* const items = { alice: { id: 1, name: 'Alice' }, bob: { id: 2, name: 'Bob' } };
|
|
119
|
+
* const result = every(items, ['name', 'Alice']);
|
|
120
|
+
* console.log(result); // false
|
|
121
|
+
*/
|
|
122
|
+
declare function every<T extends Record<string, unknown>>(object: T, doesMatchProperty: [keyof T, unknown]): boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Checks if every item in an object has a specific property, where the property name is provided as a string.
|
|
125
|
+
*
|
|
126
|
+
* @template T
|
|
127
|
+
* @param {T extends Record<string, unknown> ? T : never} object - The object to check through.
|
|
128
|
+
* @param {string} propertyToCheck - The property name to check.
|
|
129
|
+
* @returns {boolean} - `true` if every property value has the specified property, or `false` if at least one does not match.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* // Using a property name
|
|
133
|
+
* const obj = { a: { id: 1, name: 'Alice' }, b: { id: 2, name: 'Bob' } };
|
|
134
|
+
* const result = every(obj, 'name');
|
|
135
|
+
* console.log(result); // true
|
|
136
|
+
*/
|
|
137
|
+
declare function every<T extends Record<string, unknown>>(object: T, propertyToCheck: string): boolean;
|
|
138
|
+
|
|
139
|
+
export { every };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { identity } from '../_internal/identity.mjs';
|
|
2
|
+
import { property } from '../object/property.mjs';
|
|
3
|
+
import { matches } from '../predicate/matches.mjs';
|
|
4
|
+
import { matchesProperty } from '../predicate/matchesProperty.mjs';
|
|
5
|
+
|
|
6
|
+
function every(source, doesMatch) {
|
|
7
|
+
if (!source) {
|
|
8
|
+
source = [];
|
|
9
|
+
}
|
|
10
|
+
let values = source;
|
|
11
|
+
if (!Array.isArray(source)) {
|
|
12
|
+
values = Object.values(source);
|
|
13
|
+
}
|
|
14
|
+
if (!doesMatch) {
|
|
15
|
+
doesMatch = identity;
|
|
16
|
+
}
|
|
17
|
+
switch (typeof doesMatch) {
|
|
18
|
+
case 'function': {
|
|
19
|
+
if (!Array.isArray(source)) {
|
|
20
|
+
const entries = Object.entries(source);
|
|
21
|
+
for (let i = 0; i < entries.length; i++) {
|
|
22
|
+
const entry = entries[i];
|
|
23
|
+
const key = entry[0];
|
|
24
|
+
const value = entry[1];
|
|
25
|
+
if (!doesMatch(value, key, source)) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
return values.every(doesMatch);
|
|
32
|
+
}
|
|
33
|
+
case 'object': {
|
|
34
|
+
if (Array.isArray(doesMatch) && doesMatch.length === 2) {
|
|
35
|
+
const key = doesMatch[0];
|
|
36
|
+
const value = doesMatch[1];
|
|
37
|
+
return values.every(matchesProperty(key, value));
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
return values.every(matches(doesMatch));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
case 'string': {
|
|
44
|
+
return values.every(property(doesMatch));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { every };
|
|
@@ -72,7 +72,7 @@ declare function find<T>(arr: readonly T[], propertyToCheck: string): T | undefi
|
|
|
72
72
|
* const result = find(obj, (item) => item > 2);
|
|
73
73
|
* console.log(result); // 3
|
|
74
74
|
*/
|
|
75
|
-
declare function find<T extends Record<string, unknown>>(object: T, doesMatch: (item: T[keyof T], index:
|
|
75
|
+
declare function find<T extends Record<string, unknown>>(object: T, doesMatch: (item: T[keyof T], index: keyof T, object: T) => unknown): T | undefined;
|
|
76
76
|
/**
|
|
77
77
|
* Finds the first item in an object that matches the given partial value.
|
|
78
78
|
*
|
|
@@ -72,7 +72,7 @@ declare function find<T>(arr: readonly T[], propertyToCheck: string): T | undefi
|
|
|
72
72
|
* const result = find(obj, (item) => item > 2);
|
|
73
73
|
* console.log(result); // 3
|
|
74
74
|
*/
|
|
75
|
-
declare function find<T extends Record<string, unknown>>(object: T, doesMatch: (item: T[keyof T], index:
|
|
75
|
+
declare function find<T extends Record<string, unknown>>(object: T, doesMatch: (item: T[keyof T], index: keyof T, object: T) => unknown): T | undefined;
|
|
76
76
|
/**
|
|
77
77
|
* Finds the first item in an object that matches the given partial value.
|
|
78
78
|
*
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a function that invokes `func` with arguments reversed.
|
|
3
|
+
*
|
|
4
|
+
* @param {F} func The function to flip arguments for.
|
|
5
|
+
* @returns {(...args: ReverseParameters<Parameters<F>>) => ReturnType<F>} Returns the new flipped function.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* function fn(a: any, b: any, c: any, d: any) {
|
|
9
|
+
* return [a, b, c, d];
|
|
10
|
+
* }
|
|
11
|
+
*
|
|
12
|
+
* const flipped = flip(fn);
|
|
13
|
+
* flipped('a', 'b', 'c', 'd'); // => ['d', 'c', 'b', 'a']
|
|
14
|
+
*/
|
|
15
|
+
declare function flip<F extends (...args: any[]) => any>(func: F): (...args: ReverseParameters<Parameters<F>>) => ReturnType<F>;
|
|
16
|
+
type ReverseParameters<T extends any[]> = T extends [infer First, ...infer Rest] ? [...ReverseParameters<Rest>, First] : [];
|
|
17
|
+
|
|
18
|
+
export { flip };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a function that invokes `func` with arguments reversed.
|
|
3
|
+
*
|
|
4
|
+
* @param {F} func The function to flip arguments for.
|
|
5
|
+
* @returns {(...args: ReverseParameters<Parameters<F>>) => ReturnType<F>} Returns the new flipped function.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* function fn(a: any, b: any, c: any, d: any) {
|
|
9
|
+
* return [a, b, c, d];
|
|
10
|
+
* }
|
|
11
|
+
*
|
|
12
|
+
* const flipped = flip(fn);
|
|
13
|
+
* flipped('a', 'b', 'c', 'd'); // => ['d', 'c', 'b', 'a']
|
|
14
|
+
*/
|
|
15
|
+
declare function flip<F extends (...args: any[]) => any>(func: F): (...args: ReverseParameters<Parameters<F>>) => ReturnType<F>;
|
|
16
|
+
type ReverseParameters<T extends any[]> = T extends [infer First, ...infer Rest] ? [...ReverseParameters<Rest>, First] : [];
|
|
17
|
+
|
|
18
|
+
export { flip };
|
package/dist/compat/index.d.mts
CHANGED
|
@@ -5,7 +5,6 @@ export { differenceBy } from '../array/differenceBy.mjs';
|
|
|
5
5
|
export { differenceWith } from '../array/differenceWith.mjs';
|
|
6
6
|
export { dropRight } from '../array/dropRight.mjs';
|
|
7
7
|
export { dropRightWhile } from '../array/dropRightWhile.mjs';
|
|
8
|
-
export { every } from '../array/every.mjs';
|
|
9
8
|
export { flatMap } from '../array/flatMap.mjs';
|
|
10
9
|
export { flatMapDeep } from '../array/flatMapDeep.mjs';
|
|
11
10
|
export { forEachRight } from '../array/forEachRight.mjs';
|
|
@@ -98,6 +97,7 @@ export { concat } from './array/concat.mjs';
|
|
|
98
97
|
export { difference } from './array/difference.mjs';
|
|
99
98
|
export { drop } from './array/drop.mjs';
|
|
100
99
|
export { dropWhile } from './array/dropWhile.mjs';
|
|
100
|
+
export { every } from './array/every.mjs';
|
|
101
101
|
export { fill } from './array/fill.mjs';
|
|
102
102
|
export { find } from './array/find.mjs';
|
|
103
103
|
export { findIndex } from './array/findIndex.mjs';
|
|
@@ -123,6 +123,7 @@ export { rearg } from './function/rearg.mjs';
|
|
|
123
123
|
export { curry } from './function/curry.mjs';
|
|
124
124
|
export { debounce } from './function/debounce.mjs';
|
|
125
125
|
export { throttle } from './function/throttle.mjs';
|
|
126
|
+
export { flip } from './function/flip.mjs';
|
|
126
127
|
export { get } from './object/get.mjs';
|
|
127
128
|
export { set } from './object/set.mjs';
|
|
128
129
|
export { pick } from './object/pick.mjs';
|
package/dist/compat/index.d.ts
CHANGED
|
@@ -5,7 +5,6 @@ export { differenceBy } from '../array/differenceBy.js';
|
|
|
5
5
|
export { differenceWith } from '../array/differenceWith.js';
|
|
6
6
|
export { dropRight } from '../array/dropRight.js';
|
|
7
7
|
export { dropRightWhile } from '../array/dropRightWhile.js';
|
|
8
|
-
export { every } from '../array/every.js';
|
|
9
8
|
export { flatMap } from '../array/flatMap.js';
|
|
10
9
|
export { flatMapDeep } from '../array/flatMapDeep.js';
|
|
11
10
|
export { forEachRight } from '../array/forEachRight.js';
|
|
@@ -98,6 +97,7 @@ export { concat } from './array/concat.js';
|
|
|
98
97
|
export { difference } from './array/difference.js';
|
|
99
98
|
export { drop } from './array/drop.js';
|
|
100
99
|
export { dropWhile } from './array/dropWhile.js';
|
|
100
|
+
export { every } from './array/every.js';
|
|
101
101
|
export { fill } from './array/fill.js';
|
|
102
102
|
export { find } from './array/find.js';
|
|
103
103
|
export { findIndex } from './array/findIndex.js';
|
|
@@ -123,6 +123,7 @@ export { rearg } from './function/rearg.js';
|
|
|
123
123
|
export { curry } from './function/curry.js';
|
|
124
124
|
export { debounce } from './function/debounce.js';
|
|
125
125
|
export { throttle } from './function/throttle.js';
|
|
126
|
+
export { flip } from './function/flip.js';
|
|
126
127
|
export { get } from './object/get.js';
|
|
127
128
|
export { set } from './object/set.js';
|
|
128
129
|
export { pick } from './object/pick.js';
|
package/dist/compat/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const zipWith = require('../_chunk/zipWith-
|
|
5
|
+
const zipWith = require('../_chunk/zipWith-EOU_KZ.js');
|
|
6
6
|
const promise_index = require('../_chunk/index-BGZDR9.js');
|
|
7
7
|
const flow = require('../_chunk/flow-Au34h2.js');
|
|
8
8
|
const range = require('../_chunk/range-BXlMmn.js');
|
|
@@ -389,6 +389,53 @@ function dropWhile(arr, predicate) {
|
|
|
389
389
|
}
|
|
390
390
|
}
|
|
391
391
|
|
|
392
|
+
function identity(x) {
|
|
393
|
+
return x;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function every(source, doesMatch) {
|
|
397
|
+
if (!source) {
|
|
398
|
+
source = [];
|
|
399
|
+
}
|
|
400
|
+
let values = source;
|
|
401
|
+
if (!Array.isArray(source)) {
|
|
402
|
+
values = Object.values(source);
|
|
403
|
+
}
|
|
404
|
+
if (!doesMatch) {
|
|
405
|
+
doesMatch = identity;
|
|
406
|
+
}
|
|
407
|
+
switch (typeof doesMatch) {
|
|
408
|
+
case 'function': {
|
|
409
|
+
if (!Array.isArray(source)) {
|
|
410
|
+
const entries = Object.entries(source);
|
|
411
|
+
for (let i = 0; i < entries.length; i++) {
|
|
412
|
+
const entry = entries[i];
|
|
413
|
+
const key = entry[0];
|
|
414
|
+
const value = entry[1];
|
|
415
|
+
if (!doesMatch(value, key, source)) {
|
|
416
|
+
return false;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return true;
|
|
420
|
+
}
|
|
421
|
+
return values.every(doesMatch);
|
|
422
|
+
}
|
|
423
|
+
case 'object': {
|
|
424
|
+
if (Array.isArray(doesMatch) && doesMatch.length === 2) {
|
|
425
|
+
const key = doesMatch[0];
|
|
426
|
+
const value = doesMatch[1];
|
|
427
|
+
return values.every(matchesProperty(key, value));
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
return values.every(matches(doesMatch));
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
case 'string': {
|
|
434
|
+
return values.every(property(doesMatch));
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
392
439
|
function fill(array, value, start = 0, end = array.length) {
|
|
393
440
|
start = Math.floor(start);
|
|
394
441
|
end = Math.floor(end);
|
|
@@ -682,10 +729,6 @@ function size(target) {
|
|
|
682
729
|
return Object.keys(target).length;
|
|
683
730
|
}
|
|
684
731
|
|
|
685
|
-
function identity(x) {
|
|
686
|
-
return x;
|
|
687
|
-
}
|
|
688
|
-
|
|
689
732
|
function some(arr, predicate, guard) {
|
|
690
733
|
if (guard != null) {
|
|
691
734
|
predicate = undefined;
|
|
@@ -965,6 +1008,12 @@ function throttle(func, throttleMs = 0, options = {}) {
|
|
|
965
1008
|
return debounce(func, throttleMs, { leading, trailing, signal, maxWait: throttleMs });
|
|
966
1009
|
}
|
|
967
1010
|
|
|
1011
|
+
function flip(func) {
|
|
1012
|
+
return function (...args) {
|
|
1013
|
+
return func.apply(this, args.reverse());
|
|
1014
|
+
};
|
|
1015
|
+
}
|
|
1016
|
+
|
|
968
1017
|
function isNil(x) {
|
|
969
1018
|
return x == null;
|
|
970
1019
|
}
|
|
@@ -1676,7 +1725,6 @@ exports.differenceBy = zipWith.differenceBy;
|
|
|
1676
1725
|
exports.differenceWith = zipWith.differenceWith;
|
|
1677
1726
|
exports.dropRight = zipWith.dropRight;
|
|
1678
1727
|
exports.dropRightWhile = zipWith.dropRightWhile;
|
|
1679
|
-
exports.every = zipWith.every;
|
|
1680
1728
|
exports.first = zipWith.head;
|
|
1681
1729
|
exports.flatMap = zipWith.flatMap;
|
|
1682
1730
|
exports.flatMapDeep = zipWith.flatMapDeep;
|
|
@@ -1785,6 +1833,7 @@ exports.difference = difference;
|
|
|
1785
1833
|
exports.drop = drop;
|
|
1786
1834
|
exports.dropWhile = dropWhile;
|
|
1787
1835
|
exports.endsWith = endsWith;
|
|
1836
|
+
exports.every = every;
|
|
1788
1837
|
exports.fill = fill;
|
|
1789
1838
|
exports.find = find;
|
|
1790
1839
|
exports.findIndex = findIndex;
|
|
@@ -1792,6 +1841,7 @@ exports.findLastIndex = findLastIndex;
|
|
|
1792
1841
|
exports.flatten = flatten;
|
|
1793
1842
|
exports.flattenDeep = flattenDeep;
|
|
1794
1843
|
exports.flattenDepth = flattenDepth;
|
|
1844
|
+
exports.flip = flip;
|
|
1795
1845
|
exports.floor = floor;
|
|
1796
1846
|
exports.fromPairs = fromPairs;
|
|
1797
1847
|
exports.get = get;
|
package/dist/compat/index.mjs
CHANGED
|
@@ -5,7 +5,6 @@ export { differenceBy } from '../array/differenceBy.mjs';
|
|
|
5
5
|
export { differenceWith } from '../array/differenceWith.mjs';
|
|
6
6
|
export { dropRight } from '../array/dropRight.mjs';
|
|
7
7
|
export { dropRightWhile } from '../array/dropRightWhile.mjs';
|
|
8
|
-
export { every } from '../array/every.mjs';
|
|
9
8
|
export { flatMap } from '../array/flatMap.mjs';
|
|
10
9
|
export { flatMapDeep } from '../array/flatMapDeep.mjs';
|
|
11
10
|
export { forEachRight } from '../array/forEachRight.mjs';
|
|
@@ -99,6 +98,7 @@ export { concat } from './array/concat.mjs';
|
|
|
99
98
|
export { difference } from './array/difference.mjs';
|
|
100
99
|
export { drop } from './array/drop.mjs';
|
|
101
100
|
export { dropWhile } from './array/dropWhile.mjs';
|
|
101
|
+
export { every } from './array/every.mjs';
|
|
102
102
|
export { fill } from './array/fill.mjs';
|
|
103
103
|
export { find } from './array/find.mjs';
|
|
104
104
|
export { findIndex } from './array/findIndex.mjs';
|
|
@@ -124,6 +124,7 @@ export { rearg } from './function/rearg.mjs';
|
|
|
124
124
|
export { curry } from './function/curry.mjs';
|
|
125
125
|
export { debounce } from './function/debounce.mjs';
|
|
126
126
|
export { throttle } from './function/throttle.mjs';
|
|
127
|
+
export { flip } from './function/flip.mjs';
|
|
127
128
|
export { get } from './object/get.mjs';
|
|
128
129
|
export { set } from './object/set.mjs';
|
|
129
130
|
export { pick } from './object/pick.mjs';
|
package/dist/index.d.mts
CHANGED
|
@@ -9,7 +9,6 @@ export { drop } from './array/drop.mjs';
|
|
|
9
9
|
export { dropRight } from './array/dropRight.mjs';
|
|
10
10
|
export { dropRightWhile } from './array/dropRightWhile.mjs';
|
|
11
11
|
export { dropWhile } from './array/dropWhile.mjs';
|
|
12
|
-
export { every } from './array/every.mjs';
|
|
13
12
|
export { fill } from './array/fill.mjs';
|
|
14
13
|
export { flatMap } from './array/flatMap.mjs';
|
|
15
14
|
export { flatMapDeep } from './array/flatMapDeep.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,6 @@ export { drop } from './array/drop.js';
|
|
|
9
9
|
export { dropRight } from './array/dropRight.js';
|
|
10
10
|
export { dropRightWhile } from './array/dropRightWhile.js';
|
|
11
11
|
export { dropWhile } from './array/dropWhile.js';
|
|
12
|
-
export { every } from './array/every.js';
|
|
13
12
|
export { fill } from './array/fill.js';
|
|
14
13
|
export { flatMap } from './array/flatMap.js';
|
|
15
14
|
export { flatMapDeep } from './array/flatMapDeep.js';
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const zipWith = require('./_chunk/zipWith-
|
|
5
|
+
const zipWith = require('./_chunk/zipWith-EOU_KZ.js');
|
|
6
6
|
const array_index = require('./array/index.js');
|
|
7
7
|
const promise_index = require('./_chunk/index-BGZDR9.js');
|
|
8
8
|
const flow = require('./_chunk/flow-Au34h2.js');
|
|
@@ -30,7 +30,6 @@ exports.differenceWith = zipWith.differenceWith;
|
|
|
30
30
|
exports.dropRight = zipWith.dropRight;
|
|
31
31
|
exports.dropRightWhile = zipWith.dropRightWhile;
|
|
32
32
|
exports.dropWhile = zipWith.dropWhile;
|
|
33
|
-
exports.every = zipWith.every;
|
|
34
33
|
exports.fill = zipWith.fill;
|
|
35
34
|
exports.flatMap = zipWith.flatMap;
|
|
36
35
|
exports.flatMapDeep = zipWith.flatMapDeep;
|
package/dist/index.mjs
CHANGED
|
@@ -9,7 +9,6 @@ export { drop } from './array/drop.mjs';
|
|
|
9
9
|
export { dropRight } from './array/dropRight.mjs';
|
|
10
10
|
export { dropRightWhile } from './array/dropRightWhile.mjs';
|
|
11
11
|
export { dropWhile } from './array/dropWhile.mjs';
|
|
12
|
-
export { every } from './array/every.mjs';
|
|
13
12
|
export { fill } from './array/fill.mjs';
|
|
14
13
|
export { flatMap } from './array/flatMap.mjs';
|
|
15
14
|
export { flatMapDeep } from './array/flatMapDeep.mjs';
|
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.21.0-dev.
|
|
4
|
+
"version": "1.21.0-dev.680+4e926752",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|
package/dist/array/every.d.mts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checks if all elements in a collection pass the predicate.
|
|
3
|
-
*
|
|
4
|
-
* Returns `true` if all elements in an array, object, or string satisfy the predicate,
|
|
5
|
-
* or if the collection is `null` or `undefined`.
|
|
6
|
-
*
|
|
7
|
-
* Note: Empty arrays `[]`, empty strings `''`, and empty objects `{}` return `true` by default.
|
|
8
|
-
*
|
|
9
|
-
* @template T The type of elements in the collection.
|
|
10
|
-
* @param {T[] | { [key: string]: T } | string | null | undefined} collection - The collection to check.
|
|
11
|
-
* @param {(value: T, indexOrKey: number | string) => boolean} predicate - The function to test each element.
|
|
12
|
-
* @returns {boolean} `true` if all elements pass the predicate, `false` otherwise.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* every([1, 2, 3], (value) => value > 0); // true
|
|
16
|
-
* @example
|
|
17
|
-
* every('abc', (char) => /[a-z]/.test(char)); // true
|
|
18
|
-
* @example
|
|
19
|
-
* every({ a: 1, b: 2 }, (value) => value > 0); // true
|
|
20
|
-
*/
|
|
21
|
-
declare function every<T>(collection: T[] | null | undefined, predicate: (value: T, index: number) => boolean): boolean;
|
|
22
|
-
declare function every<T>(collection: {
|
|
23
|
-
[key: string]: T;
|
|
24
|
-
} | null | undefined, predicate: (value: T, key: string) => boolean): boolean;
|
|
25
|
-
declare function every(collection: string | null | undefined, predicate: (value: string, index: number) => boolean): boolean;
|
|
26
|
-
|
|
27
|
-
export { every };
|