UNPKG

extract-email-address

Version:

Extracts email address from an arbitrary text input.

27 lines (23 loc) 866 B
import decodeUriComponent from 'decode-uri-component'; import createEmojiRegex from 'emoji-regex'; const emojiRegex = createEmojiRegex(); export const normalizeInput = (input: string): string => { return ( decodeUriComponent(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() ); };