@avanio/variable-util
    Preparing search index...

    Class ConfigMap<Data>

    ConfigMap

    type ConfigEnv = {
    PORT: number;
    HOST: string;
    DEBUG: boolean;
    URL: URL;
    };
    const env = new EnvConfigLoader();
    const config = new ConfigMap<ConfigEnv>(
    {
    DEBUG: {defaultValue: false, parser: booleanParser()},
    HOST: {defaultValue: 'localhost', parser: stringParser()},
    PORT: {defaultValue: 3000, parser: integerParser()},
    URL: {defaultValue: new URL('http://localhost:3000'), parser: new UrlParser({urlSanitize: true})},
    },
    [env],
    );
    console.log('port', await config.get('PORT'));

    v1.1.0

    Type Parameters

    • Data extends Record<string, unknown>

      type of config map

    Implements

    • ISetOptionalLogger
    Index

    Constructors

    Methods

    • get env value as string from config map

      Type Parameters

      • Key extends string | number | symbol = keyof Data

      Parameters

      • key: Key

        key of config map

      • OptionalencodeOptions: EncodeOptions

        optional encode options

      Returns Promise<undefined extends Data[Key] ? string | undefined : string>

      Promise of string value or undefined

      const port: string = await config.getString('PORT');
      
    • get env value as string from config map as Result

      Type Parameters

      • Key extends string | number | symbol = keyof Data

      Parameters

      • key: Key

        key of config map

      • OptionalencodeOptions: EncodeOptions

        optional encode options

      Returns Promise<IResult<undefined extends Data[Key] ? string | undefined : string>>

      Result Promise of string value or undefined

      const port: Result<string> = await config.getStringResult('PORT');
      if (port.isOk()) {
      console.log('port', port.ok());
      }