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

argh-2

v0.1.4

Published

light weight option/argv parser for node, it only parses options, nothing more then that.

Downloads

4

Readme

argh!

Build Status

argh is an extremely light weight options or process.argv parser for node.js. It only includes the bare minimal to parse options. It's not a full blown cli library, but it can be used as a dependency of a cli library to do all the heavy lifting.

argh was born out of rage, every cli library that we've found did more than they advertised and added unneeded bloat to what we were trying to achieve... and that was argument parsing. Tiny modules should only focus on one thing and do that one thing really well.

Installation

npm install argh --save

Usage

argh has two functions:

  1. A simple parser interface for custom option parsing using argh(..)
  2. A lazy loaded parsed results for the process.argv using argh.argv
var argh = require('argh');

// You can directly access the parsed arguments of the node process through
console.log(argh.argv);

// This the same result as running
console.log(argh(process.argv));

So what is supported?

  • --arg or -a Is transformed to a boolean (true) if no value is given
  • -abc Is transformed to multiple booleans.
  • --no-arg, --disable-arg Is transformed to a boolean (false)
  • -no-abc, --disable-abc Is transformed to multiple booleans (false)
  • --foo bar, --foo="bar", --foo='bar' or --foo=bar Is all transformed to key / value pairs. Where foo is the key and bar the value
  • --port 1111 Automatically transforms the string 1111 in a number
  • --beer true As you might have guessed it, it's transformed into a boolean
  • -- Can be used as an indicator to stop parsing arguments.

Examples

Everybody likes examples, let's assume that the following code is stored as parse.js:

var argv = require('argh').argv;

console.log(argv);

Parsing a single argument:

$ node parse.js --foo

{ foo: true }

Parsing multiple arguments:

$ node parse.js --foo bar --bar='baz'

{ foo: 'bar', bar: 'baz' }

Parsing multiple boolean arguments:

$ node parse.js --foo --no-bar -s --no-f

{ foo: true,
  bar: false,
  s: true,
  f: false }

Parsing multiple short arguments:

$ node parse.js -abc -no-def

{ a: true, b: true, c: true, d: false, e: false, f: false }

Parsing different values:

$ node parse.js --awesome true --port 1111

{ awesome: true, port: 1111 }

Combining arguments in to an object:

$node parse.js --redis.port 8080 --redis.host localhost

{ redis: { port: 8080, host: 'localhost' }

Handling rest arguments:

$ node parse.js --argh --is --awesome -- 1111 --pewpew aaarrgghh

{ argh: true,
  is: true,
  awesome: true,
  argv: [ '1111', '--pewpew', 'aaarrgghh' ] }

All unknown arguments are also directly pushed in to the argv property:

$ node parse.js --foo 111 bar unkown --hello world BUUURRRRRNN

{ foo: 111,
  argv: [ 'bar', 'unkown', 'BUUURRRRRNN' ],
  hello: 'world' }

License MIT

argh npm cdn at unpkg