@npio/internals
Version:
A free visual website editor, powered with your own SolidJS components.
20 lines (17 loc) • 446 B
text/typescript
import { isPlainObject } from "moderndash";
export const merge = <T extends {}, S extends {}>(
target: T,
...sources: S[]
): T & S => {
const copy = { ...target } as any;
for (const source of sources) {
for (let [k, v] of Object.entries(source)) {
if (v == null) continue;
if (isPlainObject(v)) {
v = merge(isPlainObject(copy[k]) ? copy[k] : {}, v);
}
copy[k] = v as any;
}
}
return copy;
};