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

@sh4rkzy/brazilian-validator

v0.0.9

Published

A Brazilian document validator library for CPF validation with TypeScript support

Readme

🇧🇷 Brazilian Validator

npm version npm downloads GitHub Workflow Status TypeScript Poku Biome Coverage Status License: MIT Node.js ESM NestJS GitHub Stars

🚀 Valide documentos brasileiros (CPF e CNPJ) no NestJS/TypeScript de forma simples, nativa e sem dependências extras.

InstalaçãoUso no TypeScriptExemplos no NestJSAPI e DecoratorsTestesRoadmapContribuindoContribuindo


📦 Instalação

npm install @sh4rkzy/brazilian-validator class-validator class-transformer

ou

yarn add @sh4rkzy/brazilian-validator class-validator class-transformer

🟦 Uso no TypeScript

A biblioteca é totalmente compatível com TypeScript e pode ser usada sem NestJS.

import 'reflect-metadata';
import { validate } from 'class-validator';
import { IsCPF, IsCNPJ } from '@sh4rkzy/brazilian-validator';

class User {
  @IsCPF({ message: 'CPF inválido' })
  cpf!: string;

  @IsCNPJ({ message: 'CNPJ inválido' })
  cnpj!: string;
}

async function run() {
  const user = new User();
  user.cpf = '12345678900'; // inválido
  user.cnpj = '11222333000181'; // válido

  const errors = await validate(user);
  console.log(errors);
}

run();

Também é possível usar funções utilitárias diretamente:

import { validateCpfDigit, validateCnpjDigit } from '@sh4rkzy/brazilian-validator';

console.log(validateCpfDigit('111.444.777-35')); // true
console.log(validateCnpjDigit('11.222.333/0001-81')); // true

🛠️ Exemplos no NestJS

DTO de criação de usuário

import { IsCPF } from '@sh4rkzy/brazilian-validator';
import { Body, Controller, Post } from '@nestjs/common';

class CreateUserDto {
  @IsCPF()
  cpf!: string;
}

@Controller('users')
export class UsersController {
  @Post()
  create(@Body() body: CreateUserDto) {
    return body;
  }
}

Configurando ValidationPipe no main.ts

import { ValidationPipe } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.useGlobalPipes(new ValidationPipe());
  await app.listen(3000);
}
bootstrap();

🎯 API e Decorators

Funções utilitárias

  • validateCpfDigit(cpf: string): boolean
  • validateCnpjDigit(cnpj: string): boolean

Decorators disponíveis

  • @IsCPF(options?)
  • @IsCNPJ(options?)

Opções dos decorators:

class Company {
  @IsCPF()
  responsibleCpf!: string;

  @IsCPF({ lengthOnly: true })
  backupCpf!: string;

  @IsCNPJ({ message: 'CNPJ da empresa inválido' })
  companyCnpj!: string;
}

🧪 Testes

Este projeto possui 100% de cobertura de testes com Poku.

Executar testes

npm test

Executar testes em modo watch

npm run test:watch

Executar linting

npm run lint

🤝 Contribuindo

Contribuições são bem-vindas! Veja como contribuir:

  1. Fork o projeto
  2. Crie uma branch para sua feature (git checkout -b feature/AmazingFeature)
  3. Commit suas mudanças (git commit -m 'Add some AmazingFeature')
  4. Push para a branch (git push origin feature/AmazingFeature)
  5. Abra um Pull Request

Desenvolvimento local

# Clone o repositório
git clone https://github.com/sh4rkzy/brazilian-validator.git

# Instale as dependências
npm install

# Execute os testes
npm test

# Execute o build
npm run build

🛣️ Roadmap

  • [x] ✅ v0.0.1 - Core CPF/CNPJ validation
  • [x] ✅ v0.0.2 - TypeScript decorators
  • [x] ✅ v0.0.4 - Complete test suite
  • [ ] 🔄 v0.1.0 - RG validation
  • [ ] 🔄 v0.2.0 - CEP validation
  • [ ] 🔄 v0.3.0 - Título de Eleitor validation
  • [ ] 🔄 v0.4.0 - React Hook Form integration

📄 Licença

Este projeto está licenciado sob a Licença MIT - veja o arquivo LICENSE para detalhes.


🔗 Links Úteis

📞 Suporte

Feito com ❤️ para a comunidade

⭐ Se este projeto foi útil, considere dar uma estrela no GitHub!

Kaue Campos - Software Engineer