Security News
New Proposed CISA Mandate Would Require Critical Infrastructure to Report Ransom Payments Within 24 Hours
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
has-flag
Advanced tools
Check if argv has a specific flag
Weekly downloads
Package description
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.
Readme
Check if
argv
has a specific flag
Correctly stops looking after an --
argument terminator.
$ npm install --save has-flag
// foo.js
var hasFlag = require('has-flag');
hasFlag('unicorn');
//=> true
hasFlag('--unicorn');
//=> true
hasFlag('foo=bar');
//=> true
hasFlag('foo');
//=> false
hasFlag('rainbow');
//=> false
$ node foo.js --unicorn --foo=bar -- --rainbow
Returns a boolean whether the flag exists.
Type: string
CLI flag to look for. The --
prefix is optional.
Type: array
Default: process.argv
CLI arguments.
MIT © Sindre Sorhus
FAQs
Check if argv has a specific flag
The npm package has-flag receives a total of 189,618,088 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.
Security News
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
Security News
Redis is no longer OSS, breaking its explicit commitment to remain under the BSD 3-Clause License forever. This has angered contributors who are now working to fork the software.
Product
Socket AI now enables 'AI detected potential malware' alerts by default, ensuring users benefit from AI-powered state-of-the-art malware detection without needing to opt-in.