@brazilian-utils/brazilian-utils

中文文档
2.5.0发布于 2026/10/04MITTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 16.1万

Zero-dependency, tree-shakeable TypeScript utilities for Brazilian data: validate, format, parse and generate CPF, CNPJ, CEP, boleto, Pix, phone, holidays and more.

原始使用文档
文档目录7 节
  1. Why Brazilian Utils
  2. Installation
  3. Runtime support
  4. Usage
  5. Development
  6. Contributors
  7. License
Brazilian Utils

Utilities for Brazilian data: CPF, CNPJ, CEP, boleto, Pix, holidays and more.

📖 Documentation

npm version Downloads per month License: MIT Zero dependencies TypeScript Build Status Tests codecov Mutation tests OpenSSF Scorecard OpenSSF Best Practices

Table of Contents

Getting Started

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.

Why Brazilian Utils

  • Zero runtime dependencies. Nothing else lands in your node_modules or 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.txt for AI assistants.

Installation

npm install @brazilian-utils/brazilian-utils

The 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 support

The supported range is the engines field in package.json; every row below runs in the Tests workflow on every pull request.

RuntimeSupportedTested in CI
Node.js^20.19.0 || >=22.12.020, 22, 24, 26
Bunlatestlatest
Deno2.x2.x
BrowsersevergreenChrome, Firefox, Edge, Safari

Usage

Import the function you need:

import { isValidCpf } from "@brazilian-utils/brazilian-utils";

isValidCpf("1232454233345"); // false

The utilities reference lists every function, grouped by family, with its options and examples.

  • Using an AI coding assistant? The docs are indexed on Context7 as /brazilian-utils/javascript, and llms.txt lists every util for other tools. See AI assistants.
  • The package is tree-shakeable. Every util is also available as its own subpath (e.g. @brazilian-utils/brazilian-utils/get-cities) so you can lazy-load the few heavy ones. See Bundle size.

Development

This repository uses Vite+ as the local toolchain; it is installed as a dependency, so nothing has to be installed globally beyond Node.js 24 (the version in .nvmrc, which the toolchain needs; the library itself supports Node.js ^20.19.0 || >=22.12.0).

npm install
npm run check
npm test
npm run build

CONTRIBUTING.md lists every script and the checks a pull request goes through.

Release notes are published through GitHub Releases.

Contributors

Our "thank you" goes to these wonderful people (emoji key):


Hyan Mandian

💻 📖 🤔 ⚠️

Lucas Veloso

💻 📖 🤔 ⚠️

Andreo Vieira

💻 📖 🤔 🔧

Matheus Almeida

💻 📖 ⚠️

Fernando Rogelin

💻 📖 ⚠️

rodineijf

💻 📖 ⚠️

Emerson Laurentino

💻 📖 ⚠️

Leonardo Dutra

💻 📖 ⚠️

Victor Magalhães

💻 🔧

Amauri Dias

💻 🔧

Felipe F. Diogo

💻 ⚠️

Alan Raso

💻 ⚠️

Felipe Fetter

📖

Rafael Franco

💻 📖

Rafael Pezzetti

💻 ⚠️ 📖

Antonio Roberto Furlaneto

💻 📖 ⚠️

Felipe Nolleto Nascimento

💻 📖 ⚠️

Saulo Joab

📖

Pedro Arantes

💻 📖 ⚠️

Silvio Clécio

💻 📖 ⚠️

Lucas Nascimento

💻

Lincon Kusunoki

💻 📖 ⚠️

Marcelo Cristiano

💻 📖 ⚠️

Tarcísio Batista de Freitas Junior

📖

Lucas Carrias

📖 ⚠️ 💻 🔧

Matheus Andre

📖

Henrique Volponi

💻

Lindsay Ferreira

💻

Vicente Vendramin

💻

Joao Assad

💻 ⚠️

Jander Silva

💻

kwy404

💻 ⚠️

This project follows the all-contributors specification. Contributions of any kind are welcome!

License

MIT

版本与发布记录

@brazilian-utils/brazilian-utils 共发布 21 个版本,首次发布于 2020/01/14;过去 12 个月发布了 7 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.5.0latest2026/10/041 个月前
2.4.02026/09/181 个月前
2.3.02026/04/096 个月前
2.2.02026/04/087 个月前
2.1.02026/04/037 个月前
2.0.12026/03/317 个月前

关于 @brazilian-utils/brazilian-utils 的常见问题

@brazilian-utils/brazilian-utils 是什么?

Zero-dependency, tree-shakeable TypeScript utilities for Brazilian data: validate, format, parse and generate CPF, CNPJ, CEP, boleto, Pix, phone, holidays and more.

如何安装 @brazilian-utils/brazilian-utils?

在项目目录运行 npm install @brazilian-utils/brazilian-utils,或使用 pnpm add / yarn add / bun add。

@brazilian-utils/brazilian-utils 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@brazilian-utils/brazilian-utils 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@brazilian-utils/brazilian-utils 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js ^20.19.0 || >=22.12.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@brazilian-utils/brazilian-utils 可以商用吗?

@brazilian-utils/brazilian-utils 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@brazilian-utils/brazilian-utils 的下载量有多少?

根据 npm 官方下载统计,@brazilian-utils/brazilian-utils 在 2026/10/09 – 2026/11/07 这 30 天内被下载 160,786 次,日均约 5,360 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@brazilian-utils/brazilian-utils 还在维护吗?

最新版本 2.5.0 发布于 2026/10/04(1 个月前);至今共发布 21 个版本,其中过去 12 个月发布了 7 个;首次发布于 2020/01/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。