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 
deep copy module for node.js
Installation
$ npm install deepcopyUsage
var deepcopy = require('deepcopy');
var source = {
data: {
num: 123,
str: 'a',
now: new Date,
reg: /node/ig,
arr: [ true, false, null, undefined ],
obj: { aaa: 1, bbb: 2, ccc: 3 }
}
};
var shallow = source,
deep = deepcopy(source);
delete source.data;
console.dir(source);
// {}
console.dir(shallow);
// {}
console.dir(deep);
// { data:
// { num: 123,
// str: 'a',
// now: Sun Jan 27 2013 23:31:12 GMT+0900 (JST),
// reg: /node/gi,
// arr: [ true, false, null, undefined ],
// obj: { aaa: 1, bbb: 2, ccc: 3 } } }var deepcopy = require('deepcopy');
var a = {},
b = {};
a.to = b;
b.to = a;
try {
deepcopy(a);
} catch (e) {
console.error(e); // [RangeError: Maximum call stack size exceeded]
}Functions
deepcopy(targetObject)
targetObjectany types - copy targetreturntargetObject types - copied value
return deep copy if targetObject is Date, RegExp or primitive types.
return shallow copy if targetObject is function.
this function throws RangeError if targetObject has circular reference.
Test
$ npm install
$ npm testLicense
The MIT License. Please see LICENSE file.