You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

has-flag

Package Overview
Dependencies
Maintainers
3
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

has-flag

Check if argv has a specific flag


Version published
Weekly downloads
247M
increased by0.55%
Maintainers
3
Install size
4.20 kB
Created
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

Package last updated on 07 Jul 2015

Did you know?

Socket

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
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc