lutils-clone
clone Reliably and recursively clone javascript objects
npm install lutils-clone
API
clone([mixed], [[options]])
Clones an object, recursively.
const test = Test {} const obj = a : b: 2 {} test const newObj = newObjab = 5 objab // 2newObja === obja // falsenewObjtest === test // falsenewObjtest__proto__ === test__proto__ // truenewObjfn === objfn // true
Advanced usage
Options
// 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