# deep-clone

> Deep cloning of Arrays and plain Objects.

Latest version **4.0.0** (published 2023-03-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install deep-clone
pnpm add deep-clone
yarn add deep-clone
bun add deep-clone
```

## Health

**Score 45/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2023-03-28 |
| First published | 2015-11-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Tim Davis |
| Maintainers | thebearingedge |
| Keywords | clone |

## Links

- npm: https://www.npmjs.com/package/deep-clone
- Repository: https://github.com/thebearingedge/deep-clone
- Homepage: https://github.com/thebearingedge/deep-clone#readme
- Issues: https://github.com/thebearingedge/deep-clone/issues
- npm.io page: https://npm.io/package/deep-clone

## Recent versions

- 4.0.0 (latest) — 2023-03-28
- 3.0.3 — 2018-04-30
- 3.0.2 — 2016-11-21
- 3.0.1 — 2016-11-01
- 3.0.0 — 2016-11-01
- 2.0.2 — 2016-01-06
- 2.0.1 — 2016-01-06
- 2.0.0 — 2016-01-05
- 1.1.0 — 2015-12-19
- 1.0.2 — 2015-11-26
- 1.0.1 — 2015-11-22
- 1.0.0 — 2015-11-22

## README

# deep-clone

[![Github Actions Test Status](https://github.com/thebearingedge/deep-clone/workflows/test/badge.svg?branch=main)](https://github.com/thebearingedge/deep-clone/actions?query=workflow%3Atest+branch%3Amain)
[![codecov](https://codecov.io/gh/thebearingedge/deep-clone/branch/main/graph/badge.svg?token=PDH8IGTF1A)](https://codecov.io/gh/thebearingedge/deep-clone)

Deep cloning of data.

```bash
$ npm i -S deep-clone
```

`deepClone(obj, [stringFormatter])`
---

Recursively clone nested objects and arrays containing primitive data or nested objects and arrays containing primitive data. Clones `Date` objects too.

```javascript
import deepClone from 'deep-clone'

const foo = { bar: 'baz' }
const fooClone = deepClone(foo)

assert.deepEqual(foo, fooClone)
assert.notEqual(foo, fooClone)

const arr = [{ foo: 'bar'}, { baz: 'qux'}]
const arrClone = deepClone(arr)

assert.deepEqual(arr, arrClone)
assert.notEqual(arr, arrClone)
```

Deep clone an Object or Array and format the keys.

```javascript
import camelCase from 'camelcase'
import deepClone from 'deep-clone'

const foo = { bar_baz: 'qux' }
const fooClone = deepClone(foo, camelCase)

assert.deepEqual(fooClone, { barBaz: 'qux' })
```

Or...

```javascript
import camelCase from 'camelcase'
import { formatKeys } from 'deep-clone'

const camelKeys = formatKeys(camelCase)
const arr = [{ foo_bar: 'baz' }, { qux_quux: 'corge' }]
const camelClone = camelKeys(arr)

assert.deepEqual(camelClone, [{ fooBar: 'baz' }, { quxQuux: 'corge' }])
```

Circular references are handled using a Map.

```javascript
const foo = { bar: 'baz' }

foo.qux = [foo]

const clone = deepClone(foo)

assert.deepEqual(clone, foo)
assert.equal(clone.qux[0], clone)
```

Other options:
- [clone-deep](https://github.com/jonschlinkert/clone-deep)
- [safe-clone-deep](https://github.com/tracker1/safe-clone-deep)

---
_Source: https://npm.io/package/deep-clone · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
