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

ngx-cnpj-cpf-validator

v21.2.0

Published

[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)

Readme

ngx-cnpj-cpf-validator

License: MIT

Validador de CPF e CNPJ para Angular 19+ — incluindo o novo formato alfanumérico de CNPJ (IN RFB nº 2229/2024).

Instalação

npm install ngx-cnpj-cpf-validator

API

| Exportação | Tipo | Descrição | |---|---|---| | validaCPF(value) | (string) => boolean | Valida CPF com ou sem máscara | | validaCNPJ(value) | (string) => boolean | Valida CNPJ numérico ou alfanumérico | | formataCPF(value) | (string) => string | Aplica máscara XXX.XXX.XXX-YY | | formataCNPJ(value) | (string) => string | Aplica máscara XX.XXX.XXX/XXXX-YY | | removeFormatoCPF(value) | (string) => string | Remove máscara do CPF (retorna dígitos) | | removeFormatoCNPJ(value) | (string) => string | Remove máscara do CNPJ (preserva letras, uppercase) | | CnpjCpfValidator(tipo) | AsyncValidatorFn | Validator para Reactive Forms | | TipoPessoa | enum | PESSOA_FISICA = 1 | PESSOA_JURIDICA = 2 |


Validação — Reactive Forms

import { CnpjCpfValidator, TipoPessoa } from 'ngx-cnpj-cpf-validator';

this.form = new FormGroup({
  cnpj: new FormControl('', [], [CnpjCpfValidator(TipoPessoa.PESSOA_JURIDICA)]),
  cpf:  new FormControl('', [], [CnpjCpfValidator(TipoPessoa.PESSOA_FISICA)]),
});
@if (form.get('cnpj').hasError('cnpjCpfInvalid')) {
  <span>CNPJ inválido</span>
}

Erro emitido: { cnpjCpfInvalid: true }


Validação — Funções standalone

import { validaCPF, validaCNPJ } from 'ngx-cnpj-cpf-validator';

// CPF
validaCPF('529.982.247-25'); // true  — com máscara
validaCPF('52998224725');    // true  — sem máscara
validaCPF('529.982.247-26'); // false — dígito errado
validaCPF('111.111.111-11'); // false — sequência inválida

// CNPJ numérico (legado)
validaCNPJ('11.222.333/0001-81'); // true
validaCNPJ('11222333000181');     // true

// CNPJ alfanumérico — IN RFB nº 2229/2024
validaCNPJ('AB.CDE.FGH/0001-95'); // true
validaCNPJ('1A.000.000/0001-82'); // true
validaCNPJ('ab.cde.fgh/0001-95'); // true — minúsculas aceitas

Formatação

import { formataCPF, formataCNPJ } from 'ngx-cnpj-cpf-validator';

formataCPF('52998224725');    // '529.982.247-25'
formataCPF('529.982.247-25'); // '529.982.247-25' — idempotente
formataCPF('1234');           // '1234' — tamanho incorreto, retorna original

formataCNPJ('11222333000181');  // '11.222.333/0001-81'
formataCNPJ('ABCDEFGH000195'); // 'AB.CDE.FGH/0001-95'
formataCNPJ('abcdefgh000195'); // 'AB.CDE.FGH/0001-95' — uppercase automático

Remoção de máscara

import { removeFormatoCPF, removeFormatoCNPJ } from 'ngx-cnpj-cpf-validator';

removeFormatoCPF('529.982.247-25'); // '52998224725'
removeFormatoCPF('52998224725');    // '52998224725'

removeFormatoCNPJ('11.222.333/0001-81'); // '11222333000181'
removeFormatoCNPJ('AB.CDE.FGH/0001-95'); // 'ABCDEFGH000195'
removeFormatoCNPJ('ab.cde.fgh/0001-95'); // 'ABCDEFGH000195' — uppercase automático

CNPJ alfanumérico (IN RFB nº 2229/2024)

A partir de julho de 2026, a Receita Federal emite CNPJs com caracteres alfanuméricos (A–Z) na raiz (primeiros 8 caracteres). O algoritmo de dígito verificador usa o mesmo módulo 11, com mapeamento A = 10, B = 11, … Z = 35. Os campos de filial (4 dígitos) e DV (2 dígitos) permanecem numéricos.

| Campo | Posições | Conteúdo | |---|---|---| | Raiz | 0–7 | A–Z ou 0–9 | | Filial | 8–11 | 0–9 | | DV | 12–13 | 0–9 |

A função validaCNPJ suporta ambos os formatos automaticamente. Para campos com máscara no template Angular, utilize um campo sem máscara ao aceitar CNPJs alfanuméricos.