This commit is contained in:
Iliyan Angelov
2025-09-14 23:24:25 +03:00
commit c67067a2a4
71311 changed files with 6800714 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
const protocols = ['http', 'https', 'mailto', 'tel']
/**
* @param {string} uri
* @returns {string}
*/
export function uriTransformer(uri) {
const url = (uri || '').trim()
const first = url.charAt(0)
if (first === '#' || first === '/') {
return url
}
const colon = url.indexOf(':')
if (colon === -1) {
return url
}
let index = -1
while (++index < protocols.length) {
const protocol = protocols[index]
if (
colon === protocol.length &&
url.slice(0, protocol.length).toLowerCase() === protocol
) {
return url
}
}
index = url.indexOf('?')
if (index !== -1 && colon > index) {
return url
}
index = url.indexOf('#')
if (index !== -1 && colon > index) {
return url
}
// eslint-disable-next-line no-script-url
return 'javascript:void(0)'
}