Gathering detailed insights and metrics for @julioakira/cpf-cnpj-utils
Gathering detailed insights and metrics for @julioakira/cpf-cnpj-utils
Gathering detailed insights and metrics for @julioakira/cpf-cnpj-utils
Gathering detailed insights and metrics for @julioakira/cpf-cnpj-utils
CPF/CNPJ validator and formatter for NodeJS
npm install @julioakira/cpf-cnpj-utils
Typescript
Module System
Node Version
NPM Version
73.7
Supply Chain
99.4
Quality
83.1
Maintenance
100
Vulnerability
100
License
TypeScript (94.27%)
JavaScript (5.73%)
Total Downloads
20,141
Last Day
4
Last Week
200
Last Month
1,267
Last Year
17,559
1 Stars
37 Commits
1 Watching
3 Branches
1 Contributors
Latest Version
1.5.2
Package Id
@julioakira/cpf-cnpj-utils@1.5.2
Unpacked Size
27.18 kB
Size
6.10 kB
File Count
20
NPM Version
9.8.1
Node Version
18.18.2
Publised On
21 Nov 2024
Cumulative downloads
Total Downloads
Last day
-91.7%
4
Compared to previous day
Last week
-42.4%
200
Compared to previous week
Last month
-22.6%
1,267
Compared to previous month
Last year
580.1%
17,559
Compared to previous year
A zero-dependency simple toolkit to deal with CPFs and CNPJs written in Typescript.
yarn add @julioakira/cpf-cnpj-utils
npm i @julioakira/cpf-cnpj-utils
You can import or require CPF, CNPJ or both in your code.
1import { CPF, CNPJ } from '@julioakira/cpf-cnpj-utils' 2 3const { CPF, CNPJ } = require('@julioakira/cpf-cnpj-utils');
Both CPF and CNPJ packages have the same functionalities:
1// Returns 30.306.294/0001-45 2const formatted = CNPJ.Format('30306294000145'); 3 4// Returns 30306294000145 5const stripped = CNPJ.Strip('30.306.294/0001-45'); 6 7// Generates a valid unformatted CNPJ 8const cnpj = CNPJ.Generate() 9 10// Generates a valid formatted CNPJ 11const cnpj = CNPJ.Generate(true); 12 13// Returns true for valid and false for invalid 14const valid = CNPJ.Validate('30306294000145') 15const valid = CNPJ.Validate('30.306.294/0001-45'); 16 17const invalid = CNPJ.Validate('30306294000155'); 18const invalid = CNPJ.Validate('30.306.294/0001-55');
1// Returns 606.772.720-06 2const formatted = CPF.Format('60677272006'); 3 4// Returns 60677272006 5const stripped = CPF.Strip('606.772.720-06'); 6 7// Generates a valid unformatted CPF 8const cpf = CPF.Generate() 9 10// Generates a valid formatted CNPJ 11const cpf = CPF.Generate(true); 12 13// Returns true for valid and false for invalid 14const valid = CPF.Validate('60677272006') 15const valid = CPF.Validate('606.772.720-06'); 16 17const invalid = CPF.Validate('40308985062'); 18const invalid = CPF.Validate('403.089.850-62');
Some CPFs and CNPJs might have variable lengths and not be zero padded up to their regular length. The validate
function has a optional zero_pad
argument, which is true
by default but can be manually set to false
if desired:
1// CNPJ with 13 digits returns true 2const valid = CNPJ.Validate('4307650002502'); 3 4// Setting auto zero padding to false invalidates and returns false 5const invalid = CNPJ.Validate('4307650002502', false); 6
1// CPF with 10 digits returns true 2const valid = CPF.Validate('2204306240'); 3 4// Setting auto zero padding to false invalidates and returns false 5const invalid = CNPJ.Validate('2204306240', false); 6
Tests are handled by Jest.
yarn test
npm test
No vulnerabilities found.
No security vulnerabilities found.