Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Generated on May 16, 2024 via pnpm

optionator 0.9.3

option parsing and help generation
Package summary
Share
0
issues
1
license
7
MIT
Package created
2 Nov 2013
Version published
28 Jun 2023
Maintainers
1
Total deps
7
Direct deps
6
License
MIT

Issues

0
This package has no issues

Licenses

MIT License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
sublicense
private-use
Cannot
hold-liable
Must
include-copyright
include-license
7 Packages, Including:
@aashutoshrathi/word-wrap@1.2.6
deep-is@0.1.4
fast-levenshtein@2.0.6
levn@0.4.1
optionator@0.9.3
prelude-ls@1.2.1
type-check@0.4.0
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

6
All Dependencies CSV
β“˜ This is a list of optionator 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities
@aashutoshrathi/word-wrap1.2.64.03 kBMIT
prod
deep-is0.1.43.32 kBMIT
prod
fast-levenshtein2.0.63.61 kBMIT
prod
levn0.4.17.29 kBMIT
prod
prelude-ls1.2.19.19 kBMIT
prod
type-check0.4.06.62 kBMIT
prod

Visualizations

Frequently Asked Questions

What does optionator do?

Optionator is a powerful JavaScript/Node.js library designed for option parsing and help generation. By ensuring that only valid input is accepted, Optionator minimizes the potential for errors in your application. For instance, if an option is mistyped, Optionator will show an error along with a suggestion for the intended option. Similarly, if an option's argument is of the wrong type, Optionator will reject it rather than letting it destabilize your application. Optionator's help text adapts to fit different sizes of console windows and its flexible input options (arrays, strings, or objects) greatly facilitate testing. This makes Optionator a practical solution for developers who require rigorous, adaptable, and easy-to-use parsing capabilities.

How do you use optionator?

To utilize Optionator in your project, you need to first install it by using the npm install command: npm install optionator. After the installation is complete, you can start using Optionator in your code. Here is an example of how to initialize and use Optionator:

var optionator = require('optionator')({
    prepend: 'Usage: cmd [options]',
    append: 'Version 1.0.0',
    options: [{
        option: 'help',
        alias: 'h',
        type: 'Boolean',
        description: 'displays help'
    }, {
        option: 'count',
        alias: 'c',
        type: 'Int',
        description: 'number of things',
        example: 'cmd --count 2'
    }]
});

var options = optionator.parseArgv(process.argv);
if (options.help) {
    console.log(optionator.generateHelp());
}

In this code snippet, optionator is required and configured with options. The parseArgv function is then used to parse the command-line arguments, and the results are stored in the options variable. If the --help option is given, optionator.generateHelp() is used to display the help message.

The parse function can process your input according to the specified settings:

parse(['node', 't.js', '--count', '2', 'positional']); // {count: 2, _: ['positional']}
parse('--count 2 positional');                         // {count: 2, _: ['positional']}
parse({count: 2, _:['positional']});                   // {count: 2, _: ['positional']}

The generateHelp function produces help text based on your specified settings:

generateHelp(); /*
"Usage: cmd [options] positional

  -h, --help       displays help
  -c, --count Int  number of things

Version  1.0.0
"*/

Use generateHelpForOption to produce expanded help text for a specific option:

generateHelpForOption('count'); /*
"-c, --count Int
description: number of things
example: cmd --count 2
"*/

Where are the optionator docs?

For a comprehensive guide on using Optionator, consult the official GitHub repository at git://github.com/gkz/optionator.git. Here you'll find a detailed specification of option settings, argument formatting, and more. It also provides information about the algorithms and libraries used behind the scenes. The usage guides and examples should provide you with all the information needed to begin implementing Optionator in your projects.