@tropicalbastos/clone-js

JavaScript object deep cloning and object deep comparing library

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
@tropicalbastos/clone-js
Minified + gzip package size for @tropicalbastos/clone-js in KB

Readme

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

Method Summary
deepClone Takes an object and deep clones it
deepCloneRecursive A more performant version of deepClone()
deepEqual Takes two objects as parameters and does a deep comparison of the two, returning true if equal

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.