LivePhone.Countries (live_phone v0.4.0) View Source

The LivePhone.Countries module can be used to list all known countries and return them ordered alphabetically, and optionally you can ensure your preferred countries are prepended to the list instead of mixed in with the rest.

Link to this section Summary

Functions

This function will lookup a Country by it's country code.

This function returns all known countries as LivePhone.Country structs, sorted alphabetically by country name.

This function can be used to try and find the Country for a specific phone number in the ExPhoneNumber format.

Link to this section Types

Specs

phone() :: %ExPhoneNumber.Model.PhoneNumber{
  country_code: term(),
  country_code_source: term(),
  extension: term(),
  italian_leading_zero: term(),
  national_number: term(),
  number_of_leading_zeros: term(),
  preferred_domestic_carrier_code: term(),
  raw_input: term()
}

Link to this section Functions

Link to this function

get_country(country_code)

View Source

Specs

get_country(String.t()) :: {:ok, LivePhone.Country.t()} | {:error, :not_found}

This function will lookup a Country by it's country code.

Examples:

  iex> LivePhone.Countries.get_country("US")
  {:ok, %LivePhone.Country{code: "US", flag_emoji: "πŸ‡ΊπŸ‡Έ", name: "United States of America (the)", preferred: false, region_code: "1"}}

  iex> LivePhone.Countries.get_country("FAKE")
  {:error, :not_found}
Link to this function

list_countries(preferred \\ [])

View Source

Specs

list_countries([String.t()]) :: [LivePhone.Country.t()]

This function returns all known countries as LivePhone.Country structs, sorted alphabetically by country name.

Optionally you can specify a list of preferred country codes, these will subsequently be prepended to the list.

# This will return everything alphabetically
abc_countries = LivePhone.Countries.list_countries()

# This will return it alphabetically as well, but push
# the US and GB `LivePhone.Country` structs to the top
# of the list.
my_countries = LivePhone.Countries.list_countries(["US", "GB"])

Specs

lookup(phone()) :: {:ok, LivePhone.Country.t()} | {:error, :not_found}

This function can be used to try and find the Country for a specific phone number in the ExPhoneNumber format.