# has-flag

> Check if argv has a specific flag

Latest version **5.0.1** (published 2021-07-19) · MIT license · 0 weekly downloads

> **Better alternative:** Use process.argv.includes('--flag') — Consider using a lighter alternative

## Install

```sh
npm install has-flag
pnpm add has-flag
yarn add has-flag
bun add has-flag
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.0.1 |
| Published | 2021-07-19 |
| First published | 2015-07-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Node | >=12 |
| Dependencies | 0 |
| Unpacked size | 4.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 95 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | has, check, detect, contains, find, flag, cli, command-line, argv, process, arg, args, argument, arguments, getopt, minimist, optimist |

## Links

- npm: https://www.npmjs.com/package/has-flag
- Repository: https://github.com/sindresorhus/has-flag
- Homepage: https://github.com/sindresorhus/has-flag#readme
- Issues: https://github.com/sindresorhus/has-flag/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/has-flag

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 5.0.1 (latest) — 2021-07-19
- 5.0.0 — 2021-04-16
- 4.0.0 — 2019-04-06
- 3.0.0 — 2018-01-02
- 2.0.0 — 2016-04-11
- 1.0.0 — 2015-07-07

## README

# has-flag

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

## Install

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

## Usage

```js
// 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.

---

<div align="center">
	<b>
		<a href="https://tidelift.com/subscription/pkg/npm-has-flag?utm_source=npm-has-flag&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
	</b>
	<br>
	<sub>
		Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
	</sub>
</div>

---
_Source: https://npm.io/package/has-flag · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
