pax_global_header00006660000000000000000000000064134521451660014521gustar00rootroot0000000000000052 comment=474aa39afca7333d356c022fc5be4d31732bbba3 has-flag-4.0.0/000077500000000000000000000000001345214516600132045ustar00rootroot00000000000000has-flag-4.0.0/.editorconfig000066400000000000000000000002571345214516600156650ustar00rootroot00000000000000root = 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-4.0.0/.gitattributes000066400000000000000000000000231345214516600160720ustar00rootroot00000000000000* text=auto eol=lf has-flag-4.0.0/.gitignore000066400000000000000000000000271345214516600151730ustar00rootroot00000000000000node_modules yarn.lock has-flag-4.0.0/.npmrc000066400000000000000000000000231345214516600143170ustar00rootroot00000000000000package-lock=false has-flag-4.0.0/.travis.yml000066400000000000000000000000541345214516600153140ustar00rootroot00000000000000language: node_js node_js: - '10' - '8' has-flag-4.0.0/index.d.ts000066400000000000000000000012541345214516600151070ustar00rootroot00000000000000/** 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. @example ``` // $ ts-node foo.ts -f --unicorn --foo=bar -- --rainbow // foo.ts import 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 ``` */ declare function hasFlag(flag: string, argv?: string[]): boolean; export = hasFlag; has-flag-4.0.0/index.js000066400000000000000000000005121345214516600146470ustar00rootroot00000000000000'use strict'; module.exports = (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-4.0.0/index.test-d.ts000066400000000000000000000002351345214516600160620ustar00rootroot00000000000000import {expectType} from 'tsd'; import hasFlag = require('.'); expectType(hasFlag('unicorn')); expectType(hasFlag('unicorn', ['--foo'])); has-flag-4.0.0/license000066400000000000000000000021251345214516600145510ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (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-4.0.0/package.json000066400000000000000000000012701345214516600154720ustar00rootroot00000000000000{ "name": "has-flag", "version": "4.0.0", "description": "Check if argv has a specific flag", "license": "MIT", "repository": "sindresorhus/has-flag", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "engines": { "node": ">=8" }, "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": "^1.4.1", "tsd": "^0.7.2", "xo": "^0.24.0" } } has-flag-4.0.0/readme.md000066400000000000000000000031001345214516600147550ustar00rootroot00000000000000# has-flag [![Build Status](https://travis-ci.org/sindresorhus/has-flag.svg?branch=master)](https://travis-ci.org/sindresorhus/has-flag) > Check if [`argv`](https://nodejs.org/docs/latest/api/process.html#process_process_argv) has a specific flag Correctly stops looking after an `--` argument terminator. ---
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.
--- ## Install ``` $ npm install has-flag ``` ## Usage ```js // 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. ## Security To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. ## License MIT © [Sindre Sorhus](https://sindresorhus.com) has-flag-4.0.0/test.js000066400000000000000000000013121345214516600145160ustar00rootroot00000000000000import test from 'ava'; import hasFlag from '.'; 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'])); });