clone-deep
Recursively (deep) clone JavaScript native types, like Object, Array, RegExp, Date as well as primitives.
Install
Install with npm:
$ npm install --save clone-deep
Usage
var cloneDeep = require('clone-deep');
var obj = {a: 'b'};
var arr = [obj];
var copy = cloneDeep(arr);
obj.c = 'd';
console.log(copy);
console.log(arr);
Heads up!
The instanceClone
function is invoked to clone objects that are not "plain" objects (as defined by isPlainObjectisPlainObject
) if it is provided. If instanceClone
is not specified, it will not attempt to clone non-plain objects, and will copy the object reference.
Attribution
Based on mout's implementation of deepClone.
About
Related projects
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Building docs
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
$ npm install -g verbose/verb
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:
$ npm install && npm test
Author
Jon Schlinkert
License
Copyright © 2017, Jon Schlinkert.
Released under the MIT License.
This file was generated by verb-generate-readme, v0.6.0, on July 16, 2017.