Socket
Socket
Sign inDemoInstall

deepcopy

Package Overview
Dependencies
1
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    deepcopy

deep copy data


Version published
Weekly downloads
153K
increased by1.79%
Maintainers
1
Install size
573 kB
Created
Weekly downloads
 

Readme

Source

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

typeoperation
ArrayBufferdeep copy
Booleandeep copy
Bufferdeep copynode.js only
DataViewdeep copy
Datedeep copy
Numberdeep copy
RegExpdeep copy
Stringdeep copy
Float32Arraydeep copy
Float64Arraydeep copy
Int16Arraydeep copy
Int32Arraydeep copy
Int8Arraydeep copy
Uint16Arraydeep copy
Uint32Arraydeep copy
Uint8Arraydeep copy
Uint8ClampedArraydeep copy
booleandeep copy
nulldeep copy
numberdeep copy
stringdeep copy
symboldeep copy
undefineddeep copy
Argumentsdeep copyrecursively, copy as Array
Arraydeep copyrecursively
Mapdeep copyrecursively
Objectdeep copyrecursively
Setdeep copyrecursively
Array Iteratorshallow copy
Map Iteratorshallow copy
Promiseshallow copy
Set Iteratorshallow copy
String Iteratorshallow copy
functionshallow copy
globalshallow copywindow, global, self, etc.
WeakMapshallow copy
WeakSetshallow copy

Contributors

License

The MIT license.

FAQs

Last updated on 09 Aug 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc