npm install orityObject based arity
Lets you specify arity with an array of objects of name-type pairs:
``sh`
npm install ority
`js
const ority = require('ority')
function fn () {
const args = ority(arguments, [{
name: 'string',
options: 'object'
}, {
name: 'string',
flag: 'boolean',
}, {
name: 'string',
}, {
flag: 'boolean',
}, {
options: 'object',
}], {
defaults: {
flag: false
}
})
console.log(args)
}
``js
fn('a')
// => { name: 'a', flag: false }
fn('a', true)
// => { name: 'a', flag: true }
fn({ json: true })
// => { options: { json: true }, flag: false }
`
`js`
ority(args, arities, options)
* args [arguments] Arguments from the calling function.arities
* [array] Array of object based arities.options
* [object]
* error [Error|string] Custom Error to be thrown instead of the default one.onError
* [function] Custom error handler whose return value gets bubbled up returned to parent callerdefaults
* [object]` Default object whose properties are used to set properties not matched/found in the arguments.
* [kind-of]: to perform type comparisons.
[kind-of]: https://www.npmjs.com/package/kind-of