New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cpf-check

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cpf-check

Validador de CPF Moderno, Isomórfico e Super Leve.

  • 2.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
311
decreased by-68.59%
Maintainers
1
Weekly downloads
 
Created
Source

cpf-check

Gerador, validador e formatador de CPF que roda tanto no navegador quanto no servidor. Super pequeno, apenas 1.6KB gzipped.

Build Status Coverage Status npm version npm downloads per month

(README available in english in README-en).

Instalação

Instale a última versão do cpf-check:

npm install cpf-check --save

Agora é só usá-lo no seu index.html

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

Ou importa-lo como um módulo:

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

// ou, em ES6+

import CPF from 'cpf-check';

Esse módulo é compativel com o padrão UMD, portanto é compatível com o RequireJs, AMD, CommonJs 1 e 2, etc.

API & Uso.

CPF() & CPF.validate();

Assinatura do método:

Boolean validate(String algumCpf);

O export padrão é um método que valida CPFs. O método CPF() é um pseudônimo do método CPF.validate().

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

const algumCpf = '676.754.677-10';

const { valid, error, code } = CPF(algumCpf);
// valid => true
// error => false
// code => 'VALID'

const resultado = CPF.validate(algumCpf);
// resultado => { valid: true, error: false, code: 'VALID' }

const resultado = validate('não-cpf');
// resultado => { valid: false, error: true, code: 'LENGTH }

const resultado = validate('12345678910');
// resultado => { valid: false, error: true, code: 'INVALID' }
CPF.generate();

Assinatura do método:

String generate(?Boolean formatar);

Esse método gera CPFs válidos.

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

CPF.generate();
// '676.754.677-10'

generate();
// '676.754.677-10'

generate(false);
// '67675467710'
CPF.format();

Assinatura do método:

String format(String algumCpf);

Esse método embeleza strings de CPFs.

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

const meuCpf = '67675467710';

CPF.format(meuCpf);
// '676.754.677-10'

format(meuCpf);
// '676.754.677-10'
CPF.strip();

Assinatura do método:

String strip(String algumCpf);

Esse método retira caracteres não numéricos de uma string. Faz o oposto do método format();

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

const algumCpf = '676.754.677-10';

CPF.strip(algumCpf);
// '67675467710'

strip(algumCpf);
// '67675467710'

Copyright (c) 2017 Marcel de Oliveira Coelho sob a Licença MIT. Go Crazy. :rocket:

Keywords

FAQs

Package last updated on 12 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc