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

@safeaccess/identum

v0.1.0

Published

Brazilian document validation (CPF, CNPJ, CNH, IE, PIS, CNS, RENAVAM, CEP, Plate, Voter Title) — JavaScript/TypeScript

Readme


TypeScript/JavaScript library for validating Brazilian documents — CPF, CNPJ, CNH, CEP, CNS, PIS, IE (all 27 states), RENAVAM, Mercosul Plate, and Voter Title. ESM, input sanitization by default, zero production dependencies.

Features

  • 10 document types — CPF, CNPJ (alphanumeric), CNH, CEP, CNS, PIS, IE (all 27 states), RENAVAM, Mercosul Plate, Voter Title
  • IE all 27 states — every state algorithm implemented and tested with edge cases
  • Input sanitization by default'529.982.247-25' and '52998224725' both just work
  • validateOrFail() — throws ValidationException instead of returning false
  • Blacklist / whitelist — force-accept or force-reject specific values
  • 100% line + branch coverage — tested with Vitest · Stryker mutation testing (≥ 85% MSI)
  • Native ESM — no CommonJS fallback, tree-shakeable
  • Zero production dependencies — pure TypeScript

The problem

Validating Brazilian documents in JavaScript/TypeScript means maintaining arithmetic loops for CPF, two-pass Mod-11 for CNPJ, and 27 algorithms for IE — each in a different file, none with parity tests.

Without this library:

function validateCpf(cpf: string): boolean {
    cpf = cpf.replace(/\D/g, '');
    if (cpf.length !== 11 || /^(\d)\1+$/.test(cpf)) return false;
    // loops, running sums, modulus, digit comparison...
}

With this library:

Identum.cpf('529.982.247-25').validate();                  // true
Identum.ie('343173196450', StateEnum.SP).validate();       // true — all 27 states

Installation

npm install @safeaccess/identum

Requirements: Node.js 22+

Quick start

import { Identum, StateEnum, ValidationException } from '@safeaccess/identum';

// All document types — formatting stripped automatically
Identum.cpf('529.982.247-25').validate();                    // true
Identum.cnpj('84.773.274/0001-03').validate();               // true
Identum.cnpj('A0000000000032').validate();                   // true — alphanumeric CNPJ
Identum.cnh('22522791508').validate();                       // true
Identum.cep('78000-000').validate();                         // true
Identum.cns('100000000060018').validate();                   // true
Identum.pis('329.9506.158-9').validate();                    // true
Identum.ie('343173196450', StateEnum.SP).validate();         // true — all 27 states
Identum.renavam('60390908553').validate();                   // true
Identum.placa('ABC1D23').validate();                         // true — Mercosul format
Identum.tituloEleitor('123456781295').validate();            // true

// Validate or throw
try {
    Identum.cpf('000.000.000-00').validateOrFail();
} catch (e) {
    if (e instanceof ValidationException) {
        // handle invalid document
    }
}

// Blacklist / whitelist
Identum.cpf('529.982.247-25').blacklist(['529.982.247-25']).validate(); // false
Identum.cpf('000.000.000-00').whitelist(['000.000.000-00']).validate(); // true

Direct instantiation

import { CPFValidation } from '@safeaccess/identum';

const validator = new CPFValidation('529.982.247-25');
validator.validate(); // true

API

All validator classes share the same fluent interface after construction:

const v = Identum.cpf('52998224725'); // or new CPFValidation('52998224725')

v.validate();                                  // boolean
v.validateOrFail();                            // boolean — throws ValidationException if invalid
v.blacklist(['52998224725']).validate();        // boolean — force-reject these values
v.whitelist(['00000000000']).validate();        // boolean — force-accept these values

| Method | Return | Description | | --- | --- | --- | | validate() | boolean | Returns true if valid, false otherwise | | validateOrFail() | boolean | Returns true if valid, throws ValidationException otherwise | | blacklist(string[]) | this | Force-reject the specified values regardless of checksum | | whitelist(string[]) | this | Force-accept the specified values regardless of checksum |

Supported documents

| Document | Alias | Class | | -------------- | --------------- | ------------------------- | | CPF | cpf | CPFValidation | | CNPJ | cnpj | CNPJValidation | | CNH | cnh | CNHValidation | | CEP | cep | CEPValidation | | CNS | cns | CNSValidation | | PIS/PASEP | pis | PISValidation | | IE | ie | IEValidation | | RENAVAM | renavam | RenavamValidation | | Mercosul Plate | placa | PlateMercosulValidation | | Voter Title | tituloEleitor | VoterTitleValidation |

IE — all 27 states

import { Identum, StateEnum } from '@safeaccess/identum';

Identum.ie('153189458', StateEnum.BA).validate();     // Bahia — Mod-10/11 dual
Identum.ie('7908930932562', StateEnum.MG).validate(); // Minas Gerais
Identum.ie('P199163724045', StateEnum.SP).validate(); // São Paulo rural (P prefix)

CNPJ — alphanumeric

Identum.cnpj('A0000000000032').validate(); // true — alphanumeric CNPJ

Contributing

See CONTRIBUTING.md for development setup, commit conventions, and pull request guidelines.

License

MIT © Felipe Sauer