Cpf
🇧🇷 Validate, generate and format CPF numbers
Install / Use
/learn @fnando/CpfREADME
CPF
This package does some CPF magic. It allows you to create, validate and format CPF documents.
HINT: Check out the CNPJ counter part available at https://github.com/fnando/cnpj.
Installation
This lib is available as a NPM package. To install it, use the following command:
npm install @fnando/cpf --save
If you're using Yarn (and you should):
yarn add @fnando/cpf
Usage
// Node.js-specific
const cpf = require("@fnando/cpf/commonjs");
// @import
import * as cpf from "@fnando/cpf"; // import the whole library
import { isValid as isValidCpf } from "@fnando/cpf"; // import just one function
// import via <script>; the lib will available as window.CPF
// <script src="cpf.js"></script>
cpf.isValid("532.820.857-96");
//=> true
cpf.isValid("53282085796");
//=> true
cpf.strip("532.820.857-96");
//=> 53282085796
cpf.format("53282085796");
//=> 532.820.857-96
cpf.generate(true); // generate formatted number
//=> 838.684.734-40
cpf.generate(); // generate unformatted number
//=> 72777632898
On the web, without transformation, just use web/cpf.min.js.
Strict Validation
By default, validations will strip any characters you provide. This means that the following is valid, because only numbers will be considered:
cpf.isValid("101#688!!!!!!542......36");
//=> true
cpf.strip("101#688!!!!!!542......36");
//=> 10168854236
If you want to strict validate strings, use the following signature:
cpf.isValid(number, strict);
The same example would now return false:
cpf.isValid("101#688!!!!!!542......36", true);
//=> false
Related Skills
node-connect
352.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
111.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
352.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
352.0kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
