Comparing version 0.2.4 to 0.2.5
@@ -23,3 +23,2 @@ module.exports = function merge (target, src) { | ||
} | ||
Object.keys(src).forEach(function (key) { | ||
@@ -30,3 +29,7 @@ if (typeof src[key] !== 'object' || !src[key]) { | ||
else { | ||
dst[key] = merge(target[key], src[key]) | ||
if (!target[key]) { | ||
dst[key] = src[key] | ||
} else { | ||
dst[key] = merge(target[key], src[key]) | ||
} | ||
} | ||
@@ -33,0 +36,0 @@ }) |
@@ -5,3 +5,3 @@ { | ||
"description": "A library for deep (recursive) merging of Javascript objects", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"homepage": "https://github.com/nrf110/deepmerge", | ||
@@ -8,0 +8,0 @@ "repository": { |
@@ -87,2 +87,24 @@ var merge = require('../') | ||
test('should add nested object in target', function(t) { | ||
var src = { | ||
"b": { | ||
"c": {} | ||
} | ||
} | ||
var target = { | ||
"a": {} | ||
} | ||
var expected = { | ||
"a": {}, | ||
"b": { | ||
"c": {} | ||
} | ||
} | ||
t.deepEqual(merge(target, src), expected) | ||
t.end() | ||
}) | ||
test('should replace object with simple key in target', function (t) { | ||
@@ -89,0 +111,0 @@ var src = { key1: 'value1' } |
6992
203