A utility library that provides a deep copy function for JavaScript objects.
Using npm:
npm install deeb
Using yarn:
yarn add deeb
Import the deepCopy function and use it to create deep copies of your objects:
import deepCopy from "deeb";
const original = {
a: 1,
b: [2, 3],
c: {
d: 4,
},
e: new Map([["f", 5]]),
g: new Set([6, 7]),
};
const copied = deepCopy(original);
console.log(copied); // Output: { a: 1, b: [ 2, 3 ], c: { d: 4 }, e: Map(1) { 'f' => 5 }, g: Set(2) { 6, 7 } }
console.log(copied === original); // Output: false
console.log(copied.b === original.b); // Output: false
console.log(copied.c === original.c); // Output: false
console.log(copied.e === original.e); // Output: false
console.log(copied.g === original.g); // Output: false
MIT