Comparing version 1.1.1 to 1.2.0
@@ -1,3 +0,8 @@ | ||
# [1.1.1](https://github.com/KyleAMathews/deepmerge/releases/tag/v1.1.0) | ||
# [1.2.0](https://github.com/KyleAMathews/deepmerge/releases/tag/v1.2.0) | ||
- fix: an error that would be thrown when an array would be merged onto a truthy non-array value: pull request [46](https://github.com/KyleAMathews/deepmerge/pull/46) | ||
- feature: the ability to clone: Issue [28](https://github.com/KyleAMathews/deepmerge/issues/28), pull requests [44](https://github.com/KyleAMathews/deepmerge/pull/44) and [48](https://github.com/KyleAMathews/deepmerge/pull/48) | ||
# [1.1.1](https://github.com/KyleAMathews/deepmerge/releases/tag/v1.1.1) | ||
- fix an issue where an error was thrown when merging an array onto a non-array: [Pull request 46](https://github.com/KyleAMathews/deepmerge/pull/46) | ||
@@ -4,0 +9,0 @@ |
19
index.js
@@ -19,2 +19,11 @@ (function (root, factory) { | ||
function emptyTarget(val) { | ||
return Array.isArray(val) ? [] : {} | ||
} | ||
function cloneIfNecessary(value, optionsArgument) { | ||
var clone = optionsArgument && optionsArgument.clone === true | ||
return (clone && isMergeableObject(value)) ? deepmerge(emptyTarget(value), value, optionsArgument) : value | ||
} | ||
function defaultArrayMerge(target, source, optionsArgument) { | ||
@@ -24,7 +33,7 @@ var destination = target.slice() | ||
if (typeof destination[i] === 'undefined') { | ||
destination[i] = e | ||
destination[i] = cloneIfNecessary(e, optionsArgument) | ||
} else if (isMergeableObject(e)) { | ||
destination[i] = deepmerge(target[i], e, optionsArgument) | ||
} else if (target.indexOf(e) === -1) { | ||
destination.push(e) | ||
destination.push(cloneIfNecessary(e, optionsArgument)) | ||
} | ||
@@ -39,3 +48,3 @@ }) | ||
Object.keys(target).forEach(function (key) { | ||
destination[key] = target[key] | ||
destination[key] = cloneIfNecessary(target[key], optionsArgument) | ||
}) | ||
@@ -45,3 +54,3 @@ } | ||
if (!isMergeableObject(source[key]) || !target[key]) { | ||
destination[key] = source[key] | ||
destination[key] = cloneIfNecessary(source[key], optionsArgument) | ||
} else { | ||
@@ -60,3 +69,3 @@ destination[key] = deepmerge(target[key], source[key], optionsArgument) | ||
if (array) { | ||
return Array.isArray(target) ? arrayMerge(target, source, optionsArgument) : source.slice() | ||
return Array.isArray(target) ? arrayMerge(target, source, optionsArgument) : cloneIfNecessary(source, optionsArgument) | ||
} else { | ||
@@ -63,0 +72,0 @@ return mergeObject(target, source, optionsArgument) |
@@ -13,3 +13,3 @@ { | ||
], | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"homepage": "https://github.com/KyleAMathews/deepmerge", | ||
@@ -16,0 +16,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
84
8533
7
78
1