1 | /**
|
2 | Check 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 | It correctly stops looking after an `--` argument terminator.
|
9 |
|
10 | @example
|
11 | ```
|
12 | // $ ts-node foo.ts -f --unicorn --foo=bar -- --rainbow
|
13 |
|
14 | // foo.ts
|
15 | import hasFlag from 'has-flag';
|
16 |
|
17 | hasFlag('unicorn');
|
18 | //=> true
|
19 |
|
20 | hasFlag('--unicorn');
|
21 | //=> true
|
22 |
|
23 | hasFlag('f');
|
24 | //=> true
|
25 |
|
26 | hasFlag('-f');
|
27 | //=> true
|
28 |
|
29 | hasFlag('foo=bar');
|
30 | //=> true
|
31 |
|
32 | hasFlag('foo');
|
33 | //=> false
|
34 |
|
35 | hasFlag('rainbow');
|
36 | //=> false
|
37 | ```
|
38 | */
|
39 | export default function hasFlag(flag: string, argv?: readonly string[]): boolean;
|