@visulima/deep-clone 2.0.0 → 2.1.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,10 @@
1
+ ## @visulima/deep-clone [2.1.0](https://github.com/visulima/visulima/compare/@visulima/deep-clone@2.0.0...@visulima/deep-clone@2.1.0) (2024-02-13)
2
+
3
+
4
+ ### Features
5
+
6
+ * exported all deep-clone handler ([bc01ec0](https://github.com/visulima/visulima/commit/bc01ec06130f42644d84730295cac89f04f48c9a))
7
+
1
8
  ## @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
9
 
3
10
 
@@ -0,0 +1,7 @@
1
+ import { a, b as b$1 } from './chunk-LPGIVFCB.js';
2
+
3
+ var m=(e,r)=>{let t=[];r.cache.set(e,t);for(let n=0,{length:o}=e;n<o;++n)t[n]=r.clone(e[n],r);return t},O=(e,r)=>{let t=[];return r.cache.set(e,t),a(e,t,r)};var y=e=>{let r={BigInt64Array,BigUint64Array,Buffer:Buffer.from,Float32Array,Float64Array,Int8Array,Int16Array,Int32Array,Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array};if(e instanceof ArrayBuffer){let n=new ArrayBuffer(e.byteLength),o=new Uint8Array(e);return new Uint8Array(n).set(o),n}let t=r[e.constructor.name]??void 0;return t?new t(e):new e.constructor([...e.buffer],e.byteOffset,e.length)},u=y;var V=e=>e.slice(0,e.size,e.type),g=V;var i=e=>new DataView(u(e.buffer)),h=i;var d=e=>new Date(e.getTime()),P=d;var f=(e,r)=>{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),a(e,t,r)},b=f;var x=(e,r)=>{let t=new Map;return r.cache.set(e,t),e.forEach((n,o)=>{t.set(o,r.clone(n,r));}),t},M=(e,r)=>a(e,x(e,r),r);var p=(e,r)=>{Object.isExtensible(e)||Object.preventExtensions(r),Object.isSealed(e)&&Object.seal(r),Object.isFrozen(e)&&Object.freeze(r);},F=(e,r)=>{let t=b$1(e);r.cache.set(e,t);for(let o in e)Object.hasOwnProperty.call(e,o)&&(t[o]=r.clone(e[o],r));let n=Object.getOwnPropertySymbols(e);for(let o=0,{length:c}=n,s;o<c;++o)s=n[o],Object.prototype.propertyIsEnumerable.call(e,s)&&(t[s]=r.clone(e[s],r));return p(e,t),t},z=(e,r)=>{let t=b$1(e);r.cache.set(e,t);let n=a(e,t,r),o=Object.getPrototypeOf(e);return Object.getPrototypeOf(n)!==o&&Object.setPrototypeOf(n,o),p(e,t),n};var G=e=>{let r=new RegExp(e.source,e.flags);return r.lastIndex=e.lastIndex,r},J=(e,r)=>{let t=new RegExp(e.source,e.flags);return a(e,t,r)};var E=(e,r)=>{let t=new Set;return r.cache.set(e,t),e.forEach(n=>{t.add(r.clone(n,r));}),t},Q=(e,r)=>a(e,E(e,r),r);
4
+
5
+ export { m as a, O as b, u as c, g as d, h as e, P as f, b as g, x as h, M as i, F as j, z as k, G as l, J as m, E as n, Q as o };
6
+ //# sourceMappingURL=out.js.map
7
+ //# sourceMappingURL=chunk-3HH2B6Z5.js.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"],"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","copyObjectIsFunctions","copyObjectLoose","get_clean_clone_default","symbols","symbol","copyObjectStrict","clonedObject","objectPrototype","copyRegExpLoose","regExp","copyRegExpStrict","copySetLoose","set","copySetStrict"],"mappings":"0CAGO,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,EC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AAK3C,CAAK,EAAGA,CAAK","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 =>\n 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\nconst copyObjectIsFunctions = <Value extends UnknownRecord>(object: Value, clone: Value): void => {\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\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 copyObjectIsFunctions(object, clone as Value);\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 copyObjectIsFunctions(object, clone as Value);\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"]}
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ var chunkULIBPEBE_cjs = require('./chunk-ULIBPEBE.cjs');
4
+
5
+ var m=(e,r)=>{let t=[];r.cache.set(e,t);for(let n=0,{length:o}=e;n<o;++n)t[n]=r.clone(e[n],r);return t},O=(e,r)=>{let t=[];return r.cache.set(e,t),chunkULIBPEBE_cjs.a(e,t,r)};var y=e=>{let r={BigInt64Array,BigUint64Array,Buffer:Buffer.from,Float32Array,Float64Array,Int8Array,Int16Array,Int32Array,Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array};if(e instanceof ArrayBuffer){let n=new ArrayBuffer(e.byteLength),o=new Uint8Array(e);return new Uint8Array(n).set(o),n}let t=r[e.constructor.name]??void 0;return t?new t(e):new e.constructor([...e.buffer],e.byteOffset,e.length)},u=y;var V=e=>e.slice(0,e.size,e.type),g=V;var i=e=>new DataView(u(e.buffer)),h=i;var d=e=>new Date(e.getTime()),P=d;var f=(e,r)=>{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),chunkULIBPEBE_cjs.a(e,t,r)},b=f;var x=(e,r)=>{let t=new Map;return r.cache.set(e,t),e.forEach((n,o)=>{t.set(o,r.clone(n,r));}),t},M=(e,r)=>chunkULIBPEBE_cjs.a(e,x(e,r),r);var p=(e,r)=>{Object.isExtensible(e)||Object.preventExtensions(r),Object.isSealed(e)&&Object.seal(r),Object.isFrozen(e)&&Object.freeze(r);},F=(e,r)=>{let t=chunkULIBPEBE_cjs.b(e);r.cache.set(e,t);for(let o in e)Object.hasOwnProperty.call(e,o)&&(t[o]=r.clone(e[o],r));let n=Object.getOwnPropertySymbols(e);for(let o=0,{length:c}=n,s;o<c;++o)s=n[o],Object.prototype.propertyIsEnumerable.call(e,s)&&(t[s]=r.clone(e[s],r));return p(e,t),t},z=(e,r)=>{let t=chunkULIBPEBE_cjs.b(e);r.cache.set(e,t);let n=chunkULIBPEBE_cjs.a(e,t,r),o=Object.getPrototypeOf(e);return Object.getPrototypeOf(n)!==o&&Object.setPrototypeOf(n,o),p(e,t),n};var G=e=>{let r=new RegExp(e.source,e.flags);return r.lastIndex=e.lastIndex,r},J=(e,r)=>{let t=new RegExp(e.source,e.flags);return chunkULIBPEBE_cjs.a(e,t,r)};var E=(e,r)=>{let t=new Set;return r.cache.set(e,t),e.forEach(n=>{t.add(r.clone(n,r));}),t},Q=(e,r)=>chunkULIBPEBE_cjs.a(e,E(e,r),r);
6
+
7
+ exports.a = m;
8
+ exports.b = O;
9
+ exports.c = u;
10
+ exports.d = g;
11
+ exports.e = h;
12
+ exports.f = P;
13
+ exports.g = b;
14
+ exports.h = x;
15
+ exports.i = M;
16
+ exports.j = F;
17
+ exports.k = z;
18
+ exports.l = G;
19
+ exports.m = J;
20
+ exports.n = E;
21
+ exports.o = Q;
22
+ //# sourceMappingURL=out.js.map
23
+ //# sourceMappingURL=chunk-VKPLDMN5.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"],"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","copyObjectIsFunctions","copyObjectLoose","get_clean_clone_default","symbols","symbol","copyObjectStrict","clonedObject","objectPrototype","copyRegExpLoose","regExp","copyRegExpStrict","copySetLoose","set","copySetStrict"],"mappings":"2CAGO,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,EAAM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EAAmB,CAA8Bb,EAAevB,IAAwB,CACjG,IAAMC,EAAQgC,EAAcV,CAAM,EAGlCvB,EAAM,MAAM,IAAIuB,EAAQtB,CAAK,EAE7B,IAAMoC,EAAehC,EAAyBkB,EAAQtB,EAAgBD,CAAK,EAGrEsC,EAAiC,OAAO,eAAef,CAAM,EAEnE,OAAI,OAAO,eAAec,CAAY,IAAMC,GACxC,OAAO,eAAeD,EAAcC,CAAe,EAGvDP,EAAsBR,EAAQtB,CAAc,EAErCoC,CACX,ECtEO,IAAME,EAAyCC,GAAyB,CAE3E,IAAMvC,EAAQ,IAAI,OAAOuC,EAAO,OAAQA,EAAO,KAAK,EAEpD,OAAAvC,EAAM,UAAYuC,EAAO,UAElBvC,CACX,EAEawC,EAAmB,CAAuBD,EAAexC,IAAwB,CAE1F,IAAMC,EAAQ,IAAI,OAAOuC,EAAO,OAAQA,EAAO,KAAK,EAEpD,OAAOnC,EAAkBmC,EAAQvC,EAAOD,CAAK,CACjD,ECdO,IAAM0C,EAAe,CAA6BC,EAAY3C,IAAwB,CACzF,IAAMC,EAAQ,IAAI,IAGlB,OAAAD,EAAM,MAAM,IAAI2C,EAAK1C,CAAK,EAE1B0C,EAAI,QAASf,GAAU,CACnB3B,EAAM,IAAID,EAAM,MAAM4B,EAAO5B,CAAK,CAAC,CACvC,CAAC,EAEMC,CACX,EAKa2C,EAAgB,CAA6BD,EAAY3C,IAAwBK,EAAkBsC,EAAKD,EAAoBC,EAAK3C,CAAK,EAAGA,CAAK","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 =>\n 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\nconst copyObjectIsFunctions = <Value extends UnknownRecord>(object: Value, clone: Value): void => {\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\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 copyObjectIsFunctions(object, clone as Value);\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 copyObjectIsFunctions(object, clone as Value);\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"]}
@@ -0,0 +1,69 @@
1
+ 'use strict';
2
+
3
+ var chunkVKPLDMN5_cjs = require('./chunk-VKPLDMN5.cjs');
4
+ require('./chunk-ULIBPEBE.cjs');
5
+
6
+
7
+
8
+ Object.defineProperty(exports, 'copyArrayBuffer', {
9
+ enumerable: true,
10
+ get: function () { return chunkVKPLDMN5_cjs.c; }
11
+ });
12
+ Object.defineProperty(exports, 'copyArrayLoose', {
13
+ enumerable: true,
14
+ get: function () { return chunkVKPLDMN5_cjs.a; }
15
+ });
16
+ Object.defineProperty(exports, 'copyArrayStrict', {
17
+ enumerable: true,
18
+ get: function () { return chunkVKPLDMN5_cjs.b; }
19
+ });
20
+ Object.defineProperty(exports, 'copyBlob', {
21
+ enumerable: true,
22
+ get: function () { return chunkVKPLDMN5_cjs.d; }
23
+ });
24
+ Object.defineProperty(exports, 'copyDataView', {
25
+ enumerable: true,
26
+ get: function () { return chunkVKPLDMN5_cjs.e; }
27
+ });
28
+ Object.defineProperty(exports, 'copyDate', {
29
+ enumerable: true,
30
+ get: function () { return chunkVKPLDMN5_cjs.f; }
31
+ });
32
+ Object.defineProperty(exports, 'copyError', {
33
+ enumerable: true,
34
+ get: function () { return chunkVKPLDMN5_cjs.g; }
35
+ });
36
+ Object.defineProperty(exports, 'copyMapLoose', {
37
+ enumerable: true,
38
+ get: function () { return chunkVKPLDMN5_cjs.h; }
39
+ });
40
+ Object.defineProperty(exports, 'copyMapStrict', {
41
+ enumerable: true,
42
+ get: function () { return chunkVKPLDMN5_cjs.i; }
43
+ });
44
+ Object.defineProperty(exports, 'copyObjectLoose', {
45
+ enumerable: true,
46
+ get: function () { return chunkVKPLDMN5_cjs.j; }
47
+ });
48
+ Object.defineProperty(exports, 'copyObjectStrict', {
49
+ enumerable: true,
50
+ get: function () { return chunkVKPLDMN5_cjs.k; }
51
+ });
52
+ Object.defineProperty(exports, 'copyRegExpLoose', {
53
+ enumerable: true,
54
+ get: function () { return chunkVKPLDMN5_cjs.l; }
55
+ });
56
+ Object.defineProperty(exports, 'copyRegExpStrict', {
57
+ enumerable: true,
58
+ get: function () { return chunkVKPLDMN5_cjs.m; }
59
+ });
60
+ Object.defineProperty(exports, 'copySetLoose', {
61
+ enumerable: true,
62
+ get: function () { return chunkVKPLDMN5_cjs.n; }
63
+ });
64
+ Object.defineProperty(exports, 'copySetStrict', {
65
+ enumerable: true,
66
+ get: function () { return chunkVKPLDMN5_cjs.o; }
67
+ });
68
+ //# sourceMappingURL=out.js.map
69
+ //# sourceMappingURL=handler.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,34 @@
1
+ import { S as State } from './types-QwwO2Lbg.cjs';
2
+ import { TypedArray, UnknownRecord } from 'type-fest';
3
+
4
+ declare const copyArrayLoose: <Value extends unknown[]>(array: Value, state: State) => Value;
5
+ declare const copyArrayStrict: <Value extends unknown[]>(array: Value, state: State) => Value;
6
+
7
+ declare const copyArrayBuffer: <Value extends ArrayBuffer | ArrayBufferView | Buffer | TypedArray>(arrayBuffer: Value) => Value;
8
+
9
+ declare const copyBlob: <Value extends Blob>(blob: Value) => Value;
10
+
11
+ declare const copyDataView: <Value extends DataView>(dataView: Value) => Value;
12
+
13
+ declare const copyDate: <Value extends Date>(date: Value) => Value;
14
+
15
+ type ExtendedError = Error & {
16
+ code?: any;
17
+ errno?: any;
18
+ syscall?: any;
19
+ };
20
+ declare const copyError: <Value extends EvalError | ExtendedError | RangeError | ReferenceError | SyntaxError | TypeError | URIError>(object: Value, state: State) => Value;
21
+
22
+ declare const copyMapLoose: <Value extends Map<unknown, unknown>>(map: Value, state: State) => Value;
23
+ declare const copyMapStrict: <Value extends Map<unknown, unknown>>(map: Value, state: State) => Value;
24
+
25
+ declare const copyObjectLoose: <Value extends UnknownRecord>(object: Value, state: State) => Value;
26
+ declare const copyObjectStrict: <Value extends UnknownRecord>(object: Value, state: State) => Value;
27
+
28
+ declare const copyRegExpLoose: <Value extends RegExp>(regExp: Value) => Value;
29
+ declare const copyRegExpStrict: <Value extends RegExp>(regExp: Value, state: State) => Value;
30
+
31
+ declare const copySetLoose: <Value extends Set<unknown>>(set: Value, state: State) => Value;
32
+ declare const copySetStrict: <Value extends Set<unknown>>(set: Value, state: State) => Value;
33
+
34
+ export { copyArrayBuffer, copyArrayLoose, copyArrayStrict, copyBlob, copyDataView, copyDate, copyError, copyMapLoose, copyMapStrict, copyObjectLoose, copyObjectStrict, copyRegExpLoose, copyRegExpStrict, copySetLoose, copySetStrict };
@@ -0,0 +1,34 @@
1
+ import { S as State } from './types-QwwO2Lbg.js';
2
+ import { TypedArray, UnknownRecord } from 'type-fest';
3
+
4
+ declare const copyArrayLoose: <Value extends unknown[]>(array: Value, state: State) => Value;
5
+ declare const copyArrayStrict: <Value extends unknown[]>(array: Value, state: State) => Value;
6
+
7
+ declare const copyArrayBuffer: <Value extends ArrayBuffer | ArrayBufferView | Buffer | TypedArray>(arrayBuffer: Value) => Value;
8
+
9
+ declare const copyBlob: <Value extends Blob>(blob: Value) => Value;
10
+
11
+ declare const copyDataView: <Value extends DataView>(dataView: Value) => Value;
12
+
13
+ declare const copyDate: <Value extends Date>(date: Value) => Value;
14
+
15
+ type ExtendedError = Error & {
16
+ code?: any;
17
+ errno?: any;
18
+ syscall?: any;
19
+ };
20
+ declare const copyError: <Value extends EvalError | ExtendedError | RangeError | ReferenceError | SyntaxError | TypeError | URIError>(object: Value, state: State) => Value;
21
+
22
+ declare const copyMapLoose: <Value extends Map<unknown, unknown>>(map: Value, state: State) => Value;
23
+ declare const copyMapStrict: <Value extends Map<unknown, unknown>>(map: Value, state: State) => Value;
24
+
25
+ declare const copyObjectLoose: <Value extends UnknownRecord>(object: Value, state: State) => Value;
26
+ declare const copyObjectStrict: <Value extends UnknownRecord>(object: Value, state: State) => Value;
27
+
28
+ declare const copyRegExpLoose: <Value extends RegExp>(regExp: Value) => Value;
29
+ declare const copyRegExpStrict: <Value extends RegExp>(regExp: Value, state: State) => Value;
30
+
31
+ declare const copySetLoose: <Value extends Set<unknown>>(set: Value, state: State) => Value;
32
+ declare const copySetStrict: <Value extends Set<unknown>>(set: Value, state: State) => Value;
33
+
34
+ export { copyArrayBuffer, copyArrayLoose, copyArrayStrict, copyBlob, copyDataView, copyDate, copyError, copyMapLoose, copyMapStrict, copyObjectLoose, copyObjectStrict, copyRegExpLoose, copyRegExpStrict, copySetLoose, copySetStrict };
@@ -0,0 +1,4 @@
1
+ export { c as copyArrayBuffer, a as copyArrayLoose, b as copyArrayStrict, d as copyBlob, e as copyDataView, f as copyDate, g as copyError, h as copyMapLoose, i as copyMapStrict, j as copyObjectLoose, k as copyObjectStrict, l as copyRegExpLoose, m as copyRegExpStrict, n as copySetLoose, o as copySetStrict } from './chunk-3HH2B6Z5.js';
2
+ import './chunk-LPGIVFCB.js';
3
+ //# sourceMappingURL=out.js.map
4
+ //# sourceMappingURL=handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
package/dist/index.cjs CHANGED
@@ -1,9 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var chunkULIBPEBE_cjs = require('./chunk-ULIBPEBE.cjs');
3
+ var chunkVKPLDMN5_cjs = require('./chunk-VKPLDMN5.cjs');
4
+ require('./chunk-ULIBPEBE.cjs');
4
5
 
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
+ var D=o=>typeof o=="object"&&o!==null||typeof o=="function",E={Array:chunkVKPLDMN5_cjs.a,ArrayBuffer:chunkVKPLDMN5_cjs.c,Blob:chunkVKPLDMN5_cjs.d,DataView:chunkVKPLDMN5_cjs.e,Date:chunkVKPLDMN5_cjs.f,Error:chunkVKPLDMN5_cjs.g,Function:(o,t)=>o,Map:chunkVKPLDMN5_cjs.h,Object:chunkVKPLDMN5_cjs.j,Promise:o=>{throw new TypeError(`${o.constructor.name} objects cannot be cloned`)},RegExp:chunkVKPLDMN5_cjs.l,Set:chunkVKPLDMN5_cjs.n,SharedArrayBuffer:(o,t)=>{throw new TypeError(`${o.constructor.name} objects cannot be cloned`)},WeakMap:o=>{throw new TypeError(`${o.constructor.name} objects cannot be cloned`)},WeakSet:o=>{throw new TypeError(`${o.constructor.name} objects cannot be cloned`)}},L=(o,t)=>{if(!D(o))return o;let e={...E,...t?.strict?{Array:chunkVKPLDMN5_cjs.b,Map:chunkVKPLDMN5_cjs.i,Object:chunkVKPLDMN5_cjs.k,RegExp:chunkVKPLDMN5_cjs.m,Set:chunkVKPLDMN5_cjs.o}:{},...t?.handler},c=new WeakMap,i=(r,n)=>{if(!D(r))return r;if(n.cache.has(r))return n.cache.get(r);if(Array.isArray(r))return e.Array(r,n);if(typeof r=="object"&&r.constructor===Object&&r.nodeType===void 0)return e.Object(r,n);if(r.nodeType!==void 0&&r.cloneNode!==void 0)return r.cloneNode(!0);if(r instanceof Date)return e.Date(r,n);if(r instanceof RegExp)return e.RegExp(r,n);if(r instanceof Map)return e.Map(r,n);if(r instanceof Set)return e.Set(r,n);if(r instanceof Error)return e.Error(r,n);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 e.ArrayBuffer(r,n);if(r instanceof Blob)return e.Blob(r,n);if(r instanceof DataView)return e.DataView(r,n);if(r instanceof SharedArrayBuffer)return e.SharedArrayBuffer(r,n);if(r instanceof Promise)return e.Promise(r,n);if(r instanceof WeakMap)return e.WeakMap(r,n);if(r instanceof WeakSet)return e.WeakSet(r,n);if(r instanceof Function)return e.Function(r,n);if(typeof r=="object")return e.Object(r,n);throw new TypeError(`Type of ${typeof r} cannot be cloned`,r)},M=i(o,{cache:c,clone:i});return c=null,M};
6
7
 
