purescript-iso 0.0.1.3 → 0.0.1.4
raw patch · 3 files changed
+36/−2 lines, 3 filesdep +emailaddress
Dependencies added: emailaddress
Files
- purescript-iso.cabal +5/−2
- src/Data/Aeson/JSONEmailAddress.hs +29/−0
- test/Spec.hs +2/−0
purescript-iso.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 385def0412c2a5d163265905ddac9752da049097f6c7d5233b8afbe5e98b912c+-- hash: 288de828bb3fd2e14f409f4bd84bc2117c0794f83f469214bc6c0108da1ff70f name: purescript-iso-version: 0.0.1.3+version: 0.0.1.4 synopsis: Isomorphic trivial data type definitions over JSON description: Please see the README on GitHub at <https://github.com/githubuser/purescript-iso#readme> category: Web@@ -29,6 +29,7 @@ exposed-modules: Data.Aeson.JSONDateTime Data.Aeson.JSONEither+ Data.Aeson.JSONEmailAddress Data.Aeson.JSONString Data.Aeson.JSONTuple Data.Aeson.JSONUnit@@ -47,6 +48,7 @@ , base >=4.7 && <5 , bytestring , containers+ , emailaddress >=0.2.0.0 , monad-control , mtl , quickcheck-instances@@ -76,6 +78,7 @@ , base >=4.7 && <5 , bytestring , containers+ , emailaddress >=0.2.0.0 , monad-control , mtl , purescript-iso
+ src/Data/Aeson/JSONEmailAddress.hs view
@@ -0,0 +1,29 @@+{-# LANGUAGE+ GeneralizedNewtypeDeriving+ , DeriveGeneric+ #-}++module Data.Aeson.JSONEmailAddress where++import Text.EmailAddress (EmailAddress, emailAddressFromString)+import Data.Aeson (ToJSON, FromJSON)+import qualified Data.Char as Char+import Test.QuickCheck (Arbitrary (..))+import Test.QuickCheck.Gen (listOf1, elements, scale)+import GHC.Generics (Generic)+++newtype JSONEmailAddress = JSONEmailAddress+ { getJSONEmailAddress :: EmailAddress+ } deriving (Eq, Ord, Show, Generic, FromJSON, ToJSON)++instance Arbitrary JSONEmailAddress where+ arbitrary = do+ name <- arbitraryNonEmptyAscii -- listOf1 (arbitrary `suchThat` Char.isAlphaNum)+ domain <- arbitraryNonEmptyAscii -- listOf1 (arbitrary `suchThat` Char.isAlphaNum)+ let x = name ++ "@" ++ domain ++ ".com"+ case emailAddressFromString x of+ Just e -> pure (JSONEmailAddress e)+ Nothing -> error x+ where+ arbitraryNonEmptyAscii = scale (`div` 2) $ listOf1 (elements ['a' .. 'z'])
test/Spec.hs view
@@ -7,6 +7,7 @@ import Data.Aeson.JSONTuple (JSONTuple) import Data.Aeson.JSONDateTime (JSONDateTime) import Data.Aeson.JSONString (JSONString)+import Data.Aeson.JSONEmailAddress (JSONEmailAddress) import Data.Time (UTCTime) import Data.Time.Calendar (Day) @@ -54,6 +55,7 @@ registerTopic "JSONDate" (Proxy :: Proxy Day) registerTopic "JSONDateTime" (Proxy :: Proxy JSONDateTime) registerTopic "JSONString" (Proxy :: Proxy JSONString)+ registerTopic "JSONEmailAddress" (Proxy :: Proxy JSONEmailAddress) jsonIso :: ToJSON a => FromJSON a => Eq a => a -> Result