Skip to content
forked from theuves/cpf

Validar, formatar e gerar números de CPF (validate, format and generate CPF numbers 🇧🇷).

License

Notifications You must be signed in to change notification settings

fernando-azevedo/cpf

 
 

Repository files navigation

cpf

Functions to handle Brazilian CPF numbers

Status


Precisando de um desenvolvedor? Entre em contato: theuves@gmail.com


Installation

You can install it with npm or yarn.

Try:

  • npm: npm install cpf
  • yarn: yarn add cpf

Usage

const CPF = require('cpf');

Now, CPF is a object with some functions:

  • format
  • generate
  • isValid

CPF.format(cpf)

Format a CPF number.

Example

CPF.format('11144477735');
//=> '111.444.777-35'

Parameters

  • cpf {string} A CPF number.

Returns a string with the formatted CPF number.

CPF.generate(formatted, invalid)

Generate a random CPF number.

Parameters

  • formatted {boolean} true by default. It will generate a formatted CPF number.
  • invalid {boolean} false by default. It will generate a invalid CPF number.

Returns a CPF number.

CPF.isValid(cpf, byLength)

Check if a CPF number is valid.

Example

CPF.isValid('111.444.777-35');
// true

CPF.isValid('111.444.777-42');
// false

CPF.isValid('111.444.777-42', true);
// true

CPF.isValid('111.444.777', true);
// false

Parameters

  • cpf {string} Check if the CPF number is valid.
  • byLength {boolean} false by default. Check only if the length is valid.

Returns the check result.

License

MIT © Matheus Alves

About

Validar, formatar e gerar números de CPF (validate, format and generate CPF numbers 🇧🇷).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%