es-toolkit 1.13.1-dev.316 → 1.13.1-dev.318
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/array/index.mjs +16 -16
- package/dist/browser.js +90 -0
- package/dist/browser.js.map +1 -1
- package/dist/browser.mjs +25 -24
- package/dist/browser.mjs.map +1 -1
- package/dist/{chunk-HKO7DEJK.mjs → chunk-36ZJSTNA.mjs} +54 -50
- package/dist/{chunk-HKO7DEJK.mjs.map → chunk-36ZJSTNA.mjs.map} +1 -1
- package/dist/chunk-5CPXZFCB.mjs +93 -0
- package/dist/chunk-5CPXZFCB.mjs.map +1 -0
- package/dist/chunk-YXAOYIRV.mjs +1 -0
- package/dist/compat/index.d.mts +1 -0
- package/dist/compat/index.d.ts +1 -0
- package/dist/compat/index.js +91 -0
- package/dist/compat/index.js.map +1 -1
- package/dist/compat/index.mjs +56 -52
- package/dist/function/index.mjs +9 -9
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +91 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +57 -53
- package/dist/object/cloneDeep.d.mts +64 -0
- package/dist/object/cloneDeep.d.ts +64 -0
- package/dist/object/cloneDeep.js +117 -0
- package/dist/object/cloneDeep.js.map +1 -0
- package/dist/object/cloneDeep.mjs +8 -0
- package/dist/object/cloneDeep.mjs.map +1 -0
- package/dist/object/index.d.mts +1 -0
- package/dist/object/index.d.ts +1 -0
- package/dist/object/index.js +91 -0
- package/dist/object/index.js.map +1 -1
- package/dist/object/index.mjs +8 -4
- package/dist/predicate/index.mjs +3 -3
- package/dist/string/index.mjs +3 -3
- package/package.json +1 -1
- package/umd/browser.global.js +1 -1
- package/dist/chunk-54TK5BIS.mjs +0 -1
- /package/dist/{chunk-54TK5BIS.mjs.map → chunk-YXAOYIRV.mjs.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=chunk-YXAOYIRV.mjs.map
|
package/dist/compat/index.d.mts
CHANGED
|
@@ -70,6 +70,7 @@ export { pick } from '../object/pick.mjs';
|
|
|
70
70
|
export { pickBy } from '../object/pickBy.mjs';
|
|
71
71
|
export { invert } from '../object/invert.mjs';
|
|
72
72
|
export { clone } from '../object/clone.mjs';
|
|
73
|
+
export { cloneDeep } from '../object/cloneDeep.mjs';
|
|
73
74
|
export { flattenObject } from '../object/flattenObject.mjs';
|
|
74
75
|
export { isEqual } from '../predicate/isEqual.mjs';
|
|
75
76
|
export { isNil } from '../predicate/isNil.mjs';
|
package/dist/compat/index.d.ts
CHANGED
|
@@ -70,6 +70,7 @@ export { pick } from '../object/pick.js';
|
|
|
70
70
|
export { pickBy } from '../object/pickBy.js';
|
|
71
71
|
export { invert } from '../object/invert.js';
|
|
72
72
|
export { clone } from '../object/clone.js';
|
|
73
|
+
export { cloneDeep } from '../object/cloneDeep.js';
|
|
73
74
|
export { flattenObject } from '../object/flattenObject.js';
|
|
74
75
|
export { isEqual } from '../predicate/isEqual.js';
|
|
75
76
|
export { isNil } from '../predicate/isNil.js';
|
package/dist/compat/index.js
CHANGED
|
@@ -62,6 +62,7 @@ __export(compat_exports, {
|
|
|
62
62
|
chunk: () => chunk2,
|
|
63
63
|
clamp: () => clamp,
|
|
64
64
|
clone: () => clone,
|
|
65
|
+
cloneDeep: () => cloneDeep,
|
|
65
66
|
compact: () => compact,
|
|
66
67
|
concat: () => concat,
|
|
67
68
|
countBy: () => countBy,
|
|
@@ -949,6 +950,95 @@ function isPrimitive(value) {
|
|
|
949
950
|
return value == null || typeof value !== "object" && typeof value !== "function";
|
|
950
951
|
}
|
|
951
952
|
|
|
953
|
+
// src/object/cloneDeep.ts
|
|
954
|
+
function cloneDeep(obj) {
|
|
955
|
+
if (isPrimitive2(obj)) {
|
|
956
|
+
return obj;
|
|
957
|
+
}
|
|
958
|
+
if (Array.isArray(obj)) {
|
|
959
|
+
return obj.map((item) => cloneDeep(item));
|
|
960
|
+
}
|
|
961
|
+
if (obj instanceof Date) {
|
|
962
|
+
return new Date(obj.getTime());
|
|
963
|
+
}
|
|
964
|
+
if (obj instanceof RegExp) {
|
|
965
|
+
return new RegExp(obj.source, obj.flags);
|
|
966
|
+
}
|
|
967
|
+
if (obj instanceof Map) {
|
|
968
|
+
const result = /* @__PURE__ */ new Map();
|
|
969
|
+
for (const [key, value] of obj.entries()) {
|
|
970
|
+
result.set(key, cloneDeep(value));
|
|
971
|
+
}
|
|
972
|
+
return result;
|
|
973
|
+
}
|
|
974
|
+
if (obj instanceof Set) {
|
|
975
|
+
const result = /* @__PURE__ */ new Set();
|
|
976
|
+
for (const value of obj.values()) {
|
|
977
|
+
result.add(cloneDeep(value));
|
|
978
|
+
}
|
|
979
|
+
return result;
|
|
980
|
+
}
|
|
981
|
+
if (isTypedArray(obj)) {
|
|
982
|
+
const result = new (Object.getPrototypeOf(obj)).constructor(obj.length);
|
|
983
|
+
for (let i = 0; i < obj.length; i++) {
|
|
984
|
+
result[i] = cloneDeep(obj[i]);
|
|
985
|
+
}
|
|
986
|
+
return result;
|
|
987
|
+
}
|
|
988
|
+
if (obj instanceof ArrayBuffer || obj instanceof SharedArrayBuffer) {
|
|
989
|
+
return obj.slice(0);
|
|
990
|
+
}
|
|
991
|
+
if (obj instanceof DataView) {
|
|
992
|
+
const result = new DataView(obj.buffer.slice(0));
|
|
993
|
+
cloneDeepHelper(obj, result);
|
|
994
|
+
return result;
|
|
995
|
+
}
|
|
996
|
+
if (typeof File !== "undefined" && obj instanceof File) {
|
|
997
|
+
const result = new File([obj], obj.name, { type: obj.type });
|
|
998
|
+
cloneDeepHelper(obj, result);
|
|
999
|
+
return result;
|
|
1000
|
+
}
|
|
1001
|
+
if (obj instanceof Blob) {
|
|
1002
|
+
const result = new Blob([obj], { type: obj.type });
|
|
1003
|
+
cloneDeepHelper(obj, result);
|
|
1004
|
+
return result;
|
|
1005
|
+
}
|
|
1006
|
+
if (obj instanceof Error) {
|
|
1007
|
+
const result = new obj.constructor();
|
|
1008
|
+
result.message = obj.message;
|
|
1009
|
+
result.name = obj.name;
|
|
1010
|
+
result.stack = obj.stack;
|
|
1011
|
+
result.cause = obj.cause;
|
|
1012
|
+
cloneDeepHelper(obj, result);
|
|
1013
|
+
return result;
|
|
1014
|
+
}
|
|
1015
|
+
if (typeof obj === "object" && obj !== null) {
|
|
1016
|
+
const result = {};
|
|
1017
|
+
cloneDeepHelper(obj, result);
|
|
1018
|
+
return result;
|
|
1019
|
+
}
|
|
1020
|
+
if (typeof obj === "function") {
|
|
1021
|
+
return void 0;
|
|
1022
|
+
}
|
|
1023
|
+
return obj;
|
|
1024
|
+
}
|
|
1025
|
+
function isPrimitive2(value) {
|
|
1026
|
+
return value == null || typeof value !== "object" && typeof value !== "function";
|
|
1027
|
+
}
|
|
1028
|
+
function cloneDeepHelper(obj, clonedObj) {
|
|
1029
|
+
for (const key in obj) {
|
|
1030
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
1031
|
+
const descriptor = Object.getOwnPropertyDescriptor(obj, key);
|
|
1032
|
+
if (((descriptor == null ? void 0 : descriptor.writable) || (descriptor == null ? void 0 : descriptor.set)) && typeof (descriptor == null ? void 0 : descriptor.value) !== "function") {
|
|
1033
|
+
clonedObj[key] = cloneDeep(obj[key]);
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
function isTypedArray(obj) {
|
|
1039
|
+
return obj instanceof Uint8Array || obj instanceof Uint8ClampedArray || obj instanceof Uint16Array || obj instanceof Uint32Array || obj instanceof BigUint64Array || obj instanceof Int8Array || obj instanceof Int16Array || obj instanceof Int32Array || obj instanceof BigInt64Array || obj instanceof Float32Array || obj instanceof Float64Array;
|
|
1040
|
+
}
|
|
1041
|
+
|
|
952
1042
|
// src/predicate/isPlainObject.ts
|
|
953
1043
|
function isPlainObject(object) {
|
|
954
1044
|
if (typeof object !== "object") {
|
|
@@ -1391,6 +1481,7 @@ function min(items = []) {
|
|
|
1391
1481
|
chunk,
|
|
1392
1482
|
clamp,
|
|
1393
1483
|
clone,
|
|
1484
|
+
cloneDeep,
|
|
1394
1485
|
compact,
|
|
1395
1486
|
concat,
|
|
1396
1487
|
countBy,
|