Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nopt

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nopt - npm Package Compare versions

Comparing version 1.0.6 to 1.0.7

21

lib/nopt.js

@@ -52,15 +52,28 @@ // info about each config option.

var remove = {}
, typeDefault = [false, true, null, String, Number]
Object.keys(data).forEach(function (k) {
var val = data[k]
, isArray = Array.isArray(val)
, type = types[k]
if (!isArray) val = [val]
if (!type) type = typeDefault
if (type === Array) type = typeDefault.concat(Array)
if (!Array.isArray(type)) type = [type]
debug("val=%j", val)
debug("types=", type)
val = val.map(function (val) {
// if it's an unknown value, then parse false/true/null/numbers
if (typeof val === "string") {
debug("string %j", val)
val = val.trim()
if (val === "null" || val === "true" || val === "false") {
if ((val === "null" && ~type.indexOf(null))
|| (val === "true" &&
(~type.indexOf(true) || ~type.indexOf(Boolean)))
|| (val === "false" &&
(~type.indexOf(false) || ~type.indexOf(Boolean)))) {
val = JSON.parse(val)
} else if (!isNaN(val)) {
debug("jsonable %j", val)
} else if (~type.indexOf(Number) && !isNaN(val)) {
debug("convert to number", val)
val = +val

@@ -341,2 +354,3 @@ }

, aoa: Array
, str: String
, browser : String

@@ -453,2 +467,5 @@ , cache : path

,[]]
,["-str 100"
,{str:"100"}
,[]]
].forEach(function (test) {

@@ -455,0 +472,0 @@ var argv = test[0].split(/\s+/)

2

package.json
{ "name" : "nopt"
, "version" : "1.0.6"
, "version" : "1.0.7"
, "description" : "Option parsing for Node, supporting types, shorthands, etc. Used by npm."

@@ -4,0 +4,0 @@ , "author" : "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)"

@@ -31,2 +31,3 @@ If you want to write an option parser, and have it be good, there are

, "pick" : Boolean
, "many" : [String, Array]
}

@@ -48,29 +49,41 @@ , shortHands = { "foofoo" : ["--foo", "Mr. Foo"]

$ node my-program.js --foo "blerp" --no-flag
{ "foo" : "blerp", "flag" : false }
```bash
$ node my-program.js --foo "blerp" --no-flag
{ "foo" : "blerp", "flag" : false }
$ node my-program.js ---bar 7 --foo "Mr. Hand" --flag
{ bar: 7, foo: "Mr. Hand", flag: true }
$ node my-program.js ---bar 7 --foo "Mr. Hand" --flag
{ bar: 7, foo: "Mr. Hand", flag: true }
$ node my-program.js --foo "blerp" -f -----p
{ foo: "blerp", flag: true, pick: true }
$ node my-program.js --foo "blerp" -f -----p
{ foo: "blerp", flag: true, pick: true }
$ node my-program.js -fp --foofoo
{ foo: "Mr. Foo", flag: true, pick: true }
$ node my-program.js -fp --foofoo
{ foo: "Mr. Foo", flag: true, pick: true }
$ node my-program.js --foofoo -- -fp # -- stops the flag parsing.
{ foo: "Mr. Foo", argv: { remain: ["-fp"] } }
$ node my-program.js --foofoo -- -fp # -- stops the flag parsing.
{ foo: "Mr. Foo", argv: { remain: ["-fp"] } }
$ node my-program.js --blatzk 1000 -fp # unknown opts are ok.
{ blatzk: 1000, flag: true, pick: true }
$ node my-program.js --blatzk 1000 -fp # unknown opts are ok.
{ blatzk: 1000, flag: true, pick: true }
$ node my-program.js --blatzk true -fp # but they need a value
{ blatzk: true, flag: true, pick: true }
$ node my-program.js --blatzk true -fp # but they need a value
{ blatzk: true, flag: true, pick: true }
$ node my-program.js --no-blatzk -fp # unless they start with "no-"
{ blatzk: false, flag: true, pick: true }
$ node my-program.js --no-blatzk -fp # unless they start with "no-"
{ blatzk: false, flag: true, pick: true }
$ node my-program.js --baz b/a/z # known paths are resolved.
{ baz: "/Users/isaacs/b/a/z" }
$ node my-program.js --baz b/a/z # known paths are resolved.
{ baz: "/Users/isaacs/b/a/z" }
# if Array is one of the types, then it can take many
# values, and will always be an array. The other types provided
# specify what types are allowed in the list.
$ node my-program.js --many 1 --many null --many foo
{ many: ["1", "null", "foo"] }
$ node my-program.js --many foo
{ many: ["foo"] }
```
Read the tests at the bottom of `lib/nopt.js` for more examples of

@@ -96,2 +109,5 @@ what this puppy can do.

supply any WriteStream on the `outfd` and `logfd` config options.)
* Array: If `Array` is specified as one of the types, then the value
will be parsed as a list of options. This means that multiple values
can be specified, and that the value will always be an array.

@@ -137,10 +153,14 @@ If a type is an array of values not on this list, then those are

{ "foolhardyelephants" : Boolean
, "pileofmonkeys" : Boolean }
```javascript
{ "foolhardyelephants" : Boolean
, "pileofmonkeys" : Boolean }
```
Then this will work:
node program.js --foolhar --pil
node program.js --no-f --pileofmon
# etc.
```bash
node program.js --foolhar --pil
node program.js --no-f --pileofmon
# etc.
```

@@ -156,12 +176,16 @@ ## Shorthands

{ "s" : ["--loglevel", "silent"]
, "g" : "--global"
, "f" : "--force"
, "p" : "--parseable"
, "l" : "--long"
}
```json
{ "s" : ["--loglevel", "silent"]
, "g" : "--global"
, "f" : "--force"
, "p" : "--parseable"
, "l" : "--long"
}
```
npm ls -sgflp
# just like doing this:
npm ls --loglevel silent --global --force --long --parseable
```bash
npm ls -sgflp
# just like doing this:
npm ls --loglevel silent --global --force --long --parseable
```

@@ -168,0 +192,0 @@ ## The Rest of the args

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