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

@maboiteaspam/show-help

v3.0.0

Published

node module helpers to display help section given command line arguments

Downloads

12

Readme

show-help

node module helper to display help section given command line arguments

Install

npm i @maboiteaspam/show-help --save

Usage

function usage () {/*
    ...some text...
    ...about your program...
*/}
var pkg   = require('./package.json')
var help  = require('@maboiteaspam/show-help')(usage, process.argv, pkg)     // manage -h|--help
var debug = require('@maboiteaspam/set-verbosity')(pkg.name, process.argv);  // manage -v|--verbose [what?]
!argv['_'] && showHelp.print(usage, pkg) && showHelp.die();                  // manage some wrong invocation

Usage

process.argv

Using the node process.argv value

function usage () {/*
module name
        ...

    Usage
        ...

    Options
        ...

    Examples
        ...
*/}

var pkg       = require('./package.json')                           // always useful.
var showHelp  = require('./index.js')                               // load showHelp,
  .tpl('%name %version\n\t%description\n\n%usage')                  // set a different template.
  (usage, process.argv, pkg)                                        // Print help and quit,
                                                                    // if -h|--help.

//require('./index.js')(usage, process.argv, pkg)                   // one-liner

!argv['_']                                                          // if arguments are incorrect,
&& showHelp.print(usage, pkg)                                       // show help,
&& showHelp.die();                                                  // exit.

console.log('program execution')

Which then, can be invoked in such fashion

module-name -h
module-name --help

minimist

Using minimist module to pre parse values

function usage () {/*
module name
        ...

    Usage
        ...

    Options
        ...

    Examples
        ...
*/}
var pkg       = require('./package.json')                           // always useful.
var argv      = require('minimist')(process.argv.slice(2));         // parse args with minimist,
var showHelp  = require('./index.js')                               // load showHelp,
  .tpl('%name %version\n\t%description\n\n%usage')                  // set a different template.
  (usage, argv.h||argv.help, pkg)                                   // Print help and quit,
                                                                    // if -h|--help.

//require('./index.js')(usage, argv.h||argv.help, pkg)              // one-liner

!argv['_']                                                          // if arguments are incorrect,
&& showHelp.print(usage, pkg)                                       // show help,
&& showHelp.die();                                                  // exit.

console.log('program execution')

Which then, can be invoked in such fashion

module-name -h
module-name --help

Api

showHelp

showHelp is a function to display help and exit when needed, it returns showHelp for a fluent interface.

  • showHelp(callable fn, object arg, object pkg, int code) void

When typeof(arg) is object, detect (-h|--help), and figures out if usage should be displayed and program killed.

pkg is object of package.json file.

  • showHelp(callable fn, string arg, object pkg, int code) void

When typeof(arg) is string, and not falsy, it displays usage and kills the program with code.

pkg is object of package.json file.

  • showHelp(callable fn, bool arg, object pkg, int code) void

When typeof(arg) is bool, and not falsy, it displays usage and kills the program with code.

pkg is object of package.json file.

showHelp.tpl

showHelp.tpl is a function to set a template to render usage, it returns showHelp for a fluent interface.

  • showHelp(string newTpl) showHelp

set tpl to newTpl, then returns showHelp for chaining.

showHelp.raw

showHelp.raw is a function to parse a string as a command line input. It detects -h|--help and invoke showHelp.parsed. It returns true, if it has displayed help, otherwise false.

  • showHelp.raw(callable fn, object pkg, string arg) bool

When arg.match(/-h|--help/) is not falsy, it renders and displays usage.

showHelp.parsed

showHelp.parsed is a function to invoke showHelp.print when arg is not falsy. It returns true, if it has displayed help, otherwise false.

  • showHelp.parsed(callable fn, object pkg, string arg) bool

When arg is not falsy, it renders and displays usage.

showHelp.print

showHelp.print is a function to render template given multiline(fn) usage string and pkg object, then prints it on console.error. It returns true, always, for fluent interface with die().

  • showHelp.print(callable fn, object pkg) true

Renders usage then print it on console.error.

showHelp.die

showHelp.die is a function to exist process

  • showHelp.die(int exitCode) void

Exist process.

More

  • https://github.com/sindresorhus/multiline
  • https://nodejs.org/api/process.html#process_process_argv
  • https://github.com/maboiteaspam/npi
  • https://github.com/maboiteaspam/set-verbosity