mailcheck
mailcheck copied to clipboard
Port to Elm of mailcheck.js, suggests domains for emails with errors.
Mailcheck
An Elm library to suggest a correct domain when users misspell email addresses.
This is a port of mailcheck.js at https://github.com/mailcheck/mailcheck
What does it do?
When your user types in "[email protected]", it will suggest "[email protected]".
It is currently worth looking at the documentation at https://github.com/mailcheck/mailcheck
4.1.0 2015/12/30
Thanks to https://github.com/Adrian2112 for a pull request, he created the
`mailParts` function. I have retained `splitEmail` in API to make the version
change a Minor, but it now just uses the mailParts logic. Adrian also
contributed a few refactors I have pulled in manually.
5.0.0 2-18/09/07
Updated to Elm 0.19.
Removed splitEmail.
Installation
elm package install rluiten/elm-mailcheck
Testing
This uses elm-test for testing so install it if you dont have it.
- npm install -g elm-test
To run Tests
- elm-test
Copyright (c) 2016 Robin Luiten
Example1.elm
module Main exposing (input1, input2, mailcheckResult1, mailcheckResult2, test1Pass, test2Pass)
import Mailcheck exposing (suggest)
input1 =
"[email protected]"
mailcheckResult1 =
suggest input1
test1Pass =
mailcheckResult1 == Just ( "user", "gmail.com", "[email protected]" )
input2 =
{- "[email protected]" -}
"[email protected]"
mailcheckResult2 =
suggest input2
test2Pass =
mailcheckResult2 == Nothing
d1 =
Debug.log "mailcheckResult1" ( input1, mailcheckResult1, test1Pass )
d2 =
Debug.log "mailcheckResult2" ( input2, mailcheckResult2, test2Pass )
Example2.elm
It is possible to provide your own list of domains, second level domains and top level domains.
module Main exposing (domains, input1, input2, input3, mailcheckResult1, mailcheckResult2, mailcheckResult3, secondLevelDomains, test1Pass, test2Pass, test3Pass, topLevelDomains)
import Mailcheck exposing (suggestWith)
domains =
[ "yohomail.com" ]
secondLevelDomains =
[ "supamail" ]
topLevelDomains =
[ "cosmic" ]
input1 =
"[email protected]"
mailcheckResult1 =
suggestWith domains secondLevelDomains topLevelDomains input1
test1Pass =
mailcheckResult1 == Just ( "test", "yohomail.com", "[email protected]" )
input2 =
"[email protected]"
mailcheckResult2 =
suggestWith domains secondLevelDomains topLevelDomains input2
test2Pass =
mailcheckResult2 == Just ( "test", "fakedomain.cosmic", "[email protected]" )
input3 =
"[email protected]"
mailcheckResult3 =
suggestWith domains secondLevelDomains topLevelDomains input3
test3Pass =
mailcheckResult3 == Just ( "test", "supamail.tld", "[email protected]" )
_ =
Debug.log "mailcheckResult1" ( input1, mailcheckResult1, test1Pass )
_ =
Debug.log "mailcheckResult2" ( input2, mailcheckResult2, test2Pass )
_ =
Debug.log "mailcheckResult3" ( input3, mailcheckResult3, test3Pass )
License
Released under the BSD3 License.
(c) 2015 Robin Luiten