CPF generator, validator and formatter that runs both on the browser and in the server. Super small, only 447 Bytes gzipped.
(README disponível em português README).
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.CPFOr 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.
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');
// « falseMethod 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'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');
// « ''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 (c) 2019 Marcel de Oliveira Coelho under the MIT License. Go Crazy. 🚀