Skip to content

feat(get-cnpj-info): add getCnpjInfo to read the root, branch and check digits of a CNPJ - #560

Open
hyanmandian wants to merge 4 commits into
claude/suframafrom
claude/get-cnpj-info
Open

hyanmandian wants to merge 4 commits into
claude/suframafrom
claude/get-cnpj-info

Conversation

@hyanmandian

@hyanmandian hyanmandian commented Sep 19, 2026

Copy link
Copy Markdown
Member

Stacked on #559. This PR sits on top of #559 (SUFRAMA) and merges after it, which in turn sits on #558 and #588. Its base branch is claude/suframa, so the diff shown here is the getCnpjInfo change alone. Part of stack #591.

What

Adds getCnpjInfo(value, options?), in the style of getIbanInfo / getNfeKeyInfo / getBoletoInfo: for a valid CNPJ it returns the fields the number encodes, otherwise null. Nothing already exported changes.

API

type GetCnpjInfoOptions = Pick<IsValidCnpjOptions, "version">; // { version?: 1 | 2 }
type CnpjInfo = {
	root: string; // positions 1 to 8 (raiz)
	branch: string; // positions 9 to 12 (número de ordem)
	checkDigits: string; // positions 13 and 14
	isInitialHeadquarters: boolean; // branch === "0001"
};

getCnpjInfo(value: string, options?: GetCnpjInfoOptions): CnpjInfo | null;
getCnpjInfo("12.345.678/0001-95");
// { root: "12345678", branch: "0001", checkDigits: "95", isInitialHeadquarters: true }

getCnpjInfo("12.abc.345/01de-35", { version: 2 });
// { root: "12ABC345", branch: "01DE", checkDigits: "35", isInitialHeadquarters: false }

getCnpjInfo("12.ABC.345/01DE-35"); // null (alphanumeric, read under version 1)
getCnpjInfo("12.345.678/0001-90"); // null (bad check digits)

Design notes:

  • version is the option of isValidCnpj, read the same way (1 numeric only and the default, 2 both formats, anything else as 1). The function delegates to isValidCnpj(value, options), so it returns a value exactly when isValidCnpj returns true for the same arguments (pinned by a property test), accepts the same masks and never throws.
  • The result carries no format field. An earlier revision returned format: "numeric" | "alphanumeric" with an exported CnpjFormat type; the caller can read the same thing off the root and branch it already has, and adding a field to a returned object later is not a breaking change while removing one is, so it stays out until someone asks for it. The version option is untouched: getCnpjInfo(value, { version }) still decides which formats are read, and an alphanumeric CNPJ under version 1 is still null.
  • branch is the name of positions 9 to 12, the same one the already released generateCnpj({ branch }) uses for them, so the package carries one name for one concept. The Receita Federal calls the block "número de ordem"; the JSDoc of CnpjInfo.branch and both docs say so. A property test round-trips generateCnpj({ branch }) through getCnpjInfo(...).branch.
  • isInitialHeadquarters, not isHeadquarters: the Receita Federal Q&A, question 25, says "o sufixo 0001 continuará indicando a matriz no momento da geração do CNPJ. No entanto, essa associação não será permanente. Com o tempo, uma filial pode se tornar a matriz [...] mesmo possuindo um número de ordem diferente de 0001". The number alone cannot tell the current headquarters, so the field only claims what the number proves.

The letter test that tells an alphanumeric CNPJ from a numeric one lived twice, once in isValidCnpj and once here, so it moved to src/_internals/constants/cnpj.ts as CNPJ_LETTER_REGEX, next to CNPJ_LENGTH and the check digit weights. Dropping the format field left isValidCnpj as its only reader, as CNPJ_LENGTH already is for parseCnpj; the constant stays where it is and its doc no longer claims a second user. Behaviour is unchanged and isValidCnpj keeps the same bundle size.

