Skip to content

Instantly share code, notes, and snippets.

@indexzero
Created September 6, 2014 04:41
Show Gist options
  • Select an option

  • Save indexzero/35cc73fc4824ad004ac8 to your computer and use it in GitHub Desktop.

Select an option

Save indexzero/35cc73fc4824ad004ac8 to your computer and use it in GitHub Desktop.
Some silly arguments parsing experiment thingy
var assert = require('assert');
var targs = module.exports = function (args, names) {
var types = Object.keys(names);
return args.reduce(function (ret, arg) {
var type = typeof arg;
if (~types.indexOf(type)) {
ret[names[type]] = arg;
}
return ret;
}, {});
}
//
// Sample usage
//
function testing123 () {
console.dir(
targs(Array.prototype.slice.call(arguments), {
'number': 'port',
'string': 'host',
'function': 'callback'
})
);
}
testing123(8080, 'nodejitsu.com', function wtf() {
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment