'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var SAFE_URL_PROTOCOLS = /*#__PURE__*/new Set(['http:', 'https:', 'mailto:', 'tel:']);
var sanitizeUrl = function sanitizeUrl(url) {
  if (!url) {
    return undefined;
  }
  var trimmedUrl = url.trim();
  if (trimmedUrl.startsWith('#') || trimmedUrl.startsWith('/') && !trimmedUrl.startsWith('//') || trimmedUrl.startsWith('./') || trimmedUrl.startsWith('../')) {
    return trimmedUrl;
  }
  try {
    var baseUrl = typeof window === 'undefined' ? 'http://localhost' : window.location.href;
    var parsedUrl = new URL(trimmedUrl, baseUrl);
    return SAFE_URL_PROTOCOLS.has(parsedUrl.protocol) ? trimmedUrl : undefined;
  } catch (_unused) {
    return undefined;
  }
};

exports.sanitizeUrl = sanitizeUrl;
