• Get a value with the given specification. The standard transformers available are 'str', 'num' and 'bool'. You can also pass a custom transformer function (see TransformerFunc) as well a validator function or array of validator functions. (Import the Validators library from this library to explore the bundled validators or write your own by implementing ValidatorFunc.)

    The most common usage of this will be the following (see more examples below for advanced usage in context):

    // Get a possibly-undefined string from the SOME_VAR environment variable
    configValue('SOME_VAR');

    // Get a string with a default value of 'some default' from the SOME_VAR environment variable
    configValue('SOME_VAR', 'some default');

    // Get a possibly-undefined number from the SOME_VAR environment variable
    configValue('SOME_VAR', 'num');

    // Get a number with a default value of 5 from SOME_VAR
    configValue('SOME_VAR', 'num', 5);

    // Get a required string from SOME_VAR with no default (note: `REQUIRED` is a special imported symbol from this
    // library)
    configValue('SOME_VAR', REQUIRED);

    // Get a required number from SOME_VAR with no default
    configValue('SOME_VAR', 'num', REQUIRED);

    Parameters

    • envVarName: string | string[]

    Returns undefined | string

    Example

    Following is a more real-world example of how this might all be used in context

    const configDef = {
    port: configValue('PORT', 'num', 3000),
    hiPort: configValue('PORT', 'num', 30_000, hiport),
    host: configValue('HOST', 'str', 'http://localhost', hostValidator),
    db: {
    url: configValue('DB_URL', 'str', 'postgres://postgres@localhost:5432'),
    migrateOnStart: configValue('DB_MIGRATE_ON_START', 'bool', false),
    },
    signatureSecret: configValue('SIGNATURE_SECRET', 'str', [required, exactLength(32), hex]),
    secondsToWaitForThing: configValue('SECONDS_TO_WAIT_FOR_THING', 'num', required),
    }

    export const config = validate(configDef);

    NOTE: This function uses any-casts. This is because the underlying transformer functions are overloaded and require either one argument configuration or the other, which gets messy in a function like this. Since this function is itself properly overloaded, it's safe to use any-casts to solve this here.

  • Get a value with the given specification. The standard transformers available are 'str', 'num' and 'bool'. You can also pass a custom transformer function (see TransformerFunc) as well a validator function or array of validator functions. (Import the Validators library from this library to explore the bundled validators or write your own by implementing ValidatorFunc.)

    The most common usage of this will be the following (see more examples below for advanced usage in context):

    // Get a possibly-undefined string from the SOME_VAR environment variable
    configValue('SOME_VAR');

    // Get a string with a default value of 'some default' from the SOME_VAR environment variable
    configValue('SOME_VAR', 'some default');

    // Get a possibly-undefined number from the SOME_VAR environment variable
    configValue('SOME_VAR', 'num');

    // Get a number with a default value of 5 from SOME_VAR
    configValue('SOME_VAR', 'num', 5);

    // Get a required string from SOME_VAR with no default (note: `REQUIRED` is a special imported symbol from this
    // library)
    configValue('SOME_VAR', REQUIRED);

    // Get a required number from SOME_VAR with no default
    configValue('SOME_VAR', 'num', REQUIRED);

    Parameters

    • envVarName: string | string[]
    • defaultOrRequired: DefOrReq<string>

    Returns string

    Example

    Following is a more real-world example of how this might all be used in context

    const configDef = {
    port: configValue('PORT', 'num', 3000),
    hiPort: configValue('PORT', 'num', 30_000, hiport),
    host: configValue('HOST', 'str', 'http://localhost', hostValidator),
    db: {
    url: configValue('DB_URL', 'str', 'postgres://postgres@localhost:5432'),
    migrateOnStart: configValue('DB_MIGRATE_ON_START', 'bool', false),
    },
    signatureSecret: configValue('SIGNATURE_SECRET', 'str', [required, exactLength(32), hex]),
    secondsToWaitForThing: configValue('SECONDS_TO_WAIT_FOR_THING', 'num', required),
    }

    export const config = validate(configDef);

    NOTE: This function uses any-casts. This is because the underlying transformer functions are overloaded and require either one argument configuration or the other, which gets messy in a function like this. Since this function is itself properly overloaded, it's safe to use any-casts to solve this here.

  • Get a value with the given specification. The standard transformers available are 'str', 'num' and 'bool'. You can also pass a custom transformer function (see TransformerFunc) as well a validator function or array of validator functions. (Import the Validators library from this library to explore the bundled validators or write your own by implementing ValidatorFunc.)

    The most common usage of this will be the following (see more examples below for advanced usage in context):

    // Get a possibly-undefined string from the SOME_VAR environment variable
    configValue('SOME_VAR');

    // Get a string with a default value of 'some default' from the SOME_VAR environment variable
    configValue('SOME_VAR', 'some default');

    // Get a possibly-undefined number from the SOME_VAR environment variable
    configValue('SOME_VAR', 'num');

    // Get a number with a default value of 5 from SOME_VAR
    configValue('SOME_VAR', 'num', 5);

    // Get a required string from SOME_VAR with no default (note: `REQUIRED` is a special imported symbol from this
    // library)
    configValue('SOME_VAR', REQUIRED);

    // Get a required number from SOME_VAR with no default
    configValue('SOME_VAR', 'num', REQUIRED);

    Parameters

    • envVarName: string | string[]
    • validator: ValidatorArg<string>

    Returns undefined | string

    Example

    Following is a more real-world example of how this might all be used in context

    const configDef = {
    port: configValue('PORT', 'num', 3000),
    hiPort: configValue('PORT', 'num', 30_000, hiport),
    host: configValue('HOST', 'str', 'http://localhost', hostValidator),
    db: {
    url: configValue('DB_URL', 'str', 'postgres://postgres@localhost:5432'),
    migrateOnStart: configValue('DB_MIGRATE_ON_START', 'bool', false),
    },
    signatureSecret: configValue('SIGNATURE_SECRET', 'str', [required, exactLength(32), hex]),
    secondsToWaitForThing: configValue('SECONDS_TO_WAIT_FOR_THING', 'num', required),
    }

    export const config = validate(configDef);

    NOTE: This function uses any-casts. This is because the underlying transformer functions are overloaded and require either one argument configuration or the other, which gets messy in a function like this. Since this function is itself properly overloaded, it's safe to use any-casts to solve this here.

  • Get a value with the given specification. The standard transformers available are 'str', 'num' and 'bool'. You can also pass a custom transformer function (see TransformerFunc) as well a validator function or array of validator functions. (Import the Validators library from this library to explore the bundled validators or write your own by implementing ValidatorFunc.)

    The most common usage of this will be the following (see more examples below for advanced usage in context):

    // Get a possibly-undefined string from the SOME_VAR environment variable
    configValue('SOME_VAR');

    // Get a string with a default value of 'some default' from the SOME_VAR environment variable
    configValue('SOME_VAR', 'some default');

    // Get a possibly-undefined number from the SOME_VAR environment variable
    configValue('SOME_VAR', 'num');

    // Get a number with a default value of 5 from SOME_VAR
    configValue('SOME_VAR', 'num', 5);

    // Get a required string from SOME_VAR with no default (note: `REQUIRED` is a special imported symbol from this
    // library)
    configValue('SOME_VAR', REQUIRED);

    // Get a required number from SOME_VAR with no default
    configValue('SOME_VAR', 'num', REQUIRED);

    Parameters

    • envVarName: string | string[]
    • required: typeof REQUIRED
    • validator: ValidatorArg<string>

    Returns string

    Example

    Following is a more real-world example of how this might all be used in context

    const configDef = {
    port: configValue('PORT', 'num', 3000),
    hiPort: configValue('PORT', 'num', 30_000, hiport),
    host: configValue('HOST', 'str', 'http://localhost', hostValidator),
    db: {
    url: configValue('DB_URL', 'str', 'postgres://postgres@localhost:5432'),
    migrateOnStart: configValue('DB_MIGRATE_ON_START', 'bool', false),
    },
    signatureSecret: configValue('SIGNATURE_SECRET', 'str', [required, exactLength(32), hex]),
    secondsToWaitForThing: configValue('SECONDS_TO_WAIT_FOR_THING', 'num', required),
    }

    export const config = validate(configDef);

    NOTE: This function uses any-casts. This is because the underlying transformer functions are overloaded and require either one argument configuration or the other, which gets messy in a function like this. Since this function is itself properly overloaded, it's safe to use any-casts to solve this here.

  • Get a value with the given specification. The standard transformers available are 'str', 'num' and 'bool'. You can also pass a custom transformer function (see TransformerFunc) as well a validator function or array of validator functions. (Import the Validators library from this library to explore the bundled validators or write your own by implementing ValidatorFunc.)

    The most common usage of this will be the following (see more examples below for advanced usage in context):

    // Get a possibly-undefined string from the SOME_VAR environment variable
    configValue('SOME_VAR');

    // Get a string with a default value of 'some default' from the SOME_VAR environment variable
    configValue('SOME_VAR', 'some default');

    // Get a possibly-undefined number from the SOME_VAR environment variable
    configValue('SOME_VAR', 'num');

    // Get a number with a default value of 5 from SOME_VAR
    configValue('SOME_VAR', 'num', 5);

    // Get a required string from SOME_VAR with no default (note: `REQUIRED` is a special imported symbol from this
    // library)
    configValue('SOME_VAR', REQUIRED);

    // Get a required number from SOME_VAR with no default
    configValue('SOME_VAR', 'num', REQUIRED);

    Parameters

    • envVarName: string | string[]
    • defaultValue: string
    • validator: ValidatorArg<string>

    Returns string

    Example

    Following is a more real-world example of how this might all be used in context

    const configDef = {
    port: configValue('PORT', 'num', 3000),
    hiPort: configValue('PORT', 'num', 30_000, hiport),
    host: configValue('HOST', 'str', 'http://localhost', hostValidator),
    db: {
    url: configValue('DB_URL', 'str', 'postgres://postgres@localhost:5432'),
    migrateOnStart: configValue('DB_MIGRATE_ON_START', 'bool', false),
    },
    signatureSecret: configValue('SIGNATURE_SECRET', 'str', [required, exactLength(32), hex]),
    secondsToWaitForThing: configValue('SECONDS_TO_WAIT_FOR_THING', 'num', required),
    }

    export const config = validate(configDef);

    NOTE: This function uses any-casts. This is because the underlying transformer functions are overloaded and require either one argument configuration or the other, which gets messy in a function like this. Since this function is itself properly overloaded, it's safe to use any-casts to solve this here.

  • Get a value with the given specification. The standard transformers available are 'str', 'num' and 'bool'. You can also pass a custom transformer function (see TransformerFunc) as well a validator function or array of validator functions. (Import the Validators library from this library to explore the bundled validators or write your own by implementing ValidatorFunc.)

    The most common usage of this will be the following (see more examples below for advanced usage in context):

    // Get a possibly-undefined string from the SOME_VAR environment variable
    configValue('SOME_VAR');

    // Get a string with a default value of 'some default' from the SOME_VAR environment variable
    configValue('SOME_VAR', 'some default');

    // Get a possibly-undefined number from the SOME_VAR environment variable
    configValue('SOME_VAR', 'num');

    // Get a number with a default value of 5 from SOME_VAR
    configValue('SOME_VAR', 'num', 5);

    // Get a required string from SOME_VAR with no default (note: `REQUIRED` is a special imported symbol from this
    // library)
    configValue('SOME_VAR', REQUIRED);

    // Get a required number from SOME_VAR with no default
    configValue('SOME_VAR', 'num', REQUIRED);

    Parameters

    • envVarName: string | string[]
    • t: "str"

    Returns undefined | string

    Example

    Following is a more real-world example of how this might all be used in context

    const configDef = {
    port: configValue('PORT', 'num', 3000),
    hiPort: configValue('PORT', 'num', 30_000, hiport),
    host: configValue('HOST', 'str', 'http://localhost', hostValidator),
    db: {
    url: configValue('DB_URL', 'str', 'postgres://postgres@localhost:5432'),
    migrateOnStart: configValue('DB_MIGRATE_ON_START', 'bool', false),
    },
    signatureSecret: configValue('SIGNATURE_SECRET', 'str', [required, exactLength(32), hex]),
    secondsToWaitForThing: configValue('SECONDS_TO_WAIT_FOR_THING', 'num', required),
    }

    export const config = validate(configDef);

    NOTE: This function uses any-casts. This is because the underlying transformer functions are overloaded and require either one argument configuration or the other, which gets messy in a function like this. Since this function is itself properly overloaded, it's safe to use any-casts to solve this here.

  • Get a value with the given specification. The standard transformers available are 'str', 'num' and 'bool'. You can also pass a custom transformer function (see TransformerFunc) as well a validator function or array of validator functions. (Import the Validators library from this library to explore the bundled validators or write your own by implementing ValidatorFunc.)

    The most common usage of this will be the following (see more examples below for advanced usage in context):

    // Get a possibly-undefined string from the SOME_VAR environment variable
    configValue('SOME_VAR');

    // Get a string with a default value of 'some default' from the SOME_VAR environment variable
    configValue('SOME_VAR', 'some default');

    // Get a possibly-undefined number from the SOME_VAR environment variable
    configValue('SOME_VAR', 'num');

    // Get a number with a default value of 5 from SOME_VAR
    configValue('SOME_VAR', 'num', 5);

    // Get a required string from SOME_VAR with no default (note: `REQUIRED` is a special imported symbol from this
    // library)
    configValue('SOME_VAR', REQUIRED);

    // Get a required number from SOME_VAR with no default
    configValue('SOME_VAR', 'num', REQUIRED);

    Parameters

    • envVarName: string | string[]
    • t: "str"
    • defaultOrRequired: DefOrReq<string>

    Returns string

    Example

    Following is a more real-world example of how this might all be used in context

    const configDef = {
    port: configValue('PORT', 'num', 3000),
    hiPort: configValue('PORT', 'num', 30_000, hiport),
    host: configValue('HOST', 'str', 'http://localhost', hostValidator),
    db: {
    url: configValue('DB_URL', 'str', 'postgres://postgres@localhost:5432'),
    migrateOnStart: configValue('DB_MIGRATE_ON_START', 'bool', false),
    },
    signatureSecret: configValue('SIGNATURE_SECRET', 'str', [required, exactLength(32), hex]),
    secondsToWaitForThing: configValue('SECONDS_TO_WAIT_FOR_THING', 'num', required),
    }

    export const config = validate(configDef);

    NOTE: This function uses any-casts. This is because the underlying transformer functions are overloaded and require either one argument configuration or the other, which gets messy in a function like this. Since this function is itself properly overloaded, it's safe to use any-casts to solve this here.

  • Get a value with the given specification. The standard transformers available are 'str', 'num' and 'bool'. You can also pass a custom transformer function (see TransformerFunc) as well a validator function or array of validator functions. (Import the Validators library from this library to explore the bundled validators or write your own by implementing ValidatorFunc.)

    The most common usage of this will be the following (see more examples below for advanced usage in context):

    // Get a possibly-undefined string from the SOME_VAR environment variable
    configValue('SOME_VAR');

    // Get a string with a default value of 'some default' from the SOME_VAR environment variable
    configValue('SOME_VAR', 'some default');

    // Get a possibly-undefined number from the SOME_VAR environment variable
    configValue('SOME_VAR', 'num');

    // Get a number with a default value of 5 from SOME_VAR
    configValue('SOME_VAR', 'num', 5);

    // Get a required string from SOME_VAR with no default (note: `REQUIRED` is a special imported symbol from this
    // library)
    configValue('SOME_VAR', REQUIRED);

    // Get a required number from SOME_VAR with no default
    configValue('SOME_VAR', 'num', REQUIRED);

    Parameters

    • envVarName: string | string[]
    • t: "str"
    • validator: ValidatorArg<string>

    Returns undefined | string

    Example

    Following is a more real-world example of how this might all be used in context

    const configDef = {
    port: configValue('PORT', 'num', 3000),
    hiPort: configValue('PORT', 'num', 30_000, hiport),
    host: configValue('HOST', 'str', 'http://localhost', hostValidator),
    db: {
    url: configValue('DB_URL', 'str', 'postgres://postgres@localhost:5432'),
    migrateOnStart: configValue('DB_MIGRATE_ON_START', 'bool', false),
    },
    signatureSecret: configValue('SIGNATURE_SECRET', 'str', [required, exactLength(32), hex]),
    secondsToWaitForThing: configValue('SECONDS_TO_WAIT_FOR_THING', 'num', required),
    }

    export const config = validate(configDef);

    NOTE: This function uses any-casts. This is because the underlying transformer functions are overloaded and require either one argument configuration or the other, which gets messy in a function like this. Since this function is itself properly overloaded, it's safe to use any-casts to solve this here.

  • Get a value with the given specification. The standard transformers available are 'str', 'num' and 'bool'. You can also pass a custom transformer function (see TransformerFunc) as well a validator function or array of validator functions. (Import the Validators library from this library to explore the bundled validators or write your own by implementing ValidatorFunc.)

    The most common usage of this will be the following (see more examples below for advanced usage in context):

    // Get a possibly-undefined string from the SOME_VAR environment variable
    configValue('SOME_VAR');

    // Get a string with a default value of 'some default' from the SOME_VAR environment variable
    configValue('SOME_VAR', 'some default');

    // Get a possibly-undefined number from the SOME_VAR environment variable
    configValue('SOME_VAR', 'num');

    // Get a number with a default value of 5 from SOME_VAR
    configValue('SOME_VAR', 'num', 5);

    // Get a required string from SOME_VAR with no default (note: `REQUIRED` is a special imported symbol from this
    // library)
    configValue('SOME_VAR', REQUIRED);

    // Get a required number from SOME_VAR with no default
    configValue('SOME_VAR', 'num', REQUIRED);

    Parameters

    • envVarName: string | string[]
    • t: "str"
    • required: typeof REQUIRED
    • validator: ValidatorArg<string>

    Returns string

    Example

    Following is a more real-world example of how this might all be used in context

    const configDef = {
    port: configValue('PORT', 'num', 3000),
    hiPort: configValue('PORT', 'num', 30_000, hiport),
    host: configValue('HOST', 'str', 'http://localhost', hostValidator),
    db: {
    url: configValue('DB_URL', 'str', 'postgres://postgres@localhost:5432'),
    migrateOnStart: configValue('DB_MIGRATE_ON_START', 'bool', false),
    },
    signatureSecret: configValue('SIGNATURE_SECRET', 'str', [required, exactLength(32), hex]),
    secondsToWaitForThing: configValue('SECONDS_TO_WAIT_FOR_THING', 'num', required),
    }

    export const config = validate(configDef);

    NOTE: This function uses any-casts. This is because the underlying transformer functions are overloaded and require either one argument configuration or the other, which gets messy in a function like this. Since this function is itself properly overloaded, it's safe to use any-casts to solve this here.

  • Get a value with the given specification. The standard transformers available are 'str', 'num' and 'bool'. You can also pass a custom transformer function (see TransformerFunc) as well a validator function or array of validator functions. (Import the Validators library from this library to explore the bundled validators or write your own by implementing ValidatorFunc.)

    The most common usage of this will be the following (see more examples below for advanced usage in context):

    // Get a possibly-undefined string from the SOME_VAR environment variable
    configValue('SOME_VAR');

    // Get a string with a default value of 'some default' from the SOME_VAR environment variable
    configValue('SOME_VAR', 'some default');

    // Get a possibly-undefined number from the SOME_VAR environment variable
    configValue('SOME_VAR', 'num');

    // Get a number with a default value of 5 from SOME_VAR
    configValue('SOME_VAR', 'num', 5);

    // Get a required string from SOME_VAR with no default (note: `REQUIRED` is a special imported symbol from this
    // library)
    configValue('SOME_VAR', REQUIRED);

    // Get a required number from SOME_VAR with no default
    configValue('SOME_VAR', 'num', REQUIRED);

    Parameters

    • envVarName: string | string[]
    • t: "str"
    • defaultValue: string
    • validator: ValidatorArg<string>

    Returns string

    Example

    Following is a more real-world example of how this might all be used in context

    const configDef = {
    port: configValue('PORT', 'num', 3000),
    hiPort: configValue('PORT', 'num', 30_000, hiport),
    host: configValue('HOST', 'str', 'http://localhost', hostValidator),
    db: {
    url: configValue('DB_URL', 'str', 'postgres://postgres@localhost:5432'),
    migrateOnStart: configValue('DB_MIGRATE_ON_START', 'bool', false),
    },
    signatureSecret: configValue('SIGNATURE_SECRET', 'str', [required, exactLength(32), hex]),
    secondsToWaitForThing: configValue('SECONDS_TO_WAIT_FOR_THING', 'num', required),
    }

    export const config = validate(configDef);

    NOTE: This function uses any-casts. This is because the underlying transformer functions are overloaded and require either one argument configuration or the other, which gets messy in a function like this. Since this function is itself properly overloaded, it's safe to use any-casts to solve this here.

  • Get a value with the given specification. The standard transformers available are 'str', 'num' and 'bool'. You can also pass a custom transformer function (see TransformerFunc) as well a validator function or array of validator functions. (Import the Validators library from this library to explore the bundled validators or write your own by implementing ValidatorFunc.)

    The most common usage of this will be the following (see more examples below for advanced usage in context):

    // Get a possibly-undefined string from the SOME_VAR environment variable
    configValue('SOME_VAR');

    // Get a string with a default value of 'some default' from the SOME_VAR environment variable
    configValue('SOME_VAR', 'some default');

    // Get a possibly-undefined number from the SOME_VAR environment variable
    configValue('SOME_VAR', 'num');

    // Get a number with a default value of 5 from SOME_VAR
    configValue('SOME_VAR', 'num', 5);

    // Get a required string from SOME_VAR with no default (note: `REQUIRED` is a special imported symbol from this
    // library)
    configValue('SOME_VAR', REQUIRED);

    // Get a required number from SOME_VAR with no default
    configValue('SOME_VAR', 'num', REQUIRED);

    Parameters

    • envVarName: string | string[]
    • t: "num"

    Returns undefined | number | `::ERROR::${string}`

    Example

    Following is a more real-world example of how this might all be used in context

    const configDef = {
    port: configValue('PORT', 'num', 3000),
    hiPort: configValue('PORT', 'num', 30_000, hiport),
    host: configValue('HOST', 'str', 'http://localhost', hostValidator),
    db: {
    url: configValue('DB_URL', 'str', 'postgres://postgres@localhost:5432'),
    migrateOnStart: configValue('DB_MIGRATE_ON_START', 'bool', false),
    },
    signatureSecret: configValue('SIGNATURE_SECRET', 'str', [required, exactLength(32), hex]),
    secondsToWaitForThing: configValue('SECONDS_TO_WAIT_FOR_THING', 'num', required),
    }

    export const config = validate(configDef);

    NOTE: This function uses any-casts. This is because the underlying transformer functions are overloaded and require either one argument configuration or the other, which gets messy in a function like this. Since this function is itself properly overloaded, it's safe to use any-casts to solve this here.

  • Get a value with the given specification. The standard transformers available are 'str', 'num' and 'bool'. You can also pass a custom transformer function (see TransformerFunc) as well a validator function or array of validator functions. (Import the Validators library from this library to explore the bundled validators or write your own by implementing ValidatorFunc.)

    The most common usage of this will be the following (see more examples below for advanced usage in context):

    // Get a possibly-undefined string from the SOME_VAR environment variable
    configValue('SOME_VAR');

    // Get a string with a default value of 'some default' from the SOME_VAR environment variable
    configValue('SOME_VAR', 'some default');

    // Get a possibly-undefined number from the SOME_VAR environment variable
    configValue('SOME_VAR', 'num');

    // Get a number with a default value of 5 from SOME_VAR
    configValue('SOME_VAR', 'num', 5);

    // Get a required string from SOME_VAR with no default (note: `REQUIRED` is a special imported symbol from this
    // library)
    configValue('SOME_VAR', REQUIRED);

    // Get a required number from SOME_VAR with no default
    configValue('SOME_VAR', 'num', REQUIRED);

    Parameters

    • envVarName: string | string[]
    • t: "num"
    • defaultOrRequired: DefOrReq<number>

    Returns number | `::ERROR::${string}`

    Example

    Following is a more real-world example of how this might all be used in context

    const configDef = {
    port: configValue('PORT', 'num', 3000),
    hiPort: configValue('PORT', 'num', 30_000, hiport),
    host: configValue('HOST', 'str', 'http://localhost', hostValidator),
    db: {
    url: configValue('DB_URL', 'str', 'postgres://postgres@localhost:5432'),
    migrateOnStart: configValue('DB_MIGRATE_ON_START', 'bool', false),
    },
    signatureSecret: configValue('SIGNATURE_SECRET', 'str', [required, exactLength(32), hex]),
    secondsToWaitForThing: configValue('SECONDS_TO_WAIT_FOR_THING', 'num', required),
    }

    export const config = validate(configDef);

    NOTE: This function uses any-casts. This is because the underlying transformer functions are overloaded and require either one argument configuration or the other, which gets messy in a function like this. Since this function is itself properly overloaded, it's safe to use any-casts to solve this here.

  • Get a value with the given specification. The standard transformers available are 'str', 'num' and 'bool'. You can also pass a custom transformer function (see TransformerFunc) as well a validator function or array of validator functions. (Import the Validators library from this library to explore the bundled validators or write your own by implementing ValidatorFunc.)

    The most common usage of this will be the following (see more examples below for advanced usage in context):

    // Get a possibly-undefined string from the SOME_VAR environment variable
    configValue('SOME_VAR');

    // Get a string with a default value of 'some default' from the SOME_VAR environment variable
    configValue('SOME_VAR', 'some default');

    // Get a possibly-undefined number from the SOME_VAR environment variable
    configValue('SOME_VAR', 'num');

    // Get a number with a default value of 5 from SOME_VAR
    configValue('SOME_VAR', 'num', 5);

    // Get a required string from SOME_VAR with no default (note: `REQUIRED` is a special imported symbol from this
    // library)
    configValue('SOME_VAR', REQUIRED);

    // Get a required number from SOME_VAR with no default
    configValue('SOME_VAR', 'num', REQUIRED);

    Parameters

    • envVarName: string | string[]
    • t: "num"
    • validator: ValidatorArg<number>

    Returns number | `::ERROR::${string}`

    Example

    Following is a more real-world example of how this might all be used in context

    const configDef = {
    port: configValue('PORT', 'num', 3000),
    hiPort: configValue('PORT', 'num', 30_000, hiport),
    host: configValue('HOST', 'str', 'http://localhost', hostValidator),
    db: {
    url: configValue('DB_URL', 'str', 'postgres://postgres@localhost:5432'),
    migrateOnStart: configValue('DB_MIGRATE_ON_START', 'bool', false),
    },
    signatureSecret: configValue('SIGNATURE_SECRET', 'str', [required, exactLength(32), hex]),
    secondsToWaitForThing: configValue('SECONDS_TO_WAIT_FOR_THING', 'num', required),
    }

    export const config = validate(configDef);

    NOTE: This function uses any-casts. This is because the underlying transformer functions are overloaded and require either one argument configuration or the other, which gets messy in a function like this. Since this function is itself properly overloaded, it's safe to use any-casts to solve this here.

  • Get a value with the given specification. The standard transformers available are 'str', 'num' and 'bool'. You can also pass a custom transformer function (see TransformerFunc) as well a validator function or array of validator functions. (Import the Validators library from this library to explore the bundled validators or write your own by implementing ValidatorFunc.)

    The most common usage of this will be the following (see more examples below for advanced usage in context):

    // Get a possibly-undefined string from the SOME_VAR environment variable
    configValue('SOME_VAR');

    // Get a string with a default value of 'some default' from the SOME_VAR environment variable
    configValue('SOME_VAR', 'some default');

    // Get a possibly-undefined number from the SOME_VAR environment variable
    configValue('SOME_VAR', 'num');

    // Get a number with a default value of 5 from SOME_VAR
    configValue('SOME_VAR', 'num', 5);

    // Get a required string from SOME_VAR with no default (note: `REQUIRED` is a special imported symbol from this
    // library)
    configValue('SOME_VAR', REQUIRED);

    // Get a required number from SOME_VAR with no default
    configValue('SOME_VAR', 'num', REQUIRED);

    Parameters

    • envVarName: string | string[]
    • t: "num"
    • required: typeof REQUIRED
    • validator: ValidatorArg<number>

    Returns number | `::ERROR::${string}`

    Example

    Following is a more real-world example of how this might all be used in context

    const configDef = {
    port: configValue('PORT', 'num', 3000),
    hiPort: configValue('PORT', 'num', 30_000, hiport),
    host: configValue('HOST', 'str', 'http://localhost', hostValidator),
    db: {
    url: configValue('DB_URL', 'str', 'postgres://postgres@localhost:5432'),
    migrateOnStart: configValue('DB_MIGRATE_ON_START', 'bool', false),
    },
    signatureSecret: configValue('SIGNATURE_SECRET', 'str', [required, exactLength(32), hex]),
    secondsToWaitForThing: configValue('SECONDS_TO_WAIT_FOR_THING', 'num', required),
    }

    export const config = validate(configDef);

    NOTE: This function uses any-casts. This is because the underlying transformer functions are overloaded and require either one argument configuration or the other, which gets messy in a function like this. Since this function is itself properly overloaded, it's safe to use any-casts to solve this here.

  • Get a value with the given specification. The standard transformers available are 'str', 'num' and 'bool'. You can also pass a custom transformer function (see TransformerFunc) as well a validator function or array of validator functions. (Import the Validators library from this library to explore the bundled validators or write your own by implementing ValidatorFunc.)

    The most common usage of this will be the following (see more examples below for advanced usage in context):

    // Get a possibly-undefined string from the SOME_VAR environment variable
    configValue('SOME_VAR');

    // Get a string with a default value of 'some default' from the SOME_VAR environment variable
    configValue('SOME_VAR', 'some default');

    // Get a possibly-undefined number from the SOME_VAR environment variable
    configValue('SOME_VAR', 'num');

    // Get a number with a default value of 5 from SOME_VAR
    configValue('SOME_VAR', 'num', 5);

    // Get a required string from SOME_VAR with no default (note: `REQUIRED` is a special imported symbol from this
    // library)
    configValue('SOME_VAR', REQUIRED);

    // Get a required number from SOME_VAR with no default
    configValue('SOME_VAR', 'num', REQUIRED);

    Parameters

    • envVarName: string | string[]
    • t: "num"
    • defaultValue: number
    • validator: ValidatorArg<number>

    Returns number | `::ERROR::${string}`

    Example

    Following is a more real-world example of how this might all be used in context

    const configDef = {
    port: configValue('PORT', 'num', 3000),
    hiPort: configValue('PORT', 'num', 30_000, hiport),
    host: configValue('HOST', 'str', 'http://localhost', hostValidator),
    db: {
    url: configValue('DB_URL', 'str', 'postgres://postgres@localhost:5432'),
    migrateOnStart: configValue('DB_MIGRATE_ON_START', 'bool', false),
    },
    signatureSecret: configValue('SIGNATURE_SECRET', 'str', [required, exactLength(32), hex]),
    secondsToWaitForThing: configValue('SECONDS_TO_WAIT_FOR_THING', 'num', required),
    }

    export const config = validate(configDef);

    NOTE: This function uses any-casts. This is because the underlying transformer functions are overloaded and require either one argument configuration or the other, which gets messy in a function like this. Since this function is itself properly overloaded, it's safe to use any-casts to solve this here.

  • Get a value with the given specification. The standard transformers available are 'str', 'num' and 'bool'. You can also pass a custom transformer function (see TransformerFunc) as well a validator function or array of validator functions. (Import the Validators library from this library to explore the bundled validators or write your own by implementing ValidatorFunc.)

    The most common usage of this will be the following (see more examples below for advanced usage in context):

    // Get a possibly-undefined string from the SOME_VAR environment variable
    configValue('SOME_VAR');

    // Get a string with a default value of 'some default' from the SOME_VAR environment variable
    configValue('SOME_VAR', 'some default');

    // Get a possibly-undefined number from the SOME_VAR environment variable
    configValue('SOME_VAR', 'num');

    // Get a number with a default value of 5 from SOME_VAR
    configValue('SOME_VAR', 'num', 5);

    // Get a required string from SOME_VAR with no default (note: `REQUIRED` is a special imported symbol from this
    // library)
    configValue('SOME_VAR', REQUIRED);

    // Get a required number from SOME_VAR with no default
    configValue('SOME_VAR', 'num', REQUIRED);

    Parameters

    • envVarName: string | string[]
    • t: "bool"

    Returns undefined | boolean | `::ERROR::${string}`

    Example

    Following is a more real-world example of how this might all be used in context

    const configDef = {
    port: configValue('PORT', 'num', 3000),
    hiPort: configValue('PORT', 'num', 30_000, hiport),
    host: configValue('HOST', 'str', 'http://localhost', hostValidator),
    db: {
    url: configValue('DB_URL', 'str', 'postgres://postgres@localhost:5432'),
    migrateOnStart: configValue('DB_MIGRATE_ON_START', 'bool', false),
    },
    signatureSecret: configValue('SIGNATURE_SECRET', 'str', [required, exactLength(32), hex]),
    secondsToWaitForThing: configValue('SECONDS_TO_WAIT_FOR_THING', 'num', required),
    }

    export const config = validate(configDef);

    NOTE: This function uses any-casts. This is because the underlying transformer functions are overloaded and require either one argument configuration or the other, which gets messy in a function like this. Since this function is itself properly overloaded, it's safe to use any-casts to solve this here.

  • Get a value with the given specification. The standard transformers available are 'str', 'num' and 'bool'. You can also pass a custom transformer function (see TransformerFunc) as well a validator function or array of validator functions. (Import the Validators library from this library to explore the bundled validators or write your own by implementing ValidatorFunc.)

    The most common usage of this will be the following (see more examples below for advanced usage in context):

    // Get a possibly-undefined string from the SOME_VAR environment variable
    configValue('SOME_VAR');

    // Get a string with a default value of 'some default' from the SOME_VAR environment variable
    configValue('SOME_VAR', 'some default');

    // Get a possibly-undefined number from the SOME_VAR environment variable
    configValue('SOME_VAR', 'num');

    // Get a number with a default value of 5 from SOME_VAR
    configValue('SOME_VAR', 'num', 5);

    // Get a required string from SOME_VAR with no default (note: `REQUIRED` is a special imported symbol from this
    // library)
    configValue('SOME_VAR', REQUIRED);

    // Get a required number from SOME_VAR with no default
    configValue('SOME_VAR', 'num', REQUIRED);

    Parameters

    • envVarName: string | string[]
    • t: "bool"
    • defaultOrRequired: DefOrReq<boolean>

    Returns boolean | `::ERROR::${string}`

    Example

    Following is a more real-world example of how this might all be used in context

    const configDef = {
    port: configValue('PORT', 'num', 3000),
    hiPort: configValue('PORT', 'num', 30_000, hiport),
    host: configValue('HOST', 'str', 'http://localhost', hostValidator),
    db: {
    url: configValue('DB_URL', 'str', 'postgres://postgres@localhost:5432'),
    migrateOnStart: configValue('DB_MIGRATE_ON_START', 'bool', false),
    },
    signatureSecret: configValue('SIGNATURE_SECRET', 'str', [required, exactLength(32), hex]),
    secondsToWaitForThing: configValue('SECONDS_TO_WAIT_FOR_THING', 'num', required),
    }

    export const config = validate(configDef);

    NOTE: This function uses any-casts. This is because the underlying transformer functions are overloaded and require either one argument configuration or the other, which gets messy in a function like this. Since this function is itself properly overloaded, it's safe to use any-casts to solve this here.

  • Get a value with the given specification. The standard transformers available are 'str', 'num' and 'bool'. You can also pass a custom transformer function (see TransformerFunc) as well a validator function or array of validator functions. (Import the Validators library from this library to explore the bundled validators or write your own by implementing ValidatorFunc.)

    The most common usage of this will be the following (see more examples below for advanced usage in context):

    // Get a possibly-undefined string from the SOME_VAR environment variable
    configValue('SOME_VAR');

    // Get a string with a default value of 'some default' from the SOME_VAR environment variable
    configValue('SOME_VAR', 'some default');

    // Get a possibly-undefined number from the SOME_VAR environment variable
    configValue('SOME_VAR', 'num');

    // Get a number with a default value of 5 from SOME_VAR
    configValue('SOME_VAR', 'num', 5);

    // Get a required string from SOME_VAR with no default (note: `REQUIRED` is a special imported symbol from this
    // library)
    configValue('SOME_VAR', REQUIRED);

    // Get a required number from SOME_VAR with no default
    configValue('SOME_VAR', 'num', REQUIRED);

    Parameters

    • envVarName: string | string[]
    • t: "bool"
    • validator: ValidatorArg<boolean>

    Returns undefined | boolean | `::ERROR::${string}`

    Example

    Following is a more real-world example of how this might all be used in context

    const configDef = {
    port: configValue('PORT', 'num', 3000),
    hiPort: configValue('PORT', 'num', 30_000, hiport),
    host: configValue('HOST', 'str', 'http://localhost', hostValidator),
    db: {
    url: configValue('DB_URL', 'str', 'postgres://postgres@localhost:5432'),
    migrateOnStart: configValue('DB_MIGRATE_ON_START', 'bool', false),
    },
    signatureSecret: configValue('SIGNATURE_SECRET', 'str', [required, exactLength(32), hex]),
    secondsToWaitForThing: configValue('SECONDS_TO_WAIT_FOR_THING', 'num', required),
    }

    export const config = validate(configDef);

    NOTE: This function uses any-casts. This is because the underlying transformer functions are overloaded and require either one argument configuration or the other, which gets messy in a function like this. Since this function is itself properly overloaded, it's safe to use any-casts to solve this here.

  • Get a value with the given specification. The standard transformers available are 'str', 'num' and 'bool'. You can also pass a custom transformer function (see TransformerFunc) as well a validator function or array of validator functions. (Import the Validators library from this library to explore the bundled validators or write your own by implementing ValidatorFunc.)

    The most common usage of this will be the following (see more examples below for advanced usage in context):

    // Get a possibly-undefined string from the SOME_VAR environment variable
    configValue('SOME_VAR');

    // Get a string with a default value of 'some default' from the SOME_VAR environment variable
    configValue('SOME_VAR', 'some default');

    // Get a possibly-undefined number from the SOME_VAR environment variable
    configValue('SOME_VAR', 'num');

    // Get a number with a default value of 5 from SOME_VAR
    configValue('SOME_VAR', 'num', 5);

    // Get a required string from SOME_VAR with no default (note: `REQUIRED` is a special imported symbol from this
    // library)
    configValue('SOME_VAR', REQUIRED);

    // Get a required number from SOME_VAR with no default
    configValue('SOME_VAR', 'num', REQUIRED);

    Parameters

    • envVarName: string | string[]
    • t: "bool"
    • required: typeof REQUIRED
    • validator: ValidatorArg<boolean>

    Returns boolean | `::ERROR::${string}`

    Example

    Following is a more real-world example of how this might all be used in context

    const configDef = {
    port: configValue('PORT', 'num', 3000),
    hiPort: configValue('PORT', 'num', 30_000, hiport),
    host: configValue('HOST', 'str', 'http://localhost', hostValidator),
    db: {
    url: configValue('DB_URL', 'str', 'postgres://postgres@localhost:5432'),
    migrateOnStart: configValue('DB_MIGRATE_ON_START', 'bool', false),
    },
    signatureSecret: configValue('SIGNATURE_SECRET', 'str', [required, exactLength(32), hex]),
    secondsToWaitForThing: configValue('SECONDS_TO_WAIT_FOR_THING', 'num', required),
    }

    export const config = validate(configDef);

    NOTE: This function uses any-casts. This is because the underlying transformer functions are overloaded and require either one argument configuration or the other, which gets messy in a function like this. Since this function is itself properly overloaded, it's safe to use any-casts to solve this here.

  • Get a value with the given specification. The standard transformers available are 'str', 'num' and 'bool'. You can also pass a custom transformer function (see TransformerFunc) as well a validator function or array of validator functions. (Import the Validators library from this library to explore the bundled validators or write your own by implementing ValidatorFunc.)

    The most common usage of this will be the following (see more examples below for advanced usage in context):

    // Get a possibly-undefined string from the SOME_VAR environment variable
    configValue('SOME_VAR');

    // Get a string with a default value of 'some default' from the SOME_VAR environment variable
    configValue('SOME_VAR', 'some default');

    // Get a possibly-undefined number from the SOME_VAR environment variable
    configValue('SOME_VAR', 'num');

    // Get a number with a default value of 5 from SOME_VAR
    configValue('SOME_VAR', 'num', 5);

    // Get a required string from SOME_VAR with no default (note: `REQUIRED` is a special imported symbol from this
    // library)
    configValue('SOME_VAR', REQUIRED);

    // Get a required number from SOME_VAR with no default
    configValue('SOME_VAR', 'num', REQUIRED);

    Parameters

    • envVarName: string | string[]
    • t: "bool"
    • defaultValue: boolean
    • validator: ValidatorArg<boolean>

    Returns boolean | `::ERROR::${string}`

    Example

    Following is a more real-world example of how this might all be used in context

    const configDef = {
    port: configValue('PORT', 'num', 3000),
    hiPort: configValue('PORT', 'num', 30_000, hiport),
    host: configValue('HOST', 'str', 'http://localhost', hostValidator),
    db: {
    url: configValue('DB_URL', 'str', 'postgres://postgres@localhost:5432'),
    migrateOnStart: configValue('DB_MIGRATE_ON_START', 'bool', false),
    },
    signatureSecret: configValue('SIGNATURE_SECRET', 'str', [required, exactLength(32), hex]),
    secondsToWaitForThing: configValue('SECONDS_TO_WAIT_FOR_THING', 'num', required),
    }

    export const config = validate(configDef);

    NOTE: This function uses any-casts. This is because the underlying transformer functions are overloaded and require either one argument configuration or the other, which gets messy in a function like this. Since this function is itself properly overloaded, it's safe to use any-casts to solve this here.

  • Get a value with the given specification. The standard transformers available are 'str', 'num' and 'bool'. You can also pass a custom transformer function (see TransformerFunc) as well a validator function or array of validator functions. (Import the Validators library from this library to explore the bundled validators or write your own by implementing ValidatorFunc.)

    The most common usage of this will be the following (see more examples below for advanced usage in context):

    // Get a possibly-undefined string from the SOME_VAR environment variable
    configValue('SOME_VAR');

    // Get a string with a default value of 'some default' from the SOME_VAR environment variable
    configValue('SOME_VAR', 'some default');

    // Get a possibly-undefined number from the SOME_VAR environment variable
    configValue('SOME_VAR', 'num');

    // Get a number with a default value of 5 from SOME_VAR
    configValue('SOME_VAR', 'num', 5);

    // Get a required string from SOME_VAR with no default (note: `REQUIRED` is a special imported symbol from this
    // library)
    configValue('SOME_VAR', REQUIRED);

    // Get a required number from SOME_VAR with no default
    configValue('SOME_VAR', 'num', REQUIRED);

    Type Parameters

    • T

    Parameters

    Returns undefined | `::ERROR::${string}` | T

    Example

    Following is a more real-world example of how this might all be used in context

    const configDef = {
    port: configValue('PORT', 'num', 3000),
    hiPort: configValue('PORT', 'num', 30_000, hiport),
    host: configValue('HOST', 'str', 'http://localhost', hostValidator),
    db: {
    url: configValue('DB_URL', 'str', 'postgres://postgres@localhost:5432'),
    migrateOnStart: configValue('DB_MIGRATE_ON_START', 'bool', false),
    },
    signatureSecret: configValue('SIGNATURE_SECRET', 'str', [required, exactLength(32), hex]),
    secondsToWaitForThing: configValue('SECONDS_TO_WAIT_FOR_THING', 'num', required),
    }

    export const config = validate(configDef);

    NOTE: This function uses any-casts. This is because the underlying transformer functions are overloaded and require either one argument configuration or the other, which gets messy in a function like this. Since this function is itself properly overloaded, it's safe to use any-casts to solve this here.

  • Get a value with the given specification. The standard transformers available are 'str', 'num' and 'bool'. You can also pass a custom transformer function (see TransformerFunc) as well a validator function or array of validator functions. (Import the Validators library from this library to explore the bundled validators or write your own by implementing ValidatorFunc.)

    The most common usage of this will be the following (see more examples below for advanced usage in context):

    // Get a possibly-undefined string from the SOME_VAR environment variable
    configValue('SOME_VAR');

    // Get a string with a default value of 'some default' from the SOME_VAR environment variable
    configValue('SOME_VAR', 'some default');

    // Get a possibly-undefined number from the SOME_VAR environment variable
    configValue('SOME_VAR', 'num');

    // Get a number with a default value of 5 from SOME_VAR
    configValue('SOME_VAR', 'num', 5);

    // Get a required string from SOME_VAR with no default (note: `REQUIRED` is a special imported symbol from this
    // library)
    configValue('SOME_VAR', REQUIRED);

    // Get a required number from SOME_VAR with no default
    configValue('SOME_VAR', 'num', REQUIRED);

    Type Parameters

    • T

    Parameters

    • envVarName: string | string[]
    • t: Transformer<T>
    • defaultOrRequired: DefOrReq<T>

    Returns `::ERROR::${string}` | T

    Example

    Following is a more real-world example of how this might all be used in context

    const configDef = {
    port: configValue('PORT', 'num', 3000),
    hiPort: configValue('PORT', 'num', 30_000, hiport),
    host: configValue('HOST', 'str', 'http://localhost', hostValidator),
    db: {
    url: configValue('DB_URL', 'str', 'postgres://postgres@localhost:5432'),
    migrateOnStart: configValue('DB_MIGRATE_ON_START', 'bool', false),
    },
    signatureSecret: configValue('SIGNATURE_SECRET', 'str', [required, exactLength(32), hex]),
    secondsToWaitForThing: configValue('SECONDS_TO_WAIT_FOR_THING', 'num', required),
    }

    export const config = validate(configDef);

    NOTE: This function uses any-casts. This is because the underlying transformer functions are overloaded and require either one argument configuration or the other, which gets messy in a function like this. Since this function is itself properly overloaded, it's safe to use any-casts to solve this here.

  • Get a value with the given specification. The standard transformers available are 'str', 'num' and 'bool'. You can also pass a custom transformer function (see TransformerFunc) as well a validator function or array of validator functions. (Import the Validators library from this library to explore the bundled validators or write your own by implementing ValidatorFunc.)

    The most common usage of this will be the following (see more examples below for advanced usage in context):

    // Get a possibly-undefined string from the SOME_VAR environment variable
    configValue('SOME_VAR');

    // Get a string with a default value of 'some default' from the SOME_VAR environment variable
    configValue('SOME_VAR', 'some default');

    // Get a possibly-undefined number from the SOME_VAR environment variable
    configValue('SOME_VAR', 'num');

    // Get a number with a default value of 5 from SOME_VAR
    configValue('SOME_VAR', 'num', 5);

    // Get a required string from SOME_VAR with no default (note: `REQUIRED` is a special imported symbol from this
    // library)
    configValue('SOME_VAR', REQUIRED);

    // Get a required number from SOME_VAR with no default
    configValue('SOME_VAR', 'num', REQUIRED);

    Type Parameters

    • T

    Parameters

    • envVarName: string | string[]
    • t: Transformer<T>
    • validator: ValidatorArg<T>

    Returns undefined | `::ERROR::${string}` | T

    Example

    Following is a more real-world example of how this might all be used in context

    const configDef = {
    port: configValue('PORT', 'num', 3000),
    hiPort: configValue('PORT', 'num', 30_000, hiport),
    host: configValue('HOST', 'str', 'http://localhost', hostValidator),
    db: {
    url: configValue('DB_URL', 'str', 'postgres://postgres@localhost:5432'),
    migrateOnStart: configValue('DB_MIGRATE_ON_START', 'bool', false),
    },
    signatureSecret: configValue('SIGNATURE_SECRET', 'str', [required, exactLength(32), hex]),
    secondsToWaitForThing: configValue('SECONDS_TO_WAIT_FOR_THING', 'num', required),
    }

    export const config = validate(configDef);

    NOTE: This function uses any-casts. This is because the underlying transformer functions are overloaded and require either one argument configuration or the other, which gets messy in a function like this. Since this function is itself properly overloaded, it's safe to use any-casts to solve this here.

  • Get a value with the given specification. The standard transformers available are 'str', 'num' and 'bool'. You can also pass a custom transformer function (see TransformerFunc) as well a validator function or array of validator functions. (Import the Validators library from this library to explore the bundled validators or write your own by implementing ValidatorFunc.)

    The most common usage of this will be the following (see more examples below for advanced usage in context):

    // Get a possibly-undefined string from the SOME_VAR environment variable
    configValue('SOME_VAR');

    // Get a string with a default value of 'some default' from the SOME_VAR environment variable
    configValue('SOME_VAR', 'some default');

    // Get a possibly-undefined number from the SOME_VAR environment variable
    configValue('SOME_VAR', 'num');

    // Get a number with a default value of 5 from SOME_VAR
    configValue('SOME_VAR', 'num', 5);

    // Get a required string from SOME_VAR with no default (note: `REQUIRED` is a special imported symbol from this
    // library)
    configValue('SOME_VAR', REQUIRED);

    // Get a required number from SOME_VAR with no default
    configValue('SOME_VAR', 'num', REQUIRED);

    Type Parameters

    • T

    Parameters

    Returns `::ERROR::${string}` | T

    Example

    Following is a more real-world example of how this might all be used in context

    const configDef = {
    port: configValue('PORT', 'num', 3000),
    hiPort: configValue('PORT', 'num', 30_000, hiport),
    host: configValue('HOST', 'str', 'http://localhost', hostValidator),
    db: {
    url: configValue('DB_URL', 'str', 'postgres://postgres@localhost:5432'),
    migrateOnStart: configValue('DB_MIGRATE_ON_START', 'bool', false),
    },
    signatureSecret: configValue('SIGNATURE_SECRET', 'str', [required, exactLength(32), hex]),
    secondsToWaitForThing: configValue('SECONDS_TO_WAIT_FOR_THING', 'num', required),
    }

    export const config = validate(configDef);

    NOTE: This function uses any-casts. This is because the underlying transformer functions are overloaded and require either one argument configuration or the other, which gets messy in a function like this. Since this function is itself properly overloaded, it's safe to use any-casts to solve this here.

  • Get a value with the given specification. The standard transformers available are 'str', 'num' and 'bool'. You can also pass a custom transformer function (see TransformerFunc) as well a validator function or array of validator functions. (Import the Validators library from this library to explore the bundled validators or write your own by implementing ValidatorFunc.)

    The most common usage of this will be the following (see more examples below for advanced usage in context):

    // Get a possibly-undefined string from the SOME_VAR environment variable
    configValue('SOME_VAR');

    // Get a string with a default value of 'some default' from the SOME_VAR environment variable
    configValue('SOME_VAR', 'some default');

    // Get a possibly-undefined number from the SOME_VAR environment variable
    configValue('SOME_VAR', 'num');

    // Get a number with a default value of 5 from SOME_VAR
    configValue('SOME_VAR', 'num', 5);

    // Get a required string from SOME_VAR with no default (note: `REQUIRED` is a special imported symbol from this
    // library)
    configValue('SOME_VAR', REQUIRED);

    // Get a required number from SOME_VAR with no default
    configValue('SOME_VAR', 'num', REQUIRED);

    Type Parameters

    • T

    Parameters

    • envVarName: string | string[]
    • t: Transformer<T>
    • defaultValue: T
    • validator: ValidatorArg<T>

    Returns `::ERROR::${string}` | T

    Example

    Following is a more real-world example of how this might all be used in context

    const configDef = {
    port: configValue('PORT', 'num', 3000),
    hiPort: configValue('PORT', 'num', 30_000, hiport),
    host: configValue('HOST', 'str', 'http://localhost', hostValidator),
    db: {
    url: configValue('DB_URL', 'str', 'postgres://postgres@localhost:5432'),
    migrateOnStart: configValue('DB_MIGRATE_ON_START', 'bool', false),
    },
    signatureSecret: configValue('SIGNATURE_SECRET', 'str', [required, exactLength(32), hex]),
    secondsToWaitForThing: configValue('SECONDS_TO_WAIT_FOR_THING', 'num', required),
    }

    export const config = validate(configDef);

    NOTE: This function uses any-casts. This is because the underlying transformer functions are overloaded and require either one argument configuration or the other, which gets messy in a function like this. Since this function is itself properly overloaded, it's safe to use any-casts to solve this here.

Generated using TypeDoc