validate-args-js
v1.1.0
Published
Validate arguments to Javascript.
Downloads
5
Readme
Validate-args-js
Validate arguments to Javascript.
Installation
npm install --save validate-args-js
Usage
Import
const check = require('validate-args-js')
Simple
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!')
Accept
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!')
List
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')