Cepex.CEP (cepex v0.1.0) View Source
This module provides functions related to the Brazilian postal code (CEP) string representation.
A valid CEP has eight digits, e.g. 80010180 (check Cepex.CEP.t/0).
Link to this section Summary
Functions
Formats a valid CEP string. If the string may be invalid, call Cepex.CEP.parse/1 first.
Parses a CEP string or integer. If the string is not a valid CEP (check Cepex.CEP.t/0),
it tries building it by removing non-numeric characters and padding with zeros.
Link to this section Types
Specs
t() :: <<_::64>>
The Brazilian postal code (CEP) string representation without formatting, e.g. 80210130.
Link to this section Functions
Specs
format(t()) :: {:ok, <<_::72>>} | {:error, :invalid}
Formats a valid CEP string. If the string may be invalid, call Cepex.CEP.parse/1 first.
Examples
iex> Cepex.CEP.format("80210130")
{:ok, "80210-130"}
iex> Cepex.CEP.format(8344010)
{:error, :invalid}
Specs
Parses a CEP string or integer. If the string is not a valid CEP (check Cepex.CEP.t/0),
it tries building it by removing non-numeric characters and padding with zeros.
Examples
iex> Cepex.CEP.parse("80210130")
{:ok, "80210130"}
iex> Cepex.CEP.parse(80210130)
{:ok, "80210130"}
iex> Cepex.CEP.parse("80210-130")
{:ok, "80210130"}
iex> Cepex.CEP.parse(8344010)
{:ok, "08344010"}
iex> Cepex.CEP.parse("8344010")
{:ok, "08344010"}
iex> Cepex.CEP.parse("00000-000")
{:error, :invalid}
iex> Cepex.CEP.parse("80210130130130")
{:error, :invalid}