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

validador-fiscal-mx

v1.1.0

Published

Validación completa de RFC, CURP, NSS y otros identificadores fiscales mexicanos

Readme

validador-fiscal-mx

Validación completa de RFC, CURP, NSS y otros identificadores fiscales mexicanos con detección automática de tipo.

npm version License: MIT CI

Features

  • Validación de RFC — personas físicas (13 chars) y morales (12 chars)
  • Validación de CURP — estructura, estado, dígito verificador
  • Validación de NSS — Número de Seguridad Social IMSS (11 dígitos)
  • Detección automática — identifica el tipo de identificador sin que lo especifiques
  • Sin dependencias externas — validación por expresiones regulares
  • TypeScript ready — definiciones de tipos incluidas

Instalación

npm install validador-fiscal-mx

Uso

import validadorFiscal from 'validador-fiscal-mx';

Validar RFC

// Persona física (13 caracteres)
const rfcFisico = validadorFiscal.validarRFC('PEGJ850115AB1');
console.log(rfcFisico); // true

// Persona moral (12 caracteres)
const rfcMoral = validadorFiscal.validarRFC('XIA990101AB1');
console.log(rfcMoral); // true

// RFC inválido
const invalido = validadorFiscal.validarRFC('12345');
console.log(invalido); // false

Validar CURP

const esCURPValida = validadorFiscal.validarCURP('PEGJ850115HJCRRL09');
console.log(esCURPValida); // true

Validar NSS

const esNSSValido = validadorFiscal.validarNSS('12345678901');
console.log(esNSSValido); // true

Detección automática

// Detecta el tipo sin especificarlo
const tipoRFC = validadorFiscal.detectarTipo('PEGJ850115AB1');
console.log(tipoRFC); // 'RFC'

const tipoCURP = validadorFiscal.detectarTipo('PEGJ850115HJCRRL09');
console.log(tipoCURP); // 'CURP'

const tipoNSS = validadorFiscal.detectarTipo('12345678901');
console.log(tipoNSS); // 'NSS'

const desconocido = validadorFiscal.detectarTipo('abc123');
console.log(desconocido); // 'DESCONOCIDO'

Validación completa

const resultado = validadorFiscal.validarIdentificador('PEGJ850115AB1');
console.log(resultado);
// { identificador: 'PEGJ850115AB1', tipo: 'RFC', esValido: true }

API

validarRFC(rfc: string): boolean

Valida un RFC mexicano. Acepta tanto personas físicas (13 chars) como personas morales (12 chars).

validarCURP(curp: string): boolean

Valida una CURP mexicana de 18 caracteres.

validarNSS(nss: string): boolean

Valida un Número de Seguridad Social (11 dígitos).

detectarTipo(identificador: string): string

Detecta automáticamente el tipo: 'RFC', 'CURP', 'NSS' o 'DESCONOCIDO'.

validarIdentificador(identificador: string): object

Validación completa con tipo y resultado. Retorna { identificador, tipo, esValido }.

Caso de uso: formulario con validación automática

import validadorFiscal from 'validador-fiscal-mx';

function validarCampoFiscal(valor) {
  const resultado = validadorFiscal.validarIdentificador(valor);

  if (resultado.tipo === 'DESCONOCIDO') {
    return { valido: false, mensaje: 'No se reconoce como RFC, CURP o NSS' };
  }

  return {
    valido: resultado.esValido,
    tipo: resultado.tipo,
    mensaje: resultado.esValido
      ? `${resultado.tipo} válido`
      : `${resultado.tipo} con formato incorrecto`
  };
}

Testing

npm test
npm run test:coverage

Apoyo

Proyecto de código abierto mantenido en mi tiempo libre. Si te fue útil y quieres agradecerlo:

Ko-fi Buy Me a Coffee

Licencia

MIT © Gerardo Lucero, ver LICENSE.