also handle arrays of strings
This commit is contained in:
parent
a6162f7142
commit
77ea05a233
1 changed files with 3 additions and 2 deletions
|
@ -11,8 +11,9 @@ convict.addFormat({
|
||||||
throw new Error('must be a comma-separated list of positive integers')
|
throw new Error('must be a comma-separated list of positive integers')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
coerce: (ints_str, schema) => {
|
coerce: (ints, schema) => {
|
||||||
return ints_str.trim().split(',').map(int_str => parseInt(int_str.trim(), 10))
|
const ints_arr = Array.isArray(ints_str) ? ints : ints.trim().split(',')
|
||||||
|
return ints_arr.map(int => (typeof int === 'number') ? int : parseInt(int.trim(), 10))
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue