
Security News
ESLint Adds Official Support for Linting HTML
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
Parse command line arguments. This is a lot like yargs or optimist but not as feature rich.
You can specify flags, aliases, or not. Can pass arrays, strings, and booleans. No dependencies.
If you don't need array arguments, I'd recommend using minimist which is very good.
npm install argv-parse
Say you had a file like foo-bar-qux.js
which needed to parse arguments:
var argv = require('argv-parse')
// accepts a definition object and args
// if args is undefined, defaults to process.argv.slice(2)
var args = argv({
foo: {
type: 'boolean',
alias: 'f'
},
bar: {
type: 'string',
alias: 'b'
},
qux: {
type: 'array',
alias: 'q'
},
norf: {
type: 'boolean',
alias: 'n'
}
})
console.dir(args)
$ node foo-bar-qux.js --foo
{
foo: true
}
$ node foo-bar-qux.js --bar hey
{
bar: 'hey'
}
$ node foo-bar-qux.js --qux thing1 thing2 thing3
{
qux: ['thing1', 'thing2', 'thing3']
}
$ node foo-bar-qux.js -f -b hey -q thing1 thing2 thing3
{
foo: true,
bar: 'hey',
qux: ['thing1', 'thing2', 'thing3']
}
$ node foo-bar-qux.js -fn
{
foo: true,
norf: true
}
$ node foo-bar-qux.js not specified
{
_: ['not', 'specified']
}
$ node foo-bar-qux.js --unknown surprise
{
unknown: 'surprise'
}
If you don't care about aliases or types, you don't actually need to configure anything, argv-parse
will intelligently guess how the unknown flag should be interpreted:
simple.js
var argv = require('argv-parse')
var args = argv()
console.dir(args)
$ node simple.js --unknown
{
unknown: true
}
$ node simple.js --unknown hey
{
unknown: 'hey'
}
$ node simple.js --unknown hey you
{
unknown: ['hey', 'you']
}
$ node simple.js first second --unknown hey you
{
_: ['first', 'second'],
unknown: ['hey', 'you']
}
v1.0.1
FAQs
Parse command line arguments.
The npm package argv-parse receives a total of 431 weekly downloads. As such, argv-parse popularity was classified as not popular.
We found that argv-parse 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
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
Security News
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.