BrDocs

Utilities for Brazilian documents in Elixir.

CNPJ

BrDocs.CNPJ supports both the numeric CNPJ model and the alphanumeric model announced by Receita Federal for new registrations from July 2026.

BrDocs.CNPJ.format("00000000000191")
# {:ok, "00.000.000/0001-91"}
BrDocs.CNPJ.format("ab12cd34000184")
# {:ok, "AB.12C.D34/0001-84"}
BrDocs.CNPJ.unformat("AB.12C.D34/0001-84")
# {:ok, "AB12CD34000184"}
BrDocs.CNPJ.valid?("AB.12C.D34/0001-84")
# true

CPF

BrDocs.CPF.format("12345678909")
# {:ok, "123.456.789-09"}
BrDocs.CPF.unformat("123.456.789-09")
# {:ok, "12345678909"}
BrDocs.CPF.valid?("123.456.789-09")
# true

Installation

If available in Hex, the package can be installed by adding br_docs to your list of dependencies in mix.exs:

def deps do
[
{:br_docs, "~> 0.1.0"}
]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/br_docs.

License

This project is licensed under the MIT License. See the LICENSE file for details.