Yubin (yubin v0.1.0)

Copy Markdown View Source

Japanese postal code lookup, with data bundled from Japan Post.

Summary

Functions

Returns the date of the Japan Post data bundled with this version.

Returns the addresses of a postal code.

Returns the postal code in the form "NNN-NNNN", or {:error, :invalid} when the input is not one.

Returns the 47 prefectures in JIS order.

Functions

data_version()

@spec data_version() :: Date.t()

Returns the date of the Japan Post data bundled with this version.

lookup(input)

@spec lookup(term()) ::
  {:ok, [Yubin.Address.t(), ...]} | {:error, :not_found | :invalid}

Returns the addresses of a postal code.

Accepts the input forms of normalize/1. {:error, :not_found} can mean a code newer than the bundled data, see data_version/0.

normalize(input)

@spec normalize(term()) :: {:ok, String.t()} | {:error, :invalid}

Returns the postal code in the form "NNN-NNNN", or {:error, :invalid} when the input is not one.

The input is 7 digits with an optional hyphen after the third. Full-width characters, any hyphen or dash, a leading 〒 and spaces are accepted.

iex> Yubin.normalize("〒530ー0001")
{:ok, "530-0001"}

iex> Yubin.normalize("530-001")
{:error, :invalid}

prefectures()

@spec prefectures() :: [Yubin.Prefecture.t()]

Returns the 47 prefectures in JIS order.