BrazilianDocuments (Brazilian Documents v0.3.0) View Source

Documentation for BrazilianDocuments.

Link to this section Summary

Functions

Format a CNPJ value.

Format a CPF value.

Generate a unformatted CNPJ.

Generate a unformatted CPF.

Check if value is a valid CNPJ.

Check if value is a valid CPF.

Link to this section Functions

Specs

format_cnpj(value :: String.t()) :: {:ok, String.t()} | :error

Format a CNPJ value.

Examples

iex> BrazilianDocuments.format_cnpj("28603414938513")
{:ok, "28.603.414/9385-13"}

iex> BrazilianDocuments.format_cnpj("57.120.949/4422-42")
{:ok, "57.120.949/4422-42"}

iex> BrazilianDocuments.format_cnpj("91084416506")
:error

iex> BrazilianDocuments.format_cnpj("123")
:error

iex> BrazilianDocuments.format_cnpj("invalid")
:error

Specs

format_cpf(value :: String.t()) :: {:ok, String.t()} | :error

Format a CPF value.

Examples

iex> BrazilianDocuments.format_cpf("21987198433")
{:ok, "219.871.984-33"}

iex> BrazilianDocuments.format_cpf("219.871.984-33")
{:ok, "219.871.984-33"}

iex> BrazilianDocuments.format_cpf("62653322064594")
:error

iex> BrazilianDocuments.format_cpf("123")
:error

iex> BrazilianDocuments.format_cpf("invalid")
:error

Specs

generate_cnpj() :: String.t()

Generate a unformatted CNPJ.

Examples

iex> cnpj = BrazilianDocuments.generate_cnpj()
iex> BrazilianDocuments.valid_cnpj?(cnpj)
true

Specs

generate_cpf() :: String.t()

Generate a unformatted CPF.

Examples

iex> cnpj = BrazilianDocuments.generate_cpf()
iex> BrazilianDocuments.valid_cpf?(cnpj)
true

Specs

valid_cnpj?(value :: String.t()) :: boolean()

Check if value is a valid CNPJ.

Examples

iex> BrazilianDocuments.valid_cnpj?("69.103.604/0001-60")
true

iex> BrazilianDocuments.valid_cnpj?("41142260000189")
true

iex> BrazilianDocuments.valid_cnpj?("411407182")
false

iex> BrazilianDocuments.valid_cnpj?("11.111.111/1111-11")
false

Specs

valid_cpf?(value :: String.t()) :: boolean()

Check if value is a valid CPF.

Examples

iex> BrazilianDocuments.valid_cpf?("366.418.768-70")
true

iex> BrazilianDocuments.valid_cpf?("36641876870")
true

iex> BrazilianDocuments.valid_cpf?("366.418")
false

iex> BrazilianDocuments.valid_cpf?("213.198.013-20")
false

iex> BrazilianDocuments.valid_cpf?("2131201872781")
false

iex> BrazilianDocuments.valid_cpf?("11111111111")
false