Skip to content

Commit

Permalink
feat: lowercase matched emails
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed May 7, 2020
1 parent 51332a9 commit b030170
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .README/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ extractEmail('extracts emails surrounded by odd unicode characters, e.g. 邮箱
extractEmail('extracts emails surrounded by emojis, e.g. 📧gajus@gajus.com');
// [{email: 'gajus@gajus.com'}]

extractEmail('lowercases emails, e.g. GAJUS@GAJUS.COM');
// [{email: 'gajus@gajus.com'}]

extractEmail('excludes invalid emails with invalid TLDs, e.g. gajus@gajus.png');
// []

Expand Down
3 changes: 2 additions & 1 deletion src/normalizeInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ export default (input: string): string => {

// Matches all ASCII characters from the space to tilde.
.replace(/[^ -~]/g, ' ')
.trim();
.trim()
.toLowerCase();
};
1 change: 1 addition & 0 deletions test/extract-email-address/extractEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import extractEmail from '../../src/extractEmail';

const fixtures = [
'gajus@gajus.com',
'GAJUS@GAJUS.COM',
':gajus@gajus.com',
'📧gajus@gajus.com',
'gajus@gajus.com.',
Expand Down
1 change: 1 addition & 0 deletions test/extract-email-address/normalizeInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import test from 'ava';
import normalizeInput from '../../src/normalizeInput';

test('normalizes different email formats', (t) => {
t.is(normalizeInput('GAJUS@GAJUS.COM'), 'gajus@gajus.com');
t.is(normalizeInput(':gajus@gajus.com'), 'gajus@gajus.com');
t.is(normalizeInput('📧gajus@gajus.com'), 'gajus@gajus.com');
t.is(normalizeInput('g a j u s [at] g a j u s [dot] c o m'), 'gajus@gajus.com');
Expand Down

0 comments on commit b030170

Please sign in to comment.