const SUPPORTED_URL_PROTOCOLS = new Set([
    'http:',
    'https:',
    'mailto:',
    'sms:',
    'tel:'
]);
function sanitizeUrl(url) {
    if (url?.startsWith('/')) return url;
    try {
        const parsedUrl = new URL(url);
        if (!SUPPORTED_URL_PROTOCOLS.has(parsedUrl.protocol)) return 'about:blank';
    } catch (_e) {
        return 'https://';
    }
    return url;
}
const urlRegExp = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w-_]*)?\??(?:[-+=&;%@.\w_]*)#?(?:[\w]*))?)/;
function validateUrl(url) {
    return 'https://' === url || urlRegExp.test(url);
}
function encodeRelativeUrl(url) {
    const segments = url.split('/');
    for(let index = 0; index < segments.length; index++){
        const segment = segments[index];
        segments[index] = encodeURIComponent(segment);
    }
    return segments.join('/');
}
export { encodeRelativeUrl, sanitizeUrl, validateUrl };
