ace-diff
Version:
A diff/merging wrapper for Ace Editor built on google-diff-match-patch
31 lines (28 loc) • 679 B
JavaScript
/**
* Simple is object check.
* @param item
* @returns {boolean}
*/
function isObject(item) {
return (item && typeof item === 'object' && !Array.isArray(item) && item !== null);
}
/**
* Deep merge two objects.
* @param target
* @param source
*/
module.exports = function merge(target, source) {
if (isObject(target) && isObject(source)) {
Object.keys(source).forEach((key) => {
if (isObject(source[key])) {
if (!target[key] || !isObject(target[key])) {
target[key] = source[key];
}
merge(target[key], source[key]);
} else {
Object.assign(target, { [key]: source[key] });
}
});
}
return target;
};