@hitachivantara/uikit-react-core
Version:
UI Kit Core React components.
18 lines (17 loc) • 596 B
JavaScript
//#region src/utils/deepMerge.ts
var isObject = (val) => val && typeof val === "object" && !Array.isArray(val);
function merge(target, source) {
Object.keys(source || {}).forEach((keyProp) => {
const key = keyProp;
if (isObject(target[key]) && isObject(source?.[key])) merge(target[key], source?.[key]);
else target[key] = source?.[key];
});
}
/** Merges recursively all keys of source into target returning the resulting object. */
function deepMerge(target, source) {
const result = structuredClone(target);
merge(result, source);
return result;
}
//#endregion
export { deepMerge };