7
- exports.deepClone = ce;
8
+ exports.deepClone = L;
8
9
  //# sourceMappingURL=out.js.map
9
10
  //# sourceMappingURL=index.cjs.map
@@ -1 +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,EAEOK,EAAQN,EC3Cf,IAAMO,EAAgCC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OsB,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"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":["canValueHaveProperties","value","handlers","copyArrayLoose","copy_array_buffer_default","copy_blob_default","copy_data_view_default","copy_date_default","copy_error_default","object","_state","copyMapLoose","copyObjectLoose","copyRegExpLoose","copySetLoose","deepClone","originalData","options","cloner","copyArrayStrict","copyMapStrict","copyObjectStrict","copyRegExpStrict","copySetStrict","cache","clone","state","cloned"],"mappings":"mKAeA,IAAMA,EAA0BC,GAC3B,OAAOA,GAAU,UAAYA,IAAU,MAAS,OAAOA,GAAU,WAKhEC,EAAW,CACb,MAAOC,EACP,YAAaC,EACb,KAAMC,EACN,SAAUC,EACV,KAAMC,EACN,MAAOC,EAEP,SAAU,CAACC,EAAkBC,IAAkBD,EAC/C,IAAKE,EACL,OAAQC,EACR,QAAUH,GAA6B,CACnC,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IACjB,OAAOiB,EAAO,IAAIjB,EAAOyB,CAAK,EAGlC,GAAIzB,aAAiB,IACjB,OAAOiB,EAAO,IAAIjB,EAAOyB,CAAK,EAGlC,GAAIzB,aAAiB,MACjB,OAAOiB,EAAO,MAAMjB,EAAOyB,CAAK,EAGpC,GACIzB,aAAiB,aACjBA,aAAiB,YACjBA,aAAiB,mBACjBA,aAAiB,WACjBA,aAAiB,aACjBA,aAAiB,YACjBA,aAAiB,aACjBA,aAAiB,YACjBA,aAAiB,cACjBA,aAAiB,aAEjB,OAAOiB,EAAO,YAAYjB,EAAOyB,CAAK,EAG1C,GAAIzB,aAAiB,KACjB,OAAOiB,EAAO,KAAKjB,EAAOyB,CAAK,EAGnC,GAAIzB,aAAiB,SACjB,OAAOiB,EAAO,SAASjB,EAAOyB,CAAK,EAGvC,GAAIzB,aAAiB,kBACjB,OAAOiB,EAAO,kBAAkBjB,EAAOyB,CAAK,EAGhD,GAAIzB,aAAiB,QACjB,OAAOiB,EAAO,QAAQjB,EAAOyB,CAAK,EAGtC,GAAIzB,aAAiB,QACjB,OAAOiB,EAAO,QAAQjB,EAAOyB,CAAK,EAGtC,GAAIzB,aAAiB,QACjB,OAAOiB,EAAO,QAAQjB,EAAOyB,CAAK,EAGtC,GAAIzB,aAAiB,SACjB,OAAOiB,EAAO,SAASjB,EAAOyB,CAAK,EAGvC,GAAI,OAAOzB,GAAU,SACjB,OAAOiB,EAAO,OAAOjB,EAAwByB,CAAK,EAGtD,MAAM,IAAI,UAAU,WAAW,OAAOzB,CAAK,oBAAqBA,CAAK,CACzE,EAGM0B,EAASF,EAAMT,EAAc,CAAE,MAAAQ,EAAO,MAAAC,CAAM,CAAC,EAGnD,OAAAD,EAAQ,KAEDG,CACX","sourcesContent":["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 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\n// eslint-disable-next-line import/no-unused-modules\nexport type { Options, State } from \"./types\";\n"]}
package/dist/index.d.cts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { O as Options } from './types-QwwO2Lbg.cjs';
2
+ export { S as State } from './types-QwwO2Lbg.cjs';
2
3
 
