Gets a string
value from a finite set of expected values derived from the keys of a given object of type T
,
matched case-insensitively. An optional transform
may be provided that will preprocess both the found value
and any provided default before testing for membership in the target object's key set.
The name of the envar.
The object providing the keys to test with.
Optional
transform: ((k: string) => string)A transform function applied to both the default and value before testing that
either is a key of T
.
enum Mode { TEST = 'test', DEMO = 'demo' }
env.setString('MY_ENVAR', Mode.DEMO);
const check = env.getString('MY_ENVAR');
// check -> 'demo'
// typeof check -> string
const value = env.getKeyOf('MY_ENVAR', Mode, v => v.toUpperCase());
// value -> 'DEMO'
// typeof value -> 'TEST' | 'DEMO' (i.e. Extract<keyof typeof Mode, string>)
const enumValue = Mode[value];
// enumValue -> 'demo'
// typeof enumValue -> Mode
Gets a string
value from a finite set of expected values derived from the keys of a given object of type T
,
matched case-insensitively, using a default if not found. An optional transform
may be provided that will
preprocess both the found value and any provided default before testing for membership in the target object's
key set.
The name of the envar.
The object providing the keys to test with.
A default value.
Optional
transform: ((k: string) => string)A transform function applied to both the default and value before testing that
either is a key of T
.
Gets a list of string
values for a given key by splitting the raw value on ,
chars.
The name of the envar.
Gets a list of string
values for a given key by splitting the raw value on ,
chars.
The name of the envar.
A default list of values.
Gets a number
value for a given key. Returns the default value if no value was found.
The name of the envar.
A default number, which itself defaults to undefined
if not otherwise supplied.
Optional
def: undefinedGets a string
value from a finite set of expected values, matched case-insensitively.
The name of the envar.
The finite set of expected values.
Gets a string
value from a finite set of expected values, matched case-insensitively, using a default if
not found.
The name of the envar.
The finite set of expected values.
A default value.
InvalidDefaultEnvValueError If the provided default value is not a member of the expected set.
An injectable abstraction on top of
process.env
with various convenience functions for accessing environment variables of different anticipated shapes.