utilsbr
A Gleam library for Brazilian documents utilities. It provides functions to validate and generate CPF and CNPJ documents.
Installation
Run the following command in your project directory:
gleam add utilsbr@0.40.0
Then run gleam build
to download and compile the dependencies.
# Basic usage
### Import the module
Import the module and use the functions to validate and generate CPF and CNPJ documents.
```gleam
import utilsbr/cpf
import utilsbr/cnpj
pub fn main() {
// Validate CPF
cpf.validate("873.220.050-15")
}
CPF functions
import utilsbr/cpf
pub fn main() {
// Validate CPF
assert True = cpf.validate("873.220.050-15")
assert False = cpf.validate("123.456.789-09")
// Strict Validate CPF
assert True = cpf.strict_validate("873.220.050-15")
assert False = cpf.strict_validate(" 873.220.050-15 ")
assert False = cpf.strict_validate(" 873.220.050-15")
// Generate CPF
let cpf = cpf.generate()
> "873.220.050-15"
// Format CPF
let cpf = cpf.format("87322005015")
> "873.220.050-15"
// Strip CPF
let cpf = cpf.strip("873.220.050-15")
> "87322005015"
}
CNPJ functions
import utilsbr/cnpj
pub fn main() {
// Validate CNPJ
assert True = cnpj.validate("84.980.771/0001-82")
assert False = cnpj.validate("12.345.678/0001-09")
// Strict Validate CNPJ
assert True = cnpj.strict_validate("84.980.771/0001-82")
assert False = cnpj.strict_validate(" 84.980.771/0001-82 ")
assert False = cnpj.strict_validate(" 84.980.771/0001-82")
// Generate CNPJ
let cnpj = cnpj.generate()
> "84.980.771/0001-82"
// Format CNPJ
let cnpj = cnpj.format("84980771000182")
> "84.980.771/0001-82"
// Strip CNPJ
let cnpj = cnpj.strip("84.980.771/0001-82")
> "84980771000182"
}
Further documentation can be found at https://hexdocs.pm/utilsbr.