Skip to content

A lightweight and reliable deep cloning utility for objects, arrays, maps, sets, and more – with full TypeScript support.

License

Notifications You must be signed in to change notification settings

Ritik97/clonify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npm License

Clonify

A lightweight and reliable deep cloning utility for JavaScript and TypeScript.

Clonify is a zero-dependency deep cloning function that handles objects, arrays, maps, sets, dates, regex, symbols, and custom class instances. It also supports circular references.


✨ Features

  • 🔁 Deep clones complex nested structures
  • 🔒 Handles circular references safely
  • 🧠 Clones Maps, Sets, Dates, Regex, Symbols
  • 💎 Preserves prototypes of custom class instances
  • 🧾 Full TypeScript support

📦 Installation

npm install clonify

🚀 Usage

import { clonify } from 'clonify'

class User {
  constructor(public name: string) {}
}

const original = {
  user: new User("Ritik"),
  numbers: [1, 2, 3],
  meta: new Map([["key", "value"]]),
}

original.self = original // circular reference

const copy = clonify(original)

console.log(copy)

📚 API

clonify(value: any): any

Performs a deep clone of the provided value, supporting all standard JavaScript data structures.


🧪 Supported Types

  • Objects (POJOs and class instances)

  • Arrays

  • Maps

  • Sets

  • Dates

  • RegExps

  • Symbols (as keys and values)

  • Circular references


📘 License

MIT © Ritik

About

A lightweight and reliable deep cloning utility for objects, arrays, maps, sets, and more – with full TypeScript support.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published