es-toolkit 1.37.2 → 1.38.0-dev.1285
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 +15 -0
- package/dist/_chunk/{snakeCase-BwvoPi.js → snakeCase-6cG1f4.js} +0 -1
- package/dist/_chunk/{unary-DzPndU.js → unary-BVQ0iC.js} +0 -16
- package/dist/_chunk/{upperFirst-C7IztG.js → upperFirst-Cx78bs.js} +1 -1
- package/dist/_chunk/{zip-CIqPLd.js → zip-Cyyp17.js} +10 -4
- package/dist/array/at.d.mts +1 -1
- package/dist/array/at.d.ts +1 -1
- package/dist/array/index.js +1 -1
- package/dist/array/maxBy.d.mts +2 -1
- package/dist/array/maxBy.d.ts +2 -1
- package/dist/array/maxBy.mjs +5 -2
- package/dist/array/minBy.d.mts +2 -1
- package/dist/array/minBy.d.ts +2 -1
- package/dist/array/minBy.mjs +5 -2
- package/dist/array/zip.d.mts +20 -0
- package/dist/array/zip.d.ts +20 -0
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/array/every.mjs +25 -16
- package/dist/compat/array/filter.mjs +9 -3
- package/dist/compat/array/invokeMap.d.mts +43 -0
- package/dist/compat/array/invokeMap.d.ts +43 -0
- package/dist/compat/array/invokeMap.mjs +36 -0
- package/dist/compat/array/some.mjs +36 -4
- package/dist/compat/array/sortedLastIndexOf.d.mts +35 -0
- package/dist/compat/array/sortedLastIndexOf.d.ts +35 -0
- package/dist/compat/array/sortedLastIndexOf.mjs +15 -0
- package/dist/compat/compat.d.mts +8 -2
- package/dist/compat/compat.d.ts +8 -2
- package/dist/compat/compat.mjs +8 -2
- package/dist/compat/function/memoize.d.mts +138 -0
- package/dist/compat/function/memoize.d.ts +138 -0
- package/dist/compat/function/memoize.mjs +21 -0
- package/dist/compat/index.d.mts +8 -2
- package/dist/compat/index.d.ts +8 -2
- package/dist/compat/index.js +425 -48
- package/dist/compat/index.mjs +8 -2
- package/dist/compat/math/max.d.mts +7 -5
- package/dist/compat/math/max.d.ts +7 -5
- package/dist/compat/math/max.mjs +12 -8
- package/dist/compat/math/min.d.mts +6 -5
- package/dist/compat/math/min.d.ts +6 -5
- package/dist/compat/math/min.mjs +12 -8
- package/dist/compat/object/clone.d.mts +31 -0
- package/dist/compat/object/clone.d.ts +31 -0
- package/dist/compat/object/clone.mjs +160 -0
- package/dist/compat/object/cloneWith.d.mts +48 -0
- package/dist/compat/object/cloneWith.d.ts +48 -0
- package/dist/compat/object/cloneWith.mjs +14 -0
- package/dist/compat/object/findKey.d.mts +1 -1
- package/dist/compat/object/findKey.d.ts +1 -1
- package/dist/compat/object/setWith.d.mts +25 -0
- package/dist/compat/object/setWith.d.ts +25 -0
- package/dist/compat/object/setWith.mjs +14 -0
- package/dist/compat/predicate/isNative.d.mts +18 -0
- package/dist/compat/predicate/isNative.d.ts +18 -0
- package/dist/compat/predicate/isNative.mjs +17 -0
- package/dist/compat/string/words.mjs +23 -3
- package/dist/compat/util/bindAll.d.mts +28 -0
- package/dist/compat/util/bindAll.d.ts +28 -0
- package/dist/compat/util/bindAll.mjs +43 -0
- package/dist/function/index.js +17 -2
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -5
- package/dist/index.mjs +1 -1
- package/dist/object/index.js +1 -1
- package/dist/string/index.js +2 -2
- package/dist/util/index.d.mts +1 -1
- package/dist/util/index.d.ts +1 -1
- package/dist/util/index.js +5 -1
- package/dist/util/index.mjs +1 -1
- package/dist/util/invariant.d.mts +21 -8
- package/dist/util/invariant.d.ts +21 -8
- package/dist/util/invariant.mjs +4 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# es-toolkit Changelog
|
|
2
2
|
|
|
3
|
+
## Version v1.38.0
|
|
4
|
+
|
|
5
|
+
Released on May 5th, 2025.
|
|
6
|
+
|
|
7
|
+
- Added compatibility functions for [bindAll](https://es-toolkit.slash.page/reference/compat/util/bindAll.html), [setWith](https://es-toolkit.slash.page/reference/compat/object/setWith.html), [memoize](https://es-toolkit.slash.page/reference/function/memoize.html), [isNative](https://es-toolkit.slash.page/reference/compat/predicate/isNative.html), [invokeMap](https://es-toolkit.slash.page/reference/compat/array/invokeMap.html), [clone](https://es-toolkit.slash.page/reference/object/clone.html), [cloneWith](https://es-toolkit.slash.page/reference/compat/object/cloneWith.html), and [sortedLastIndexOf](https://es-toolkit.slash.page/reference/compat/array/sortedLastIndexOf.html).
|
|
8
|
+
- Enhanced [invariant](https://es-toolkit.slash.page/reference/util/invariant.html) function to accept Error instances and added [assert](https://es-toolkit.slash.page/reference/util/assert.html) alias.
|
|
9
|
+
- Fixed type definitions and empty array handling in [maxBy](https://es-toolkit.slash.page/reference/array/maxBy.html) and [minBy](https://es-toolkit.slash.page/reference/array/minBy.html).
|
|
10
|
+
- Fixed typo 'Partail' to 'Partial' in [findKey](https://es-toolkit.slash.page/reference/object/findKey.html) type annotation.
|
|
11
|
+
- Enhanced [max](https://es-toolkit.slash.page/reference/math/max.html) and [min](https://es-toolkit.slash.page/reference/math/min.html) functions to skip NaN, symbol, and null values, and return undefined when all values are skipped.
|
|
12
|
+
- Fixed sparse array handling in compat functions to match Lodash's behavior.
|
|
13
|
+
- Improved test coverage and documentation for various functions.
|
|
14
|
+
- Fixed various documentation issues and typos.
|
|
15
|
+
|
|
16
|
+
We sincerely thank @myungjuice, @scato3, @uniqueeest, @YEONDG, @shren207, @hyesungoh, @kms0219kms, @minjongbaek, @kristian240, @D-Sketon, @Seung-wan, @jiji-hoon96, @raon0211, and @dayongkr for their contributions. We appreciate your great efforts!
|
|
17
|
+
|
|
3
18
|
## Version v1.37.2
|
|
4
19
|
|
|
5
20
|
Released on May 4th, 2025.
|
|
@@ -99,21 +99,6 @@ function identity(x) {
|
|
|
99
99
|
return x;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
function memoize(fn, options = {}) {
|
|
103
|
-
const { cache = new Map(), getCacheKey } = options;
|
|
104
|
-
const memoizedFn = function (arg) {
|
|
105
|
-
const key = getCacheKey ? getCacheKey(arg) : arg;
|
|
106
|
-
if (cache.has(key)) {
|
|
107
|
-
return cache.get(key);
|
|
108
|
-
}
|
|
109
|
-
const result = fn.call(this, arg);
|
|
110
|
-
cache.set(key, result);
|
|
111
|
-
return result;
|
|
112
|
-
};
|
|
113
|
-
memoizedFn.cache = cache;
|
|
114
|
-
return memoizedFn;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
102
|
function negate(func) {
|
|
118
103
|
return ((...args) => !func(...args));
|
|
119
104
|
}
|
|
@@ -193,7 +178,6 @@ exports.debounce = debounce;
|
|
|
193
178
|
exports.flow = flow;
|
|
194
179
|
exports.flowRight = flowRight;
|
|
195
180
|
exports.identity = identity;
|
|
196
|
-
exports.memoize = memoize;
|
|
197
181
|
exports.negate = negate;
|
|
198
182
|
exports.once = once;
|
|
199
183
|
exports.partial = partial;
|
|
@@ -151,9 +151,12 @@ function last(arr) {
|
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
function maxBy(items, getValue) {
|
|
154
|
+
if (items.length === 0) {
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
154
157
|
let maxElement = items[0];
|
|
155
|
-
let max =
|
|
156
|
-
for (let i =
|
|
158
|
+
let max = getValue(maxElement);
|
|
159
|
+
for (let i = 1; i < items.length; i++) {
|
|
157
160
|
const element = items[i];
|
|
158
161
|
const value = getValue(element);
|
|
159
162
|
if (value > max) {
|
|
@@ -165,9 +168,12 @@ function maxBy(items, getValue) {
|
|
|
165
168
|
}
|
|
166
169
|
|
|
167
170
|
function minBy(items, getValue) {
|
|
171
|
+
if (items.length === 0) {
|
|
172
|
+
return undefined;
|
|
173
|
+
}
|
|
168
174
|
let minElement = items[0];
|
|
169
|
-
let min =
|
|
170
|
-
for (let i =
|
|
175
|
+
let min = getValue(minElement);
|
|
176
|
+
for (let i = 1; i < items.length; i++) {
|
|
171
177
|
const element = items[i];
|
|
172
178
|
const value = getValue(element);
|
|
173
179
|
if (value < min) {
|
package/dist/array/at.d.mts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @template T
|
|
7
7
|
* @param {readonly T[]} arr - The array to retrieve elements from.
|
|
8
8
|
* @param {number[]} indices - An array of indices specifying the positions of elements to retrieve.
|
|
9
|
-
* @returns {
|
|
9
|
+
* @returns {T[]} A new array containing the elements at the specified indices.
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
12
|
* const numbers = [10, 20, 30, 40, 50];
|
package/dist/array/at.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @template T
|
|
7
7
|
* @param {readonly T[]} arr - The array to retrieve elements from.
|
|
8
8
|
* @param {number[]} indices - An array of indices specifying the positions of elements to retrieve.
|
|
9
|
-
* @returns {
|
|
9
|
+
* @returns {T[]} A new array containing the elements at the specified indices.
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
12
|
* const numbers = [10, 20, 30, 40, 50];
|
package/dist/array/index.js
CHANGED
package/dist/array/maxBy.d.mts
CHANGED
|
@@ -26,7 +26,8 @@ declare function maxBy<T>(items: readonly [T, ...T[]], getValue: (element: T) =>
|
|
|
26
26
|
* @template T - The type of elements in the array.
|
|
27
27
|
* @param {T[]} items The array of elements to search.
|
|
28
28
|
* @param {(element: T) => number} getValue A function that selects a numeric value from each element.
|
|
29
|
-
* @returns {T | undefined} The element with the maximum value as determined by the `getValue` function
|
|
29
|
+
* @returns {T | undefined} The element with the maximum value as determined by the `getValue` function,
|
|
30
|
+
* or `undefined` if the array is empty.
|
|
30
31
|
* @example
|
|
31
32
|
* maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }
|
|
32
33
|
* maxBy([], x => x.a); // Returns: undefined
|
package/dist/array/maxBy.d.ts
CHANGED
|
@@ -26,7 +26,8 @@ declare function maxBy<T>(items: readonly [T, ...T[]], getValue: (element: T) =>
|
|
|
26
26
|
* @template T - The type of elements in the array.
|
|
27
27
|
* @param {T[]} items The array of elements to search.
|
|
28
28
|
* @param {(element: T) => number} getValue A function that selects a numeric value from each element.
|
|
29
|
-
* @returns {T | undefined} The element with the maximum value as determined by the `getValue` function
|
|
29
|
+
* @returns {T | undefined} The element with the maximum value as determined by the `getValue` function,
|
|
30
|
+
* or `undefined` if the array is empty.
|
|
30
31
|
* @example
|
|
31
32
|
* maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }
|
|
32
33
|
* maxBy([], x => x.a); // Returns: undefined
|
package/dist/array/maxBy.mjs
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
function maxBy(items, getValue) {
|
|
2
|
+
if (items.length === 0) {
|
|
3
|
+
return undefined;
|
|
4
|
+
}
|
|
2
5
|
let maxElement = items[0];
|
|
3
|
-
let max =
|
|
4
|
-
for (let i =
|
|
6
|
+
let max = getValue(maxElement);
|
|
7
|
+
for (let i = 1; i < items.length; i++) {
|
|
5
8
|
const element = items[i];
|
|
6
9
|
const value = getValue(element);
|
|
7
10
|
if (value > max) {
|
package/dist/array/minBy.d.mts
CHANGED
|
@@ -26,7 +26,8 @@ declare function minBy<T>(items: readonly [T, ...T[]], getValue: (element: T) =>
|
|
|
26
26
|
* @template T - The type of elements in the array.
|
|
27
27
|
* @param {T[]} items The array of elements to search.
|
|
28
28
|
* @param {(element: T) => number} getValue A function that selects a numeric value from each element.
|
|
29
|
-
* @returns {T | undefined} The element with the minimum value as determined by the `getValue` function
|
|
29
|
+
* @returns {T | undefined} The element with the minimum value as determined by the `getValue` function,
|
|
30
|
+
* or `undefined` if the array is empty.
|
|
30
31
|
* @example
|
|
31
32
|
* minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 1 }
|
|
32
33
|
* minBy([], x => x.a); // Returns: undefined
|
package/dist/array/minBy.d.ts
CHANGED
|
@@ -26,7 +26,8 @@ declare function minBy<T>(items: readonly [T, ...T[]], getValue: (element: T) =>
|
|
|
26
26
|
* @template T - The type of elements in the array.
|
|
27
27
|
* @param {T[]} items The array of elements to search.
|
|
28
28
|
* @param {(element: T) => number} getValue A function that selects a numeric value from each element.
|
|
29
|
-
* @returns {T | undefined} The element with the minimum value as determined by the `getValue` function
|
|
29
|
+
* @returns {T | undefined} The element with the minimum value as determined by the `getValue` function,
|
|
30
|
+
* or `undefined` if the array is empty.
|
|
30
31
|
* @example
|
|
31
32
|
* minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 1 }
|
|
32
33
|
* minBy([], x => x.a); // Returns: undefined
|
package/dist/array/minBy.mjs
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
function minBy(items, getValue) {
|
|
2
|
+
if (items.length === 0) {
|
|
3
|
+
return undefined;
|
|
4
|
+
}
|
|
2
5
|
let minElement = items[0];
|
|
3
|
-
let min =
|
|
4
|
-
for (let i =
|
|
6
|
+
let min = getValue(minElement);
|
|
7
|
+
for (let i = 1; i < items.length; i++) {
|
|
5
8
|
const element = items[i];
|
|
6
9
|
const value = getValue(element);
|
|
7
10
|
if (value < min) {
|
package/dist/array/zip.d.mts
CHANGED
|
@@ -82,5 +82,25 @@ declare function zip<T, U, V>(arr1: readonly T[], arr2: readonly U[], arr3: read
|
|
|
82
82
|
* // result will be [[1, 'a', true, null], [2, 'b', false, null], [3, 'c', undefined, null]]
|
|
83
83
|
*/
|
|
84
84
|
declare function zip<T, U, V, W>(arr1: readonly T[], arr2: readonly U[], arr3: readonly V[], arr4: readonly W[]): Array<[T, U, V, W]>;
|
|
85
|
+
/**
|
|
86
|
+
* Combines multiple arrays into a single array of tuples.
|
|
87
|
+
*
|
|
88
|
+
* This function takes multiple arrays and returns a new array where each element is a tuple
|
|
89
|
+
* containing the corresponding elements from the input arrays. If the input arrays are of
|
|
90
|
+
* different lengths, the resulting array will have the length of the longest input array,
|
|
91
|
+
* with undefined values for missing elements.
|
|
92
|
+
*
|
|
93
|
+
* @template T
|
|
94
|
+
* @param {...Array<readonly T[]>} arrs - The arrays to zip together.
|
|
95
|
+
* @returns {T[][]} A new array of tuples containing the corresponding elements from the input arrays.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* const arr1 = [1, 2, 3];
|
|
99
|
+
* const arr2 = ['a', 'b', 'c'];
|
|
100
|
+
* const arr3 = [true, false];
|
|
101
|
+
* const result = zip(arr1, arr2, arr3);
|
|
102
|
+
* // result will be [[1, 'a', true], [2, 'b', false], [3, 'c', undefined]]
|
|
103
|
+
*/
|
|
104
|
+
declare function zip<T>(...arrs: Array<readonly T[]>): T[][];
|
|
85
105
|
|
|
86
106
|
export { zip };
|
package/dist/array/zip.d.ts
CHANGED
|
@@ -82,5 +82,25 @@ declare function zip<T, U, V>(arr1: readonly T[], arr2: readonly U[], arr3: read
|
|
|
82
82
|
* // result will be [[1, 'a', true, null], [2, 'b', false, null], [3, 'c', undefined, null]]
|
|
83
83
|
*/
|
|
84
84
|
declare function zip<T, U, V, W>(arr1: readonly T[], arr2: readonly U[], arr3: readonly V[], arr4: readonly W[]): Array<[T, U, V, W]>;
|
|
85
|
+
/**
|
|
86
|
+
* Combines multiple arrays into a single array of tuples.
|
|
87
|
+
*
|
|
88
|
+
* This function takes multiple arrays and returns a new array where each element is a tuple
|
|
89
|
+
* containing the corresponding elements from the input arrays. If the input arrays are of
|
|
90
|
+
* different lengths, the resulting array will have the length of the longest input array,
|
|
91
|
+
* with undefined values for missing elements.
|
|
92
|
+
*
|
|
93
|
+
* @template T
|
|
94
|
+
* @param {...Array<readonly T[]>} arrs - The arrays to zip together.
|
|
95
|
+
* @returns {T[][]} A new array of tuples containing the corresponding elements from the input arrays.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* const arr1 = [1, 2, 3];
|
|
99
|
+
* const arr2 = ['a', 'b', 'c'];
|
|
100
|
+
* const arr3 = [true, false];
|
|
101
|
+
* const result = zip(arr1, arr2, arr3);
|
|
102
|
+
* // result will be [[1, 'a', true], [2, 'b', false], [3, 'c', undefined]]
|
|
103
|
+
*/
|
|
104
|
+
declare function zip<T>(...arrs: Array<readonly T[]>): T[][];
|
|
85
105
|
|
|
86
106
|
export { zip };
|