You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

miniargs

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

miniargs - npm Package Compare versions

Comparing version

to
0.1.0

28

lib/index.js

@@ -17,6 +17,28 @@ var undef,

// we would iterate on entire command line arguments that were pre-split using spaces. (the first two being system
// arguments and skipped). In essence, the loop would run in a toggle-mode where one run would have the parameter
// name and the second run is expected to be the value (or next parmeter)
argv && argv.slice && argv.slice(2).forEach(function (item) {
patt.test(item) ?
((arg = item.replace(patt, rep)), args[arg] = undef) :
(arg && (args[arg] = item), (arg = undef));
// decide wthether the item is a parameter name or the value of previous paramter name detected.
if (patt.test(item)) {
arg = item.replace(patt, rep); // clean the hyphens
!args.hasOwnProperty(arg) && (args[arg] = undef); // add one key to object if none exist
}
else if (arg) { // now the item should be a value
// if the value of arg is undefined, it implies that this is the first occurance of a parameter's value and
// we simply assign the value to the same
if (args[arg] === undef) {
args[arg] = item;
}
// if we are here, it implies that we already have one parameter defined with the same name and as such
// we decide to append or create a new array based on the results
else if (Array.isArray(args[arg])) {
args[arg].push(item);
}
else {
args[arg] = [args[arg], item];
}
arg = undef; // clear parameter state
}
});

@@ -23,0 +45,0 @@

8

package.json
{
"name": "miniargs",
"version": "0.0.1",
"version": "0.1.0",
"main": "lib/index.js",

@@ -25,7 +25,7 @@ "description": "Lightweight command-line tool argument processing package",

"expect.js": "^0.3.1",
"istanbul": "^0.3.8",
"jscs": "^1.11.3",
"istanbul": "^0.4.5",
"jscs": "^3.0.7",
"jshint": "^2.6.3",
"mocha": "^2.2.1"
"mocha": "^3.2.0"
}
}

@@ -1,19 +0,13 @@

/* global describe, it */
var expect = require('expect.js'),
miniargs;
/* global describe, it, beforeEach, afterEach */
var expect = require('expect.js');
describe('miniargs', function () {
it('module must be require-able', function () {
var error;
var miniargs;
try {
miniargs = require('../lib/index.js');
}
catch (e) {
error = e;
}
beforeEach(function () {
miniargs = require('../lib/index.js');
});
expect(error).to.not.be.ok();
expect(miniargs).to.be.ok();
expect(typeof miniargs).to.be('object');
afterEach(function () {
miniargs = null;
});

@@ -71,2 +65,18 @@

});
it('must accept multiple switches as an array', function () {
expect(miniargs.parse(['', '', '--param-name', 'value1', '--param-name', 'value2'])).to.eql({
'param-name': ['value1', 'value2']
});
});
it('must accept multiple switches as an array even with value-less one', function () {
expect(miniargs.parse(['', '', '--param-name', '--param-name', 'value2'])).to.eql({
'param-name': 'value2'
});
expect(miniargs.parse(['', '', '--param-name', 'value1', '--param-name', '--param2'])).to.eql({
'param-name': 'value1',
'param2': undefined
});
});
});

Sorry, the diff of this file is not supported yet