mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-24 09:25:15 +00:00
26 lines
723 B
JavaScript
26 lines
723 B
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
export function isPlainObject(item) {
|
|
return item && typeof item === 'object' && item.constructor === Object;
|
|
}
|
|
export default function deepmerge(target, source, options = {
|
|
clone: true
|
|
}) {
|
|
const output = options.clone ? _extends({}, target) : target;
|
|
|
|
if (isPlainObject(target) && isPlainObject(source)) {
|
|
Object.keys(source).forEach(key => {
|
|
// Avoid prototype pollution
|
|
if (key === '__proto__') {
|
|
return;
|
|
}
|
|
|
|
if (isPlainObject(source[key]) && key in target) {
|
|
output[key] = deepmerge(target[key], source[key], options);
|
|
} else {
|
|
output[key] = source[key];
|
|
}
|
|
});
|
|
}
|
|
|
|
return output;
|
|
} |