const hex = envalid.makeValidator<Buffer>(value => Buffer.from(value, 'hex'))
envalid.cleanEnv({
VALUE: 'decafbad',
}, {
VALUE: hex({ default: 'ff' }), // TypeScript expects a Buffer or undefined
})
The parser is typed as receiving a string value:
|
parser: (input: string) => any, |
However the validator specs infer the validated type and mandate it for the default and devDefault values. That's nice for numbers and booleans but I suspect it'll trip up the json validator. It works for my hex validator above but only because Node.js doesn't throw an error for the unnecessary encoding argument.
Perhaps the default values should always be strings, and be typed as such?