const REDIRECT_HOSTS = {
  "duckduckgo.com": "uddg",
  "www.duckduckgo.com": "uddg",
  "lite.duckduckgo.com": "uddg",
  "html.duckduckgo.com": "uddg",
  "google.com": "q",
  "www.google.com": "q"
};
function unwrapRedirect(input) {
  if (!input) return null;
  let candidate = input;
  if (candidate.startsWith("//")) candidate = "https:" + candidate;
  let parsed;
  try {
    parsed = new URL(candidate);
  } catch {
    return null;
  }
  const param = REDIRECT_HOSTS[parsed.hostname];
  if (!param) return null;
  const target = parsed.searchParams.get(param);
  if (!target) return null;
  let decoded;
  try {
    decoded = decodeURIComponent(target);
  } catch {
    return null;
  }
  if (!/^https?:\/\//i.test(decoded)) return null;
  try {
    new URL(decoded);
  } catch {
    return null;
  }
  return decoded;
}
function normalizeResultUrl(input) {
  const unwrapped = unwrapRedirect(input);
  return unwrapped ?? input;
}
export {
  normalizeResultUrl,
  unwrapRedirect
};
//# sourceMappingURL=url-unwrap.js.map