UNPKG

738 BTypeScriptView Raw
1/**
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
8It 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
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*/
39export default function hasFlag(flag: string, argv?: readonly string[]): boolean;