Provide some arguments, get back a hash object of the arguments indexed by their type. Very useful for agnostic argument orders.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example
source
.editorconfig
.eslintrc.js
.gitignore v1.1.0 updated base files and internal conventions Jan 31, 2018
.npmignore
.travis.yml
CONTRIBUTING.md
HISTORY.md
LICENSE.md
README.md
index.js
package-lock.json
package.json
test.js

README.md

Arguments By Type

Travis CI Build Status NPM version NPM downloads Dependency Status Dev Dependency Status
Patreon donate button Open Collective donate button Gratipay donate button Flattr donate button PayPal donate button Bitcoin donate button Wishlist browse button
Slack community badge

Provide some arguments, get back a hash object of the arguments indexed by their type. Very useful for agnostic argument orders.

Install

NPM

  • Install: npm install --save argsbytype
  • Module: require('argsbytype')

Browserify

  • Install: npm install --save argsbytype
  • Module: require('argsbytype')
  • CDN URL: //wzrd.in/bundle/argsbytype@1.1.0

Ender

  • Install: ender add argsbytype
  • Module: require('argsbytype')

Editions

This package is published with the following editions:

  • argsbytype aliases argsbytype/index.js which uses Editions to automatically select the correct edition for the consumers environment
  • argsbytype/source/index.js is Source + ESNext + Require
  • argsbytype/es2015/index.js is Babel Compiled + ES2015 + Require

Older environments may need Babel's Polyfill or something similar.

Usage

Let's say your coding a function, and you want to accept arguments in any order. Traditionally this would look like:

https://github.com/bevry/argsbytype/blob/master/example/01.js

But what happens when you:

  • Start having arguments that are regular expressions or dates which typeof is still object instead of regexp or date
  • Or, when you start having multiple arguments of the same type, that you would like to accept (e.g. the first string should be the name property, the second string should be the keyword property)

At that point in time, it becomes too much trouble to bother with. Fortunately, argsbytype is to the rescue! Now you can do:

https://github.com/bevry/argsbytype/blob/master/example/02.js

Yay! Big win for agnostic argument order! But when would you actually want this? Well, it turns out that in CoffeeScript options come first, in JavaScript, options usually come last. By using this, we can support both conventions, for example:

https://github.com/bevry/argsbytype/blob/master/example/03.js

History

Discover the release history by heading on over to the HISTORY.md file.

Contribute

Discover how you can contribute by heading on over to the CONTRIBUTING.md file.

Backers

Maintainers

These amazing people are maintaining this project:

Sponsors

No sponsors yet! Will you be the first?

Patreon donate button Open Collective donate button Gratipay donate button Flattr donate button PayPal donate button Bitcoin donate button Wishlist browse button

Contributors

These amazing people have contributed code to this project:

Discover how you can contribute by heading on over to the CONTRIBUTING.md file.

License

Unless stated otherwise all works are:

and licensed under: