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

@ascnpj/core

v0.1.3

Published

Author-led AS-CNPJ library for validation, normalization and formatting of numeric and alphanumeric CNPJ.

Downloads

499

Readme

Idiomas: Português (Brasil) | English | Español | Français

Status

  • repositório público e ativo;
  • pacote em fase inicial 0.x;
  • publicado no npm como @ascnpj/core;
  • Trusted Publishing configurado via GitHub Actions;
  • algoritmo validado por testes automatizados e vetores compartilhados do ecossistema.

Instalação

npm install @ascnpj/core

Exemplo rápido

import {
  assertValid,
  calculateCNPJCheckDigits,
  format,
  isValid,
  normalize
} from "@ascnpj/core";

isValid("12.ABC.345/01DE-35");
normalize("12.abc.345/01de-35");
format("12ABC34501DE35");
assertValid("12.ABC.345/01DE-35", { strict: true });
calculateCNPJCheckDigits("12ABC34501DE");

Casos de uso

  • formulários web e cadastros B2B que precisam aceitar o legado e o novo padrão;
  • APIs Node.js que validam e normalizam CNPJ antes de persistir;
  • integrações com ERP, faturamento, compliance e onboarding;
  • suites de teste e homologação que precisam gerar e validar exemplos consistentes.

O que esta biblioteca entrega

  • validação de CNPJ numérico legado;
  • validação de CNPJ alfanumérico previsto pela Receita Federal para julho de 2026;
  • suporte a entradas com máscara e sem máscara;
  • modo permissivo e modo estrito;
  • zero dependências de runtime no pacote;
  • consistência com vetores compartilhados do hub.

API pública

Funções principais:

  • normalize(value)
  • isValid(value, options?)
  • format(value, options?)
  • assertValid(value, options?)
  • calculateCheckDigits(base12)
  • validateMany(values, options?)

Aliases explícitos:

  • normalizeCNPJ(value)
  • isValidCNPJ(value, options?)
  • formatCNPJ(value, options?)
  • assertValidCNPJ(value, options?)
  • calculateCNPJCheckDigits(base12)
  • validateManyCNPJ(values, options?)

Validação em lote

Além da API unitária, a biblioteca expõe:

  • validateMany(values, options?)
  • validateManyCNPJ(values, options?)

O retorno preserva a ordem de entrada e entrega:

  • items: resultado item a item com index, input, normalized, formatted, valid, strictValid e reason;
  • summary: total, válidos, inválidos e contagem agregada por motivo.
import { validateMany } from "@ascnpj/core";

const result = validateMany([
  "12.ABC.345/01DE-35",
  "12.ABC.345/01DE-36",
  null
]);

result.items[0].valid;
result.items[1].reason;
result.summary.reasons;

Garantias centrais

  • aceita A-Z0-9 nos 12 primeiros caracteres;
  • mantém os 2 dígitos verificadores como numéricos;
  • usa módulo 11 com conversão ASCII - 48;
  • normaliza entrada para caixa alta;
  • rejeita repetições triviais inválidas;
  • trata segurança de publicação e supply chain como parte do projeto.

Documentação e referências

Vetores compartilhados

O as-cnpj-js não define a verdade sozinho.

O contrato do ecossistema depende também de:

  • vetores compartilhados no hub;
  • regras documentadas a partir das fontes oficiais;
  • convergência entre implementações futuras em outras linguagens.

Manutenção

Maintainer: @0moura
Contato institucional: [email protected]