All Projects → segunolalive → deepClone

segunolalive / deepClone

Licence: MIT license
A tiny library for deeply copying Javascript objects and arrays

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to deepClone

go-clone
Clone any Go data structure deeply and thoroughly.
Stars: ✭ 182 (+970.59%)
Mutual labels:  immutable, deepcopy
bytekit
Java 字节操作的工具库(不是字节码的工具库)
Stars: ✭ 40 (+135.29%)
Mutual labels:  deepcopy
Hamt
Immutable and Memory-Efficient Maps and Sets in Go
Stars: ✭ 213 (+1152.94%)
Mutual labels:  immutable
HighlightTranslator
Highlight Translator can help you to translate the words quickly and accurately. By only highlighting, copying, or screenshoting the content you want to translate anywhere on your computer (ex. PDF, PPT, WORD etc.), the translated results will then be automatically displayed before you.
Stars: ✭ 54 (+217.65%)
Mutual labels:  copy
Collectable
High-performance immutable data structures for modern JavaScript and TypeScript applications. Functional interfaces, deep/composite operations API, mixed mutability API, TypeScript definitions, ES2015 module exports.
Stars: ✭ 233 (+1270.59%)
Mutual labels:  immutable
transmute
kind of like lodash but works with Immutable
Stars: ✭ 35 (+105.88%)
Mutual labels:  immutable
Digag Pc React
digag pc website based on react.
Stars: ✭ 209 (+1129.41%)
Mutual labels:  immutable
extendable-immutable
Wrapper classes around Immutable.js that turn it inheritable
Stars: ✭ 58 (+241.18%)
Mutual labels:  immutable
cloner
A deep copy algorithm for haxe
Stars: ✭ 24 (+41.18%)
Mutual labels:  copy
grand central
State-management and action-dispatching for Ruby apps
Stars: ✭ 20 (+17.65%)
Mutual labels:  immutable
Unchanged
A tiny, fast, unopinionated handler for updating JS objects and arrays immutably
Stars: ✭ 237 (+1294.12%)
Mutual labels:  immutable
kotlin-ktor-exposed-sample-api
Kotlin Ktor Exposed SQL Immutable DB Rest API
Stars: ✭ 44 (+158.82%)
Mutual labels:  immutable
react-gluejar
Paste images from your clipboard, declaratively
Stars: ✭ 58 (+241.18%)
Mutual labels:  copy
Static Frame
Immutable and grow-only Pandas-like DataFrames with a more explicit and consistent interface.
Stars: ✭ 217 (+1176.47%)
Mutual labels:  immutable
rrbit
An Immutable vectors/lists/arrays library using the Relaxed Radix Balancing(RRB) technique
Stars: ✭ 12 (-29.41%)
Mutual labels:  immutable
Music163 React
🔥基于React全家桶开发:「网易云音乐PC端项目」实战
Stars: ✭ 209 (+1129.41%)
Mutual labels:  immutable
SandDB
A simple immutable database for the masses.
Stars: ✭ 21 (+23.53%)
Mutual labels:  immutable
gotoReact-
react的一些案例
Stars: ✭ 20 (+17.65%)
Mutual labels:  immutable
cassandra-exporter
Simple Tool to Export / Import Cassandra Tables into JSON
Stars: ✭ 44 (+158.82%)
Mutual labels:  copy
product-language-framework
A ready-to-go starter kit for product copywriting and style guidelines. Useful guidelines, examples, and an optional static site generator.
Stars: ✭ 20 (+17.65%)
Mutual labels:  copy

Deep Clone

A nifty zero-dependency utility for deeply cloning javascript objects and arrays.

NOTE:
Only enumerable properties are cloned. Non-enumerable properties and Prototype chains are not cloned. If used with other data types, it simply returns the arguement passed.

Why?

Where immutability matters, javascript fails the developer miserably. Although javascript provides some functional programming features, it manipulates complex data types by mutation. For example

const a = { a: 1, b: 2, c: { d: 4 } }
const b = a;
a[b] = 3;
console.log(a) // { a: 1, b: 3, c: { d: 4 } }

With Object.assign, we can get around this but it only takes us so far since it only performs a shallow copy while nested objects and arrays are still copied by reference.

const a = { a: 1, b: 2, c: { d: 4 } }
const b = Object.assign({}, a);
console.log(b) // { a: 1, b: 3, c: { d: 4 } }
a.a = 2 // no effect on b;
console.log(b) // { a: 1, b: 3, c: { d: 4 } }
a.c.d = 44; // changes b as well
console.log(b) // { a: 1, b: 3, c: { d: 44 } }

This is what deepClone helps to solve.

   const deepClone = require('deepClonejs');

let a = let a = {
    a: 1,
    b: 2,
    c: [1, 2, 3, {
        e: 5,
        f: [{
              g: 1
            },
            {
              h: 8
            }],
        i: 9}
        ],
        j: 10
    }
let b = deepClone(a);
a.c.f.g = 500
b.c.f.g = 1 // unaffected by change in a's child object's values

This is particularly useful when mutation is not an option e.g in a Redux application.

How To Use

npm install --save deepclonejs

const deepClone = require('deepclonejs');

then use as in the example above.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].