Utility to deep clone javascript objects
With deep cloning becoming a regular practice & a required thing for supporting immutability, deep-clone-util provides a way just to do that.
- No dependeny on any library
- 2kB of unzipped bundle size
- Elementary values
- Array, Objects (nesting upto any level)
- Functions
- Promises
- Dates
- Regular expressions
- Maps & Sets
- Support circular references
- Suppprt more object types
npm i deep-clone-util
const clone = require('deep-clone-util');
const obj = {
a: 1,
b: "string",
c: function(a) {console.log(a)},
d: [1,2,3],
f: {
g: 1
}
}
const clonedObj = clone(obj)
clonedObj.f.g = 10
console.log(obj.f.g) // Prints 1
- Author: Gaurav Behere
- Please raise a PR, if you see some improvement possible.