Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/theuves/cpf
Validar, formatar e gerar números de CPF (validate, format and generate CPF numbers 🇧🇷).
https://github.com/theuves/cpf
brasil brazil cpf cpf-formate cpf-generator cpf-mask cpf-validador cpf-validate cpf-validation cpf-validator number numbers
Last synced: about 10 hours ago
JSON representation
Validar, formatar e gerar números de CPF (validate, format and generate CPF numbers 🇧🇷).
- Host: GitHub
- URL: https://github.com/theuves/cpf
- Owner: theuves
- License: mit
- Created: 2015-12-27T22:13:09.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2024-05-07T19:22:08.000Z (8 months ago)
- Last Synced: 2025-01-08T10:14:01.756Z (about 14 hours ago)
- Topics: brasil, brazil, cpf, cpf-formate, cpf-generator, cpf-mask, cpf-validador, cpf-validate, cpf-validation, cpf-validator, number, numbers
- Language: JavaScript
- Homepage: https://twitter.com/theuves/status/1528501442910334977
- Size: 701 KB
- Stars: 60
- Watchers: 2
- Forks: 13
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# `cpf`
> Functions to handle Brazilian CPF numbers
![Status](https://travis-ci.org/theuves/cpf.svg?branch=master)
***
**Precisando de um desenvolvedor? Entre em contato: [email protected]**
***## Installation
You can install it with *npm* or *yarn*.
Try:
- *npm*: `npm install cpf`
- *yarn*: `yarn add cpf`## Usage
```js
const CPF = require('cpf');
```Now, `CPF` is a object with some functions:
- `format`
- `generate`
- `isValid`### `CPF.format(cpf)`
> Format a CPF number.
#### Example
```js
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
```js
CPF.isValid('111.444.777-35');
// trueCPF.isValid('111.444.777-42');
// falseCPF.isValid('111.444.777-42', true);
// trueCPF.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