
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
npm-remaining-args
Advanced tools
Simplify use of remaining args in npm scripts
This package provides a simple command that can be used inside npm scripts to grab all the remaining arguments passed to npm run
. These can then be inserted anywhere in the command, not just at the end.
$ npm install --save-dev npm-remaining-args
$ yarn add --dev npm-remaining-args
The npm-remaining-args
command will print all the remaining arguments from the npm
invocation.
{
...
"scripts": {
"start": "echo started && echo $(npm-remaining-args) && echo done && npm-no-args"
}
...
}
$ npm run start -- Hello World
first Hello World last
The npm-arg
command will extract a single named argument from the npm
invocation.
{
...
"scripts": {
"start": "echo first $(npm-arg --my-arg) last && npm-no-args"
}
...
}
$ npm run start -- --arg1 x --my-arg "Hello World" --arg2 y
first Hello World last
$ npm run start -- --arg1 x --my-arg --arg2 y
first last
Adding a default value will print the default value if the argument is absent.
{
...
"scripts": {
"start": "echo first $(npm-arg --my-arg:default-value) last && npm-no-args"
}
...
}
$ npm run start -- --arg1 x --my-arg "Hello World" --arg2 y
first Hello World last
$ npm run start -- --arg1 x --arg2 y
first default-value last
$ npm run start -- --arg1 x --my-arg --arg2 y
first last
The npm-fwd
command will forward a single named argument from the npm
invocation. This is basically a shortcut for --my-arg $(npm-arg --my-arg)
, except that it handles missing values and default values.
{
...
"scripts": {
"start": "echo first $(npm-fwd --my-arg) last && npm-no-args"
}
...
}
$ npm run start -- --arg1 x --my-arg "Hello World" --arg2 y
first --my-arg Hello World last
$ npm run start -- --arg1 x --arg2 y
first last
{
...
"scripts": {
"start": "echo first $(npm-fwd --my-arg:default-value) last && npm-no-args"
}
...
}
$ npm run start -- --arg1 x --my-arg "Hello World" --arg2 y
first --my-arg Hello World last
$ npm run start -- --arg1 x --arg2 y
first --my-arg default-value last
$ npm run start -- --arg1 x --my-arg --arg2 y
first --my-arg last
FAQs
Simplify use of remaining args in npm scripts
We found that npm-remaining-args 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.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.