Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Process command line arguments with complete control over how they are interpreted by defining a function to handle each parsed value.
npm install argv-walk
or
yarn add argv-walk
const walkArgv = require('argv-walk');
const args = { _: [] };
walkArgv(process.argv.slice(2), {
onArg: (arg) => {
if (arg.key) {
args[arg.key] = arg.value;
} else {
args._.push(arg.item);
}
}
});
argv-walk is a lower level package than minimist so it has no concept of abstractions like aliases or types other than string and boolean.
This package is most useful when you would like to to provide your own implementations of such abstractions (or don't need them).
walkArgv
▸ walkArgv(argv
: string[], options
: Options): void
Iterate over argv
array and call options.onArg
for each parsed argument.
Uses minimist parsing conventions with the following differences:
--foo.bar
) are NOT treated differently than other arguments (when processing the preceding example, the argument key
would be "foo.bar"
)Returns: void
Options
Propertiesboolean
▸ boolean?: true | string | string[]
Optional: Key or array of keys to always treat as booleans, or true
If true, all double hyphenated arguments without equal signs are treated as boolean (e.g. affects --foo
, not -f
or --foo=bar
).
onArg
▸ onArg(arg: Arg): boolean | undefined | void
Called with each argument
Returns: If false is returned, the walk will stop (no further args will be processed)
Arg
Propertiesitem
▸ item: string
Current
argv
item
index
▸ index: number
Current
argv
index
indexOffset
▸ indexOffset: number
1 if
value
is based on the nextargv
item, otherwise 0
compoundIndex
▸ compoundIndex: number | undefined
Current compound index if argument is a compound argument (ex.
-abc
), otherwise undefined
Example: When processing -abc
, a
would have compoundIndex
0, b
would have compoundIndex
1 and so on. The index
value for all three keys would be the same (in this case 0).
isShort
▸ isShort: boolean
true if argument used short syntax (ex.
-k
or-abc
), otherwise false
isStrict
▸ isStrict: boolean
true if argument used strict syntax (ex.
--key=value
or-k=value
), otherwise false
key
▸ key: null | string
Parsed argument name
"--"
for all arguments after --
is encounteredvalue
▸ value: boolean | string
Parsed value for key
test
)git clone https://github.com/adamjarret/argv-walk.git
cd argv-walk
yarn
If you use VS Code, see .vscode/settings.sample.json for recommended project settings.
yarn test
yarn fix
Runs all the scripts required to format and check the module.
yarn lint
Runs eslint
(see eslint) on all javascript files not ignored in the .eslintignore file.
See .eslintrc.js for configuration.
yarn pretty
Runs prettier
(see prettier) to check source code file format. Files with the extensions ts, js, json or md that are not ignored in the .eslintignore file are processed.
See .prettierrc.js for configuration.
yarn spell
Runs cspell
(see cspell) to spell-check source code files.
See .vscode/cSpell.json for configuration.
Note: This configuration path is used so the settings can also be honored by the Code Spell Checker plugin for VS Code.
yarn ncu
Runs ncu
(see npm-check-updates) to check for dependency updates.
Use the -u
flag to update version numbers in package.json file.
Any additional arguments will be passed to the ncu
command.
yarn test
Runs all unit tests with spooning.
yarn cover
Same as yarn test
but also collects and outputs test coverage information.
FAQs
Walk an argv array with a handler function using minimist conventions
The npm package argv-walk receives a total of 118 weekly downloads. As such, argv-walk popularity was classified as not popular.
We found that argv-walk 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
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.