mikroconf
Version:
A flexible, zero-dependency, type-safe configuration manager that just makes sense.
86 lines (83 loc) • 2.66 kB
text/typescript
import { MikroConfOptions } from './interfaces/index.mjs';
/**
* @description MikroConf is a simple but powerful configuration manager
* that handles CLI arguments, config files, and direct configuration with
* merging, parsing, and validation capabilities.
*
* @example
* import { MikroConf } from 'mikroconf';
*
* const config = new MikroConf({
* configFilePath: 'config.json',
* options: [
* { path: 'server.host', defaultValue: 'localhost' },
* { path: 'server.port', defaultValue: 3000 },
* { path: 'logging.level', defaultValue: 'info' },
* { path: 'debug', defaultValue: process.env.DEBUG === 'true' ? true : false }
* ]
* });
*
* const appConfig = config.get();
* console.log(appConfig);
*
* const port = config.getValue('server.port');
* const host = config.getValue('server.host');
* console.log(`Server will start at http://${host}:${port}`);
*/
declare class MikroConf {
private config;
private options;
private validators;
private autoValidate;
/**
* @description Creates a new MikroConf instance.
*/
constructor(options?: MikroConfOptions);
/**
* @description Deep merges two objects.
*/
private deepMerge;
/**
* @description Sets a value at a nested path in an object.
*/
private setValueAtPath;
/**
* @description Gets a value from a nested path in an object.
*/
private getValueAtPath;
/**
* @description Creates a configuration object by merging defaults, config file settings,
* explicit input, and CLI arguments.
*/
private createConfig;
/**
* @description Parses command line arguments into a configuration object based on defined options.
*/
private parseCliArgs;
/**
* @description Validates the configuration against defined validators.
*/
validate(): void;
/**
* @description Returns the complete configuration.
* @returns The configuration object.
*/
get<T = Record<string, any>>(): T;
/**
* @description Gets a specific configuration value by path.
* @param path The dot-notation path to the configuration value.
* @param defaultValue Optional default value if the path doesn't exist.
*/
getValue<T>(path: string, defaultValue?: T): T;
/**
* @description Sets a specific configuration value by path.
* @param path The dot-notation path to set.
* @param value The value to set.
*/
setValue(path: string, value: any): void;
/**
* @description Generates help text based on the defined options.
*/
getHelpText(): string;
}
export { MikroConf };