npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kssfilo/getopt

v0.3.0

Published

NodeJS command line 'parser' (forked for -- separator support from great dresende's version)

Downloads

2

Readme

@kssfilo/getopt (forked from dresende's getopt)

API

setopt(options, [arguments])

Set the options for your program. If arguments is not set, process.argv is used.

Options is a string containing letters that correspond to the options you want. If a letter is proceeded by a :, the option has a required argument. If a letter is proceeded by double :, the option has an optional argument.

This function throws exceptions when an invalid option is set and when a required option is not set.

getopt(callback)

Callback will be called with 2 arguments, where the first is the option name (a letter) and the second is the option parameter(s) or the number of times the option has appeared.

Example

An example is worth 1000 words..

$ test.js -ab -c 34 -d

var opt = require('getopt');

try {
	opt.setopt("abc:d::");  //-a -b is boolean, -c needs string -d accepts string but can be omitted
} catch (e) {
	// exceptions object {type:<string>,opt:<string>} are thrown when an invalid option
	// is set or a required parameter is not set
	console.dir(e);
}

opt.getopt(function (o, p) {
	switch (o) {
		case "a":
		case "b":
			console.log("option %s set", o);  //p is number of count of the option
			break;
		case "c":
			console.log("option c param = '%s'", p[0]);  //if user specified multiple times. p[1],p[2],... are used.
			break;
		case "d":
			if(p[0].length==0){
				console.log("option d set without string"); //p==[""] in this case
			}else{
				console.log("option d param = '%s'", p[0]); 
			}
			break;
	}
});

About this version

This is forked version of dresende's great getopt module for double hyphen separator (--) support.

Difference from original version is

  • if double hyphen (--) is in arguments , remaining arguments will be pushed into the params array which able to get from opt.param() evenif that is started from hyphen(-)
  • also stores double hyphen "--" into param() array for detecting separation point from user program.

e.g.

$ userprogram.js -a -b file1 -- file2 -a -c

will be

console.log(opt.params());  #after opt.setopt(..)
["file1","--","file2","-a","-c"]

I think that it is "breaking changes". so publishing by myself.

Change Log

  • 0.3.x : removes script name from param() array.
  • 0.2.x : @kssfilo's version
  • 0.1.0 : dresende's version