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 🙏

© 2026 – Pkg Stats / Ryan Hefner

argvparser

v1.0.4

Published

Simple argument parser

Readme

ArgvParser

Simple command line argument parser. Allows the easy specification of required and optional arguments for command line utilities.

Installation

$ npm i argvparser --save

Usage

var ArgvParser = require('argvparser'),
    program = new ArgvParser();

program.register('<required_arg> [optional_arg]', function (rarg, oarg, options, flags) {
    console.log('Required Arg: ', rarg);
    console.log('Optional Arg: ', oarg);
});

// Register calls can be chained [ArgvParser::register() returns instance of ArgvParser]
program
    .register('test [optional_arg] --test', function (oarg, options, flags) {
        // flags.test === true or false
        console.log('Optional Argument', oarg);
    })
    .register('test2 -o:2 <required_tuple, 3>', function (tuple, options, flags) {
        // options.o.length === 3 (if option o is given)
        // tuple.length == 3
        console.log('Tuple Argument', tuple);
    });

// to actually parse arguments call ArgvParser::parse()
program.parse();

API

ArgvParser::register(cmd_template, cb, [failCb])

cmd_template: a string giving the command template. See command template grammer for full details. Some notes:

  • Flag and option ids must start with a letter and only contain letters and numbers.
  • Arguments with sequence modifier (... or ..INT) passed to callback in arrays.
  • Arguments with tuple modifier (<ID, INT> or [ID, INT]) passed to callback in arrays.
  • So <ID, 2>..2 would be passed to callback as an array of arrays of two element ([[1, 2], [1, 2]]).
  • Options expect 1 argument by default. Can be changed with quantifier (-option_name:INT).
  • INT > 0

cb: callback to be called when a command matches the given template. cb passed required and optional arguments followed by a maps of options and flags. See more examples for more details.

failCb: optional failure callback. If specified, will be called with error that occured. Otherwise, if not given, error is thrown. An example error that could occur: new Error('Not enough arguments given for option test;')

More Examples

Assume script is located in ./script Command template following by script calls and corresponding argument values.

program.register('<required_arg> -o [optional_arg]...', function (rarg, oarg, options, flags) {
    ...
});

$ ./script arg1 arg2 arg3
    rarg = 'arg1'
    oarg = ['arg2', 'arg3']
    options = {
        o: undefined
    }
    flags = {}

$ ./script arg1 arg2 -o test
    rarg = 'arg1'
    oarg = 'arg2'
    options = {
        o: 'test'
    }
    flags = {}
program.register('<required_arg>..2 -o:2 --flag [optional_arg, 2]...', function (rarg, oarg, options, flags) {
    ...
});

$ ./script arg1 arg2 arg3 arg4
    rarg = ['arg1', 'arg2']
    oarg = [['arg3', 'arg4']]
    options = {
        o: undefined
    }
    flags = {
        flag: false
    }

$ ./script arg1 arg2 -o test --flag
    rarg = ['arg1', 'arg2']
    oarg = undefined
    options = {
        o: 'test'
    }
    flags = {
        flag: true
    }

Command Template Grammar

ε corresponds to the empty string.

template = ids aofs
ids = id ids
    = ε
aofs = aof aofs
     = lastaof
aof = rarg
    = option
    = flag
rarg = <ID>
     = <ID, INT>
     = <ID>..INT
     = <ID, INT>..INT
option = -ID
       = -ID:INT
flag = --ID
lastaof = lastarg ofs
ofs = option ofs
    = flag ofs
    = ε
lastarg = rarg
        = <ID>...
        = <ID, INT>...
        = [ID]
        = [ID, INT]
        = [ID]..INT
        = [ID, INT]..INT
        = [ID]...
        = [ID, INT]...

Infinite and optional arguments must appear last.

License

MIT