normalizeEmail.js 729 B

12345678910111213141516171819202122232425262728
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.normalizeEmail = void 0;
  4. const DOT_REG = /\./g;
  5. /**
  6. * 1. Lower-cases whole email.
  7. * 2. Removes dots ".".
  8. * 3. Remotes name part after "+".
  9. * 4. Throws if cannot parse the email.
  10. *
  11. * For example, this email
  12. *
  13. * Michal.Loler+twitter@Gmail.com
  14. *
  15. * will be normalized to
  16. *
  17. * michalloler@gmail.com
  18. *
  19. */
  20. const normalizeEmail = (email) => {
  21. const [name, host] = email.split('@');
  22. let [beforePlus] = name.split('+');
  23. beforePlus = beforePlus.replace(DOT_REG, '');
  24. const result = beforePlus.toLowerCase() + '@' + host.toLowerCase();
  25. Number(result);
  26. return result;
  27. };
  28. exports.normalizeEmail = normalizeEmail;