A package used to clone and freeze object in more than just a superficial level
The content below does not correspond to the object structure of the objects
This package allows for cloning and freezing all the way, and even supports circular references!
npm install @protagonists/deep
const { deepClone, deepFreeze } = require("@protagonists/deep");
// Imports
const { deepClone } = require("@protagonists/deep");
// Create some object
const John = {
name: "John",
age: 37,
friend: {
name: "Steve",
age: 35
}
}
// Clone it
const clone = deepClone("John");
// Edit a value in the nested object
clone.friend.name = "Meep";
// Log them both
// this show that the nested object in the clone is not the same!
console.log(John);
console.log(clone);{
name: 'John',
age: 37,
friend: {
name: 'Steve',
age: 35
}
}
{
name: 'John',
age: 37,
friend: {
name: 'Meep',
age: 35
}
}