Repository navigation
Releases: potatowski/brazilcode
Releases · potatowski/brazilcode
Release list
v3.1.0
[3.1.0] - 2026-06-20
Added
- Alphanumeric CNPJ support (in effect from July 2026): the 12-character base may
now contain the lettersA-Zin addition to digits, followed by 2 numeric
check digits. Each character contributes its value asASCII − '0'(digits map
to0-9, letters to17-42) using the same mod-11 algorithm as numeric CNPJ. CNPJ.GenerateAlphanumeric()generates a random valid alphanumeric CNPJ.digit.RemoveCNPJFormattingstrips CNPJ formatting (dots, dashes, slashes,
whitespace) and upper-cases the result while preserving letters.digit.GenerateAlphanumericCharsgenerates random alphanumeric characters
(0-9,A-Z).
Changed
CNPJ.IsValidandCNPJ.Formatnow accept both numeric (legacy) and
alphanumeric CNPJs. Input is sanitized withRemoveCNPJFormatting(which keeps
letters) instead ofRemoveNonDigits. As a result, a 14-character input that
contains letters and matches the alphanumeric shape but fails the checksum now
returnsErrCNPJInvalidrather thanErrCNPJInvalidLength.
v3.0.0
Added
- Functional options pattern for
Generatemethod (WithUFfor VoterRegistration). - Validation for identical-digit documents (e.g.,
111.111.111-11for CPF,11.111.111/1111-11for CNPJ). internal/digitpackage with pre-compiled regex andstrings.Builderoptimizations.- Benchmarks for all document types (validation, formatting, generation).
Documentinterface withOptiontype alias for cross-package compatibility.- Exported document variables (
brazilcode.CPF,brazilcode.CNPJ, etc.) for direct use. ErrDocTypeNotSupportedexported error for better error handling.- Sub-package usage: each document type can be imported individually.
- Migration guide in README.
Changed
- BREAKING: Module path changed from
v2tov3. - BREAKING:
Generatesignature changed fromGenerate(params map[string]string)toGenerate(opts ...Option). - BREAKING: Removed
src/directory — packages moved to root-level sub-packages (cpf/,cnpj/,cnh/,renavam/,voter/). - BREAKING: Removed
ifacepackage —Documentinterface now lives in rootbrazilcodepackage. - BREAKING:
voterRegistrationpackage renamed tovoter. - Replaced
regexp.MustCompileper-call with pre-compiled package-level regex. - Replaced string concatenation (
+=) withstrings.Builderfor document generation. - Replaced
fmt.Sprintf("%d", ...)withstrconv.Itoa(...)for digit conversion. - Replaced
rand.Seed(deprecated) — uses globalmath/randsource. - Consolidated utility functions into
internal/digit(unexported to consumers). - CNH
Generatenow retries on rare edge cases where check digits exceed single digit.
Removed
src/directory (Go anti-pattern).ifacepackage (unnecessary indirection).utilspackage (consolidated intointernal/digit).- Debug
fmt.Printlnin voter registration generation.
v2.1.0
What's Changed
Added
- Implement RENAVAM validation and generation functions.
- Add RENAVAM instance for vehicle registration management.
- Add unit tests for RENAVAM validation, formatting, and generation.
- Add unit tests for Document interface using a mock implementation.
- Add documentation for CPF, CNPJ, CNH, and VoterRegistration.
Changed
- Update README to reflect module path change to v2.
- Update README to include RENAVAM in the list of features.
- Update CHANGELOG with new RENAVAM features and unit tests.
Full Changelog: v2.0.0...v2.1.0
v2.0.0
What's Changed
Added
Documentinterface for document operations.IsValid,Format, andGeneratemethods for document validation and formatting.
Changed
- Converted voter registration functions to methods of
VoterRegistrationstruct implementing theDocumentinterface. - Converted CPF functions to methods of
CPFstruct implementing theDocumentinterface. - Converted CNPJ functions to methods of
CNPJstruct implementing theDocumentinterface. - Converted CNH functions to methods of
CNHstruct implementing theDocumentinterface. - Consolidated document operations into a unified interface with
IsValid,Format, andGeneratemethods. - Updated README to reflect method changes for
CNPJandVoterRegistration. - Enhanced clarity on package functionality and usage examples in README.
Fixed
- Updated voter registration test to ignore voter output.
Full Changelog: v1.1.1...v2.0.0
v1.1.1
improv: added functions about voter registration
v1.1.0
v1.0.0
Created feature to validate and generate the document CNH