0.5.0 • Published 7 years ago

ority v0.5.0

Weekly downloads
8
License
-
Repository
github
Last release
7 years ago

ority

npm

Object based arity

Lets you specify arity with an array of objects of name-type pairs:

Install

npm install ority

Usage

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 caller
    • defaults [object] Default object whose properties are used to set properties not matched/found in the arguments.

Libraries used

  • kind-of: to perform type comparisons.
0.5.0

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.3

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago