JSPM

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

library of deep copy

Package Exports

  • deepcopy
  • deepcopy/index.js

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

library of deep copy

Installation

npm

$ npm install deepcopy

bower

$ bower install deepcopy

Usage

var deepcopy = require('deepcopy');

var source = {
  data: {
    number: 123,
    string: 'a',
    boolean: true,
    null: null,
    undefined: undefined,
    date: new Date,
    regexp: /regexp/ig,
    array: [
      [ 123, 'abc', false ],
      [ new Date, /node/i ],
      { array: [] }
    ],
    object: {
      number: 123, string: 'abc', boolean: false
    },
    to: undefined
  }
};

source.data.to = source;

var shallow = source,
    deep = deepcopy(source);

delete source.data;

console.dir(source);
// {}
console.dir(shallow);
// {}
console.log(
    require('util').inspect(deep, {depth: null}));
// { data:
//    { number: 123,
//      string: 'a',
//      boolean: true,
//      null: null,
//      undefined: undefined,
//      date: Sun May 26 2013 16:16:32 GMT+0900 (JST),
//      regexp: /regexp/gi,
//      array:
//       [ [ 123, 'abc', false ],
//         [ Sun May 26 2013 16:16:32 GMT+0900 (JST), /node/i ],
//         { array: [] } ],
//      object: { number: 123, string: 'abc', boolean: false },
//      to: [Circular] } }

Functions

deepcopy(target)

  • target any types - target of copy
  • return any types - copied object from target

get deep copy of target.

return deep copy if target is Date, RegExp or primitive types. return shallow copy if target is function.

do recursive copy if target is Array or Object. also can copy if target has circular reference.

Test

test for node.js

$ npm install
$ npm test

test for browser

$ npm install
$ npm run-script bower
$ npm run-script testem

License

The MIT License. Please see LICENSE file.