index.d.ts 684 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /**
  2. Check if [`argv`](https://nodejs.org/docs/latest/api/process.html#process_process_argv) has a specific flag.
  3. @param flag - CLI flag to look for. The `--` prefix is optional.
  4. @param argv - CLI arguments. Default: `process.argv`.
  5. @returns Whether the flag exists.
  6. @example
  7. ```
  8. // $ ts-node foo.ts -f --unicorn --foo=bar -- --rainbow
  9. // foo.ts
  10. import hasFlag = require('has-flag');
  11. hasFlag('unicorn');
  12. //=> true
  13. hasFlag('--unicorn');
  14. //=> true
  15. hasFlag('f');
  16. //=> true
  17. hasFlag('-f');
  18. //=> true
  19. hasFlag('foo=bar');
  20. //=> true
  21. hasFlag('foo');
  22. //=> false
  23. hasFlag('rainbow');
  24. //=> false
  25. ```
  26. */
  27. declare function hasFlag(flag: string, argv?: string[]): boolean;
  28. export = hasFlag;