1 |
3a515b92
|
cagy
|
# requires-port
|
2 |
|
|
|
3 |
|
|
[](http://unshift.io)[](http://browsenpm.org/package/requires-port)[](https://travis-ci.org/unshiftio/requires-port)[](https://david-dm.org/unshiftio/requires-port)[](https://coveralls.io/r/unshiftio/requires-port?branch=master)[](http://webchat.freenode.net/?channels=unshift)
|
4 |
|
|
|
5 |
|
|
The module name says it all, check if a protocol requires a given port.
|
6 |
|
|
|
7 |
|
|
## Installation
|
8 |
|
|
|
9 |
|
|
This module is intended to be used with browserify or Node.js and is distributed
|
10 |
|
|
in the public npm registry. To install it simply run the following command from
|
11 |
|
|
your CLI:
|
12 |
|
|
|
13 |
|
|
```j
|
14 |
|
|
npm install --save requires-port
|
15 |
|
|
```
|
16 |
|
|
|
17 |
|
|
## Usage
|
18 |
|
|
|
19 |
|
|
The module exports it self as function and requires 2 arguments:
|
20 |
|
|
|
21 |
|
|
1. The port number, can be a string or number.
|
22 |
|
|
2. Protocol, can be `http`, `http:` or even `https://yomoma.com`. We just split
|
23 |
|
|
it at `:` and use the first result. We currently accept the following
|
24 |
|
|
protocols:
|
25 |
|
|
- `http`
|
26 |
|
|
- `https`
|
27 |
|
|
- `ws`
|
28 |
|
|
- `wss`
|
29 |
|
|
- `ftp`
|
30 |
|
|
- `gopher`
|
31 |
|
|
- `file`
|
32 |
|
|
|
33 |
|
|
It returns a boolean that indicates if protocol requires this port to be added
|
34 |
|
|
to your URL.
|
35 |
|
|
|
36 |
|
|
```js
|
37 |
|
|
'use strict';
|
38 |
|
|
|
39 |
|
|
var required = require('requires-port');
|
40 |
|
|
|
41 |
|
|
console.log(required('8080', 'http')) // true
|
42 |
|
|
console.log(required('80', 'http')) // false
|
43 |
|
|
```
|
44 |
|
|
|
45 |
|
|
# License
|
46 |
|
|
|
47 |
|
|
MIT
|