// src/lib/email-normalize.ts
var INVISIBLE_OR_NBSP = /[\u200B-\u200D\uFEFF\u00A0]/g;
function normalizeEmail(input, options) {
  const t = input.trim().replace(INVISIBLE_OR_NBSP, "").replace(/\s+/g, "");
  const normalized = t.normalize("NFC").toLowerCase();
  if (!options?.gmailAlias) {
    return normalized;
  }
  const at = normalized.lastIndexOf("@");
  if (at <= 0) {
    return normalized;
  }
  const local = normalized.slice(0, at);
  const domain = normalized.slice(at + 1);
  if (!(domain === "gmail.com" || domain === "googlemail.com")) {
    return normalized;
  }
  const canonicalLocal = local.split("+")[0]?.replace(/\./g, "") ?? local;
  return `${canonicalLocal}@gmail.com`;
}
function normalizeGmailAliasEmail(input, options) {
  if (!options?.gmailAlias) {
    return null;
  }
  const basic = normalizeEmail(input);
  const at = basic.lastIndexOf("@");
  if (at <= 0) {
    return null;
  }
  const domain = basic.slice(at + 1);
  if (!(domain === "gmail.com" || domain === "googlemail.com")) {
    return null;
  }
  return normalizeEmail(input, options);
}
export {
  normalizeEmail,
  normalizeGmailAliasEmail
};
//# sourceMappingURL=email-normalize.js.map