[Pkg-javascript-commits] [node-requires-port] 01/04: Imported Upstream version 0.0.1

Thorsten Alteholz alteholz at moszumanska.debian.org
Sat Feb 6 18:43:36 UTC 2016


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

alteholz pushed a commit to branch master
in repository node-requires-port.

commit 63c62b57f12be9dba4ec22f141adde26a2a301bc
Author: Thorsten Alteholz <debian at alteholz.de>
Date:   Sat Feb 6 19:43:28 2016 +0100

    Imported Upstream version 0.0.1
---
 .npmignore   |  2 ++
 .travis.yml  | 28 +++++++++++++++++
 LICENSE      | 22 ++++++++++++++
 README.md    | 47 +++++++++++++++++++++++++++++
 index.js     | 38 +++++++++++++++++++++++
 package.json | 47 +++++++++++++++++++++++++++++
 test.js      | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 282 insertions(+)

diff --git a/.npmignore b/.npmignore
new file mode 100644
index 0000000..ba2a97b
--- /dev/null
+++ b/.npmignore
@@ -0,0 +1,2 @@
+node_modules
+coverage
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..22ebb02
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,28 @@
+language: node_js
+node_js:
+  - "0.12"
+  - "0.11"
+  - "0.10"
+  - "0.9"
+  - "0.8"
+  - "iojs-v1.1"
+  - "iojs-v1.0"
+before_install:
+  - "npm install -g npm at 1.4.x"
+script:
+  - "npm run test-travis"
+after_script:
+  - "npm install coveralls at 2.11.x && cat coverage/lcov.info | coveralls"
+matrix:
+  fast_finish: true
+  allow_failures:
+    - node_js: "0.11"
+    - node_js: "0.9"
+    - node_js: "iojs-v1.1"
+    - node_js: "iojs-v1.0"
+notifications:
+  irc:
+    channels:
+      - "irc.freenode.org#unshift"
+    on_success: change
+    on_failure: change
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..6dc9316
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,22 @@
+The MIT License (MIT)
+
+Copyright (c) 2015 Unshift.io, Arnout Kazemier,  the Contributors.
+
+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/README.md b/README.md
new file mode 100644
index 0000000..3effe75
--- /dev/null
+++ b/README.md
@@ -0,0 +1,47 @@
+# requires-port
+
+[![Made by unshift](https://img.shields.io/badge/made%20by-unshift-00ffcc.svg?style=flat-square)](http://unshift.io)[![Version npm](http://img.shields.io/npm/v/requires-port.svg?style=flat-square)](http://browsenpm.org/package/requires-port)[![Build Status](http://img.shields.io/travis/unshiftio/requires-port/master.svg?style=flat-square)](https://travis-ci.org/unshiftio/requires-port)[![Dependencies](https://img.shields.io/david/unshiftio/requires-port.svg?style=flat-square)](https://da [...]
+
+The module name says it all, check if a protocol requires a given port.
+
+## Installation
+
+This module is intended to be used with browserify or Node.js and is distributed
+in the public npm registry. To install it simply run the following command from
+your CLI:
+
+```j
+npm install --save requires-port
+```
+
+## Usage
+
+The module exports it self as function and requires 2 arguments:
+
+1. The port number, can be a string or number.
+2. Protocol, can be `http`, `http:` or even `https://yomoma.com`. We just split
+   it at `:` and use the first result. We currently accept the following
+   protocols:
+   - `http`
+   - `https`
+   - `ws`
+   - `wss`
+   - `ftp`
+   - `gopher`
+   - `file`
+
+It returns a boolean that indicates if protocol requires this port to be added
+to your URL.
+
+```js
+'use strict';
+
+var required = require('requires-port');
+
+console.log(required('8080', 'http')) // true
+console.log(required('80', 'http'))   // false
+```
+
+# License
+
+MIT
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..9ecfae3
--- /dev/null
+++ b/index.js
@@ -0,0 +1,38 @@
+'use strict';
+
+/**
+ * Check if we're required to add a port number.
+ *
+ * @see https://url.spec.whatwg.org/#default-port
+ * @param {Number|String} port Port number we need to check
+ * @param {String} protocol Protocol we need to check against.
+ * @returns {Boolean} Is it a default port for the given protocol
+ * @api private
+ */
+module.exports = function required(port, protocol) {
+  protocol = protocol.split(':')[0];
+  port = +port;
+
+  if (!port) return false;
+
+  switch (protocol) {
+    case 'http':
+    case 'ws':
+    return port !== 80;
+
+    case 'https':
+    case 'wss':
+    return port !== 443;
+
+    case 'ftp':
+    return port !== 22;
+
+    case 'gopher':
+    return port !== 70;
+
+    case 'file':
+    return false;
+  }
+
+  return port !== 0;
+};
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..4159070
--- /dev/null
+++ b/package.json
@@ -0,0 +1,47 @@
+{
+  "name": "requires-port",
+  "version": "0.0.1",
+  "description": "Check if a protocol requires a certain port number to be added to an URL.",
+  "main": "index.js",
+  "scripts": {
+    "100%": "istanbul check-coverage --statements 100 --functions 100 --lines 100 --branches 100",
+    "test": "mocha test.js",
+    "watch": "mocha --watch test.js",
+    "coverage": "istanbul cover ./node_modules/.bin/_mocha -- test.js",
+    "test-travis": "istanbul cover node_modules/.bin/_mocha --report lcovonly -- test.js"
+  },
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/unshiftio/requires-port"
+  },
+  "keywords": [
+    "port",
+    "require",
+    "http",
+    "https",
+    "ws",
+    "wss",
+    "gopher",
+    "file",
+    "ftp",
+    "requires",
+    "requried",
+    "portnumber",
+    "url",
+    "parsing",
+    "validation",
+    "cows"
+  ],
+  "author": "Arnout Kazemier",
+  "license": "MIT",
+  "bugs": {
+    "url": "https://github.com/unshiftio/requires-port/issues"
+  },
+  "homepage": "https://github.com/unshiftio/requires-port",
+  "devDependencies": {
+    "assume": "1.1.x",
+    "istanbul": "0.3.x",
+    "mocha": "2.1.x",
+    "pre-commit": "1.0.x"
+  }
+}
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..abd6bcb
--- /dev/null
+++ b/test.js
@@ -0,0 +1,98 @@
+describe('requires-port', function () {
+  'use strict';
+
+  var assume = require('assume')
+    , required = require('./');
+
+  it('is exported as a function', function () {
+    assume(required).is.a('function');
+  });
+
+  it('does not require empty ports', function () {
+    assume(required('', 'http')).false();
+    assume(required('', 'wss')).false();
+    assume(required('', 'ws')).false();
+    assume(required('', 'cowsack')).false();
+  });
+
+  it('assumes true for unknown protocols',function () {
+    assume(required('808', 'foo')).true();
+    assume(required('80', 'bar')).true();
+  });
+
+  it('never requires port numbers for file', function () {
+    assume(required(8080, 'file')).false();
+  });
+
+  it('does not require port 80 for http', function () {
+    assume(required('80', 'http')).false();
+    assume(required(80, 'http')).false();
+    assume(required(80, 'http://')).false();
+    assume(required(80, 'http://www.google.com')).false();
+
+    assume(required('8080', 'http')).true();
+    assume(required(8080, 'http')).true();
+    assume(required(8080, 'http://')).true();
+    assume(required(8080, 'http://www.google.com')).true();
+  });
+
+  it('does not require port 80 for ws', function () {
+    assume(required('80', 'ws')).false();
+    assume(required(80, 'ws')).false();
+    assume(required(80, 'ws://')).false();
+    assume(required(80, 'ws://www.google.com')).false();
+
+    assume(required('8080', 'ws')).true();
+    assume(required(8080, 'ws')).true();
+    assume(required(8080, 'ws://')).true();
+    assume(required(8080, 'ws://www.google.com')).true();
+  });
+
+  it('does not require port 443 for https', function () {
+    assume(required('443', 'https')).false();
+    assume(required(443, 'https')).false();
+    assume(required(443, 'https://')).false();
+    assume(required(443, 'https://www.google.com')).false();
+
+    assume(required('8080', 'https')).true();
+    assume(required(8080, 'https')).true();
+    assume(required(8080, 'https://')).true();
+    assume(required(8080, 'https://www.google.com')).true();
+  });
+
+  it('does not require port 443 for wss', function () {
+    assume(required('443', 'wss')).false();
+    assume(required(443, 'wss')).false();
+    assume(required(443, 'wss://')).false();
+    assume(required(443, 'wss://www.google.com')).false();
+
+    assume(required('8080', 'wss')).true();
+    assume(required(8080, 'wss')).true();
+    assume(required(8080, 'wss://')).true();
+    assume(required(8080, 'wss://www.google.com')).true();
+  });
+
+  it('does not require port 22 for ftp', function () {
+    assume(required('22', 'ftp')).false();
+    assume(required(22, 'ftp')).false();
+    assume(required(22, 'ftp://')).false();
+    assume(required(22, 'ftp://www.google.com')).false();
+
+    assume(required('8080', 'ftp')).true();
+    assume(required(8080, 'ftp')).true();
+    assume(required(8080, 'ftp://')).true();
+    assume(required(8080, 'ftp://www.google.com')).true();
+  });
+
+  it('does not require port 70 for gopher', function () {
+    assume(required('70', 'gopher')).false();
+    assume(required(70, 'gopher')).false();
+    assume(required(70, 'gopher://')).false();
+    assume(required(70, 'gopher://www.google.com')).false();
+
+    assume(required('8080', 'gopher')).true();
+    assume(required(8080, 'gopher')).true();
+    assume(required(8080, 'gopher://')).true();
+    assume(required(8080, 'gopher://www.google.com')).true();
+  });
+});

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



More information about the Pkg-javascript-commits mailing list