Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaredwilli/1de0567035e393a7a996a7624adda387 to your computer and use it in GitHub Desktop.
Save jaredwilli/1de0567035e393a7a996a7624adda387 to your computer and use it in GitHub Desktop.
mergeDeep
/**
* mergeDeep
*
* @param {*} target object to merge data into
* @param {*} source object containing the data to merge
*/
export function deepMerge(target, source) {
let output = Object.assign({}, target);
if (isObject(target) || isObject(source)) {
Object.keys(source).forEach((key) => {
if (isObject(source[key])) {
if (!(key in target)) {
Object.assign(output, {
[key]: source[key]
});
} else {
output[key] = deepMerge(target[key], source[key]);
}
} else {
Object.assign(output, {
[key]: source[key]
});
}
});
}
return output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment