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.0.1

.editorconfig

27

lib/index.js

@@ -1,3 +0,5 @@

var E = '',
patt = /^(-[^-\s]|--[^-\s].+)$/g; // pattern to detect single or double hyphen start
var undef,
rep = '$2$4',
patt = /(^-([^-\s]$))|(^--([^-\s][\s\S]+$))/, // pattern to detect single or double hyphen start
parse;

@@ -9,13 +11,20 @@ /**

* @example
* var args = require('./quickargs.js')(process.argv);
* var args = require('miniargs').parse(process.argv);
*/
module.exports = function (argv) {
parse = function (argv) {
var args = {}, // object to store all key-value argument extraction
lastarg; // args are split by space, so we keep a track of last key detected
arg; // args are split by space, so we keep a track of last key detected
argv && argv.slice && argv.slice(2).forEach(function (item) {
lastarg = patt.test(item) ? item.replace(patt, E) : (lastarg && (args[lastarg] = item), undefined);
patt.test(item) ?
((arg = item.replace(patt, rep)), args[arg] = undef) :
(arg && (args[arg] = item), (arg = undef));
});
return args;
};
};
// export parse function
module.exports = {
parse: parse
};
{
"name": "miniargs",
"version": "0.0.0",
"version": "0.0.1",
"main": "lib/index.js",
"description": "Lightweight command-line tool argument processing package",
"scripts": {
"test": "mocha test/**/*-spec.js"
"test": "jscs lib test && jshint lib test && istanbul cover _mocha -- test/**/*-spec.js"
},

@@ -25,4 +25,7 @@ "repository": {

"expect.js": "^0.3.1",
"istanbul": "^0.3.8",
"jscs": "^1.11.3",
"jshint": "^2.6.3",
"mocha": "^2.2.1"
}
}
# miniargs
Lightweight command-line tool argument processing package
## Usage
```javascript
var args = require('miniargs').parse(process.argv);
```

@@ -0,31 +1,71 @@

/* global describe, it */
var expect = require('expect.js'),
miniargs;
miniargs;
describe('miniargs', function () {
it ('module must be require-able', function () {
var error;
it('module must be require-able', function () {
var error;
try {
miniargs = require('../lib/index.js');
}
catch (e) {
error = e;
}
try {
miniargs = require('../lib/index.js');
}
catch (e) {
error = e;
}
expect(error).to.not.be.ok();
expect(miniargs).to.be.ok();
expect(typeof miniargs).to.be('function');
});
expect(error).to.not.be.ok();
expect(miniargs).to.be.ok();
expect(typeof miniargs).to.be('object');
});
it ('must handle blank parameters', function () {
expect(miniargs()).to.eql({});
expect(miniargs(null)).to.eql({});
expect(miniargs(false)).to.eql({});
expect(miniargs([])).to.eql({});
expect(miniargs({})).to.eql({});
});
it('.parse() function must be available', function () {
expect(miniargs && (typeof miniargs.parse)).to.be('function');
});
it ('must ignore first two argument parameters', function () {
expect(miniargs(['first', 'second', 'third', 'undefined'])).to.eql({third: undefined});
});
});
it('must handle blank parameters', function () {
expect(miniargs.parse()).to.eql({});
expect(miniargs.parse(null)).to.eql({});
expect(miniargs.parse(false)).to.eql({});
expect(miniargs.parse([])).to.eql({});
expect(miniargs.parse({})).to.eql({});
});
it('must ignore first two argument parameters (as from process.argv)', function () {
expect(miniargs.parse(['first', 'second'])).to.eql({});
expect(miniargs.parse(['first', 'second', '-t', 'works'])).to.eql({
t: 'works'
});
});
it('must accept single hyphen arguments', function () {
expect(miniargs.parse(['', '', '-a', 'y', '-b', 'n'])).to.eql({
a: 'y',
b: 'n'
});
});
it('must set undefined to value of value-less parameters', function () {
expect(miniargs.parse(['', '', '-p', '--param'])).to.eql({
p: undefined,
param: undefined
});
});
it('must not accept single hyphen arguments having more than one character', function () {
expect(miniargs.parse(['', '', '-pp', 'value'])).to.eql({});
});
it('must not accept double hyphen arguments with just one character', function () {
expect(miniargs.parse(['', '', '--p', 'value'])).to.eql({});
});
it('must not accept whitespace or hyphen between hyphen and character', function () {
expect(miniargs.parse(['', '', '- p', 'v', '-- param', 'value', '---param2', 'value2'])).to.eql({});
});
it('must allow hyphen between param name', function () {
expect(miniargs.parse(['', '', '--param-name', 'value'])).to.eql({
'param-name': 'value'
});
});
});