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

@joro/optimist

v0.1.7

Published

Optimize options list

Readme

Simply maps common command-line options to an object, turning their values to literal types.

Table of Contents

Usage

Install Optimist using npm:

npm install --save-dev @joro/optimist

Or yarn:

yarn add --dev @joro/optimist

Get started by simply requiring optimist module and define an optional default values:

const optimist = require('@joro/optimist');

const defaults = {
  option1: 'string',
  option2: [true, false],
  option3: {
    defaults: -1.1,
    aliases: 'opt3'
  },
  option4: {
    defaults: [null, undefined],
    aliases: ['opt4']
  }
};

console.log(optimist(process.argv.slice(2), defaults));

Now, if we execute our script with the following arguments:

node <script.js> --option1 string --option2 -opt3 -1.1 -opt4=undefined

It will output an optimized representation of the given options:

{
  _: [],
  option1: 'string',
  option2: true,
  option3: -1.1,
  option4: undefined
}

Options and Values

Valid options syntax are marked with a -- or -, and values are separated with a space or =. Single options are parsed with an implicit true value.

Number values like -1.1 are treated as both an option or a value depending on the position of arguments, e.g in -123=value and --option=-123, the former is an option name while the latter is a value. Values such as boolean, number, null, or undefined types are parsed as literals. Others will remain as raw string.

Defaults and Aliases

Referring to the above example, the given defaults are used to determine if the actual command-line arguments contains valid or invalid options as well as provide default values to those options not explicitly specified. Such defaults are defined as the following:

  • option1: Represents an option with a single default value.
    • Matches: --option1 'string' or --option1=string
  • option2: Represents an option with multiple required values.
    • Matches: --option2 or --option2=false
  • option3: Represents an option with a single default value including an alias.
    • Matches: --option3 -1.1 or -opt3=-1.1
  • option4: Represents an option with multiple required values including an alias.
    • Matches: --option4 null or -opt4=undefined

Note: For multiple values, the actual default value is the first element (index [0]), e.g in [true, false], true is the default value.

Note: Use the aliases property to define a name alias. Doing so, will let you use the defaults property for default values. Aliases will always return their exact option name, e.g, --opt3=value will return option3:value.

Returned Value

The returned object contains an option:value pairs including a ['_'] property containing a list of all invalid options. An invalid option is captured if its name or value is not defined in the defaults. If there are no provided defaults, then only the syntax will be parsed.

References

Optimist is designed to be just simple. If you didn't find what you're looking for, try minimist instead.

Contributing

Fork or star this repository to give a positive feedback :heavy_heart_exclamation:. Send bug reports, and other issues here.

License

Copyright 2020 Jōro. Use of this source code is governed by the MIT license that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.