has-flag (3.0.0)

Published 2026-02-24 13:57:33 +00:00 by atheaadmin

Installation

registry=
npm install has-flag@3.0.0
"has-flag": "3.0.0"

About this package

has-flag Build Status

Check if argv has a specific flag

Correctly stops looking after an -- argument terminator.

Install

$ npm install has-flag

Usage

// foo.js
const hasFlag = require('has-flag');

hasFlag('unicorn');
//=> true

hasFlag('--unicorn');
//=> true

hasFlag('f');
//=> true

hasFlag('-f');
//=> true

hasFlag('foo=bar');
//=> true

hasFlag('foo');
//=> false

hasFlag('rainbow');
//=> false
$ node foo.js -f --unicorn --foo=bar -- --rainbow

API

hasFlag(flag, [argv])

Returns a boolean for whether the flag exists.

flag

Type: string

CLI flag to look for. The -- prefix is optional.

argv

Type: string[]
Default: process.argv

CLI arguments.

License

MIT © Sindre Sorhus

Dependencies

Development Dependencies

ID Version
ava *
xo *

Keywords

has check detect contains find flag cli command-line argv process arg args argument arguments getopt minimist optimist
Details
npm
2026-02-24 13:57:33 +00:00
0
Sindre Sorhus
MIT
1.7 KiB
Assets (1)
Versions (2) View all
4.0.0 2026-02-24
3.0.0 2026-02-24