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

betterargs

v1.0.4

Published

Lightweight tool that parses command line arguments and organizes them by flag input.

Downloads

1

Readme

BetterArgs

BetterArgs is a lightweight tool that parses command line arguments and organizes them by flags. Its purpose is to create an easier method for developing command line interfaces.

Example

BetterArgs parses the following command... $ yourcli makeproject TestProj -d ~/desktop --license MIT ...into the following JavaScript object.

{
  0: ['...', '...', 'makeproject', 'TestProj'],
 'd': ['~/desktop'],
 'license': ['MIT']
}

Installation

To use, run npm install betterargs.

Usage

BetterArgs exports three functions alongside the parsed data. The functions are listed below...

  • setGlobalFlag
  • setCommand
  • init

The parsed data is exported as args.

To use BetterArgs install with the command npm install betterargs and require it at the top of the program.

const cli = require('betterargs');

Use the setGlobalFlag and setCommand functions to create a command line interface, and lastly initialize the program using the init function.

Example

const cli = require('betterargs');

cli.setGlobalFlag('version', 'v', (flagData) => {
	console.log('v1.0.0');
}, true);

cli.setCommand('install', (cmdArgs, flagData) => {
	
	// Code block for command implementation

});

cli.setCommand('printParsedInput', (cmdArgs, flagData) => {
	const parsedInput = cli.args;
	console.log(parsedInput);
});

cli.init();

To get hold of the entire object storing the parsed command input, use cli.args.

Functions

BetterArgs exports a few functions which use the parsed data to help create command line interfaces. These functions are listed below...

  • setGlobalFlag
  • setCommand

setGlobalFlag - The setGlobalFlag(name, alias, func, terminating) function sets a flag that may or may not override the command that is entered. The terminating option is what makes the decision of whether or not the program will terminate after the flags function has been executed.

Example

const cli = require('betterargs');

cli.setGlobalFlag('version', 'v', (flagArgs) => {
	console.log('v1.0.0');
}, true);

cli.init();

The above example creates a command line interface that prints the version number whenever the flag -v or --version is typed in the command line. After the version number is printed, the program terminates.

As shown above, setGlobalFlag accepts a function as an argument. That function accepts flagArgs which stores an array holding the data entered between the flag that is being set, and the flag that comes after it.

For further example...

const cli = require('betterargs');

cli.setGlobalFlag('flag', 'f', (flagArgs) => {
	console.log(flagArgs);
}, true);

cli.init();

...the above program will print the flagArgs of the flag named flag whenever the flag has been entered in the command. Below is an example of the command line interface that the program above creates.

Input: $ yourcli --flag arg1 arg1
Output: ['arg1', 'arg2']

setCommand - The setCommand(name, func) function sets a function to a command name. The function being accepted has access to the arguments after the original command, and data holding the parsed flag information.

Example

const cli = require('betterargs');

cli.setCommand('makeproject', (cmdArgs, flagData) => {
	
	const projName = cmdArgs[0];
	const DIR_FLAG = flagData['d'] ? flagData['d'] : flagData['directory'];
	
	/* Check if dir_flag is set */
	if (DIR_FLAG) {
		const _dir = DIR_FLAG[0]; // Get directory input. 
		// Create a new project using the directory
		return;
	}

	/* dir_flag not set */
	// Create new project using defaults.
	
});

cli.init();