Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(component): use sift3 to detect email differences instead of sif4 or js-levenshtein #3

Merged
merged 9 commits into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
typescript

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
Expand Down
2 changes: 1 addition & 1 deletion src/lib/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Default configuration options

import sift3Distance from '../helpers/sift3Distance';
import sift3Distance from '../fuzzy-detection/sift3-distance';

/***
* Default list of popular emails for 2022 and onwards.
Expand Down
2 changes: 1 addition & 1 deletion src/lib/run.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assertValidUserOptions from './helpers/asser-valid-user-options';
import assertValidUserOptions from './helpers/assert-valid-user-options';
import suggestEmail from './suggest-email';
import getOptions from './helpers/get-options';
import { MailSuggestion, Options, UserOptions } from './types';
Expand Down
41 changes: 39 additions & 2 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import run from '../src/lib/check-mail';
import distanceFunction from '../src/lib/helpers/distance-function';
import run from '../src/lib/run';
import distanceFunction from '../src/lib/fuzzy-detection/sift3-distance';
import encodeEmail from '../src/lib/helpers/encode-email';
import findClosestDomain from '../src/lib/helpers/find-closest-domain';
import parseEmail from '../src/lib/helpers/parse-email';
Expand All @@ -11,6 +11,7 @@ const domains = [
'comcast.net',
'facebook.com',
'msn.com',
'zoho.com',
];
const secondLevelDomains = [
'yahoo',
Expand Down Expand Up @@ -104,6 +105,41 @@ describe('mailSpellChecker', () => {
full: '[email protected]',
});
});

it.only('validates common emails', function () {
expect(
run({
email: '[email protected]',
domains: domains,
})
).toEqual({
address: 'test',
domain: 'gmail.com',
full: '[email protected]',
});

expect(
run({
email: '[email protected]',
domains: domains,
})
).toEqual({
address: 'test',
domain: 'yahoo.com',
full: '[email protected]',
});

expect(
run({
email: '[email protected]',
domains: domains,
})
).toEqual({
address: 'test',
domain: 'zoho.com',
full: '[email protected]',
});
});
});

describe('parseEmail', function () {
Expand Down Expand Up @@ -231,6 +267,7 @@ describe('mailSpellChecker', () => {
it('returns the most similar second-level domain', function () {
expect(findClosest('hotmial', secondLevelDomains)).toEqual('hotmail');
expect(findClosest('tahoo', secondLevelDomains)).toEqual('yahoo');
expect(findClosest('yaho', secondLevelDomains)).toEqual('yahoo');
expect(findClosest('livr', secondLevelDomains)).toEqual('live');
expect(findClosest('outllok', secondLevelDomains)).toEqual('outlook');
});
Expand Down