Comparing version 0.2.5 to 0.2.6
@@ -9,3 +9,5 @@ module.exports = function merge (target, src) { | ||
src.forEach(function(e, i) { | ||
if (typeof e === 'object') { | ||
if (typeof target[i] === 'undefined') { | ||
dst[i] = e | ||
} else if (typeof e === 'object') { | ||
dst[i] = merge(target[i], e) | ||
@@ -12,0 +14,0 @@ } else { |
@@ -5,3 +5,3 @@ { | ||
"description": "A library for deep (recursive) merging of Javascript objects", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"homepage": "https://github.com/nrf110/deepmerge", | ||
@@ -8,0 +8,0 @@ "repository": { |
@@ -194,3 +194,19 @@ var merge = require('../') | ||
test('should work on arrays of nested objects', function(t) { | ||
var target = [ | ||
{ key1: { subkey: 'one' }} | ||
] | ||
var src = [ | ||
{ key1: { subkey: 'two' }}, | ||
{ key2: { subkey: 'three' }} | ||
] | ||
var expected = [ | ||
{ key1: { subkey: 'two' }}, | ||
{ key2: { subkey: 'three' }} | ||
] | ||
t.deepEqual(merge(target, src), expected) | ||
t.end() | ||
}) |
7457
220