https://github.com/flasd/cpf-check
CPF Validator, Generator e Formatter, runs both on browser and server-side. Incredibly Small 2.2KB (447bytes gziped!!).
https://github.com/flasd/cpf-check
cpf cpf-validador javascript-library
Last synced: 4 months ago
JSON representation
CPF Validator, Generator e Formatter, runs both on browser and server-side. Incredibly Small 2.2KB (447bytes gziped!!).
- Host: GitHub
- URL: https://github.com/flasd/cpf-check
- Owner: flasd
- License: mit
- Created: 2017-08-01T19:18:19.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T15:15:07.000Z (about 3 years ago)
- Last Synced: 2025-08-09T03:48:53.696Z (5 months ago)
- Topics: cpf, cpf-validador, javascript-library
- Language: TypeScript
- Homepage:
- Size: 1.56 MB
- Stars: 14
- Watchers: 1
- Forks: 3
- Open Issues: 12
-
Metadata Files:
- Readme: README-en.md
- License: LICENSE
Awesome Lists containing this project
README
# cpf-check
CPF generator, validator and formatter that runs both on the browser and in the server. Super small, only 447 Bytes gzipped.
[](https://travis-ci.org/husscode/cpf-check)
[](https://coveralls.io/github/husscode/cpf-check?branch=master)
[](https://www.npmjs.com/package/cpf-check)
[](https://www.npmjs.com/package/cpf-check)
(README disponível em português [README](https://github.com/husscode/cpf-check/blob/master/README.md)).
## Installation
Install the latest version of cpf-check:
```
npm install cpf-check --save
```
Now you can use it in your index.html
```html
// window.CPF
```
Or import it as a module.
```javascript
const CPF = require('cpf-check');
// or, in ES6+
import CPF from 'cpf-check';
```
This module is [UMD](https://github.com/umdjs/umd) compliant, therefore it's compatible with RequireJs, AMD, CommonJs 1 & 2, etc.
## API & Usage.
#### CPF.validate();
Method signature:
```typescript
validate(someCpf: any): boolean;
```
```javascript
import CPF, { validate } from 'cpf-check';
const someCpf = '676.754.677-10';
CPF.validate(someCpf);
// « true
validate(someCpf);
// « true
validate('not-a-cpf');
// « false
validate('12345678910');
// « false
```
#### CPF.generate();
Method signature:
```typescript
generate(format?: boolean): string;
```
This method generates valid CPFs:
```javascript
import CPF, { generate } from 'cpf-check';
CPF.generate();
// « '67675467710'
generate(true);
// « '676.754.677-10'
generate();
// « '67675467710'
```
#### CPF.format();
Method signature:
```typescript
format(someCpf: any): string;
```
This method add punctuation to CPFs strings.
```javascript
import CPF, { format } from 'cpf-check';
const someCpf = '67675467710';
CPF.format(someCpf);
// « '676.754.677-10'
format(someCpf);
// « '676.754.677-10'
format('not-a-cpf');
// « ''
```
#### CPF.strip();
Method signature:
```typescript
strip(someCpf: any): string;
```
This method removes non-numeric characters from a string.
```javascript
import CPF, { strip } from 'cpf-check';
const someCpf = '676.754.677-10';
cpfCheck.strip(someCpf);
// « '67675467710'
strip(someCpf);
// « '67675467710'
```
### Copyright & License
Copyright (c) 2019 [Marcel de Oliveira Coelho](https://github.com/husscode) under the [MIT License](https://github.com/husscode/cpf-check/blob/master/LICENSE.md). Go Crazy. :rocket: