ChatGPT-Next-Web/app/utils/merge.ts

13 lines
419 B
TypeScript
Raw Normal View History

2023-05-18 16:59:04 +00:00
export function merge(target: any, source: any) {
Object.keys(source).forEach(function (key) {
2023-08-25 11:48:38 +00:00
if (
source.hasOwnProperty(key) && // Check if the property is not inherited
source[key] &&
typeof source[key] === "object" || key === "__proto__" || key === "constructor"
) {
2023-05-18 16:59:04 +00:00
merge((target[key] = target[key] || {}), source[key]);
return;
}
target[key] = source[key];
});
2023-08-25 11:48:38 +00:00
}