https://github.com/igorskyflyer/npm-clone-js
𧬠A NPM wrapper around a lightweight JavaScript utility allowing deep copy-by-value of nested objects, arrays and arrays of objects. πͺ
https://github.com/igorskyflyer/npm-clone-js
array back-end biome clone clonejs igorskyflyer javascript js nested-objects node nodejs npm object package typescript vitest wrapper
Last synced: 4 months ago
JSON representation
𧬠A NPM wrapper around a lightweight JavaScript utility allowing deep copy-by-value of nested objects, arrays and arrays of objects. πͺ
- Host: GitHub
- URL: https://github.com/igorskyflyer/npm-clone-js
- Owner: igorskyflyer
- License: mit
- Created: 2019-10-16T00:38:47.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2025-08-27T23:38:11.000Z (10 months ago)
- Last Synced: 2025-10-30T23:19:33.860Z (7 months ago)
- Topics: array, back-end, biome, clone, clonejs, igorskyflyer, javascript, js, nested-objects, node, nodejs, npm, object, package, typescript, vitest, wrapper
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@igorskyflyer/clone
- Size: 606 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Support: SUPPORT.md
Awesome Lists containing this project
README
clone.js
𧬠A lightweight JavaScript utility allowing deep copy-by-value of nested objects, arrays and arrays of objects. πͺ
## π Table of Contents
- [Features](#-features)
- [Usage](#-usage)
- [API](#-api)
- [Changelog](#-changelog)
- [Support](#-support)
- [License](#-license)
- [Related](#-related)
- [Author](#-author)
## π€ Features
- 𧬠Deepβclones objects and arrays with full fidelity
- π Recursively copies nested structures without mutation
- π‘οΈ Preserves original data while enabling safe edits
- π§ Smart handling of null and nonβobject values
- π§© Works with mixed arrays, primitives, and objects
- βοΈ Zero dependencies - dropβin and lightweight
- π Ideal for state snapshots, undo systems, or sandboxing
## π΅πΌ Usage
Install it by executing any of the following, depending on your preferred package manager:
```bash
pnpm add @igorskyflyer/clone
```
```bash
yarn add @igorskyflyer/clone
```
```bash
npm i @igorskyflyer/clone
```
## π€ΉπΌ API
### Simple array copy
```javascript
import { clone } from '@igorskyflyer/clone'
const firstArray = [1, 2, 3]
const secondArray = clone(firstArray)
secondArray[0] = 5
console.log('firstArray => ', firstArray) // [1, 2, 3]
console.log('secondArray => ', secondArray) // [5, 2, 3]
```
### Complex array (array of objects)
```javascript
import { clone } from '@igorskyflyer/clone'
const firstArray = [
{
id: '103',
name: 'Peter',
},
{
id: '214',
name: 'Eve',
},
]
const secondArray = clone(firstArray)
secondArray[0].name = 'John'
console.log('firstArray => ', firstArray)
console.log('secondArray => ', secondArray)
```
### Simple object copy
```javascript
import { clone } from '@igorskyflyer/clone'
const firstStudent = {
id: 103,
name: 'Ben',
classes: ['Maths', 'Science', 'English language'],
}
const secondStudent = clone(firstStudent)
secondStudent.classes[0] = 'Psychology'
console.log('firstStudent => ', firstStudent)
console.log('secondStudent => ', secondStudent)
```
### Nested object copy
```javascript
import { clone } from '@igorskyflyer/clone'
const firstStudent = {
id: 103,
name: 'Ben',
subjects: {
groupDke: {
science: 'B',
maths: 'C',
},
groupOpe: {
foo: 'bar',
},
},
}
const secondStudent = clone(firstStudent)
secondStudent.subjects.groupDke.maths = 'B'
console.log('firstStudent => ', firstStudent)
console.log('secondStudent => ', secondStudent)
```
## π Changelog
π The changelog is available here, [CHANGELOG.md](https://github.com/igorskyflyer/npm-clone-js/blob/main/CHANGELOG.md).
## πͺͺ License
Licensed under the MIT license which is available here, [MIT license](https://github.com/igorskyflyer/npm-clone-js/blob/main/LICENSE).
## π Support
I work hard for every project, including this one and your support means a lot to me!
Consider buying me a coffee. β
Thank you for supporting my efforts! ππ
## 𧬠Related
[@igorskyflyer/pathexists](https://www.npmjs.com/package/@igorskyflyer/pathexists)
> _π§² Provides ways of properly checking if a path exists inside a given array of files/directories both on Windows and UNIX-like operating systems. πΊ_
[@igorskyflyer/zep](https://www.npmjs.com/package/@igorskyflyer/zep)
> _π§ Zep is a zero-dependency, efficient debounce module. β°_
[@igorskyflyer/valid-path](https://www.npmjs.com/package/@igorskyflyer/valid-path)
> _π§° Provides ways of testing whether a given value can be a valid file/directory name. π_
[@igorskyflyer/my-file-path](https://www.npmjs.com/package/@igorskyflyer/my-file-path)
> _π An npm module that strongly types file paths! π₯_
[@igorskyflyer/recursive-readdir](https://www.npmjs.com/package/@igorskyflyer/recursive-readdir)
> _π Provides recursive readdir() and readdirSync() functions. π_
## π¨π»βπ» Author
Created by **Igor DimitrijeviΔ** ([*@igorskyflyer*](https://github.com/igorskyflyer/)).