Overview
Implement the cnpj-fmt Ruby gem — a class-based utility for formatting and parsing CNPJ strings, fully compatible with both the traditional numeric and the upcoming alphanumeric CNPJ formats.
Background
The current CNPJ structure is purely numerical, following the format 99.999.999/9999-99 with check digits for validation. Brazil's Tax Reform introduces an alphanumeric CNPJ format, replacing the purely numeric model while keeping the same 14-character length. Under the new format, the first 12 characters of the CNPJ include letters and numbers; the last two characters remain numeric check digits. This update is effective from July 2026, and existing CNPJs containing numeric characters only will continue to be valid and recognized.
Goals
- Implement a class-based interface within the
CnpjFmt module that exposes methods to format and parse CNPJ strings.
- Apply the standard CNPJ mask:
XX.XXX.XXX/XXXX-XX.
- Strip the mask from a formatted CNPJ, returning only the raw alphanumeric characters.
- Accept both numeric-only (legacy) and alphanumeric (new format) CNPJs as valid inputs.
- Follow the same conventions already adopted by sibling packages in this monorepo (e.g.
cpf-fmt).
Expected API (tentative)
# Apply mask
CnpjFmt.format('11222333000181') # => '11.222.333/0001-81'
CnpjFmt.format('11ABC3330001DE') # => '11.ABC.333/0001-DE'
# Strip mask
CnpjFmt.unformat('11.222.333/0001-81') # => '11222333000181'
CnpjFmt.unformat('11.ABC.333/0001-DE') # => '11ABC3330001DE'
Acceptance Criteria
References
Overview
Implement the
cnpj-fmtRuby gem — a class-based utility for formatting and parsing CNPJ strings, fully compatible with both the traditional numeric and the upcoming alphanumeric CNPJ formats.Background
The current CNPJ structure is purely numerical, following the format
99.999.999/9999-99with check digits for validation. Brazil's Tax Reform introduces an alphanumeric CNPJ format, replacing the purely numeric model while keeping the same 14-character length. Under the new format, the first 12 characters of the CNPJ include letters and numbers; the last two characters remain numeric check digits. This update is effective from July 2026, and existing CNPJs containing numeric characters only will continue to be valid and recognized.Goals
CnpjFmtmodule that exposes methods to format and parse CNPJ strings.XX.XXX.XXX/XXXX-XX.cpf-fmt).Expected API (tentative)
Acceptance Criteria
CnpjFmt.format(cnpj)returns the CNPJ string with theXX.XXX.XXX/XXXX-XXmask applied.CnpjFmt.unformat(cnpj)returns the raw CNPJ string with all punctuation removed.0.1.0upon first functional release.gemspecsummary and description are updated to reflect the actual functionality.References
packages/cpf-fmt