Deep fast clone JavaScript objects with circular references handling and TypeScript support
npm install deeply-clone!GitHub package.json version
!npm bundle size
!GitHub Workflow Status
!Testspace pass ratio
!Coverage Status

Deep fast clone JavaScript objects with circular references handling and TypeScript support
``sh`Install with npm
npm install deeply-clone`sh`Install with yarn
yarn add deeply-clone
Once the package is installed, you can import the library using import or require approach:
`js`
import { deeplyClone } from "deeply-clone";
or
`js`
const deeplyClone = require("deeply-clone");
* Clones deeply objects
* Supports Object, Array, Map or Set cloning
* Objects can have any circular references
* Fast algorithm with caching
* Strongly typed merged result with TypeScript
* No dependencies
* Small size
* Works in browser and Node.js
`typescript
const book = {
title: "Harry Potter",
price: {
value: 69,
currency: "USD"
}
};
const bookCopy = deeplyClone(book);
console.log(bookCopy === book); // false
// const bookCopy = {
// title: "Harry Potter",
// price: {
// value: 69,
// currency: "USD"
// }
// };
`
`typescript
const book = {
title: "Harry Potter",
price: 49,
author: {
name: "Joanne Rowling",
books: [] // → [book]
}
};
book.author.books.push(book); // add circular reference
const bookCopy = deeplyClone(book);
console.log(bookCopy === book); // false
console.log(bookCopy.author.books[0] === bookCopy); // true
// const bookCopy = {
// title: "Harry Potter",
// price: 49,
// author: {
// name: "Joanne Rowling",
// books: [bookCopy] // circular reference → [bookCopy]
// }
// };
``