Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Better arguments handling for Javascript
branch: master
Failed to load latest commit information.
build Add more build options
src hello world
.gitignore Some npm stuff
.jshintrc hello world
Gruntfile.js Add more build options
README.md Update README
index.js NPM friendly
package.json Finally README is parsed correctly
tests.js hello world

README.md

Arrg!!!

This is your sound when you have to deal with arguments (parameters) in Javascript. Although, I love to work with Javascript, but sometimes the arguments system got out of my control and I was like "where the heck was that param coming form?"

The Idea

The idea of this little library is to make working with arguments (for functions or methods) a bit easier by providing a utility to extract arguments so that they can be consistent across the project

How?

function pickThat() {
  var args = arrg(arguments, ['what', 'where']);
}

pickThat('duck', 'near the pack'); // now args becomes {what: 'duck', where: 'near the pack'}

How is it considered convinient and consistent for the project? Imaging that you have another developer joining your project and he is so in love with passing objects everywhere. So the above function still works as expected

pickThat({what: 'alligator', where: 'the zoo'}); // args now has {what: 'alligator', where: 'the zoo'}

Still not convinced? Now, what if you want to have default values? Right, default values are sweet and handy

function pickThat() {
  var args = arrg(arguments, ['what', 'where'], {what: 'bear', where: 'Finland'});
}

pickThat('bear'); // now args becomes {what: 'bear', where: 'Finland'}, not sure if Finland has bears, though

Want more? Read tests.js

Development

Gruntfile.js and package.json contain enough information

License

MIT

Something went wrong with that request. Please try again.