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

argvsus

v1.0.0

Published

Flags, arguments, actions, and documentation for `process.argv` in Node.js or io.js

Downloads

2

Readme

Process v1.0.0

Process helps your terminal scripts support flags, arguments, actions, and documentation!

The exported types are Process, Process.Action, and Process.Flag.

var Process = require("Process")

To run the tests:

$ npm install
$ grunt test

To export to js/index.js:

$ grunt export

Example

This is the terminal input:

$ node path/to/npm/bin.js install --global --nodedir path/to/node --force Process

This is what path/to/npm/bin.js looks like:

// Used in the case of a --help flag.
process.help = ["The package manager for Node."]

// Add flags for the primary command (eg: 'npm --version')
process.flags = {
	version: {
		short: "v",
		args: 0,
		help: "Echoes the current version of NPM."
	}
}

// Add subcommands for the primary command (eg: 'npm install')
process.actions = {
	install: {
		short: "i",
		help: "Install the dependencies in the local node_modules folder."
	}
}

// Flags for the 'install' subcommand (eg: 'npm install -g')
process.actions.install.flags = {
	global: {
		short: "g",
		args: 0,
		help: "Installs the given dependencies into the global node_modules folder."
	}
}

require("Process")(process).parse()

These are the new properties available after parse() is called:

process.script = [
	"node",
	"path/to/npm/bin.js"
]

process.actions = [
	"npm", 
	"install"
]

process.flags = {
	global: true,
	nodedir: "path/to/node",
	force: true
}

process.args = [
	"Process"
]

Process.prototype

parse()

Arguments: (ArrayOf(String) or Undefined)

Once you wrap your process object with Process(), call process.parse() and you'll have full access to the properties listed here.

Normally, you won't pass an array of strings to this. Instead, the process.argv array will be used.

Before you call this, make sure you have process.flags, process.actions, process.action, and process.help all set to your liking.

help

Type: String or ArrayOf(String)

A description of your script.

This is shown when the --help flag is passed.

If an array of strings is passed, it is joined with "\n".

flags

Type: Object

Before process.parse():

   The valid flag names and their option objects.

After process.parse():

   The passed flag names and their arguments.

Learn more about Process.Flag.

actions

Type: Object

Before process.parse():

   The valid action names and their option objects.

After process.parse():

   No value.

Learn more about Process.Action.

options

Type: Object

Contains the values of process.flags and process.actions before process.parse() was called.

command

Type: ArrayOf(String)

script

Type: ArrayOf(String)

The command used to run this script. (eg: node path/to/my-module/index.js)

Process.Action

Note: You'll never have to construct one of these on your own. Instead, use process.options.addAction or define process.actions before process.parse().

name

Note: This is implemented, but not yet documented.

help

Note: This is implemented, but not yet documented.

example

Note: This is implemented, but not yet documented.

action

Note: This is implemented, but not yet documented.

actions

Note: This is implemented, but not yet documented.

flags

Note: This is implemented, but not yet documented.

default

Note: This is implemented, but not yet documented.

validate

Note: This is not yet implemented.

transform

Note: This is not yet implemented.

Process.Flag

Note: You'll never have to construct one of these on your own. Instead, use process.options.addFlag or define process.flags before process.parse().

name

The many-letter ID of this Flag.

short

A string to map a single-letter flag (eg: -f) to a many-letter flag (eg: --force).

help

An array of strings to describe what this Flag is used for.

example

An array of strings to describe how to use this Flag.

default

A function that returns a default value.

Only called when this Flag has no arguments.

Can be undefined.

validate

A function that verifies whether this Flag's arguments are valid by returning true or false.

Can be undefined.

Note: Called before the default value is applied to the Flag.

transform

A function that mutates this Flag's arguments and returns a new value.

Can be undefined.

Note: Called after the default value is applied to this Flag.

args

The maximum number of arguments possibly associated with this Flag.