UNPKG

1.22 kBMarkdownView Raw
1# has-flag
2
3> Check if [`argv`](https://nodejs.org/docs/latest/api/process.html#process_process_argv) has a specific flag
4
5## Install
6
7```
8$ npm install has-flag
9```
10
11## Usage
12
13```js
14// foo.js
15import hasFlag from 'has-flag';
16
17hasFlag('unicorn');
18//=> true
19
20hasFlag('--unicorn');
21//=> true
22
23hasFlag('f');
24//=> true
25
26hasFlag('-f');
27//=> true
28
29hasFlag('foo=bar');
30//=> true
31
32hasFlag('foo');
33//=> false
34
35hasFlag('rainbow');
36//=> false
37```
38
39```
40$ node foo.js -f --unicorn --foo=bar -- --rainbow
41```
42
43## API
44
45### hasFlag(flag, argv?)
46
47Returns a boolean for whether the flag exists.
48
49It correctly stops looking after an `--` argument terminator.
50
51#### flag
52
53Type: `string`
54
55CLI flag to look for. The `--` prefix is optional.
56
57#### argv
58
59Type: `string[]`\
60Default: `process.argv`
61
62CLI arguments.
63
64---
65
66<div align="center">
67 <b>
68 <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>
69 </b>
70 <br>
71 <sub>
72 Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
73 </sub>
74</div>