Email Amender




An opinionated library on how to correct fat-fingered and mis-typed email addresses from user input.
How it Works
1) It trims and lowercases the input email address. If it's falsy, i.e. it returns null.
2) Then it splits the email string into domain, TLD (Top Level Domain), and SLD (Second Level Domain).
Note:
.co.uk among other non-US TLDs would break this, which will be addressed in future versions of Email Amender.
3) It checks to see if the
TLD exists in a common
list of TLDs. If so it skips to the next step. Otherwise:
1) It first checks to the ceo the user input TLD begins with one of the common TLDs, which is a cheap check to see if extra letters happened to be added on. An example would be when a user thinks they've moved to the nexxt form field, and started typing more into the email address input field.
2) If there is nothing found, it uses
fuzzyset.js to fine the nearest probable match to one of the common TLDs.
4) This is super primitive right now._ It checks to see if the
SLD exists in a common
list of SLDs. If the SLD doesn't exist in the preset list, it checks to see if there's one using
fuzzyset.js, but requires an 80% probability. See the TODOs.
Development
Just run
yarn, and then run
yarn test to see if everything is working right.
To try to solve the failing tests, use yarn test:failing to check your work.
Credits
- Jaideep Srivastava (
@jaideepsrivastava)