Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function cleanUrlSIO (ma) {
const maStrSplit = ma.toString().split('/')
const tcpProto = ma.protos()[1].name
const wsProto = ma.protos()[2].name
const tcpPort = ma.stringTuples()[1][1]
if (tcpProto !== 'tcp' || (wsProto !== 'ws' && wsProto !== 'wss')) {
throw new Error('invalid multiaddr: ' + ma.toString())
}
if (!multiaddr.isName(ma)) {
return 'http://' + maStrSplit[2] + ':' + maStrSplit[4]
}
if (wsProto === 'ws') {
return 'http://' + maStrSplit[2] + (tcpPort === 80 ? '' : ':' + tcpPort)
}
if (wsProto === 'wss') {
return 'https://' + maStrSplit[2] + (tcpPort === 443 ? '' : ':' + tcpPort)
}
}