es-toolkit 1.25.2 → 1.26.0-dev.828
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 +11 -0
- package/dist/_chunk/{sumBy-BkErWJ.js → sumBy-RVppiV.js} +21 -0
- package/dist/_chunk/{toMerged-BLnW4M.js → toMerged-wNz52b.js} +2 -2
- package/dist/_chunk/{unary-CMvKXy.js → unary-CcTNuC.js} +5 -0
- 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.d.mts +2 -2
- package/dist/compat/array/every.d.ts +2 -2
- package/dist/compat/array/every.mjs +6 -2
- package/dist/compat/array/filter.d.mts +3 -3
- package/dist/compat/array/filter.d.ts +3 -3
- package/dist/compat/array/filter.mjs +1 -1
- package/dist/compat/array/find.d.mts +6 -6
- package/dist/compat/array/find.d.ts +6 -6
- package/dist/compat/array/intersectionBy.d.mts +111 -0
- package/dist/compat/array/intersectionBy.d.ts +111 -0
- package/dist/compat/array/intersectionBy.mjs +36 -0
- package/dist/compat/array/orderBy.d.mts +3 -2
- package/dist/compat/array/orderBy.d.ts +3 -2
- package/dist/compat/array/orderBy.mjs +7 -3
- package/dist/compat/array/some.d.mts +68 -21
- package/dist/compat/array/some.d.ts +68 -21
- package/dist/compat/array/some.mjs +21 -9
- package/dist/compat/array/sortBy.d.mts +3 -3
- package/dist/compat/array/sortBy.d.ts +3 -3
- package/dist/compat/array/sortBy.mjs +11 -2
- 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/array/zipObjectDeep.d.mts +2 -4
- package/dist/compat/array/zipObjectDeep.d.ts +2 -4
- package/dist/compat/index.d.mts +7 -1
- package/dist/compat/index.d.ts +7 -1
- package/dist/compat/index.js +218 -70
- package/dist/compat/index.mjs +7 -1
- package/dist/compat/object/invertBy.mjs +1 -1
- package/dist/compat/object/mapKeys.mjs +1 -1
- package/dist/compat/object/mapValues.mjs +1 -1
- package/dist/compat/string/template.d.mts +89 -0
- package/dist/compat/string/template.d.ts +89 -0
- package/dist/compat/string/template.mjs +86 -0
- package/dist/compat/util/uniqueId.d.mts +25 -0
- package/dist/compat/util/uniqueId.d.ts +25 -0
- package/dist/compat/util/uniqueId.mjs +7 -0
- package/dist/function/identity.d.mts +22 -0
- package/dist/function/identity.d.ts +22 -0
- package/dist/function/index.d.mts +1 -0
- package/dist/function/index.d.ts +1 -0
- package/dist/function/index.js +2 -1
- package/dist/function/index.mjs +1 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +8 -3
- package/dist/index.mjs +4 -0
- package/dist/math/index.d.mts +2 -0
- package/dist/math/index.d.ts +2 -0
- package/dist/math/index.js +3 -1
- package/dist/math/index.mjs +2 -0
- package/dist/math/median.d.mts +25 -0
- package/dist/math/median.d.ts +25 -0
- package/dist/math/median.mjs +15 -0
- package/dist/math/medianBy.d.mts +23 -0
- package/dist/math/medianBy.d.ts +23 -0
- package/dist/math/medianBy.mjs +8 -0
- package/dist/object/cloneDeep.mjs +2 -2
- package/dist/object/index.js +1 -1
- package/dist/object/merge.d.mts +1 -1
- package/dist/object/merge.d.ts +1 -1
- package/dist/util/index.d.mts +1 -0
- package/dist/util/index.d.ts +1 -0
- package/dist/util/index.js +12 -0
- package/dist/util/index.mjs +1 -0
- package/dist/util/invariant.d.mts +27 -0
- package/dist/util/invariant.d.ts +27 -0
- package/dist/util/invariant.mjs +8 -0
- package/package.json +21 -1
- package/util.d.ts +1 -0
- /package/dist/{compat/_internal → function}/identity.mjs +0 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates the median of an array of elements when applying
|
|
3
|
+
* the `getValue` function to each element.
|
|
4
|
+
*
|
|
5
|
+
* The median is the middle value of a sorted array.
|
|
6
|
+
* If the array has an odd number of elements, the median is the middle value.
|
|
7
|
+
* If the array has an even number of elements, it returns the average of the two middle values.
|
|
8
|
+
*
|
|
9
|
+
* If the array is empty, this function returns `NaN`.
|
|
10
|
+
*
|
|
11
|
+
* @template T - The type of elements in the array.
|
|
12
|
+
* @param {T[]} items An array to calculate the median.
|
|
13
|
+
* @param {(element: T) => number} getValue A function that selects a numeric value from each element.
|
|
14
|
+
* @returns {number} The median of all the numbers as determined by the `getValue` function.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* medianBy([{ a: 1 }, { a: 2 }, { a: 3 }, { a: 4 }, { a: 5 }], x => x.a); // Returns: 3
|
|
18
|
+
* medianBy([{ a: 1 }, { a: 2 }, { a: 3 }, { a: 4 }], x => x.a); // Returns: 2.5
|
|
19
|
+
* medianBy([], x => x.a); // Returns: NaN
|
|
20
|
+
*/
|
|
21
|
+
declare function medianBy<T>(items: readonly T[], getValue: (element: T) => number): number;
|
|
22
|
+
|
|
23
|
+
export { medianBy };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates the median of an array of elements when applying
|
|
3
|
+
* the `getValue` function to each element.
|
|
4
|
+
*
|
|
5
|
+
* The median is the middle value of a sorted array.
|
|
6
|
+
* If the array has an odd number of elements, the median is the middle value.
|
|
7
|
+
* If the array has an even number of elements, it returns the average of the two middle values.
|
|
8
|
+
*
|
|
9
|
+
* If the array is empty, this function returns `NaN`.
|
|
10
|
+
*
|
|
11
|
+
* @template T - The type of elements in the array.
|
|
12
|
+
* @param {T[]} items An array to calculate the median.
|
|
13
|
+
* @param {(element: T) => number} getValue A function that selects a numeric value from each element.
|
|
14
|
+
* @returns {number} The median of all the numbers as determined by the `getValue` function.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* medianBy([{ a: 1 }, { a: 2 }, { a: 3 }, { a: 4 }, { a: 5 }], x => x.a); // Returns: 3
|
|
18
|
+
* medianBy([{ a: 1 }, { a: 2 }, { a: 3 }, { a: 4 }], x => x.a); // Returns: 2.5
|
|
19
|
+
* medianBy([], x => x.a); // Returns: NaN
|
|
20
|
+
*/
|
|
21
|
+
declare function medianBy<T>(items: readonly T[], getValue: (element: T) => number): number;
|
|
22
|
+
|
|
23
|
+
export { medianBy };
|
|
@@ -37,7 +37,7 @@ function cloneDeepImpl(obj, stack = new Map()) {
|
|
|
37
37
|
if (obj instanceof Map) {
|
|
38
38
|
const result = new Map();
|
|
39
39
|
stack.set(obj, result);
|
|
40
|
-
for (const [key, value] of obj
|
|
40
|
+
for (const [key, value] of obj) {
|
|
41
41
|
result.set(key, cloneDeepImpl(value, stack));
|
|
42
42
|
}
|
|
43
43
|
return result;
|
|
@@ -45,7 +45,7 @@ function cloneDeepImpl(obj, stack = new Map()) {
|
|
|
45
45
|
if (obj instanceof Set) {
|
|
46
46
|
const result = new Set();
|
|
47
47
|
stack.set(obj, result);
|
|
48
|
-
for (const value of obj
|
|
48
|
+
for (const value of obj) {
|
|
49
49
|
result.add(cloneDeepImpl(value, stack));
|
|
50
50
|
}
|
|
51
51
|
return result;
|
package/dist/object/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const toMerged = require('../_chunk/toMerged-
|
|
5
|
+
const toMerged = require('../_chunk/toMerged-wNz52b.js');
|
|
6
6
|
|
|
7
7
|
function mergeWith(target, source, merge) {
|
|
8
8
|
const sourceKeys = Object.keys(source);
|
package/dist/object/merge.d.mts
CHANGED
|
@@ -38,6 +38,6 @@
|
|
|
38
38
|
* console.log(result);
|
|
39
39
|
* // Output: { a: [1, 2, 3] }
|
|
40
40
|
*/
|
|
41
|
-
declare function merge<T, S
|
|
41
|
+
declare function merge<T extends Record<PropertyKey, any>, S extends Record<PropertyKey, any>>(target: T, source: S): T & S;
|
|
42
42
|
|
|
43
43
|
export { merge };
|
package/dist/object/merge.d.ts
CHANGED
|
@@ -38,6 +38,6 @@
|
|
|
38
38
|
* console.log(result);
|
|
39
39
|
* // Output: { a: [1, 2, 3] }
|
|
40
40
|
*/
|
|
41
|
-
declare function merge<T, S
|
|
41
|
+
declare function merge<T extends Record<PropertyKey, any>, S extends Record<PropertyKey, any>>(target: T, source: S): T & S;
|
|
42
42
|
|
|
43
43
|
export { merge };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { invariant } from './invariant.mjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { invariant } from './invariant.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { invariant } from './invariant.mjs';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asserts that a given condition is true. If the condition is false, an error is thrown with the provided message.
|
|
3
|
+
*
|
|
4
|
+
* @param {unknown} condition - The condition to evaluate.
|
|
5
|
+
* @param {string} [message] - The error message to throw if the condition is false.
|
|
6
|
+
* @returns {void} Returns void if the condition is true.
|
|
7
|
+
* @throws {Error} Throws an error if the condition is false.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* // This call will succeed without any errors
|
|
11
|
+
* invariant(true, 'This should not throw');
|
|
12
|
+
*
|
|
13
|
+
* // This call will fail and throw an error with the message 'This should throw'
|
|
14
|
+
* invariant(false, 'This should throw');
|
|
15
|
+
*
|
|
16
|
+
* // Example of using invariant with a condition
|
|
17
|
+
* invariant(condition, 'Expected condition is false');
|
|
18
|
+
*
|
|
19
|
+
* // Ensure that the value is neither null nor undefined
|
|
20
|
+
* invariant(value !== null && value !== undefined, 'Value should not be null or undefined');
|
|
21
|
+
*
|
|
22
|
+
* // Example of using invariant to check if a number is positive
|
|
23
|
+
* invariant(number > 0, 'Number must be positive');
|
|
24
|
+
*/
|
|
25
|
+
declare function invariant(condition: unknown, message: string): asserts condition;
|
|
26
|
+
|
|
27
|
+
export { invariant };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asserts that a given condition is true. If the condition is false, an error is thrown with the provided message.
|
|
3
|
+
*
|
|
4
|
+
* @param {unknown} condition - The condition to evaluate.
|
|
5
|
+
* @param {string} [message] - The error message to throw if the condition is false.
|
|
6
|
+
* @returns {void} Returns void if the condition is true.
|
|
7
|
+
* @throws {Error} Throws an error if the condition is false.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* // This call will succeed without any errors
|
|
11
|
+
* invariant(true, 'This should not throw');
|
|
12
|
+
*
|
|
13
|
+
* // This call will fail and throw an error with the message 'This should throw'
|
|
14
|
+
* invariant(false, 'This should throw');
|
|
15
|
+
*
|
|
16
|
+
* // Example of using invariant with a condition
|
|
17
|
+
* invariant(condition, 'Expected condition is false');
|
|
18
|
+
*
|
|
19
|
+
* // Ensure that the value is neither null nor undefined
|
|
20
|
+
* invariant(value !== null && value !== undefined, 'Value should not be null or undefined');
|
|
21
|
+
*
|
|
22
|
+
* // Example of using invariant to check if a number is positive
|
|
23
|
+
* invariant(number > 0, 'Number must be positive');
|
|
24
|
+
*/
|
|
25
|
+
declare function invariant(condition: unknown, message: string): asserts condition;
|
|
26
|
+
|
|
27
|
+
export { invariant };
|
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.
|
|
4
|
+
"version": "1.26.0-dev.828+eb01f788",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|
|
@@ -95,6 +95,16 @@
|
|
|
95
95
|
"default": "./dist/string/index.js"
|
|
96
96
|
}
|
|
97
97
|
},
|
|
98
|
+
"./util": {
|
|
99
|
+
"import": {
|
|
100
|
+
"types": "./dist/util/index.d.mts",
|
|
101
|
+
"default": "./dist/util/index.mjs"
|
|
102
|
+
},
|
|
103
|
+
"require": {
|
|
104
|
+
"types": "./dist/util/index.d.ts",
|
|
105
|
+
"default": "./dist/util/index.js"
|
|
106
|
+
}
|
|
107
|
+
},
|
|
98
108
|
"./compat": {
|
|
99
109
|
"import": {
|
|
100
110
|
"types": "./dist/compat/index.d.mts",
|
|
@@ -198,6 +208,16 @@
|
|
|
198
208
|
"default": "./dist/string/index.js"
|
|
199
209
|
}
|
|
200
210
|
},
|
|
211
|
+
"./util": {
|
|
212
|
+
"import": {
|
|
213
|
+
"types": "./dist/util/index.d.mts",
|
|
214
|
+
"default": "./dist/util/index.mjs"
|
|
215
|
+
},
|
|
216
|
+
"require": {
|
|
217
|
+
"types": "./dist/util/index.d.ts",
|
|
218
|
+
"default": "./dist/util/index.js"
|
|
219
|
+
}
|
|
220
|
+
},
|
|
201
221
|
"./compat": {
|
|
202
222
|
"import": {
|
|
203
223
|
"types": "./dist/compat/index.d.mts",
|
package/util.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/util';
|
|
File without changes
|