Skip to content

Latest commit

 

History

History
116 lines (89 loc) · 2.69 KB

File metadata and controls

116 lines (89 loc) · 2.69 KB

cpf-check

CPF generator, validator and formatter that runs both on the browser and in the server. Super small, only 447 Bytes gzipped.

Build Status Coverage Status npm version npm downloads per month

(README disponível em português README).

Installation

Install the latest version of cpf-check:

npm install cpf-check --save

Now you can use it in your index.html

<script type="text/javascript" src="./node_modules/cpf-check/dist/index.umd.js"></script>
// window.CPF

Or import it as a module.

const CPF = require('cpf-check');

// or, in ES6+

import CPF from 'cpf-check';

This module is UMD compliant, therefore it's compatible with RequireJs, AMD, CommonJs 1 & 2, etc.

API & Usage.

CPF.validate();

Method signature:

validate(someCpf: any): boolean;
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:

generate(format?: boolean): string;

This method generates valid CPFs:

import CPF, { generate } from 'cpf-check';

CPF.generate();
// « '67675467710'

generate(true);
// « '676.754.677-10'

generate();
// « '67675467710'

CPF.format();

Method signature:

format(someCpf: any): string;

This method add punctuation to CPFs strings.

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:

strip(someCpf: any): string;

This method removes non-numeric characters from a string.

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 under the MIT License. Go Crazy. 🚀