| Leo Repp | 58b9f11 | 2021-11-22 11:57:47 +0100 | [diff] [blame^] | 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 | @example |
| 9 | ``` |
| 10 | // $ ts-node foo.ts -f --unicorn --foo=bar -- --rainbow |
| 11 | |
| 12 | // foo.ts |
| 13 | import hasFlag = require('has-flag'); |
| 14 | |
| 15 | hasFlag('unicorn'); |
| 16 | //=> true |
| 17 | |
| 18 | hasFlag('--unicorn'); |
| 19 | //=> true |
| 20 | |
| 21 | hasFlag('f'); |
| 22 | //=> true |
| 23 | |
| 24 | hasFlag('-f'); |
| 25 | //=> true |
| 26 | |
| 27 | hasFlag('foo=bar'); |
| 28 | //=> true |
| 29 | |
| 30 | hasFlag('foo'); |
| 31 | //=> false |
| 32 | |
| 33 | hasFlag('rainbow'); |
| 34 | //=> false |
| 35 | ``` |
| 36 | */ |
| 37 | declare function hasFlag(flag: string, argv?: string[]): boolean; |
| 38 | |
| 39 | export = hasFlag; |