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

tiny-opts-parser

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

tiny-opts-parser - npm Package Compare versions

Comparing version

to
0.0.2

.eslintrc

71

dist/index.js

@@ -1,70 +0,1 @@

'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
exports.default = function (rawArgs) {
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { boolean: [], '--': false };
// Next two lines are for cases where user supplies either
// boolean or ['--'], but not both. We don't want the unsupplied
// one to be undefined, and the default parameter value doesn't
// kick in because the user supplied an opts hash.
if (opts.boolean === undefined) opts.boolean = [];
if (opts['--'] === undefined) opts['--'] = false;
var args = rawArgs.map(String);
var argv = {};
argv._ = [];
if (opts['--']) argv['--'] = [];
// Cycle through arguments
// Use traditional for loop instead of for..in or for..of
// because in some cases we want to skip an iteration,
// which we do by incrementing i
var _loop = function _loop(_i) {
var arg = args[_i];
function setToNextOrTrue(optName) {
if (opts.boolean.indexOf(optName) > -1) {
argv[optName] = true;
} else if (args[_i + 1] && !args[_i + 1].match(/^-/)) {
argv[optName] = args[_i + 1];
_i++;
} else {
argv[optName] = true;
}
}
if (arg.match(/^--$/)) {
var _argv$, _argv$_;
if (opts['--']) (_argv$ = argv['--']).push.apply(_argv$, _toConsumableArray(args.slice(_i + 1)));else (_argv$_ = argv._).push.apply(_argv$_, _toConsumableArray(args.slice(_i + 1)));
return 'break';
} else if (arg.match(/^-[^-]+/)) {
arg.slice(1, -1).split('').forEach(function (letter) {
return argv[letter] = true;
});
var lastLetter = arg.slice(-1);
setToNextOrTrue(lastLetter);
} else if (arg.match(/^--[^-]+/)) {
var optName = arg.slice(2);
setToNextOrTrue(optName);
} else {
argv._.push(arg);
}
i = _i;
};
for (var i = 0; i < args.length; i++) {
var _ret = _loop(i);
if (_ret === 'break') break;
}
return argv;
};
"use strict";function _toConsumableArray(r){if(Array.isArray(r)){for(var a=0,e=Array(r.length);a<r.length;a++)e[a]=r[a];return e}return Array.from(r)}module.exports=function(r){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},e={boolean:[],"--":!1},n=Object.assign({},e,a),t=r.map(String),i={};i._=[],n["--"]&&(i["--"]=[]);for(var o=function(r){function a(a){n.boolean.indexOf(a)>-1?i[a]=!0:t[r+1]&&!t[r+1].match(/^-/)?(i[a]=t[r+1],r+=1):i[a]=!0}var e=t[r];if(e.match(/^--$/)){var o,s;return n["--"]?(o=i["--"]).push.apply(o,_toConsumableArray(t.slice(r+1))):(s=i._).push.apply(s,_toConsumableArray(t.slice(r+1))),"break"}if(e.match(/^-[^-]+/)){e.slice(1,-1).split("").forEach(function(r){return i[r]=!0});var u=e.slice(-1);a(u)}else if(e.match(/^--[^-]+/)){var c=e.slice(2);a(c)}else i._.push(e);l=r},l=0;l<t.length;l+=1){var s=o(l);if("break"===s)break}return i};
{
"name": "tiny-opts-parser",
"version": "0.0.1",
"version": "0.0.2",
"description": "A tiny options parser.",
"main": "./dist/index.js",
"scripts": {
"build": "babel src -d dist",
"build": "npm run transpile && npm run uglify",
"lint": "eslint src/index.js; exit 0",
"prepublish": "npm run build",
"test": "mocha",
"test": "npm run lint && ttr",
"transpile": "babel src/index.js -o dist/index.js",
"uglify": "uglifyjs dist/index.js --compress --mangle -o dist/index.js",
"watch": "babel src --watch -d dist"
},
"author": "Zachary Miller",
"license": "ISC",
"license": "MIT",
"devDependencies": {
"babel-core": "^6.18.0",
"babel-preset-es2015": "^6.18.0",
"mocha": "^3.1.2"
"eslint": "^3.8.1",
"eslint-config-airbnb-base": "^9.0.0",
"eslint-plugin-import": "^2.0.1",
"mocha": "^3.1.2",
"uglify-js": "^2.7.4"
}
}
An extremely lightweight CLI options parser.
Treats everything as if a string. Doesn't allow multiple uses of same option (as in `-a b -a c` or `--ab c --ab d`). Doesn't allow use of `=` to assign value to option (as in `-a=b` or `-ab=b`). Doesn't allow number immediately following single-letter option (as in `-a13`). Doesn't allow dotted option (as in `-a.b` or `--ab.c`).
In node, command line input is passed to application as an array. Tiny Opts Parser takes this array as its first argument, and an options object as its (optional) second argument. Tiny Opts Parser returns an object that maps the name of each argument or option to its value. The output will be exactly the same as the output of all the popular JS CLI parsers like Commander, Minimist, and Yargs.
For those who are new to CLI options parsing, the process can get quite complicated. For example, if someone types the following on the command line: `mycommand -a -bcd def xyz --abcd`, the parser needs to know turn this into the following object:
```js
{
_: ['xyz'],
a: true,
b: true,
c: true,
d: 'def',
abcd: true,
}
```

Sorry, the diff of this file is not supported yet