node-convict
node-convict copied to clipboard
Support for env variable arrays
Sry if there is already a ticket, I could not find it.
Is there any way to use arrays in a ENV variable? something like FOO=1,2,3
?
I understand that comma might be a valid char, so maybe have it opt in?
This should work
convict.addFormat({
name: "comma-separated-string",
validate: function (val) {
const emptyStringRegex = /^$/;
const commaSeparatedStringRegex = /^[\w\d]+(,[\w\d]+)*$/;
if (!emptyStringRegex.test(val) && !commaSeparatedStringRegex.test(val)) {
throw new Error("must be a comma separated string");
}
},
coerce: function (val) {
if (!val) return [];
return val.split(",");
},
});