@visulima/deep-clone 2.1.10 → 3.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.
Files changed (56) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +62 -9
  3. package/dist/handler.js +1 -0
  4. package/dist/index.js +1 -0
  5. package/dist/packem_shared/copyArrayBuffer-_dUBQIVn.js +1 -0
  6. package/dist/packem_shared/copyArrayLoose-BEBF0PeG.js +1 -0
  7. package/dist/packem_shared/copyBlob-S-Z7ux38.js +1 -0
  8. package/dist/packem_shared/copyDataView-EF9L1_xC.js +1 -0
  9. package/dist/packem_shared/copyDate-b-cxY0ZF.js +1 -0
  10. package/dist/packem_shared/copyError-Bdcealjm.js +1 -0
  11. package/dist/packem_shared/copyMapLoose-BodEbKp7.js +1 -0
  12. package/dist/packem_shared/copyObjectLoose-C5x-tHKP.js +1 -0
  13. package/dist/packem_shared/copyOwnProperties-QEhjt2x8.js +1 -0
  14. package/dist/packem_shared/copyRegExpLoose-Cio6jQWx.js +1 -0
  15. package/dist/packem_shared/copySetLoose-L-swSTFR.js +1 -0
  16. package/dist/packem_shared/getCleanClone-D0FN9QGR.js +1 -0
  17. package/dist/utils.js +1 -0
  18. package/package.json +8 -42
  19. package/dist/handler.cjs +0 -32
  20. package/dist/handler.d.cts +0 -33
  21. package/dist/handler.d.mts +0 -33
  22. package/dist/handler.mjs +0 -10
  23. package/dist/index.cjs +0 -121
  24. package/dist/index.d.cts +0 -9
  25. package/dist/index.d.mts +0 -9
  26. package/dist/index.mjs +0 -117
  27. package/dist/packem_shared/copyArrayBuffer-CCGJtx0g.cjs +0 -36
  28. package/dist/packem_shared/copyArrayBuffer-DnYU3Ab_.mjs +0 -34
  29. package/dist/packem_shared/copyArrayLoose-DutO2eEt.mjs +0 -19
  30. package/dist/packem_shared/copyArrayLoose-jv5B0O8W.cjs +0 -24
  31. package/dist/packem_shared/copyBlob-B8SnIatQ.cjs +0 -7
  32. package/dist/packem_shared/copyBlob-ChzBsdC1.mjs +0 -5
  33. package/dist/packem_shared/copyDataView-BJMKTRTm.mjs +0 -7
  34. package/dist/packem_shared/copyDataView-DHMi5seB.cjs +0 -9
  35. package/dist/packem_shared/copyDate-Bgbm3mwe.mjs +0 -5
  36. package/dist/packem_shared/copyDate-CSIVko_l.cjs +0 -7
  37. package/dist/packem_shared/copyError-8k5J3dj4.mjs +0 -22
  38. package/dist/packem_shared/copyError-C1oK1eBT.cjs +0 -24
  39. package/dist/packem_shared/copyMapLoose-6OISt6H6.mjs +0 -15
  40. package/dist/packem_shared/copyMapLoose-DpoR0LmV.cjs +0 -20
  41. package/dist/packem_shared/copyObjectLoose-C0Xe4P0E.mjs +0 -47
  42. package/dist/packem_shared/copyObjectLoose-PHaYRVaE.cjs +0 -52
  43. package/dist/packem_shared/copyOwnProperties-FDDRgAnK.mjs +0 -30
  44. package/dist/packem_shared/copyOwnProperties-NdANNH2P.cjs +0 -32
  45. package/dist/packem_shared/copyRegExpLoose-455kIpwH.cjs +0 -20
  46. package/dist/packem_shared/copyRegExpLoose-CPAMvOoY.mjs +0 -15
  47. package/dist/packem_shared/copySetLoose-BBgAFOdx.cjs +0 -20
  48. package/dist/packem_shared/copySetLoose-BIxHjmWz.mjs +0 -15
  49. package/dist/packem_shared/getCleanClone-BhfRMqgx.cjs +0 -22
  50. package/dist/packem_shared/getCleanClone-Ch3gqIzM.mjs +0 -20
  51. package/dist/packem_shared/types-_Qve7nv8.d.cts +0 -31
  52. package/dist/packem_shared/types-_Qve7nv8.d.mts +0 -31
  53. package/dist/utils.cjs +0 -11
  54. package/dist/utils.d.cts +0 -7
  55. package/dist/utils.d.mts +0 -7
  56. package/dist/utils.mjs +0 -2
