Recursively (deep) clone JavaScript native types, like Object, Array, RegExp, Date as well as primitives.
The instanceClone
function is invoked to clone objects that are not "plain" objects (as defined by isPlainObject
) if it is provided. If instanceClone
is not specified, it will not attempt to clone non-plain objects, and will copy the object reference.
Install with npm
sh
$ npm i clone-deep --save
```js var cloneDeep = require('clone-deep');
var obj = {a: 'b'}; var arr = [obj];
var copy = cloneDeep(arr); obj.c = 'd';
console.log(copy); //=> [{a: 'b'}]
console.log(arr); //=> [{a: 'b', c: 'd'}] ```
Install dev dependencies:
sh
$ npm i -d && npm test
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Jon Schlinkert
Based on mout's implementation of deepClone.
Copyright © 2014-2015 Jon Schlinkert Released under the MIT license.
This file was generated by verb on December 23, 2015.