f21db5cb01
Co-authored-by: vee <vendicated@riseup.net>
24 lines
622 B
TypeScript
24 lines
622 B
TypeScript
/*
|
|
* Vencord, a Discord client mod
|
|
* Copyright (c) 2024 Vendicated and contributors
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
*/
|
|
|
|
/**
|
|
* Recursively merges defaults into an object and returns the same object
|
|
* @param obj Object
|
|
* @param defaults Defaults
|
|
* @returns obj
|
|
*/
|
|
export function mergeDefaults<T>(obj: T, defaults: T): T {
|
|
for (const key in defaults) {
|
|
const v = defaults[key];
|
|
if (typeof v === "object" && !Array.isArray(v)) {
|
|
obj[key] ??= {} as any;
|
|
mergeDefaults(obj[key], v);
|
|
} else {
|
|
obj[key] ??= v;
|
|
}
|
|
}
|
|
return obj;
|
|
}
|