Socket
Socket
Sign inDemoInstall

yargs

Package Overview
Dependencies
Maintainers
3
Versions
250
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yargs - npm Package Compare versions

Comparing version 3.3.1 to 3.4.0

15

index.js

@@ -54,2 +54,3 @@ var path = require('path');

string: [],
narg: {},
key: {},

@@ -88,2 +89,13 @@ alias: {},

self.nargs = function (key, n) {
if (typeof key === 'object') {
Object.keys(key).forEach(function(k) {
self.nargs(k, key[k]);
});
} else {
options.narg[key] = n;
}
return self;
}
self.normalize = function (strings) {

@@ -239,2 +251,5 @@ options.normalize.push.apply(options.normalize, [].concat(strings));

}
if ('nargs' in opt) {
self.nargs(key, opt.nargs);
}
if (opt.boolean || opt.type === 'boolean') {

@@ -241,0 +256,0 @@ self.boolean(key);

76

lib/parser.js

@@ -9,3 +9,2 @@ // fancy-pants parsing of argv, originally forked

if (!opts) opts = {};
var flags = { arrays: {}, bools : {}, strings : {}, counts: {}, normalize: {}, configs: {} };

@@ -92,15 +91,21 @@

var key = arg.match(/^--(.+)/)[1];
var next = args[i + 1];
if (next !== undefined && !next.match(/^-/)
&& !checkAllAliases(key, flags.bools)) {
setArg(key, next);
i++;
if (checkAllAliases(key, opts.narg)) {
i = eatNargs(i, key, args);
} else {
var next = args[i + 1];
if (next !== undefined && !next.match(/^-/)
&& !checkAllAliases(key, flags.bools)) {
setArg(key, next);
i++;
}
else if (/^(true|false)$/.test(next)) {
setArg(key, next);
i++;
}
else {
setArg(key, defaultForType(guessType(key, flags)));
}
}
else if (/^(true|false)$/.test(next)) {
setArg(key, next);
i++;
}
else {
setArg(key, defaultForType(guessType(key, flags)));
}
}

@@ -142,3 +147,2 @@ // dot-notation flag seperated by '='.

}
if (/[A-Za-z]/.test(letters[j])

@@ -150,3 +154,2 @@ && /-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) {

}
if (letters[j+1] && letters[j+1].match(/\W/)) {

@@ -163,15 +166,20 @@ setArg(letters[j], arg.slice(j+2));

var key = arg.slice(-1)[0];
if (!broken && key !== '-') {
if (args[i+1] && !/^(-|--)[^-]/.test(args[i+1])
&& !checkAllAliases(key, flags.bools)) {
setArg(key, args[i+1]);
i++;
if (checkAllAliases(key, opts.narg)) {
i = eatNargs(i, key, args);
} else {
if (args[i+1] && !/^(-|--)[^-]/.test(args[i+1])
&& !checkAllAliases(key, flags.bools)) {
setArg(key, args[i+1]);
i++;
}
else if (args[i+1] && /true|false/.test(args[i+1])) {
setArg(key, args[i+1]);
i++;
}
else {
setArg(key, defaultForType(guessType(key, flags)));
}
}
else if (args[i+1] && /true|false/.test(args[i+1])) {
setArg(key, args[i+1]);
i++;
}
else {
setArg(key, defaultForType(guessType(key, flags)));
}
}

@@ -197,2 +205,16 @@ }

// how many arguments should we consume, based
// on the nargs option?
function eatNargs (i, key, args) {
var toEat = checkAllAliases(key, opts.narg);
if (args.length - (i + 1) < toEat) throw Error('not enough arguments following: ' + key);
for (var ii = i + 1; ii < (toEat + i + 1); ii++) {
setArg(key, args[ii]);
}
return (i + toEat);
}
function setArg (key, val) {

@@ -353,3 +375,3 @@ // handle parsing boolean arguments --foo=true --bar false.

toCheck.forEach(function(key) {
if (flag[key]) isSet = true;
if (flag[key]) isSet = flag[key];
});

@@ -356,0 +378,0 @@

{
"name": "yargs",
"version": "3.3.1",
"version": "3.4.0",
"description": "Light-weight option parsing with an argv hash. No optstrings attached.",

@@ -5,0 +5,0 @@ "main": "./index.js",

@@ -576,2 +576,20 @@ yargs

.nargs(key, count)
-----------
The number of arguments that should be consumed after a key. This can be a
useful hint to prevent parsing ambiguity:
```js
var argv = require('yargs')
.nargs('token', 1)
.parse(['--token', '-my-token']);
```
parses as:
`{ _: [], token: '-my-token', '$0': 'node test' }`
Optionally `.nargs()` can take an object of `key`/`narg` pairs.
.config(key)

@@ -578,0 +596,0 @@ ------------

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc