main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
986 bytes
|
Rev | Line | |
---|
[d565449] | 1 | # has-flag [![Build Status](https://travis-ci.org/sindresorhus/has-flag.svg?branch=master)](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 |
|
---|
| 5 | Correctly 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
|
---|
| 19 | const hasFlag = require('has-flag');
|
---|
| 20 |
|
---|
| 21 | hasFlag('unicorn');
|
---|
| 22 | //=> true
|
---|
| 23 |
|
---|
| 24 | hasFlag('--unicorn');
|
---|
| 25 | //=> true
|
---|
| 26 |
|
---|
| 27 | hasFlag('f');
|
---|
| 28 | //=> true
|
---|
| 29 |
|
---|
| 30 | hasFlag('-f');
|
---|
| 31 | //=> true
|
---|
| 32 |
|
---|
| 33 | hasFlag('foo=bar');
|
---|
| 34 | //=> true
|
---|
| 35 |
|
---|
| 36 | hasFlag('foo');
|
---|
| 37 | //=> false
|
---|
| 38 |
|
---|
| 39 | hasFlag('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 |
|
---|
| 52 | Returns a boolean for whether the flag exists.
|
---|
| 53 |
|
---|
| 54 | #### flag
|
---|
| 55 |
|
---|
| 56 | Type: `string`
|
---|
| 57 |
|
---|
| 58 | CLI flag to look for. The `--` prefix is optional.
|
---|
| 59 |
|
---|
| 60 | #### argv
|
---|
| 61 |
|
---|
| 62 | Type: `string[]`<br>
|
---|
| 63 | Default: `process.argv`
|
---|
| 64 |
|
---|
| 65 | CLI arguments.
|
---|
| 66 |
|
---|
| 67 |
|
---|
| 68 | ## License
|
---|
| 69 |
|
---|
| 70 | MIT © [Sindre Sorhus](https://sindresorhus.com)
|
---|
Note:
See
TracBrowser
for help on using the repository browser.