3
4
  type DeepReadwrite<T> = T extends object | [] ? {
4
5
  -readonly [P in keyof T]: DeepReadwrite<T[P]>;
5
6
  } : T;
6
7
  declare const deepClone: <T>(originalData: T, options?: Options) => DeepReadwrite<T>;
7
8
 
8
- export { deepClone };
9
+ export { Options, deepClone };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { O as Options } from './types-QwwO2Lbg.js';
2
+ export { S as State } from './types-QwwO2Lbg.js';
2
3
 
3
4
  type DeepReadwrite<T> = T extends object | [] ? {
4
5
  -readonly [P in keyof T]: DeepReadwrite<T[P]>;
5
6
  } : T;
6
7
  declare const deepClone: <T>(originalData: T, options?: Options) => DeepReadwrite<T>;
7
8
 
8
- export { deepClone };
9
+ export { Options, deepClone };
package/dist/index.js CHANGED
@@ -1,7 +1,8 @@
1
- import { a, b as b$1 } from './chunk-LPGIVFCB.js';
1
+ import { b, i, k, m, o, a, c, d, e, f, g, h, j, l, n } from './chunk-3HH2B6Z5.js';
2
+ import './chunk-LPGIVFCB.js';
2
3
 
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
+ var D=o=>typeof o=="object"&&o!==null||typeof o=="function",E={Array:a,ArrayBuffer:c,Blob:d,DataView:e,Date:f,Error:g,Function:(o,t)=>o,Map:h,Object:j,Promise:o=>{throw new TypeError(`${o.constructor.name} objects cannot be cloned`)},RegExp:l,Set:n,SharedArrayBuffer:(o,t)=>{throw new TypeError(`${o.constructor.name} objects cannot be cloned`)},WeakMap:o=>{throw new TypeError(`${o.constructor.name} objects cannot be cloned`)},WeakSet:o=>{throw new TypeError(`${o.constructor.name} objects cannot be cloned`)}},L=(o$1,t)=>{if(!D(o$1))return o$1;let e={...E,...t?.strict?{Array:b,Map:i,Object:k,RegExp:m,Set:o}:{},...t?.handler},c=new WeakMap,i$1=(r,n)=>{if(!D(r))return r;if(n.cache.has(r))return n.cache.get(r);if(Array.isArray(r))return e.Array(r,n);if(typeof r=="object"&&r.constructor===Object&&r.nodeType===void 0)return e.Object(r,n);if(r.nodeType!==void 0&&r.cloneNode!==void 0)return r.cloneNode(!0);if(r instanceof Date)return e.Date(r,n);if(r instanceof RegExp)return e.RegExp(r,n);if(r instanceof Map)return e.Map(r,n);if(r instanceof Set)return e.Set(r,n);if(r instanceof Error)return e.Error(r,n);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 e.ArrayBuffer(r,n);if(r instanceof Blob)return e.Blob(r,n);if(r instanceof DataView)return e.DataView(r,n);if(r instanceof SharedArrayBuffer)return e.SharedArrayBuffer(r,n);if(r instanceof Promise)return e.Promise(r,n);if(r instanceof WeakMap)return e.WeakMap(r,n);if(r instanceof WeakSet)return e.WeakSet(r,n);if(r instanceof Function)return e.Function(r,n);if(typeof r=="object")return e.Object(r,n);throw new TypeError(`Type of ${typeof r} cannot be cloned`,r)},M=i$1(o$1,{cache:c,clone:i$1});return c=null,M};
4
5
 
