source: trip-planner-front/node_modules/requires-port/index.js@ 188ee53

Last change on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 753 bytes
Line 
1'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 */
12module.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};
Note: See TracBrowser for help on using the repository browser.