email-amender
v0.2.2
Published
Rectify your user email address inputs from common spelling mistakes, probably due to the new MacBook Pro keyboard.
Downloads
3
Readme
Email Amender
An opinionated library on how to correct fat-fingered and mis-typed email addresses from user input.
How it Works
- It trims and lowercases the input email address. If it's falsy, i.e. it returns null.
- 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. - It checks to see if the
TLD
exists in a common list of TLDs. If so it skips to the next step. Otherwise:- 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.
- If there is nothing found, it uses fuzzyset.js to fine the nearest probable match to one of the common TLDs.
- 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 usingfuzzyset.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)