All Projects → fnando → Cpf

fnando / Cpf

Licence: mit
🇧🇷 Validate, generate and format CPF numbers

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Labels

Projects that are alternatives of or similar to Cpf

Pnpm
Fast, disk space efficient package manager -- 快速的,节省磁盘空间的包管理工具
Stars: ✭ 14,219 (+10056.43%)
Mutual labels:  npm
Nestjs Rbac
Awesome RBAC for NestJs
Stars: ✭ 129 (-7.86%)
Mutual labels:  npm
Webpack Guide
Webpack Handbook
Stars: ✭ 136 (-2.86%)
Mutual labels:  npm
Try
📦 Quickly try out NPM packages inside a container
Stars: ✭ 128 (-8.57%)
Mutual labels:  npm
Npmcharts.com
Compare npm package downloads over time
Stars: ✭ 129 (-7.86%)
Mutual labels:  npm
Tsparticles
tsParticles - Easily create highly customizable particles animations and use them as animated backgrounds for your website. Ready to use components available for React.js, Vue.js (2.x and 3.x), Angular, Svelte, jQuery, Preact, Inferno, Solid, Riot and Web Components.
Stars: ✭ 2,694 (+1824.29%)
Mutual labels:  npm
Npm Expansions
Send us a pull request by editing expansions.txt
Stars: ✭ 1,777 (+1169.29%)
Mutual labels:  npm
Use Clippy
React Hook for reading from and writing to the user's clipboard.
Stars: ✭ 139 (-0.71%)
Mutual labels:  npm
Web Starter Kit
Web Starter Kit is an opinionated boilerplate for web development. A solid starting point for both professionals and newcomers to the industry.
Stars: ✭ 130 (-7.14%)
Mutual labels:  npm
Ohshitgit
⁉️Oh shit! A cli tool to help you unfuck your git mistakes
Stars: ✭ 135 (-3.57%)
Mutual labels:  npm
Importabular
5kb spreadsheet editor for the web, let your users import their data from excel.
Stars: ✭ 129 (-7.86%)
Mutual labels:  npm
Vscode Deploy Reloaded
Recoded version of Visual Studio Code extension 'vs-deploy', which provides commands to deploy files to one or more destinations.
Stars: ✭ 129 (-7.86%)
Mutual labels:  npm
Replem
🚴 Instantly try npm modules in REPL environment
Stars: ✭ 132 (-5.71%)
Mutual labels:  npm
Flagpack Core
Flagpack contains 260+ easily implementable flag icons to use in your design or code project.
Stars: ✭ 127 (-9.29%)
Mutual labels:  npm
Foxy
A fast, reliable, and secure NPM/Yarn bridge for Composer
Stars: ✭ 137 (-2.14%)
Mutual labels:  npm
Npm Module Checklist
Steps to check when starting, working and publishing a module to NPM
Stars: ✭ 125 (-10.71%)
Mutual labels:  npm
Chainabstractionlayer
Blockchain abstraction layer
Stars: ✭ 131 (-6.43%)
Mutual labels:  npm
Tyrian
Full-featured TypeScript on JVM
Stars: ✭ 138 (-1.43%)
Mutual labels:  npm
Npm Webdav Server
WebDAV Server for npm
Stars: ✭ 138 (-1.43%)
Mutual labels:  npm
Whackage
Multi-repo development tooling for React Native
Stars: ✭ 134 (-4.29%)
Mutual labels:  npm

CPF

Build Status NPM package version License: MIT Minified size Minified+Gzip size

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
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].