UNPKG

2.16 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.isValidEmail = exports.isEmailLocalPartChar = exports.isEmailLocalPartStartChar = exports.mailtoSchemePrefixRe = void 0;
4var regex_lib_1 = require("../regex-lib");
5var uri_utils_1 = require("./uri-utils");
6/**
7 * A regular expression to match a 'mailto:' prefix on an email address.
8 */
9exports.mailtoSchemePrefixRe = /^mailto:/i;
10/**
11 * Regular expression for all of the valid characters of the local part of an
12 * email address.
13 */
14var emailLocalPartCharRegex = new RegExp("[".concat(regex_lib_1.alphaNumericAndMarksCharsStr, "!#$%&'*+/=?^_`{|}~-]"));
15/**
16 * Determines if the given character may start the "local part" of an email
17 * address. The local part is the part to the left of the '@' sign.
18 *
19 * Technically according to the email spec, any of the characters in the
20 * {@link emailLocalPartCharRegex} can start an email address (including any of
21 * the special characters), but this is so rare in the wild and the
22 * implementation is much simpler by only starting an email address with a word
23 * character. This is especially important when matching the '{' character which
24 * generally starts a brace that isn't part of the email address.
25 */
26function isEmailLocalPartStartChar(char) {
27 return regex_lib_1.alphaNumericAndMarksRe.test(char);
28}
29exports.isEmailLocalPartStartChar = isEmailLocalPartStartChar;
30/**
31 * Determines if the given character can be part of the "local part" of an email
32 * address. The local part is the part to the left of the '@' sign.
33 */
34function isEmailLocalPartChar(char) {
35 return emailLocalPartCharRegex.test(char);
36}
37exports.isEmailLocalPartChar = isEmailLocalPartChar;
38/**
39 * Determines if the given email address is valid. We consider it valid if it
40 * has a valid TLD in its host.
41 *
42 * @param emailAddress email address
43 * @return true is email have valid TLD, false otherwise
44 */
45function isValidEmail(emailAddress) {
46 var emailAddressTld = emailAddress.split('.').pop() || '';
47 return (0, uri_utils_1.isKnownTld)(emailAddressTld);
48}
49exports.isValidEmail = isValidEmail;
50//# sourceMappingURL=email-utils.js.map
\No newline at end of file