Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var reLeadingHyphen = /^\-+/
- function reduceArgs(collection, arg, idx) {
- var key
- if (arg[0] === '-') {
- key = arg.replace(reLeadingHyphen, '')
- collection[key] = null,
- collection.__wantsValue = key
- } else if (collection.__wantsValue !== null) {
- collection[collection.__wantsValue] = arg
- collection.__wantsValue = null
- } else {
- if (!collection.ordered) {
- collection.ordered = []
- }
- collection.ordered.push(arg)
- }
- return collection
- }
- module.exports = function(argv) {
- var args = argv.slice(2)
- var argMap = args.reduce(reduceArgs, { __wantsValue: null })
- delete(argMap['__wantsValue'])
- return argMap
- }
Add Comment
Please, Sign In to add comment