@visulima/deep-clone 1.0.7 → 2.0.0

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 CHANGED
@@ -1,3 +1,24 @@
1
+ ## @visulima/deep-clone [2.0.0](https://github.com/visulima/visulima/compare/@visulima/deep-clone@1.0.8...@visulima/deep-clone@2.0.0) (2024-02-10)
2
+
3
+
4
+ ### ⚠ BREAKING CHANGES
5
+
6
+ * refactored deep-clone, added new handler option for overwrite our internal cloner
7
+
8
+ Signed-off-by: prisis <d.bannert@anolilab.de>
9
+
10
+ ### Features
11
+
12
+ * refactored deep-clone to be 5 time faster in a loose version ([41b3604](https://github.com/visulima/visulima/commit/41b3604ad46a8021fb51fe0cabf207ed7002a231))
13
+ * refactored deep-clone, added new handler option for overwrite our internal cloner, created a loose and a strict version ([c641f2d](https://github.com/visulima/visulima/commit/c641f2dc8d07c7d25fd623a22cc4430a39fdd38d))
14
+
15
+ ## @visulima/deep-clone [1.0.8](https://github.com/visulima/visulima/compare/@visulima/deep-clone@1.0.7...@visulima/deep-clone@1.0.8) (2024-01-19)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * updated all deps, updated test based on eslint errors ([909f8f3](https://github.com/visulima/visulima/commit/909f8f384804d7ef140354ab44f867532dbc9847))
21
+
1
22
  ## @visulima/deep-clone [1.0.7](https://github.com/visulima/visulima/compare/@visulima/deep-clone@1.0.6...@visulima/deep-clone@1.0.7) (2023-11-30)
2
23
 
3
24
 
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 visulima
3
+ Copyright (c) 2024 visulima
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -51,15 +51,92 @@ const cloned = deepClone({ a: 1, b: { c: 2 } });
51
51
  console.log(cloned); // => {a: 1, b: {c: 2}}
52
52
  ```
53
53
 
54
+ ## API
55
+
56
+ ### deepClone(input, options?)
57
+
58
+ #### input
59
+
60
+ Type: `any`
61
+
62
+ The input value to copy.
63
+
64
+ #### options
65
+
66
+ Type: `object`
67
+
68
+ ##### strict
69
+
70
+ Type: `boolean`<br>
71
+
72
+ Default: `false`
73
+
74
+ If `true`, it will copy all properties, including non-enumerable ones and symbols.
75
+
76
+ ##### handlers
77
+
78
+ Type: `object`
79
+
80
+ A set of custom handlers for specific type of value. Each handler is a function that takes the original value and returns a new value or throws an error if the value is not supported.
81
+
82
+ - Array: InternalHandler<unknown[]>;
83
+ - ArrayBuffer: InternalHandler<ArrayBuffer>;
84
+ - Blob: InternalHandler<Blob>;
85
+ - DataView: InternalHandler<DataView>;
86
+ - Date: InternalHandler<Date>;
87
+ - Error: InternalHandler<Error>;
88
+ - Float32Array: InternalHandler<Float32Array>;
89
+ - Float64Array: InternalHandler<Float64Array>;
90
+ - Int8Array: InternalHandler<Int8Array>;
91
+ - Int16Array: InternalHandler<Int16Array>;
92
+ - Int32Array: InternalHandler<Int32Array>;
93
+ - Map: InternalHandler<Map<unknown, unknown>>;
94
+ - Object: InternalHandler<Record<string, unknown>>;
95
+ - Promise: InternalHandler<Promise<unknown>>;
96
+ - RegExp: InternalHandler<RegExp>;
97
+ - Set: InternalHandler<Set<unknown>>;
98
+ - WeakMap: InternalHandler<WeakMap<any, unknown>>;
99
+ - WeakSet: InternalHandler<WeakSet<any>>;
100
+
101
+ ## Utils
102
+
103
+ ### copyOwnProperties(input)
104
+
105
+ Copy all properties contained on the object.
106
+
107
+ ```typescript
108
+ import { copyOwnProperties } from "@visulima/deep-clone/utils";
109
+
110
+ const obj = { a: 1, b: 2 };
111
+
112
+ const copy = copyOwnProperties(obj);
113
+
114
+ console.log(copy); // => {a: 1, b: 2}
115
+ ```
116
+
117
+ ### getCleanClone(input)
118
+
119
+ Get an empty version of the object with the same prototype it has.
120
+
121
+ ```typescript
122
+ import { getCleanClone } from "@visulima/deep-clone/utils";
123
+
124
+ const obj = { a: 1, b: 2 };
125
+
126
+ const clean = getCleanClone(obj);
127
+
128
+ console.log(clean); // => {}
129
+ ```
130
+
54
131
  ## Notes
55
132
 
56
133
  - List of **supported** values/types:
57
134
 
58
- - `undefined`
59
- - `null`
60
- - `boolean`/`Boolean`
61
- - `string`/`String`
62
- - `number`/`Number`
135
+ - `undefined` (original value is returned)
136
+ - `null` (original value is returned)
137
+ - `boolean`/`Boolean` (original value is returned)
138
+ - `string`/`String` (original value is returned)
139
+ - `number`/`Number` (original value is returned)
63
140
  - `function`
64
141
  - `Object`
65
142
  - `Date`
@@ -85,6 +162,8 @@ console.log(cloned); // => {a: 1, b: {c: 2}}
85
162
  - `Float32Array`
86
163
  - `Float64Array`
87
164
  - `Buffer` ([Node.js][node-buffer])
165
+ - `DataView`
166
+ - `Blob`
88
167
 
89
168
  - List of **unsupported** values/types:
90
169
 
@@ -92,12 +171,10 @@ console.log(cloned); // => {a: 1, b: {c: 2}}
92
171
  - `Symbol`
93
172
  - `WeakMap`
94
173
  - `WeakSet`
95
- - `Blob`
96
174
  - `File`
97
175
  - `FileList`
98
176
  - `ImageData`
99
177
  - `ImageBitmap`
100
- - `DataView`
101
178
  - `Promise`
102
179
  - `SharedArrayBuffer`
103
180
 
@@ -0,0 +1,5 @@
1
+ var a=e=>[...Object.getOwnPropertyNames(e),...Object.getOwnPropertySymbols(e)],s=(e,t,n)=>{let c=a(e);for(let r of c){if(r==="callee"||r==="caller")continue;let o=Object.getOwnPropertyDescriptor(e,r);if(!o){t[r]=n.clone(e[r],n);continue}!o.get&&!o.set&&(o.value=n.clone(o.value,n));try{Object.defineProperty(t,r,o);}catch{t[r]=o.value;}}return t},y=s;var l=e=>{if(!e)return Object.create(null);let t=e.constructor;if(t===Object)return e===Object.prototype?{}:Object.create(e);if(~Function.prototype.toString.call(t).indexOf("[native code]"))try{return new t}catch{}return Object.create(e)},p=l;
2
+
3
+ export { y as a, p as b };
4
+ //# sourceMappingURL=out.js.map
5
+ //# sourceMappingURL=chunk-LPGIVFCB.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/copy-own-properties.ts","../src/utils/get-clean-clone.ts"],"names":["getStrictProperties","object","copyOwnProperties","value","clone","state","properties","property","descriptor","copy_own_properties_default","getCleanClone","input","Constructor","get_clean_clone_default"],"mappings":"AAEA,IAAMA,EAAuBC,GAAyC,CAClE,GAAI,OAAO,oBAAoBA,CAAM,EACrC,GAAG,OAAO,sBAAsBA,CAAM,CAC1C,EAKMC,EAAoB,CAAQC,EAAcC,EAAcC,IAAwB,CAClF,IAAMC,EAAaN,EAAoBG,CAAK,EAG5C,QAAWI,KAAYD,EAAY,CAC/B,GAAIC,IAAa,UAAYA,IAAa,SAEtC,SAGJ,IAAMC,EAAa,OAAO,yBAAyBL,EAAOI,CAAQ,EAElE,GAAI,CAACC,EAAY,CAKZJ,EAAcG,CAAQ,EAAIF,EAAM,MAAOF,EAAcI,CAAQ,EAAGF,CAAK,EAEtE,QACJ,CAGI,CAACG,EAAW,KAAO,CAACA,EAAW,MAC/BA,EAAW,MAAQH,EAAM,MAAMG,EAAW,MAAOH,CAAK,GAG1D,GAAI,CACA,OAAO,eAAeD,EAAOG,EAAUC,CAAU,CACrD,MAAQ,CAGHJ,EAAcG,CAAQ,EAAIC,EAAW,KAC1C,CACJ,CAEA,OAAOJ,CACX,EAEOK,EAAQP,EC7Cf,IAAMQ,EAAiBC,GAAwB,CAC3C,GAAI,CAACA,EACD,OAAO,OAAO,OAAO,IAAI,EAG7B,IAAMC,EAAcD,EAAM,YAE1B,GAAIC,IAAgB,OAChB,OAAOD,IAAU,OAAO,UAAY,CAAC,EAAI,OAAO,OAAOA,CAAK,EAIhE,GAAI,CAAC,SAAS,UAAU,SAAS,KAAKC,CAAW,EAAE,QAAQ,eAAe,EACtE,GAAI,CAEA,OAAO,IAAIA,CACf,MAAQ,CAER,CAGJ,OAAO,OAAO,OAAOD,CAAK,CAC9B,EAEOE,EAAQH","sourcesContent":["import type { State } from \"../types\";\n\nconst getStrictProperties = (object: unknown): (string | symbol)[] => [\n ...(Object.getOwnPropertyNames(object) as (string | symbol)[]),\n ...Object.getOwnPropertySymbols(object),\n];\n\n/**\n * Strict copy all properties contained on the object.\n */\nconst copyOwnProperties = <Value>(value: Value, clone: Value, state: State): Value => {\n const properties = getStrictProperties(value);\n\n // eslint-disable-next-line no-loops/no-loops,no-restricted-syntax\n for (const property of properties) {\n if (property === \"callee\" || property === \"caller\") {\n // eslint-disable-next-line no-continue\n continue;\n }\n\n const descriptor = Object.getOwnPropertyDescriptor(value, property);\n\n if (!descriptor) {\n // In extra edge cases where the property descriptor cannot be retrived, fall back to\n // the loose assignment.\n\n // eslint-disable-next-line no-param-reassign,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-explicit-any\n (clone as any)[property] = state.clone((value as any)[property], state);\n // eslint-disable-next-line no-continue\n continue;\n }\n\n // Only clone the value if actually a value, not a getter / setter.\n if (!descriptor.get && !descriptor.set) {\n descriptor.value = state.clone(descriptor.value, state);\n }\n\n try {\n Object.defineProperty(clone, property, descriptor);\n } catch {\n // Tee above can fail on node in edge cases, so fall back to the loose assignment.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,no-param-reassign,@typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-member-access\n (clone as any)[property] = descriptor.value;\n }\n }\n\n return clone;\n};\n\nexport default copyOwnProperties;\n","/**\n * Get an empty version of the object with the same prototype it has.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst getCleanClone = (input: unknown): any => {\n if (!input) {\n return Object.create(null);\n }\n\n const Constructor = input.constructor;\n\n if (Constructor === Object) {\n return input === Object.prototype ? {} : Object.create(input);\n }\n\n // eslint-disable-next-line no-bitwise\n if (~Function.prototype.toString.call(Constructor).indexOf(\"[native code]\")) {\n try {\n // @ts-expect-error - We don't know the type of the object, can be a function\n return new Constructor();\n } catch {\n /* empty */\n }\n }\n\n return Object.create(input);\n};\n\nexport default getCleanClone;\n"]}
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ var a=e=>[...Object.getOwnPropertyNames(e),...Object.getOwnPropertySymbols(e)],s=(e,t,n)=>{let c=a(e);for(let r of c){if(r==="callee"||r==="caller")continue;let o=Object.getOwnPropertyDescriptor(e,r);if(!o){t[r]=n.clone(e[r],n);continue}!o.get&&!o.set&&(o.value=n.clone(o.value,n));try{Object.defineProperty(t,r,o);}catch{t[r]=o.value;}}return t},y=s;var l=e=>{if(!e)return Object.create(null);let t=e.constructor;if(t===Object)return e===Object.prototype?{}:Object.create(e);if(~Function.prototype.toString.call(t).indexOf("[native code]"))try{return new t}catch{}return Object.create(e)},p=l;
4
+
5
+ exports.a = y;
6
+ exports.b = p;
7
+ //# sourceMappingURL=out.js.map
8
+ //# sourceMappingURL=chunk-ULIBPEBE.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/copy-own-properties.ts","../src/utils/get-clean-clone.ts"],"names":["getStrictProperties","object","copyOwnProperties","value","clone","state","properties","property","descriptor","copy_own_properties_default","getCleanClone","input","Constructor","get_clean_clone_default"],"mappings":"AAEA,IAAMA,EAAuBC,GAAyC,CAClE,GAAI,OAAO,oBAAoBA,CAAM,EACrC,GAAG,OAAO,sBAAsBA,CAAM,CAC1C,EAKMC,EAAoB,CAAQC,EAAcC,EAAcC,IAAwB,CAClF,IAAMC,EAAaN,EAAoBG,CAAK,EAG5C,QAAWI,KAAYD,EAAY,CAC/B,GAAIC,IAAa,UAAYA,IAAa,SAEtC,SAGJ,IAAMC,EAAa,OAAO,yBAAyBL,EAAOI,CAAQ,EAElE,GAAI,CAACC,EAAY,CAKZJ,EAAcG,CAAQ,EAAIF,EAAM,MAAOF,EAAcI,CAAQ,EAAGF,CAAK,EAEtE,QACJ,CAGI,CAACG,EAAW,KAAO,CAACA,EAAW,MAC/BA,EAAW,MAAQH,EAAM,MAAMG,EAAW,MAAOH,CAAK,GAG1D,GAAI,CACA,OAAO,eAAeD,EAAOG,EAAUC,CAAU,CACrD,MAAQ,CAGHJ,EAAcG,CAAQ,EAAIC,EAAW,KAC1C,CACJ,CAEA,OAAOJ,CACX,EAEOK,EAAQP,EC7Cf,IAAMQ,EAAiBC,GAAwB,CAC3C,GAAI,CAACA,EACD,OAAO,OAAO,OAAO,IAAI,EAG7B,IAAMC,EAAcD,EAAM,YAE1B,GAAIC,IAAgB,OAChB,OAAOD,IAAU,OAAO,UAAY,CAAC,EAAI,OAAO,OAAOA,CAAK,EAIhE,GAAI,CAAC,SAAS,UAAU,SAAS,KAAKC,CAAW,EAAE,QAAQ,eAAe,EACtE,GAAI,CAEA,OAAO,IAAIA,CACf,MAAQ,CAER,CAGJ,OAAO,OAAO,OAAOD,CAAK,CAC9B,EAEOE,EAAQH","sourcesContent":["import type { State } from \"../types\";\n\nconst getStrictProperties = (object: unknown): (string | symbol)[] => [\n ...(Object.getOwnPropertyNames(object) as (string | symbol)[]),\n ...Object.getOwnPropertySymbols(object),\n];\n\n/**\n * Strict copy all properties contained on the object.\n */\nconst copyOwnProperties = <Value>(value: Value, clone: Value, state: State): Value => {\n const properties = getStrictProperties(value);\n\n // eslint-disable-next-line no-loops/no-loops,no-restricted-syntax\n for (const property of properties) {\n if (property === \"callee\" || property === \"caller\") {\n // eslint-disable-next-line no-continue\n continue;\n }\n\n const descriptor = Object.getOwnPropertyDescriptor(value, property);\n\n if (!descriptor) {\n // In extra edge cases where the property descriptor cannot be retrived, fall back to\n // the loose assignment.\n\n // eslint-disable-next-line no-param-reassign,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-explicit-any\n (clone as any)[property] = state.clone((value as any)[property], state);\n // eslint-disable-next-line no-continue\n continue;\n }\n\n // Only clone the value if actually a value, not a getter / setter.\n if (!descriptor.get && !descriptor.set) {\n descriptor.value = state.clone(descriptor.value, state);\n }\n\n try {\n Object.defineProperty(clone, property, descriptor);\n } catch {\n // Tee above can fail on node in edge cases, so fall back to the loose assignment.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,no-param-reassign,@typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-member-access\n (clone as any)[property] = descriptor.value;\n }\n }\n\n return clone;\n};\n\nexport default copyOwnProperties;\n","/**\n * Get an empty version of the object with the same prototype it has.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst getCleanClone = (input: unknown): any => {\n if (!input) {\n return Object.create(null);\n }\n\n const Constructor = input.constructor;\n\n if (Constructor === Object) {\n return input === Object.prototype ? {} : Object.create(input);\n }\n\n // eslint-disable-next-line no-bitwise\n if (~Function.prototype.toString.call(Constructor).indexOf(\"[native code]\")) {\n try {\n // @ts-expect-error - We don't know the type of the object, can be a function\n return new Constructor();\n } catch {\n /* empty */\n }\n }\n\n return Object.create(input);\n};\n\nexport default getCleanClone;\n"]}
package/dist/index.cjs ADDED
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ var chunkULIBPEBE_cjs = require('./chunk-ULIBPEBE.cjs');
4
+
5
+ var u=(e,o)=>{let n=[];o.cache.set(e,n);for(let t=0,{length:a}=e;t<a;++t)n[t]=o.clone(e[t],o);return n},d=(e,o)=>{let n=[];return o.cache.set(e,n),chunkULIBPEBE_cjs.a(e,n,o)};var h=e=>{let o={BigInt64Array,BigUint64Array,Buffer:Buffer.from,Float32Array,Float64Array,Int8Array,Int16Array,Int32Array,Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array};if(e instanceof ArrayBuffer){let t=new ArrayBuffer(e.byteLength),a=new Uint8Array(e);return new Uint8Array(t).set(a),t}let n=o[e.constructor.name]??void 0;return n?new n(e):new e.constructor([...e.buffer],e.byteOffset,e.length)},i=h;var g=e=>e.slice(0,e.size,e.type),V=g;var T=e=>new DataView(i(e.buffer)),m=T;var D=e=>new Date(e.getTime()),w=D;var M=(e,o)=>{let n=new e.constructor(e.message);return e.stack&&(n.stack=e.stack),e.code&&(n.code=e.code),e.errno&&(n.errno=e.errno),e.syscall&&(n.syscall=e.syscall),chunkULIBPEBE_cjs.a(e,n,o)},E=M;var f=(e,o)=>{let n=new Map;return o.cache.set(e,n),e.forEach((t,a)=>{n.set(a,o.clone(t,o));}),n},x=(e,o)=>chunkULIBPEBE_cjs.a(e,f(e,o),o);var S=(e,o)=>{let n=chunkULIBPEBE_cjs.b(e);o.cache.set(e,n);for(let a in e)Object.hasOwnProperty.call(e,a)&&(n[a]=o.clone(e[a],o));let t=Object.getOwnPropertySymbols(e);for(let a=0,{length:p}=t,r;a<p;++a)r=t[a],Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=o.clone(e[r],o));return Object.isExtensible(e)||Object.preventExtensions(n),Object.isSealed(e)&&Object.seal(n),Object.isFrozen(e)&&Object.freeze(n),n},O=(e,o)=>{let n=chunkULIBPEBE_cjs.b(e);o.cache.set(e,n);let t=chunkULIBPEBE_cjs.a(e,n,o),a=Object.getPrototypeOf(e);return Object.getPrototypeOf(t)!==a&&Object.setPrototypeOf(t,a),Object.isExtensible(e)||Object.preventExtensions(t),Object.isSealed(e)&&Object.seal(t),Object.isFrozen(e)&&Object.freeze(t),t};var A=e=>{let o=new RegExp(e.source,e.flags);return o.lastIndex=e.lastIndex,o},k=(e,o)=>{let n=new RegExp(e.source,e.flags);return chunkULIBPEBE_cjs.a(e,n,o)};var l=(e,o)=>{let n=new Set;return o.cache.set(e,n),e.forEach(t=>{n.add(o.clone(t,o));}),n},b=(e,o)=>chunkULIBPEBE_cjs.a(e,l(e,o),o);var R=e=>typeof e=="object"&&e!==null||typeof e=="function",B={Array:u,ArrayBuffer:i,Blob:V,DataView:m,Date:w,Error:E,Function:(e,o)=>e,Map:f,Object:S,Promise:e=>{throw new TypeError(`${e.constructor.name} objects cannot be cloned`)},RegExp:A,Set:l,SharedArrayBuffer:(e,o)=>{throw new TypeError(`${e.constructor.name} objects cannot be cloned`)},WeakMap:e=>{throw new TypeError(`${e.constructor.name} objects cannot be cloned`)},WeakSet:e=>{throw new TypeError(`${e.constructor.name} objects cannot be cloned`)}},ce=(e,o)=>{if(!R(e))return e;let n={...B,...o?.strict?{Array:d,Map:x,Object:O,RegExp:k,Set:b}:{},...o?.handler},t=new WeakMap,a=(r,c)=>{if(!R(r))return r;if(c.cache.has(r))return c.cache.get(r);if(Array.isArray(r))return n.Array(r,c);if(typeof r=="object"&&r.constructor===Object&&r.nodeType===void 0)return n.Object(r,c);if(r.nodeType!==void 0&&r.cloneNode!==void 0)return r.cloneNode(!0);if(r instanceof Date)return n.Date(r,c);if(r instanceof RegExp)return n.RegExp(r,c);if(r instanceof Map)return n.Map(r,c);if(r instanceof Set)return n.Set(r,c);if(r instanceof Error)return n.Error(r,c);if(r instanceof ArrayBuffer||r instanceof Uint8Array||r instanceof Uint8ClampedArray||r instanceof Int8Array||r instanceof Uint16Array||r instanceof Int16Array||r instanceof Uint32Array||r instanceof Int32Array||r instanceof Float32Array||r instanceof Float64Array)return n.ArrayBuffer(r,c);if(r instanceof Blob)return n.Blob(r,c);if(r instanceof DataView)return n.DataView(r,c);if(r instanceof SharedArrayBuffer)return n.SharedArrayBuffer(r,c);if(r instanceof Promise)return n.Promise(r,c);if(r instanceof WeakMap)return n.WeakMap(r,c);if(r instanceof WeakSet)return n.WeakSet(r,c);if(r instanceof Function)return n.Function(r,c);if(typeof r=="object")return n.Object(r,c);throw new TypeError(`Type of ${typeof r} cannot be cloned`,r)},p=a(e,{cache:t,clone:a});return t=null,p};
6
+
7
+ exports.deepClone = ce;
8
+ //# sourceMappingURL=out.js.map
9
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/handler/copy-array.ts","../src/handler/copy-array-buffer.ts","../src/handler/copy-blob.ts","../src/handler/copy-data-view.ts","../src/handler/copy-date.ts","../src/handler/copy-error.ts","../src/handler/copy-map.ts","../src/handler/copy-object.ts","../src/handler/copy-regexp.ts","../src/handler/copy-set.ts","../src/index.ts"],"names":["copyArrayLoose","array","state","clone","index","length","copyArrayStrict","copy_own_properties_default","copyArrayBuffer","arrayBuffer","typeHandlers","newBuffer","origView","Ctor","copy_array_buffer_default","copyBlob","blob","copy_blob_default","copyDataView","dataView","copy_data_view_default","copyDate","date","copy_date_default","copyError","object","error","copy_error_default","copyMapLoose","map","value","key","copyMapStrict","copyObjectLoose","get_clean_clone_default","symbols","symbol","copyObjectStrict","clonedObject","objectPrototype","copyRegExpLoose","regExp","copyRegExpStrict","copySetLoose","set","copySetStrict","canValueHaveProperties","handlers","_state","deepClone","originalData","options","cloner","cache","cloned"],"mappings":"gDAGO,IAAMA,EAAiB,CAA0BC,EAAcC,IAAwB,CAC1F,IAAMC,EAAe,CAAC,EAGtBD,EAAM,MAAM,IAAID,EAAOE,CAAK,EAG5B,QAASC,EAAQ,EAAG,CAAE,OAAAC,CAAO,EAAIJ,EAAOG,EAAQC,EAAQ,EAAED,EACtDD,EAAMC,CAAK,EAAIF,EAAM,MAAMD,EAAMG,CAAK,EAAGF,CAAK,EAGlD,OAAOC,CACX,EAKaG,EAAkB,CAA0BL,EAAcC,IAAwB,CAC3F,IAAMC,EAAe,CAAC,EAGtB,OAAAD,EAAM,MAAM,IAAID,EAAOE,CAAK,EAErBI,EAAkBN,EAAOE,EAAOD,CAAK,CAChD,ECzBA,IAAMM,EAAsFC,GAA8B,CAEtH,IAAMC,EAAyD,CAC3D,cACA,eAGA,OAAQ,OAAO,KACf,aACA,aACA,UACA,WACA,WACA,WACA,kBACA,YACA,WACJ,EAEA,GAAID,aAAuB,YAAa,CACpC,IAAME,EAAY,IAAI,YAAYF,EAAY,UAAU,EAClDG,EAAW,IAAI,WAAWH,CAAW,EAG3C,OAFgB,IAAI,WAAWE,CAAS,EAEhC,IAAIC,CAAQ,EAEbD,CACX,CAEA,IAAME,EAAOH,EAAaD,EAAY,YAAY,IAAI,GAAK,OAE3D,OAAII,EAEO,IAAIA,EAAKJ,CAAW,EAKxB,IAAKA,EAAgC,YAAY,CAAC,GAAGA,EAAY,MAAM,EAAGA,EAAY,WAAYA,EAAY,MAAM,CAC/H,EAE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,EAGtC,GAAI4B,aAAiB,QACjB,OAAOsB,EAAO,QAAQtB,EAAO5B,CAAK,EAGtC,GAAI4B,aAAiB,SACjB,OAAOsB,EAAO,SAAStB,EAAO5B,CAAK,EAGvC,GAAI,OAAO4B,GAAU,SACjB,OAAOsB,EAAO,OAAOtB,EAAwB5B,CAAK,EAGtD,MAAM,IAAI,UAAU,WAAW,OAAO4B,CAAK,oBAAqBA,CAAK,CACzE,EAGMwB,EAASnD,EAAM+C,EAAc,CAAE,MAAAG,EAAO,MAAAlD,CAAM,CAAC,EAGnD,OAAAkD,EAAQ,KAEDC,CACX","sourcesContent":["import type { State } from \"../types\";\nimport copyOwnProperties from \"../utils/copy-own-properties\";\n\nexport const copyArrayLoose = <Value extends unknown[]>(array: Value, state: State): Value => {\n const clone: Value = [] as unknown as Value;\n\n // set in the cache immediately to be able to reuse the object recursively\n state.cache.set(array, clone);\n\n // eslint-disable-next-line no-loops/no-loops,no-plusplus\n for (let index = 0, { length } = array; index < length; ++index) {\n clone[index] = state.clone(array[index], state);\n }\n\n return clone;\n};\n\n/**\n * Deeply copy the indexed values in the array, as well as any custom properties.\n */\nexport const copyArrayStrict = <Value extends unknown[]>(array: Value, state: State): Value => {\n const clone: Value = [] as unknown as Value;\n\n // set in the cache immediately to be able to reuse the object recursively\n state.cache.set(array, clone);\n\n return copyOwnProperties(array, clone, state);\n};\n","import type { TypedArray } from \"type-fest\";\n\nconst copyArrayBuffer = <Value extends ArrayBuffer | ArrayBufferView | Buffer | TypedArray>(arrayBuffer: Value): Value => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const typeHandlers: Record<string, new (buffer: any) => any> = {\n BigInt64Array,\n BigUint64Array,\n // @ts-expect-error - Buffer has no constructor\n // eslint-disable-next-line @typescript-eslint/unbound-method\n Buffer: Buffer.from,\n Float32Array,\n Float64Array,\n Int8Array,\n Int16Array,\n Int32Array,\n Uint8Array,\n Uint8ClampedArray,\n Uint16Array,\n Uint32Array,\n };\n\n if (arrayBuffer instanceof ArrayBuffer) {\n const newBuffer = new ArrayBuffer(arrayBuffer.byteLength);\n const origView = new Uint8Array(arrayBuffer);\n const newView = new Uint8Array(newBuffer);\n\n newView.set(origView);\n\n return newBuffer as Value;\n }\n\n const Ctor = typeHandlers[arrayBuffer.constructor.name] ?? undefined;\n\n if (Ctor) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return new Ctor(arrayBuffer);\n }\n\n // @ts-expect-error - Fallback to ArrayBufferView\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return new (arrayBuffer as ArrayBufferView).constructor([...arrayBuffer.buffer], arrayBuffer.byteOffset, arrayBuffer.length);\n};\n\nexport default copyArrayBuffer;\n","const copyBlob = <Value extends Blob>(blob: Value): Value => blob.slice(0, blob.size, blob.type) as Value;\n\nexport default copyBlob;\n","import copyArrayBuffer from \"./copy-array-buffer\";\n\nconst copyDataView = <Value extends DataView>(dataView: Value): Value => new DataView(copyArrayBuffer(dataView.buffer)) as Value;\n\nexport default copyDataView;\n","const copyDate = <Value extends Date>(date: Value): Value => new Date(date.getTime()) as Value;\n\nexport default copyDate;\n","import type { State } from \"../types\";\nimport copyOwnProperties from \"../utils/copy-own-properties\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype ExtendedError = Error & { code?: any; errno?: any; syscall?: any };\n\nconst copyError = <Value extends EvalError | ExtendedError | RangeError | ReferenceError | SyntaxError | TypeError | URIError>(\n object: Value,\n state: State,\n): Value => {\n // @ts-expect-error - We don't know the type of the object, can be an error\n const error = new object.constructor(object.message) as EvalError | ExtendedError | RangeError | ReferenceError | SyntaxError | TypeError | URIError;\n\n // If a `stack` property is present, copy it over...\n if (object.stack) {\n error.stack = object.stack;\n }\n\n // Node.js specific (system errors)...\n if ((object as ExtendedError).code) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n (error as ExtendedError).code = (object as ExtendedError).code;\n }\n\n if ((object as ExtendedError).errno) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n (error as ExtendedError).errno = (object as ExtendedError).errno;\n }\n\n if ((object as ExtendedError).syscall) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n (error as ExtendedError).syscall = (object as ExtendedError).syscall;\n }\n\n return copyOwnProperties(object, error, state) as Value;\n};\n\nexport default copyError;\n","import type { State } from \"../types\";\nimport copyOwnProperties from \"../utils/copy-own-properties\";\n\nexport const copyMapLoose = <Value extends Map<unknown, unknown>>(map: Value, state: State): Value => {\n const clone = new Map() as Value;\n\n // set in the cache immediately to be able to reuse the object recursively\n state.cache.set(map, clone);\n\n map.forEach((value, key) => {\n clone.set(key, state.clone(value, state));\n });\n\n return clone;\n};\n\n/**\n * Deeply copy the keys and values of the original, as well as any custom properties.\n */\nexport const copyMapStrict = <Value extends Map<unknown, unknown>>(map: Value, state: State): Value => copyOwnProperties(map, copyMapLoose<Value>(map, state), state);\n","import type { EmptyObject, UnknownRecord } from \"type-fest\";\n\nimport type { State } from \"../types\";\nimport copyOwnProperties from \"../utils/copy-own-properties\";\nimport getCleanClone from \"../utils/get-clean-clone\";\n\nexport const copyObjectLoose = <Value extends UnknownRecord>(object: Value, state: State): Value => {\n const clone = getCleanClone(object) as EmptyObject;\n\n // set in the cache immediately to be able to reuse the object recursively\n state.cache.set(object, clone);\n\n // eslint-disable-next-line no-loops/no-loops,no-restricted-syntax\n for (const key in object) {\n if (Object.hasOwnProperty.call(object, key)) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-explicit-any\n (clone as any)[key] = state.clone(object[key], state);\n }\n }\n\n const symbols = Object.getOwnPropertySymbols(object);\n\n // eslint-disable-next-line no-loops/no-loops,no-plusplus\n for (let index = 0, { length } = symbols, symbol; index < length; ++index) {\n symbol = symbols[index] as symbol;\n\n if (Object.prototype.propertyIsEnumerable.call(object, symbol)) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-explicit-any\n (clone as any)[symbol] = state.clone((object as any)[symbol], state);\n }\n }\n\n if (!Object.isExtensible(object)) {\n Object.preventExtensions(clone);\n }\n\n if (Object.isSealed(object)) {\n Object.seal(clone);\n }\n\n if (Object.isFrozen(object)) {\n Object.freeze(clone);\n }\n\n return clone as Value;\n};\n\n/**\n * Deeply copy the properties (keys and symbols) and values of the original, as well\n * as any hidden or non-enumerable properties.\n */\nexport const copyObjectStrict = <Value extends UnknownRecord>(object: Value, state: State): Value => {\n const clone = getCleanClone(object) as EmptyObject;\n\n // set in the cache immediately to be able to reuse the object recursively\n state.cache.set(object, clone);\n\n const clonedObject = copyOwnProperties<Value>(object, clone as Value, state);\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const objectPrototype: object | null = Object.getPrototypeOf(object);\n\n if (Object.getPrototypeOf(clonedObject) !== objectPrototype) {\n Object.setPrototypeOf(clonedObject, objectPrototype);\n }\n\n if (!Object.isExtensible(object)) {\n Object.preventExtensions(clonedObject);\n }\n\n if (Object.isSealed(object)) {\n Object.seal(clonedObject);\n }\n\n if (Object.isFrozen(object)) {\n Object.freeze(clonedObject);\n }\n\n return clonedObject as Value;\n};\n","import type { State } from \"../types\";\nimport copyOwnProperties from \"../utils/copy-own-properties\";\n\nexport const copyRegExpLoose = <Value extends RegExp>(regExp: Value): Value => {\n // eslint-disable-next-line @rushstack/security/no-unsafe-regexp,security/detect-non-literal-regexp\n const clone = new RegExp(regExp.source, regExp.flags) as Value;\n\n clone.lastIndex = regExp.lastIndex;\n\n return clone;\n};\n\nexport const copyRegExpStrict = <Value extends RegExp>(regExp: Value, state: State): Value => {\n // eslint-disable-next-line @rushstack/security/no-unsafe-regexp,security/detect-non-literal-regexp\n const clone = new RegExp(regExp.source, regExp.flags) as Value;\n\n return copyOwnProperties(regExp, clone, state);\n};\n","import type { State } from \"../types\";\nimport copyOwnProperties from \"../utils/copy-own-properties\";\n\nexport const copySetLoose = <Value extends Set<unknown>>(set: Value, state: State): Value => {\n const clone = new Set() as Value;\n\n // set in the cache immediately to be able to reuse the object recursively\n state.cache.set(set, clone);\n\n set.forEach((value) => {\n clone.add(state.clone(value, state));\n });\n\n return clone;\n}\n\n/**\n * Deeply copy the values of the original, as well as any custom properties.\n */\nexport const copySetStrict = <Value extends Set<unknown>>(set: Value, state: State): Value => copyOwnProperties(set, copySetLoose<Value>(set, state), state);\n","import type { UnknownRecord } from \"type-fest\";\n\nimport { copyArrayLoose, copyArrayStrict } from \"./handler/copy-array\";\nimport copyArrayBuffer from \"./handler/copy-array-buffer\";\nimport copyBlob from \"./handler/copy-blob\";\nimport copyDataView from \"./handler/copy-data-view\";\nimport copyDate from \"./handler/copy-date\";\nimport copyError from \"./handler/copy-error\";\nimport { copyMapLoose, copyMapStrict } from \"./handler/copy-map\";\nimport { copyObjectLoose, copyObjectStrict } from \"./handler/copy-object\";\nimport { copyRegExpLoose, copyRegExpStrict } from \"./handler/copy-regexp\";\nimport { copySetLoose, copySetStrict } from \"./handler/copy-set\";\nimport type { Options, State } from \"./types\";\n\n// eslint-disable-next-line @typescript-eslint/ban-types\nconst canValueHaveProperties = (value: unknown): value is NonNullable<Function | object> =>\n (typeof value === \"object\" && value !== null) || typeof value === \"function\";\n\n/**\n * handler mappings for different data types.\n */\nconst handlers = {\n Array: copyArrayLoose,\n ArrayBuffer: copyArrayBuffer,\n Blob: copyBlob,\n DataView: copyDataView,\n Date: copyDate,\n Error: copyError,\n // eslint-disable-next-line @typescript-eslint/ban-types,@typescript-eslint/no-unused-vars\n Function: (object: Function, _state: State) => object,\n Map: copyMapLoose,\n Object: copyObjectLoose,\n Promise: (object: Promise<unknown>) => {\n throw new TypeError(`${object.constructor.name} objects cannot be cloned`);\n },\n RegExp: copyRegExpLoose,\n Set: copySetLoose,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n SharedArrayBuffer: (object: SharedArrayBuffer, _state: State) => {\n throw new TypeError(`${object.constructor.name} objects cannot be cloned`);\n },\n WeakMap: (object: WeakMap<any, any>) => {\n throw new TypeError(`${object.constructor.name} objects cannot be cloned`);\n },\n WeakSet: (object: WeakSet<any>) => {\n throw new TypeError(`${object.constructor.name} objects cannot be cloned`);\n },\n};\n\ntype DeepReadwrite<T> = T extends object | [] ? { -readonly [P in keyof T]: DeepReadwrite<T[P]> } : T;\n\ninterface FakeJSDOM {\n cloneNode?: (check: boolean) => unknown;\n nodeType?: unknown;\n}\n\n/**\n * Function that creates a deep clone of an object or array.\n *\n * @template T - The type of the original data.\n * @param originalData - The original data to be cloned. It uses the generic parameter `T`.\n * @param options - Optional. The cloning options. Type of this parameter is `Options`.\n * @returns The deep cloned data with its type as `DeepReadwrite<T>`.\n */\n// eslint-disable-next-line import/prefer-default-export,sonarjs/cognitive-complexity\nexport const deepClone = <T>(originalData: T, options?: Options): DeepReadwrite<T> => {\n if (!canValueHaveProperties(originalData)) {\n return originalData as DeepReadwrite<T>;\n }\n\n const cloner = {\n ...handlers,\n ...(options?.strict ? { Array: copyArrayStrict, Map: copyMapStrict, Object: copyObjectStrict, RegExp: copyRegExpStrict, Set: copySetStrict } : {}),\n ...options?.handler,\n };\n\n let cache: WeakMap<any, any> | null = new WeakMap();\n\n const clone = (value: any, state: State): any => {\n if (!canValueHaveProperties(value)) {\n return value as DeepReadwrite<T>;\n }\n\n if (state.cache.has(value)) {\n return state.cache.get(value);\n }\n\n if (Array.isArray(value)) {\n return cloner.Array(value, state);\n }\n\n if (typeof value === \"object\" && value.constructor === Object && (value as FakeJSDOM).nodeType === undefined) {\n return cloner.Object(value as UnknownRecord, state);\n }\n\n if ((value as FakeJSDOM).nodeType !== undefined && (value as FakeJSDOM).cloneNode !== undefined) {\n return (value as { cloneNode: (check: boolean) => unknown }).cloneNode(true);\n }\n\n if (value instanceof Date) {\n return cloner.Date(value, state);\n }\n\n if (value instanceof RegExp) {\n return cloner.RegExp(value, state);\n }\n\n if (value instanceof Map) {\n return cloner.Map(value, state);\n }\n\n if (value instanceof Set) {\n return cloner.Set(value, state);\n }\n\n if (value instanceof Error) {\n return cloner.Error(value, state);\n }\n\n if (\n value instanceof ArrayBuffer ||\n value instanceof Uint8Array ||\n value instanceof Uint8ClampedArray ||\n value instanceof Int8Array ||\n value instanceof Uint16Array ||\n value instanceof Int16Array ||\n value instanceof Uint32Array ||\n value instanceof Int32Array ||\n value instanceof Float32Array ||\n value instanceof Float64Array\n ) {\n return cloner.ArrayBuffer(value, state);\n }\n\n if (value instanceof Blob) {\n return cloner.Blob(value, state);\n }\n\n if (value instanceof DataView) {\n return cloner.DataView(value, state);\n }\n\n if (value instanceof SharedArrayBuffer) {\n return cloner.SharedArrayBuffer(value, state);\n }\n\n if (value instanceof Promise) {\n return cloner.Promise(value, state);\n }\n\n if (value instanceof WeakMap) {\n return cloner.WeakMap(value, state);\n }\n\n if (value instanceof WeakSet) {\n return cloner.WeakSet(value, state);\n }\n\n if (value instanceof Function) {\n return cloner.Function(value, state);\n }\n\n if (typeof value === \"object\") {\n return cloner.Object(value as UnknownRecord, state);\n }\n\n throw new TypeError(`Type of ${typeof value} cannot be cloned`, value);\n };\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const cloned = clone(originalData, { cache, clone });\n\n // Reset the cache to free up memory\n cache = null;\n\n return cloned as DeepReadwrite<T>;\n};\n"]}
@@ -0,0 +1,8 @@
1
+ import { O as Options } from './types-QwwO2Lbg.cjs';
2
+
3
+ type DeepReadwrite<T> = T extends object | [] ? {
4
+ -readonly [P in keyof T]: DeepReadwrite<T[P]>;
5
+ } : T;
6
+ declare const deepClone: <T>(originalData: T, options?: Options) => DeepReadwrite<T>;
7
+
8
+ export { deepClone };
package/dist/index.d.ts CHANGED
@@ -1,10 +1,8 @@
1
+ import { O as Options } from './types-QwwO2Lbg.js';
2
+
1
3
  type DeepReadwrite<T> = T extends object | [] ? {
2
4
  -readonly [P in keyof T]: DeepReadwrite<T[P]>;
3
5
  } : T;
4
- interface Options {
5
- circles?: boolean;
6
- proto?: boolean;
7
- }
8
- declare const deepClone: <T = unknown>(originalData: T, options?: Options) => DeepReadwrite<T>;
6
+ declare const deepClone: <T>(originalData: T, options?: Options) => DeepReadwrite<T>;
9
7
 
10
8
  export { deepClone };
package/dist/index.js CHANGED
@@ -1,5 +1,7 @@
1
- var w=e=>typeof e=="object"&&e!==null||typeof e=="function",k=e=>{let t={BigInt64Array,BigUint64Array,Buffer:Buffer.from,Float32Array,Float64Array,Int8Array,Int16Array,Int32Array,Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array};if(e instanceof ArrayBuffer){let r=new ArrayBuffer(e.byteLength),n=new Uint8Array(e);return new Uint8Array(r).set(n),r}let o=t[e.constructor.name];return o?new o(e):new e.constructor([...e.buffer],e.byteOffset,e.length)},d=[{checker:e=>e instanceof Date,handler:e=>new Date(e),type:"date"},{checker:e=>e instanceof RegExp,handler:e=>{let t=new RegExp(e);return typeof e!="string"&&Object.keys(e).forEach(o=>{let r=Object.getOwnPropertyDescriptor(e,o);r&&(r.hasOwnProperty("value")&&(r.value=l(e[o])),Object.defineProperty(t,o,r));}),t},type:"regex"},{checker:e=>e instanceof Error,handler:e=>{let t=new e.constructor(e.message);return e.stack&&(t.stack=e.stack),e.code&&(t.code=e.code),e.errno&&(t.errno=e.errno),e.syscall&&(t.syscall=e.syscall),Object.keys(e).forEach(o=>{let r=Object.getOwnPropertyDescriptor(e,o);r&&(r.hasOwnProperty("value")&&(r.value=l(e[o])),Object.defineProperty(t,o,r));}),t},type:"error"},{checker:e=>e?.nodeType!==void 0&&e.cloneNode!==void 0,handler:e=>e.cloneNode(!0),type:"jsdom"},{checker:e=>ArrayBuffer.isView(e),handler:e=>k(e),type:"buffer"},{checker:e=>typeof e!="object"||e===null,handler:e=>typeof e=="number"||typeof e=="boolean"||typeof e=="string"?e.valueOf():e,type:"primitive"}],p=[...d,{checker:e=>e instanceof Map,handler:(e,t,o,r,n)=>new Map(f([...e],r,y(t,o,r,n))),type:"map"},{checker:e=>e instanceof Set,handler:(e,t,o,r,n)=>new Set(f([...e],r,y(t,o,r,n))),type:"set"}],E=e=>[...Object.getOwnPropertyNames(e),...Object.getOwnPropertySymbols(e)],f=(e,t,o)=>{let r=Array.from({length:e.length});for(let n=0;n<e.length;n++){let c=e[n],a=d.find(s=>s.checker(c));a?r[n]=a.handler(c):t(o,e,r,n);}return r},h=[e=>e instanceof WeakMap,e=>e instanceof WeakSet,e=>e instanceof SharedArrayBuffer,e=>e instanceof DataView,e=>e instanceof Promise,e=>e instanceof Blob],y=(e,t,o,r)=>n=>{if(typeof n!="object"||n===null||typeof n=="function")return n;for(let a of p)if(a.checker(n))return a.handler(n,e??!1,t,o,r);for(let a of h)if(a(n))throw new TypeError(`${n.constructor.name} objects cannot be cloned`);if(Array.isArray(n))return f(n,o,y(e,t,o,r));let c={};t(n,c);for(let a of E(n)){let s=Object.getOwnPropertyDescriptor(n,a).value;if(typeof s!="object"||s===null)c[a]=s;else {let i=p.find(u=>u.checker(s));i?c[a]=i.handler(s,e??!1,t,o,r):o(y(e,t,o,r),n,c,a);}}if(e){let a=Object.getPrototypeOf(n);Object.getPrototypeOf(c)!==a&&Object.setPrototypeOf(c,a);}return r(),Object.isExtensible(n)||Object.preventExtensions(c),Object.isSealed(n)&&Object.seal(c),Object.isFrozen(n)&&Object.freeze(c),c},O=(e,t)=>{let o=new Map;return y(t,(r,n)=>{o.set(r,n);},(r,n,c,a)=>{if(o.has(n[a]))c[a]=o.get(n[a]);else if(Array.isArray(n))c[a]=r(n[a]);else {let s=Object.getOwnPropertyDescriptor(n,a);s?.value&&(s.value=r(s.value),Object.defineProperty(c,a,s));}},()=>{o.delete(e);})(e)},l=(e,t)=>w(e)?t?.circles?O(e,t?.proto):y(t?.proto,()=>{},(o,r,n,c)=>{let a=r[c];n[c]=o(a);},()=>{})(e):e;
1
+ import { a, b as b$1 } from './chunk-LPGIVFCB.js';
2
2
 
3
- export { l as deepClone };
3
+ var u=(e,o)=>{let n=[];o.cache.set(e,n);for(let t=0,{length:a}=e;t<a;++t)n[t]=o.clone(e[t],o);return n},d=(e,o)=>{let n=[];return o.cache.set(e,n),a(e,n,o)};var h=e=>{let o={BigInt64Array,BigUint64Array,Buffer:Buffer.from,Float32Array,Float64Array,Int8Array,Int16Array,Int32Array,Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array};if(e instanceof ArrayBuffer){let t=new ArrayBuffer(e.byteLength),a=new Uint8Array(e);return new Uint8Array(t).set(a),t}let n=o[e.constructor.name]??void 0;return n?new n(e):new e.constructor([...e.buffer],e.byteOffset,e.length)},i=h;var g=e=>e.slice(0,e.size,e.type),V=g;var T=e=>new DataView(i(e.buffer)),m=T;var D=e=>new Date(e.getTime()),w=D;var M=(e,o)=>{let n=new e.constructor(e.message);return e.stack&&(n.stack=e.stack),e.code&&(n.code=e.code),e.errno&&(n.errno=e.errno),e.syscall&&(n.syscall=e.syscall),a(e,n,o)},E=M;var f=(e,o)=>{let n=new Map;return o.cache.set(e,n),e.forEach((t,a)=>{n.set(a,o.clone(t,o));}),n},x=(e,o)=>a(e,f(e,o),o);var S=(e,o)=>{let n=b$1(e);o.cache.set(e,n);for(let a in e)Object.hasOwnProperty.call(e,a)&&(n[a]=o.clone(e[a],o));let t=Object.getOwnPropertySymbols(e);for(let a=0,{length:p}=t,r;a<p;++a)r=t[a],Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=o.clone(e[r],o));return Object.isExtensible(e)||Object.preventExtensions(n),Object.isSealed(e)&&Object.seal(n),Object.isFrozen(e)&&Object.freeze(n),n},O=(e,o)=>{let n=b$1(e);o.cache.set(e,n);let t=a(e,n,o),a$1=Object.getPrototypeOf(e);return Object.getPrototypeOf(t)!==a$1&&Object.setPrototypeOf(t,a$1),Object.isExtensible(e)||Object.preventExtensions(t),Object.isSealed(e)&&Object.seal(t),Object.isFrozen(e)&&Object.freeze(t),t};var A=e=>{let o=new RegExp(e.source,e.flags);return o.lastIndex=e.lastIndex,o},k=(e,o)=>{let n=new RegExp(e.source,e.flags);return a(e,n,o)};var l=(e,o)=>{let n=new Set;return o.cache.set(e,n),e.forEach(t=>{n.add(o.clone(t,o));}),n},b=(e,o)=>a(e,l(e,o),o);var R=e=>typeof e=="object"&&e!==null||typeof e=="function",B={Array:u,ArrayBuffer:i,Blob:V,DataView:m,Date:w,Error:E,Function:(e,o)=>e,Map:f,Object:S,Promise:e=>{throw new TypeError(`${e.constructor.name} objects cannot be cloned`)},RegExp:A,Set:l,SharedArrayBuffer:(e,o)=>{throw new TypeError(`${e.constructor.name} objects cannot be cloned`)},WeakMap:e=>{throw new TypeError(`${e.constructor.name} objects cannot be cloned`)},WeakSet:e=>{throw new TypeError(`${e.constructor.name} objects cannot be cloned`)}},ce=(e,o)=>{if(!R(e))return e;let n={...B,...o?.strict?{Array:d,Map:x,Object:O,RegExp:k,Set:b}:{},...o?.handler},t=new WeakMap,a=(r,c)=>{if(!R(r))return r;if(c.cache.has(r))return c.cache.get(r);if(Array.isArray(r))return n.Array(r,c);if(typeof r=="object"&&r.constructor===Object&&r.nodeType===void 0)return n.Object(r,c);if(r.nodeType!==void 0&&r.cloneNode!==void 0)return r.cloneNode(!0);if(r instanceof Date)return n.Date(r,c);if(r instanceof RegExp)return n.RegExp(r,c);if(r instanceof Map)return n.Map(r,c);if(r instanceof Set)return n.Set(r,c);if(r instanceof Error)return n.Error(r,c);if(r instanceof ArrayBuffer||r instanceof Uint8Array||r instanceof Uint8ClampedArray||r instanceof Int8Array||r instanceof Uint16Array||r instanceof Int16Array||r instanceof Uint32Array||r instanceof Int32Array||r instanceof Float32Array||r instanceof Float64Array)return n.ArrayBuffer(r,c);if(r instanceof Blob)return n.Blob(r,c);if(r instanceof DataView)return n.DataView(r,c);if(r instanceof SharedArrayBuffer)return n.SharedArrayBuffer(r,c);if(r instanceof Promise)return n.Promise(r,c);if(r instanceof WeakMap)return n.WeakMap(r,c);if(r instanceof WeakSet)return n.WeakSet(r,c);if(r instanceof Function)return n.Function(r,c);if(typeof r=="object")return n.Object(r,c);throw new TypeError(`Type of ${typeof r} cannot be cloned`,r)},p=a(e,{cache:t,clone:a});return t=null,p};
4
+
5
+ export { ce as deepClone };
4
6
  //# sourceMappingURL=out.js.map
5
7
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["canValueHaveProperties","value","copyBuffer","current","typeHandlers","newBuffer","origView","Ctor","arrayCheckerHandlers","object","regexClone","key","desc","deepClone","error","objectCheckerHandlers","useProto","beforeIteration","onIteration","afterIteration","cloneArray","clone","getPropertyKeys","array","function_","cloned","index","handlerData","ch","invalidCloneTypeCheckers","data","invalidTypeChecker","clonedObject","propertyKey","objectPrototype","cloneCircles","originalData","references","object_","propertyDescriptor","options","propertyValue"],"mappings":"AA6BA,IAAMA,EAA0BC,GAC3B,OAAOA,GAAU,UAAYA,IAAU,MAAS,OAAOA,GAAU,WAQhEC,EAAcC,GAAsH,CACtI,IAAMC,EAAyD,CAC3D,cACA,eAGA,OAAQ,OAAO,KACf,aACA,aACA,UACA,WACA,WACA,WACA,kBACA,YACA,WACJ,EAEA,GAAID,aAAmB,YAAa,CAChC,IAAME,EAAY,IAAI,YAAYF,EAAQ,UAAU,EAC9CG,EAAW,IAAI,WAAWH,CAAO,EAGvC,OAFgB,IAAI,WAAWE,CAAS,EAEhC,IAAIC,CAAQ,EAEbD,CACX,CAEA,IAAME,EAAOH,EAAaD,EAAQ,YAAY,IAAI,EAElD,OAAII,EAEO,IAAIA,EAAKJ,CAAO,EAKpB,IAAKA,EAA4B,YAAY,CAAC,GAAGA,EAAQ,MAAM,EAAGA,EAAQ,WAAYA,EAAQ,MAAM,CAC/G,EAYMK,EAA+C,CACjD,CACI,QAAUC,GAAgBA,aAAkB,KAC5C,QAAUA,GAAgB,IAAI,KAAKA,CAAc,EACjD,KAAM,MACV,EACA,CACI,QAAUA,GAAgBA,aAAkB,OAC5C,QAAUA,GAA4B,CAElC,IAAMC,EAAa,IAAI,OAAOD,CAAM,EAGpC,OAAI,OAAOA,GAAW,UAClB,OAAO,KAAKA,CAAM,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WM,EAAME,EAAcrB,IAAQ,CAEpC,GAAI0B,EAAW,IAAIP,EAAKnB,CAAG,CAAC,EAGvBqB,EAA2CrB,CAAG,EAAI0B,EAAW,IAAIP,EAAKnB,CAAG,CAAC,UACpE,MAAM,QAAQmB,CAAI,EAGzBE,EAAarB,CAAa,EAAIa,EAAUM,EAAKnB,CAAG,CAAC,MAC9C,CACH,IAAM4B,EAAqB,OAAO,yBAAyBT,EAAMnB,CAAG,EAEhE4B,GAAoB,QACpBA,EAAmB,MAAQf,EAAUe,EAAmB,KAAK,EAE7D,OAAO,eAAeP,EAAcrB,EAAK4B,CAAkB,EAEnE,CACJ,EACA,IAAM,CACFF,EAAW,OAAOD,CAAY,CAClC,CACJ,EAAEA,CAAY,CAClB,EAkBavB,EAAY,CAAcuB,EAAiBI,IAC/CxC,EAAuBoC,CAAY,EAIpCI,GAAS,QAEFL,EAAgBC,EAAcI,GAAS,KAAK,EAGhDnB,EACHmB,GAAS,MACT,IAAM,CAAC,EACP,CAAChB,EAAWM,EAAME,EAAcrB,IAAQ,CAGpC,IAAM8B,EAAgBX,EAAKnB,CAAG,EAE1B,MAAM,QAAQmB,CAAI,EAElBE,EAAarB,CAAa,EAAIa,EAAUiB,CAAa,CAO7D,EACA,IAAM,CAAC,CACX,EAAEL,CAAY,EA3BHA","sourcesContent":["import type { TypedArray, UnknownRecord } from \"type-fest\";\n\ntype OnIteration = (function_: (oData: any) => unknown, levelData: unknown[] | UnknownRecord, clonedData: unknown[] | UnknownRecord, key: PropertyKey) => void;\n\ntype DataType = \"buffer\" | \"date\" | \"error\" | \"jsdom\" | \"map\" | \"object\" | \"primitive\" | \"regex\" | \"set\" | \"unknown\";\n\ntype DataTypeChecker = (object: any) => boolean;\n\ntype ObjectDataTypeHandler = (\n object: any,\n useProto: boolean,\n beforeIteration: (data: unknown, clonedData: unknown) => void,\n onIteration: OnIteration,\n afterIteration: () => void,\n) => any;\n\ninterface ArrayDataTypeMapping {\n checker: DataTypeChecker;\n handler: (object: any) => any;\n type: DataType;\n}\n\ninterface ObjectDataTypeMapping {\n checker: DataTypeChecker;\n handler: ObjectDataTypeHandler;\n type: DataType;\n}\n\n// eslint-disable-next-line @typescript-eslint/ban-types\nconst canValueHaveProperties = (value: unknown): value is NonNullable<Function | object> =>\n (typeof value === \"object\" && value !== null) || typeof value === \"function\";\n\n/**\n * Copy buffer function for cloning ArrayBuffer, ArrayBufferView, Buffer, or TypedArray objects.\n *\n * @param current - The buffer object to be copied. The type of `current` is `ArrayBuffer | ArrayBufferView | Buffer | TypedArray`.\n * @returns The copied buffer object. The return type of the function is `ArrayBuffer | ArrayBufferView | Buffer | TypedArray`.\n */\nconst copyBuffer = (current: ArrayBuffer | ArrayBufferView | Buffer | TypedArray): ArrayBuffer | ArrayBufferView | Buffer | TypedArray => {\n const typeHandlers: Record<string, new (buffer: any) => any> = {\n BigInt64Array,\n BigUint64Array,\n // @ts-expect-error - Buffer has no constructor\n // eslint-disable-next-line @typescript-eslint/unbound-method\n Buffer: Buffer.from,\n Float32Array,\n Float64Array,\n Int8Array,\n Int16Array,\n Int32Array,\n Uint8Array,\n Uint8ClampedArray,\n Uint16Array,\n Uint32Array,\n };\n\n if (current instanceof ArrayBuffer) {\n const newBuffer = new ArrayBuffer(current.byteLength);\n const origView = new Uint8Array(current);\n const newView = new Uint8Array(newBuffer);\n\n newView.set(origView);\n\n return newBuffer;\n }\n\n const Ctor = typeHandlers[current.constructor.name];\n\n if (Ctor) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return new Ctor(current);\n }\n\n // @ts-expect-error - Fallback to ArrayBufferView\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return new (current as ArrayBufferView).constructor([...current.buffer], current.byteOffset, current.length);\n};\n\ninterface FakeJSDOM {\n cloneNode?: (check: boolean) => unknown;\n nodeType?: unknown;\n}\n\ntype ExtendedError = Error & { code?: any; errno?: any; syscall?: any };\n\n/**\n * An Array of checker and handler mappings for different data types.\n */\nconst arrayCheckerHandlers: ArrayDataTypeMapping[] = [\n {\n checker: (object: any) => object instanceof Date,\n handler: (object: any) => new Date(object as Date),\n type: \"date\",\n },\n {\n checker: (object: any) => object instanceof RegExp,\n handler: (object: RegExp | string) => {\n // eslint-disable-next-line @rushstack/security/no-unsafe-regexp,security/detect-non-literal-regexp\n const regexClone = new RegExp(object);\n\n // Any enumerable properties...\n if (typeof object !== \"string\") {\n Object.keys(object).forEach((key) => {\n const desc = Object.getOwnPropertyDescriptor(object, key);\n\n if (desc) {\n // eslint-disable-next-line no-prototype-builtins\n if (desc.hasOwnProperty(\"value\")) {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n desc.value = deepClone(object[key as keyof RegExp]);\n }\n\n Object.defineProperty(regexClone, key, desc);\n }\n });\n }\n\n return regexClone;\n },\n type: \"regex\",\n },\n {\n checker: (object: any) => object instanceof Error,\n handler: (object: EvalError | ExtendedError | RangeError | ReferenceError | SyntaxError | TypeError | URIError) => {\n // @ts-expect-error - We don't know the type of the object, can be an error\n const error = new object.constructor(object.message) as\n | EvalError\n | ExtendedError\n | RangeError\n | ReferenceError\n | SyntaxError\n | TypeError\n | URIError;\n\n // If a `stack` property is present, copy it over...\n if (object.stack) {\n error.stack = object.stack;\n }\n\n // Node.js specific (system errors)...\n if ((object as ExtendedError).code) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n (error as ExtendedError).code = (object as ExtendedError).code;\n }\n\n if ((object as ExtendedError).errno) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n (error as ExtendedError).errno = (object as ExtendedError).errno;\n }\n\n if ((object as ExtendedError).syscall) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n (error as ExtendedError).syscall = (object as ExtendedError).syscall;\n }\n\n // Any enumerable properties...\n Object.keys(object).forEach((key) => {\n const desc = Object.getOwnPropertyDescriptor(object, key);\n\n if (desc) {\n // eslint-disable-next-line no-prototype-builtins\n if (desc.hasOwnProperty(\"value\")) {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n desc.value = deepClone(object[key as keyof Error]);\n }\n\n Object.defineProperty(error, key, desc);\n }\n });\n\n return error;\n },\n type: \"error\",\n },\n {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n checker: (object: FakeJSDOM): object is FakeJSDOM => object?.nodeType !== undefined && object.cloneNode !== undefined,\n handler: (object: Required<FakeJSDOM>) => object.cloneNode(true),\n type: \"jsdom\",\n },\n {\n checker: (object: any) => ArrayBuffer.isView(object),\n handler: (object: ArrayBuffer | ArrayBufferView | Buffer | TypedArray) => copyBuffer(object),\n type: \"buffer\",\n },\n {\n checker: (object: any) => typeof object !== \"object\" || object === null,\n // eslint-disable-next-line @typescript-eslint/ban-types\n handler: (object: Function | bigint | boolean | number | string | symbol | null | undefined) => {\n if (typeof object === \"number\" || typeof object === \"boolean\" || typeof object === \"string\") {\n return object.valueOf();\n }\n\n return object;\n },\n type: \"primitive\",\n },\n];\n\nconst objectCheckerHandlers: ObjectDataTypeMapping[] = [\n ...(arrayCheckerHandlers as unknown as ObjectDataTypeMapping[]),\n {\n checker: (object: any) => object instanceof Map,\n handler: (\n object: any,\n useProto: boolean,\n beforeIteration: (data: unknown, clonedData: unknown) => void,\n onIteration: OnIteration,\n afterIteration: () => void,\n ) =>\n new Map(\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n cloneArray([...(object as [])], onIteration, clone(useProto, beforeIteration, onIteration, afterIteration)) as ReadonlyArray<\n [unknown, unknown]\n >,\n ),\n type: \"map\",\n },\n {\n checker: (object) => object instanceof Set,\n handler: (\n object: any,\n useProto: boolean,\n beforeIteration: (data: unknown, clonedData: unknown) => void,\n onIteration: OnIteration,\n afterIteration: () => void,\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n ) => new Set(cloneArray([...(object as [])], onIteration, clone(useProto, beforeIteration, onIteration, afterIteration))),\n type: \"set\",\n },\n];\n\nconst getPropertyKeys = (object: any): (string | symbol)[] => [...Object.getOwnPropertyNames(object), ...Object.getOwnPropertySymbols(object)];\n\n/**\n * Clones an array by iterating through its elements and applying a function to each element.\n * If an element matches a defined checker function, the element is handled by a corresponding handler function.\n * Otherwise, the element is passed to the provided function for further processing.\n *\n * @param array - The array to clone. The type of `array` is `unknown[]`.\n * @param onIteration - A callback function called for each iteration. It is invoked with the provided function,\n * the original array, the cloned array, and the index of the current element. The type of `onIteration` is a function\n * that accepts four parameters: the provided function of type `(element: unknown) => unknown`, the original array of type `unknown[]`,\n * the cloned array of type `unknown[]`, and the index of the current element of type `number`.\n * @param function_ - The function to apply to each element that does not match a checker function. The type of `function_` is\n * a function that accepts one parameter of type `unknown`.\n * @returns A new array containing the cloned elements. The return type of the function is `unknown[]`.\n */\nconst cloneArray = (array: any[], onIteration: OnIteration, function_: (values: unknown) => unknown): unknown[] => {\n const cloned = Array.from({ length: array.length });\n\n // eslint-disable-next-line no-plusplus,no-loops/no-loops\n for (let index = 0; index < array.length; index++) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const current = array[index];\n const handlerData = arrayCheckerHandlers.find((ch) => ch.checker(current));\n\n if (handlerData) {\n cloned[index] = handlerData.handler(current);\n } else {\n onIteration(function_, array, cloned, index);\n }\n }\n\n return cloned;\n};\n\nconst invalidCloneTypeCheckers: ((object: any) => boolean)[] = [\n (object: any) => object instanceof WeakMap,\n (object: any) => object instanceof WeakSet,\n (object: any) => object instanceof SharedArrayBuffer,\n (object: any) => object instanceof DataView,\n (object: any) => object instanceof Promise,\n (object: any) => object instanceof Blob,\n];\n\n/**\n * Function that clones a given object with optional configuration parameters.\n * It creates a deep clone of the object, including arrays and nested objects.\n * It applies handlers for specific object types, before and after iteration functions,\n * and provides a callback function for each iteration step.\n *\n * @param useProto - Flag indicating whether to use the prototype of the object. The type of `useProto` is `boolean`.\n * @param beforeIteration - Function to be called before each iteration step with the current data\n * being iterated and the cloned data object. The type of `beforeIteration` is a function that\n * accepts two parameters of type `unknown`.\n * @param onIteration - Function to be called for each iteration step with the current data being\n * iterated, the cloned data object, and the property key. The type of `onIteration` is a function\n * that accepts two parameters of type `unknown[] | UnknownRecord` and one parameter of type `string | number`.\n * @param afterIteration - Function to be called after all iterations have completed. The type\n * of `afterIteration` is a function that accepts no parameters.\n * @returns The cloned object. The return type of the function is `unknown`.\n */\nconst clone =\n (useProto: boolean | undefined, beforeIteration: (data: unknown, clonedData: unknown) => void, onIteration: OnIteration, afterIteration: () => void) =>\n // eslint-disable-next-line sonarjs/cognitive-complexity\n (data: any): unknown => {\n if (typeof data !== \"object\" || data === null || typeof data === \"function\") {\n return data;\n }\n\n // eslint-disable-next-line no-restricted-syntax,no-loops/no-loops\n for (const handlerData of objectCheckerHandlers) {\n if (handlerData.checker(data)) {\n return handlerData.handler(data, useProto ?? false, beforeIteration, onIteration, afterIteration);\n }\n }\n\n // eslint-disable-next-line no-restricted-syntax,no-loops/no-loops\n for (const invalidTypeChecker of invalidCloneTypeCheckers) {\n if (invalidTypeChecker(data)) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n throw new TypeError(`${data.constructor.name} objects cannot be cloned`);\n }\n }\n\n if (Array.isArray(data)) {\n return cloneArray(data, onIteration, clone(useProto, beforeIteration, onIteration, afterIteration));\n }\n\n const clonedObject: UnknownRecord = {};\n\n beforeIteration(data, clonedObject);\n\n // eslint-disable-next-line no-restricted-syntax,no-loops/no-loops\n for (const propertyKey of getPropertyKeys(data)) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const current = (Object.getOwnPropertyDescriptor(data, propertyKey) as PropertyDescriptor).value;\n\n if (typeof current !== \"object\" || current === null) {\n clonedObject[propertyKey] = current;\n } else {\n const handlerData = objectCheckerHandlers.find((ch) => ch.checker(current));\n\n if (handlerData) {\n clonedObject[propertyKey] = handlerData.handler(current, useProto ?? false, beforeIteration, onIteration, afterIteration);\n } else {\n onIteration(clone(useProto, beforeIteration, onIteration, afterIteration), data as unknown[] | UnknownRecord, clonedObject, propertyKey);\n }\n }\n }\n\n if (useProto) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const objectPrototype: object | null = Object.getPrototypeOf(data);\n\n if (Object.getPrototypeOf(clonedObject) !== objectPrototype) {\n Object.setPrototypeOf(clonedObject, objectPrototype);\n }\n }\n\n afterIteration();\n\n if (!Object.isExtensible(data)) {\n Object.preventExtensions(clonedObject);\n }\n\n if (Object.isSealed(data)) {\n Object.seal(clonedObject);\n }\n\n if (Object.isFrozen(data)) {\n Object.freeze(clonedObject);\n }\n\n return clonedObject;\n };\n\n/**\n * Function that clones the given data object, including circular references.\n *\n * @template T - The type of the original data.\n * @param originalData - The original data object to clone. It uses the generic parameter `T`.\n * @param useProto - Optional. Whether to use `__proto__` when cloning objects. The type of `useProto` is `boolean`.\n * @returns The cloned data object. The return type is defined by the generic parameter `T`.\n */\nconst cloneCircles = <T>(originalData: T, useProto: boolean | undefined) => {\n const references = new Map<unknown, unknown>();\n\n return clone(\n useProto,\n (object_, clonedObject) => {\n references.set(object_, clonedObject);\n },\n (function_, data, clonedObject, key) => {\n // @ts-expect-error - We don't know the type of the data, can be an object or array\n if (references.has(data[key])) {\n // @ts-expect-error - We don't know the type of the data, can be an object or array\n // eslint-disable-next-line no-param-reassign\n (clonedObject as unknown[] | UnknownRecord)[key] = references.get(data[key]);\n } else if (Array.isArray(data)) {\n // @ts-expect-error - We don't know the type of the data, can be an object or array\n // eslint-disable-next-line no-param-reassign\n clonedObject[key as number] = function_(data[key]);\n } else {\n const propertyDescriptor = Object.getOwnPropertyDescriptor(data, key);\n\n if (propertyDescriptor?.value) {\n propertyDescriptor.value = function_(propertyDescriptor.value);\n\n Object.defineProperty(clonedObject, key, propertyDescriptor);\n }\n }\n },\n () => {\n references.delete(originalData);\n },\n )(originalData);\n};\n\ntype DeepReadwrite<T> = T extends object | [] ? { -readonly [P in keyof T]: DeepReadwrite<T[P]> } : T;\n\ninterface Options {\n circles?: boolean;\n proto?: boolean;\n}\n\n/**\n * Function that creates a deep clone of an object or array.\n *\n * @template T - The type of the original data.\n * @param originalData - The original data to be cloned. It uses the generic parameter `T`.\n * @param options - Optional. The cloning options. Type of this parameter is `Options`.\n * @returns The deep cloned data with its type as `DeepReadwrite<T>`.\n */\n// eslint-disable-next-line import/prefer-default-export,import/no-unused-modules\nexport const deepClone = <T = unknown>(originalData: T, options?: Options): DeepReadwrite<T> => {\n if (!canValueHaveProperties(originalData)) {\n return originalData as DeepReadwrite<T>;\n }\n\n if (options?.circles) {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n return cloneCircles<T>(originalData, options?.proto) as DeepReadwrite<T>;\n }\n\n return clone(\n options?.proto,\n () => {},\n (function_, data, clonedObject, key) => {\n // @ts-expect-error - We don't know the type of the data, can be an object or array\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const propertyValue = data[key];\n\n if (Array.isArray(data)) {\n // eslint-disable-next-line no-param-reassign\n clonedObject[key as number] = function_(propertyValue);\n } else {\n // Assign properties if possible to avoid expensive operations\n // @ts-expect-error - We don't know the type of the data, can be an object or array\n // eslint-disable-next-line no-param-reassign\n clonedObject[key] = function_(propertyValue);\n }\n },\n () => {},\n )(originalData) as DeepReadwrite<T>;\n};\n"]}
1
+ {"version":3,"sources":["../src/handler/copy-array.ts","../src/handler/copy-array-buffer.ts","../src/handler/copy-blob.ts","../src/handler/copy-data-view.ts","../src/handler/copy-date.ts","../src/handler/copy-error.ts","../src/handler/copy-map.ts","../src/handler/copy-object.ts","../src/handler/copy-regexp.ts","../src/handler/copy-set.ts","../src/index.ts"],"names":["copyArrayLoose","array","state","clone","index","length","copyArrayStrict","copy_own_properties_default","copyArrayBuffer","arrayBuffer","typeHandlers","newBuffer","origView","Ctor","copy_array_buffer_default","copyBlob","blob","copy_blob_default","copyDataView","dataView","copy_data_view_default","copyDate","date","copy_date_default","copyError","object","error","copy_error_default","copyMapLoose","map","value","key","copyMapStrict","copyObjectLoose","get_clean_clone_default","symbols","symbol","copyObjectStrict","clonedObject","objectPrototype","copyRegExpLoose","regExp","copyRegExpStrict","copySetLoose","set","copySetStrict","canValueHaveProperties","handlers","_state","deepClone","originalData","options","cloner","cache","cloned"],"mappings":"+CAGO,IAAMA,EAAiB,CAA0BC,EAAcC,IAAwB,CAC1F,IAAMC,EAAe,CAAC,EAGtBD,EAAM,MAAM,IAAID,EAAOE,CAAK,EAG5B,QAASC,EAAQ,EAAG,CAAE,OAAAC,CAAO,EAAIJ,EAAOG,EAAQC,EAAQ,EAAED,EACtDD,EAAMC,CAAK,EAAIF,EAAM,MAAMD,EAAMG,CAAK,EAAGF,CAAK,EAGlD,OAAOC,CACX,EAKaG,EAAkB,CAA0BL,EAAcC,IAAwB,CAC3F,IAAMC,EAAe,CAAC,EAGtB,OAAAD,EAAM,MAAM,IAAID,EAAOE,CAAK,EAErBI,EAAkBN,EAAOE,EAAOD,CAAK,CAChD,ECzBA,IAAMM,EAAsFC,GAA8B,CAEtH,IAAMC,EAAyD,CAC3D,cACA,eAGA,OAAQ,OAAO,KACf,aACA,aACA,UACA,WACA,WACA,WACA,kBACA,YACA,WACJ,EAEA,GAAID,aAAuB,YAAa,CACpC,IAAME,EAAY,IAAI,YAAYF,EAAY,UAAU,EAClDG,EAAW,IAAI,WAAWH,CAAW,EAG3C,OAFgB,IAAI,WAAWE,CAAS,EAEhC,IAAIC,CAAQ,EAEbD,CACX,CAEA,IAAME,EAAOH,EAAaD,EAAY,YAAY,IAAI,GAAK,OAE3D,OAAII,EAEO,IAAIA,EAAKJ,CAAW,EAKxB,IAAKA,EAAgC,YAAY,CAAC,GAAGA,EAAY,MAAM,EAAGA,EAAY,WAAYA,EAAY,MAAM,CAC/H,EAEOK,EAAQN,EC3Cf,IAAMO,EAAgCC,GAAuBA,EAAK,MAAM,EAAGA,EAAK,KAAMA,EAAK,IAAI,EAExFC,EAAQF,ECAf,IAAMG,EAAwCC,GAA2B,IAAI,SAASL,EAAgBK,EAAS,MAAM,CAAC,EAE/GC,EAAQF,ECJf,IAAMG,EAAgCC,GAAuB,IAAI,K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I,UAAU,WAAW,OAAO4B,CAAK,oBAAqBA,CAAK,CACzE,EAGMwB,EAASnD,EAAM+C,EAAc,CAAE,MAAAG,EAAO,MAAAlD,CAAM,CAAC,EAGnD,OAAAkD,EAAQ,KAEDC,CACX","sourcesContent":["import type { State } from \"../types\";\nimport copyOwnProperties from \"../utils/copy-own-properties\";\n\nexport const copyArrayLoose = <Value extends unknown[]>(array: Value, state: State): Value => {\n const clone: Value = [] as unknown as Value;\n\n // set in the cache immediately to be able to reuse the object recursively\n state.cache.set(array, clone);\n\n // eslint-disable-next-line no-loops/no-loops,no-plusplus\n for (let index = 0, { length } = array; index < length; ++index) {\n clone[index] = state.clone(array[index], state);\n }\n\n return clone;\n};\n\n/**\n * Deeply copy the indexed values in the array, as well as any custom properties.\n */\nexport const copyArrayStrict = <Value extends unknown[]>(array: Value, state: State): Value => {\n const clone: Value = [] as unknown as Value;\n\n // set in the cache immediately to be able to reuse the object recursively\n state.cache.set(array, clone);\n\n return copyOwnProperties(array, clone, state);\n};\n","import type { TypedArray } from \"type-fest\";\n\nconst copyArrayBuffer = <Value extends ArrayBuffer | ArrayBufferView | Buffer | TypedArray>(arrayBuffer: Value): Value => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const typeHandlers: Record<string, new (buffer: any) => any> = {\n BigInt64Array,\n BigUint64Array,\n // @ts-expect-error - Buffer has no constructor\n // eslint-disable-next-line @typescript-eslint/unbound-method\n Buffer: Buffer.from,\n Float32Array,\n Float64Array,\n Int8Array,\n Int16Array,\n Int32Array,\n Uint8Array,\n Uint8ClampedArray,\n Uint16Array,\n Uint32Array,\n };\n\n if (arrayBuffer instanceof ArrayBuffer) {\n const newBuffer = new ArrayBuffer(arrayBuffer.byteLength);\n const origView = new Uint8Array(arrayBuffer);\n const newView = new Uint8Array(newBuffer);\n\n newView.set(origView);\n\n return newBuffer as Value;\n }\n\n const Ctor = typeHandlers[arrayBuffer.constructor.name] ?? undefined;\n\n if (Ctor) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return new Ctor(arrayBuffer);\n }\n\n // @ts-expect-error - Fallback to ArrayBufferView\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return new (arrayBuffer as ArrayBufferView).constructor([...arrayBuffer.buffer], arrayBuffer.byteOffset, arrayBuffer.length);\n};\n\nexport default copyArrayBuffer;\n","const copyBlob = <Value extends Blob>(blob: Value): Value => blob.slice(0, blob.size, blob.type) as Value;\n\nexport default copyBlob;\n","import copyArrayBuffer from \"./copy-array-buffer\";\n\nconst copyDataView = <Value extends DataView>(dataView: Value): Value => new DataView(copyArrayBuffer(dataView.buffer)) as Value;\n\nexport default copyDataView;\n","const copyDate = <Value extends Date>(date: Value): Value => new Date(date.getTime()) as Value;\n\nexport default copyDate;\n","import type { State } from \"../types\";\nimport copyOwnProperties from \"../utils/copy-own-properties\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype ExtendedError = Error & { code?: any; errno?: any; syscall?: any };\n\nconst copyError = <Value extends EvalError | ExtendedError | RangeError | ReferenceError | SyntaxError | TypeError | URIError>(\n object: Value,\n state: State,\n): Value => {\n // @ts-expect-error - We don't know the type of the object, can be an error\n const error = new object.constructor(object.message) as EvalError | ExtendedError | RangeError | ReferenceError | SyntaxError | TypeError | URIError;\n\n // If a `stack` property is present, copy it over...\n if (object.stack) {\n error.stack = object.stack;\n }\n\n // Node.js specific (system errors)...\n if ((object as ExtendedError).code) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n (error as ExtendedError).code = (object as ExtendedError).code;\n }\n\n if ((object as ExtendedError).errno) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n (error as ExtendedError).errno = (object as ExtendedError).errno;\n }\n\n if ((object as ExtendedError).syscall) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n (error as ExtendedError).syscall = (object as ExtendedError).syscall;\n }\n\n return copyOwnProperties(object, error, state) as Value;\n};\n\nexport default copyError;\n","import type { State } from \"../types\";\nimport copyOwnProperties from \"../utils/copy-own-properties\";\n\nexport const copyMapLoose = <Value extends Map<unknown, unknown>>(map: Value, state: State): Value => {\n const clone = new Map() as Value;\n\n // set in the cache immediately to be able to reuse the object recursively\n state.cache.set(map, clone);\n\n map.forEach((value, key) => {\n clone.set(key, state.clone(value, state));\n });\n\n return clone;\n};\n\n/**\n * Deeply copy the keys and values of the original, as well as any custom properties.\n */\nexport const copyMapStrict = <Value extends Map<unknown, unknown>>(map: Value, state: State): Value => copyOwnProperties(map, copyMapLoose<Value>(map, state), state);\n","import type { EmptyObject, UnknownRecord } from \"type-fest\";\n\nimport type { State } from \"../types\";\nimport copyOwnProperties from \"../utils/copy-own-properties\";\nimport getCleanClone from \"../utils/get-clean-clone\";\n\nexport const copyObjectLoose = <Value extends UnknownRecord>(object: Value, state: State): Value => {\n const clone = getCleanClone(object) as EmptyObject;\n\n // set in the cache immediately to be able to reuse the object recursively\n state.cache.set(object, clone);\n\n // eslint-disable-next-line no-loops/no-loops,no-restricted-syntax\n for (const key in object) {\n if (Object.hasOwnProperty.call(object, key)) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-explicit-any\n (clone as any)[key] = state.clone(object[key], state);\n }\n }\n\n const symbols = Object.getOwnPropertySymbols(object);\n\n // eslint-disable-next-line no-loops/no-loops,no-plusplus\n for (let index = 0, { length } = symbols, symbol; index < length; ++index) {\n symbol = symbols[index] as symbol;\n\n if (Object.prototype.propertyIsEnumerable.call(object, symbol)) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-explicit-any\n (clone as any)[symbol] = state.clone((object as any)[symbol], state);\n }\n }\n\n if (!Object.isExtensible(object)) {\n Object.preventExtensions(clone);\n }\n\n if (Object.isSealed(object)) {\n Object.seal(clone);\n }\n\n if (Object.isFrozen(object)) {\n Object.freeze(clone);\n }\n\n return clone as Value;\n};\n\n/**\n * Deeply copy the properties (keys and symbols) and values of the original, as well\n * as any hidden or non-enumerable properties.\n */\nexport const copyObjectStrict = <Value extends UnknownRecord>(object: Value, state: State): Value => {\n const clone = getCleanClone(object) as EmptyObject;\n\n // set in the cache immediately to be able to reuse the object recursively\n state.cache.set(object, clone);\n\n const clonedObject = copyOwnProperties<Value>(object, clone as Value, state);\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const objectPrototype: object | null = Object.getPrototypeOf(object);\n\n if (Object.getPrototypeOf(clonedObject) !== objectPrototype) {\n Object.setPrototypeOf(clonedObject, objectPrototype);\n }\n\n if (!Object.isExtensible(object)) {\n Object.preventExtensions(clonedObject);\n }\n\n if (Object.isSealed(object)) {\n Object.seal(clonedObject);\n }\n\n if (Object.isFrozen(object)) {\n Object.freeze(clonedObject);\n }\n\n return clonedObject as Value;\n};\n","import type { State } from \"../types\";\nimport copyOwnProperties from \"../utils/copy-own-properties\";\n\nexport const copyRegExpLoose = <Value extends RegExp>(regExp: Value): Value => {\n // eslint-disable-next-line @rushstack/security/no-unsafe-regexp,security/detect-non-literal-regexp\n const clone = new RegExp(regExp.source, regExp.flags) as Value;\n\n clone.lastIndex = regExp.lastIndex;\n\n return clone;\n};\n\nexport const copyRegExpStrict = <Value extends RegExp>(regExp: Value, state: State): Value => {\n // eslint-disable-next-line @rushstack/security/no-unsafe-regexp,security/detect-non-literal-regexp\n const clone = new RegExp(regExp.source, regExp.flags) as Value;\n\n return copyOwnProperties(regExp, clone, state);\n};\n","import type { State } from \"../types\";\nimport copyOwnProperties from \"../utils/copy-own-properties\";\n\nexport const copySetLoose = <Value extends Set<unknown>>(set: Value, state: State): Value => {\n const clone = new Set() as Value;\n\n // set in the cache immediately to be able to reuse the object recursively\n state.cache.set(set, clone);\n\n set.forEach((value) => {\n clone.add(state.clone(value, state));\n });\n\n return clone;\n}\n\n/**\n * Deeply copy the values of the original, as well as any custom properties.\n */\nexport const copySetStrict = <Value extends Set<unknown>>(set: Value, state: State): Value => copyOwnProperties(set, copySetLoose<Value>(set, state), state);\n","import type { UnknownRecord } from \"type-fest\";\n\nimport { copyArrayLoose, copyArrayStrict } from \"./handler/copy-array\";\nimport copyArrayBuffer from \"./handler/copy-array-buffer\";\nimport copyBlob from \"./handler/copy-blob\";\nimport copyDataView from \"./handler/copy-data-view\";\nimport copyDate from \"./handler/copy-date\";\nimport copyError from \"./handler/copy-error\";\nimport { copyMapLoose, copyMapStrict } from \"./handler/copy-map\";\nimport { copyObjectLoose, copyObjectStrict } from \"./handler/copy-object\";\nimport { copyRegExpLoose, copyRegExpStrict } from \"./handler/copy-regexp\";\nimport { copySetLoose, copySetStrict } from \"./handler/copy-set\";\nimport type { Options, State } from \"./types\";\n\n// eslint-disable-next-line @typescript-eslint/ban-types\nconst canValueHaveProperties = (value: unknown): value is NonNullable<Function | object> =>\n (typeof value === \"object\" && value !== null) || typeof value === \"function\";\n\n/**\n * handler mappings for different data types.\n */\nconst handlers = {\n Array: copyArrayLoose,\n ArrayBuffer: copyArrayBuffer,\n Blob: copyBlob,\n DataView: copyDataView,\n Date: copyDate,\n Error: copyError,\n // eslint-disable-next-line @typescript-eslint/ban-types,@typescript-eslint/no-unused-vars\n Function: (object: Function, _state: State) => object,\n Map: copyMapLoose,\n Object: copyObjectLoose,\n Promise: (object: Promise<unknown>) => {\n throw new TypeError(`${object.constructor.name} objects cannot be cloned`);\n },\n RegExp: copyRegExpLoose,\n Set: copySetLoose,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n SharedArrayBuffer: (object: SharedArrayBuffer, _state: State) => {\n throw new TypeError(`${object.constructor.name} objects cannot be cloned`);\n },\n WeakMap: (object: WeakMap<any, any>) => {\n throw new TypeError(`${object.constructor.name} objects cannot be cloned`);\n },\n WeakSet: (object: WeakSet<any>) => {\n throw new TypeError(`${object.constructor.name} objects cannot be cloned`);\n },\n};\n\ntype DeepReadwrite<T> = T extends object | [] ? { -readonly [P in keyof T]: DeepReadwrite<T[P]> } : T;\n\ninterface FakeJSDOM {\n cloneNode?: (check: boolean) => unknown;\n nodeType?: unknown;\n}\n\n/**\n * Function that creates a deep clone of an object or array.\n *\n * @template T - The type of the original data.\n * @param originalData - The original data to be cloned. It uses the generic parameter `T`.\n * @param options - Optional. The cloning options. Type of this parameter is `Options`.\n * @returns The deep cloned data with its type as `DeepReadwrite<T>`.\n */\n// eslint-disable-next-line import/prefer-default-export,sonarjs/cognitive-complexity\nexport const deepClone = <T>(originalData: T, options?: Options): DeepReadwrite<T> => {\n if (!canValueHaveProperties(originalData)) {\n return originalData as DeepReadwrite<T>;\n }\n\n const cloner = {\n ...handlers,\n ...(options?.strict ? { Array: copyArrayStrict, Map: copyMapStrict, Object: copyObjectStrict, RegExp: copyRegExpStrict, Set: copySetStrict } : {}),\n ...options?.handler,\n };\n\n let cache: WeakMap<any, any> | null = new WeakMap();\n\n const clone = (value: any, state: State): any => {\n if (!canValueHaveProperties(value)) {\n return value as DeepReadwrite<T>;\n }\n\n if (state.cache.has(value)) {\n return state.cache.get(value);\n }\n\n if (Array.isArray(value)) {\n return cloner.Array(value, state);\n }\n\n if (typeof value === \"object\" && value.constructor === Object && (value as FakeJSDOM).nodeType === undefined) {\n return cloner.Object(value as UnknownRecord, state);\n }\n\n if ((value as FakeJSDOM).nodeType !== undefined && (value as FakeJSDOM).cloneNode !== undefined) {\n return (value as { cloneNode: (check: boolean) => unknown }).cloneNode(true);\n }\n\n if (value instanceof Date) {\n return cloner.Date(value, state);\n }\n\n if (value instanceof RegExp) {\n return cloner.RegExp(value, state);\n }\n\n if (value instanceof Map) {\n return cloner.Map(value, state);\n }\n\n if (value instanceof Set) {\n return cloner.Set(value, state);\n }\n\n if (value instanceof Error) {\n return cloner.Error(value, state);\n }\n\n if (\n value instanceof ArrayBuffer ||\n value instanceof Uint8Array ||\n value instanceof Uint8ClampedArray ||\n value instanceof Int8Array ||\n value instanceof Uint16Array ||\n value instanceof Int16Array ||\n value instanceof Uint32Array ||\n value instanceof Int32Array ||\n value instanceof Float32Array ||\n value instanceof Float64Array\n ) {\n return cloner.ArrayBuffer(value, state);\n }\n\n if (value instanceof Blob) {\n return cloner.Blob(value, state);\n }\n\n if (value instanceof DataView) {\n return cloner.DataView(value, state);\n }\n\n if (value instanceof SharedArrayBuffer) {\n return cloner.SharedArrayBuffer(value, state);\n }\n\n if (value instanceof Promise) {\n return cloner.Promise(value, state);\n }\n\n if (value instanceof WeakMap) {\n return cloner.WeakMap(value, state);\n }\n\n if (value instanceof WeakSet) {\n return cloner.WeakSet(value, state);\n }\n\n if (value instanceof Function) {\n return cloner.Function(value, state);\n }\n\n if (typeof value === \"object\") {\n return cloner.Object(value as UnknownRecord, state);\n }\n\n throw new TypeError(`Type of ${typeof value} cannot be cloned`, value);\n };\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const cloned = clone(originalData, { cache, clone });\n\n // Reset the cache to free up memory\n cache = null;\n\n return cloned as DeepReadwrite<T>;\n};\n"]}
@@ -0,0 +1,30 @@
1
+ type InternalHandler<Value> = (value: Value, state: State) => Value;
2
+ interface State {
3
+ cache: WeakMap<any, unknown>;
4
+ clone: InternalHandler<unknown>;
5
+ }
6
+ type Options = {
7
+ handler?: {
8
+ Array: InternalHandler<unknown[]>;
9
+ ArrayBuffer: InternalHandler<ArrayBuffer>;
10
+ Blob: InternalHandler<Blob>;
11
+ DataView: InternalHandler<DataView>;
12
+ Date: InternalHandler<Date>;
13
+ Error: InternalHandler<Error>;
14
+ Float32Array: InternalHandler<Float32Array>;
15
+ Float64Array: InternalHandler<Float64Array>;
16
+ Int8Array: InternalHandler<Int8Array>;
17
+ Int16Array: InternalHandler<Int16Array>;
18
+ Int32Array: InternalHandler<Int32Array>;
19
+ Map: InternalHandler<Map<unknown, unknown>>;
20
+ Object: InternalHandler<Record<string, unknown>>;
21
+ Promise: InternalHandler<Promise<unknown>>;
22
+ RegExp: InternalHandler<RegExp>;
23
+ Set: InternalHandler<Set<unknown>>;
24
+ WeakMap: InternalHandler<WeakMap<any, unknown>>;
25
+ WeakSet: InternalHandler<WeakSet<any>>;
26
+ };
27
+ strict?: boolean;
28
+ };
29
+
30
+ export type { Options as O, State as S };
@@ -0,0 +1,30 @@
1
+ type InternalHandler<Value> = (value: Value, state: State) => Value;
2
+ interface State {
3
+ cache: WeakMap<any, unknown>;
4
+ clone: InternalHandler<unknown>;
5
+ }
6
+ type Options = {
7
+ handler?: {
8
+ Array: InternalHandler<unknown[]>;
9
+ ArrayBuffer: InternalHandler<ArrayBuffer>;
10
+ Blob: InternalHandler<Blob>;
11
+ DataView: InternalHandler<DataView>;
12
+ Date: InternalHandler<Date>;
13
+ Error: InternalHandler<Error>;
14
+ Float32Array: InternalHandler<Float32Array>;
15
+ Float64Array: InternalHandler<Float64Array>;
16
+ Int8Array: InternalHandler<Int8Array>;
17
+ Int16Array: InternalHandler<Int16Array>;
18
+ Int32Array: InternalHandler<Int32Array>;
19
+ Map: InternalHandler<Map<unknown, unknown>>;
20
+ Object: InternalHandler<Record<string, unknown>>;
21
+ Promise: InternalHandler<Promise<unknown>>;
22
+ RegExp: InternalHandler<RegExp>;
23
+ Set: InternalHandler<Set<unknown>>;
24
+ WeakMap: InternalHandler<WeakMap<any, unknown>>;
25
+ WeakSet: InternalHandler<WeakSet<any>>;
26
+ };
27
+ strict?: boolean;
28
+ };
29
+
30
+ export type { Options as O, State as S };
package/dist/utils.cjs ADDED
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ var chunkULIBPEBE_cjs = require('./chunk-ULIBPEBE.cjs');
4
+
5
+
6
+
7
+ Object.defineProperty(exports, 'copyOwnProperties', {
8
+ enumerable: true,
9
+ get: function () { return chunkULIBPEBE_cjs.a; }
10
+ });
11
+ Object.defineProperty(exports, 'getCleanClone', {
12
+ enumerable: true,
13
+ get: function () { return chunkULIBPEBE_cjs.b; }
14
+ });
15
+ //# sourceMappingURL=out.js.map
16
+ //# sourceMappingURL=utils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ import { S as State } from './types-QwwO2Lbg.cjs';
2
+
3
+ declare const copyOwnProperties: <Value>(value: Value, clone: Value, state: State) => Value;
4
+
5
+ declare const getCleanClone: (input: unknown) => any;
6
+
7
+ export { copyOwnProperties, getCleanClone };
@@ -0,0 +1,7 @@
1
+ import { S as State } from './types-QwwO2Lbg.js';
2
+
3
+ declare const copyOwnProperties: <Value>(value: Value, clone: Value, state: State) => Value;
4
+
5
+ declare const getCleanClone: (input: unknown) => any;
6
+
7
+ export { copyOwnProperties, getCleanClone };
package/dist/utils.js ADDED
@@ -0,0 +1,3 @@
1
+ export { a as copyOwnProperties, b as getCleanClone } from './chunk-LPGIVFCB.js';
2
+ //# sourceMappingURL=out.js.map
3
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,40 +1,41 @@
1
1
  {
2
2
  "name": "@visulima/deep-clone",
3
- "version": "1.0.7",
3
+ "version": "2.0.0",
4
4
  "description": "Fastest deep clone implementation.",
5
5
  "keywords": [
6
6
  "anolilab",
7
- "deep-clone",
8
7
  "clone",
9
- "fast-clone",
10
- "object",
11
- "obj",
12
- "properties",
8
+ "clone-deep",
13
9
  "copy",
14
10
  "deep",
15
- "recursive",
16
- "key",
17
- "keys",
18
- "values",
19
- "prop",
20
- "deepclone",
11
+ "deep-clone",
21
12
  "deep-copy",
13
+ "deepclone",
22
14
  "deepcopy",
23
15
  "fast",
24
- "performance",
25
- "performant",
26
- "fastclone",
27
- "fastcopy",
28
- "fast-deep-clone",
16
+ "fast-clone",
29
17
  "fast-copy",
18
+ "fast-deep-clone",
30
19
  "fast-deep-copy",
31
- "clone-deep",
20
+ "fastclone",
21
+ "fastcopy",
32
22
  "fastest-json-copy",
23
+ "key",
24
+ "keys",
33
25
  "lodash.clonedeep",
34
26
  "nano-copy",
27
+ "obj",
28
+ "object",
29
+ "performance",
30
+ "performant",
35
31
  "plain-object-clone",
32
+ "prop",
33
+ "properties",
36
34
  "ramda",
37
- "standard"
35
+ "recursive",
36
+ "standard",
37
+ "values",
38
+ "visulima"
38
39
  ],
39
40
  "homepage": "https://www.visulima.com/docs/package/deep-clone",
40
41
  "repository": {
@@ -61,15 +62,29 @@
61
62
  "type": "module",
62
63
  "exports": {
63
64
  ".": {
65
+ "require": {
66
+ "types": "./dist/index.d.cts",
67
+ "default": "./dist/index.cjs"
68
+ },
64
69
  "import": {
65
70
  "types": "./dist/index.d.ts",
66
71
  "default": "./dist/index.js"
67
72
  }
68
73
  },
74
+ "./utils": {
75
+ "require": {
76
+ "types": "./dist/utils.d.cts",
77
+ "default": "./dist/utils.cjs"
78
+ },
79
+ "import": {
80
+ "types": "./dist/utils.d.ts",
81
+ "default": "./dist/utils.js"
82
+ }
83
+ },
69
84
  "./package.json": "./package.json"
70
85
  },
86
+ "main": "dist/index.cjs",
71
87
  "module": "dist/index.js",
72
- "source": "src/index.ts",
73
88
  "types": "dist/index.d.ts",
74
89
  "files": [
75
90
  "dist/**",
@@ -81,7 +96,6 @@
81
96
  "build": "cross-env NODE_ENV=development tsup",
82
97
  "build:prod": "cross-env NODE_ENV=production tsup",
83
98
  "clean": "rimraf node_modules dist .eslintcache",
84
- "coverage": "vitest run --coverage",
85
99
  "dev": "pnpm run build --watch",
86
100
  "lint:eslint": "eslint . --ext js,cjs,mjs,jsx,ts,tsx,json,yaml,yml,md,mdx --max-warnings=0 --config .eslintrc.cjs",
87
101
  "lint:eslint:fix": "pnpm run lint:eslint --fix",
@@ -91,47 +105,49 @@
91
105
  "lint:types": "tsc --noEmit",
92
106
  "test": "vitest run",
93
107
  "test:bench": "vitest bench",
108
+ "test:coverage": "vitest run --coverage",
109
+ "test:ui": "vitest --ui --coverage.enabled=true",
94
110
  "test:watch": "vitest"
95
111
  },
96
112
  "devDependencies": {
97
- "@anolilab/eslint-config": "^15.0.2",
98
- "@anolilab/prettier-config": "^5.0.13",
99
- "@anolilab/semantic-release-preset": "^8.0.2",
113
+ "@anolilab/eslint-config": "^15.0.3",
114
+ "@anolilab/prettier-config": "^5.0.14",
115
+ "@anolilab/semantic-release-preset": "^8.0.3",
100
116
  "@mfederczuk/deeptools": "2.1.0-indev01",
101
- "@rushstack/eslint-plugin-security": "^0.7.1",
117
+ "@rushstack/eslint-plugin-security": "^0.8.0",
102
118
  "@total-typescript/ts-reset": "^0.5.1",
103
119
  "@types/lodash.clonedeep": "^4.5.9",
104
120
  "@types/node": "18.18.8",
105
121
  "@ungap/structured-clone": "^1.2.0",
106
- "@vitest/coverage-v8": "^0.34.6",
122
+ "@vitest/coverage-v8": "^1.2.2",
123
+ "@vitest/ui": "^1.2.2",
107
124
  "clone-deep": "^4.0.1",
108
125
  "cross-env": "^7.0.3",
109
126
  "deep-copy": "^1.4.2",
110
- "eslint": "^8.54.0",
127
+ "eslint": "^8.56.0",
111
128
  "eslint-plugin-deprecation": "^2.0.0",
112
129
  "eslint-plugin-etc": "^2.0.3",
113
- "eslint-plugin-mdx": "^2.2.0",
130
+ "eslint-plugin-mdx": "^3.1.5",
114
131
  "eslint-plugin-tsdoc": "^0.2.17",
115
- "eslint-plugin-vitest": "^0.3.10",
132
+ "eslint-plugin-vitest": "^0.3.21",
116
133
  "eslint-plugin-vitest-globals": "^1.4.0",
117
134
  "fast-copy": "^3.0.1",
118
- "jsdom": "^23.0.1",
119
- "jsondiffpatch": "^0.5.0",
135
+ "jsdom": "^24.0.0",
120
136
  "lodash.clonedeep": "^4.5.0",
121
137
  "nano-copy": "^0.1.0",
122
138
  "nanoclone": "^1.0.2",
123
139
  "plain-object-clone": "^2.0.0",
124
- "prettier": "^3.1.0",
140
+ "prettier": "^3.2.4",
125
141
  "ramda": "^0.29.1",
126
- "rfdc": "^1.3.0",
142
+ "rfdc": "^1.3.1",
127
143
  "rimraf": "^5.0.5",
128
- "semantic-release": "^22.0.8",
129
- "sort-package-json": "^2.6.0",
144
+ "semantic-release": "^23.0.0",
145
+ "sort-package-json": "^2.7.0",
130
146
  "standard": "^17.1.0",
131
147
  "tsup": "^8.0.1",
132
- "type-fest": "^4.8.2",
133
- "typescript": "^5.3.2",
134
- "vitest": "^0.34.6"
148
+ "type-fest": "^4.10.2",
149
+ "typescript": "^5.3.3",
150
+ "vitest": "^1.2.2"
135
151
  },
136
152
  "engines": {
137
153
  "node": ">=18.* <=21.*"
@@ -151,5 +167,9 @@
151
167
  "info_on_disabling_jsonc_sort_keys_rule": false,
152
168
  "info_on_disabling_etc_no_deprecated": false
153
169
  }
154
- }
170
+ },
171
+ "sources": [
172
+ "src/index.ts",
173
+ "src/utils.ts"
174
+ ]
155
175
  }