Skip to content

v3.0.0

Choose a tag to compare

@potatowski potatowski released this 13 Apr 05:38
· 4 commits to dev since this release
v3.0.0

Added

  • Functional options pattern for Generate method (WithUF for VoterRegistration).
  • Validation for identical-digit documents (e.g., 111.111.111-11 for CPF, 11.111.111/1111-11 for CNPJ).
  • internal/digit package with pre-compiled regex and strings.Builder optimizations.
  • Benchmarks for all document types (validation, formatting, generation).
  • Document interface with Option type alias for cross-package compatibility.
  • Exported document variables (brazilcode.CPF, brazilcode.CNPJ, etc.) for direct use.
  • ErrDocTypeNotSupported exported 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 v2 to v3.
  • BREAKING: Generate signature changed from Generate(params map[string]string) to Generate(opts ...Option).
  • BREAKING: Removed src/ directory — packages moved to root-level sub-packages (cpf/, cnpj/, cnh/, renavam/, voter/).
  • BREAKING: Removed iface package — Document interface now lives in root brazilcode package.
  • BREAKING: voterRegistration package renamed to voter.
  • Replaced regexp.MustCompile per-call with pre-compiled package-level regex.
  • Replaced string concatenation (+=) with strings.Builder for document generation.
  • Replaced fmt.Sprintf("%d", ...) with strconv.Itoa(...) for digit conversion.
  • Replaced rand.Seed (deprecated) — uses global math/rand source.
  • Consolidated utility functions into internal/digit (unexported to consumers).
  • CNH Generate now retries on rare edge cases where check digits exceed single digit.

Removed

  • src/ directory (Go anti-pattern).
  • iface package (unnecessary indirection).
  • utils package (consolidated into internal/digit).
  • Debug fmt.Println in voter registration generation.