feat: add support for alphanumeric CNPJ format#62
Conversation
|
Nice implementation of the alphanumeric support! |
|
Thank you very much for this, @JeanNesi! 🙏 I reviewed all three alphanumeric-CNPJ PRs against the official Receita Federal reference implementation, and yours was selected as the base: it was the only one using the correct ASCII offset of 48 ( The Merged in #67 with you as co-author. Closing this in favor of that PR — thanks again for the great work! |
|
Consolidated and merged via #67 (you are credited as co-author). Thank you! |
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>
|
Thank you for the detailed review and for carrying this forward! I'm glad the implementation was useful and that it could serve as the basis for the final solution. I really appreciate the co-author credit and the effort to adapt everything to the current codebase. 🚀 |
What changes
Adds support for the new alphanumeric CNPJ format (12 uppercase alphanumeric positions + 2 numeric check digits), as defined by the Receita Federal, while keeping the traditional numeric format fully functional.
Examples now accepted:
12.ABC.345/01DE-35(with punctuation)12ABC34501DE35(without punctuation)00.000.000/0000-00/00000000000000(legacy numeric format)How
'0'→ 0,'A'→ 17), following the Receita Federal spec.charToNumberandgenerateChecksum..,/,-), and validation uses the regex^[A-Z\d]{12}\d{2}$, ensuring uppercase letters in the first 12 positions and numeric digits in the 2 check positions.Tests
Coverage added in
validateCNPJ.spec.tsandusevalidationsbr.spec.ts:BB.BBB.BBB/BBBB-BB,AAAAAAAAAAAAAA)All tests pass with
pnpm test.