pax_global_header00006660000000000000000000000064127027434510014517gustar00rootroot0000000000000052 comment=601137409f2617c75838d8f3febed5c6e6e8ee2c has-flag-2.0.0/000077500000000000000000000000001270274345100132005ustar00rootroot00000000000000has-flag-2.0.0/.editorconfig000066400000000000000000000002761270274345100156620ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [{package.json,*.yml}] indent_style = space indent_size = 2 has-flag-2.0.0/.gitattributes000066400000000000000000000000141270274345100160660ustar00rootroot00000000000000* text=auto has-flag-2.0.0/.gitignore000066400000000000000000000000151270274345100151640ustar00rootroot00000000000000node_modules has-flag-2.0.0/.travis.yml000066400000000000000000000001151270274345100153060ustar00rootroot00000000000000sudo: false language: node_js node_js: - '5' - '4' - '0.12' - '0.10' has-flag-2.0.0/index.js000066400000000000000000000004461270274345100146510ustar00rootroot00000000000000'use strict'; module.exports = function (flag, argv) { argv = argv || process.argv; var terminatorPos = argv.indexOf('--'); var prefix = /^-{1,2}/.test(flag) ? '' : '--'; var pos = argv.indexOf(prefix + flag); return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos); }; has-flag-2.0.0/license000066400000000000000000000021371270274345100145500ustar00rootroot00000000000000The MIT License (MIT) 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-2.0.0/package.json000066400000000000000000000016311270274345100154670ustar00rootroot00000000000000{ "name": "has-flag", "version": "2.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" }, "maintainers": [ "Sindre Sorhus (sindresorhus.com)", "Joshua Appelman (jbnicolai.com)", "JD Ballard (github.com/qix-)" ], "engines": { "node": ">=0.10.0" }, "scripts": { "test": "xo && ava" }, "files": [ "index.js" ], "keywords": [ "has", "check", "detect", "contains", "find", "flag", "cli", "command-line", "argv", "process", "arg", "args", "argument", "arguments", "getopt", "minimist", "optimist" ], "devDependencies": { "ava": "*", "xo": "*" } } has-flag-2.0.0/readme.md000066400000000000000000000017011270274345100147560ustar00rootroot00000000000000# 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. ## Install ``` $ npm install --save has-flag ``` ## Usage ```js // foo.js const hasFlag = require('has-flag'); hasFlag('unicorn'); //=> true hasFlag('--unicorn'); //=> 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 whether the flag exists. #### flag Type: `string` CLI flag to look for. The `--` prefix is optional. #### argv Type: `array`
Default: `process.argv` CLI arguments. ## License MIT © [Sindre Sorhus](https://sindresorhus.com) has-flag-2.0.0/test.js000066400000000000000000000011111270274345100145070ustar00rootroot00000000000000import test from 'ava'; import m from './'; test(t => { t.true(m('unicorn', ['--foo', '--unicorn', '--bar'])); t.true(m('--unicorn', ['--foo', '--unicorn', '--bar']), 'optional prefix'); t.true(m('unicorn=rainbow', ['--foo', '--unicorn=rainbow', '--bar'])); t.true(m('unicorn', ['--unicorn', '--', '--foo'])); t.true(m('-u', ['-f', '-u', '-b'])); t.true(m('-u', ['-u', '--', '-f'])); t.false(m('unicorn', ['--foo', '--', '--unicorn']), 'don\'t match flags after terminator'); t.false(m('unicorn', ['--foo'])); t.false(m('u', ['-f', '-u', '-b']), 'default prefix is --'); });