/**
 * Shared URL normalisation for matching crawled/session/attribution URLs.
 * Strips trailing slashes and lowercases so comparison is stable across
 * URL sources that may differ only in case or trailing slash.
 */
export function normUrl(url: string | null | undefined): string {
  if (!url) return "";
  try {
    const u = new URL(url);
    return (u.hostname + u.pathname).replace(/\/+$/, "").toLowerCase();
  } catch {
    return url.toLowerCase().replace(/\/+$/, "");
  }
}
