blob: a0a48c89112785902cb109a27475840fd0952de8 [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001/**
2Check if [`argv`](https://nodejs.org/docs/latest/api/process.html#process_process_argv) has a specific flag.
3
4@param flag - CLI flag to look for. The `--` prefix is optional.
5@param argv - CLI arguments. Default: `process.argv`.
6@returns Whether the flag exists.
7
8@example
9```
10// $ ts-node foo.ts -f --unicorn --foo=bar -- --rainbow
11
12// foo.ts
13import hasFlag = require('has-flag');
14
15hasFlag('unicorn');
16//=> true
17
18hasFlag('--unicorn');
19//=> true
20
21hasFlag('f');
22//=> true
23
24hasFlag('-f');
25//=> true
26
27hasFlag('foo=bar');
28//=> true
29
30hasFlag('foo');
31//=> false
32
33hasFlag('rainbow');
34//=> false
35```
36*/
37declare function hasFlag(flag: string, argv?: string[]): boolean;
38
39export = hasFlag;