add comments
This commit is contained in:
parent
77ea05a233
commit
0ffc960523
@ -5,16 +5,19 @@ const { randomBytes } = require('crypto');
|
|||||||
|
|
||||||
convict.addFormat({
|
convict.addFormat({
|
||||||
name: 'positive-int-array',
|
name: 'positive-int-array',
|
||||||
validate: (ints, schema) => {
|
coerce: (ints, schema) => { // can take: int[] | string[] | string (csv), returns -> int[]
|
||||||
|
const ints_arr = Array.isArray(ints) ? ints : ints.trim().split(',')
|
||||||
|
return ints_arr.map(int =>
|
||||||
|
(typeof int === 'number')
|
||||||
|
? int
|
||||||
|
: parseInt(int.trim(), 10))
|
||||||
|
},
|
||||||
|
validate: (ints, schema) => { // takes: int[], errors if any NaNs, negatives, or floats present
|
||||||
for (const int of ints) {
|
for (const int of ints) {
|
||||||
if (isNaN(int) || int < 0)
|
if (typeof(int) !== 'number' || isNaN(int) || int < 0 || int % 1 > 0)
|
||||||
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, 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))
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const conf = convict({
|
const conf = convict({
|
||||||
|
Loading…
Reference in New Issue
Block a user