Something went wrong. Try again.
Starship Simulator Controls thoriumsim.com
Something went wrong. Try again.
605 B · 24 lines
TypeScript
at develop
12345678910111213141516171819202122232425import { isObject } from "@thorium/typeguards/isObject";
/** * Deep merge two objects. * @param target * @param ...sources */export function mergeDeep<T>(target: T, ...sources: Partial<T>[]): T { if (!sources.length) return target; const source = sources.shift();
if (isObject(target) && isObject(source)) { for (const key in source) { if (isObject(source[key])) { if (!target[key]) Object.assign(target, { [key]: {} }); mergeDeep(target[key], source[key] as any); } else { Object.assign(target, { [key]: source[key] }); } } }
return mergeDeep(target, ...sources);}