Projekt

Obecné

Profil

Stáhnout (753 Bajtů) Statistiky
| Větev: | Revize:
1 3a515b92 cagy
'use strict';
2
3
/**
4
 * Check if we're required to add a port number.
5
 *
6
 * @see https://url.spec.whatwg.org/#default-port
7
 * @param {Number|String} port Port number we need to check
8
 * @param {String} protocol Protocol we need to check against.
9
 * @returns {Boolean} Is it a default port for the given protocol
10
 * @api private
11
 */
12
module.exports = function required(port, protocol) {
13
  protocol = protocol.split(':')[0];
14
  port = +port;
15
16
  if (!port) return false;
17
18
  switch (protocol) {
19
    case 'http':
20
    case 'ws':
21
    return port !== 80;
22
23
    case 'https':
24
    case 'wss':
25
    return port !== 443;
26
27
    case 'ftp':
28
    return port !== 21;
29
30
    case 'gopher':
31
    return port !== 70;
32
33
    case 'file':
34
    return false;
35
  }
36
37
  return port !== 0;
38
};