[Pkg-javascript-commits] [node-has-flag] 01/02: Imported Upstream version 2.0.0

Thorsten Alteholz alteholz at moszumanska.debian.org
Sun Jul 17 13:16:18 UTC 2016


This is an automated email from the git hooks/post-receive script.

alteholz pushed a commit to branch master
in repository node-has-flag.

commit b1b0dbd460b451d66bd6e807396dec8be15a2ff3
Author: Thorsten Alteholz <debian at alteholz.de>
Date:   Sun Jul 17 15:16:16 2016 +0200

    Imported Upstream version 2.0.0
---
 .editorconfig  | 12 +++++++++++
 .gitattributes |  1 +
 .gitignore     |  1 +
 .travis.yml    |  7 ++++++
 index.js       | 10 +++++++++
 license        | 21 ++++++++++++++++++
 package.json   | 49 ++++++++++++++++++++++++++++++++++++++++++
 readme.md      | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 test.js        | 14 ++++++++++++
 9 files changed, 182 insertions(+)

diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..98a761d
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,12 @@
+root = 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
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..176a458
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+* text=auto
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3c3629e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+node_modules
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..a78e23d
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,7 @@
+sudo: false
+language: node_js
+node_js:
+  - '5'
+  - '4'
+  - '0.12'
+  - '0.10'
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..6882030
--- /dev/null
+++ b/index.js
@@ -0,0 +1,10 @@
+'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);
+};
diff --git a/license b/license
new file mode 100644
index 0000000..654d0bf
--- /dev/null
+++ b/license
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) Sindre Sorhus <sindresorhus at gmail.com> (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.
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..bfcd302
--- /dev/null
+++ b/package.json
@@ -0,0 +1,49 @@
+{
+  "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 at gmail.com",
+    "url": "sindresorhus.com"
+  },
+  "maintainers": [
+    "Sindre Sorhus <sindresorhus at gmail.com> (sindresorhus.com)",
+    "Joshua Appelman <jappelman at xebia.com> (jbnicolai.com)",
+    "JD Ballard <i.am.qix at gmail.com> (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": "*"
+  }
+}
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..0caca6c
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,67 @@
+# 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`<br>
+Default: `process.argv`
+
+CLI arguments.
+
+
+## License
+
+MIT © [Sindre Sorhus](https://sindresorhus.com)
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..4eec5aa
--- /dev/null
+++ b/test.js
@@ -0,0 +1,14 @@
+import 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 --');
+});

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-has-flag.git



More information about the Pkg-javascript-commits mailing list