Like the original clone-deep, it will recursively (deep) clone JavaScript native types, like Object, Array, RegExp, Date as well as primitives, setters, getters and circular objects cloning. Clones object property descriptors info as well.
npm install @emahuni/clone-deep> Like the original clone-deep, it will recursively (deep) clone JavaScript native types, like Object, Array, RegExp, Date as well as primitives, setters, getters and circular objects cloning. Clones object property descriptors info as well.
Please consider following this project's author, Emmanuel Mahuni, and consider starring the project to show your :heart: and support.
Install with npm:
``sh`
$ npm install --save @emahuni/clone-deep
`js
const cloneDeep = require('@emahuni/clone-deep');
let obj = { a: 'b' };
let arr = [obj];
let copy = cloneDeep(arr);
obj.c = 'd';
console.log(copy);
//=> [{ a: 'b' }]
console.log(arr);
//=> [{ a: 'b', c: 'd' }]
obj.e = obj;
copy = cloneDeep(arr);
console.log(copy);
//=> [{ a: 'b', c: 'd', e: {...} }] // handles circular arrays and objects cloning
`
The last argument specifies whether to clone instances (objects that are from a custom class or are not created by the Object constructor. This value may be true or the function use for cloning instances.
When an instanceClone function is provided, it will be invoked to clone objects that are not "plain" objects (as defined by isPlainObjectisPlainObject). If instanceClone is not specified, this library will not attempt to clone non-plain objects, and will simply copy the object reference.
Based on jonschlinkert's that was...
initially based on mout's implementation of deepClone.
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Running Tests
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
`sh``
$ npm install && npm test
| Commits | Contributor |
| -- | --- |
| 24 | emahuni |
| 46 | jonschlinkert |
| 2 | yujunlong2000 |
Emmanuel Mahuni
* GitHub Profile
* Twitter Profile
* LinkedIn Profile
Copyright © 2022, Emmanuel Mahuni.
Released under the MIT License.
*