
Security News
MCP Community Begins Work on Official MCP Metaregistry
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
minimist-options
Advanced tools
The minimist-options npm package is designed to enhance the functionality of the minimist library, which is a popular argument parser for Node.js. Minimist-options allows for more detailed configuration of command line option parsing, including setting types, defaults, and aliases for options. This makes it easier to build complex command-line interfaces (CLIs) with more readable and maintainable code.
Defining option types
This feature allows you to specify the type of value you expect for an option. For example, defining an option as a 'string' ensures that the parsed value will be treated as a string.
{"optionName": {"type": "string"}}
Setting default values
You can set default values for options, which will be used if the option is not provided by the user. This is useful for providing fallback values and making certain options optional.
{"optionName": {"type": "number", "default": 10}}
Using aliases
Aliases allow you to define short versions of option names, making your CLI easier to use. For example, an option '--name' could have an alias '-n', allowing it to be used interchangeably.
{"optionName": {"alias": "n"}}
Yargs is a comprehensive command-line option parser that offers a rich set of features similar to minimist-options, such as command handling, argument parsing, and validation. It differs in providing a more extensive API and built-in support for generating help messages and command suggestions.
Commander is another popular npm package for building command-line interfaces. It provides a high-level API for defining commands, options, and action handlers. Compared to minimist-options, Commander offers a more object-oriented approach and includes features for auto-generating help information.
Caporal is a robust CLI framework that offers features like argument parsing, validation, auto-help, and auto-completion. While it provides functionalities similar to minimist-options, Caporal focuses more on structuring commands and subcommands in a hierarchical manner, making it suitable for complex CLI applications.
Write options for minimist and yargs in a comfortable way. Supports string, boolean, number and array options.
$ npm install --save minimist-options
const buildOptions = require('minimist-options');
const minimist = require('minimist');
const options = buildOptions({
name: {
type: 'string',
alias: 'n',
default: 'john'
},
force: {
type: 'boolean',
alias: ['f', 'o'],
default: false
},
score: {
type: 'number',
alias: 's',
default: 0
},
arr: {
type: 'array',
alias: 'a',
default: []
},
strings: {
type: 'string-array',
alias: 's',
default: ['a', 'b']
},
booleans: {
type: 'boolean-array',
alias: 'b',
default: [true, false]
},
numbers: {
type: 'number-array',
alias: 'n',
default: [0, 1]
},
published: 'boolean',
// Special option for positional arguments (`_` in minimist)
arguments: 'string'
});
const args = minimist(process.argv.slice(2), options);
instead of:
const minimist = require('minimist');
const options = {
string: ['name', '_'],
number: ['score'],
array: [
'arr',
{key: 'strings', string: true},
{key: 'booleans', boolean: true},
{key: 'numbers', number: true}
],
boolean: ['force', 'published'],
alias: {
n: 'name',
f: 'force',
s: 'score',
a: 'arr'
},
default: {
name: 'john',
f: false,
score: 0,
arr: []
}
};
const args = minimist(process.argv.slice(2), options);
The array
types are only supported by yargs.
minimist does not explicitly support array type options. If you set an option multiple times, it will indeed yield an array of values. However, if you only set it once, it will simply give the value as is, without wrapping it in an array. Thus, effectively ignoring {type: 'array'}
.
{type: 'array'}
is shorthand for {type: 'string-array'}
. To have values coerced to boolean
or number
, use boolean-array
or number-array
, respectively.
MIT © Vadim Demedes
FAQs
Pretty options for minimist
We found that minimist-options demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.