merge-options
Advanced tools
Comparing version 1.0.0 to 1.0.1
28
index.js
@@ -6,2 +6,9 @@ 'use strict'; | ||
const propIsEnumerable = Object.propertyIsEnumerable; | ||
const defineProperty = (obj, name, value) => Object.defineProperty(obj, name, { | ||
value, | ||
writable: true, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
const globalThis = this; | ||
@@ -51,3 +58,3 @@ const defaultMergeOpts = { | ||
getEnumerableOwnPropertyKeys(array).forEach(key => { | ||
result[key] = clone(array[key]); | ||
defineProperty(result, key, clone(array[key])); | ||
}); | ||
@@ -62,3 +69,3 @@ | ||
getEnumerableOwnPropertyKeys(obj).forEach(key => { | ||
result[key] = clone(obj[key]); | ||
defineProperty(result, key, clone(obj[key])); | ||
}); | ||
@@ -75,6 +82,7 @@ | ||
keys.forEach(key => { | ||
if (key in merged) { | ||
merged[key] = merge(merged[key], source[key], mergeOpts); | ||
// Do not recurse into prototype chain of merged | ||
if (key in merged && merged[key] !== Object.getPrototypeOf(merged)) { | ||
defineProperty(merged, key, merge(merged[key], source[key], mergeOpts)); | ||
} else { | ||
merged[key] = clone(source[key]); | ||
defineProperty(merged, key, clone(source[key])); | ||
} | ||
@@ -109,5 +117,5 @@ }); | ||
// Already cloned | ||
result[resultIndex++] = array[k]; | ||
defineProperty(result, resultIndex++, array[k]); | ||
} else { | ||
result[resultIndex++] = clone(array[k]); | ||
defineProperty(result, resultIndex++, clone(array[k])); | ||
} | ||
@@ -143,3 +151,3 @@ } | ||
const mergeOpts = merge(clone(defaultMergeOpts), (this !== globalThis && this) || {}, defaultMergeOpts); | ||
let merged = {}; | ||
let merged = {foobar: {}}; | ||
@@ -157,6 +165,6 @@ for (let i = 0; i < arguments.length; i++) { | ||
merged = merge(merged, option, mergeOpts); | ||
merged = merge(merged, {foobar: option}, mergeOpts); | ||
} | ||
return merged; | ||
return merged.foobar; | ||
}; |
{ | ||
"name": "merge-options", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Merge Option Objects", | ||
@@ -33,7 +33,7 @@ "license": "MIT", | ||
"devDependencies": { | ||
"ava": "^0.19", | ||
"coveralls": "^2.13", | ||
"nyc": "^10.3", | ||
"ava": "^0.25", | ||
"coveralls": "^3.0", | ||
"nyc": "^11.7", | ||
"rimraf": "^2.5", | ||
"xo": "^0.18" | ||
"xo": "^0.20" | ||
}, | ||
@@ -40,0 +40,0 @@ "dependencies": { |
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
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
9118
129