1.0.3 • Published 3 years ago

@protagonists/deep v1.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

About

A package used to clone and freeze object in more than just a superficial level


Table of content

The content below does not correspond to the object structure of the objects


How to use?

Description

This package allows for cloning and freezing all the way, and even supports circular references!

Import

Terminal

npm install @protagonists/deep

Node.js

const { deepClone, deepFreeze } = require("@protagonists/deep");

Example

Code:

// 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);

Output:

{
  name: 'John',
  age: 37,
  friend: {
    name: 'Steve',
    age: 35
  }
}
{
  name: 'John',
  age: 37,
  friend: {
    name: 'Meep',
    age: 35
  }
}