has-flag

Check if argv has a specific flag

v5.0.1
MIT
hop.js robot avatar

v5.0.1

5.0.1
5.0.0
4.0.0
3.0.0
2.0.0
1.0.0
Download
Install
Files
<!-- hop.js - Package: has-flag  Version: 5.0.1 -->
<script 
	type="text/javascript" 
	src="https://cdn.hopjs.net/npm/has-flag@5.0.1/index.js" 
	crossorigin="anonymous" 
	referrerpolicy="no-referrer">
</script>
<!-- End of package -->

        
Copy the code below and paste it into your HTML file.
The package version has been scanned for malware

Readme

has-flag

Check if argv has a specific flag

Install

$ npm install has-flag

Usage

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

API

hasFlag(flag, argv?)

Returns a boolean for whether the flag exists.

It correctly stops looking after an -- argument terminator.

flag

Type: string

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

argv

Type: string[]
Default: process.argv

CLI arguments.


Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.

Package Info
v5.0.1

No known vulnerabilities
0 Low 0 Medium 0 High 0 Critical
93 stars   0 open issues   5 years since last commit

Include has-flag into your own domain?
Try bunny.net

NPM Statistics

1.6B weekly downloads +21%
14.7B yearly downloads +124%

Dependencies

has-flag does not depend on any external packages.

Tags

  has, check, detect, contains, find, flag, cli, command-line, argv, process, arg, args, argument, arguments, getopt, minimist, optimist      

What is HopJS?

hop.js is a privacy-first CDN service powered by bunny.net, designed to offer a free, industry-leading performance with zero logging.

An unhandled error has occurred. Reload 🗙