2.0.1 • Published 5 years ago

cpf v2.0.1

Weekly downloads
9,633
License
MIT
Repository
github
Last release
5 years ago

cpf

Functions to handle brazilian CPF numbers

Status

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

2.0.1

5 years ago

2.0.0

5 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.1.5

7 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago