Installations
npm install cpf-cnpj-validator
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
12.16.1
NPM Version
6.10.1
Score
98.4
Supply Chain
100
Quality
75.2
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (98.23%)
JavaScript (1.77%)
Developer
carvalhoviniciusluiz
Download Statistics
Total Downloads
6,682,258
Last Day
927
Last Week
33,197
Last Month
215,757
Last Year
2,445,306
GitHub Statistics
209 Stars
71 Commits
28 Forks
5 Watching
7 Branches
6 Contributors
Package Meta Information
Latest Version
1.0.3
Package Id
cpf-cnpj-validator@1.0.3
Size
4.17 kB
NPM Version
6.10.1
Node Version
12.16.1
Publised On
02 Sept 2020
Total Downloads
Cumulative downloads
Total Downloads
6,682,258
Last day
-91.5%
927
Compared to previous day
Last week
-37.8%
33,197
Compared to previous week
Last month
2.2%
215,757
Compared to previous month
Last year
34.8%
2,445,306
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
cpf-cnpj-validator
Valida e formata strings de CPF ou CNPJ.
Requer:
Node ^8.0.0
.
@hapi/joi ^17.1.0
.
Instalação:
npm i cpf-cnpj-validator -S
Uso:
:warning: NOTE: Os exemplos estão na versão es6, mas você pode está usando a sintaxe antiga como preferir.
1import { cpf } from 'cpf-cnpj-validator'; 2// or const { cpf } = require('cpf-cnpj-validator'); 3 4// gera um número de cpf 5const num = cpf.generate(); 6// #=> 25634428777 7 8// verifica se é um número válido 9cpf.isValid(num); 10// #=> true 11 12// formata o número gerado 13cpf.format(num); 14// #=> 256.344.287-77
:warning: NOTE: Os módulos de cpf e cnpj possuem métodos nomeados de forma igual diferindo se apenas os resultados.
1import { cnpj } from 'cpf-cnpj-validator'; 2// or const { cnpj } = require('cpf-cnpj-validator'); 3 4// gera um número de cpnj 5const num = cnpj.generate(); 6// #=> 58403919000106 7 8// verifica se é um número válido 9cnpj.isValid(num); 10// #=> true 11 12// formata o número gerado 13cnpj.format(num); 14// #=> 58.403.919/0001-06
Veja mais exemplos práticos consultando os testes para CPF e CNPJ.
Joi
@hapi/joi é uma excelente biblioteca para validação de objetos javascript que permite a construção de mecanismos personalizados para tal. A biblioteca cpf-cnpj-validator disponibiliza um mecanismo personalizado para Joi capaz de validar se uma string pode ser, ou não, um número válido de CPF ou CNPJ:
1import validator from 'cpf-cnpj-validator'; 2// or 3// const { validator } = require('cpf-cnpj-validator') 4// 5const Joi = require('@hapi/joi').extend(validator) 6 7const cnpjSchema = Joi.document().cnpj(); 8const cpfSchema = Joi.document().cpf(); 9 10// valida o CPF 11cpfSchema.validate('54271113107'); 12// #=> true 13 14// valida o CNPJ 15cnpjSchema.validate('38313108000107'); 16// #=> true
Maiores informações podem ser obtidas com os testes de validação 1 e validação 2.
Tests
1npm test
:rocket: Serviços
Site | Descrição |
---|---|
GERADOR_CPF | Interface para geração de números de CPF |
GERADOR_CNPJ | Interface para geração de números de CNPJ |
License
Copyright (c) 2020-present
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 4/9 approved changesets -- score normalized to 4
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 25 are checked with a SAST tool
Reason
37 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25
- Warn: Project is vulnerable to: GHSA-cwfw-4gq5-mrqx
- Warn: Project is vulnerable to: GHSA-g95f-p29q-9xw4
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-257v-vj4p-3w2h
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-7r28-3m3f-r2pr
- Warn: Project is vulnerable to: GHSA-r8j5-h5cx-65gg
- Warn: Project is vulnerable to: GHSA-2pr6-76vf-7546
- Warn: Project is vulnerable to: GHSA-8j8c-7jfh-h6hx
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-76p3-8jx3-jpfq
- Warn: Project is vulnerable to: GHSA-3rfm-jhwj-7488
- Warn: Project is vulnerable to: GHSA-hhq3-ff78-jv3g
- Warn: Project is vulnerable to: GHSA-7wpw-2hjm-89gp
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p
- Warn: Project is vulnerable to: GHSA-566m-qj78-rww5
- Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-h9rv-jmmf-4pgx
- Warn: Project is vulnerable to: GHSA-hxcc-f52p-wc94
- Warn: Project is vulnerable to: GHSA-4wf5-vphf-c2xc
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
2.3
/10
Last Scanned on 2024-12-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More