-
Notifications
You must be signed in to change notification settings - Fork 0
/
getConfigVariable.ts
42 lines (41 loc) · 1.61 KB
/
getConfigVariable.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import {IConfigLoader, IConfigParser} from './interfaces/';
import {ConfigOptions} from './ConfigOptions';
import {FormatParameters} from './lib/formatUtils';
import {getConfigObject} from './getConfigObject';
import {Loadable} from './types/Loadable';
/**
* get config variable from loaders
* @example
* // from "@avanio/variable-util-node"
* const fileEnv = new FileConfigLoader({fileName: './settings.json', type: 'json'}).getLoader;
*
* const port: Promise<string> = await getConfigVariable('PORT', [env(), fileEnv()], stringParser, '8080', {showValue: true});
* // with override key
* const port: Promise<string> = await getConfigVariable('PORT', [env('HTTP_PORT', fileEnv())], stringParser, '8080', {showValue: true});
*/
export async function getConfigVariable<Output>(
rootKey: string,
loaders: IConfigLoader[],
parser: IConfigParser<Output, unknown>,
defaultValueLoadable: Loadable<Output>,
params?: FormatParameters,
options?: ConfigOptions,
): Promise<Output>;
export async function getConfigVariable<Output>(
rootKey: string,
loaders: IConfigLoader[],
parser: IConfigParser<Output, unknown>,
defaultValueLoadable?: Loadable<Output> | undefined,
params?: FormatParameters,
options?: ConfigOptions,
): Promise<Output | undefined>;
export async function getConfigVariable<Output>(
rootKey: string,
loaders: IConfigLoader[],
parser: IConfigParser<Output, unknown>,
defaultValueLoadable?: Loadable<Output> | undefined,
params?: FormatParameters,
options?: ConfigOptions,
): Promise<Output | undefined> {
return (await getConfigObject(rootKey, loaders, parser, defaultValueLoadable, params, options))?.value;
}