5
- export { ce as deepClone };
6
+ export { L as deepClone };
6
7
  //# sourceMappingURL=out.js.map
7
8
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +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":"+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,EA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A,aAAiB,WACjBA,aAAiB,aACjBA,aAAiB,YACjBA,aAAiB,aACjBA,aAAiB,YACjBA,aAAiB,cACjBA,aAAiB,aAEjB,OAAOsB,EAAO,YAAYtB,EAAO5B,CAAK,EAG1C,GAAI4B,aAAiB,KACjB,OAAOsB,EAAO,KAAKtB,EAAO5B,CAAK,EAGnC,GAAI4B,aAAiB,SACjB,OAAOsB,EAAO,SAAStB,EAAO5B,CAAK,EAGvC,GAAI4B,aAAiB,kBACjB,OAAOsB,EAAO,kBAAkBtB,EAAO5B,CAAK,EAGhD,GAAI4B,aAAiB,QACjB,OAAOsB,EAAO,QAAQtB,EAAO5B,CAAK,EAGtC,GAAI4B,aAAiB,QACjB,OAAOsB,EAAO,QAAQtB,EAAO5B,CAAK,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"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":["canValueHaveProperties","value","handlers","copyArrayLoose","copy_array_buffer_default","copy_blob_default","copy_data_view_default","copy_date_default","copy_error_default","object","_state","copyMapLoose","copyObjectLoose","copyRegExpLoose","copySetLoose","deepClone","originalData","options","cloner","copyArrayStrict","copyMapStrict","copyObjectStrict","copyRegExpStrict","copySetStrict","cache","clone","state","cloned"],"mappings":"iKAeA,IAAMA,EAA0BC,GAC3B,OAAOA,GAAU,UAAYA,IAAU,MAAS,OAAOA,GAAU,WAKhEC,EAAW,CACb,MAAOC,EACP,YAAaC,EACb,KAAMC,EACN,SAAUC,EACV,KAAMC,EACN,MAAOC,EAEP,SAAU,CAACC,EAAkBC,IAAkBD,EAC/C,IAAKE,EACL,OAAQC,EACR,QAAUH,GAA6B,CACnC,MAAM,IAAI,UAAU,GAAGA,EAAO,YAAY,IAAI,2BAA2B,CAC7E,EACA,OAAQI,EACR,IAAKC,EAEL,kBAAmB,CAACL,EAA2BC,IAAkB,CAC7D,MAAM,IAAI,UAAU,GAAGD,EAAO,YAAY,IAAI,2BAA2B,CAC7E,EACA,QAAUA,GAA8B,CACpC,MAAM,IAAI,UAAU,GAAGA,EAAO,YAAY,IAAI,2BAA2B,CAC7E,EACA,QAAUA,GAAyB,CAC/B,MAAM,IAAI,UAAU,GAAGA,EAAO,YAAY,IAAI,2BAA2B,CAC7E,CACJ,EAkBaM,EAAY,CAAIC,EAAiBC,IAAwC,CAClF,GAAI,CAACjB,EAAuBgB,CAAY,EACpC,OAAOA,EAGX,IAAME,EAAS,CACX,GAAGhB,EACH,GAAIe,GAAS,OAAS,CAAE,MAAOE,EAAiB,IAAKC,EAAe,OAAQC,EAAkB,OAAQC,EAAkB,IAAKC,CAAc,EAAI,CAAC,EAChJ,GAAGN,GAAS,OAChB,EAEIO,EAAkC,IAAI,QAEpCC,EAAQ,CAACxB,EAAYyB,IAAsB,CAC7C,GAAI,CAAC1B,EAAuBC,CAAK,EAC7B,OAAOA,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iB,QACjB,OAAOiB,EAAO,QAAQjB,EAAOyB,CAAK,EAGtC,GAAIzB,aAAiB,SACjB,OAAOiB,EAAO,SAASjB,EAAOyB,CAAK,EAGvC,GAAI,OAAOzB,GAAU,SACjB,OAAOiB,EAAO,OAAOjB,EAAwByB,CAAK,EAGtD,MAAM,IAAI,UAAU,WAAW,OAAOzB,CAAK,oBAAqBA,CAAK,CACzE,EAGM0B,EAASF,EAAMT,EAAc,CAAE,MAAAQ,EAAO,MAAAC,CAAM,CAAC,EAGnD,OAAAD,EAAQ,KAEDG,CACX","sourcesContent":["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 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\n// eslint-disable-next-line import/no-unused-modules\nexport type { Options, State } from \"./types\";\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/deep-clone",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Fastest deep clone implementation.",
5
5
  "keywords": [
6
6
  "anolilab",
@@ -71,6 +71,16 @@
71
71
  "default": "./dist/index.js"
72
72
  }
73
73
  },
