html-email-validate 0.1.0.0 → 0.2.0.0
raw patch · 3 files changed
+10/−14 lines, 3 filesdep −text-showdep ~basePVP ok
version bump matches the API change (PVP)
Dependencies removed: text-show
Dependency ranges changed: base
API changes (from Hackage documentation)
Files
- html-email-validate.cabal +4/−5
- src/Text/Html/Email/Validate.hs +5/−9
- tests/Main.hs +1/−0
html-email-validate.cabal view
@@ -1,5 +1,5 @@ name: html-email-validate-version: 0.1.0.0+version: 0.2.0.0 synopsis: Validating an email address against HTML standard description: The library allows to validate and parse an email address as it's defined in <https://html.spec.whatwg.org/multipage/forms.html#valid-e-mail-address HTML standard>.@@ -23,8 +23,7 @@ DeriveDataTypeable DeriveGeneric - build-depends: base >=4.0 && <5.0- , text-show+ build-depends: base >=4.7 && <5.0 , attoparsec , text @@ -36,7 +35,7 @@ hs-source-dirs: tests/ main-is: Main.hs type: exitcode-stdio-1.0- build-depends: base >= 4.7 && < 4.8+ build-depends: base >= 4.7 && < 5.0 , attoparsec , hspec , text@@ -49,7 +48,7 @@ type: exitcode-stdio-1.0 hs-source-dirs: bench main-is: Main.hs- build-depends: base+ build-depends: base >= 4.7 && < 5.0 , html-email-validate , text , criterion
src/Text/Html/Email/Validate.hs view
@@ -14,6 +14,7 @@ import Control.Applicative import Control.Monad (when)+import Data.Either (isRight) import Data.Text (Text, intercalate) import qualified Data.Text as T import Data.Attoparsec.Text@@ -21,7 +22,6 @@ import qualified Text.Read as Read import Data.Data (Data, Typeable) import GHC.Generics (Generic)-import qualified Text.Show.Text as TS -- | Represents an email address data EmailAddress = EmailAddress { localPart :: Text@@ -29,7 +29,7 @@ } deriving (Eq, Ord, Data, Typeable, Generic) instance Show EmailAddress where- show = TS.toString . TS.showb+ show = T.unpack . emailToText instance Read EmailAddress where readListPrec = Read.readListPrecDefault@@ -37,16 +37,12 @@ text <- Read.readPrec either (const Read.pfail) return $ parseOnly emailParser text -instance TS.Show EmailAddress where- showb EmailAddress{..} = TS.fromText localPart <> TS.singleton '@' <> TS.fromText domainPart---- | Convert to text. Note that 'EmailAddress' has an instance of 'TS.Show' from--- 'text-show', you might want to use it instead.+-- | Convert to text. -- -- >>> emailToText $ EmailAddress "name" "example.com" -- "name@example.com emailToText :: EmailAddress -> Text-emailToText = TS.show+emailToText EmailAddress{..} = localPart <> T.singleton '@' <> domainPart -- | Validates given email. Email shouldn't have trailing or preceding spaces -- @@ -56,7 +52,7 @@ -- >>> isValidEmail "name@example..com" -- False isValidEmail :: Text -> Bool-isValidEmail = either (const False) (const True) . parseEmail+isValidEmail = isRight . parseEmail -- | Parce an email. Error messages aren't very helpful. parseEmail :: Text -> Either String EmailAddress
tests/Main.hs view
@@ -34,6 +34,7 @@ testEmail email = (isValidEmail $ pack email) `shouldBe` validateEmailRegex email +validateEmailRegex :: String -> Bool validateEmailRegex email | any (== '\n') email = False -- For some reason when using Text.Regex.PCRE -- the javascript regex matches '\n' even