An open API service indexing awesome lists of open source software.

https://github.com/ritik97/clonify

A lightweight and reliable deep cloning utility for objects, arrays, maps, sets, and more โ€“ with full TypeScript support.
https://github.com/ritik97/clonify

deep-clone javascript npm-package object-clone open-source typescript utility

Last synced: 14 days ago
JSON representation

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

Awesome Lists containing this project

README

          

![npm](https://img.shields.io/npm/v/clonify?cacheSeconds=10)
![License](https://img.shields.io/github/license/Ritik97/clonify)

# 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

```bash
npm install clonify
```

---

## ๐Ÿš€ Usage

```ts
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](https://github.com/Ritik97)