package/CHANGELOG.md CHANGED
@@ -1,3 +1,25 @@
1
+ ## @visulima/deep-clone [3.0.0](https://github.com/visulima/visulima/compare/@visulima/deep-clone@2.1.10...@visulima/deep-clone@3.0.0) (2025-10-15)
2
+
3
+ ### ⚠ BREAKING CHANGES
4
+
5
+ * Adjusted the node engine requirement to support versions 20.19 and above
6
+
7
+ ### Bug Fixes
8
+
9
+ * Adjusted the node engine requirement to support versions 20.19 and above ([65d4848](https://github.com/visulima/visulima/commit/65d484883d7c5cb3b9d5984158f0176631f1da83))
10
+ * update @visulima/packem to 2.0.0-alpha.30 across multiple packages for improved compatibility ([27b346e](https://github.com/visulima/visulima/commit/27b346eaa1c0fb0e420d9a9824482028307f4249))
11
+
12
+ ### Miscellaneous Chores
13
+
14
+ * **deep-clone:** update devDependencies ([524421f](https://github.com/visulima/visulima/commit/524421f642d516cb07d0e3308755f6d1609e0ad4))
15
+ * **deps:** update build scripts and remove cross-env dependency ([7510e82](https://github.com/visulima/visulima/commit/7510e826b9235a0013fe61c82a7eb333bc4cbb78))
16
+ * enhance ESLint commands and clean up code for improved readability ([374219a](https://github.com/visulima/visulima/commit/374219a349f909972790210dd4efd340baf0b933))
17
+ * update dependencies and enhance README for deep-clone package ([b774771](https://github.com/visulima/visulima/commit/b7747714092deb505c9a9978bd8b9407c03d72e7))
18
+ * update dependencies and fix linting issues ([0e802fe](https://github.com/visulima/visulima/commit/0e802fe02bb9ed791659cb5f3c77605ae5b42ec8))
19
+ * update package dependencies across multiple packages for improved compatibility and performance ([9567591](https://github.com/visulima/visulima/commit/9567591c415da3002f3a4fe08f8caf7ce01ca5f7))
20
+ * update package.json and pnpm-lock.yaml to include publint@0.3.12 and adjust build/test commands to exclude shared-utils ([1f7b3c0](https://github.com/visulima/visulima/commit/1f7b3c0381d77edfeec80ea1bf57b3469e929414))
21
+ * updated dev dependencies ([2433ed5](https://github.com/visulima/visulima/commit/2433ed5fb662e0303c37edee8ddc21b46c21263f))
22
+
1
23
  ## @visulima/deep-clone [2.1.10](https://github.com/visulima/visulima/compare/@visulima/deep-clone@2.1.9...@visulima/deep-clone@2.1.10) (2025-03-07)
2
24
 
3
25
  ### Bug Fixes
package/README.md CHANGED
@@ -131,7 +131,6 @@ console.log(clean); // => {}
131
131
  ## Notes
132
132
 
133
133
  - List of **supported** values/types:
134
-
135
134
  - `undefined` (original value is returned)
136
135
  - `null` (original value is returned)
137
136
  - `boolean`/`Boolean` (original value is returned)
@@ -166,7 +165,6 @@ console.log(clean); // => {}
166
165
  - `Blob`
167
166
 
168
167
  - List of **unsupported** values/types:
169
-
170
168
  - `DOMElement`: to copy DOM elements, use `element.cloneNode()`.
171
169
  - `Symbol`
172
170
  - `WeakMap`
@@ -186,13 +184,68 @@ console.log(clean); // => {}
186
184
 
187
185
  ## Benchmarks
188
186
 
189
- Note:
190
-
191
- It is true that `jsondiffpatch.clone()` from [jsondiffpatch](https://www.npmjs.com/package/jsondiffpatch) is faster than `@visulima/deep-clonse` in this particular benchmark, but it cannot handle as many situations as `@visulima/deep-clonse` can.
192
-
193
- It is true that [fastest-json-copy](https://www.npmjs.com/package/fastest-json-copy) is faster than `@visulima/deep-clonse` in this particular benchmark. Also, fastest-json-copy has such huge limitations that it is rarely useful. For example, it treats things like `Date` and `Map` instances the same as empty `{}`. It can't handle circular references.
194
-
195
- [plain-object-clone](https://www.npmjs.com/package/plain-object-clone) is also really limited in capability.
187
+ > **Note:** Run `pnpm --filter "deep-clone-bench" run test:bench` to run the benchmarks yourself.
188
+
189
+ ### Shallow Clone Performance
190
+
191
+ Performance comparison for shallow object cloning `{ a: "a", b: "b", c: "c" }`:
192
+
193
+ | Library | Operations/sec | Relative Performance |
194
+ |---------|----------------|---------------------|
195
+ | **plain-object-clone** | 5,650,888 | **1.00x** (fastest) |
196
+ | fast-copy | 5,056,607 | 0.89x |
197
+ | rfdc - default | 4,674,249 | 0.83x |
198
+ | deep-copy | 4,522,595 | 0.80x |
199
+ | rfdc - proto | 4,371,388 | 0.77x |
200
+ | nanoclone | 4,282,256 | 0.76x |
201
+ | **@visulima/deep-clone - loose** | 3,551,940 | 0.63x |
202
+ | clone-deep | 3,740,025 | 0.66x |
203
+ | nano-copy | 3,673,002 | 0.65x |
204
+ | rfdc - circles and proto | 3,423,507 | 0.61x |
205
+ | rfdc - circles | 3,235,513 | 0.57x |
206
+ | ramda.clone | 2,514,785 | 0.44x |
207
+ | lodash.clonedeep | 2,236,361 | 0.40x |
208
+ | structured-clone | 1,503,190 | 0.27x |
209
+ | @mfederczuk/deeptools | 1,305,034 | 0.23x |
210
+ | @ungap/structured-clone | 1,231,364 | 0.22x |
211
+ | fast-copy strict | 1,196,932 | 0.21x |
212
+ | @visulima/deep-clone - strict | 930,414 | 0.16x |
213
+
214
+ ### Deep Clone Performance
215
+
216
+ Performance comparison for deep object cloning (complex nested structure):
217
+
218
+ | Library | Operations/sec | Relative Performance |
219
+ |---------|----------------|---------------------|
220
+ | **rfdc - proto** | 412,630 | **1.00x** (fastest) |
221
+ | rfdc - default | 400,110 | 0.97x |
222
+ | rfdc - circles | 369,861 | 0.90x |
223
+ | rfdc - circles and proto | 367,846 | 0.89x |
224
+ | nanoclone | 314,105 | 0.76x |
225
+ | deep-copy | 301,609 | 0.73x |
226
+ | plain-object-clone | 249,603 | 0.60x |
227
+ | nano-copy | 248,646 | 0.60x |
228
+ | fast-copy | 228,871 | 0.55x |
229
+ | clone-deep | 217,880 | 0.53x |
230
+ | **@visulima/deep-clone - loose** | 194,650 | 0.47x |
231
+ | lodash.clonedeep | 130,934 | 0.32x |
232
+ | structured-clone | 90,495 | 0.22x |
233
+ | @ungap/structured-clone | 88,710 | 0.21x |
234
+ | ramda.clone | 58,385 | 0.14x |
235
+ | fast-copy strict | 34,771 | 0.08x |
236
+ | @visulima/deep-clone - strict | 33,065 | 0.08x |
237
+ | @mfederczuk/deeptools | 15,357 | 0.04x |
238
+
239
+ ### Important Notes
240
+
241
+ - **@visulima/deep-clone** provides the best balance between performance and feature completeness
242
+ - **Loose mode** (default): Fast performance with standard cloning behavior
243
+ - **Strict mode**: Slower but clones all properties including non-enumerable ones and symbols
244
+ - Libraries like `plain-object-clone` and `fastest-json-copy` are faster but have significant limitations:
245
+ - Cannot handle circular references
246
+ - Treat complex objects (Date, Map, etc.) as plain objects
247
+ - Limited type support
248
+ - **rfdc** is very fast but has fewer features than @visulima/deep-clone
196
249
 
197
250
  ## Supported Node.js Versions
198
251
 
@@ -0,0 +1 @@
1
+ import{copyArrayLoose as t,copyArrayStrict as e}from"./packem_shared/copyArrayLoose-BEBF0PeG.js";import{default as c}from"./packem_shared/copyArrayBuffer-_dUBQIVn.js";import{default as y}from"./packem_shared/copyBlob-S-Z7ux38.js";import{default as x}from"./packem_shared/copyDataView-EF9L1_xC.js";import{default as s}from"./packem_shared/copyDate-b-cxY0ZF.js";import{default as i}from"./packem_shared/copyError-Bdcealjm.js";import{copyMapLoose as u,copyMapStrict as d}from"./packem_shared/copyMapLoose-BodEbKp7.js";import{copyObjectLoose as b,copyObjectStrict as A}from"./packem_shared/copyObjectLoose-C5x-tHKP.js";import{copyRegExpLoose as g,copyRegExpStrict as j}from"./packem_shared/copyRegExpLoose-Cio6jQWx.js";import{copySetLoose as D,copySetStrict as M}from"./packem_shared/copySetLoose-L-swSTFR.js";export{c as copyArrayBuffer,t as copyArrayLoose,e as copyArrayStrict,y as copyBlob,x as copyDataView,s as copyDate,i as copyError,u as copyMapLoose,d as copyMapStrict,b as copyObjectLoose,A as copyObjectStrict,g as copyRegExpLoose,j as copyRegExpStrict,D as copySetLoose,M as copySetStrict};
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ var s=Object.defineProperty;var f=(t,n)=>s(t,"name",{value:n,configurable:!0});import{copyArrayStrict as u,copyArrayLoose as m}from"./packem_shared/copyArrayLoose-BEBF0PeG.js";import b from"./packem_shared/copyArrayBuffer-_dUBQIVn.js";import l from"./packem_shared/copyBlob-S-Z7ux38.js";import A from"./packem_shared/copyDataView-EF9L1_xC.js";import d from"./packem_shared/copyDate-b-cxY0ZF.js";import S from"./packem_shared/copyError-Bdcealjm.js";import{copyMapStrict as j,copyMapLoose as h}from"./packem_shared/copyMapLoose-BodEbKp7.js";import{copyObjectStrict as w,copyObjectLoose as E}from"./packem_shared/copyObjectLoose-C5x-tHKP.js";import{copyRegExpStrict as M,copyRegExpLoose as B}from"./packem_shared/copyRegExpLoose-Cio6jQWx.js";import{copySetStrict as k,copySetLoose as W}from"./packem_shared/copySetLoose-L-swSTFR.js";var g=Object.defineProperty,a=f((t,n)=>g(t,"name",{value:n,configurable:!0}),"t");const p=a(t=>typeof t=="object"&&t!==null||typeof t=="function","canValueHaveProperties"),v={Array:m,ArrayBuffer:b,Blob:l,DataView:A,Date:d,Error:S,Function:a((t,n)=>t,"Function"),Map:h,Object:E,Promise:a(t=>{throw new TypeError(`${t.constructor.name} objects cannot be cloned`)},"Promise"),RegExp:B,Set:W,SharedArrayBuffer:a((t,n)=>{throw new TypeError(`${t.constructor.name} objects cannot be cloned`)},"SharedArrayBuffer"),WeakMap:a(t=>{throw new TypeError(`${t.constructor.name} objects cannot be cloned`)},"WeakMap"),WeakSet:a(t=>{throw new TypeError(`${t.constructor.name} objects cannot be cloned`)},"WeakSet")},C=a((t,n)=>{if(!p(t))return t;const r={...v,...n?.strict?{Array:u,Map:j,Object:w,RegExp:M,Set:k}:{},...n?.handler};let c=new WeakMap;const i=a((e,o)=>{if(!p(e))return e;if(o.cache.has(e))return o.cache.get(e);if(Array.isArray(e))return r.Array(e,o);if(typeof e=="object"&&e.constructor===Object&&e.nodeType===void 0)return r.Object(e,o);if(e.nodeType!==void 0&&e.cloneNode!==void 0)return e.cloneNode(!0);if(e instanceof Date)return r.Date(e,o);if(e instanceof RegExp)return r.RegExp(e,o);if(e instanceof Map)return r.Map(e,o);if(e instanceof Set)return r.Set(e,o);if(e instanceof Error)return r.Error(e,o);if(e instanceof ArrayBuffer||e instanceof Uint8Array||e instanceof Uint8ClampedArray||e instanceof Int8Array||e instanceof Uint16Array||e instanceof Int16Array||e instanceof Uint32Array||e instanceof Int32Array||e instanceof Float32Array||e instanceof Float64Array)return r.ArrayBuffer(e,o);if(e instanceof Blob)return r.Blob(e,o);if(e instanceof DataView)return r.DataView(e,o);if(e instanceof SharedArrayBuffer)return r.SharedArrayBuffer(e,o);if(e instanceof Promise)return r.Promise(e,o);if(e instanceof WeakMap)return r.WeakMap(e,o);if(e instanceof WeakSet)return r.WeakSet(e,o);if(typeof e=="function")return r.Function(e,o);if(typeof e=="object")return r.Object(e,o);throw new TypeError(`Type of ${typeof e} cannot be cloned`,e)},"clone"),y=i(t,{cache:c,clone:i});return c=void 0,y},"deepClone");export{C as deepClone};
@@ -0,0 +1 @@
1
+ var f=Object.defineProperty;var a=(r,t)=>f(r,"name",{value:t,configurable:!0});var o=Object.defineProperty,A=a((r,t)=>o(r,"name",{value:t,configurable:!0}),"y");const u=A(r=>{const t={BigInt64Array,BigUint64Array,Buffer:Buffer.from,Float32Array,Float64Array,Int8Array,Int16Array,Int32Array,Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array};if(r instanceof ArrayBuffer){const n=new ArrayBuffer(r.byteLength),y=new Uint8Array(r);return new Uint8Array(n).set(y),n}const e=t[r.constructor.name]??void 0;return e?new e(r):new r.constructor([...r.buffer],r.byteOffset,r.length)},"copyArrayBuffer");export{u as default};
@@ -0,0 +1 @@
1
+ var n=Object.defineProperty;var e=(r,o)=>n(r,"name",{value:o,configurable:!0});import p from"./copyOwnProperties-QEhjt2x8.js";var s=Object.defineProperty,a=e((r,o)=>s(r,"name",{value:o,configurable:!0}),"u");const u=a((r,o)=>{const t=[];o.cache.set(r,t);for(let c=0,{length:y}=r;c<y;++c)t[c]=o.clone(r[c],o);return t},"copyArrayLoose"),f=a((r,o)=>{const t=[];return o.cache.set(r,t),p(r,t,o)},"copyArrayStrict");export{u as copyArrayLoose,f as copyArrayStrict};
@@ -0,0 +1 @@
1
+ var r=Object.defineProperty;var t=(e,a)=>r(e,"name",{value:a,configurable:!0});var o=Object.defineProperty,c=t((e,a)=>o(e,"name",{value:a,configurable:!0}),"a");const s=c(e=>e.slice(0,e.size,e.type),"copyBlob");export{s as default};
@@ -0,0 +1 @@
1
+ var t=Object.defineProperty;var r=(e,a)=>t(e,"name",{value:a,configurable:!0});import o from"./copyArrayBuffer-_dUBQIVn.js";var f=Object.defineProperty,i=r((e,a)=>f(e,"name",{value:a,configurable:!0}),"a");const c=i(e=>new DataView(o(e.buffer)),"copyDataView");export{c as default};
@@ -0,0 +1 @@
1
+ var r=Object.defineProperty;var t=(e,a)=>r(e,"name",{value:a,configurable:!0});var n=Object.defineProperty,o=t((e,a)=>n(e,"name",{value:a,configurable:!0}),"a");const c=o(e=>new Date(e),"copyDate");export{c as default};
@@ -0,0 +1 @@
1
+ var s=Object.defineProperty;var a=(e,o)=>s(e,"name",{value:o,configurable:!0});import t from"./copyOwnProperties-QEhjt2x8.js";var r=Object.defineProperty,n=a((e,o)=>r(e,"name",{value:o,configurable:!0}),"o");const u=n((e,o)=>{const c=new e.constructor(e.message);return e.stack&&(c.stack=e.stack),e.code&&(c.code=e.code),e.errno&&(c.errno=e.errno),e.syscall&&(c.syscall=e.syscall),t(e,c,o)},"copyError");export{u as default};
@@ -0,0 +1 @@
1
+ var i=Object.defineProperty;var e=(t,o)=>i(t,"name",{value:o,configurable:!0});import n from"./copyOwnProperties-QEhjt2x8.js";var s=Object.defineProperty,r=e((t,o)=>s(t,"name",{value:o,configurable:!0}),"t");const u=r((t,o)=>{const c=new Map;return o.cache.set(t,c),t.forEach((a,p)=>{c.set(p,o.clone(a,o))}),c},"copyMapLoose"),f=r((t,o)=>n(t,u(t,o),o),"copyMapStrict");export{u as copyMapLoose,f as copyMapStrict};
@@ -0,0 +1 @@
1
+ var l=Object.defineProperty;var O=(t,e)=>l(t,"name",{value:e,configurable:!0});import y from"./copyOwnProperties-QEhjt2x8.js";import b from"./getCleanClone-D0FN9QGR.js";var i=Object.defineProperty,s=O((t,e)=>i(t,"name",{value:e,configurable:!0}),"l");const p=s((t,e)=>{Object.isExtensible(t)||Object.preventExtensions(e),Object.isSealed(t)&&Object.seal(e),Object.isFrozen(t)&&Object.freeze(e)},"copyObjectIsFunctions"),u=s((t,e)=>{const c=b(t);e.cache.set(t,c);for(const o in t)Object.hasOwnProperty.call(t,o)&&(c[o]=e.clone(t[o],e));const r=Object.getOwnPropertySymbols(t);for(let o=0,n,{length:j}=r;o<j;++o)n=r[o],Object.prototype.propertyIsEnumerable.call(t,n)&&(c[n]=e.clone(t[n],e));return p(t,c),c},"copyObjectLoose"),P=s((t,e)=>{const c=b(t);e.cache.set(t,c);const r=y(t,c,e),o=Object.getPrototypeOf(t);return Object.getPrototypeOf(r)!==o&&Object.setPrototypeOf(r,o),p(t,c),r},"copyObjectStrict");export{u as copyObjectLoose,P as copyObjectStrict};
@@ -0,0 +1 @@
1
+ var i=Object.defineProperty;var n=(e,t)=>i(e,"name",{value:t,configurable:!0});var s=Object.defineProperty,a=n((e,t)=>s(e,"name",{value:t,configurable:!0}),"s");const p=a(e=>[...Object.getOwnPropertyNames(e),...Object.getOwnPropertySymbols(e)],"getStrictProperties"),O=a((e,t,o)=>{const l=p(e);for(const r of l){if(r==="callee"||r==="caller")continue;const c=Object.getOwnPropertyDescriptor(e,r);if(!c){t[r]=o.clone(e[r],o);continue}!c.get&&!c.set&&(c.value=o.clone(c.value,o));try{Object.defineProperty(t,r,c)}catch{t[r]=c.value}}return t},"copyOwnProperties");export{O as default};
@@ -0,0 +1 @@
1
+ var p=Object.defineProperty;var r=(e,o)=>p(e,"name",{value:o,configurable:!0});import n from"./copyOwnProperties-QEhjt2x8.js";var s=Object.defineProperty,t=r((e,o)=>s(e,"name",{value:o,configurable:!0}),"o");const x=t(e=>{const o=new RegExp(e.source,e.flags);return o.lastIndex=e.lastIndex,o},"copyRegExpLoose"),u=t((e,o)=>{const c=new RegExp(e.source,e.flags);return n(e,c,o)},"copyRegExpStrict");export{x as copyRegExpLoose,u as copyRegExpStrict};
@@ -0,0 +1 @@
1
+ var a=Object.defineProperty;var o=(e,t)=>a(e,"name",{value:t,configurable:!0});import p from"./copyOwnProperties-QEhjt2x8.js";var S=Object.defineProperty,r=o((e,t)=>S(e,"name",{value:t,configurable:!0}),"n");const i=r((e,t)=>{const c=new Set;return t.cache.set(e,c),e.forEach(n=>{c.add(t.clone(n,t))}),c},"copySetLoose"),f=r((e,t)=>p(e,i(e,t),t),"copySetStrict");export{i as copySetLoose,f as copySetStrict};
@@ -0,0 +1 @@
1
+ var c=Object.defineProperty;var r=(e,t)=>c(e,"name",{value:t,configurable:!0});var n=Object.defineProperty,o=r((e,t)=>n(e,"name",{value:t,configurable:!0}),"r");const u=o(e=>{if(!e)return Object.create(null);const 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)},"getCleanClone");export{u as default};
package/dist/utils.js ADDED
@@ -0,0 +1 @@
1
+ import{default as r}from"./packem_shared/copyOwnProperties-QEhjt2x8.js";import{default as a}from"./packem_shared/getCleanClone-D0FN9QGR.js";export{r as copyOwnProperties,a as getCleanClone};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/deep-clone",
3
- "version": "2.1.10",
3
+ "version": "3.0.0",
4
4
  "description": "Fastest deep clone implementation.",
5
5
  "keywords": [
6
6
  "anolilab",
@@ -62,53 +62,19 @@
62
62
  "type": "module",
63
63
  "exports": {
64
64
  ".": {
65
- "require": {
66
- "types": "./dist/index.d.cts",
67
- "default": "./dist/index.cjs"
68
- },
69
- "import": {
70
- "types": "./dist/index.d.mts",
71
- "default": "./dist/index.mjs"
72
- }
65
+ "types": "./dist/index.d.ts",
66
+ "default": "./dist/index.js"
73
67
  },
74
68
  "./handler": {
75
- "require": {
76
- "types": "./dist/handler.d.cts",
77
- "default": "./dist/handler.cjs"
78
- },
79
- "import": {
80
- "types": "./dist/handler.d.mts",
81
- "default": "./dist/handler.mjs"
82
- }
69
+ "types": "./dist/handler.d.ts",
70
+ "default": "./dist/handler.js"
83
71
  },
84
72
  "./utils": {
85
- "require": {
86
- "types": "./dist/utils.d.cts",
87
- "default": "./dist/utils.cjs"
88
- },
89
- "import": {
90
- "types": "./dist/utils.d.mts",
91
- "default": "./dist/utils.mjs"
92
- }
73
+ "types": "./dist/utils.d.ts",
74
+ "default": "./dist/utils.js"
93
75
  },
94
76
  "./package.json": "./package.json"
95
77
  },
96
- "main": "dist/index.cjs",
97
- "module": "dist/index.mjs",
98
- "types": "dist/index.d.ts",
99
- "typesVersions": {
100
- ">=5.0": {
101
- ".": [
102
- "./dist/index.d.ts"
103
- ],
104
- "handler": [
105
- "./dist/handler.d.ts"
106
- ],
107
- "utils": [
108
- "./dist/utils.d.ts"
109
- ]
110
- }
111
- },
112
78
  "files": [
113
79
  "dist/**",
114
80
  "README.md",
@@ -116,7 +82,7 @@
116
82
  "LICENSE.md"
117
83
  ],
118
84
  "engines": {
119
- "node": ">=18.0.0 <=23.x"
85
+ "node": ">=20.19 <=24.x"
120
86
  },
121
87
  "os": [
122
88
  "darwin",
package/dist/handler.cjs DELETED
@@ -1,32 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
-
5
- const copyArrayLoose = require('./packem_shared/copyArrayLoose-jv5B0O8W.cjs');
6
- const copyArrayBuffer = require('./packem_shared/copyArrayBuffer-CCGJtx0g.cjs');
7
- const copyBlob = require('./packem_shared/copyBlob-B8SnIatQ.cjs');
8
- const copyDataView = require('./packem_shared/copyDataView-DHMi5seB.cjs');
9
- const copyDate = require('./packem_shared/copyDate-CSIVko_l.cjs');
10
- const copyError = require('./packem_shared/copyError-C1oK1eBT.cjs');
11
- const copyMapLoose = require('./packem_shared/copyMapLoose-DpoR0LmV.cjs');
12
- const copyObjectLoose = require('./packem_shared/copyObjectLoose-PHaYRVaE.cjs');
13
- const copyRegExpLoose = require('./packem_shared/copyRegExpLoose-455kIpwH.cjs');
14
- const copySetLoose = require('./packem_shared/copySetLoose-BBgAFOdx.cjs');
15
-
16
-
17
-
18
- exports.copyArrayLoose = copyArrayLoose.copyArrayLoose;
19
- exports.copyArrayStrict = copyArrayLoose.copyArrayStrict;
20
- exports.copyArrayBuffer = copyArrayBuffer;
21
- exports.copyBlob = copyBlob;
22
- exports.copyDataView = copyDataView;
23
- exports.copyDate = copyDate;
24
- exports.copyError = copyError;
25
- exports.copyMapLoose = copyMapLoose.copyMapLoose;
26
- exports.copyMapStrict = copyMapLoose.copyMapStrict;
27
- exports.copyObjectLoose = copyObjectLoose.copyObjectLoose;
28
- exports.copyObjectStrict = copyObjectLoose.copyObjectStrict;
29
- exports.copyRegExpLoose = copyRegExpLoose.copyRegExpLoose;
30
- exports.copyRegExpStrict = copyRegExpLoose.copyRegExpStrict;
31
- exports.copySetLoose = copySetLoose.copySetLoose;
32
- exports.copySetStrict = copySetLoose.copySetStrict;
@@ -1,33 +0,0 @@
1
- import { S as State, T as TypedArray } from './packem_shared/types-_Qve7nv8.cjs';
2
-
3
- declare const copyArrayLoose: <Value extends unknown[]>(array: Value, state: State) => Value;
4
- declare const copyArrayStrict: <Value extends unknown[]>(array: Value, state: State) => Value;
5
-
6
- declare const copyArrayBuffer: <Value extends ArrayBuffer | ArrayBufferView | Buffer | TypedArray>(arrayBuffer: Value) => Value;
7
-
8
- declare const copyBlob: <Value extends Blob>(blob: Value) => Value;
9
-
10
- declare const copyDataView: <Value extends DataView>(dataView: Value) => Value;
11
-
12
- declare const copyDate: <Value extends Date>(date: Value) => Value;
13
-
14
- type ExtendedError = Error & {
15
- code?: any;
16
- errno?: any;
17
- syscall?: any;
18
- };
19
- declare const copyError: <Value extends EvalError | ExtendedError | RangeError | ReferenceError | SyntaxError | TypeError | URIError>(object: Value, state: State) => Value;
20
-
21
- declare const copyMapLoose: <Value extends Map<unknown, unknown>>(map: Value, state: State) => Value;
22
- declare const copyMapStrict: <Value extends Map<unknown, unknown>>(map: Value, state: State) => Value;
23
-
24
- declare const copyObjectLoose: <Value extends Record<PropertyKey, unknown>>(object: Value, state: State) => Value;
25
- declare const copyObjectStrict: <Value extends Record<PropertyKey, unknown>>(object: Value, state: State) => Value;
26
-
27
- declare const copyRegExpLoose: <Value extends RegExp>(regExp: Value) => Value;
28
- declare const copyRegExpStrict: <Value extends RegExp>(regExp: Value, state: State) => Value;
29
-
30
- declare const copySetLoose: <Value extends Set<unknown>>(set: Value, state: State) => Value;
31
- declare const copySetStrict: <Value extends Set<unknown>>(set: Value, state: State) => Value;
32
-
33
- export { copyArrayBuffer, copyArrayLoose, copyArrayStrict, copyBlob, copyDataView, copyDate, copyError, copyMapLoose, copyMapStrict, copyObjectLoose, copyObjectStrict, copyRegExpLoose, copyRegExpStrict, copySetLoose, copySetStrict };
@@ -1,33 +0,0 @@
1
- import { S as State, T as TypedArray } from './packem_shared/types-_Qve7nv8.mjs';
2
-
3
- declare const copyArrayLoose: <Value extends unknown[]>(array: Value, state: State) => Value;
4
- declare const copyArrayStrict: <Value extends unknown[]>(array: Value, state: State) => Value;
5
-
6
- declare const copyArrayBuffer: <Value extends ArrayBuffer | ArrayBufferView | Buffer | TypedArray>(arrayBuffer: Value) => Value;
7
-
8
- declare const copyBlob: <Value extends Blob>(blob: Value) => Value;
9
-
10
- declare const copyDataView: <Value extends DataView>(dataView: Value) => Value;
11
-
12
- declare const copyDate: <Value extends Date>(date: Value) => Value;
13
-
14
- type ExtendedError = Error & {
15
- code?: any;
16
- errno?: any;
17
- syscall?: any;
18
- };
19
- declare const copyError: <Value extends EvalError | ExtendedError | RangeError | ReferenceError | SyntaxError | TypeError | URIError>(object: Value, state: State) => Value;
20
-
21
- declare const copyMapLoose: <Value extends Map<unknown, unknown>>(map: Value, state: State) => Value;
22
- declare const copyMapStrict: <Value extends Map<unknown, unknown>>(map: Value, state: State) => Value;
23
-
24
- declare const copyObjectLoose: <Value extends Record<PropertyKey, unknown>>(object: Value, state: State) => Value;
25
- declare const copyObjectStrict: <Value extends Record<PropertyKey, unknown>>(object: Value, state: State) => Value;
26
-
27
- declare const copyRegExpLoose: <Value extends RegExp>(regExp: Value) => Value;
28
- declare const copyRegExpStrict: <Value extends RegExp>(regExp: Value, state: State) => Value;
29
-
30
- declare const copySetLoose: <Value extends Set<unknown>>(set: Value, state: State) => Value;
31
- declare const copySetStrict: <Value extends Set<unknown>>(set: Value, state: State) => Value;
32
-
33
- export { copyArrayBuffer, copyArrayLoose, copyArrayStrict, copyBlob, copyDataView, copyDate, copyError, copyMapLoose, copyMapStrict, copyObjectLoose, copyObjectStrict, copyRegExpLoose, copyRegExpStrict, copySetLoose, copySetStrict };
package/dist/handler.mjs DELETED
@@ -1,10 +0,0 @@
1
- export { copyArrayLoose, copyArrayStrict } from './packem_shared/copyArrayLoose-DutO2eEt.mjs';
2
- export { default as copyArrayBuffer } from './packem_shared/copyArrayBuffer-DnYU3Ab_.mjs';
3
- export { default as copyBlob } from './packem_shared/copyBlob-ChzBsdC1.mjs';
4
- export { default as copyDataView } from './packem_shared/copyDataView-BJMKTRTm.mjs';
5
- export { default as copyDate } from './packem_shared/copyDate-Bgbm3mwe.mjs';
6
- export { default as copyError } from './packem_shared/copyError-8k5J3dj4.mjs';
7
- export { copyMapLoose, copyMapStrict } from './packem_shared/copyMapLoose-6OISt6H6.mjs';
8
- export { copyObjectLoose, copyObjectStrict } from './packem_shared/copyObjectLoose-C0Xe4P0E.mjs';
9
- export { copyRegExpLoose, copyRegExpStrict } from './packem_shared/copyRegExpLoose-CPAMvOoY.mjs';
10
- export { copySetLoose, copySetStrict } from './packem_shared/copySetLoose-BIxHjmWz.mjs';
package/dist/index.cjs DELETED
@@ -1,121 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
-
5
- const copyArrayLoose = require('./packem_shared/copyArrayLoose-jv5B0O8W.cjs');
6
- const copyArrayBuffer = require('./packem_shared/copyArrayBuffer-CCGJtx0g.cjs');
7
- const copyBlob = require('./packem_shared/copyBlob-B8SnIatQ.cjs');
8
- const copyDataView = require('./packem_shared/copyDataView-DHMi5seB.cjs');
9
- const copyDate = require('./packem_shared/copyDate-CSIVko_l.cjs');
10
- const copyError = require('./packem_shared/copyError-C1oK1eBT.cjs');
11
- const copyMapLoose = require('./packem_shared/copyMapLoose-DpoR0LmV.cjs');
12
- const copyObjectLoose = require('./packem_shared/copyObjectLoose-PHaYRVaE.cjs');
13
- const copyRegExpLoose = require('./packem_shared/copyRegExpLoose-455kIpwH.cjs');
14
- const copySetLoose = require('./packem_shared/copySetLoose-BBgAFOdx.cjs');
15
-
16
- var __defProp = Object.defineProperty;
17
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
18
- const canValueHaveProperties = /* @__PURE__ */ __name((value) => typeof value === "object" && value !== null || typeof value === "function", "canValueHaveProperties");
19
- const handlers = {
20
- Array: copyArrayLoose.copyArrayLoose,
21
- ArrayBuffer: copyArrayBuffer,
22
- Blob: copyBlob,
23
- DataView: copyDataView,
24
- Date: copyDate,
25
- Error: copyError,
26
- // eslint-disable-next-line @typescript-eslint/ban-types,@typescript-eslint/no-unused-vars
27
- Function: /* @__PURE__ */ __name((object, _state) => object, "Function"),
28
- Map: copyMapLoose.copyMapLoose,
29
- Object: copyObjectLoose.copyObjectLoose,
30
- Promise: /* @__PURE__ */ __name((object) => {
31
- throw new TypeError(`${object.constructor.name} objects cannot be cloned`);
32
- }, "Promise"),
33
- RegExp: copyRegExpLoose.copyRegExpLoose,
34
- Set: copySetLoose.copySetLoose,
35
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
36
- SharedArrayBuffer: /* @__PURE__ */ __name((object, _state) => {
37
- throw new TypeError(`${object.constructor.name} objects cannot be cloned`);
38
- }, "SharedArrayBuffer"),
39
- WeakMap: /* @__PURE__ */ __name((object) => {
40
- throw new TypeError(`${object.constructor.name} objects cannot be cloned`);
41
- }, "WeakMap"),
42
- WeakSet: /* @__PURE__ */ __name((object) => {
43
- throw new TypeError(`${object.constructor.name} objects cannot be cloned`);
44
- }, "WeakSet")
45
- };
46
- const deepClone = /* @__PURE__ */ __name((originalData, options) => {
47
- if (!canValueHaveProperties(originalData)) {
48
- return originalData;
49
- }
50
- const cloner = {
51
- ...handlers,
52
- ...options?.strict ? { Array: copyArrayLoose.copyArrayStrict, Map: copyMapLoose.copyMapStrict, Object: copyObjectLoose.copyObjectStrict, RegExp: copyRegExpLoose.copyRegExpStrict, Set: copySetLoose.copySetStrict } : {},
53
- ...options?.handler
54
- };
55
- let cache = /* @__PURE__ */ new WeakMap();
56
- const clone = /* @__PURE__ */ __name((value, state) => {
57
- if (!canValueHaveProperties(value)) {
58
- return value;
59
- }
60
- if (state.cache.has(value)) {
61
- return state.cache.get(value);
62
- }
63
- if (Array.isArray(value)) {
64
- return cloner.Array(value, state);
65
- }
66
- if (typeof value === "object" && value.constructor === Object && value.nodeType === void 0) {
67
- return cloner.Object(value, state);
68
- }
69
- if (value.nodeType !== void 0 && value.cloneNode !== void 0) {
70
- return value.cloneNode(true);
71
- }
72
- if (value instanceof Date) {
73
- return cloner.Date(value, state);
74
- }
75
- if (value instanceof RegExp) {
76
- return cloner.RegExp(value, state);
77
- }
78
- if (value instanceof Map) {
79
- return cloner.Map(value, state);
80
- }
81
- if (value instanceof Set) {
82
- return cloner.Set(value, state);
83
- }
84
- if (value instanceof Error) {
85
- return cloner.Error(value, state);
86
- }
87
- if (value instanceof ArrayBuffer || value instanceof Uint8Array || value instanceof Uint8ClampedArray || value instanceof Int8Array || value instanceof Uint16Array || value instanceof Int16Array || value instanceof Uint32Array || value instanceof Int32Array || value instanceof Float32Array || value instanceof Float64Array) {
88
- return cloner.ArrayBuffer(value, state);
89
- }
90
- if (value instanceof Blob) {
91
- return cloner.Blob(value, state);
92
- }
93
- if (value instanceof DataView) {
94
- return cloner.DataView(value, state);
95
- }
96
- if (value instanceof SharedArrayBuffer) {
97
- return cloner.SharedArrayBuffer(value, state);
98
- }
99
- if (value instanceof Promise) {
100
- return cloner.Promise(value, state);
101
- }
102
- if (value instanceof WeakMap) {
103
- return cloner.WeakMap(value, state);
104
- }
105
- if (value instanceof WeakSet) {
106
- return cloner.WeakSet(value, state);
107
- }
108
- if (value instanceof Function) {
109
- return cloner.Function(value, state);
110
- }
111
- if (typeof value === "object") {
112
- return cloner.Object(value, state);
113
- }
114
- throw new TypeError(`Type of ${typeof value} cannot be cloned`, value);
115
- }, "clone");
116
- const cloned = clone(originalData, { cache, clone });
117
- cache = null;
118
- return cloned;
119
- }, "deepClone");
120
-
121
- exports.deepClone = deepClone;
package/dist/index.d.cts DELETED
@@ -1,9 +0,0 @@
1
- import { O as Options } from './packem_shared/types-_Qve7nv8.cjs';
2
- export { S as State } from './packem_shared/types-_Qve7nv8.cjs';
3
-
4
- type DeepReadwrite<T> = T extends object | [] ? {
5
- -readonly [P in keyof T]: DeepReadwrite<T[P]>;
6
- } : T;
7
- declare const deepClone: <T>(originalData: T, options?: Options) => DeepReadwrite<T>;
8
-
9
- export { Options, deepClone };
package/dist/index.d.mts DELETED
@@ -1,9 +0,0 @@
1
- import { O as Options } from './packem_shared/types-_Qve7nv8.mjs';
2
- export { S as State } from './packem_shared/types-_Qve7nv8.mjs';
3
-
4
- type DeepReadwrite<T> = T extends object | [] ? {
5
- -readonly [P in keyof T]: DeepReadwrite<T[P]>;
6
- } : T;
7
- declare const deepClone: <T>(originalData: T, options?: Options) => DeepReadwrite<T>;
8
-
9
- export { Options, deepClone };
package/dist/index.mjs DELETED
@@ -1,117 +0,0 @@
1
- import { copyArrayStrict, copyArrayLoose } from './packem_shared/copyArrayLoose-DutO2eEt.mjs';
2
- import copyArrayBuffer from './packem_shared/copyArrayBuffer-DnYU3Ab_.mjs';
3
- import copyBlob from './packem_shared/copyBlob-ChzBsdC1.mjs';
4
- import copyDataView from './packem_shared/copyDataView-BJMKTRTm.mjs';
5
- import copyDate from './packem_shared/copyDate-Bgbm3mwe.mjs';
6
- import copyError from './packem_shared/copyError-8k5J3dj4.mjs';
7
- import { copyMapStrict, copyMapLoose } from './packem_shared/copyMapLoose-6OISt6H6.mjs';
8
- import { copyObjectStrict, copyObjectLoose } from './packem_shared/copyObjectLoose-C0Xe4P0E.mjs';
9
- import { copyRegExpStrict, copyRegExpLoose } from './packem_shared/copyRegExpLoose-CPAMvOoY.mjs';
10
- import { copySetStrict, copySetLoose } from './packem_shared/copySetLoose-BIxHjmWz.mjs';
11
-
12
- var __defProp = Object.defineProperty;
13
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
14
- const canValueHaveProperties = /* @__PURE__ */ __name((value) => typeof value === "object" && value !== null || typeof value === "function", "canValueHaveProperties");
15
- const handlers = {
16
- Array: copyArrayLoose,
17
- ArrayBuffer: copyArrayBuffer,
18
- Blob: copyBlob,
19
- DataView: copyDataView,
20
- Date: copyDate,
21
- Error: copyError,
22
- // eslint-disable-next-line @typescript-eslint/ban-types,@typescript-eslint/no-unused-vars
23
- Function: /* @__PURE__ */ __name((object, _state) => object, "Function"),
24
- Map: copyMapLoose,
25
- Object: copyObjectLoose,
26
- Promise: /* @__PURE__ */ __name((object) => {
27
- throw new TypeError(`${object.constructor.name} objects cannot be cloned`);
28
- }, "Promise"),
29
- RegExp: copyRegExpLoose,
30
- Set: copySetLoose,
31
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
32
- SharedArrayBuffer: /* @__PURE__ */ __name((object, _state) => {
33
- throw new TypeError(`${object.constructor.name} objects cannot be cloned`);
34
- }, "SharedArrayBuffer"),
35
- WeakMap: /* @__PURE__ */ __name((object) => {
36
- throw new TypeError(`${object.constructor.name} objects cannot be cloned`);
37
- }, "WeakMap"),
38
- WeakSet: /* @__PURE__ */ __name((object) => {
39
- throw new TypeError(`${object.constructor.name} objects cannot be cloned`);
40
- }, "WeakSet")
41
- };
42
- const deepClone = /* @__PURE__ */ __name((originalData, options) => {
43
- if (!canValueHaveProperties(originalData)) {
44
- return originalData;
45
- }
46
- const cloner = {
47
- ...handlers,
48
- ...options?.strict ? { Array: copyArrayStrict, Map: copyMapStrict, Object: copyObjectStrict, RegExp: copyRegExpStrict, Set: copySetStrict } : {},
49
- ...options?.handler
50
- };
51
- let cache = /* @__PURE__ */ new WeakMap();
52
- const clone = /* @__PURE__ */ __name((value, state) => {
53
- if (!canValueHaveProperties(value)) {
54
- return value;
55
- }
56
- if (state.cache.has(value)) {
57
- return state.cache.get(value);
58
- }
59
- if (Array.isArray(value)) {
60
- return cloner.Array(value, state);
61
- }
62
- if (typeof value === "object" && value.constructor === Object && value.nodeType === void 0) {
63
- return cloner.Object(value, state);
64
- }
65
- if (value.nodeType !== void 0 && value.cloneNode !== void 0) {
66
- return value.cloneNode(true);
67
- }
68
- if (value instanceof Date) {
69
- return cloner.Date(value, state);
70
- }
71
- if (value instanceof RegExp) {
72
- return cloner.RegExp(value, state);
73
- }
74
- if (value instanceof Map) {
75
- return cloner.Map(value, state);
76
- }
77
- if (value instanceof Set) {
78
- return cloner.Set(value, state);
79
- }
80
- if (value instanceof Error) {
81
- return cloner.Error(value, state);
82
- }
83
- if (value instanceof ArrayBuffer || value instanceof Uint8Array || value instanceof Uint8ClampedArray || value instanceof Int8Array || value instanceof Uint16Array || value instanceof Int16Array || value instanceof Uint32Array || value instanceof Int32Array || value instanceof Float32Array || value instanceof Float64Array) {
84
- return cloner.ArrayBuffer(value, state);
85
- }
86
- if (value instanceof Blob) {
87
- return cloner.Blob(value, state);
88
- }
89
- if (value instanceof DataView) {
90
- return cloner.DataView(value, state);
91
- }
92
- if (value instanceof SharedArrayBuffer) {
93
- return cloner.SharedArrayBuffer(value, state);
94
- }
95
- if (value instanceof Promise) {
96
- return cloner.Promise(value, state);
97
- }
98
- if (value instanceof WeakMap) {
99
- return cloner.WeakMap(value, state);
100
- }
101
- if (value instanceof WeakSet) {
102
- return cloner.WeakSet(value, state);
103
- }
104
- if (value instanceof Function) {
105
- return cloner.Function(value, state);
106
- }
107
- if (typeof value === "object") {
108
- return cloner.Object(value, state);
109
- }
110
- throw new TypeError(`Type of ${typeof value} cannot be cloned`, value);
111
- }, "clone");
112
- const cloned = clone(originalData, { cache, clone });
113
- cache = null;
114
- return cloned;
115
- }, "deepClone");
116
-
117
- export { deepClone };