Comparing version 0.2.10 to 1.0.0
16
index.js
@@ -11,2 +11,11 @@ (function (root, factory) { | ||
function isMergeableObject(val) { | ||
var nonNullObject = val && typeof val === 'object' | ||
return nonNullObject | ||
&& Object.prototype.toString.call(val) !== '[object RegExp]' | ||
&& Object.prototype.toString.call(val) !== '[object Date]' | ||
} | ||
return function deepmerge(target, src) { | ||
@@ -31,3 +40,3 @@ var array = Array.isArray(src); | ||
} else { | ||
if (target && typeof target === 'object') { | ||
if (isMergeableObject(target)) { | ||
Object.keys(target).forEach(function (key) { | ||
@@ -38,6 +47,5 @@ dst[key] = target[key]; | ||
Object.keys(src).forEach(function (key) { | ||
if (typeof src[key] !== 'object' || !src[key]) { | ||
if (!isMergeableObject(src[key])) { | ||
dst[key] = src[key]; | ||
} | ||
else { | ||
} else { | ||
if (!target[key]) { | ||
@@ -44,0 +52,0 @@ dst[key] = src[key]; |
@@ -5,3 +5,3 @@ { | ||
"description": "A library for deep (recursive) merging of Javascript objects", | ||
"version": "0.2.10", | ||
"version": "1.0.0", | ||
"homepage": "https://github.com/nrf110/deepmerge", | ||
@@ -8,0 +8,0 @@ "repository": { |
@@ -223,1 +223,32 @@ var merge = require('../') | ||
}) | ||
test('should treat regular expressions like primitive values', function (t) { | ||
var target = { key1: /abc/ } | ||
var src = { key1: /efg/ } | ||
var expected = { key1: /efg/ } | ||
t.deepEqual(merge(target, src), expected) | ||
t.deepEqual(merge(target, src).key1.test('efg'), true) | ||
t.end() | ||
}) | ||
test('should treat dates like primitives', function(t) { | ||
var monday = new Date('2016-09-27T01:08:12.761Z') | ||
var tuesday = new Date('2016-09-28T01:18:12.761Z') | ||
var target = { | ||
key: monday | ||
} | ||
var source = { | ||
key: tuesday | ||
} | ||
var expected = { | ||
key: tuesday | ||
} | ||
var actual = merge(target, source) | ||
t.deepEqual(actual, expected) | ||
t.equal(actual.key.valueOf(), tuesday.valueOf()) | ||
t.end() | ||
}) |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
10695
269
0