🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@br-validators/express

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@br-validators/express

Express and Fastify middleware for Brazilian document validators — delegates to @br-validators/core

latest
Source
npmnpm
Version
1.10.0
Version published
Maintainers
1
Created
Source

@br-validators/express

npm MIT GitHub release

Express and Fastify middleware for Brazilian document validation — delegates to @br-validators/core v1.10.0 validate* functions (BR-GENERATE-001 / BR-VALIDATE parity).

Install

pnpm add @br-validators/express @br-validators/core express

Peer dependencies: express ^4.21.0 || ^5.0.0, @br-validators/core

Express

import express from 'express';
import { brValidate } from '@br-validators/express';

const app = express();
app.use(express.json());

app.post(
  '/cliente',
  brValidate({
    body: { cpf: 'cpf', cnpj: 'cnpj', cep: 'cep' },
    uf: { from: 'body', field: 'uf' },
  }),
  (req, res) => {
    res.json({ ok: true });
  },
);

Invalid input returns HTTP 400 with a structured body:

{
  "ok": false,
  "field": "cpf",
  "code": "INVALID_CHECK_DIGIT",
  "message": "..."
}

Fastify

import Fastify from 'fastify';
import { brValidateFastify } from '@br-validators/express/fastify';

const app = Fastify();

app.post(
  '/cliente',
  {
    preHandler: brValidateFastify({
      body: { cpf: 'cpf', ie: 'inscricao-estadual' },
      uf: { from: 'body', field: 'uf' },
    }),
  },
  async () => ({ ok: true }),
);

Schema

OptionDescription
bodyMap field names → core validator type id
querySame for req.query
paramsSame for req.params
uf{ from: 'body' | 'query' | 'params', field: 'uf' } or { value: 'SP' } — required for IE and RG

Supported type ids (18)

cpf, cnpj, cep, placa, pis-pasep, pix, telefone, boleto, cartao-credito, cnh, renavam, nfe-chave, titulo-eleitor, processo-judicial, inscricao-estadual, inscricao-estadual-produtor-rural, brcode, rg

Official algorithm sources: docs/OFFICIAL-SOURCES.md.

License

MIT

Keywords

brazil

FAQs

Package last updated on 27 Jun 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts