NeoFaker.Address (neo_faker v0.15.0)

Copy Markdown View Source

Functions for generating random address data.

Provides utilities to generate street names, city names, country names, building numbers, and geographic coordinates with support for multiple locales.

Summary

Functions

Generates a random building number within the given range, as a string.

Generates a random city name.

Generates a random {latitude, longitude} coordinate pair.

Generates a random country name.

Generates a random latitude between -90.0 and 90.0.

Generates a random longitude between -180.0 and 180.0.

Functions

building_number(range \\ %{__struct__: Range, first: 1, last: 100, step: 1})

(since 0.12.0)
@spec building_number(Range.t()) :: String.t()

Generates a random building number within the given range, as a string.

range defaults to 1..100. Call String.to_integer/1 yourself if you need an integer.

Examples

iex> NeoFaker.Address.building_number()
"42"

iex> NeoFaker.Address.building_number(1..100)
"25"

city(opts \\ [])

(since 0.12.0)
@spec city(keyword()) :: String.t()

Generates a random city name.

The city name is selected from locale-specific data. See the available locales for supported codes.

Options

  • :locale (atom) - the locale to use. Defaults to the application's configured locale.

Examples

iex> NeoFaker.Address.city()
"Saint Marys City"

iex> NeoFaker.Address.city(locale: :id_id)
"Palu"

coordinate(opts \\ [])

(since 0.12.0)
@spec coordinate(keyword()) :: {float(), float()}

Generates a random {latitude, longitude} coordinate pair.

For a single component, use latitude/1 or longitude/1.

Options

  • :precision (non-negative integer) - the number of decimal places. Defaults to 6.

Examples

iex> NeoFaker.Address.coordinate()
{11.5831672, 165.3662683}

iex> NeoFaker.Address.coordinate(precision: 2)
{11.58, 165.37}

country(opts \\ [])

(since 0.12.0)
@spec country(keyword()) :: String.t()

Generates a random country name.

The country name is selected from locale-specific data. See the available locales for supported codes.

Options

  • :locale (atom) - the locale to use. Defaults to the application's configured locale.

Examples

iex> NeoFaker.Address.country()
"United States"

iex> NeoFaker.Address.country(locale: :id_id)
"Amerika Serikat"

latitude(opts \\ [])

(since 0.12.0)
@spec latitude(keyword()) :: float()

Generates a random latitude between -90.0 and 90.0.

Options

  • :precision (non-negative integer) - the number of decimal places. Defaults to 6.

Examples

iex> NeoFaker.Address.latitude()
11.5831672

iex> NeoFaker.Address.latitude(precision: 4)
11.5832

longitude(opts \\ [])

(since 0.12.0)
@spec longitude(keyword()) :: float()

Generates a random longitude between -180.0 and 180.0.

Options

  • :precision (non-negative integer) - the number of decimal places. Defaults to 6.

Examples

iex> NeoFaker.Address.longitude()
165.3662683

iex> NeoFaker.Address.longitude(precision: 4)
165.3663