74
+ "./handler": {
75
+ "require": {
76
+ "types": "./dist/handler.d.cts",
77
+ "default": "./dist/handler.cjs"
78
+ },
79
+ "import": {
80
+ "types": "./dist/handler.d.ts",
81
+ "default": "./dist/handler.js"
82
+ }
83
+ },
74
84
  "./utils": {
75
85
  "require": {
76
86
  "types": "./dist/utils.d.cts",
@@ -129,7 +139,7 @@
129
139
  "eslint-plugin-etc": "^2.0.3",
130
140
  "eslint-plugin-mdx": "^3.1.5",
131
141
  "eslint-plugin-tsdoc": "^0.2.17",
132
- "eslint-plugin-vitest": "^0.3.21",
142
+ "eslint-plugin-vitest": "^0.3.22",
133
143
  "eslint-plugin-vitest-globals": "^1.4.0",
134
144
  "fast-copy": "^3.0.1",
135
145
  "jsdom": "^24.0.0",
@@ -137,14 +147,14 @@
137
147
  "nano-copy": "^0.1.0",
138
148
  "nanoclone": "^1.0.2",
139
149
  "plain-object-clone": "^2.0.0",
140
- "prettier": "^3.2.4",
150
+ "prettier": "^3.2.5",
141
151
  "ramda": "^0.29.1",
142
152
  "rfdc": "^1.3.1",
143
153
  "rimraf": "^5.0.5",
144
- "semantic-release": "^23.0.0",
154
+ "semantic-release": "^23.0.2",
145
155
  "sort-package-json": "^2.7.0",
146
156
  "standard": "^17.1.0",
147
- "tsup": "^8.0.1",
157
+ "tsup": "^8.0.2",
148
158
  "type-fest": "^4.10.2",
149
159
  "typescript": "^5.3.3",
150
160
  "vitest": "^1.2.2"
@@ -170,6 +180,7 @@
170
180
  },
171
181
  "sources": [
172
182
  "src/index.ts",
183
+ "src/handler.ts",
173
184
  "src/utils.ts"
174
185
  ]
175
186
  }