-
Notifications
You must be signed in to change notification settings - Fork 0
/
protocolHelper.js
44 lines (39 loc) · 947 Bytes
/
protocolHelper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const dictionary = {
"ftp": 21,
"gopher": 70,
"http": 80,
"https": 443,
"ws": 80,
"wss": 443
}
function getPort(protocol) {
if(typeof(protocol) == 'string') {
protocol = strip(protocol)
return dictionary[protocol] || 80
}
return 80
}
function getProtocol(port) {
if(typeof(port) == 'number') {
for(let protocol in dictionary) {
if(dictionary[protocol] == port) {
return protocol
}
}
}
return null
}
function isHttp(protocol) {
if(typeof(protocol) == 'string') {
protocol = strip(protocol)
return protocol == "http" || protocol == "https"
}
return false
}
function strip(protocol) {
if(typeof(protocol) == 'string') {
protocol = protocol.indexOf(":") != -1 ? protocol.substr(0, protocol.indexOf(":")) : protocol
}
return protocol
}
module.exports = { getPort, isHttp, strip }