Socket
Socket
Sign inDemoInstall

dashdash

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dashdash - npm Package Compare versions

Comparing version 1.2.1 to 1.3.0

14

CHANGES.md
# node-dashdash changelog
## 1.3.0
- [Backward incompatible change for boolean envvars] Change the
interpretation of environment variables for boolean options to consider '0'
to be false. Previous to this *any* value to the envvar was considered
true -- which was quite misleading. Example:
$ FOO_VERBOSE=0 node examples/foo.js
# opts: { verbose: [ false ],
_order: [ { key: 'verbose', value: false, from: 'env' } ],
_args: [] }
# args: []
## 1.2.1

@@ -4,0 +18,0 @@

@@ -25,4 +25,12 @@ var dashdash = require('../lib/dashdash');

type: 'string',
env: 'FOO_FILE',
help: 'File to process',
helpArg: 'FILE'
},
{
names: ['timeout', 't'],
type: 'positiveInteger',
env: 'FOO_TIMEOUT',
help: 'Processing timeout in milliseconds',
helpArg: 'MS'
}

@@ -29,0 +37,0 @@ ];

15

lib/dashdash.js
/**
* dashdash - yet another node.js optional parsing library
* dashdash - A light, featureful and explicit option parsing library for
* node.js.
*/

@@ -89,3 +90,3 @@

function parseBool(option, optstr, arg) {
return true;
return Boolean(arg);
}

@@ -415,6 +416,8 @@

addOpt(option, envname, option.key, val, 'env');
} else if (val) {
// For now, we make VAR=<empty-string> NOT set the value
// false. It is as if the VAR was not set.
addOpt(option, envname, option.key, true, 'env');
} else if (val !== '') {
// Boolean envvar handling:
// - VAR=<empty-string> not set (as if the VAR was not set)
// - VAR=0 false
// - anything else true
addOpt(option, envname, option.key, (val !== '0'), 'env');
}

@@ -421,0 +424,0 @@ });

2

package.json
{
"name": "dashdash",
"description": "A light, featureful and explicit option parsing library.",
"version": "1.2.1",
"version": "1.3.0",
"author": "Trent Mick (trentm.com)",

@@ -6,0 +6,0 @@ "repository": {

@@ -169,2 +169,52 @@ A light, featureful and explicit option parsing library for node.js.

Boolean options will interpret the empty string as unset, '0' as false
and anything else as true.
```shell
$ FOO_VERBOSE= node examples/foo.js # not set
# opts: { _order: [], _args: [] }
# args: []
$ FOO_VERBOSE=0 node examples/foo.js # '0' is false
# opts: { verbose: [ false ],
_order: [ { key: 'verbose', value: false, from: 'env' } ],
_args: [] }
# args: []
$ FOO_VERBOSE=1 node examples/foo.js # true
# opts: { verbose: [ true ],
_order: [ { key: 'verbose', value: true, from: 'env' } ],
_args: [] }
# args: []
$ FOO_VERBOSE=boogabooga node examples/foo.js # true
# opts: { verbose: [ true ],
_order: [ { key: 'verbose', value: true, from: 'env' } ],
_args: [] }
# args: []
```
Non-booleans can be used as well. Strings:
```shell
$ FOO_FILE=data.txt node examples/foo.js
# opts: { file: 'data.txt',
_order: [ { key: 'file', value: 'data.txt', from: 'env' } ],
_args: [] }
# args: []
```
Numbers:
```shell
$ FOO_TIMEOUT=5000 node examples/foo.js
# opts: { timeout: 5000,
_order: [ { key: 'timeout', value: 5000, from: 'env' } ],
_args: [] }
# args: []
$ FOO_TIMEOUT=blarg node examples/foo.js
foo: error: arg for "FOO_TIMEOUT" is not a positive integer: "blarg"
```
With the `includeEnv: true` config to `parser.help()` the environment

@@ -171,0 +221,0 @@ variable can also be included in **help output**:

@@ -514,9 +514,7 @@ /*

argv: 'node foo.js',
// No '0' or 'false' interp, just empty string or not.
// TODO: still debatable behaviour
env: {FOO_VERBOSE: '0'},
expect: {
v: true,
v: false,
_args: [],
_order: [ {key: 'v', value: true, from: 'env'} ]
_order: [ {key: 'v', value: false, from: 'env'} ]
}

@@ -523,0 +521,0 @@ },

Sorry, the diff of this file is not supported yet

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