Skip to content

feat: add support for alphanumeric CNPJ#59

Closed
wenderrodrigo wants to merge 1 commit into
reactivando:mainfrom
wenderrodrigo:feat/cnpj-alfanumerico
Closed

feat: add support for alphanumeric CNPJ#59
wenderrodrigo wants to merge 1 commit into
reactivando:mainfrom
wenderrodrigo:feat/cnpj-alfanumerico

Conversation

@wenderrodrigo

Copy link
Copy Markdown

No description provided.

@wenderrodrigo

Copy link
Copy Markdown
Author

📌 Summary

Adds support for the new alphanumeric CNPJ format introduced by Receita Federal.

✅ Changes

  • Accepts alphanumeric characters in CNPJ
  • Updates validation logic (mod 11 with alphanumeric support)
  • Maintains backward compatibility

🧪 Tests

  • Added tests for new alphanumeric format
  • Existing numeric CNPJ tests still passing

🚀 Motivation

Brazil is transitioning to alphanumeric CNPJ identifiers starting in 2026.

AZagatti added a commit that referenced this pull request Jun 24, 2026
Adds alphanumeric CNPJ validation (12 alphanumeric + 2 numeric DV) per the Receita Federal spec, keeping legacy numeric support. Consolidates #59/#60/#62; base implementation from #62 (@JeanNesi). Full canonical test set; 115 tests pass.

Co-authored-by: Jean Carlos Nesi <jean.nesi@nextfit.com.br>
@AZagatti

Copy link
Copy Markdown
Collaborator

Obrigado pela contribuição, @wenderrodrigo! 🙏

Revisei os três PRs de CNPJ alfanumérico comparando com a implementação oficial de referência da Receita Federal e, na sua, notei alguns pontos que me levaram a escolher outra base:

  1. Cálculo do dígito verificador: o charToNumber usa char.charCodeAt(0) - 55 (resultando em A→10), mas o spec oficial define offset 48 (A→17). Com o offset 55, os DVs calculados para CNPJ alfanumérico ficam incorretos — por exemplo, 12.ABC.345/01DE-35 (válido pela Receita) seria rejeitado.
  2. Alteração na função compartilhada isRepeated (em utils.ts), que é usada por outros validadores (CPF, PIS) — mudar essa função tem risco de efeito colateral nos demais.
  3. Sem testes incluídos no PR.

Acabei consolidando a funcionalidade a partir do #62 (que seguia o offset oficial) num PR novo sobre a main atual, com a suíte completa de testes canônicos da Receita: #67. Vou fechar este em favor do #67. Agradeço bastante o esforço e espero ver mais contribuições suas! 💪

@AZagatti

Copy link
Copy Markdown
Collaborator

Funcionalidade consolidada e mergeada no #67. Obrigado pela contribuição!

@AZagatti AZagatti closed this Jun 24, 2026
AZagatti added a commit that referenced this pull request Jun 24, 2026
Adds alphanumeric CNPJ validation (12 alphanumeric + 2 numeric DV) per the
Receita Federal spec, keeping legacy numeric support. Consolidates
#59/#60/#62; base implementation from #62 (@JeanNesi). Full canonical test
set; 115 tests pass.

Co-authored-by: Jean Carlos Nesi <102368879+JeanNesi@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants