Type alias TransformerFunc<T>

TransformerFunc<T>: ((val, varname) => T | undefined | ConfigError)

Any function conforming to this interface may be passed to the configValue function to transform the value of a given config key.

Type Parameters

  • T

Type declaration

    • (val, varname): T | undefined | ConfigError
    • Parameters

      • val: string | undefined
      • varname: string

      Returns T | undefined | ConfigError

Example

const myType = ((val: string | undefined, varname: string) => {
if (!val) {
if (def === REQUIRED) {
return `::ERROR::${varname}::This value is required`;
}
return def;
}
try {
// Normally you would validate but for testing we're skipping that and just returning whatever
return JSON.parse(val) as MyType;
} catch (e: any) {
return `::ERROR::${varname}::Invalid JSON string passed: ${e.message}`;
}
}) as TransformerFunction<MyType>;

// ...

const configDef = {
myType: configValue('MY_TYPE', myType, REQUIRED),
// ...
}

Generated using TypeDoc