Skip to content

Commit 6fd0cc3

Browse files
committed
release for version 0.6.1
2 parents a34d8f8 + c55e455 commit 6fd0cc3

File tree

6 files changed

+58
-12
lines changed

6 files changed

+58
-12
lines changed

HISTORY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 0.6.1 / 2016-01-13
2+
3+
- fixed #9
4+
15
# 0.6.0 / 2015-12-29
26

37
- fixed #7

build/deepcopy.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,8 @@ return /******/ (function(modules) { // webpackBootstrap
354354
var key = undefined,
355355
value = undefined,
356356
index = undefined,
357-
result = undefined,
358357
resultCopy = undefined,
358+
result = undefined,
359359
ref = undefined;
360360

361361
for (i = 0, len = keys.length; i < len; ++i) {
@@ -367,8 +367,10 @@ return /******/ (function(modules) { // webpackBootstrap
367367
resultCopy = _copy.copy(value, customizer);
368368
result = resultCopy !== null ? resultCopy : value;
369369

370-
visited.push(value);
371-
reference.push(result);
370+
if (value !== null && /^(?:function|object)$/.test(typeof value)) {
371+
visited.push(value);
372+
reference.push(result);
373+
}
372374
} else {
373375
// circular reference
374376
ref = reference[index];

build/deepcopy.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "deepcopy",
3-
"version": "0.6.0",
3+
"version": "0.6.1",
44
"author": "sasa+1 <[email protected]>",
55
"contributors": [
66
"kjirou <[email protected]>"
@@ -51,9 +51,5 @@
5151
"power-assert": "^1.2.0",
5252
"rimraf": "^2.4.4",
5353
"webpack": "^1.12.9"
54-
},
55-
"engines": {
56-
"node": "^4.2.3",
57-
"npm": "^2.14.7"
5854
}
5955
}

src/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function recursiveCopy(target, customizer, clone, visited, reference) {
4545

4646
let i, len;
4747

48-
let key, value, index, result, resultCopy, ref;
48+
let key, value, index, resultCopy, result, ref;
4949

5050
for (i = 0, len = keys.length; i < len; ++i) {
5151
key = keys[i];
@@ -56,8 +56,10 @@ function recursiveCopy(target, customizer, clone, visited, reference) {
5656
resultCopy = copy(value, customizer);
5757
result = (resultCopy !== null) ? resultCopy : value;
5858

59-
visited.push(value);
60-
reference.push(result);
59+
if (value !== null && /^(?:function|object)$/.test(typeof value)) {
60+
visited.push(value);
61+
reference.push(result);
62+
}
6163
} else {
6264
// circular reference
6365
ref = reference[index];

test/index.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,48 @@ describe('deepcopy', function() {
295295
assert(+copiedSymbolObject[a] === +copiedSymbolObject[b]);
296296
});
297297

298+
it('can recursively copy from Object in Array', function() {
299+
const array = [
300+
{
301+
a: 1,
302+
b: 2,
303+
},
304+
{
305+
a: 1,
306+
b: 3,
307+
},
308+
];
309+
310+
const copiedArray = deepcopy(array);
311+
312+
assert(array !== copiedArray);
313+
assert(array[0].a === copiedArray[0].a);
314+
assert(array[0].b === copiedArray[0].b);
315+
assert(array[1].a === copiedArray[1].a);
316+
assert(array[1].b === copiedArray[1].b);
317+
});
318+
319+
it('can recursively copy from Array in Objct', function() {
320+
const object = {
321+
a: [
322+
1,
323+
2,
324+
],
325+
b: [
326+
1,
327+
3,
328+
],
329+
};
330+
331+
const copiedObject = deepcopy(object);
332+
333+
assert(object !== copiedObject);
334+
assert(object.a[0] === copiedObject.a[0]);
335+
assert(object.b[0] === copiedObject.b[0]);
336+
assert(object.a[1] === copiedObject.a[1]);
337+
assert(object.b[1] === copiedObject.b[1]);
338+
});
339+
298340
it('can copy Class from Array and Object by customizer', function() {
299341
function MyClass(number) {
300342
this.number = +number;

0 commit comments

Comments
 (0)