ZooTools / email-spell-checker

📮 An ultratiny (1.9 KB) and fast JavaScript email checker to reduce users typing a wrong email. Written in TypeScript. Enterprise-grade.
https://zootools.co/tools/email-spell-checker
MIT License
164 stars 11 forks source link

.com should take priority over .co in 3 letter domains beginning in 'c' #33

Open PatrickEGorman opened 1 year ago

PatrickEGorman commented 1 year ago

Feature Request

Is your feature request related to a problem? Please describe.

There are some cases where .co is the preferred suggestion when .com seems to be a much more likely candidate of what the user meant to input.

Ex: test@test.con corrects to test@test.co or test@test.cin (right hand shifted one key left on a querty keyboard) also corrects to test@test.co even though test@test.com seems like a much more probable candidate on what the user meant to input.

Describe the solution you'd like

With around 50% of top level domains being .com and only around 1% of TLDs being .co it seems like .com should be preferred over .co in a majority of cases especially in 3 letter domain names beginning with c.

Are you willing to resolve this issue by submitting a Pull Request?

bgmort commented 7 months ago

@PatrickEGorman I was able to work around this by using a custom distance function with a special case for .com:

import mailcheck from '@zootools/email-spell-checker'
import distance from '@zootools/email-spell-checker/dist/lib/helpers/sift3Distance'

const mailcheckDistance = (domain: string, knownDomain: string) => {
  let dist = distance(domain, knownDomain)
  // force prioritize .com matches over .co and .ca
  if (knownDomain === 'com') dist -= 0.75
  return dist
}

const suggestion = mailcheck.run({ email, distanceFunction: mailcheckDistance })