Sha256: 9855507d638613cbb56c6e43b5aa3c8c18e0263be9a08c1c0cacfc002ab7fc25

Contents?: true

Size: 986 Bytes

Versions: 178

Compression:

Stored size: 986 Bytes

Contents

# has-flag [![Build Status](https://travis-ci.org/sindresorhus/has-flag.svg?branch=master)](https://travis-ci.org/sindresorhus/has-flag)

> Check if [`argv`](https://nodejs.org/docs/latest/api/process.html#process_process_argv) has a specific flag

Correctly stops looking after an `--` argument terminator.


## Install

```
$ npm install has-flag
```


## Usage

```js
// foo.js
const hasFlag = require('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.

#### flag

Type: `string`

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

#### argv

Type: `string[]`<br>
Default: `process.argv`

CLI arguments.


## License

MIT © [Sindre Sorhus](https://sindresorhus.com)

Version data entries

178 entries across 177 versions & 21 rubygems

Version Path
immosquare-cleaner-0.1.60 node_modules/@babel/highlight/node_modules/chalk/node_modules/supports-color/node_modules/has-flag/readme.md
immosquare-cleaner-0.1.59 node_modules/@babel/highlight/node_modules/chalk/node_modules/supports-color/node_modules/has-flag/readme.md
immosquare-cleaner-0.1.58 node_modules/@babel/highlight/node_modules/chalk/node_modules/supports-color/node_modules/has-flag/readme.md
immosquare-cleaner-0.1.57 node_modules/@babel/highlight/node_modules/chalk/node_modules/supports-color/node_modules/has-flag/readme.md
immosquare-cleaner-0.1.56 node_modules/@babel/highlight/node_modules/chalk/node_modules/supports-color/node_modules/has-flag/readme.md
immosquare-cleaner-0.1.55 node_modules/@babel/highlight/node_modules/chalk/node_modules/supports-color/node_modules/has-flag/readme.md
immosquare-cleaner-0.1.54 node_modules/@babel/highlight/node_modules/chalk/node_modules/supports-color/node_modules/has-flag/readme.md
immosquare-cleaner-0.1.53 node_modules/@babel/highlight/node_modules/chalk/node_modules/supports-color/node_modules/has-flag/readme.md
immosquare-cleaner-0.1.52 node_modules/@babel/highlight/node_modules/chalk/node_modules/supports-color/node_modules/has-flag/readme.md
trusty-cms-6.3.1 node_modules/has-flag/readme.md
immosquare-cleaner-0.1.51 node_modules/@babel/highlight/node_modules/chalk/node_modules/supports-color/node_modules/has-flag/readme.md
boring_generators-0.15.0 tmp/templates/app_template/node_modules/has-flag/readme.md
clapton-0.0.26 lib/clapton/javascripts/node_modules/@babel/highlight/node_modules/has-flag/readme.md
clapton-0.0.25 lib/clapton/javascripts/node_modules/@babel/highlight/node_modules/has-flag/readme.md
immosquare-cleaner-0.1.50 node_modules/@babel/highlight/node_modules/chalk/node_modules/supports-color/node_modules/has-flag/readme.md
clapton-0.0.24 lib/clapton/javascripts/node_modules/@babel/highlight/node_modules/has-flag/readme.md
clapton-0.0.23 lib/clapton/javascripts/node_modules/@babel/highlight/node_modules/has-flag/readme.md
clapton-0.0.22 lib/clapton/javascripts/node_modules/@babel/highlight/node_modules/has-flag/readme.md
clapton-0.0.21 lib/clapton/javascripts/node_modules/@babel/highlight/node_modules/has-flag/readme.md
clapton-0.0.20 lib/clapton/javascripts/node_modules/@babel/highlight/node_modules/has-flag/readme.md