@synergy-design-system/components
Version:
This package provides the base of the Synergy Design System as native web components. It uses [lit](https://www.lit.dev) and parts of [shoelace](https://shoelace.style/). Synergy officially supports the latest two versions of all major browsers (as define
26 lines (22 loc) • 737 B
JavaScript
/**
* Creates a deep merged clone of the given objects.
* @param {...any} objects The objects to merge
* @returns {object} The new object
*/
export const mergeDeep = (...objects) => {
const isObject = obj => obj && typeof obj === 'object';
return objects.reduce((acc, obj) => {
Object.keys(obj).forEach(key => {
const accValue = acc[key];
const objValue = obj[key];
if (Array.isArray(objValue)) {
acc[key] = Array.isArray(accValue) ? [...accValue, ...objValue] : [...objValue];
} else if (isObject(objValue)) {
acc[key] = isObject(accValue) ? mergeDeep(accValue, objValue) : { ...objValue };
} else {
acc[key] = objValue;
}
});
return acc;
}, {});
};