mirror of
https://github.com/trafficlunar/tomodachi-share.git
synced 2026-05-13 13:17:45 +00:00
18 lines
519 B
TypeScript
18 lines
519 B
TypeScript
export function deepMerge<T>(target: T, source: Partial<T>): T {
|
|
const output = structuredClone(target);
|
|
|
|
if (typeof source !== "object" || source === null) return output;
|
|
|
|
for (const key in source) {
|
|
const sourceValue = source[key];
|
|
const targetValue = (output as any)[key];
|
|
|
|
if (typeof sourceValue === "object" && sourceValue !== null && !Array.isArray(sourceValue)) {
|
|
(output as any)[key] = deepMerge(targetValue, sourceValue);
|
|
} else {
|
|
(output as any)[key] = sourceValue;
|
|
}
|
|
}
|
|
|
|
return output;
|
|
}
|