worldwide

A typed database of world countries.

worldwide ships no country data itself: run gleam run -m worldwide/pull_countries once in your own project to generate data/worldwide_countries.json. worldwide.all() (and any other lookup) reads it the first time it’s called and panics with instructions if it isn’t there yet.

Quick start

import worldwide
import worldwide/region

pub fn main() {
  worldwide.all()
  |> worldwide.filter_by(worldwide.Region(region.Europe))
  // -> [Country(region: Europe, ..), ..]
}

See the worldwide/country module for more details.

Types

Filters that can be used to quickly get subsets of the worldwide data.

pub type Filter {
  NameContains(String)
  Region(region.Region)
  Subregion(region.Subregion)
  Currency(String)
  Language(String)
  CallingCode(String)
  TimeZone(duration.Duration)
}

Constructors

  • NameContains(String)

    Filters by names containing the provided String.

  • Region(region.Region)

    Filters by the provided Region.

  • Subregion(region.Subregion)

    Filters by the provided Subregion.

  • Currency(String)

    Filters by the provided Currency.

  • Language(String)

    Filters by the provided Language.

  • CallingCode(String)

    Filters by the provided CallingCode.

  • TimeZone(duration.Duration)

    Filters by the provided TimeZone.

Values

pub fn all() -> List(country.Country)

Return every known country.

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

pub fn currencies() -> List(currency.Currency)

Returns every currency as a typed value.

pub fn filter_by(
  countries: List(country.Country),
  filter: Filter,
) -> List(country.Country)

Used to filter countries by the supported filters.

import worldwide
import worldwide/region.{Europe}

pub fn main() {
  worldwide.all()
  |> worldwide.filter_by(worldwide.Region(Europe))
  // -> [Country(region: Europe, ..), ..]
}
pub fn languages() -> List(language.Language)

Returns every language as a typed value.

pub fn regions() -> List(region.Region)

Returns every region as a typed value.

pub fn subregions() -> List(region.Subregion)

Returns every region as a typed value.

pub fn timezones() -> List(duration.Duration)

Returns every timezone as a typed value.

Search Document