0.5.0 • Published 8 years ago
ority v0.5.0
ority
Object based arity
Lets you specify arity with an array of objects of name-type pairs:
Install
npm install orityUsage
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)
}fn('a')
// => { name: 'a', flag: false }
fn('a', true)
// => { name: 'a', flag: true }
fn({ json: true })
// => { options: { json: true }, flag: false }API
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.
Libraries used
- kind-of: to perform type comparisons.