Simple deno module to do simple and fast deep cloning.
/** Import from GH via `denopkg` */
import { deepClone } from "https://cdn.jsdelivr.net/gh/motss/[email protected]/deep_clone/mod.ts";
(async () => {
const simpleObject = {
a: {
b: { c: [1, 2, 3] },
e: [{ f: null }]
},
d: "deep"
};
const complexObject = {
a: () => {},
b: /test/gi,
c: [1, 2],
d: new Date(),
e: { f: 111 }
};
await deepClone(simpleObject);
await deepClone(complexObject, { absolute: true });
})();
target
<T
> Target to be cloned.options
<?Object> Optionally setabsolute: true
for deep cloning complex objects that are not possible withJSON.parse
+JSON.stringify
.absolute
<boolean> If true, deep clone complex objects.
- returns: <Promise<
T
>> Promise which resolves with the deeply cloned target.
This method deeply clones a given target with JSON.parse
+ JSON.stringify
asynchronously by default. Set absolute: true
for deep cloning complex objects that contain Date, RegExp, Function, etc.
This methods works the same as deepClone(target[, options])
except that this is the synchronous version.
MIT License © Rong Sen Ng