Skip to content

🧬 A NPM wrapper around a lightweight JavaScript utility allowing deep copy-by-value of nested objects, arrays and arrays of objects. πŸͺ

License

Notifications You must be signed in to change notification settings

igorskyflyer/npm-clone-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

70 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

clone.js

🧬 A lightweight JavaScript utility allowing deep copy-by-value of nested objects, arrays and arrays of objects. πŸͺ

npm('clone.js')



πŸ’– Support further development

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! πŸ™πŸ˜Š


Donate to igorskyflyer

@igorskyflyer


πŸ•΅πŸΌ Usage

Install it by executing:

npm i "@igor.dvlpr/node-clone-js"

🀹🏼 API

Simple array copy

import { clone } from '@igor.dvlpr/node-clone-js'

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)

import { clone } from '@igor.dvlpr/node-clone-js'

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

import { clone } from '@igor.dvlpr/node-clone-js'

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

import { clone } from '@igor.dvlpr/node-clone-js'

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)

Development

git clone https://github.com/igorskyflyer/npm-clone-js.git

cd npm-clone-js

npm install

Test

npm test

πŸͺͺ License

Licensed under the MIT license which is available here, MIT license.


🧬 Related

@igor.dvlpr/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. πŸ—Ί

@igor.dvlpr/zep

🧠 Zep is a zero-dependency, efficient debounce module. ⏰

@igor.dvlpr/valid-path

🧰 Provides ways of testing whether a given value can be a valid file/directory name. 🏜

@igor.dvlpr/my-file-path

🌟 An npm module that strongly types file paths! πŸ₯Š

@igor.dvlpr/recursive-readdir

πŸ“– Provides recursive readdir() and readdirSync() functions. πŸ“



Provided by Igor Dimitrijević (@igorskyflyer).

About

🧬 A NPM wrapper around a lightweight JavaScript utility allowing deep copy-by-value of nested objects, arrays and arrays of objects. πŸͺ

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project