ExCountries.Country (ex_countries v0.0.2)
This module contains functions to transform country codes into country names and vice versa
Summary
Functions
Returns country code(alpha2 or alpha3) by full name and returns nil
if not found.
Normalize country code(alpha2 or alpha3) and returns the other codes.
By default it will switch between alpha2 and alpha3,
but you can pass :alpha2
or :alpha3
options, will only return alpha2 or alpha3
.
Functions
Link to this function
code_by_name(country_name, code \\ "alpha2")
Returns country code(alpha2 or alpha3) by full name and returns nil
if not found.
Examples
iex> ExCountries.Country.code_by_name("United States")
"US"
iex> ExCountries.Country.code_by_name("United States", "alpha3")
"USA"
iex> ExCountries.Country.code_by_name("wrong name")
nil
Link to this function
normalize_alpha(country_code, opts \\ :switch)
Normalize country code(alpha2 or alpha3) and returns the other codes.
By default it will switch between alpha2 and alpha3,
but you can pass :alpha2
or :alpha3
options, will only return alpha2 or alpha3
.
Examples
iex> ExCountries.Country.normalize_alpha("USA")
"US"
iex> ExCountries.Country.normalize_alpha("US", :alpha3)
"USA"
iex> ExCountries.Country.normalize_alpha("wrong name")
nil