-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(component): use sift3 to detect email differences instead of sif4…
… or js-levenshtein (#3) * fix(component): use shift3 since 4 and js-levenshtein are not accurate
- Loading branch information
Showing
6 changed files
with
42 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
|
@@ -11,6 +11,7 @@ const domains = [ | |
'comcast.net', | ||
'facebook.com', | ||
'msn.com', | ||
'zoho.com', | ||
]; | ||
const secondLevelDomains = [ | ||
'yahoo', | ||
|
@@ -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 () { | ||
|
@@ -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'); | ||
}); | ||
|