npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cauacampos/validate-br

v1.1.2

Published

Biblioteca leve e sem dependências para validações de dados brasileiros.

Downloads

12

Readme

npm i @cauacampos/validate-br

Tests Passing npm version License MIT Zero Dependencies

Lightweight, zero-dependency library for Brazilian validations

A simple and performant library for validating common Brazilian data formats. No external dependencies, just pure JavaScript.

Features

Zero Dependencies - No external packages required
High Performance - Minimal overhead, optimized validations
📦 Dual Module Support - Works with both ESM and CommonJS
🧮 Real Calculations - CPF and CNPJ validation with digit verification
🛡️ Type Safe - TypeScript definitions included

Installation

npm install @caua/validate-br

Usage

ESM

import validate from '@caua/validate-br';

validate.email('[email protected]');     // true
validate.cpf('123.456.789-09');         // true/false
validate.cnpj('11.222.333/0001-81');    // true/false
validate.phone('(11) 99999-9999');      // true

Or import individual validators:

import { cpf, email, cnpj, phone } from '@caua/validate-br';

cpf('12345678909');
email('[email protected]');

CommonJS

const validate = require('@caua/validate-br');

validate.email('[email protected]');
validate.cpf('123.456.789-09');
validate.cnpj('11.222.333/0001-81');
validate.phone('11999999999');

API

email(input: string): boolean

Validates an email address using a secure regex pattern and additional RFC 5322 checks.

validate.email('[email protected]');      // true
validate.email('invalid.email');         // false
validate.email('user@domain');           // false

cpf(input: string): boolean

Validates a CPF (Cadastro de Pessoas Físicas) with real digit verification.

Accepts CPF with or without formatting:

validate.cpf('123.456.789-09');         // true
validate.cpf('12345678909');            // true
validate.cpf('111.111.111-11');         // false (invalid sequence)
validate.cpf('000.000.000-00');         // false (invalid sequence)

cnpj(input: string): boolean

Validates a CNPJ (Cadastro Nacional da Pessoa Jurídica) with real digit verification.

Accepts CNPJ with or without formatting:

validate.cnpj('11.222.333/0001-81');    // true
validate.cnpj('11222333000181');        // true
validate.cnpj('00.000.000/0000-00');    // false (invalid sequence)

phone(input: string): boolean

Validates Brazilian phone numbers (mobile and landline).

Supports:

  • With or without DDD (area code)
  • With or without formatting
  • Mobile (9 digits) and Landline (8 digits)
// With DDD
validate.phone('(11) 99999-9999');      // true (mobile)
validate.phone('(11) 3333-3333');       // true (landline)
validate.phone('11 99999-9999');        // true
validate.phone('11999999999');          // true

// Without DDD (local number)
validate.phone('999999999');            // true (mobile - 9 digits)
validate.phone('9999999-9999');         // true (mobile with formatting)
validate.phone('33333333');             // true (landline - 8 digits)
validate.phone('3333-3333');            // true (landline with formatting)

Input Normalization

All validators automatically:

  • Trim whitespace
  • Remove common formatting characters (hyphens, slashes, parentheses)
  • Handle case-insensitivity (for email)

You can pass formatted or unformatted inputs:

validate.cpf('123.456.789-09');         // ✓ Works
validate.cpf('12345678909');            // ✓ Works

validate.phone('(11) 99999-9999');      // ✓ Works
validate.phone('11999999999');          // ✓ Works

Examples

Validating User Registration

import validate from '@caua/validate-br';

function validateUserData(user) {
  const errors = {};

  if (!validate.email(user.email)) {
    errors.email = 'Invalid email';
  }

  if (!validate.cpf(user.cpf)) {
    errors.cpf = 'Invalid CPF';
  }

  if (!validate.phone(user.phone)) {
    errors.phone = 'Invalid phone number';
  }

  return Object.keys(errors).length === 0 ? { valid: true } : { valid: false, errors };
}

const result = validateUserData({
  email: '[email protected]',
  cpf: '123.456.789-09',
  phone: '(11) 99999-9999',
});

console.log(result); // { valid: true }

Validating Company Data

import { cnpj } from '@caua/validate-br';

function isValidCompany(company) {
  return cnpj(company.cnpj) && company.name.length > 0;
}

TypeScript Support

TypeScript definitions are included:

import validate from '@caua/validate-br';

const isValid: boolean = validate.cpf('123.456.789-09');

Performance

This library is optimized for performance:

  • No regex compilation on each call
  • Efficient string manipulation
  • Early validation exits
  • Minimal memory footprint

License

MIT License - see LICENSE file for details

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests.

Author

Cauã - @caua