Sources

  • IN RFB nº 2.229/2024 (link published on the Receita Federal "CNPJ Alfanumérico" page). Its Anexo Único is the Anexo XV of IN RFB nº 2.119/2022: "1ª a 8ª posições [...] compondo a raiz do CNPJ", "9ª a 12ª posições [...] identificando a ordem do estabelecimento", "13ª e 14ª posições: numéricas, identificando os dígitos verificadores", for both the numeric and the alphanumeric format. The normas site is a JavaScript application whose API answers 403 to scripts, so the annex was read on the Datalegis mirror (cited as @see Based on:).
  • Receita Federal Q&A on the alphanumeric CNPJ (PDF): questions 21 and 23 (root = first 8 positions, número de ordem (branch) = 9th to 12th, either may be numeric or alphanumeric), question 25 (the branch 0001 and the matriz), and the examples AA345678/000A-29 and 12.345.678/000A-08, used as test vectors.
  • Check digit manual (PDF): the worked example 12.ABC.345/01DE-35, used as a test vector.
  • Receita Federal "CNPJ Alfanumérico" page: the index of the documents above and the July 2026 start.

The other test vectors are synthetic, with check digits computed by hand from the manual's algorithm.

Verification

Re-run on the rebased branch (base claude/suframa), after dropping the format field:

  • npm run check: pass
  • npm run test:coverage: 192 files, 6309 tests, 100% statements, branches, functions and lines
  • npm run build and npm run check:api:update: pass, report committed (CnpjFormat and CnpjInfo.format gone from the report)
  • npm run check:unused, npm run check:duplication (0 clones), npm run check:commits: pass
  • npm run test:mutation -- --mutate 'src/get-cnpj-info/get-cnpj-info.ts': 12 of 12 mutants killed, 100%
  • npm run build:docs and npm run build:jsr: run, output committed (jsr.json gains ./get-cnpj-info)
  • Not run: the browser test scripts, the full Stryker run, and check:tree-shaking (its CI job was broken on every branch rebased past feat: Standard Schema wrapper, JSR, pkg.pr.new, docs previews and a playground #556; fix(build): the document field templates stop breaking the package build #588, now at the bottom of this stack, fixes it, and the job is green here)

Rebase onto #559

Rebased onto claude/suframa after #556 landed on main. Conflicts resolved:

  • docs/llms.txt and docs/llms-full.txt are no longer tracked (they are generated now), so both were git rm-ed.
  • The getCnpjInfo section of docs/utilities.md and docs/pt-br/utilities.md was ported into the new per-utility format: a short paragraph, a bullet list for the options and the returned fields, the javascript block, and a Source: line at the end of the block.
  • src/index.ts, src/index.test.ts and reports/api/brazilian-utils.api.md kept strictly alphabetical next to getCpfInfo, which feat(get-cpf-info): add getCpfInfo #558 adds.
  • jsr.json (new on main) regenerated with npm run build:jsr.

Open points

  • The first example of question 23 of the Q&A, AA345678/0003-29, does not pass the check digit algorithm of the Receita Federal's own manual (the digits for AA3456780003 are 86; 29 is the pair of the next example, AA345678/000A-29). It reads as a typo in the Q&A, so it is left out of the tests.
  • Naming of positions 9 to 12: decided, branch, consistent with generateCnpj (was order in the first revision).
  • No headquarters / filial enum is exposed, for the reason given under isInitialHeadquarters. If a plain isHeadquarters name is preferred despite the Q&A, it is a one-line rename before release.
  • Whether the value is written in the numeric or the alphanumeric format is no longer reported. If a caller turns out to want it, it can come back as a new field without breaking anyone.

Summary by CodeRabbit

  • New Features

    • Added getCnpjInfo to parse and validate numeric or alphanumeric CNPJs.
    • Returns root, branch, check digits, and initial-headquarters status for valid values; invalid inputs return null.
    • Supports version selection and is available through the package’s public exports and subpath.
  • Documentation

    • Added usage details and examples in English and Brazilian Portuguese documentation.

@coderabbitai

coderabbitai Bot commented Sep 19, 2026

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: d1a1fa3d-6b8b-4a8d-8c6b-c92d4953faab

📥 Commits

Reviewing files that changed from the base of the PR and between ea12037 and e3a51ea.

📒 Files selected for processing (9)
  • docs/pt-br/utilities.md
  • docs/utilities.md
  • jsr.json
  • reports/api/brazilian-utils.api.md
  • src/_internals/constants/cnpj.ts
  • src/get-cnpj-info/get-cnpj-info.test.ts
  • src/get-cnpj-info/get-cnpj-info.ts
  • src/index.test.ts
  • src/index.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

Adds getCnpjInfo for validated numeric and alphanumeric CNPJ parsing. The function returns parsed fields or null, supports version selection, normalizes alphanumeric fields, classifies branch 0001, and is available through public and subpath exports.

Changes

CNPJ information lookup

Layer / File(s) Summary
Parsed CNPJ contract and parser
src/get-cnpj-info/..., src/get-cnpj-info/get-cnpj-info.test.ts
Adds CnpjInfo, GetCnpjInfoOptions, and getCnpjInfo. The parser validates input, extracts root, branch, and checkDigits, normalizes alphanumeric fields, and sets isInitialHeadquarters for branch 0001. Tests cover valid, invalid, property-based, and compile-time cases.
Shared validation and package exports
src/_internals/constants/cnpj.ts, src/is-valid-cnpj/..., src/index.ts, src/index.test.ts, jsr.json
Shares uppercase-letter detection with isValidCnpj. Adds the public exports, subpath export, and export assertions.
Public API documentation
docs/utilities.md, docs/pt-br/utilities.md, reports/api/brazilian-utils.api.md
Documents the function, options, result fields, version behavior, invalid-input results, examples, and API declarations.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant getCnpjInfo
  participant isValidCnpj
  Caller->>getCnpjInfo: Pass CNPJ and version
  getCnpjInfo->>isValidCnpj: Validate input
  isValidCnpj-->>getCnpjInfo: Return valid or invalid result
  getCnpjInfo-->>Caller: Return CnpjInfo or null
Loading

Merge Risk: ⚪ Minimal · up to e3a51

This change adds validated CNPJ parsing and public exports without a concrete remaining correctness, compatibility, security, or runtime risk requiring action before merge.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 6…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding getCnpjInfo to parse a CNPJ's root, branch, and check digits.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Sep 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (5b2b199) to head (214ce29).

Additional details and impacted files
@@               Coverage Diff                @@
##           claude/suframa      #560   +/-   ##
================================================
  Coverage          100.00%   100.00%           
================================================
  Files                 191       192    +1     
  Lines                2094      2101    +7     
  Branches              618       619    +1     
================================================
+ Hits                 2094      2101    +7     
Flag Coverage Δ
node 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Tree-shaking report

No size regression. 2 grew, 1 new out of 162 exports.

Base Head Δ
Pre-existing exports, all imported 649.9 KB 649.9 KB (gzip 166.6 KB) +4 B (+0.0%)
Full import 649.9 KB 650.1 KB (gzip 166.6 KB) +177 B (+0.0%)
Exports 161 162 +1

What changed (3)

Export Base Head Δ gzip
🆕 getCnpjInfo 1.8 KB new 1012 B
🟡 generateCnpj 1.6 KB 1.6 KB +4 B (+0.2%) 968 B
🟡 generateCNPJ 1.6 KB 1.6 KB +4 B (+0.2%) 968 B
All exports (162)
Export Base Head Δ gzip
GetAddressInfoByCepError 966 B 966 B 0 B 600 B
GetAddressInfoByCepNotFoundError 1.0 KB 1.0 KB 0 B 618 B
GetAddressInfoByCepServiceError 1.0 KB 1.0 KB 0 B 617 B
GetAddressInfoByCepValidationError 1.0 KB 1.0 KB 0 B 620 B
GetCepInfoByAddressError 966 B 966 B 0 B 600 B
GetCepInfoByAddressNotFoundError 1.0 KB 1.0 KB 0 B 618 B
GetCepInfoByAddressValidationError 1.0 KB 1.0 KB 0 B 620 B
addBusinessDays 6.8 KB 6.8 KB 0 B 2.8 KB
capitalize 2.5 KB 2.5 KB 0 B 1.3 KB
convertCurrencyToWords 2.8 KB 2.8 KB 0 B 1.5 KB
convertDateToWords 3.2 KB 3.2 KB 0 B 1.7 KB
convertLicensePlateToMercosul 1.3 KB 1.3 KB 0 B 807 B
convertNumberToWords 2.4 KB 2.4 KB 0 B 1.3 KB
differenceInBusinessDays 6.9 KB 6.9 KB 0 B 2.9 KB
formatBoleto 1.4 KB 1.4 KB 0 B 837 B
formatCEP 1.2 KB 1.2 KB 0 B 778 B
formatCNPJ 1.4 KB 1.4 KB 0 B 855 B
formatCPF 1.3 KB 1.3 KB 0 B 807 B
formatCaepf 1.3 KB 1.3 KB 0 B 787 B
formatCei 1.3 KB 1.3 KB 0 B 785 B
formatCep 1.2 KB 1.2 KB 0 B 778 B
formatCertidao 1.3 KB 1.3 KB 0 B 789 B
formatCnae 1.2 KB 1.2 KB 0 B 782 B
formatCnh 1.3 KB 1.3 KB 0 B 780 B
formatCno 1.3 KB 1.3 KB 0 B 786 B
formatCnpj 1.4 KB 1.4 KB 0 B 855 B
formatCns 1.3 KB 1.3 KB 0 B 780 B
formatCpf 1.3 KB 1.3 KB 0 B 807 B
formatCurrency 1.8 KB 1.8 KB 0 B 1.0 KB
formatIban 1.1 KB 1.1 KB 0 B 696 B
formatLegalNature 1.2 KB 1.2 KB 0 B 777 B
formatLicensePlate 1.2 KB 1.2 KB 0 B 738 B
formatNcm 1.2 KB 1.2 KB 0 B 780 B
formatNfeKey 1.3 KB 1.3 KB 0 B 783 B
formatPassport 1.0 KB 1.0 KB 0 B 643 B
formatPhone 2.8 KB 2.8 KB 0 B 1.5 KB
formatPis 1.3 KB 1.3 KB 0 B 781 B
formatProcessoJuridico 1.3 KB 1.3 KB 0 B 785 B
formatSuframa 1.3 KB 1.3 KB 0 B 779 B
formatVoterId 1.3 KB 1.3 KB 0 B 821 B
generateBoleto 2.1 KB 2.1 KB 0 B 1.2 KB
🟡 generateCNPJ 1.6 KB 1.6 KB +4 B (+0.2%) 968 B
generateCPF 1.4 KB 1.4 KB 0 B 878 B
generateCep 984 B 984 B 0 B 610 B
generateCnh 1.4 KB 1.4 KB 0 B 829 B
🟡 generateCnpj 1.6 KB 1.6 KB +4 B (+0.2%) 968 B
generateCpf 1.4 KB 1.4 KB 0 B 878 B
generateLegalNature 5.9 KB 5.9 KB 0 B 2.1 KB
generateLicensePlate 1.1 KB 1.1 KB 0 B 692 B
generatePassport 1.1 KB 1.1 KB 0 B 656 B
generatePhone 1.5 KB 1.5 KB 0 B 900 B
generatePis 1.2 KB 1.2 KB 0 B 744 B
generatePixPayload 6.3 KB 6.3 KB 0 B 2.8 KB
generateProcessoJuridico 1.4 KB 1.4 KB 0 B 870 B
generateRenavam 1.2 KB 1.2 KB 0 B 760 B
generateSuframa 1.3 KB 1.3 KB 0 B 809 B
generateVoterId 1.7 KB 1.7 KB 0 B 1021 B
getAddressInfoByCep 4.1 KB 4.1 KB 0 B 1.9 KB
getAreaCodeInfo 3.9 KB 3.9 KB 0 B 1.4 KB
getAreaCodesByState 1.6 KB 1.6 KB 0 B 917 B
getBankByCode 38.6 KB 38.6 KB 0 B 9.8 KB
getBankByIspb 38.6 KB 38.6 KB 0 B 9.8 KB
getBanks 38.4 KB 38.4 KB 0 B 9.6 KB
getBoletoInfo 3.1 KB 3.1 KB 0 B 1.6 KB
getCbo 119.1 KB 119.1 KB 0 B 30.7 KB
getCepInfoByAddress 2.7 KB 2.7 KB 0 B 1.4 KB
getCertidaoInfo 1.8 KB 1.8 KB 0 B 1.0 KB
getCfop 68.9 KB 68.9 KB 0 B 6.9 KB
getCities 154.3 KB 154.3 KB 0 B 49.9 KB
getCnae 93.9 KB 93.9 KB 0 B 21.2 KB
🆕 getCnpjInfo 1.8 KB new 1012 B
getCpfInfo 1.7 KB 1.7 KB 0 B 999 B
getFormatLicensePlate 1.1 KB 1.1 KB 0 B 692 B
getHolidays 6.1 KB 6.1 KB 0 B 2.6 KB
getIbanInfo 1.6 KB 1.6 KB 0 B 955 B
getLegalNature 6.3 KB 6.3 KB 0 B 2.3 KB
getLegalNatures 5.9 KB 5.9 KB 0 B 2.1 KB
getLegalNaturesByCategory 6.5 KB 6.5 KB 0 B 2.4 KB
getMunicipalities 156.4 KB 156.4 KB 0 B 50.3 KB
getMunicipality 154.9 KB 154.9 KB 0 B 50.3 KB
getMunicipalityByCode 156.5 KB 156.5 KB 0 B 50.4 KB
getNfeKeyInfo 2.7 KB 2.7 KB 0 B 1.5 KB
getPixKeyInfo 4.5 KB 4.5 KB 0 B 2.0 KB
getPixPayloadInfo 2.9 KB 2.9 KB 0 B 1.4 KB
getStateByIbgeCode 3.2 KB 3.2 KB 0 B 1.1 KB
getStateCodeByName 3.2 KB 3.2 KB 0 B 1.1 KB
getStateNameByCode 3.1 KB 3.1 KB 0 B 1.0 KB
getStates 3.0 KB 3.0 KB 0 B 1017 B
getTimezoneByState 1.6 KB 1.6 KB 0 B 809 B
isBusinessDay 6.5 KB 6.5 KB 0 B 2.7 KB
isHoliday 6.4 KB 6.4 KB 0 B 2.7 KB
isValidBankAccount 7.4 KB 7.4 KB 0 B 2.8 KB
isValidBoleto 2.4 KB 2.4 KB 0 B 1.3 KB
isValidCEP 984 B 984 B 0 B 610 B
isValidCNPJ 1.6 KB 1.6 KB 0 B 914 B
isValidCPF 1.3 KB 1.3 KB 0 B 805 B
isValidCaepf 1.5 KB 1.5 KB 0 B 913 B
isValidCbo 119.2 KB 119.2 KB 0 B 30.7 KB
isValidCei 1.5 KB 1.5 KB 0 B 898 B
isValidCep 984 B 984 B 0 B 610 B
isValidCertidao 1.6 KB 1.6 KB 0 B 938 B
isValidCfop 68.9 KB 68.9 KB 0 B 6.9 KB
isValidCnae 94.0 KB 94.0 KB 0 B 21.2 KB
isValidCnh 1.4 KB 1.4 KB 0 B 856 B
isValidCno 1.5 KB 1.5 KB 0 B 901 B
isValidCnpj 1.6 KB 1.6 KB 0 B 914 B
isValidCns 1.5 KB 1.5 KB 0 B 925 B
isValidCpf 1.3 KB 1.3 KB 0 B 805 B
isValidCreditCard 1.4 KB 1.4 KB 0 B 868 B
isValidCsosn 1.2 KB 1.2 KB 0 B 737 B
isValidCst 1.8 KB 1.8 KB 0 B 1.0 KB
isValidEmail 1.0 KB 1.0 KB 0 B 622 B
isValidIE 5.7 KB 5.7 KB 0 B 2.1 KB
isValidIban 1.3 KB 1.3 KB 0 B 836 B
isValidIe 5.7 KB 5.7 KB 0 B 2.1 KB
isValidLandlinePhone 1.5 KB 1.5 KB 0 B 932 B
isValidLegalNature 5.8 KB 5.8 KB 0 B 2.1 KB
isValidLicensePlate 1.1 KB 1.1 KB 0 B 702 B
isValidMobilePhone 1.6 KB 1.6 KB 0 B 971 B
isValidNcm 114.2 KB 114.2 KB 0 B 24.6 KB
isValidNfeKey 2.7 KB 2.7 KB 0 B 1.5 KB
isValidPIS 1.2 KB 1.2 KB 0 B 784 B
isValidPassport 1.0 KB 1.0 KB 0 B 654 B
isValidPhone 2.6 KB 2.6 KB 0 B 1.3 KB
isValidPis 1.2 KB 1.2 KB 0 B 784 B
isValidPixKey 4.6 KB 4.6 KB 0 B 2.1 KB
isValidPixPayload 2.9 KB 2.9 KB 0 B 1.5 KB
isValidProcessoJuridico 1.3 KB 1.3 KB 0 B 787 B
isValidRegistroProfissional 1.6 KB 1.6 KB 0 B 964 B
isValidRenavam 1.3 KB 1.3 KB 0 B 814 B
isValidServicePhone 1.5 KB 1.5 KB 0 B 846 B
isValidSuframa 1.4 KB 1.4 KB 0 B 884 B
isValidVin 1.6 KB 1.6 KB 0 B 995 B
isValidVoterId 1.6 KB 1.6 KB 0 B 900 B
parseBoleto 1020 B 1020 B 0 B 634 B
parseCaepf 1003 B 1003 B 0 B 621 B
parseCbo 1002 B 1002 B 0 B 620 B
parseCei 1003 B 1003 B 0 B 619 B
parseCep 1002 B 1002 B 0 B 620 B
parseCertidao 1003 B 1003 B 0 B 620 B
parseCfop 1002 B 1002 B 0 B 620 B
parseCnae 1002 B 1002 B 0 B 620 B
parseCnh 1003 B 1003 B 0 B 621 B
parseCno 1003 B 1003 B 0 B 619 B
parseCnpj 1.1 KB 1.1 KB 0 B 669 B
parseCns 1003 B 1003 B 0 B 621 B
parseCpf 1003 B 1003 B 0 B 621 B
parseCurrency 1.4 KB 1.4 KB 0 B 881 B
parseIban 1.0 KB 1.0 KB 0 B 638 B
parseLegalNature 1002 B 1002 B 0 B 620 B
parseLicensePlate 1.0 KB 1.0 KB 0 B 638 B
parseNcm 1002 B 1002 B 0 B 620 B
parseNfeKey 1.0 KB 1.0 KB 0 B 659 B
parsePassport 1.0 KB 1.0 KB 0 B 637 B
parsePhone 1.1 KB 1.1 KB 0 B 707 B
parsePis 1003 B 1003 B 0 B 621 B
parseProcessoJuridico 1003 B 1003 B 0 B 621 B
parseSuframa 1002 B 1002 B 0 B 620 B
parseVoterId 1.0 KB 1.0 KB 0 B 649 B
removeAccents 953 B 953 B 0 B 593 B
subBusinessDays 6.9 KB 6.9 KB 0 B 2.9 KB
toStandardSchema 1.1 KB 1.1 KB 0 B 713 B
How this is measured

Every export is imported alone into an esbuild consumer bundle (minified, tree-shaken) built from the head and from the base of this pull request; the sizes are the resulting bundles, gzip is their gzipped size. 🔴 marks a regression: a pre-existing export that grew more than 20% and more than 256 B, or the bundle importing every pre-existing export growing more than 5%. 🟡 is growth under the threshold, 🟢 a decrease, ⚪ no change, 🆕 an export that does not exist on the base (never a regression), 🗑️ an export that was removed. An intentional increase is accepted with the tree-shaking: accepted label.

@hyanmandian

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 19, 2026

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@hyanmandian

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 19, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@vercel

vercel Bot commented Sep 19, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
brazilian-utils Ready Ready Preview Sep 22, 2026 4:58am UTC

@hyanmandian

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 19, 2026

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@hyanmandian

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 19, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@hyanmandian hyanmandian changed the title feat(get-cnpj-info): add getCnpjInfo to read the root, order and check digits of a CNPJ feat(get-cnpj-info): add getCnpjInfo to read the root, branch and check digits of a CNPJ Sep 19, 2026
@hyanmandian
hyanmandian changed the base branch from main to claude/suframa September 22, 2026 04:44
@hyanmandian
hyanmandian added this pull request to stack #589 September 22, 2026 04:45
@pkg-pr-new

pkg-pr-new Bot commented Sep 22, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@brazilian-utils/brazilian-utils@560

commit: 214ce29

@hyanmandian

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 22, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@hyanmandian
hyanmandian removed this pull request from stack #589 September 22, 2026 04:57
…k digits of a CNPJ

A CNPJ encodes more than its validity: Anexo XV of IN RFB 2.119/2022, added by
IN RFB 2.229/2024, lays the 14 positions out as 8 (root, the entity) + 4 (order,
the establishment) + 2 (numeric check digits), for the numeric and for the
alphanumeric format assigned from July 2026. getCnpjInfo returns those fields,
the format the value is written in and whether the order is 0001, or null when
isValidCnpj turns the same arguments down.

The version option is the one of isValidCnpj (1 numeric only and the default,
2 both formats), so the CNPJ utils agree on what they read and nothing already
exported changes.

The 0001 flag is named isInitialHeadquarters because the Receita Federal Q&A
(question 25) states that a branch can become the headquarters while keeping
its order: the number only tells which establishment was the headquarters when
the root was registered.
…jInfo

Both modules asked the same question of a sanitized CNPJ, whether it
carries a letter, with their own copy of /[A-Z]/. A constant used by two
modules belongs in src/_internals/constants, next to CNPJ_LENGTH and the
check digit weights, so it moves there as CNPJ_LETTER_REGEX.

The docs of CnpjInfo.order also now say that those four positions are
the ones generateCnpj takes as branch, so a reader moving between the
two functions can tell the two names mean the same block.
Positions 9 to 12 of a CNPJ were exposed as CnpjInfo.order, after the
"número de ordem" of the Receita Federal. The already released
generateCnpj fills those same positions through its branch option, so
reading them back under a different name would make the two utilities
disagree about one concept. The key is now branch, and its JSDoc keeps
the Receita Federal term so the mapping to the official layout stays
visible.
The field only said whether the root or the branch carried a letter,
which the caller can read off root and branch it already has. Adding a
field to a returned object later is not a breaking change while removing
one is, so it stays out until someone asks for it, and CnpjFormat leaves
the public surface with it.

The version option is untouched: getCnpjInfo(value, { version }) still
decides which formats are read, and an alphanumeric CNPJ under version 1
is still null.

CNPJ_LETTER_REGEX stays in _internals/constants/cnpj.ts, next to
CNPJ_LENGTH which parse-cnpj is the only reader of, but its doc no
longer claims getCnpjInfo as a second user.
@hyanmandian

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 22, 2026

Copy link
Copy Markdown
⚠️ Action not completed

No files to review.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

This branch was successfully deployed

1 active deployment
Preview 214ce29d Deployed Sep 22, 2026 by vercel[bot]
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.

1 participant