Skip to content

Function: parseEmails()

parseEmails(input, options?): string[]

Normalize the shapes an email address field accepts - a single string, a comma / semicolon / whitespace separated list, an array of either, or nothing - into a clean string[]. Each entry is split on the list separators, trimmed, and de-emptied; blanks and non-string array members are dropped. By default duplicates are removed case-insensitively (first-seen casing wins) and casing is otherwise preserved; pass lowercase to fold everything to lower case (e.g. for an allow-list). This is the one place recipient lists, CC/BCC inputs, and sender allow-lists across the repo agree on how free-text email input is read. Never throws; does not validate - pair with isEmail when you need to reject malformed addresses.

string | readonly string[] | null | undefined

ParseEmailsOptions = {}

string[]

parseEmails("a@x.com, b@y.com; a@x.com"); // ["a@x.com", "b@y.com"]
parseEmails(["A@x.com", " b@y.com "]); // ["A@x.com", "b@y.com"]
parseEmails("*@corp.com", { lowercase: true }); // ["*@corp.com"]
parseEmails(undefined); // []