@erikarg/br-utils
v0.1.0
Published
Generate, validate and format Brazilian CPF and CNPJ documents, including the alphanumeric CNPJ format.
Maintainers
Readme
@erikarg/br-utils
Generate, validate and format Brazilian CPF and CNPJ documents — including the alphanumeric CNPJ format Receita Federal assigns to new registrations from July 2026.
Zero runtime dependencies. Strict TypeScript. Works offline, in Node and in the browser, with no framework coupling.
npm install @erikarg/br-utilsimport { generateCNPJ, validateCNPJ, formatCNPJ } from "@erikarg/br-utils";
const cnpj = generateCNPJ({ type: "alphanumeric" });
validateCNPJ(cnpj); // true
formatCNPJ(cnpj); // e.g. "12.ABC.345/01DE-35"API
| CPF | CNPJ |
| --- | --- |
| generateCPF(options?) | generateCNPJ(options?) |
| validateCPF(value) | validateCNPJ(value) |
| formatCPF(value) | formatCNPJ(value) |
| unformatCPF(value) | unformatCNPJ(value) |
| explainCPF(value) | explainCNPJ(value) |
| | getCNPJType(value) |
CLI
npx @erikarg/br-utils cpf generate
npx @erikarg/br-utils cnpj generate --type alphanumeric --json
npx @erikarg/br-utils cnpj validate 12.ABC.345/01DE-35Synthetic data
Generated values are synthetic test data. They are structurally valid but are not registered to anyone. Do not use them to impersonate real people or organizations.
Full documentation, the alphanumeric CNPJ specification and the development guide live in the repository README.
MIT © Érika Rocha
