@bemoje/clone
Deep and shallow clone.
Version
Travis CI
Dependencies
Stats
Donate
Installation
npm install @bemoje/clone
npm install --save @bemoje/clone
npm install --save-dev @bemoje/clone
Usage
import clone from '@bemoje/clone'
clone({ a: 2 })
//=> {a: 2}
clone.deep({ a: 2, b: [25, 2] })
//=> {a: 2, b: [25,2]}
Tests
Uses Jest to test module functionality. Run tests to get coverage details.
npm run test
API
Table of Contents
clone
Deep and shallow clone.
Merged forks of https://github.com/jonschlinkert/shallow-clone and https://github.com/jonschlinkert/clone-deep.
Parameters
-
value
any The value to clone -
deep
boolean Whether or not to do a deep clone (optional, defaultfalse
) -
instanceClone
boolean Whether or not to deep clone custom objects. (optional, defaulttrue
)
Array
Shallow clone an array.
Parameters
-
arr
Array
Returns Array
Object
Shallow clone an object.
Parameters
-
obj
object
Returns object
Date
Shallow clone a Date-object.
Parameters
-
date
Date
Returns Date
Map
Shallow clone a Map object.
Parameters
-
map
Map
Returns Map
Set
Shallow clone a Set.
Parameters
-
set
Set
Returns Set
Error
Shallow clone an Error object.
Parameters
-
err
Error
Returns Error
RegExp
Shallow clone an RegExp object.
Parameters
-
regex
RegExp
Returns RegExp
ArrayBuffer
Shallow clone an ArrayBuffer.
Parameters
-
arrBuf
ArrayBuffer
Returns ArrayBuffer
TypedArray
Shallow clone a TypedArray
Parameters
-
arrTyped
TypedArray
Returns TypedArray
Buffer
Shallow clone a Buffer.
Parameters
-
buf
Buffer
Returns Buffer
Symbol
Shallow clone a Symbol.
Parameters
-
sym
Symbol
Returns Symbol
deep
Deep clone a value
Parameters
-
value
any The value to clone. -
instanceClone
boolean Whether or not to deep clone custom objects. (optional, defaulttrue
)
Returns any