worldwide/country

The Country type, and lookups over it.

worldwide ships no country data itself: run gleam run -m worldwide/pull_countries in your own project to generate data/worldwide_countries.json. The functions below read that file the first time they are used and panic with instructions if it isn’t there yet.

Types

A Country record.

pub type Country {
  Country(
    name: String,
    alpha2: String,
    alpha3: String,
    numeric: String,
    region: region.Region,
    subregion: option.Option(region.Subregion),
    capital: option.Option(String),
    currencies: List(currency.Currency),
    languages: List(language.Language),
    calling_codes: List(String),
    timezones: List(duration.Duration),
  )
}

Constructors

  • Country(
      name: String,
      alpha2: String,
      alpha3: String,
      numeric: String,
      region: region.Region,
      subregion: option.Option(region.Subregion),
      capital: option.Option(String),
      currencies: List(currency.Currency),
      languages: List(language.Language),
      calling_codes: List(String),
      timezones: List(duration.Duration),
    )

    Arguments

    name

    Common English name, e.g. “Spain”.

    alpha2

    ISO 3166-1 alpha-2 code, uppercase, e.g. “ES”.

    alpha3

    ISO 3166-1 alpha-3 code, uppercase, e.g. “ESP”.

    numeric

    ISO 3166-1 numeric code as a zero-padded string, e.g. “724”.

    region

    Continental region.

    subregion

    Continental subregion.

    capital

    Capital city, if the country has one.

    currencies

    Currencies in use, primary first. May be empty.

    languages

    Official / common languages. May be empty.

    calling_codes

    International dialing prefixes, e.g. [“34”]. May be empty.

    timezones

    Fixed UTC offsets used by the country. May be empty.

Values

pub fn all() -> List(Country)

Return every known country in countries.dev name order.

Panics if gleam run -m worldwide/pull_countries has not been run yet in this project.

pub fn alpha2(country: Country) -> String

A record access function for the alpha2 field to use when composing functions and piping.

pub fn alpha3(country: Country) -> String

A record access function for the alpha3 field to use when composing functions and piping.

pub fn calling_codes(country: Country) -> List(String)

A record access function for the calling_codes field to use when composing functions and piping.

pub fn capital(country: Country) -> option.Option(String)

A record access function for the capital field to use when composing functions and piping.

pub fn currencies(country: Country) -> List(currency.Currency)

A record access function for the currencies field to use when composing functions and piping.

pub fn from_alpha2(alpha2: String) -> Result(Country, Nil)

Look up a country by normalized alpha-2 code.

pub fn from_iso_code(code: String) -> Result(Country, Nil)

Look up a country by normalized alpha-2, alpha-3, or numeric code.

pub fn from_name(name: String) -> Result(Country, Nil)

Look up a country by exact common English name.

pub fn is_iso_code(code: String) -> Bool
pub fn languages(country: Country) -> List(language.Language)

A record access function for the languages field to use when composing functions and piping.

pub fn name(country: Country) -> String

A record access function for the name field to use when composing functions and piping.

pub fn numeric(country: Country) -> String

A record access function for the numeric field to use when composing functions and piping.

pub fn region(country: Country) -> region.Region

A record access function for the region field to use when composing functions and piping.

pub fn timezones(country: Country) -> List(duration.Duration)

A record access function for the timezones field to use when composing functions and piping.

Search Document