From e7fbab12edb53f573421cd6a87089b56b2c998cd Mon Sep 17 00:00:00 2001 From: ItzCrazyKns <95534749+ItzCrazyKns@users.noreply.github.com> Date: Mon, 13 Oct 2025 21:58:30 +0530 Subject: [PATCH] feat(config): add `getConfig` method --- src/lib/config/index.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/lib/config/index.ts b/src/lib/config/index.ts index e8c3b5d..79be5a7 100644 --- a/src/lib/config/index.ts +++ b/src/lib/config/index.ts @@ -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 */ return config; } @@ -132,6 +132,22 @@ class ConfigManager { 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]; + } + + return obj === undefined ? defaultValue : obj; + } } -new ConfigManager(); +const configManager = new ConfigManager(); + +export default configManager \ No newline at end of file