Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
minimist-subcommand
Advanced tools
A simple sub-command parser for minimist
npm install --save minimist-subcommand
basic.js
:
var parseArgs = require('minimist');
var parseCommands = require('minimist-subcommand');
// parse sub-commands
var commandDefinition = {
commands: {
foo: null,
bar: null
}
};
var parsedCommandsAndArgv = parseCommands(commandDefinition, process.argv.slice(2));
// pass parsed argv to minimist
var options = parseArgs(parsedCommandsAndArgv.argv);
console.log('sub-command:', parsedCommandsAndArgv.commands);
console.log('parsed options by minimist:', options);
$ node ./basic.js foo arg -a -b val -c
sub-command: [ 'foo' ]
parsed options by minimist: { _: [ 'arg' ], a: true, b: 'val', c: true }
$ node ./basic.js arg -a
sub-command: []
parsed options by minimist: { _: [ 'arg' ], a: true }
$ node ./basic.js bar foo
sub-command: [ 'bar' ]
parsed options by minimist: { _: [ 'foo' ] }
nested-commands.js
:
var parseArgs = require('minimist');
var parseCommands = require('minimist-subcommand');
// parse sub-commands
var commandDefinition = {
commands: {
singleton: null,
married: {
commands: {
child: {
commands: {
grandchild: null
}
}
}
}
}
};
var parsedCommandsAndArgv = parseCommands(commandDefinition, process.argv.slice(2));
// pass parsed argv to minimist
var options = parseArgs(parsedCommandsAndArgv.argv);
console.log('commands:', parsedCommandsAndArgv.commands);
console.log('parsed options by minimist:', options);
$ node ./nested-commands.js married child grandchild arg -a
commands: [ 'married', 'child', 'grandchild' ]
parsed options by minimist: { _: [ 'arg' ], a: true }
$ node ./nested-commands.js singleton child grandchild
commands: [ 'singleton' ]
parsed options by minimist: { _: [ 'child', 'grandchild' ] }
use-default-option.js
:
var parseArgs = require('minimist');
var parseCommands = require('minimist-subcommand');
// parse sub-commands
var commandDefinition = {
default: 'bar',
commands: {
foo: null,
bar: null
}
};
var parsedCommandsAndArgv = parseCommands(commandDefinition, process.argv.slice(2));
// pass parsed argv to minimist
var options = parseArgs(parsedCommandsAndArgv.argv);
console.log('sub-command:', parsedCommandsAndArgv.commands);
console.log('parsed options by minimist:', options);
$ node ./use-default-option.js arg -a
sub-command: [ 'bar' ]
parsed options by minimist: { _: [ 'arg' ], a: true }
Please, look at JSON Schema in source code now.
FAQs
A simple sub-command parser for minimist
The npm package minimist-subcommand receives a total of 2,243 weekly downloads. As such, minimist-subcommand popularity was classified as popular.
We found that minimist-subcommand 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 researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.