UNPKG

@foal/core

Version:

Full-featured Node.js framework, with no complexity

59 lines (58 loc) 2.3 kB
type ValueStringType = 'string' | 'number' | 'boolean' | 'boolean|string' | 'number|string' | 'any'; type ValueType<T extends ValueStringType> = T extends 'string' ? string : T extends 'number' ? number : T extends 'boolean' ? boolean : T extends 'boolean|string' ? boolean | string : T extends 'number|string' ? number | string : any; /** * Static class to access environment variables and configuration files. * * This class can also be used as a service. * * @export * @class Config */ export declare class Config { /** * Read the configuration value associated with the given key. Optionaly check its type. * * @static * @template T * @param {string} key - The configuration key. * @param {T} [type] - The expected type of the returned value. * @param {ValueType<T>} [defaultValue] - A default value if none is found. * @returns {ValueType<T>|undefined} The configuration value * @memberof Config */ static get<T extends ValueStringType>(key: string, type: T, defaultValue: ValueType<T>): ValueType<T>; static get<T extends ValueStringType>(key: string, type?: T): ValueType<T> | undefined; /** * Read the configuration value associated with the given key. Optionaly check its type. * * Throw an ConfigNotFoundError if no value is found. * * @static * @template T * @param {string} key - The configuration key. * @param {T} [type] - The expected type of the returned value. * @param {string} [msg] - The message of the ConfigNotFoundError if no value is found. * @returns {ValueType<T>} The configuration value. * @memberof Config */ static getOrThrow<T extends ValueStringType>(key: string, type?: T, msg?: string): ValueType<T>; /** * Clear the cache of the loaded files. * * @static * @memberof Config */ static clearCache(): void; static set(key: string, value: string | number | boolean): void; static remove(key: string): void; private static yaml; private static config; private static testConfig; private static readJSON; private static readYAML; private static readJS; private static readConfigValue; private static mergeDeep; private static getYAMLInstance; } export {};