UNPKG

extract-email-address

Version:

Extracts email address from an arbitrary text input.

29 lines 1.27 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.normalizeInput = void 0; const decode_uri_component_1 = __importDefault(require("decode-uri-component")); const emoji_regex_1 = __importDefault(require("emoji-regex")); const emojiRegex = (0, emoji_regex_1.default)(); const normalizeInput = (input) => { return ((0, decode_uri_component_1.default)(input) .replace(emojiRegex, ' ') .replaceAll(/(?<=\s|^)([.\-_a-z])\s?(?=[.\-_a-z](?:\s|$))/gu, '$1') .replaceAll(/\s+at\s+/gu, '@') .replaceAll(/\s+dot\s+/gu, '.') .replaceAll(/\s*<at>\s*/gu, '@') .replaceAll(/\s*<dot>\s*/gu, '.') .replaceAll(/\s*\(at\)\s*/gu, '@') .replaceAll(/\s*\(dot\)\s*/gu, '.') .replaceAll(/\s*\[at\]\s*/gu, '@') .replaceAll(/\s*\[dot\]\s*/gu, '.') // Matches all ASCII characters from the space to tilde. // eslint-disable-next-line regexp/no-obscure-range .replaceAll(/[^ -~]/gu, ' ') .trim() .toLowerCase()); }; exports.normalizeInput = normalizeInput; //# sourceMappingURL=normalizeInput.js.map