Validate arguments.
npm install --save validate-args-js
const check = require('validate-args-js')
check.arg({
arg: undefined,
err: 'err name'
})
//Return -> throw new Error('err name')
check.arg({
arg: undefined,
err: undefined
})
//Return -> throw new Error('one argument has not been defined!')
check.arg({
arg: undefined,
err: 'err name',
accept: {
options: [1,2,3],
err: 'err accept name'
}
})
//Return -> throw new Error('err name')
check.arg({
arg: 4,
err: 'err name',
accept: {
options: [1,2,3],
err: 'err accept name'
}
})
//Return -> throw new Error('err accept name')
check.arg({
arg: 4,
err: 'err name',
accept: {
options: [1,2,3],
err: undefined
}
})
//Return -> throw new Error('one argument has not been accepted!')
check.args([
{
arg: 1,
err: 'err value',
accept: {
options: [1,2,3],
err: 'err accept value'
}
},
{
arg: 4,
err: 'err value 2',
accept: {
options: [1,2,3],
err: 'err accept value 2'
}
}
])
//Return -> throw new Error('err accept value 2')
check.args([{
arg: undefined,
err: 'err name',
accept: {
options: [1,2,3],
err: 'err accept name'
}
}])
//Return -> throw new Error('err name')