cnpj v0.2.0 CNPJ
CNPJ provides you functions to work with CNPJs.
Link to this section Summary
Functions
Returns a tuple with the eleven digits of the given cnpj.
Formats a cnpj to friendly readable text.
Returns an :ok tuple with a cnpj when the given number is valid.
Otherwise returns an :error tuple with the error reason.
Returns a cnpj when the given number is valid. Otherwise raises
CNPJ.ParsingError error.
Returns true if given number is a valid CNPJ, otherwise false.
Link to this section Types
The CNPJ type. It' composed of fourteen digits(0-9]).
Link to this section Functions
Returns a tuple with the eleven digits of the given cnpj.
Examples
iex> 70947414000108 |> CNPJ.parse!() |> CNPJ.digits() {7, 0, 9, 4, 7, 4, 1, 4, 0, 0, 0, 1, 0, 8}
Formats a cnpj to friendly readable text.
Examples
iex> 70947414000108 |> CNPJ.parse!() |> CNPJ.format()
"70.947.414/0001-08"
parse(number)
parse(pos_integer() | String.t()) :: {:ok, t()} | {:error, CNPJ.ParsingError.t()}
Returns an :ok tuple with a cnpj when the given number is valid.
Otherwise returns an :error tuple with the error reason.
Examples
iex> CNPJ.parse(30794968000106)
{:ok, %CNPJ{digits: {3, 0, 7, 9, 4, 9, 6, 8, 0, 0, 0, 1, 0, 6}}}
iex> CNPJ.parse("30794968000106")
{:ok, %CNPJ{digits: {3, 0, 7, 9, 4, 9, 6, 8, 0, 0, 0, 1, 0, 6}}}
iex> CNPJ.parse("70.947.414/0001-08")
{:ok, %CNPJ{digits: {7, 0, 9, 4, 7, 4, 1, 4, 0, 0, 0, 1, 0, 8}}}
iex> CNPJ.parse(82)
{:error, %CNPJ.ParsingError{reason: :invalid_verifier}}
Returns a cnpj when the given number is valid. Otherwise raises
CNPJ.ParsingError error.
Examples
iex> CNPJ.parse!(30794968000106)
%CNPJ{digits: {3, 0, 7, 9, 4, 9, 6, 8, 0, 0, 0, 1, 0, 6}}
iex> CNPJ.parse!("30794968000106")
%CNPJ{digits: {3, 0, 7, 9, 4, 9, 6, 8, 0, 0, 0, 1, 0, 6}}
iex> CNPJ.parse!("70.947.414/0001-08")
%CNPJ{digits: {7, 0, 9, 4, 7, 4, 1, 4, 0, 0, 0, 1, 0, 8}}
iex> CNPJ.parse!(82)
** (CNPJ.ParsingError) invalid_verifier
Returns true if given number is a valid CNPJ, otherwise false.
Examples
iex> CNPJ.valid?(87)
false
iex> CNPJ.valid?(30794968000106)
true
iex> CNPJ.valid?("87")
false
iex> CNPJ.valid?("30794968000106")
true
iex> CNPJ.valid?("70.947.414/0001-08")
true