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 🙏

© 2025 – Pkg Stats / Ryan Hefner

argparce

v1.0.0

Published

Parse command line arguments in nodejs

Downloads

3

Readme

argparce

An easy argument parser for nodejs

Install

npm install --save argparce

Usage

const ArgParser = require('argparce');

API Reference

ArgParser.parse(args, options)

  • args <Array> an array of arguments

  • options <Object>

    • args <Array> an array of argument flag definitions
      • <Object>
        • type <string> The data type of the argument.
          • Valid types are 'string', 'integer', 'uinteger', 'float', 'ufloat', 'url'.
          • 'boolean' arguments do not require a following argument and can be called as --arg (which gives the value true) or --arg=false (which gives the value false)
          • all other argument types must be called either as --arg=value or --arg value
        • name <string> The full name of the argument.
          • Example: 'connect-timeout' will create an argument named --connect-timeout
        • short <string> The short name of the argument.
          • Example: 'v' will create a short argument named -v
        • default <Any> The default value of the argument
    • maxStrays <integer> the maximum number of stray (not attached to flags) arguments allowed, or -1 to allow an infinite amount. Default: 0
    • unmappedArgsDefault <string> the default behavior for handling unrecognized argument flags. Default: null
      • null unrecognized flags will cause an error
      • 'stray' unrecognized flags will be added as stray arguments.
      • 'boolean' unrecognized flags will be read as boolean arguments and added to args in the result
      • 'string' unrecognized flags will be read as string arguments (in the form --arg=<string>)
    • stopAtError <boolean> stop parsing when an error is encountered.
    • stopIfTooManyStrays <boolean> stop parsing when a stray is encountered that can't be added due to maxStrays, and doesn't add an error to errors in the result.
    • errorExitCode <integer> An exit code to exit with if errors occur during parsing, or null to not exit. Default: null
  • Returns <Object>

    • args <Object> An object mapping of argument names to their values
    • errors <Array> An array of string messages for errors that occurred during parsing.
    • endIndex <integer> The args index where parsing stopped, or args.length if parsing completed without stopping
    • strays <Array> An array of stray arguments. Stray arguments are command line parameters that didn't match any arguments defined in options.args. Array is empty by default unless options has some non-default values.
    • stopped <boolean> Indicates if parsing was stopped before finishing

Parses the command line arguments with the given options

  • Example:

    Javascript Code:

    // test.js
    var result = ArgParser.parse(process.argv.slice(2), {
    	args: [
    		{
    			type: 'boolean',
    			name: 'verbose',
    			short: 'v'
    		},
    		{
    			type: 'uinteger',
    			name: 'request-timeout',
    			default: 10000
    		},
    		{
    			type: 'string',
    			name: 'name'
    		}
    	],
    	maxStrays: 2,
    	stopAtError: true
    });
    console.log(result);

    Command Line:

    node test.js --request-timeout=23470 "bing" --verbose "bang" --name "hello world" "bong"

    Output:

    {
    	"args": {
    		"request-timeout": 23470,
    		"verbose": true,
    		"name": "hello world"
    	},
    	"strays": ["bing", "bang"],
    	"errors": ["invalid argument bong"],
    	"stopped": true,
    	"endIndex": 6
    }

ArgParser.validate(type, value)

  • type The argument type to valid
    • Valid types are 'string', 'integer', 'uinteger', 'float', 'ufloat', 'url'.
  • value The value to validate against the type
  • Returns: The validated value, or null if validation failed

Validate a value against a type.