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.
Using npm:
npm i brazilian-doc-validator
Using yarn:
yarn add brazilian-doc-validator
import {cpf} from 'brazilian-doc-validator';
or
const {cpf} = require('brazilian-doc-validator');
cpf.validate("111.111.111-11");
Result: false
const validCpf = "###########";
cpf.mask(validCpf)
Result: ###.###.###-##
const validCpf = "###.###.###-##";
cpf.unmask(validCpf)
Result: ###########
const newCpfMasked = cpf.generate({mask: true});
Result: ###.###.###-##
const newCpfOnlyNumbers = cpf.generate({mask: false});
Result: ###########
import {cnpj} from 'brazilian-doc-validator';
or
const {cnpj} = require('brazilian-doc-validator');
cnpj.validate("11.111.111/1111-11");
Result: false
const validCnpj = "##############";
cnpj.mask(validCnpj)
Result: ##.###.###/####-##
const validCnpj = "##.###.###/####-##";
cnpj.unmask(validCnpj)
Result: ##############
const newMaskedCnpj = cnpj.generate({mask: true});
Result: ##.###.###/####-##
const newCnpj = cnpj.generate({mask: false};
Result: ##############
To do
npm run test