pax_global_header00006660000000000000000000000064140753154370014523gustar00rootroot0000000000000052 comment=0c7d032214c51d14b458364c9f6575ea9afa08b1 has-flag-5.0.1/000077500000000000000000000000001407531543700132105ustar00rootroot00000000000000has-flag-5.0.1/.editorconfig000066400000000000000000000002571407531543700156710ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 has-flag-5.0.1/.gitattributes000066400000000000000000000000231407531543700160760ustar00rootroot00000000000000* text=auto eol=lf has-flag-5.0.1/.github/000077500000000000000000000000001407531543700145505ustar00rootroot00000000000000has-flag-5.0.1/.github/funding.yml000066400000000000000000000001621407531543700167240ustar00rootroot00000000000000github: sindresorhus open_collective: sindresorhus tidelift: npm/has-flag custom: https://sindresorhus.com/donate has-flag-5.0.1/.github/security.md000066400000000000000000000002631407531543700167420ustar00rootroot00000000000000# Security Policy To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. has-flag-5.0.1/.github/workflows/000077500000000000000000000000001407531543700166055ustar00rootroot00000000000000has-flag-5.0.1/.github/workflows/main.yml000066400000000000000000000006451407531543700202610ustar00rootroot00000000000000name: CI on: - push - pull_request jobs: test: name: Node.js ${{ matrix.node-version }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: node-version: - 14 - 12 steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: node-version: ${{ matrix.node-version }} - run: npm install - run: npm test has-flag-5.0.1/.gitignore000066400000000000000000000000271407531543700151770ustar00rootroot00000000000000node_modules yarn.lock has-flag-5.0.1/.npmrc000066400000000000000000000000231407531543700143230ustar00rootroot00000000000000package-lock=false has-flag-5.0.1/index.d.ts000066400000000000000000000013421407531543700151110ustar00rootroot00000000000000/** Check if [`argv`](https://nodejs.org/docs/latest/api/process.html#process_process_argv) has a specific flag. @param flag - CLI flag to look for. The `--` prefix is optional. @param argv - CLI arguments. Default: `process.argv`. @returns Whether the flag exists. It correctly stops looking after an `--` argument terminator. @example ``` // $ ts-node foo.ts -f --unicorn --foo=bar -- --rainbow // foo.ts import hasFlag from 'has-flag'; hasFlag('unicorn'); //=> true hasFlag('--unicorn'); //=> true hasFlag('f'); //=> true hasFlag('-f'); //=> true hasFlag('foo=bar'); //=> true hasFlag('foo'); //=> false hasFlag('rainbow'); //=> false ``` */ export default function hasFlag(flag: string, argv?: readonly string[]): boolean; has-flag-5.0.1/index.js000066400000000000000000000006271407531543700146620ustar00rootroot00000000000000import process from 'process'; // eslint-disable-line node/prefer-global/process export default function hasFlag(flag, argv = process.argv) { const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--'); const position = argv.indexOf(prefix + flag); const terminatorPosition = argv.indexOf('--'); return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition); } has-flag-5.0.1/index.test-d.ts000066400000000000000000000002401407531543700160620ustar00rootroot00000000000000import {expectType} from 'tsd'; import hasFlag from './index.js'; expectType(hasFlag('unicorn')); expectType(hasFlag('unicorn', ['--foo'])); has-flag-5.0.1/license000066400000000000000000000021351407531543700145560ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (https://sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. has-flag-5.0.1/package.json000066400000000000000000000014501407531543700154760ustar00rootroot00000000000000{ "name": "has-flag", "version": "5.0.1", "description": "Check if argv has a specific flag", "license": "MIT", "repository": "sindresorhus/has-flag", "funding": "https://github.com/sponsors/sindresorhus", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, "type": "module", "exports": "./index.js", "engines": { "node": ">=12" }, "scripts": { "test": "xo && ava && tsd" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "has", "check", "detect", "contains", "find", "flag", "cli", "command-line", "argv", "process", "arg", "args", "argument", "arguments", "getopt", "minimist", "optimist" ], "devDependencies": { "ava": "^3.15.0", "tsd": "^0.14.0", "xo": "^0.38.2" } } has-flag-5.0.1/readme.md000066400000000000000000000023061407531543700147700ustar00rootroot00000000000000# has-flag > Check if [`argv`](https://nodejs.org/docs/latest/api/process.html#process_process_argv) has a specific flag ## Install ``` $ npm install has-flag ``` ## Usage ```js // foo.js import hasFlag from '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. It correctly stops looking after an `--` argument terminator. #### flag Type: `string` CLI flag to look for. The `--` prefix is optional. #### argv Type: `string[]`\ Default: `process.argv` CLI arguments. ---
Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.
has-flag-5.0.1/test.js000066400000000000000000000013231407531543700145240ustar00rootroot00000000000000import test from 'ava'; import hasFlag from './index.js'; test('main', t => { t.true(hasFlag('unicorn', ['--foo', '--unicorn', '--bar'])); t.true(hasFlag('--unicorn', ['--foo', '--unicorn', '--bar']), 'optional prefix'); t.true(hasFlag('unicorn=rainbow', ['--foo', '--unicorn=rainbow', '--bar'])); t.true(hasFlag('unicorn', ['--unicorn', '--', '--foo'])); t.false(hasFlag('unicorn', ['--foo', '--', '--unicorn']), 'don\'t match flags after terminator'); t.false(hasFlag('unicorn', ['--foo'])); t.true(hasFlag('-u', ['-f', '-u', '-b'])); t.true(hasFlag('-u', ['-u', '--', '-f'])); t.true(hasFlag('u', ['-f', '-u', '-b'])); t.true(hasFlag('u', ['-u', '--', '-f'])); t.false(hasFlag('f', ['-u', '--', '-f'])); });