UNPKG

nitropage

Version:

A free and open source, extensible visual page builder based on SolidStart.

20 lines (17 loc) 446 B
import { isPlainObject } from "es-toolkit"; 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; };