@alexandrezanata/validators-core
v0.10.0-alpha.0
Published
100% open-source Brazilian document validators — CPF, CNPJ, CEP, IE (27 UFs), PIX, boleto, and more
Downloads
91
Maintainers
Readme
@alexandrezanata/validators-core
100% open-source Brazilian document validators (MIT).
npm: @alexandrezanata/validators-core
Repo: github.com/AlexandreZanata/doc-raiz
The unscoped name
br-validatorson npm is a different package. Use@alexandrezanata/validators-core.
Install
npm install @alexandrezanata/validators-coreRequires Node ≥ 18. ESM only ("type": "module").
Supported types
| Module | Functions | Golden vector |
|--------|-----------|---------------|
| CNPJ | validateCnpj, formatCnpj, stripCnpj | 12ABC34501DE35 |
| CPF | validateCpf, formatCpf, stripCpf | 12345678909 |
| CEP | validateCep, formatCep, stripCep | 01310100 |
| Placa | validatePlaca, formatPlaca, convertPlacaToMercosul | ABC1D23 |
| PIS/PASEP | validatePisPasep, formatPisPasep | 10027230888 |
| PIX key | validatePixKey, formatPixKey | [email protected] |
| Boleto | validateBoleto, formatBoleto | Situação 1 + 2 |
| Credit card | validateCartaoCredito, passesLuhn | 4111111111111111 |
| IE (27 UFs) | validateInscricaoEstadual, validateIeSp, … | per UF — see docs |
Subpath imports for tree-shaking:
import { validateCnpj } from '@alexandrezanata/validators-core/cnpj';
import { validateInscricaoEstadual } from '@alexandrezanata/validators-core/inscricao-estadual';Examples
import { validateCnpj, formatCnpj } from '@alexandrezanata/validators-core';
const result = validateCnpj('12ABC34501DE35');
// { ok: true, value: '12ABC34501DE35', format: 'alphanumeric', ... }
formatCnpj('12ABC34501DE35');
// { ok: true, formatted: '12.ABC.345/01DE-35', ... }import { validateInscricaoEstadual } from '@alexandrezanata/validators-core/inscricao-estadual';
validateInscricaoEstadual('110042490114', { uf: 'SP' });
validateInscricaoEstadual('0730000100109', { uf: 'DF' });Official sources
Every algorithm cites a primary government source. Full table: OFFICIAL-SOURCES.md
Per-type URLs also available via constants (CNPJ_OFFICIAL_SOURCE_URL, IE_OFFICIAL_SOURCE_URLS, etc.).
API reference
CLI companion
npm install -g @alexandrezanata/validators-cli
br-validators cnpj validate 12ABC34501DE35 --jsonLicense
MIT
