The types for this config validator.
An object that maps a config key to a custom validator function.
Private
Readonly
customAn object that maps a config key to a custom validator function. This validator function will be used to validate the config supplied. It will skip the default type validator and instead use the one specified here. This function should not return anything, but throw a TypeError if the given value is not correct.
ConfigValidator
Private
Readonly
typesThe types for this config validator.
ConfigValidator
Static
Readonly
VALID_The valid types that can be used. It is also possible to have an array of these types.
ConfigValidator
Casts the values in an object of string values into its corresponding types
based on the types defined in this validator. If a cast is not possible, the function will throw.
This does not mutate the config object given and instead returns a copy of it with the cast config values.
If the type includes string
then this function will try to cast first to any of the available types and
if it fails to cast to any of them, it will return the string
version of the value instead of throwing.
The object of string values to be cast.
An object with the values cast.
Throws if a config value cannot be cast to any of its specified types.
Private
isReturns true
if the value given conforms the type given.
The value to test.
The type to test.
Whether the value's type is valid.
Private
tryTries to cast a value into its type from string. It returns the same value if the cast is not possible.
The value to cast.
The type to cast the value to.
The cast value.
Throws if the type is invalid.
Throws if the value cannot be cast to its specified type.
Validate that the provided config complies with all the types defined in this validator.
The configuration object to test.
Throws if the config contains a value that does not have a correct type.
Private
validateGenerated using TypeDoc
A validator class for the configuration provider. This class receives an object with a subset of the keys of the config with a type or array of types corresponding to that config value.
Valid types include:
boolean
,number
,string
andnull
, or including their array types:boolean[]
,number[]
andstring[]
You can set a type to be an array containing multiple of the ones above.It is preferable to specify all the types for your config. However, if a type is omitted it will be defaulted to
string
. Keep this in mind in the case you need to have a boolean or a number in your configuration.You may also specify custom validators by passing an object that maps the key of the config with its validator. This validator function does not need to return anything, but throw a TypeError if the given value in its parameter is not valid according to your criteria. If you pass a customValidator for a specific key, you should still pass its type because it is used to cast the value coming from environment variables, since they're only strings.
This configuration is most useful for configuration coming from env variables since they are only strings. Although, in a case where only a JSON configuration is specified, you may run into trouble if you don't specify the types for those settings because, while JSON properties can be typed, the validator will default them to
string
, which will make the validation throw an error during the ConfigProvider creation.