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/dist/compat/index.mjs
CHANGED
|
@@ -30,6 +30,7 @@ export { initial } from './array/initial.mjs';
|
|
|
30
30
|
export { intersection } from './array/intersection.mjs';
|
|
31
31
|
export { intersectionBy } from './array/intersectionBy.mjs';
|
|
32
32
|
export { intersectionWith } from './array/intersectionWith.mjs';
|
|
33
|
+
export { invokeMap } from './array/invokeMap.mjs';
|
|
33
34
|
export { join } from './array/join.mjs';
|
|
34
35
|
export { keyBy } from './array/keyBy.mjs';
|
|
35
36
|
export { last } from './array/last.mjs';
|
|
@@ -60,6 +61,7 @@ export { sortedIndexBy } from './array/sortedIndexBy.mjs';
|
|
|
60
61
|
export { sortedIndexOf } from './array/sortedIndexOf.mjs';
|
|
61
62
|
export { sortedLastIndex } from './array/sortedLastIndex.mjs';
|
|
62
63
|
export { sortedLastIndexBy } from './array/sortedLastIndexBy.mjs';
|
|
64
|
+
export { sortedLastIndexOf } from './array/sortedLastIndexOf.mjs';
|
|
63
65
|
export { tail } from './array/tail.mjs';
|
|
64
66
|
export { take } from './array/take.mjs';
|
|
65
67
|
export { takeRight } from './array/takeRight.mjs';
|
|
@@ -95,7 +97,7 @@ export { delay } from './function/delay.mjs';
|
|
|
95
97
|
export { flip } from './function/flip.mjs';
|
|
96
98
|
export { flow } from './function/flow.mjs';
|
|
97
99
|
export { flowRight } from './function/flowRight.mjs';
|
|
98
|
-
export { memoize } from '
|
|
100
|
+
export { memoize } from './function/memoize.mjs';
|
|
99
101
|
export { negate } from './function/negate.mjs';
|
|
100
102
|
export { nthArg } from './function/nthArg.mjs';
|
|
101
103
|
export { once } from '../function/once.mjs';
|
|
@@ -133,9 +135,10 @@ export { assignIn, assignIn as extend } from './object/assignIn.mjs';
|
|
|
133
135
|
export { assignInWith, assignInWith as extendWith } from './object/assignInWith.mjs';
|
|
134
136
|
export { assignWith } from './object/assignWith.mjs';
|
|
135
137
|
export { at } from './object/at.mjs';
|
|
136
|
-
export { clone } from '
|
|
138
|
+
export { clone } from './object/clone.mjs';
|
|
137
139
|
export { cloneDeep } from './object/cloneDeep.mjs';
|
|
138
140
|
export { cloneDeepWith } from './object/cloneDeepWith.mjs';
|
|
141
|
+
export { cloneWith } from './object/cloneWith.mjs';
|
|
139
142
|
export { create } from './object/create.mjs';
|
|
140
143
|
export { defaults } from './object/defaults.mjs';
|
|
141
144
|
export { findKey } from './object/findKey.mjs';
|
|
@@ -155,6 +158,7 @@ export { invertBy } from './object/invertBy.mjs';
|
|
|
155
158
|
export { isEqual } from '../predicate/isEqual.mjs';
|
|
156
159
|
export { isFunction } from '../predicate/isFunction.mjs';
|
|
157
160
|
export { isLength } from '../predicate/isLength.mjs';
|
|
161
|
+
export { isNative } from './predicate/isNative.mjs';
|
|
158
162
|
export { isNull } from '../predicate/isNull.mjs';
|
|
159
163
|
export { isUndefined } from '../predicate/isUndefined.mjs';
|
|
160
164
|
export { keys } from './object/keys.mjs';
|
|
@@ -172,6 +176,7 @@ export { property } from './object/property.mjs';
|
|
|
172
176
|
export { propertyOf } from './object/propertyOf.mjs';
|
|
173
177
|
export { result } from './object/result.mjs';
|
|
174
178
|
export { set } from './object/set.mjs';
|
|
179
|
+
export { setWith } from './object/setWith.mjs';
|
|
175
180
|
export { toDefaulted } from './object/toDefaulted.mjs';
|
|
176
181
|
export { toPairs } from './object/toPairs.mjs';
|
|
177
182
|
export { toPairsIn } from './object/toPairsIn.mjs';
|
|
@@ -181,6 +186,7 @@ export { update } from './object/update.mjs';
|
|
|
181
186
|
export { updateWith } from './object/updateWith.mjs';
|
|
182
187
|
export { values } from './object/values.mjs';
|
|
183
188
|
export { valuesIn } from './object/valuesIn.mjs';
|
|
189
|
+
export { bindAll } from './util/bindAll.mjs';
|
|
184
190
|
export { capitalize } from '../string/capitalize.mjs';
|
|
185
191
|
export { conforms } from './predicate/conforms.mjs';
|
|
186
192
|
export { conformsTo } from './predicate/conformsTo.mjs';
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Finds the element in an array that has the maximum value.
|
|
3
3
|
*
|
|
4
|
+
* @template T - The type of elements in the array.
|
|
4
5
|
* @param {[T, ...T[]]} items - The array of elements to search.
|
|
5
|
-
* @returns {T
|
|
6
|
+
* @returns {T} - The element with the maximum value.
|
|
6
7
|
* @example
|
|
7
8
|
* // Returns 9
|
|
8
9
|
* max([3, 1, 4, 1, 5, 9]);
|
|
@@ -15,16 +16,17 @@ declare function max<T>(items: readonly [T, ...T[]]): T;
|
|
|
15
16
|
/**
|
|
16
17
|
* Finds the element in an array that has the maximum value.
|
|
17
18
|
* Returns undefined when no arguments are provided.
|
|
18
|
-
*
|
|
19
|
+
*
|
|
20
|
+
* @returns {undefined} - Returns `undefined` when the function is called with no arguments.
|
|
19
21
|
*/
|
|
20
22
|
declare function max(): undefined;
|
|
21
23
|
/**
|
|
22
24
|
* Finds the element in an array that has the maximum value.
|
|
23
25
|
*
|
|
24
26
|
* @template T - The type of elements in the array.
|
|
25
|
-
* @param {T
|
|
26
|
-
* @returns {T | undefined} - The element with the maximum value, or undefined if the array is empty
|
|
27
|
+
* @param {ArrayLike<T> | null | undefined} [items] - The array of elements to search.
|
|
28
|
+
* @returns {T | undefined} - The element with the maximum value, or `undefined` if the array is empty, `null`, or `undefined`.
|
|
27
29
|
*/
|
|
28
|
-
declare function max<T>(items?:
|
|
30
|
+
declare function max<T>(items?: ArrayLike<T> | null | undefined): T | undefined;
|
|
29
31
|
|
|
30
32
|
export { max };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Finds the element in an array that has the maximum value.
|
|
3
3
|
*
|
|
4
|
+
* @template T - The type of elements in the array.
|
|
4
5
|
* @param {[T, ...T[]]} items - The array of elements to search.
|
|
5
|
-
* @returns {T
|
|
6
|
+
* @returns {T} - The element with the maximum value.
|
|
6
7
|
* @example
|
|
7
8
|
* // Returns 9
|
|
8
9
|
* max([3, 1, 4, 1, 5, 9]);
|
|
@@ -15,16 +16,17 @@ declare function max<T>(items: readonly [T, ...T[]]): T;
|
|
|
15
16
|
/**
|
|
16
17
|
* Finds the element in an array that has the maximum value.
|
|
17
18
|
* Returns undefined when no arguments are provided.
|
|
18
|
-
*
|
|
19
|
+
*
|
|
20
|
+
* @returns {undefined} - Returns `undefined` when the function is called with no arguments.
|
|
19
21
|
*/
|
|
20
22
|
declare function max(): undefined;
|
|
21
23
|
/**
|
|
22
24
|
* Finds the element in an array that has the maximum value.
|
|
23
25
|
*
|
|
24
26
|
* @template T - The type of elements in the array.
|
|
25
|
-
* @param {T
|
|
26
|
-
* @returns {T | undefined} - The element with the maximum value, or undefined if the array is empty
|
|
27
|
+
* @param {ArrayLike<T> | null | undefined} [items] - The array of elements to search.
|
|
28
|
+
* @returns {T | undefined} - The element with the maximum value, or `undefined` if the array is empty, `null`, or `undefined`.
|
|
27
29
|
*/
|
|
28
|
-
declare function max<T>(items?:
|
|
30
|
+
declare function max<T>(items?: ArrayLike<T> | null | undefined): T | undefined;
|
|
29
31
|
|
|
30
32
|
export { max };
|
package/dist/compat/math/max.mjs
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
function max(items
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
function max(items) {
|
|
2
|
+
if (!items || items.length === 0) {
|
|
3
|
+
return undefined;
|
|
4
|
+
}
|
|
5
|
+
let maxResult = undefined;
|
|
4
6
|
for (let i = 0; i < items.length; i++) {
|
|
5
|
-
const
|
|
6
|
-
if (
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const current = items[i];
|
|
8
|
+
if (current == null || Number.isNaN(current) || typeof current === 'symbol') {
|
|
9
|
+
continue;
|
|
10
|
+
}
|
|
11
|
+
if (maxResult === undefined || current > maxResult) {
|
|
12
|
+
maxResult = current;
|
|
9
13
|
}
|
|
10
14
|
}
|
|
11
|
-
return
|
|
15
|
+
return maxResult;
|
|
12
16
|
}
|
|
13
17
|
|
|
14
18
|
export { max };
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @template T - The type of elements in the array.
|
|
5
5
|
* @param {[T, ...T[]]} items - The array of elements to search.
|
|
6
|
-
* @returns {T
|
|
6
|
+
* @returns {T} - The element with the minimum value.
|
|
7
7
|
* @example
|
|
8
8
|
* // Returns 1
|
|
9
9
|
* min([3, 1, 4, 1, 5, 9]);
|
|
@@ -16,16 +16,17 @@ declare function min<T>(items: readonly [T, ...T[]]): T;
|
|
|
16
16
|
/**
|
|
17
17
|
* Finds the element in an array that has the minimum value.
|
|
18
18
|
* Returns undefined when no arguments are provided.
|
|
19
|
-
*
|
|
19
|
+
*
|
|
20
|
+
* @returns {undefined} - Returns `undefined` when the function is called with no arguments.
|
|
20
21
|
*/
|
|
21
22
|
declare function min(): undefined;
|
|
22
23
|
/**
|
|
23
24
|
* Finds the element in an array that has the minimum value.
|
|
24
25
|
*
|
|
25
26
|
* @template T - The type of elements in the array.
|
|
26
|
-
* @param {T
|
|
27
|
-
* @returns {T | undefined} - The element with the minimum value, or undefined if the array is empty
|
|
27
|
+
* @param {ArrayLike<T> | null | undefined} [items] - The array of elements to search.
|
|
28
|
+
* @returns {T | undefined} - The element with the minimum value, or `undefined` if the array is empty, `null`, or `undefined`.
|
|
28
29
|
*/
|
|
29
|
-
declare function min<T>(items?:
|
|
30
|
+
declare function min<T>(items?: ArrayLike<T> | null | undefined): T | undefined;
|
|
30
31
|
|
|
31
32
|
export { min };
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @template T - The type of elements in the array.
|
|
5
5
|
* @param {[T, ...T[]]} items - The array of elements to search.
|
|
6
|
-
* @returns {T
|
|
6
|
+
* @returns {T} - The element with the minimum value.
|
|
7
7
|
* @example
|
|
8
8
|
* // Returns 1
|
|
9
9
|
* min([3, 1, 4, 1, 5, 9]);
|
|
@@ -16,16 +16,17 @@ declare function min<T>(items: readonly [T, ...T[]]): T;
|
|
|
16
16
|
/**
|
|
17
17
|
* Finds the element in an array that has the minimum value.
|
|
18
18
|
* Returns undefined when no arguments are provided.
|
|
19
|
-
*
|
|
19
|
+
*
|
|
20
|
+
* @returns {undefined} - Returns `undefined` when the function is called with no arguments.
|
|
20
21
|
*/
|
|
21
22
|
declare function min(): undefined;
|
|
22
23
|
/**
|
|
23
24
|
* Finds the element in an array that has the minimum value.
|
|
24
25
|
*
|
|
25
26
|
* @template T - The type of elements in the array.
|
|
26
|
-
* @param {T
|
|
27
|
-
* @returns {T | undefined} - The element with the minimum value, or undefined if the array is empty
|
|
27
|
+
* @param {ArrayLike<T> | null | undefined} [items] - The array of elements to search.
|
|
28
|
+
* @returns {T | undefined} - The element with the minimum value, or `undefined` if the array is empty, `null`, or `undefined`.
|
|
28
29
|
*/
|
|
29
|
-
declare function min<T>(items?:
|
|
30
|
+
declare function min<T>(items?: ArrayLike<T> | null | undefined): T | undefined;
|
|
30
31
|
|
|
31
32
|
export { min };
|
package/dist/compat/math/min.mjs
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
function min(items
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
function min(items) {
|
|
2
|
+
if (!items || items.length === 0) {
|
|
3
|
+
return undefined;
|
|
4
|
+
}
|
|
5
|
+
let minResult = undefined;
|
|
4
6
|
for (let i = 0; i < items.length; i++) {
|
|
5
|
-
const
|
|
6
|
-
if (
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const current = items[i];
|
|
8
|
+
if (current == null || Number.isNaN(current) || typeof current === 'symbol') {
|
|
9
|
+
continue;
|
|
10
|
+
}
|
|
11
|
+
if (minResult === undefined || current < minResult) {
|
|
12
|
+
minResult = current;
|
|
9
13
|
}
|
|
10
14
|
}
|
|
11
|
-
return
|
|
15
|
+
return minResult;
|
|
12
16
|
}
|
|
13
17
|
|
|
14
18
|
export { min };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a shallow clone of the given object.
|
|
3
|
+
*
|
|
4
|
+
* @template T - The type of the object.
|
|
5
|
+
* @param {T} obj - The object to clone.
|
|
6
|
+
* @returns {T} - A shallow clone of the given object.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* // Clone a primitive objs
|
|
10
|
+
* const num = 29;
|
|
11
|
+
* const clonedNum = clone(num);
|
|
12
|
+
* console.log(clonedNum); // 29
|
|
13
|
+
* console.log(clonedNum === num) ; // true
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // Clone an array
|
|
17
|
+
* const arr = [1, 2, 3];
|
|
18
|
+
* const clonedArr = clone(arr);
|
|
19
|
+
* console.log(clonedArr); // [1, 2, 3]
|
|
20
|
+
* console.log(clonedArr === arr); // false
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // Clone an object
|
|
24
|
+
* const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] };
|
|
25
|
+
* const clonedObj = clone(obj);
|
|
26
|
+
* console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] }
|
|
27
|
+
* console.log(clonedObj === obj); // false
|
|
28
|
+
*/
|
|
29
|
+
declare function clone<T>(obj: T): T;
|
|
30
|
+
|
|
31
|
+
export { clone };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a shallow clone of the given object.
|
|
3
|
+
*
|
|
4
|
+
* @template T - The type of the object.
|
|
5
|
+
* @param {T} obj - The object to clone.
|
|
6
|
+
* @returns {T} - A shallow clone of the given object.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* // Clone a primitive objs
|
|
10
|
+
* const num = 29;
|
|
11
|
+
* const clonedNum = clone(num);
|
|
12
|
+
* console.log(clonedNum); // 29
|
|
13
|
+
* console.log(clonedNum === num) ; // true
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // Clone an array
|
|
17
|
+
* const arr = [1, 2, 3];
|
|
18
|
+
* const clonedArr = clone(arr);
|
|
19
|
+
* console.log(clonedArr); // [1, 2, 3]
|
|
20
|
+
* console.log(clonedArr === arr); // false
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // Clone an object
|
|
24
|
+
* const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] };
|
|
25
|
+
* const clonedObj = clone(obj);
|
|
26
|
+
* console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] }
|
|
27
|
+
* console.log(clonedObj === obj); // false
|
|
28
|
+
*/
|
|
29
|
+
declare function clone<T>(obj: T): T;
|
|
30
|
+
|
|
31
|
+
export { clone };
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { isPrimitive } from '../../predicate/isPrimitive.mjs';
|
|
2
|
+
import { getTag } from '../_internal/getTag.mjs';
|
|
3
|
+
import { arrayBufferTag, dataViewTag, booleanTag, numberTag, stringTag, dateTag, regexpTag, symbolTag, mapTag, setTag, argumentsTag, uint32ArrayTag, uint16ArrayTag, uint8ClampedArrayTag, uint8ArrayTag, objectTag, int32ArrayTag, int16ArrayTag, int8ArrayTag, float64ArrayTag, float32ArrayTag, arrayTag } from '../_internal/tags.mjs';
|
|
4
|
+
import { isArray } from '../predicate/isArray.mjs';
|
|
5
|
+
import { isTypedArray } from '../predicate/isTypedArray.mjs';
|
|
6
|
+
|
|
7
|
+
function clone(obj) {
|
|
8
|
+
if (isPrimitive(obj)) {
|
|
9
|
+
return obj;
|
|
10
|
+
}
|
|
11
|
+
const tag = getTag(obj);
|
|
12
|
+
if (!isCloneableObject(obj)) {
|
|
13
|
+
return {};
|
|
14
|
+
}
|
|
15
|
+
if (isArray(obj)) {
|
|
16
|
+
const result = Array.from(obj);
|
|
17
|
+
if (obj.length > 0 && typeof obj[0] === 'string' && Object.hasOwn(obj, 'index')) {
|
|
18
|
+
result.index = obj.index;
|
|
19
|
+
result.input = obj.input;
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
if (isTypedArray(obj)) {
|
|
24
|
+
const typedArray = obj;
|
|
25
|
+
const Ctor = typedArray.constructor;
|
|
26
|
+
return new Ctor(typedArray.buffer, typedArray.byteOffset, typedArray.length);
|
|
27
|
+
}
|
|
28
|
+
if (tag === arrayBufferTag) {
|
|
29
|
+
return new ArrayBuffer(obj.byteLength);
|
|
30
|
+
}
|
|
31
|
+
if (tag === dataViewTag) {
|
|
32
|
+
const dataView = obj;
|
|
33
|
+
const buffer = dataView.buffer;
|
|
34
|
+
const byteOffset = dataView.byteOffset;
|
|
35
|
+
const byteLength = dataView.byteLength;
|
|
36
|
+
const clonedBuffer = new ArrayBuffer(byteLength);
|
|
37
|
+
const srcView = new Uint8Array(buffer, byteOffset, byteLength);
|
|
38
|
+
const destView = new Uint8Array(clonedBuffer);
|
|
39
|
+
destView.set(srcView);
|
|
40
|
+
return new DataView(clonedBuffer);
|
|
41
|
+
}
|
|
42
|
+
if (tag === booleanTag || tag === numberTag || tag === stringTag) {
|
|
43
|
+
const Ctor = obj.constructor;
|
|
44
|
+
const clone = new Ctor(obj.valueOf());
|
|
45
|
+
if (tag === stringTag) {
|
|
46
|
+
cloneStringObjectProperties(clone, obj);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
copyOwnProperties(clone, obj);
|
|
50
|
+
}
|
|
51
|
+
return clone;
|
|
52
|
+
}
|
|
53
|
+
if (tag === dateTag) {
|
|
54
|
+
return new Date(Number(obj));
|
|
55
|
+
}
|
|
56
|
+
if (tag === regexpTag) {
|
|
57
|
+
const regExp = obj;
|
|
58
|
+
const clone = new RegExp(regExp.source, regExp.flags);
|
|
59
|
+
clone.lastIndex = regExp.lastIndex;
|
|
60
|
+
return clone;
|
|
61
|
+
}
|
|
62
|
+
if (tag === symbolTag) {
|
|
63
|
+
return Object(Symbol.prototype.valueOf.call(obj));
|
|
64
|
+
}
|
|
65
|
+
if (tag === mapTag) {
|
|
66
|
+
const map = obj;
|
|
67
|
+
const result = new Map();
|
|
68
|
+
map.forEach((obj, key) => {
|
|
69
|
+
result.set(key, obj);
|
|
70
|
+
});
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
if (tag === setTag) {
|
|
74
|
+
const set = obj;
|
|
75
|
+
const result = new Set();
|
|
76
|
+
set.forEach(obj => {
|
|
77
|
+
result.add(obj);
|
|
78
|
+
});
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
if (tag === argumentsTag) {
|
|
82
|
+
const args = obj;
|
|
83
|
+
const result = {};
|
|
84
|
+
copyOwnProperties(result, args);
|
|
85
|
+
result.length = args.length;
|
|
86
|
+
result[Symbol.iterator] = args[Symbol.iterator];
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
const result = {};
|
|
90
|
+
copyPrototype(result, obj);
|
|
91
|
+
copyOwnProperties(result, obj);
|
|
92
|
+
copySymbolProperties(result, obj);
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
function isCloneableObject(object) {
|
|
96
|
+
switch (getTag(object)) {
|
|
97
|
+
case argumentsTag:
|
|
98
|
+
case arrayTag:
|
|
99
|
+
case arrayBufferTag:
|
|
100
|
+
case dataViewTag:
|
|
101
|
+
case booleanTag:
|
|
102
|
+
case dateTag:
|
|
103
|
+
case float32ArrayTag:
|
|
104
|
+
case float64ArrayTag:
|
|
105
|
+
case int8ArrayTag:
|
|
106
|
+
case int16ArrayTag:
|
|
107
|
+
case int32ArrayTag:
|
|
108
|
+
case mapTag:
|
|
109
|
+
case numberTag:
|
|
110
|
+
case objectTag:
|
|
111
|
+
case regexpTag:
|
|
112
|
+
case setTag:
|
|
113
|
+
case stringTag:
|
|
114
|
+
case symbolTag:
|
|
115
|
+
case uint8ArrayTag:
|
|
116
|
+
case uint8ClampedArrayTag:
|
|
117
|
+
case uint16ArrayTag:
|
|
118
|
+
case uint32ArrayTag: {
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
default: {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function copyOwnProperties(target, source) {
|
|
127
|
+
for (const key in source) {
|
|
128
|
+
if (Object.hasOwn(source, key)) {
|
|
129
|
+
target[key] = source[key];
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function copySymbolProperties(target, source) {
|
|
134
|
+
const symbols = Object.getOwnPropertySymbols(source);
|
|
135
|
+
for (let i = 0; i < symbols.length; i++) {
|
|
136
|
+
const symbol = symbols[i];
|
|
137
|
+
if (Object.prototype.propertyIsEnumerable.call(source, symbol)) {
|
|
138
|
+
target[symbol] = source[symbol];
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
function cloneStringObjectProperties(target, source) {
|
|
143
|
+
const stringLength = source.valueOf().length;
|
|
144
|
+
for (const key in source) {
|
|
145
|
+
if (Object.hasOwn(source, key) && (Number.isNaN(Number(key)) || Number(key) >= stringLength)) {
|
|
146
|
+
target[key] = source[key];
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function copyPrototype(target, source) {
|
|
151
|
+
const proto = Object.getPrototypeOf(source);
|
|
152
|
+
if (proto !== null) {
|
|
153
|
+
const Ctor = source.constructor;
|
|
154
|
+
if (typeof Ctor === 'function') {
|
|
155
|
+
Object.setPrototypeOf(target, proto);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export { clone };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a shallow clone of the given object with customization.
|
|
3
|
+
* This method is like `_.clone` except that it accepts a customizer which
|
|
4
|
+
* is invoked to produce the cloned value. If customizer returns undefined,
|
|
5
|
+
* cloning is handled by the method instead.
|
|
6
|
+
*
|
|
7
|
+
* If no customizer is provided, it behaves like `clone`.
|
|
8
|
+
*
|
|
9
|
+
* @template T - The type of the object.
|
|
10
|
+
* @param {T} value - The value to clone.
|
|
11
|
+
* @param {Function} [customizer] - The function to customize cloning.
|
|
12
|
+
* @returns {T} - A shallow clone of the given object.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Clone a primitive values
|
|
16
|
+
* const num = 29;
|
|
17
|
+
* const clonedNum = cloneWith(num);
|
|
18
|
+
* console.log(clonedNum); // 29
|
|
19
|
+
* console.log(clonedNum === num) ; // true
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // Clone an array
|
|
23
|
+
* const arr = [1, 2, 3];
|
|
24
|
+
* const clonedArr = cloneWith(arr);
|
|
25
|
+
* console.log(clonedArr); // [1, 2, 3]
|
|
26
|
+
* console.log(clonedArr === arr); // false
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // Clone an object
|
|
30
|
+
* const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] };
|
|
31
|
+
* const clonedObj = cloneWith(obj);
|
|
32
|
+
* console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] }
|
|
33
|
+
* console.log(clonedObj === obj); // false
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* // Clone an object with a customizer
|
|
37
|
+
* const obj = { a: 1, b: 2 };
|
|
38
|
+
* const clonedObj = cloneWith(obj, (value) => {
|
|
39
|
+
* if (typeof value === 'number') {
|
|
40
|
+
* return value * 2; // Double the number
|
|
41
|
+
* }
|
|
42
|
+
* // Returning undefined uses the default cloning
|
|
43
|
+
* });
|
|
44
|
+
* console.log(clonedObj); // { a: 2, b: 4 }
|
|
45
|
+
*/
|
|
46
|
+
declare function cloneWith<T>(value: T, customizer?: (value: any) => any): T;
|
|
47
|
+
|
|
48
|
+
export { cloneWith };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a shallow clone of the given object with customization.
|
|
3
|
+
* This method is like `_.clone` except that it accepts a customizer which
|
|
4
|
+
* is invoked to produce the cloned value. If customizer returns undefined,
|
|
5
|
+
* cloning is handled by the method instead.
|
|
6
|
+
*
|
|
7
|
+
* If no customizer is provided, it behaves like `clone`.
|
|
8
|
+
*
|
|
9
|
+
* @template T - The type of the object.
|
|
10
|
+
* @param {T} value - The value to clone.
|
|
11
|
+
* @param {Function} [customizer] - The function to customize cloning.
|
|
12
|
+
* @returns {T} - A shallow clone of the given object.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Clone a primitive values
|
|
16
|
+
* const num = 29;
|
|
17
|
+
* const clonedNum = cloneWith(num);
|
|
18
|
+
* console.log(clonedNum); // 29
|
|
19
|
+
* console.log(clonedNum === num) ; // true
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // Clone an array
|
|
23
|
+
* const arr = [1, 2, 3];
|
|
24
|
+
* const clonedArr = cloneWith(arr);
|
|
25
|
+
* console.log(clonedArr); // [1, 2, 3]
|
|
26
|
+
* console.log(clonedArr === arr); // false
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // Clone an object
|
|
30
|
+
* const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] };
|
|
31
|
+
* const clonedObj = cloneWith(obj);
|
|
32
|
+
* console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] }
|
|
33
|
+
* console.log(clonedObj === obj); // false
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* // Clone an object with a customizer
|
|
37
|
+
* const obj = { a: 1, b: 2 };
|
|
38
|
+
* const clonedObj = cloneWith(obj, (value) => {
|
|
39
|
+
* if (typeof value === 'number') {
|
|
40
|
+
* return value * 2; // Double the number
|
|
41
|
+
* }
|
|
42
|
+
* // Returning undefined uses the default cloning
|
|
43
|
+
* });
|
|
44
|
+
* console.log(clonedObj); // { a: 2, b: 4 }
|
|
45
|
+
*/
|
|
46
|
+
declare function cloneWith<T>(value: T, customizer?: (value: any) => any): T;
|
|
47
|
+
|
|
48
|
+
export { cloneWith };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { clone } from './clone.mjs';
|
|
2
|
+
|
|
3
|
+
function cloneWith(value, customizer) {
|
|
4
|
+
if (!customizer) {
|
|
5
|
+
return clone(value);
|
|
6
|
+
}
|
|
7
|
+
const result = customizer(value);
|
|
8
|
+
if (result !== undefined) {
|
|
9
|
+
return result;
|
|
10
|
+
}
|
|
11
|
+
return clone(value);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { cloneWith };
|
|
@@ -17,7 +17,7 @@ declare function findKey<T extends Record<any, any>>(obj: T | null | undefined,
|
|
|
17
17
|
*
|
|
18
18
|
* @template T - The type of the object.
|
|
19
19
|
* @param {T | null | undefined} obj - The object to inspect.
|
|
20
|
-
* @param {
|
|
20
|
+
* @param {Partial<T[keyof T]>} objectToFind - The object to match.
|
|
21
21
|
* @returns {keyof T | undefined} Returns the key of the matched element, else `undefined`.
|
|
22
22
|
*
|
|
23
23
|
* @example
|
|
@@ -17,7 +17,7 @@ declare function findKey<T extends Record<any, any>>(obj: T | null | undefined,
|
|
|
17
17
|
*
|
|
18
18
|
* @template T - The type of the object.
|
|
19
19
|
* @param {T | null | undefined} obj - The object to inspect.
|
|
20
|
-
* @param {
|
|
20
|
+
* @param {Partial<T[keyof T]>} objectToFind - The object to match.
|
|
21
21
|
* @returns {keyof T | undefined} Returns the key of the matched element, else `undefined`.
|
|
22
22
|
*
|
|
23
23
|
* @example
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sets the value at the specified path of the given object using a customizer function.
|
|
3
|
+
* If any part of the path does not exist, it will be created based on the customizer's result.
|
|
4
|
+
*
|
|
5
|
+
* The customizer is invoked to produce the objects of the path. If the customizer returns
|
|
6
|
+
* a value, that value is used for the current path segment. If the customizer returns
|
|
7
|
+
* `undefined`, the method will create an appropriate object based on the path - an array
|
|
8
|
+
* if the next path segment is a valid array index, or an object otherwise.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The type of the object.
|
|
11
|
+
* @param {T} obj - The object to modify.
|
|
12
|
+
* @param {PropertyKey | readonly PropertyKey[]} path - The path of the property to set.
|
|
13
|
+
* @param {unknown} value - The value to set.
|
|
14
|
+
* @param {(value: unknown) => unknown} [customizer] - The function to customize assigned values.
|
|
15
|
+
* @returns {T} - The modified object.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // Set a value with a customizer that creates arrays for numeric path segments
|
|
19
|
+
* const object = {};
|
|
20
|
+
* setWith(object, '[0][1]', 'a', (value) => Array.isArray(value) ? value : []);
|
|
21
|
+
* // => { '0': ['a'] }
|
|
22
|
+
*/
|
|
23
|
+
declare function setWith<T extends object | null | undefined>(obj: T, path: PropertyKey | readonly PropertyKey[], value: unknown, customizer?: (value: unknown) => unknown): T;
|
|
24
|
+
|
|
25
|
+
export { setWith };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sets the value at the specified path of the given object using a customizer function.
|
|
3
|
+
* If any part of the path does not exist, it will be created based on the customizer's result.
|
|
4
|
+
*
|
|
5
|
+
* The customizer is invoked to produce the objects of the path. If the customizer returns
|
|
6
|
+
* a value, that value is used for the current path segment. If the customizer returns
|
|
7
|
+
* `undefined`, the method will create an appropriate object based on the path - an array
|
|
8
|
+
* if the next path segment is a valid array index, or an object otherwise.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The type of the object.
|
|
11
|
+
* @param {T} obj - The object to modify.
|
|
12
|
+
* @param {PropertyKey | readonly PropertyKey[]} path - The path of the property to set.
|
|
13
|
+
* @param {unknown} value - The value to set.
|
|
14
|
+
* @param {(value: unknown) => unknown} [customizer] - The function to customize assigned values.
|
|
15
|
+
* @returns {T} - The modified object.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // Set a value with a customizer that creates arrays for numeric path segments
|
|
19
|
+
* const object = {};
|
|
20
|
+
* setWith(object, '[0][1]', 'a', (value) => Array.isArray(value) ? value : []);
|
|
21
|
+
* // => { '0': ['a'] }
|
|
22
|
+
*/
|
|
23
|
+
declare function setWith<T extends object | null | undefined>(obj: T, path: PropertyKey | readonly PropertyKey[], value: unknown, customizer?: (value: unknown) => unknown): T;
|
|
24
|
+
|
|
25
|
+
export { setWith };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { updateWith } from './updateWith.mjs';
|
|
2
|
+
|
|
3
|
+
function setWith(obj, path, value, customizer) {
|
|
4
|
+
let customizerFn;
|
|
5
|
+
if (typeof customizer === 'function') {
|
|
6
|
+
customizerFn = customizer;
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
customizerFn = () => undefined;
|
|
10
|
+
}
|
|
11
|
+
return updateWith(obj, path, () => value, customizerFn);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { setWith };
|