codigo_azul/node_modules/brazilian-doc-validator
2024-05-28 20:04:17 -04:00
..
dist Adicionado validacao do cpf 2024-05-28 20:04:17 -04:00
src/validator Adicionado validacao do cpf 2024-05-28 20:04:17 -04:00
tests Adicionado validacao do cpf 2024-05-28 20:04:17 -04:00
.DS_Store Adicionado validacao do cpf 2024-05-28 20:04:17 -04:00
.eslintignore Adicionado validacao do cpf 2024-05-28 20:04:17 -04:00
.eslintrc.json Adicionado validacao do cpf 2024-05-28 20:04:17 -04:00
babel.config.js Adicionado validacao do cpf 2024-05-28 20:04:17 -04:00
index.js Adicionado validacao do cpf 2024-05-28 20:04:17 -04:00
index.ts Adicionado validacao do cpf 2024-05-28 20:04:17 -04:00
LICENSE Adicionado validacao do cpf 2024-05-28 20:04:17 -04:00
package.json Adicionado validacao do cpf 2024-05-28 20:04:17 -04:00
README.md Adicionado validacao do cpf 2024-05-28 20:04:17 -04:00
tsconfig.json Adicionado validacao do cpf 2024-05-28 20:04:17 -04:00

brazilian-doc-validator

Validator for common brazilian patterns, such as cpf and cnpj validations. Generator and mask/unmask CPF or CNPJ document numbers. It is a npm package to be used in javascript applications.

Table of contents

Installing

Using npm:

npm i brazilian-doc-validator

Using yarn:

yarn add brazilian-doc-validator

Usage

CPF

import {cpf} from 'brazilian-doc-validator';

or

const {cpf} = require('brazilian-doc-validator');

Validation

cpf.validate("111.111.111-11");

Result: false

Mask Formated

const validCpf = "###########";
cpf.mask(validCpf)

Result: ###.###.###-##

Unmask CPF (only numbers)

const validCpf = "###.###.###-##";
cpf.unmask(validCpf)

Result: ###########

Generate Valid CPF

const newCpfMasked = cpf.generate({mask: true});

Result: ###.###.###-##

const newCpfOnlyNumbers = cpf.generate({mask: false});

Result: ###########

CNPJ

import {cnpj} from 'brazilian-doc-validator';

or

const {cnpj} = require('brazilian-doc-validator');

Validation

cnpj.validate("11.111.111/1111-11");

Result: false

Mask Formated

const validCnpj = "##############";
cnpj.mask(validCnpj)

Result: ##.###.###/####-##

Unmask CNPJ (only numbers)

const validCnpj = "##.###.###/####-##";
cnpj.unmask(validCnpj)

Result: ##############

Generate Valid CNPJ

const newMaskedCnpj = cnpj.generate({mask: true});

Result: ##.###.###/####-##

const newCnpj = cnpj.generate({mask: false};

Result: ##############

Contributing

To do

Testing

npm run test