Comparing version 0.0.5 to 0.0.6
@@ -11,13 +11,11 @@ /** | ||
var opts = {}, | ||
curSwitch; | ||
var opts = {}, curSwitch; | ||
args.forEach(function(arg) { | ||
var curValType = typeof opts[curSwitch]; | ||
// its a switch | ||
if (/^(-|--)/.test(arg)) { | ||
if (/^(-|--)/.test(arg) || !curSwitch) { | ||
opts[arg] = true; | ||
curSwitch = arg; | ||
// this arg is some data | ||
} else if (curSwitch) { | ||
// this arg is a data | ||
} else { | ||
if (arg === 'false') { | ||
@@ -31,12 +29,11 @@ arg = false; | ||
if (curValType === 'boolean') { | ||
// it was a boolean switch per default, | ||
// now it has got a val | ||
if (typeof opts[curSwitch] === 'boolean') { | ||
opts[curSwitch] = arg; | ||
} else if (curValType === 'string') { | ||
} else if (Array.isArray(opts[curSwitch])) { | ||
opts[curSwitch].push(arg); | ||
} else { | ||
opts[curSwitch] = [opts[curSwitch], arg]; | ||
} else { | ||
opts[curSwitch].push(arg); | ||
} | ||
} else { | ||
opts[arg] = true; | ||
curSwitch = arg; | ||
} | ||
@@ -43,0 +40,0 @@ }); |
{ | ||
"name": "argsparser", | ||
"description": "A tiny command line arguments parser", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"author": "Oleg Slobodskoi <oleg008@gmail.com>", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -37,2 +37,4 @@ var a = require('assert'), | ||
a.deepEqual(parse(['--port', '80', '8080']), {'--port': [80, 8080]}, 'node server.js --port 80 8080'); | ||
util.print('All tests ok\n'); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4954
7
59