Skip to content

michaelrhodes/arg-find

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

arg-find

Write functions that accept arguments in any order (so long as each is of a unique type). It’s weird, yes, but I sometimes find this useful for handling optional parameters.

Build status

Install

$ npm install arg-find

Example

var find = require('arg-find')

function fn () {
  var arg = find(arguments)
  var opt = arg('object') || {}
  var cb = arg('function')

  opt.throw ?
    cb(new Error) :
    cb(null)
}

fn(function (err) {
  console.log(err)
  > null
})

fn({ throw: true }, function (err) {
  console.log(err instanceof Error)
  > true
})

fn(function (err) {
  console.log(err instanceof Error)
  > true
}, { throw: true })

Weight (Browserified)

compression size
arg-find.js 1.48 kB
arg-find.min.js 994 B
arg-find.min.js.gz 514 B

License

MIT

About

write functions that accept arguments in any order

Resources

Stars

Watchers

Forks

Packages

No packages published