Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
The simplest CLI arguments parser.
npm install --save-prod argcat
import { parseArgs } from 'argcat';
const options = parseArgs(process.argv.slice(2));
Arguments prefixed with a '--'
are treated as options:
parseArgs(['--foo']);
// ⮕ { foo: [] }
Options can have values:
parseArgs(['--foo', 'bar']);
// ⮕ { foo: ['bar'] }
parseArgs(['--foo', '--qux', 'bar']);
// ⮕ { foo: [], qux: ['bar'] }
If an option is repeated multiple times then all values are captured in an array:
parseArgs(['--foo', 'bar', '--foo', 'qux']);
// ⮕ { foo: ['bar', 'qux'] }
Arguments that aren't prefixed with minus chars are stored under ''
key:
parseArgs(['foo', 'bar']);
// ⮕ { '': ['foo', 'bar'] }
There's a special option '--'
, after which all arguments are stored under '--'
key:
parseArgs(['--', '--foo', 'bar']);
// ⮕ { '--': ['--foo', 'bar'] }
Mark an option as a flag to prevent value capturing:
parseArgs(['--foo', 'bar']);
// ⮕ { '--foo': 'bar' }
parseArgs(['--foo', 'bar'], { flags: ['foo'] });
// ⮕ { '--foo': true, '': ['bar'] }
Flag options have true
value instead of an array.
By default, shorthand options are ignored:
parseArgs(['-x']);
// ⮕ {}
To preserve shorthands, use keepShorthands
option:
parseArgs(['-x'], { keepShorthands: true });
// ⮕ { x: [] }
Multiple shorthands can be combined:
parseArgs(['-abc'], { keepShorthands: true });
// ⮕ { a: [], b: [], c: [] }
Use shorthand
mapping to expand shorthands:
parseArgs(['-x'], { shorthands: { x: 'foo' } });
// ⮕ { foo: [] }
argcat doesn't have a special treatment for commands syntax, but it can be easily emulated:
const argv = ['push', '--tags'];
const result = parseArgs(argv, { flags: ['tags'] });
// ⮕ { '': ['push'], tags: true }
The first element of ''
is a command:
const command = result[''].pop();
if (command === 'push') {
// Push it to the limit
}
Note that this approach allows user to specify options before the command:
const result = parseArgs(['--tags', 'push'], { flags: ['tags'] });
// ⮕ { '': ['push'], tags: true }
Combine argcat with Doubter to validate parsed arguments and to coerce their types.
import { parseArgs } from 'argcat';
import * as d from 'doubter';
const argsShape = d.object({
foo: d.number()
});
const options = argsShape.parse(
// 🟡 This comes from process.argv.slice(2)
parseArgs(['--age', '42']),
{ coerce: true }
);
// ⮕ { age: 42 }
Cat by Laura Graves
FAQs
The simplest CLI arguments parser.
The npm package argcat receives a total of 13 weekly downloads. As such, argcat popularity was classified as not popular.
We found that argcat 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.