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.
The has-flag npm package is a simple utility that checks if a specific flag is provided in the command line arguments (process.argv). It is commonly used to determine if a flag is set when running a Node.js script from the terminal.
Check for the presence of a command line flag
This feature allows you to check if a flag, such as '--unicorn', is passed to the script. The code sample demonstrates how to use has-flag to check for the 'unicorn' flag and log a message if it is present.
const hasFlag = require('has-flag');
if (hasFlag('unicorn')) {
console.log('We have a unicorn!');
}
Minimist is a more comprehensive command line argument parsing library. Unlike has-flag, which only checks for the existence of flags, minimist parses all arguments into a structured object, making it easier to work with multiple types of command line parameters.
Commander is a complete solution for building command line applications in Node.js. It provides a high-level API for parsing command line options, as well as a variety of other features such as subcommands and automated help generation. Commander is more feature-rich compared to has-flag, which is focused solely on flag detection.
Yargs is another full-featured command line option parser that offers advanced features like command chaining, argument validation, and automatic help generation. It is more complex and feature-complete than has-flag, which is a minimalistic tool for flag checking.
Check if
argv
has a specific flag
$ npm install has-flag
// foo.js
import hasFlag from 'has-flag';
hasFlag('unicorn');
//=> true
hasFlag('--unicorn');
//=> true
hasFlag('f');
//=> true
hasFlag('-f');
//=> true
hasFlag('foo=bar');
//=> true
hasFlag('foo');
//=> false
hasFlag('rainbow');
//=> false
$ node foo.js -f --unicorn --foo=bar -- --rainbow
Returns a boolean for whether the flag exists.
It correctly stops looking after an --
argument terminator.
Type: string
CLI flag to look for. The --
prefix is optional.
Type: string[]
Default: process.argv
CLI arguments.
FAQs
Check if argv has a specific flag
The npm package has-flag receives a total of 199,665,112 weekly downloads. As such, has-flag popularity was classified as popular.
We found that has-flag 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.