node-convict
node-convict copied to clipboard
list formats
There is currently an Array format, but you can't restrict the values in the array to a certain type.
I was thinking of just wrapping the format property in an array to signify that it should be a list with elements of only that type.
E.g.:
var config = convict({
foo: {
default: ["5 seconds", "10 seconds"],
format: ["duration"]
}
});
One concern is that it looks similar to the enum format, although enums shouldn't be allowed to have a single element. An alternative would be to add a list: true to the schema.
You can make your own format :
foo: {
child: ["5 seconds", "10 seconds"],
format: duration-array
}
convict.addFormat({
name: 'duration-array',
validate: function(children, schema) {
if (!Array.isArray(children)) {
throw new Error('must be of type Array');
}
for (child of children) {
convict({
child: { default: '', format: 'duration' }
}).load({ child: child }).validate();
}
}
});
Also refer to #238.
And #312 ?
convict.addFormat({
name: /^enum\[.*\]$/, //enum[duration]
// ...
})
This issue should be closed because we have several way to do that.