Created
September 6, 2014 04:41
-
-
Save indexzero/35cc73fc4824ad004ac8 to your computer and use it in GitHub Desktop.
Some silly arguments parsing experiment thingy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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