Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/totakke/clj-iso3166
ISO 3166 country definitions for Clojure(Script)
https://github.com/totakke/clj-iso3166
clojure clojurescript iso3166
Last synced: 22 days ago
JSON representation
ISO 3166 country definitions for Clojure(Script)
- Host: GitHub
- URL: https://github.com/totakke/clj-iso3166
- Owner: totakke
- License: mit
- Created: 2019-07-30T07:47:16.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-05-08T12:34:11.000Z (6 months ago)
- Last Synced: 2024-10-10T20:12:43.443Z (26 days ago)
- Topics: clojure, clojurescript, iso3166
- Language: Clojure
- Homepage:
- Size: 33.2 KB
- Stars: 9
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# clj-iso3166
[![Clojars Project](https://img.shields.io/clojars/v/net.totakke/clj-iso3166.svg)](https://clojars.org/net.totakke/clj-iso3166)
[![build](https://github.com/totakke/clj-iso3166/actions/workflows/build.yml/badge.svg)](https://github.com/totakke/clj-iso3166/actions/workflows/build.yml)ISO 3166 country definitions for Clojure(Script)
## Installation
Clojure CLI/deps.edn (as Git):
```clojure
io.github.totakke/clj-iso3166 {:git/tag "v0.4.0" :git/sha "3877e13"}
```Clojure CLI/deps.edn (as Maven):
```clojure
net.totakke/clj-iso3166 {:mvn/version "0.4.0"}
```Leiningen/Boot:
```clojure
[net.totakke/clj-iso3166 "0.4.0"]
```## Usage
### Basics
```clojure
(require '[clj-iso3166.country :as c])c/countries
;;=> [{:name "Andorra", :numeric 20, :alpha3 "AND", :alpha2 "AD"}
;; {:name "United Arab Emirates", :numeric 784, :alpha3 "ARE", :alpha2 "AE"}
;; {:name "Afghanistan", :numeric 4, :alpha3 "AFG", :alpha2 "AF"}
;; {:name "Antigua and Barbuda", :numeric 28, :alpha3 "ATG", :alpha2 "AG"}
;; {:name "Anguilla", :numeric 660, :alpha3 "AIA", :alpha2 "AI"}
;; ...](c/name->country "Japan")
;;=> {:name "Japan", :numeric 392, :alpha3 "JPN", :alpha2 "JP"}(c/numeric->country 380)
;;=> {:name "Italy", :numeric 380, :alpha3 "ITA", :alpha2 "IT"}(c/alpha3->country "USA")
;;=> {:name "United States", :numeric 840, :alpha3 "USA", :alpha2 "US"}(c/alpha2->country "EG")
;;=> {:name "Egypt", :numeric 818, :alpha3 "EGY", :alpha2 "EG"}
```### Former Countries
```clojure
(require '[clj-iso3166.former-country :as fc])(fc/name->former-country "Czechoslovakia")
;;=> {:name "Czechoslovakia",
;; :alpha4 "CSHH",
;; :former-code {:numeric 200, :alpha3 "CSK", :alpha2 "CS"},
;; :latter-codes [{:numeric 203, :alpha3 "CZE", :alpha2 "CZ"}
;; {:numeric 703, :alpha3 "SVK", :alpha2 "SK"}]}(def yugoslavia (fc/alpha4->former-country "YUCS"))
(fc/migrate-country yugoslavia)
;;=> ({:name "Montenegro", :numeric 499, :alpha3 "MNE", :alpha2 "ME"}
;; {:name "Serbia", :numeric 688, :alpha3 "SRB", :alpha2 "RS"})
```### Spec
```clojure
(require '[clj-iso3166.country :as c]
'[clojure.spec.alpha :as s])(s/valid? ::c/alpha2 "JP")
;;=> true(s/explain ::c/alpha3 "IT")
;; "IT" - failed: (re-matches #"[A-Z]{3}" %) spec: :clj-iso3166.country/alpha3
```## License
Copyright © 2019 [Toshiki Takeuchi](https://totakke.net/)
Distributed under the MIT License.