Skip to content

Commit

Permalink
fix(component): use sift3 to detect email differences instead of sif4…
Browse files Browse the repository at this point in the history
… or js-levenshtein (#3)

* fix(component): use shift3 since 4 and js-levenshtein are not accurate
  • Loading branch information
ferreiro authored Oct 21, 2022
1 parent 4aeed95 commit b47c381
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 4 deletions.
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
File renamed without changes.
File renamed without changes.
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

0 comments on commit b47c381

Please sign in to comment.