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

cli-params

v1.2.1

Published

cli-params is a simple module that helps your CLI tool parse command line arguments and build parameters format to test if cmd is valid

Readme

cli-params

cli-params is a simple module that helps your CLI tool parse command line arguments and build parameters format to test if cmd is valid

Installation

npm i cli-params

Usage

cli-params works on both regular package and globally installed one.

Simple Method

Dead simple, use it on the fly.

# node
node index.js --p1 --p2 hello
# global
your-cli-tool --p1 --p2 hello
import CLIParams from 'cli-params';

new CLIParams().exec((err, params) => {
    if (err) return console.log(err);
    console.log(params);
});
{ "p1": true, "p2": "hello" }

Prebuilt Format

Use add method to add format(s).

node index.js -d -i --id scrwdrv --bonus 12.0
const cliParams = new CLIParams();

cliParams.add({
    params: [
        {
            param: 'debug',
            type: 'boolean', // true or false, no given value will be treated as `true`
            optional: true, // boolean is optional by default, no param means `false`
            alias: 'd'
        },
        {
            param: 'interval',
            type: 'int', // no floating point is allowed,
            default: 50, // default value when value is not given
            alias: 'i'
        },
        {
            param: 'id',
            type: 'string'
        },
        {
            param: 'bonus',
            type: 'float', // allow both int and float
            optional: false // which is default
        }
    ]
}, (err) => {
    if (err) return console.log(err);
    cliParams.exec((err, params) => {
        if (err) return console.log(err);
        console.log(params);
    });
});
{ "debug": true, "interval": 50, "id": "scrwdrv", "bonus": 12 }

Types for Param

  • int
  • float
  • string
  • boolean
  • array-of-int (not available for Target)
  • array-of-float (not available for Target)
  • array-of-string (not available for Target)
  • array-of-boolean (not available for Target)

Mutiple Formats

You can pass formats in an array, by array index order, formats will be used to parse given parameters and callback the first successfully parsed one.

node index.js -h
cliParams.add([
    {
        params: [
            {
                param: 'input',
                type: 'string',
                alias: 'i'
            },
            {
                param: 'password',
                type: 'string',
                optional: true,
                alias: 'p'
            }
        ],
        id: 'regular' // id is not optional when multiple formats are submitted
    },
    {
        params: {
            param: 'help',
            type: 'boolean',
            alias: 'h'
        },
        id: 'help' // id is not optional when multiple formats are submitted
    },
    {
        params: {
            param: 'version',
            type: 'boolean',
            alias: 'v'
        },
        id: 'version' // id is not optional when multiple formats are submitted
    }
]).exec((err, params, id) => {
    if (err) return console.log(err);
    console.log(id);
    // output: help
    console.log(params);
});
{ "help": true }

Trailing Param (Target)

Parameter with no name and located at the end of command line will be treated as Target. Every cmd can only have one target and need to be named beforehand.

node index.js -r 50 https://google.com
cliParams.add({
    params:
    {
        param: 'rate',
        type: 'int',
        alias: 'r'
    },
    target: {
        param: 'url',
        type: 'string',
        optional: false // which is default
    }
}, (err) => {
    if (err) return console.log(err);
    cliParams.exec((err, params) => {
        if (err) return console.log(err);
        console.log(params);
    });
});
{ "url": "https://google.com", "rate": 50 }

Array of ...

Passing multiple values with space as separator to a single parameter.

node index.js -i 1 2 3 4 5 -s google yahoo myTarget 
new CLIParams().add({
    params: [
        {
            param: 'intArr',
            type: 'array-of-int',
            alias: 'i'
        }, {
            param: 'stringArr',
            type: 'array-of-string',
            alias: 's'
        }
    ],
    target: {
        param: 'target',
        type: 'string'
    }
}).exec(async (err, params) => {
    if (err) return console.log(err);
    console.log(params);
});
{ "target": "myTarget", "intArr": [ 1, 2, 3, 4, 5 ], "stringArr": [ "google", "yahoo" ] }