| title | Getting Started | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| description | Install Brazilian Utils, the zero-dependency library of utilities for Brazilian data, import a util, check the supported runtimes and keep your bundle small. | ||||||||||||
| keywords |
|
Brazilian Utils is a zero-dependency library of small utilities for the day-to-day problems of building software for Brazil: validating, formatting, parsing and generating CPF, CNPJ, CEP, boleto, Pix, phone numbers, holidays and more.
- Zero runtime dependencies. Nothing else lands in your
node_modulesor in your bundle. - Tree-shakeable, down to the function.
import { isValidCpf }costs about 0.5 KB minified (0.3 KB gzipped). Every util is also its own subpath entry, so the heavy ones can be lazy-loaded. - Runs everywhere. Node.js
^20.19.0 || >=22.12.0, Bun, Deno and evergreen browsers, all tested in CI. - Written in TypeScript. Types ship with the package, and every pull request is checked against the last release so the public API never changes silently.
- Validated against the official rules. Every validator cites the specification, law or dataset it implements, and the test suite is mutation-tested, not just covered.
- Documented in English and Portuguese, with an
llms.txtfor AI assistants.
npm install @brazilian-utils/brazilian-utilsThe same package works with yarn add, pnpm add and bun add. In a plain <script> tag it exposes the global BrazilianUtils:
<script src="https://unpkg.com/@brazilian-utils/brazilian-utils/dist/brazilian-utils.umd.cjs"></script>| Runtime | Supported | Tested in CI |
|---|---|---|
| Node.js | ^20.19.0 || >=22.12.0 |
20, 22, 24, 26 |
| Bun | latest | latest |
| Deno | 2.x | 2.x |
| Browsers | evergreen | Chrome, Firefox, Edge, Safari |
Import the function you need:
import { isValidCpf } from '@brazilian-utils/brazilian-utils';
isValidCpf('1232454233345'); // falseThe utilities reference lists every function, grouped by family, with its options and examples. The guides show a CPF field in React, Angular, Vue and plain JavaScript.
The documentation is indexed on Context7 as /brazilian-utils/javascript. In a coding agent connected to the Context7 MCP server, name the library in the prompt and the agent skips the library search:
Validate a CNPJ with Brazilian Utils. use library /brazilian-utils/javascript
To stop repeating it, add a rule to the agent's instructions file (CLAUDE.md, Cursor rules or the equivalent): "For Brazilian document utils, use the Context7 library /brazilian-utils/javascript".
Without Context7, point the assistant at llms.txt, which lists every utility page of the documentation site, or at utilities.md, the whole English reference in one Markdown file.
The package is tree-shakeable: importing one util from the root pulls in only that util's code. isValidCpf, for example, adds about 0.5 KB minified (0.3 KB gzipped) to your bundle.
A few utils embed an official dataset and weigh far more than everything else combined:
| Util | Dataset | Minified | Gzipped |
|---|---|---|---|
getCid10 |
CID-10 V2008 categories and subcategories plus the SIM U07 codes, with the DATASUS descriptions |
721.6 KB | 113.5 KB |
getCest |
CEST descriptions and segments (Convênio ICMS 142/18) | 102.3 KB | 24.1 KB |
getMunicipalitiesByAreaCode · getAreaCodeByMunicipalityCode |
5571 IBGE municipalities, with the DDD of each (Anatel) | 23.6 - 90.4 KB | 5.6 - 33.0 KB |
getCbo |
CBO 2002 occupation titles | 80.6 KB | 24.1 KB |
getMunicipalities · getMunicipalityByCode · getCodeByMunicipalityName · getMunicipality |
5571 IBGE municipalities, with names and codes | 76.3 - 77.2 KB | 29.5 - 30.1 KB |
getCnae |
CNAE-Subclasses 2.3 | 66.8 KB | 17.7 KB |
getCities |
5571 IBGE municipality names | 64.2 KB | 26.4 KB |
getCfop |
CFOP operation descriptions | 56.9 KB | 5.1 KB |
getNbs |
NBS 2.0 (Nomenclatura Brasileira de Serviços) descriptions | 51.1 KB | 11.3 KB |
getClassTrib |
cClassTrib (IBS/CBS) names and descriptions | 50.0 KB | 9.0 KB |
isValidNcm |
NCM (Nomenclatura Comum do Mercosul) codes | 29.6 KB | 9.0 KB |
getBanks · getBankByCode · getBankByIspb |
Banco Central STR participants (COMPE + ISPB) | 26.2 - 26.6 KB | 7.6 - 7.9 KB |
getServiceItem |
Service list of the Lei Complementar 116/2003 | 25.5 KB | 8.2 KB |
getIsbnInfo · formatIsbn |
ISBN ranges of the International ISBN Agency (RangeMessage) | 15.1 - 15.3 KB | 5.4 - 5.5 KB |
isValidCbo |
CBO 2002 occupation codes, without the titles | 6.7 KB | 1.7 KB |
isValidCid10 |
CID-10 V2008 category and subcategory codes plus the SIM U07 codes, without the descriptions |
6.7 KB | 2.4 KB |
isValidCnae |
CNAE-Subclasses 2.3 codes, without the descriptions | 4.6 KB | 1.9 KB |
isValidCest |
CEST codes, without the descriptions | 3.6 KB | 0.8 KB |
isValidNbs |
NBS 2.0 codes, without the descriptions | 3.5 KB | 1.3 KB |
The root of the package is a single ESM module, so a bundler cannot split one of these datasets out of it: importing a heavy util from the root puts its whole dataset in your main bundle, and a dynamic import() of the root does not help. To lazy-load one, import it from its own subpath:
const { getCities } = await import('@brazilian-utils/brazilian-utils/get-cities');
getCities('SP');const { getMunicipalityByCode } = await import(
'@brazilian-utils/brazilian-utils/get-municipality-by-code'
);
getMunicipalityByCode('3550308');Every util has a subpath, @brazilian-utils/brazilian-utils/<util-name> in kebab-case (isValidCpf is is-valid-cpf).
Pick one style per util in a given app. A bundler treats the root import and the subpath import as two unrelated modules, so importing getCities from both bundles the city table twice.