Skip to content

The brazilcode package provides functionality to validate, generate, and format Brazilian identification codes, including CPF, CNPJ, CNH, and Título de Eleitor (Voter Registration).

License

Notifications You must be signed in to change notification settings

potatowski/brazilcode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

97 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Brazil Code

The brazilcode package provides functionality to validate, generate, and format Brazilian identification codes, including CPF, CNPJ, CNH, and Título de Eleitor (Voter Registration).

Supported Formats

  • CPF: Cadastro de Pessoas Físicas (Individual Taxpayer Registry)
  • CNPJ: Cadastro Nacional de Pessoas Jurídicas (National Register of Legal Entities)
  • CNH: Carteira Nacional de Habilitação (National Driver's License)
  • Voter Registration (Título de Eleitor): Brazilian Electoral Registration Number
  • RENAVAM: Brazilian National Registry of Motor Vehicle

Installation

To install the brazilcode package, run the following command in your shell:

$ go get github.com/potatowski/brazilcode/v2

Usage

Once the package is installed, you can use the functions provided to generate, validate, and format documents.

Example Code:

package main

import (
	"fmt"
	"github.com/potatowski/brazilcode/v2"
)

func main() {
	// Generate a CNPJ document
	doc, err := brazilcode.CNPJ.Generate()
	if err != nil {
		panic(err)
	}

	// Format the CNPJ document
	docFormatted, err := brazilcode.CNPJ.Format(doc)
	if err != nil {
		panic(err)
	}

	// Print both unformatted and formatted documents
	fmt.Println(doc, docFormatted)
}

Alternatively, you can use the generic Generate and Format functions to generate and format any document type:

doc, err := brazilcode.Generate("CNPJ")
if err != nil {
	panic(err)
}

docFormatted, err := brazilcode.Format("CNPJ", doc)
if err != nil {
	panic(err)
}

fmt.Println(doc, docFormatted)

License

This project is licensed under the MIT License.

© 2023 João Vitor Lima da Rocha

About

The brazilcode package provides functionality to validate, generate, and format Brazilian identification codes, including CPF, CNPJ, CNH, and Título de Eleitor (Voter Registration).

Topics

Resources

License

Stars

Watchers

Forks

Languages