Socket
Socket
Sign inDemoInstall

has-flag

Package Overview
Dependencies
0
Maintainers
3
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

has-flag

Check if argv has a specific flag


Version published
Maintainers
3
Weekly downloads
230,343,105
decreased by-10.05%

Weekly downloads

Package description

What is has-flag?

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.

What are has-flag's main functionalities?

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!');
}

Other packages similar to has-flag

Readme

Source

has-flag Build Status

Check if argv has a specific flag

Correctly stops looking after an -- argument terminator.

Install

$ npm install --save has-flag

Usage

// 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

API

hasFlag(flag, [argv])

Returns a boolean whether the flag exists.

flag

Type: string

CLI flag to look for. The -- prefix is optional.

argv

Type: array
Default: process.argv

CLI arguments.

License

MIT © Sindre Sorhus

Keywords

FAQs

Last updated on 07 Jul 2015

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc