1.0.1 • Published 6 years ago

@tropicalbastos/clone-js v1.0.1

Weekly downloads
1
License
MIT
Repository
-
Last release
6 years ago

CloneJs

Object.assign() is sometimes no good because it does not deep clone nested properties. That's where CloneJs comes in handy! You can deep clone objects with thousands of nested properties and run a deep comparison on them, see below:

Usage

To deep clone an object you can easily call the utility method deepClone:

const util = require('clone');

var obj = {
    a: 'a',
    b: [
        {
            c: 'c'
        }
    ]
}

var clone = util.deepClone(obj)

If you wish to do a recursive comparison of two different objects you can call deepEqual:

const util = require('clone');

var obj = {
    a: 'a',
    b: [
        {
            c: 'c'
        }
    ]
}

var clone = util.deepClone(obj)
console.log(util.deepEqual(obj, clone)) //logs true

Method Reference

MethodSummary
deepCloneTakes an object and deep clones it
deepCloneRecursiveA more performant version of deepClone()
deepEqualTakes two objects as parameters and does a deep comparison of the two, returning true if equal