https://github.com/sequencemedia/dupe
https://github.com/sequencemedia/dupe
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/sequencemedia/dupe
- Owner: sequencemedia
- Created: 2024-12-07T21:22:22.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-29T01:04:10.000Z (about 1 year ago)
- Last Synced: 2025-03-29T02:20:12.797Z (about 1 year ago)
- Language: JavaScript
- Size: 423 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# `@sequencemedia/dupe`
Produces a duplicate (or deep clone) of an object or array, preserving circular references _in the duplicated values_, and preserving functions
Primitives are returned as-is
```javascript
import dupe from '@sequencemedia/dupe'
const a = [1, 2, 3]
a.push(a)
const o = { a: 4, b: 5, c: 6, func () { } }
o.o = o
a.push(o)
const array = dupe(a)
```
These types as well as `Buffer` instances can be duplicated using `@sequencemedia/dupe/node`
```javascript
import dupe from '@sequencemedia/dupe/node'
const a = [1, 2, 3, Buffer.from('x')]
a.push(a)
const o = { a: 4, b: 5, c: 6, func () { }, buff: Buffer.from('y') }
o.o = o
a.push(o)
const array = dupe(a)
```
For most values (i.e., except functions) `structuredClone` is preferable