fix: normalize user's website urls
This commit is contained in:
@@ -15,6 +15,18 @@ export function normalizeUrl(url: string): string {
|
||||
return p.toString()
|
||||
}
|
||||
|
||||
export function normalizeHttpUrl(url: string): string {
|
||||
if (url.indexOf('://') === -1) url = 'https://' + url
|
||||
const p = new URL(url)
|
||||
p.pathname = p.pathname.replace(/\/+/g, '/')
|
||||
if (p.pathname.endsWith('/')) p.pathname = p.pathname.slice(0, -1)
|
||||
if ((p.port === '80' && p.protocol === 'http:') || (p.port === '443' && p.protocol === 'https:'))
|
||||
p.port = ''
|
||||
p.searchParams.sort()
|
||||
p.hash = ''
|
||||
return p.toString()
|
||||
}
|
||||
|
||||
export function simplifyUrl(url: string): string {
|
||||
return url.replace('wss://', '').replace('ws://', '').replace(/\/$/, '')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user