summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoracamino <>2017-08-23 12:24:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2017-08-23 12:24:00 (GMT)
commit80fa59a40c1b5b3c4bb139c7d9a676e234766a70 (patch)
treeb82c54a5a4d6ae42a2d1e4e66d034a923916281a
parent4883a567c0ca61112a8afe670ddb5c7a81d369c1 (diff)
version 0.1.10.1.1
-rw-r--r--README.md41
-rw-r--r--src/Data/StateCodes.hs12
-rw-r--r--src/Data/StateCodes/ISO31662US.hs215
-rw-r--r--state-codes.cabal2
4 files changed, 141 insertions, 129 deletions
diff --git a/README.md b/README.md
index 50c1805..13c684e 100644
--- a/README.md
+++ b/README.md
@@ -3,3 +3,44 @@
[![Build Status](https://travis-ci.org/acamino/state-codes.svg?branch=master)](https://travis-ci.org/acamino/state-codes)
This package provides the ISO 3166-2:US state codes and i18n names.
+This work is entirely based on the package [Data.CountryCodes](http://hackage.haskell.org/package/country-codes).
+
+## Local Development
+
+1. Fork the project [on GitHub](https://github.com/acamino/state-codes) and clone your fork locally.
+
+ ```bash
+ $ git clone git@github.com:acamino/state-codes.git
+ $ cd state-codes
+ $ git remote add upstream https://github.com/acamino/state-codes.git
+ ```
+
+1. Install [Stack](https://docs.haskellstack.org/en/stable/README/).
+
+1. Get the appropriate GHC for the project.
+
+ ```bash
+ $ stack setup
+ ```
+
+1. If you want to launch a REPL and have fun with this program.
+
+ ```bash
+ $ stack repl
+ ```
+
+## Issues & Support
+
+Please [file tickets](https://github.com/acamino/state-codes/issues) for
+bug or problems.
+
+## Contributing
+
+Edits and enhancements are welcome. Just fork the repository, make your changes
+and send me a pull request.
+
+## Licence
+
+The code in this repository is licensed under the terms of the
+[MIT License](http://www.opensource.org/licenses/mit-license.html).
+Please see the [LICENSE](LICENSE) file for details.
diff --git a/src/Data/StateCodes.hs b/src/Data/StateCodes.hs
index 514e66c..494603c 100644
--- a/src/Data/StateCodes.hs
+++ b/src/Data/StateCodes.hs
@@ -1,9 +1,12 @@
--- | Main entry point, exposing all that needs to be
+-- | Main entry point.
module Data.StateCodes
( StateCode(..)
, allNames
+ , allStates
, stateList
+ , districtList
+ , outlyingAreasList
, fromMName
, fromMText
, fromName
@@ -21,3 +24,10 @@ import Data.StateCodes.ISO31662US
allNames :: [(StateCode, Text)]
allNames = map (id &&& toName) $ enumFrom minBound
+
+
+-- | List all states with codes. This is ready to be used in a yesod
+-- selectField, for example
+
+allStates :: [(Text, StateCode)]
+allStates = map (toName &&& id) $ enumFrom minBound
diff --git a/src/Data/StateCodes/ISO31662US.hs b/src/Data/StateCodes/ISO31662US.hs
index 964e618..4e9ab0f 100644
--- a/src/Data/StateCodes/ISO31662US.hs
+++ b/src/Data/StateCodes/ISO31662US.hs
@@ -1,14 +1,17 @@
+-- | This module defines codes for the names of the principal subdivisions for
+-- the United States according to ISO 3166-2:US
+-- <https://en.wikipedia.org/wiki/ISO_3166-2:US>.
+
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternGuards #-}
--- | This file is generated from the Wikipedia page
--- <https://en.wikipedia.org/wiki/ISO_3166-2:US>
-
module Data.StateCodes.ISO31662US
( StateCode(..)
, stateList
+ , districtList
+ , outlyingAreasList
, fromMName
, fromMText
, fromName
@@ -18,73 +21,74 @@ module Data.StateCodes.ISO31662US
) where
import Control.Applicative (pure)
+import Control.Arrow ((&&&))
import Data.Aeson
import Data.Text (Text)
import qualified Data.Text as T
import Data.Typeable
import Text.Shakespeare.I18N
-data StateCode = AL
- | AK
- | AZ
- | AR
- | CA
- | CO
- | CT
- | DE
- | FL
- | GA
- | HI
- | ID
- | IL
- | IN
- | IA
- | KS
- | KY
- | LA
- | ME
- | MD
- | MA
- | MI
- | MN
- | MS
- | MO
- | MT
- | NE
- | NV
- | NH
- | NJ
- | NM
- | NY
- | NC
- | ND
- | OH
- | OK
- | OR
- | PA
- | RI
- | SC
- | SD
- | TN
- | TX
- | UT
- | VT
- | VA
- | WA
- | WV
- | WI
- | WY
- | DC
- | AS
- | GU
- | MP
- | PR
- | UM
- | VI
+data StateCode = AL -- ^ Alabama
+ | AK -- ^ Alaska
+ | AZ -- ^ Arizona
+ | AR -- ^ Arkansas
+ | CA -- ^ California
+ | CO -- ^ Colorado
+ | CT -- ^ Connecticut
+ | DE -- ^ Delaware
+ | FL -- ^ Florida
+ | GA -- ^ Georgia
+ | HI -- ^ Hawaii
+ | ID -- ^ Idaho
+ | IL -- ^ Illinois
+ | IN -- ^ Indiana
+ | IA -- ^ Iowa
+ | KS -- ^ Kansas
+ | KY -- ^ Kentucky
+ | LA -- ^ Louisiana
+ | ME -- ^ Maine
+ | MD -- ^ Maryland
+ | MA -- ^ Massachusetts
+ | MI -- ^ Michigan
+ | MN -- ^ Minnesota
+ | MS -- ^ Mississippi
+ | MO -- ^ Missouri
+ | MT -- ^ Montana
+ | NE -- ^ Nebraska
+ | NV -- ^ Nevada
+ | NH -- ^ New Hampshire
+ | NJ -- ^ New Jersey
+ | NM -- ^ New Mexico
+ | NY -- ^ New York
+ | NC -- ^ North Carolina
+ | ND -- ^ North Dakota
+ | OH -- ^ Ohio
+ | OK -- ^ Oklahoma
+ | OR -- ^ Oregon
+ | PA -- ^ Pennsylvania
+ | RI -- ^ Rhode Island
+ | SC -- ^ South Carolina
+ | SD -- ^ South Dakota
+ | TN -- ^ Tennessee
+ | TX -- ^ Texas
+ | UT -- ^ Utah
+ | VT -- ^ Vermont
+ | VA -- ^ Virginia
+ | WA -- ^ Washington
+ | WV -- ^ West Virginia
+ | WI -- ^ Wisconsin
+ | WY -- ^ Wyoming
+ | DC -- ^ District of Columbia
+ | AS -- ^ American Samoa
+ | GU -- ^ Guam
+ | MP -- ^ Northern Mariana Islands
+ | PR -- ^ Puerto Rico
+ | UM -- ^ United States Minor Outlying Islands
+ | VI -- ^ Virgin Islands, U.S.
deriving (Bounded, Eq, Enum, Show, Read, Ord, Typeable)
--- | Maybe get the StateCode from the text code.
+-- | Maybe get the state code from the text code.
fromMText :: Text -> Maybe StateCode
fromMText "AL" = Just AL
@@ -147,7 +151,7 @@ fromMText "VI" = Just VI
fromMText _ = Nothing
--- | Get the StateCode from the text code. Errors if the code is unknown
+-- | Get the state code from the text code. Errors if the code is unknown
fromText :: Text -> StateCode
fromText c = case fromMText c of
@@ -155,7 +159,7 @@ fromText c = case fromMText c of
_ -> error $ "fromText: Unknown state code:" ++ T.unpack c
--- | Get the code as text
+-- | Get the state code as text
toText :: StateCode -> Text
toText AL = "AL"
@@ -217,7 +221,7 @@ toText UM = "UM"
toText VI = "VI"
--- | Maybe get the code from the user readable name
+-- | Maybe get the state code from the state readable name
fromMName :: Text -> Maybe StateCode
fromMName "Alabama" = Just AL
@@ -280,7 +284,7 @@ fromMName "Virgin Islands, U.S." = Just VI
fromMName _ = Nothing
--- | Get the StateCode from the user readable name. Errors if the name is unknown
+-- | Get the state code from the state readable name. Errors if the name is unknown
fromName:: Text -> StateCode
fromName s = case fromMName s of
@@ -288,7 +292,7 @@ fromName s = case fromMName s of
_ -> error $ "fromName: Unknown state code:" ++ T.unpack s
--- | Get the user readable name
+-- | Get the state readable name
toName :: StateCode -> Text
toName AL = "Alabama"
@@ -350,68 +354,25 @@ toName UM = "United States Minor Outlying Islands"
toName VI = "Virgin Islands, U.S."
--- | List of names sorted by alphabetical order, with state code
+-- | List of states sorted by alphabetical order, with state code
+-- this is ready to be used in a yesod selectField, for example
+
+stateList :: [(Text, StateCode)]
+stateList = map (toName &&& id) $ enumFromTo minBound WY
+
+
+-- | List of districts sorted by alphabetical order, with state code
+-- this is ready to be used in a yesod selectField, for example
+
+districtList :: [(Text, StateCode)]
+districtList = [("District of Columbia", DC)]
+
+
+-- | List of outlying areas sorted by alphabetical order, with state code
-- this is ready to be used in a yesod selectField, for example
-stateList :: [(T.Text, StateCode)]
-stateList = [ ("Alabama", AL)
- , ("Alaska", AK)
- , ("Arizona", AZ)
- , ("Arkansas", AR)
- , ("California", CA)
- , ("Colorado", CO)
- , ("Connecticut", CT)
- , ("Delaware", DE)
- , ("Florida", FL)
- , ("Georgia", GA)
- , ("Hawaii", HI)
- , ("Idaho", ID)
- , ("Illinois", IL)
- , ("Indiana", IN)
- , ("Iowa", IA)
- , ("Kansas", KS)
- , ("Kentucky", KY)
- , ("Louisiana", LA)
- , ("Maine", ME)
- , ("Maryland", MD)
- , ("Massachusetts", MA)
- , ("Michigan", MI)
- , ("Minnesota", MN)
- , ("Mississippi", MS)
- , ("Missouri", MO)
- , ("Montana", MT)
- , ("Nebraska", NE)
- , ("Nevada", NV)
- , ("New Hampshire", NH)
- , ("New Jersey", NJ)
- , ("New Mexico", NM)
- , ("New York", NY)
- , ("North Carolina", NC)
- , ("North Dakota", ND)
- , ("Ohio", OH)
- , ("Oklahoma", OK)
- , ("Oregon", OR)
- , ("Pennsylvania", PA)
- , ("Rhode Island", RI)
- , ("South Carolina", SC)
- , ("South Dakota", SD)
- , ("Tennessee", TN)
- , ("Texas", TX)
- , ("Utah", UT)
- , ("Vermont", VT)
- , ("Virginia", VA)
- , ("Washington", WA)
- , ("West Virginia", WV)
- , ("Wisconsin", WI)
- , ("Wyoming", WY)
- , ("District of Columbia", DC)
- , ("American Samoa", AS)
- , ("Guam", GU)
- , ("Northern Mariana Islands", MP)
- , ("Puerto Rico", PR)
- , ("United States Minor Outlying Islands", UM)
- , ("Virgin Islands, U.S.", VI)
- ]
+outlyingAreasList :: [(Text, StateCode)]
+outlyingAreasList = map (toName &&& id) $ enumFromTo AS maxBound
-- | To JSON: as a simple string
@@ -428,7 +389,7 @@ instance FromJSON StateCode where
parseJSON _ = fail "StateCode"
--- | Show user readable name, in English (ignoring locale for now)
+-- | Show state readable name, in English (ignoring locale for now)
instance RenderMessage master StateCode where
renderMessage _ _ = toName
diff --git a/state-codes.cabal b/state-codes.cabal
index 2c843db..2c96f73 100644
--- a/state-codes.cabal
+++ b/state-codes.cabal
@@ -1,5 +1,5 @@
name: state-codes
-version: 0.1.0
+version: 0.1.1
synopsis: ISO 3166-2:US state codes and i18n names
description: This package provides the ISO 3166-2:US state codes and i18n names
homepage: https://github.com/acamino/state-codes#README