Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jonschlinkert/clone-deep
Recursively (deep) clone JavaScript native types, like Object, Array, RegExp, Date as well as primitives. Used by superstruct, merge-deep, and many others!
https://github.com/jonschlinkert/clone-deep
clone clone-deep copy deep deep-clone deep-copy javascript jonschlinkert js node nodejs object
Last synced: 24 days ago
JSON representation
Recursively (deep) clone JavaScript native types, like Object, Array, RegExp, Date as well as primitives. Used by superstruct, merge-deep, and many others!
- Host: GitHub
- URL: https://github.com/jonschlinkert/clone-deep
- Owner: jonschlinkert
- License: mit
- Created: 2015-02-27T05:13:07.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-02-09T23:45:49.000Z (9 months ago)
- Last Synced: 2024-05-15T13:26:14.923Z (6 months ago)
- Topics: clone, clone-deep, copy, deep, deep-clone, deep-copy, javascript, jonschlinkert, js, node, nodejs, object
- Language: JavaScript
- Homepage: https://github.com/jonschlinkert
- Size: 43 KB
- Stars: 309
- Watchers: 7
- Forks: 53
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# clone-deep [![NPM version](https://img.shields.io/npm/v/clone-deep.svg?style=flat)](https://www.npmjs.com/package/clone-deep) [![NPM monthly downloads](https://img.shields.io/npm/dm/clone-deep.svg?style=flat)](https://npmjs.org/package/clone-deep) [![NPM total downloads](https://img.shields.io/npm/dt/clone-deep.svg?style=flat)](https://npmjs.org/package/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](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
## Install
Install with [npm](https://www.npmjs.com/):```sh
$ npm install --save clone-deep
```## Sponsors
The following companies, organizations, and individuals support the ongoing maintenance and development of clone-deep. [Become a Sponsor](https://github.com/sponsors/jonschlinkert) to add your logo to this README, or any of [my other projects](https://github.com/jonschlinkert?tab=repositories&q=&type=&language=&sort=stargazers)
### Gold Sponsors
| [](https://jaake.tech/) |
|:---:|
| [https://jaake.tech/](https://jaake.tech/) |## Usage
```js
const cloneDeep = require('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' }]
```## Heads up!
The last argument specifies whether or not 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 [`isPlainObject`](#isPlainObject)). If `instanceClone` is not specified, this library will not attempt to clone non-plain objects, and will simply copy the object reference.
## Attribution
Initially based on [mout's](https://github.com/mout/mout) implementation of deepClone.
## About
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
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
```Building docs
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
To generate the readme, run the following command:
```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```### Related projects
You might also be interested in these projects:
- [is-plain-object](https://www.npmjs.com/package/is-plain-object): Returns true if an object was created by the `Object` constructor, or Object.create(null). | [homepage](https://github.com/jonschlinkert/is-plain-object "Returns true if an object was created by the `Object` constructor, or Object.create(null).")
- [isobject](https://www.npmjs.com/package/isobject): Returns true if the value is an object and not an array or null. | [homepage](https://github.com/jonschlinkert/isobject "Returns true if the value is an object and not an array or null.")
- [kind-of](https://www.npmjs.com/package/kind-of): Get the native type of a value. | [homepage](https://github.com/jonschlinkert/kind-of "Get the native type of a value.")
- [shallow-clone](https://www.npmjs.com/package/shallow-clone): Creates a shallow clone of any JavaScript value. | [homepage](https://github.com/jonschlinkert/shallow-clone "Creates a shallow clone of any JavaScript value.")### Contributors
| **Commits** | **Contributor** |
| --- | --- |
| 49 | [jonschlinkert](https://github.com/jonschlinkert) |
| 2 | [yujunlong2000](https://github.com/yujunlong2000) |### Author
**Jon Schlinkert**
+ [GitHub Profile](https://github.com/jonschlinkert)
+ [Twitter Profile](https://twitter.com/jonschlinkert)
+ [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)### License
Copyright © 2023, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).***
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on July 12, 2023._