feat(config): add getConfig method

This commit is contained in:
ItzCrazyKns
2025-10-13 21:58:30 +05:30
parent 387da5dbdd
commit e7fbab12ed

View File

@@ -68,11 +68,11 @@ class ConfigManager {
} }
} }
this.currentConfig = this.migrateConfigNeeded(this.currentConfig); this.currentConfig = this.migrateConfig(this.currentConfig);
} }
} }
private migrateConfigNeeded(config: Config): Config { private migrateConfig(config: Config): Config {
/* TODO: Add migrations */ /* TODO: Add migrations */
return config; return config;
} }
@@ -132,6 +132,22 @@ class ConfigManager {
this.saveConfig(); this.saveConfig();
} }
public getConfig(key: string, defaultValue?: any): any {
const nested = key.split('.');
let obj: any = this.currentConfig;
for (let i = 0; i < nested.length; i++) {
const part = nested[i];
if (obj == null) return defaultValue;
obj = obj[part];
} }
new ConfigManager(); return obj === undefined ? defaultValue : obj;
}
}
const configManager = new ConfigManager();
export default configManager