• Stars
    star
    129
  • Rank 279,262 (Top 6 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 12 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

deep copy data

deepcopy.js

test npm version Try deepcopy on RunKit renovate

deep copy data

Installation

npm

$ npm install deepcopy

Usage

node.js

JavaScript

const deepcopy = require('deepcopy');

TypeScript

import * as deepcopy from 'deepcopy';

browser

<script src="deepcopy.min.js"></script>

Example

basic usage:

const src = {
  desserts: [
    { name: 'cake'      },
    { name: 'ice cream' },
    { name: 'pudding'   }
  ]
};

const dist = deepcopy(src);

src.desserts = null;

console.log(src);   // { desserts: null }
console.log(dist);  // { desserts: [ { name: 'cake' }, { name: 'ice cream' }, { name: 'pudding' } ] }

customize deepcopy:

function MyClass(id) {
  this._id = id;
}

const src = {
  myClasses: [
    new MyClass(1),
    new MyClass(2),
    new MyClass(3)
  ]
};

const dest = deepcopy(base, {
  customizer(value) {
    if (target.constructor === MyClass) {
      return new MyClass(target._id);
    }
  }
});

src.myClasses = null;

console.log(src);   // { myClasses: null }
console.log(dest);  // { myClasses: [ MyClass { _id: 1 }, MyClass { _id: 2 }, MyClass { _id: 3 } ] }

Functions

deepcopy(value[, options])

  • value
    • *
      • target value
  • options
    • Object|Function
      • Object - pass options
      • Function - use as customize function
  • return
    • * - copied value

Supported types and copy operation

type operation
ArrayBuffer deep copy
Boolean deep copy
Buffer deep copy node.js only
DataView deep copy
Date deep copy
Number deep copy
RegExp deep copy
String deep copy
Float32Array deep copy
Float64Array deep copy
Int16Array deep copy
Int32Array deep copy
Int8Array deep copy
Uint16Array deep copy
Uint32Array deep copy
Uint8Array deep copy
Uint8ClampedArray deep copy
boolean deep copy
null deep copy
number deep copy
string deep copy
symbol deep copy
undefined deep copy
Arguments deep copy recursively, copy as Array
Array deep copy recursively
Map deep copy recursively
Object deep copy recursively
Set deep copy recursively
Array Iterator shallow copy
Map Iterator shallow copy
Promise shallow copy
Set Iterator shallow copy
String Iterator shallow copy
function shallow copy
global shallow copy window, global, self, etc.
WeakMap shallow copy
WeakSet shallow copy

Contributors

License

The MIT license.

More Repositories

1

ipc-promise

ipc use as Promises
JavaScript
35
star
2

base62.js

base62 encode/decode library
JavaScript
18
star
3

qiita-organizations-graph

Qiita organizations graph
JavaScript
15
star
4

ltsv.js

LTSV parser, formatter, validator and TransformStream
TypeScript
14
star
5

mktemp

mktemp command for node.js
TypeScript
10
star
6

stylelint-processor-ignore-front-matter

stylelint processor for ignore front matter
JavaScript
3
star
7

textlint-plugin-tsdoc

textlint plugin for tsdoc
TypeScript
3
star
8

cookie.js

library for Cookie
JavaScript
2
star
9

cssstylesheet.js

cross browser CSSStyleSheet
JavaScript
2
star
10

dotfiles

my dotfiles
Vim Script
2
star
11

generator-prototyping

Yeoman generator for client side webapp prototyping
CoffeeScript
2
star
12

generator-flowtime

Yeoman generator for slide template with flowtime.js
JavaScript
2
star
13

javascript-lightweight-development-environment

my JavaScript lightweight development environment
JavaScript
1
star
14

which-chrome

get Google Chrome path
JavaScript
1
star
15

http-router

router module for node.js
JavaScript
1
star
16

docker-madge

Docker image for madge and Graphviz
Dockerfile
1
star
17

macos-vim

my Vim for macOS
Makefile
1
star
18

random-notes

my random notes
Shell
1
star
19

javascript-module-development-environment

my JavaScript module development environment
JavaScript
1
star
20

imagemagick-environment

imagemagick environment on Ubuntu
1
star
21

gruntfiles

my gruntfiles
CoffeeScript
1
star
22

alternate-stylesheets.js

switch Alternate Style Sheets
JavaScript
1
star
23

docker-fix-orientation

fix orientation for 360 panorama photo
Makefile
1
star
24

fix-creation-date.sh

fix creation_date metadata within mp4 from filename(for the Nintendo Switch)
Shell
1
star
25

ameba-color-palette.dict

dictionary of ameba-color-palette.css for Vim
Shell
1
star
26

macos-tmux

tmux for macOS, build from source
Makefile
1
star