Name |
Date |
Size |
#Lines |
LOC |
||
---|---|---|---|---|---|---|
.. | - | - | ||||
index.js | D | 12-May-2024 | 320 | 9 | 8 | |
license | D | 12-May-2024 | 1.1 KiB | 10 | 5 | |
package.json | D | 12-May-2024 | 1.6 KiB | 77 | 76 | |
readme.md | D | 12-May-2024 | 986 | 71 | 41 |
readme.md
1# has-flag [](https://travis-ci.org/sindresorhus/has-flag) 2 3> Check if [`argv`](https://nodejs.org/docs/latest/api/process.html#process_process_argv) has a specific flag 4 5Correctly stops looking after an `--` argument terminator. 6 7 8## Install 9 10``` 11$ npm install has-flag 12``` 13 14 15## Usage 16 17```js 18// foo.js 19const hasFlag = require('has-flag'); 20 21hasFlag('unicorn'); 22//=> true 23 24hasFlag('--unicorn'); 25//=> true 26 27hasFlag('f'); 28//=> true 29 30hasFlag('-f'); 31//=> true 32 33hasFlag('foo=bar'); 34//=> true 35 36hasFlag('foo'); 37//=> false 38 39hasFlag('rainbow'); 40//=> false 41``` 42 43``` 44$ node foo.js -f --unicorn --foo=bar -- --rainbow 45``` 46 47 48## API 49 50### hasFlag(flag, [argv]) 51 52Returns a boolean for whether the flag exists. 53 54#### flag 55 56Type: `string` 57 58CLI flag to look for. The `--` prefix is optional. 59 60#### argv 61 62Type: `string[]`<br> 63Default: `process.argv` 64 65CLI arguments. 66 67 68## License 69 70MIT © [Sindre Sorhus](https://sindresorhus.com) 71