JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 287355
  • Score
    100M100P100Q166251F
  • License MIT

deep copy for any data

Package Exports

  • deepcopy

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (deepcopy) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

deepcopy.js

Build Status Dependency Status NPM version Bower version

deep copy for any data

Installation

npm

$ npm install deepcopy

bower

$ bower install deepcopy

Usage

node.js

var deepcopy = require('deepcopy');

browser

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

define deepcopy by define() if using AMD loader.

otherwise deepcopy export to global.

Example

var data, shallow, deep;

data = {
  objects: {
    array: [
      null, undefined, new Date, /deepcopy/ig
    ],
    object: {
      number: NaN,
      string: 'A',
      boolean: true
    },
    to: null
  }
};

// circular reference
data.objects.to = data;

// shallow copy and deep copy
shallow = data;
deep = deepcopy(data);

// remove entry
delete data.objects;

// results
console.log(data);
// {}
console.log(shallow);
// {}
console.log(require('util').inspect(deep, { depth: null }));
// { objects:
//    { array:
//       [ null,
//         undefined,
//         Sat Jan 10 2015 03:18:32 GMT+0900 (JST),
//         /deepcopy/gi ],
//      object: { number: NaN, string: 'A', boolean: true },
//      to: [Circular] } }

Functions

deepcopy(value)

  • value
    • * - copy target value
  • return
    • * - deep copied value

return deep copied value.

supported types are below:

  • Number
  • String
  • Boolean
  • Null
  • Undefined
  • Function (shallow copy)
  • Date
  • RegExp
  • Array
    • recursive copy
    • also can copy if it has circular reference
  • Object
    • recursive copy
    • also can copy if it has circular reference
  • Buffer (node.js only)

Test

node.js

$ npm install
$ npm test

browser

$ npm install
$ npm run bower
$ npm run testem

Contributors

License

The MIT license. Please see LICENSE file.