codigo_azul/node_modules/brazilian-doc-validator/README.md

1.9 KiB

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