es-toolkit 1.9.0-dev.196 → 1.9.0-dev.197
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-NY33CVEY.mjs → chunk-U4JGKZ56.mjs} +15 -1
- package/dist/chunk-U4JGKZ56.mjs.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/object/clone.js +14 -0
- package/dist/object/clone.js.map +1 -1
- package/dist/object/clone.mjs +1 -1
- package/dist/object/index.js +14 -0
- package/dist/object/index.js.map +1 -1
- package/dist/object/index.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-NY33CVEY.mjs.map +0 -1
|
@@ -12,6 +12,20 @@ function clone(obj) {
|
|
|
12
12
|
if (obj instanceof RegExp) {
|
|
13
13
|
return new RegExp(obj.source, obj.flags);
|
|
14
14
|
}
|
|
15
|
+
if (obj instanceof Map) {
|
|
16
|
+
const result = /* @__PURE__ */ new Map();
|
|
17
|
+
for (const [key, value] of obj) {
|
|
18
|
+
result.set(key, value);
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
if (obj instanceof Set) {
|
|
23
|
+
const result = /* @__PURE__ */ new Set();
|
|
24
|
+
for (const value of obj) {
|
|
25
|
+
result.add(value);
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
15
29
|
if (typeof obj === "object") {
|
|
16
30
|
return Object.assign({}, obj);
|
|
17
31
|
}
|
|
@@ -24,4 +38,4 @@ function isPrimitive(value) {
|
|
|
24
38
|
export {
|
|
25
39
|
clone
|
|
26
40
|
};
|
|
27
|
-
//# sourceMappingURL=chunk-
|
|
41
|
+
//# sourceMappingURL=chunk-U4JGKZ56.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/object/clone.ts"],"sourcesContent":["/**\n * Creates a shallow clone of the given object.\n *\n * @template T - The type of the object.\n * @param {T} obj - The object to clone.\n * @returns {T} - A shallow clone of the given object.\n *\n * @example\n * // Clone a primitive values\n * const num = 29;\n * const clonedNum = clone(num);\n * console.log(clonedNum); // 29\n * console.log(clonedNum === num) ; // true\n *\n * @example\n * // Clone an array\n * const arr = [1, 2, 3];\n * const clonedArr = clone(arr);\n * console.log(clonedArr); // [1, 2, 3]\n * console.log(clonedArr === arr); // false\n *\n * @example\n * // Clone an object\n * const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] };\n * const clonedObj = clone(obj);\n * console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] }\n * console.log(clonedObj === obj); // false\n */\nexport function clone<T>(obj: T): T {\n if (isPrimitive(obj)) {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.slice() as T;\n }\n\n if (obj instanceof Date) {\n return new Date(obj.getTime()) as T;\n }\n\n if (obj instanceof RegExp) {\n return new RegExp(obj.source, obj.flags) as T;\n }\n\n if (obj instanceof Map) {\n const result = new Map();\n for (const [key, value] of obj) {\n result.set(key, value);\n }\n return result as T;\n }\n\n if (obj instanceof Set) {\n const result = new Set();\n for (const value of obj) {\n result.add(value);\n }\n return result as T;\n }\n\n if (typeof obj === \"object\") {\n return Object.assign({}, obj) as T;\n }\n return obj;\n}\n\ntype Primitive = null | undefined | string | number | boolean | symbol | bigint;\n\nfunction isPrimitive(value: unknown): value is Primitive {\n return value == null ||\n (typeof value !== \"object\" && typeof value !== \"function\");\n}\n"],"mappings":";AA4BO,SAAS,MAAS,KAAW;AAClC,MAAI,YAAY,GAAG,GAAG;AACpB,WAAO;AAAA,EACT;AAEA,MAAI,MAAM,QAAQ,GAAG,GAAG;AACtB,WAAO,IAAI,MAAM;AAAA,EACnB;AAEA,MAAI,eAAe,MAAM;AACvB,WAAO,IAAI,KAAK,IAAI,QAAQ,CAAC;AAAA,EAC/B;AAEA,MAAI,eAAe,QAAQ;AACzB,WAAO,IAAI,OAAO,IAAI,QAAQ,IAAI,KAAK;AAAA,EACzC;AAEA,MAAI,eAAe,KAAK;AACtB,UAAM,SAAS,oBAAI,IAAI;AACvB,eAAW,CAAC,KAAK,KAAK,KAAK,KAAK;AAC9B,aAAO,IAAI,KAAK,KAAK;AAAA,IACvB;AACA,WAAO;AAAA,EACT;AAEA,MAAI,eAAe,KAAK;AACtB,UAAM,SAAS,oBAAI,IAAI;AACvB,eAAW,SAAS,KAAK;AACvB,aAAO,IAAI,KAAK;AAAA,IAClB;AACA,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,QAAQ,UAAU;AAC3B,WAAO,OAAO,OAAO,CAAC,GAAG,GAAG;AAAA,EAC9B;AACA,SAAO;AACT;AAIA,SAAS,YAAY,OAAoC;AACvD,SAAO,SAAS,QACb,OAAO,UAAU,YAAY,OAAO,UAAU;AACnD;","names":[]}
|
package/dist/index.js
CHANGED
|
@@ -6326,6 +6326,20 @@ function clone(obj) {
|
|
|
6326
6326
|
if (obj instanceof RegExp) {
|
|
6327
6327
|
return new RegExp(obj.source, obj.flags);
|
|
6328
6328
|
}
|
|
6329
|
+
if (obj instanceof Map) {
|
|
6330
|
+
const result = /* @__PURE__ */ new Map();
|
|
6331
|
+
for (const [key, value] of obj) {
|
|
6332
|
+
result.set(key, value);
|
|
6333
|
+
}
|
|
6334
|
+
return result;
|
|
6335
|
+
}
|
|
6336
|
+
if (obj instanceof Set) {
|
|
6337
|
+
const result = /* @__PURE__ */ new Set();
|
|
6338
|
+
for (const value of obj) {
|
|
6339
|
+
result.add(value);
|
|
6340
|
+
}
|
|
6341
|
+
return result;
|
|
6342
|
+
}
|
|
6329
6343
|
if (typeof obj === "object") {
|
|
6330
6344
|
return Object.assign({}, obj);
|
|
6331
6345
|
}
|