
Security News
Open Source Maintainers Feeling the Weight of the EU’s Cyber Resilience Act
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
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 641 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
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.