3.7 KiB
clone-deep
Recursively (deep) clone JavaScript native types, like Object, Array, RegExp, Date as well as primitives.
Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your ❤️ and support.
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
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:
$ npm install && npm test
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
Related projects
You might also be interested in these 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
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 November 16, 2017.