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 2.0.0 to 2.1.0

11

bin/nopt.js

@@ -10,3 +10,7 @@ #!/usr/bin/env node

, "bool-list": [Boolean, Array]
, str: String }
, str: String
, clear: Boolean
, config: Boolean
, length: Number
}
, shorthands = { s: [ "--str", "astring" ]

@@ -19,3 +23,6 @@ , b: [ "--bool" ]

, H: ["--help"]
, n: [ "--num", "125" ] }
, n: [ "--num", "125" ]
, c: ["--config"]
, l: ["--length"]
}
, parsed = nopt( types

@@ -22,0 +29,0 @@ , shorthands

72

lib/nopt.js

@@ -53,3 +53,3 @@ // info about each config option.

var remove = {}
, typeDefault = [false, true, null, String, Number]
, typeDefault = [false, true, null, String, Number, Array]

@@ -248,2 +248,3 @@ Object.keys(data).forEach(function (k) {

}
// see if it's a shorthand

@@ -273,2 +274,9 @@ // if so, splice and back up to re-parse it.

// allow unknown things to be arrays if specified multiple times.
if (!types.hasOwnProperty(arg) && data.hasOwnProperty(arg)) {
if (!Array.isArray(data[arg]))
data[arg] = [data[arg]]
isArray = true
}
var val

@@ -347,28 +355,39 @@ , la = args[i + 1]

arg = arg.replace(/^-+/, '')
if (abbrevs[arg] && !shorthands[arg]) {
// first check to see if this arg is a set of single-char shorthands
var singles = shorthands.___singles
if (!singles) {
singles = Object.keys(shorthands).filter(function (s) {
return s.length === 1
}).reduce(function (l,r) {
l[r] = true
return l
}, {})
shorthands.___singles = singles
debug('shorthand singles', singles)
}
var chrs = arg.split("").filter(function (c) {
return singles[c]
})
if (chrs.join("") === arg) return chrs.map(function (c) {
return shorthands[c]
}).reduce(function (l, r) {
return l.concat(r)
}, [])
// if it's an arg abbrev, and not a literal shorthand, then prefer the arg
if (abbrevs[arg] && !shorthands[arg])
return null
}
if (shortAbbr[arg]) {
// if it's an abbr for a shorthand, then use that
if (shortAbbr[arg])
arg = shortAbbr[arg]
} else {
var singles = shorthands.___singles
if (!singles) {
singles = Object.keys(shorthands).filter(function (s) {
return s.length === 1
}).reduce(function (l,r) { l[r] = true ; return l }, {})
shorthands.___singles = singles
}
var chrs = arg.split("").filter(function (c) {
return singles[c]
})
if (chrs.join("") === arg) return chrs.map(function (c) {
return shorthands[c]
}).reduce(function (l, r) {
return l.concat(r)
}, [])
}
if (shorthands[arg] && !Array.isArray(shorthands[arg])) {
// make it an array, if it's a list of words
if (shorthands[arg] && !Array.isArray(shorthands[arg]))
shorthands[arg] = shorthands[arg].split(/\s+/)
}
return shorthands[arg]

@@ -540,2 +559,7 @@ }

,[]]
,["-cl 1"
,{config: true, length: 1}
,[]
,{config: Boolean, length: Number, clear: Boolean}
,{c: "--config", l: "--length"}]
].forEach(function (test) {

@@ -545,3 +569,3 @@ var argv = test[0].split(/\s+/)

, rem = test[2]
, actual = nopt(types, shorthands, argv, 0)
, actual = nopt(test[3] || types, test[4] || shorthands, argv, 0)
, parsed = actual.argv

@@ -548,0 +572,0 @@ delete actual.argv

{
"name": "nopt",
"version": "2.0.0",
"version": "2.1.0",
"description": "Option parsing for Node, supporting types, shorthands, etc. Used by npm.",

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

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