Add merge function from @eartharoid

Co-authored-by: Isaac Saunders <contact@eartharoid.me>
This commit is contained in:
David Ralph
2021-02-28 12:51:26 +00:00
parent d42f69ae95
commit 5836849ab9
3 changed files with 21 additions and 3 deletions

View File

@@ -0,0 +1,19 @@
export default function deepmerge(...objects) {
let target = {};
const merge = (obj) => {
for (let prop in obj) {
if (obj.hasOwnProperty(prop)) {
if (typeof obj[prop] === 'object') {
target[prop] = deepmerge(target[prop], obj[prop]);
} else {
target[prop] = obj[prop];
}
}
}
};
objects.forEach(object => merge(object));
return target;
}