https://github.com/nfour/lutils-clone
Reliably and recursively clone javascript objects
https://github.com/nfour/lutils-clone
Last synced: over 1 year ago
JSON representation
Reliably and recursively clone javascript objects
- Host: GitHub
- URL: https://github.com/nfour/lutils-clone
- Owner: nfour
- Created: 2016-02-21T03:25:02.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-01-10T10:57:18.000Z (over 9 years ago)
- Last Synced: 2024-04-26T18:46:48.674Z (about 2 years ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# clone `lutils-clone`
Reliably and recursively clone javascript objects
`npm install lutils-clone`
## API
### `clone([mixed], [[options]])`
Clones an object, recursively.
```js
import clone from 'lutils-clone'
const test = new class Test {}
const obj = {
a : { b: 2 },
fn : function() {}
test,
}
const newObj = clone(obj)
newObj.a.b = 5
obj.a.b // 2
newObj.a === obj.a // false
newObj.test === test // false
newObj.test.__proto__ === test.__proto__ // true
newObj.fn === obj.fn // true
```
## Advanced usage
### Options
```js
{
// Decremented with each recursion for each nested object, halting the clone at 0
// A halted clone will preserve references to any remaining values
depth: 8,
// Determines whether recursing will occur. When this type matches, it will be iterated over.
types: { object: true, array: true }
types: [ "object", "array" ] // Can also be an array of type strings
}
```