Comparing version 0.1.0 to 0.1.1
@@ -0,3 +1,10 @@ | ||
# 0.1.1 / 2013-01-28 | ||
- deleted chai and sinon | ||
- fixed test and test message | ||
- fixed README.md | ||
- fixed code @66e9af5 | ||
# 0.1.0 / 2013-01-26 | ||
- initial release |
@@ -35,6 +35,4 @@ // deepcopy Copyright(c) 2013 sasa+1 | ||
keys = Object.keys(targetObject); | ||
i = 0; | ||
len = keys.length; | ||
for (; i < len; ++i) { | ||
for (i = 0, len = keys.length; i < len; ++i) { | ||
keyValue = keys[i]; | ||
@@ -41,0 +39,0 @@ cloneObject[keyValue] = deepcopy(targetObject[keyValue]); |
{ | ||
"name": "deepcopy", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"author": "sasa+1 <sasaplus1@gmail.com>", | ||
@@ -18,6 +18,4 @@ "description": "deep copy module for node.js", | ||
"devDependencies": { | ||
"chai": "~1.4", | ||
"mocha": "~1.8", | ||
"sinon": "~1.5" | ||
"mocha": "~1.8" | ||
} | ||
} |
@@ -14,53 +14,48 @@ # deepcopy [![Build Status](https://travis-ci.org/sasaplus1/deepcopy.png)](https://travis-ci.org/sasaplus1/deepcopy) | ||
```js | ||
var util = require('util'), | ||
deepcopy = require('deepcopy'); | ||
var deepcopy = require('deepcopy'); | ||
var copied, | ||
obj = { | ||
num: 123, | ||
str: 'a', | ||
bool: false, | ||
nil: null, | ||
undef: undefined, | ||
now: new Date, | ||
reg: /node/ig, | ||
arr: [ | ||
true, false, null | ||
], | ||
obj: { | ||
aaa: 1, | ||
bbb: 2, | ||
ccc: 3 | ||
} | ||
}; | ||
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 } | ||
} | ||
}; | ||
copied = deepcopy(obj); | ||
var shallow = source, | ||
deep = deepcopy(source); | ||
obj.num = 555; | ||
obj.str = 'A'; | ||
obj.bool = true; | ||
delete source.data; | ||
console.log(copied === obj); // false | ||
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 } } } | ||
``` | ||
console.log(util.inspect(obj, false, null, true)); | ||
// { num: 555, | ||
// str: 'A', | ||
// bool: true, | ||
// nil: null, | ||
// undef: undefined, | ||
// now: Sat Jan 26 2013 00:21:37 GMT+0900 (JST), | ||
// reg: /node/gi, | ||
// arr: [ true, false, null ], | ||
// obj: { aaa: 1, bbb: 2, ccc: 3 } } | ||
```js | ||
var deepcopy = require('deepcopy'); | ||
console.log(util.inspect(copied, false, null, true)); | ||
// { num: 123, | ||
// str: 'a', | ||
// bool: false, | ||
// nil: null, | ||
// undef: undefined, | ||
// now: Sat Jan 26 2013 00:21:37 GMT+0900 (JST), | ||
// reg: /node/gi, | ||
// arr: [ true, false, null ], | ||
// obj: { aaa: 1, bbb: 2, ccc: 3 } } | ||
var a = {}, | ||
b = {}; | ||
a.to = b; | ||
b.to = a; | ||
try { | ||
deepcopy(a); | ||
} catch (e) { | ||
console.error(e); // [RangeError: Maximum call stack size exceeded] | ||
} | ||
``` | ||
@@ -72,7 +67,10 @@ | ||
* `targetObject` any types - deep copy target | ||
* `return` `targetObject` types - copied object | ||
* `targetObject` any types - copy target | ||
* `return` targetObject types - copied value | ||
return deep copied object from targetObject. | ||
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 | ||
@@ -79,0 +77,0 @@ |
@@ -1,3 +0,2 @@ | ||
var assert = require('chai').assert, | ||
sinon = require('sinon'), | ||
var assert = require('assert'), | ||
deepcopy = require('../'); | ||
@@ -68,3 +67,3 @@ | ||
assert.deepEqual(copiedObj, obj, | ||
'deepcopy(Object) should be return RegExp'); | ||
'deepcopy(Object) should be return Object'); | ||
}); | ||
@@ -87,3 +86,3 @@ | ||
assert.deepEqual(copiedArr, arr, | ||
'deepcopy(Array) should be return RegExp'); | ||
'deepcopy(Array) should be return Array'); | ||
}); | ||
@@ -109,7 +108,7 @@ | ||
assert.deepEqual(copiedObj, obj, | ||
'deepcopy(Object) should be return RegExp'); | ||
'deepcopy(Object) should be return Object'); | ||
}); | ||
test('循環参照でRangeErrorが投げられること', function() { | ||
assert.throw(function() { | ||
assert.throws(function() { | ||
var a = {}, | ||
@@ -122,3 +121,3 @@ b = {}; | ||
return deepcopy(a); | ||
}, RangeError, 'Maximum call stack size exceeded'); | ||
}, RangeError); | ||
}); | ||
@@ -125,0 +124,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1
8578
141
84