NeoFaker.Address (neo_faker v0.14.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 a specified range.

Generates a random city name.

Generates random geographic coordinates.

Generates a random country name.

Functions

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

(since 0.12.0)
@spec building_number(
  Range.t(),
  keyword()
) :: integer() | String.t()

Generates a random building number within a specified range.

Returns the building number as a string by default, or as an integer when type: :integer is passed.

Parameters

  • range - The range of building numbers. Defaults to 1..100.
  • opts - Keyword list of options:
    • :type - Return type. Either :string (default) or :integer.

Examples

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

iex> NeoFaker.Address.building_number(1..100, type: :integer)
25

city(opts \\ [])

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

Generates a random city name.

The city name is selected from locale-specific data. Pass locale: to use a different locale. See the available locales for supported codes.

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()} | float()

Generates random geographic coordinates.

Returns a {latitude, longitude} tuple by default. Use the :type option to return a single value, and :precision to control decimal places.

Parameters

  • opts - Keyword list of options:
    • :type - Which coordinate(s) to return. Defaults to :full.
    • :precision - Number of decimal places. Defaults to 6.

Options

The values for :type can be:

  • :full - Returns {latitude, longitude} tuple (default).
  • :latitude - Returns only the latitude as a float.
  • :longitude - Returns only the longitude as a float.

Examples

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

iex> NeoFaker.Address.coordinate(type: :latitude)
11.5831672

iex> NeoFaker.Address.coordinate(type: :longitude)
165.3662683

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

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

country(opts \\ [])

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

Generates a random country name.

The country name is selected from locale-specific data. Pass locale: to use a different locale. See the available locales for supported codes.

Examples

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

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