clone-deep2
v1.0.1
Published
Recursively (deep) clone JavaScript native types, like Object, Array, RegExp, Date as well as primitives.
Downloads
10
Maintainers
Readme
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);
//=> [{a: 'b'}]
console.log(arr);
//=> [{a: 'b', c: 'd'}]
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
- is-plain-object: Returns true if an object was created by the
Object
constructor. | homepage - isobject: Returns true if the value is an object and not an array or null. | homepage
- kind-of: Get the native type of a value. | homepage
- shallow-clone: Make a shallow clone of an object, array or primitive. | homepage
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#dev verb-generate-readme && 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.