also handle arrays of strings

This commit is contained in:
Nick Sweeting 2021-05-19 01:46:12 -04:00 committed by GitHub
parent a6162f7142
commit 77ea05a233
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,8 +11,9 @@ convict.addFormat({
throw new Error('must be a comma-separated list of positive integers')
}
},
coerce: (ints_str, schema) => {
return ints_str.trim().split(',').map(int_str => parseInt(int_str.trim(), 10))
coerce: (ints, schema) => {
const ints_arr = Array.isArray(ints_str) ? ints : ints.trim().split(',')
return ints_arr.map(int => (typeof int === 'number') ? int : parseInt(int.trim(), 10))
},
});