Getting Started
About
@box4dev/validador-br
A lightweight and robust library for validating Brazilian documents.
The library aims to ensure that documents comply with the mathematical and check digit calculations stipulated by the institutions.
Installation
To install the package in your project, run one of the commands below:
NPM
1npm install @box4dev/validador-brYarn
1yarn add @box4dev/validador-brPNPM
1pnpm add @box4dev/validador-brImport
Named exports (recommended)
Use named functions to import only what you need.
123import { isValidCpf, isValidCnpj } from '@box4dev/validador-br';console.log(isValidCpf('123.456.789-09')); // true ou falseconsole.log(isValidCnpj('GY.HU8.PG2/971E-10')); // true ou falsevalidate object (centralized)
Or use the `validate` object which centralizes all validators.
123import { validate } from '@box4dev/validador-br';console.log(validate.cpf('123.456.789-09')); // true ou falseconsole.log(validate.cnpj('12.345.678/0001-95')); // true ou falseCommonJS (require)
123const { isValidCpf, isValidCnpj, validate } = require('@box4dev/validador-br');console.log(isValidCpf('12345678909')); // true ou falseconsole.log(validate.cnpj('GYHU8PG2971E10')); // true ou false