git.iko.soy/typeable/country-codes
on master help sign in
.gitignore+2
since splitsnapshots
unifiedsplit
@@ -11,3 +11,5 @@ cabal.sandbox.config
11cabal.config
11cabal.config
12.dist-buildwrapper
12.dist-buildwrapper
13.project
13.project
14+.stack-work
15+*.history
country-codes.cabal+11−3
@@ -1,5 +1,5 @@
1name: country-codes
1name: country-codes
2−version: 0.1.3
2+version: 0.1.4
3cabal-version: >= 1.8
3cabal-version: >= 1.8
4build-type: Simple
4build-type: Simple
5author: JP Moresmau <jpmoresmau@gmail.com>
5author: JP Moresmau <jpmoresmau@gmail.com>
@@ -31,7 +31,14 @@ library
31 , text >= 0.11
31 , text >= 0.11
32 , aeson >= 0.5
32 , aeson >= 0.5
33 , deepseq >= 1.4
33 , deepseq >= 1.4
34− , shakespeare == 2.0.*
34+ , shakespeare
35+ -- == 2.0.*
36+ if !(impl(ghcjs) || arch(javascript) || arch(wasm32))
37+ build-depends:
38+ openapi3
39+ , QuickCheck
40+ , generic-arbitrary
41+ cpp-options: -DBACKEND
35 ghc-options: -Wall
42 ghc-options: -Wall
36 other-modules: Data.CountryCodes.ISO31661
43 other-modules: Data.CountryCodes.ISO31661
37 exposed-modules: Data.CountryCodes
44 exposed-modules: Data.CountryCodes
@@ -42,7 +49,8 @@ executable country-codes-generate
42 build-depends:
49 build-depends:
43 base >= 4 && < 5
50 base >= 4 && < 5
44 , text >= 0.11
51 , text >= 0.11
45− , tagsoup >= 0.13 && < 0.15
52+ , tagsoup >= 0.13
53+ -- && < 0.15
46 ghc-options: -Wall -rtsopts
54 ghc-options: -Wall -rtsopts
47 main-is: Main.hs
55 main-is: Main.hs
48 if !flag(generate)
56 if !flag(generate)
src/Data/CountryCodes/ISO31661.hs+67−11
@@ -1,4 +1,7 @@
1−{-# LANGUAGE DeriveDataTypeable, OverloadedStrings, NoImplicitPrelude, PatternGuards, FlexibleInstances, MultiParamTypeClasses #-}
1+{-# LANGUAGE DeriveDataTypeable, OverloadedStrings, NoImplicitPrelude
2+ , DeriveGeneric, DeriveAnyClass, PatternGuards, FlexibleInstances
3+ , MultiParamTypeClasses, StandaloneDeriving, CPP #-}
4+{-# OPTIONS_GHC -fconstraint-solver-iterations=10 #-}
2-- | This file is generated from the Wikipedia page
5-- | This file is generated from the Wikipedia page
3-- <http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2>
6-- <http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2>
4module Data.CountryCodes.ISO31661 (
7module Data.CountryCodes.ISO31661 (
@@ -14,13 +17,19 @@ module Data.CountryCodes.ISO31661 (
14
17
15import Control.Applicative (pure)
18import Control.Applicative (pure)
16import Control.DeepSeq (NFData(..))
19import Control.DeepSeq (NFData(..))
17−import Data.Aeson
20+import Data.Aeson
18−import Data.Typeable
21+import Data.Typeable
19−import qualified Data.Text as T
22+import Data.Text as T
23+import GHC.Generics
20−import Prelude (Show,Read,Eq,Ord,Bounded,Enum,error,($),(++),Maybe(..),(.),fail,seq)
24+import Prelude (Show,Read,Eq,Ord,Bounded,Enum,error,($),(++),Maybe(..),(.),fail,seq)
21−import Text.Shakespeare.I18N
25+import Text.Shakespeare.I18N
26+#ifdef BACKEND
27+import Data.OpenApi
28+import Test.QuickCheck.Arbitrary
29+import Test.QuickCheck.Arbitrary.Generic
30+#endif
22
31
23−data CountryCode =
32+data CountryCode =
24 AD
33 AD
25 | AE
34 | AE
26 | AF
35 | AF
@@ -270,7 +279,19 @@ data CountryCode =
270 | ZA
279 | ZA
271 | ZM
280 | ZM
272 | ZW
281 | ZW
282+ -- Added these non standard codes that occur in
283+ -- travolutionary database
284+ -- https://typeable.atlassian.net/browse/B2H-796
285+ | XA
286+ | AN
287+ | XK
288+ | XC
289+ | WE
273− deriving (Show,Read,Eq,Ord,Bounded,Enum,Typeable)
290+ deriving (Show,Read,Eq,Ord,Bounded,Enum,Typeable, Generic
291+#ifdef BACKEND
292+ , ToSchema
293+#endif
294+ )
274
295
275-- | Maybe get the CountryCode from the text code.
296-- | Maybe get the CountryCode from the text code.
276fromMText :: T.Text -> Maybe CountryCode
297fromMText :: T.Text -> Maybe CountryCode
@@ -523,6 +544,11 @@ fromMText "YT" = Just YT
523fromMText "ZA" = Just ZA
544fromMText "ZA" = Just ZA
524fromMText "ZM" = Just ZM
545fromMText "ZM" = Just ZM
525fromMText "ZW" = Just ZW
546fromMText "ZW" = Just ZW
547+fromMText "XA" = Just XA
548+fromMText "AN" = Just AN
549+fromMText "XK" = Just XK
550+fromMText "XC" = Just XC
551+fromMText "WE" = Just WE
526fromMText _ = Nothing
552fromMText _ = Nothing
527
553
528-- | Get the CountryCode from the text code. Errors if the code is unknown
554-- | Get the CountryCode from the text code. Errors if the code is unknown
@@ -782,6 +808,11 @@ toText YT = "YT"
782toText ZA = "ZA"
808toText ZA = "ZA"
783toText ZM = "ZM"
809toText ZM = "ZM"
784toText ZW = "ZW"
810toText ZW = "ZW"
811+toText XA = "XA"
812+toText AN = "AN"
813+toText XK = "XK"
814+toText XC = "XC"
815+toText WE = "WE"
785
816
786-- | Maybe get the code from the user readable name.
817-- | Maybe get the code from the user readable name.
787fromMName :: T.Text -> Maybe CountryCode
818fromMName :: T.Text -> Maybe CountryCode
@@ -1034,6 +1065,11 @@ fromMName "Mayotte" = Just YT
1034fromMName "South Africa" = Just ZA
1065fromMName "South Africa" = Just ZA
1035fromMName "Zambia" = Just ZM
1066fromMName "Zambia" = Just ZM
1036fromMName "Zimbabwe" = Just ZW
1067fromMName "Zimbabwe" = Just ZW
1068+fromMName "Canary Islands" = Just XA
1069+fromMName "Netherlands Antilles" = Just AN
1070+fromMName "Kosovo" = Just XK
1071+fromMName "Ceuta" = Just XC
1072+fromMName "West Bank" = Just WE
1037fromMName _ = Nothing
1073fromMName _ = Nothing
1038
1074
1039-- | Get the CountryCode from the user readable name. Errors if the name is unknown
1075-- | Get the CountryCode from the user readable name. Errors if the name is unknown
@@ -1293,6 +1329,11 @@ toName YT = "Mayotte"
1293toName ZA = "South Africa"
1329toName ZA = "South Africa"
1294toName ZM = "Zambia"
1330toName ZM = "Zambia"
1295toName ZW = "Zimbabwe"
1331toName ZW = "Zimbabwe"
1332+toName XA = "Canary Islands"
1333+toName AN = "Netherlands Antilles"
1334+toName XK = "Kosovo"
1335+toName XC = "Ceuta"
1336+toName WE = "West Bank"
1296
1337
1297-- | list of names sorted by alphabetical order, with country code
1338-- | list of names sorted by alphabetical order, with country code
1298-- this is ready to be used in a yesod selectField, for example
1339-- this is ready to be used in a yesod selectField, for example
@@ -1545,17 +1586,26 @@ countryList = [("Afghanistan",AF)
1545 ,("Yemen",YE)
1586 ,("Yemen",YE)
1546 ,("Zambia",ZM)
1587 ,("Zambia",ZM)
1547 ,("Zimbabwe",ZW)
1588 ,("Zimbabwe",ZW)
1548− ,("Åland Islands",AX) ]
1589+ ,("Åland Islands",AX)
1590+ ,("Canary Islands", XA)
1591+ ,("Netherlands Antilles",AN)
1592+ ,("Kosovo",XK)
1593+ ,("Ceuta",XC)
1594+ ,("West Bank",WE)
1595+ ]
1549
1596
1550-- | to json: as a simple string
1597-- | to json: as a simple string
1551instance ToJSON CountryCode where
1598instance ToJSON CountryCode where
1552− toJSON =toJSON . toText
1599+ toJSON = toJSON . toText
1553
1600
1554-- | from json: as a simple string
1601-- | from json: as a simple string
1555instance FromJSON CountryCode where
1602instance FromJSON CountryCode where
1556 parseJSON (String s)
1603 parseJSON (String s)
1557 | Just a <- fromMText s=pure a
1604 | Just a <- fromMText s=pure a
1558− parseJSON _ =fail "CountryCode"
1605+ parseJSON _ = fail "CountryCode"
1606+
1607+deriving instance ToJSONKey CountryCode
1608+deriving instance FromJSONKey CountryCode
1559
1609
1560-- | show user readable name, in English (ignoring locale for now)
1610-- | show user readable name, in English (ignoring locale for now)
1561instance RenderMessage master CountryCode where
1611instance RenderMessage master CountryCode where
@@ -1564,3 +1614,9 @@ instance RenderMessage master CountryCode where
1564-- | Allow the deep evaluation of CountryCode with `deepseq`
1614-- | Allow the deep evaluation of CountryCode with `deepseq`
1565instance NFData CountryCode where
1615instance NFData CountryCode where
1566 rnf a = a `seq` ()
1616 rnf a = a `seq` ()
1617+
1618+#ifdef BACKEND
1619+instance Arbitrary CountryCode where
1620+ arbitrary = genericArbitrary
1621+ shrink = genericShrink
1622+#endif
stack.yamlnew file+12
@@ -0,0 +1,12 @@
1+resolver: lts-21.3
2+
3+packages:
4+- .
5+
6+# extra-deps:
7+# - git: https://github.com/typeable/openapi3.git
8+# # nix-sha256: 1aqn5dia4aqwpmr3v0rcb8kzhknp5674hhay8h7p76206dx83ykg
9+# commit: bb1c64f8501535143c92907166fdc9f8df6d51b9
10+# - git: https://github.com/typeable/generic-arbitrary.git
11+# # nix-sha256: 01k87zxa8cd5ssy1wiqwyqqvz4v7lvh3q6cipmadg4w2ynmfbdn0
12+# commit: 84c62a4de517c78e5080f5451714ce7944987ba6