2.0.0 • Published 9 months ago

@pivanov/deep-clone v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

@pivanov/deep-clone

A versatile and lightweight deep clone utility for JavaScript and TypeScript.

Installation

npm install @pivanov/deep-clone --save-dev

or with yarn:

yarn add @pivanov/deep-clone --dev

or with pnpm:

pnpm add @pivanov/deep-clone --dev

Usage

import { deepClone } from '@pivanov/deep-clone';

Note that one of inject or fileName must be provided.

const userProfile = {
  name: "Alice",
  contact: {
    email: "alice@example.com",
    phone: { mobile: "123-456", work: "789-101" },
  },
  preferences: new Set(["dark-mode", "notifications"]),
};

const clonedProfile = deepClone(userProfile);

// Modifying the cloned profile won’t affect the original
clonedProfile.contact.phone.mobile = '999-999';

Author

Created by pivanov.

License

MIT