Socket
Socket
Sign inDemoInstall

nopt

Package Overview
Dependencies
Maintainers
0
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.0 to 1.0.1

examples/my-program.js

29

lib/nopt.js
// info about each config option.
var debug = process.env.DEBUG_OPTPARSE
var debug = process.env.DEBUG_NOPT
? function () { console.error.apply(console, arguments) }

@@ -12,3 +12,3 @@ : function () {}

module.exports = exports = optparse
module.exports = exports = nopt
exports.clean = clean

@@ -25,3 +25,3 @@

function optparse (types, shorthands, args, slice) {
function nopt (types, shorthands, args, slice) {
args = args || process.argv

@@ -32,2 +32,4 @@ types = types || {}

debug(types, shorthands, args, slice)
args = args.slice(slice)

@@ -151,2 +153,4 @@ var data = {}

function parse (args, data, remain, types, shorthands) {
debug("parse", args, data, remain)
var key = null

@@ -158,2 +162,4 @@ , abbrevs = abbrev(Object.keys(types))

var arg = args[i]
debug("arg", arg)
if (arg.match(/^-{2,}$/)) {

@@ -175,7 +181,11 @@ // done with keys.

// if so, splice and back up to re-parse it.
var shRes = resolveShort(arg, shorthands, shortAbbr)
var shRes = resolveShort(arg, shorthands, shortAbbr, abbrevs)
debug("arg=%j shRes=%j", arg, shRes)
if (shRes) {
debug(arg, shRes)
args.splice.apply(args, [i, 1].concat(shRes))
i --
continue
if (arg !== shRes[0]) {
i --
continue
}
}

@@ -216,3 +226,3 @@ arg = arg.replace(/^-+/, "")

function resolveShort (arg, shorthands, shortAbbr) {
function resolveShort (arg, shorthands, shortAbbr, abbrevs) {
// handle single-char shorthands glommed together, like

@@ -223,2 +233,5 @@ // npm ls -glp, but only if there is one dash, and only if

arg = arg.replace(/^-+/, '')
if (abbrevs[arg]) {
return null
}
if (shortAbbr[arg]) {

@@ -377,3 +390,3 @@ arg = shortAbbr[arg]

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

@@ -380,0 +393,0 @@ delete actual.argv

{ "name" : "nopt"
, "version" : "1.0.0"
, "version" : "1.0.1"
, "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/)"

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

// my-program.js
var nopt = require("nopt")

@@ -43,2 +44,3 @@ , Stream = require("stream").Stream

, parsed = nopt(knownOpts, shortHands, process.argv, 2)
console.log(parsed)

@@ -45,0 +47,0 @@ This would give you support for any of the following:

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