Skip to content

Commit 6741ffd

Browse files
authored
Merge pull request #725 from linkinmedo/normalize-email-single-function
remove isEmail form normalizeEmail
2 parents e6d2cc8 + 571567b commit 6741ffd

File tree

6 files changed

+2
-27
lines changed

6 files changed

+2
-27
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ Sanitizer | Description
122122
**escape(input)** | replace `<`, `>`, `&`, `'`, `"` and `/` with HTML entities.
123123
**unescape(input)** | replaces HTML encoded entities with `<`, `>`, `&`, `'`, `"` and `/`.
124124
**ltrim(input [, chars])** | trim characters from the left-side of the input.
125-
**normalizeEmail(email [, options])** | canonicalizes an email address.<br/><br/>`options` is an object with the following keys and default values:<br/><ul><li>*all_lowercase: true* - Transforms the local part (before the @ symbol) of all email addresses to lowercase. Please note that this may violate RFC 5321, which gives providers the possibility to treat the local part of email addresses in a case sensitive way (although in practice most - yet not all - providers don't). The domain part of the email address is always lowercased, as it's case insensitive per RFC 1035.</li><li>*gmail_lowercase: true* - GMail addresses are known to be case-insensitive, so this switch allows lowercasing them even when *all_lowercase* is set to false. Please note that when *all_lowercase* is true, GMail addresses are lowercased regardless of the value of this setting.</li><li>*gmail_remove_dots: true*: Removes dots from the local part of the email address, as GMail ignores them (e.g. "john.doe" and "johndoe" are considered equal).</li><li>*gmail_remove_subaddress: true*: Normalizes addresses by removing "sub-addresses", which is the part following a "+" sign (e.g. "[email protected]" becomes "[email protected]").</li><li>*gmail_convert_googlemaildotcom: true*: Converts addresses with domain @googlemail.com to @gmail.com, as they're equivalent.</li><li>*outlookdotcom_lowercase: true* - Outlook.com addresses (including Windows Live and Hotmail) are known to be case-insensitive, so this switch allows lowercasing them even when *all_lowercase* is set to false. Please note that when *all_lowercase* is true, Outlook.com addresses are lowercased regardless of the value of this setting.</li><li>*outlookdotcom_remove_subaddress: true*: Normalizes addresses by removing "sub-addresses", which is the part following a "+" sign (e.g. "[email protected]" becomes "[email protected]").</li><li>*yahoo_lowercase: true* - Yahoo Mail addresses are known to be case-insensitive, so this switch allows lowercasing them even when *all_lowercase* is set to false. Please note that when *all_lowercase* is true, Yahoo Mail addresses are lowercased regardless of the value of this setting.</li><li>*yahoo_remove_subaddress: true*: Normalizes addresses by removing "sub-addresses", which is the part following a "-" sign (e.g. "[email protected]" becomes "[email protected]").</li><li>*icloud_lowercase: true* - iCloud addresses (including MobileMe) are known to be case-insensitive, so this switch allows lowercasing them even when *all_lowercase* is set to false. Please note that when *all_lowercase* is true, iCloud addresses are lowercased regardless of the value of this setting.</li><li>*icloud_remove_subaddress: true*: Normalizes addresses by removing "sub-addresses", which is the part following a "+" sign (e.g. "[email protected]" becomes "[email protected]").</li></ul>
125+
**normalizeEmail(email [, options])** | canonicalizes an email address. (This doesn't validate that the input is an email, if you want to validate you email use isEmail beforehand)<br/><br/>`options` is an object with the following keys and default values:<br/><ul><li>*all_lowercase: true* - Transforms the local part (before the @ symbol) of all email addresses to lowercase. Please note that this may violate RFC 5321, which gives providers the possibility to treat the local part of email addresses in a case sensitive way (although in practice most - yet not all - providers don't). The domain part of the email address is always lowercased, as it's case insensitive per RFC 1035.</li><li>*gmail_lowercase: true* - GMail addresses are known to be case-insensitive, so this switch allows lowercasing them even when *all_lowercase* is set to false. Please note that when *all_lowercase* is true, GMail addresses are lowercased regardless of the value of this setting.</li><li>*gmail_remove_dots: true*: Removes dots from the local part of the email address, as GMail ignores them (e.g. "john.doe" and "johndoe" are considered equal).</li><li>*gmail_remove_subaddress: true*: Normalizes addresses by removing "sub-addresses", which is the part following a "+" sign (e.g. "[email protected]" becomes "[email protected]").</li><li>*gmail_convert_googlemaildotcom: true*: Converts addresses with domain @googlemail.com to @gmail.com, as they're equivalent.</li><li>*outlookdotcom_lowercase: true* - Outlook.com addresses (including Windows Live and Hotmail) are known to be case-insensitive, so this switch allows lowercasing them even when *all_lowercase* is set to false. Please note that when *all_lowercase* is true, Outlook.com addresses are lowercased regardless of the value of this setting.</li><li>*outlookdotcom_remove_subaddress: true*: Normalizes addresses by removing "sub-addresses", which is the part following a "+" sign (e.g. "[email protected]" becomes "[email protected]").</li><li>*yahoo_lowercase: true* - Yahoo Mail addresses are known to be case-insensitive, so this switch allows lowercasing them even when *all_lowercase* is set to false. Please note that when *all_lowercase* is true, Yahoo Mail addresses are lowercased regardless of the value of this setting.</li><li>*yahoo_remove_subaddress: true*: Normalizes addresses by removing "sub-addresses", which is the part following a "-" sign (e.g. "[email protected]" becomes "[email protected]").</li><li>*icloud_lowercase: true* - iCloud addresses (including MobileMe) are known to be case-insensitive, so this switch allows lowercasing them even when *all_lowercase* is set to false. Please note that when *all_lowercase* is true, iCloud addresses are lowercased regardless of the value of this setting.</li><li>*icloud_remove_subaddress: true*: Normalizes addresses by removing "sub-addresses", which is the part following a "+" sign (e.g. "[email protected]" becomes "[email protected]").</li></ul>
126126
**rtrim(input [, chars])** | trim characters from the right-side of the input.
127127
**stripLow(input [, keep_new_lines])** | remove characters with a numerical value < 32 and 127, mostly control characters. If `keep_new_lines` is `true`, newline characters are preserved (`\n` and `\r`, hex `0xA` and `0xD`). Unicode-safe in JavaScript.
128128
**toBoolean(input [, strict])** | convert the input string to a boolean. Everything except for `'0'`, `'false'` and `''` returns `true`. In strict mode only `'1'` and `'true'` return `true`.

lib/normalizeEmail.js

-8
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ Object.defineProperty(exports, "__esModule", {
55
});
66
exports.default = normalizeEmail;
77

8-
var _isEmail = require('./isEmail');
9-
10-
var _isEmail2 = _interopRequireDefault(_isEmail);
11-
128
var _merge = require('./util/merge');
139

1410
var _merge2 = _interopRequireDefault(_merge);
@@ -67,10 +63,6 @@ var yahoo_domains = ['rocketmail.com', 'yahoo.ca', 'yahoo.co.uk', 'yahoo.com', '
6763
function normalizeEmail(email, options) {
6864
options = (0, _merge2.default)(options, default_normalize_email_options);
6965

70-
if (!(0, _isEmail2.default)(email)) {
71-
return false;
72-
}
73-
7466
var raw_parts = email.split('@');
7567
var domain = raw_parts.pop();
7668
var user = raw_parts.join('@');

src/lib/normalizeEmail.js

-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import isEmail from './isEmail';
21
import merge from './util/merge';
32

43
const default_normalize_email_options = {
@@ -149,10 +148,6 @@ const yahoo_domains = [
149148
export default function normalizeEmail(email, options) {
150149
options = merge(options, default_normalize_email_options);
151150

152-
if (!isEmail(email)) {
153-
return false;
154-
}
155-
156151
const raw_parts = email.split('@');
157152
const domain = raw_parts.pop();
158153
const user = raw_parts.join('@');

test/sanitizers.js

-8
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,6 @@ describe('Sanitizers', function () {
235235
236236
237237
'hans@m端ller.com': 'hans@m端ller.com',
238-
'an invalid email address': false,
239-
'': false,
240-
241-
242-
243-
244-
245-
246238
247239
'"foo@bar"@baz.com': '"foo@bar"@baz.com',
248240
},

validator.js

-4
Original file line numberDiff line numberDiff line change
@@ -1290,10 +1290,6 @@ var yahoo_domains = ['rocketmail.com', 'yahoo.ca', 'yahoo.co.uk', 'yahoo.com', '
12901290
function normalizeEmail(email, options) {
12911291
options = merge(options, default_normalize_email_options);
12921292

1293-
if (!isEmail(email)) {
1294-
return false;
1295-
}
1296-
12971293
var raw_parts = email.split('@');
12981294
var domain = raw_parts.pop();
12991295
var user = raw_parts.join('@');

validator.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)