tmp BROKEN settings

This commit is contained in:
Stef-00012 2025-01-29 19:33:13 +01:00
parent e04c40915a
commit 8d295153bc
No known key found for this signature in database
GPG key ID: 28BE9A9E4EF0E6BF
3 changed files with 888 additions and 1455 deletions

View file

@ -98,6 +98,36 @@ export function colorHash(str: string) {
return color;
}
function getNestedValue(object: Record<string, unknown>, path: string) {
return path.split('.').reduce((acc, part) => acc && acc[part], obj);
// biome-ignore lint/suspicious/noExplicitAny: can't know the type of the key
export function getObjectValue<T extends Record<string, any> = Record<string, any>>(obj: T, path: string): T[keyof T] | undefined {
const keys = path.split(".");
let result = obj;
for (const key of keys) {
if (result[key] === undefined) {
return undefined;
}
result = result[key];
}
return result as T[keyof T];
}
// biome-ignore lint/suspicious/noExplicitAny: can't know the type of the key
export function setObjectValue<T extends Record<string, any> = Record<string, any>>(obj: T, path: string, value: any): T {
const keys = path.split(".");
let result = obj;
for (let i = 0; i < keys.length - 1; i++) {
if (result[keys[i]] === undefined) {
(result as Record<string, unknown>)[keys[i]] = {};
}
result = result[keys[i]];
}
(result as Record<string, unknown>)[keys[keys.length - 1]] = value;
return result;
}