node-convict
node-convict copied to clipboard
Object format cannot use null-default
From the ReadMe:
However, you can set a default value to null and if your format doesn't accept null it will throw an error.
This works for String
for example, but not for the Object
format. This is unfortunate (in my case anyway :)), and I was wondering if there is a design-choice underlying this, or if it could be allowed? Thanks!
Do you have an example of what you want to do ?
Heh, I wish you had asked in May :) I should've been clearer the first time around, apologies.
iirc, I was hoping to configure a dictionary-style property like:
{
format: Object,
default: null
}
I think I wanted that to throw when the configuration was omitted?
Similar to : https://github.com/mozilla/node-convict/issues/7#issuecomment-553856857
You can make your own format and accept null or object ? Or with #312 :
convict.addFormat({
name: /^(.*)-null$/, //accept : String-null, Object-null, etc...
validate: function(value, schema) {
if (value === null)
return true;
const subSchema = {};
subSchema["value-or-null"] = {
format: schema.format.match(/^Array\[(.*)]$/)[1],
default: null
};
convict(subSchema).load(value).validate();
})
})
Do you have any proper solution which need a PR ?