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

validadores-pt

v1.0.1

Published

Generation and validation of Portuguese NIF, NISS, Citizen Card and IBAN. TypeScript, zero dependencies, tested.

Readme

validadores-pt

Generation and validation of Portuguese NIF, NISS, Citizen Card and IBAN. TypeScript, zero dependencies, test coverage with official cases.

The generated numbers are mathematically valid (they pass the check digits), but fictitious — they don't belong to anyone real. Meant for software testing and development, never for real documents.

Extracted from the library used at geranif.pt, where each algorithm is documented step by step with a hand-worked example:

Installation

npm install validadores-pt

Usage

import { validateNIF, generateNIF, validateIBAN, generateIBAN } from 'validadores-pt';

validateNIF('123456789'); // true
generateNIF('individual'); // "217345670" (varies on each call)

validateIBAN('PT50000201231234567890154'); // true
generateIBAN();                            // "PT50..." from a random bank

Every validation function has a *Detailed variant that returns the exact reason for failure (useful for form error messages):

import { validateNIFDetailed } from 'validadores-pt';

validateNIFDetailed('123456780');
// { valid: false, error: 'checkDigit', expectedDigit: 9, type: 'individual' }

NIF

import { validateNIF, validateNIFDetailed, generateNIF, typeOfNIF } from 'validadores-pt';

validateNIF('123456789');          // true
typeOfNIF('123456789');            // "individual"
generateNIF('corporate');          // corporate NIF (prefix 5)
generateNIF();                     // random type

Types accepted by generateNIF: 'individual' | 'corporate' | 'nonResident' | 'public' | 'other' | 'any'.

NISS

import { validateNISS, generateNISS } from 'validadores-pt';

validateNISS('12345678902'); // true
generateNISS('individual');  // individual NISS (prefix 1)

Citizen Card

import { validateCC, generateCC } from 'validadores-pt';

validateCC('000000000ZZ4'); // true
generateCC();                // full document number (NIC + version + final check digit)

IBAN / NIB

import { validateIBAN, generateIBAN, generateNIB, validateNIB, validateNIBDetailed, PT_BANKS } from 'validadores-pt';

validateIBAN('PT50000201231234567890154'); // true
generateIBAN();                            // random bank among those in PT_BANKS
generateIBAN('0035');                      // Caixa Geral de Depósitos IBAN

validateNIBDetailed('000201231234567890154');
// { valid: true }

Display formatting

import { formatNIF, formatCC, formatIBAN } from 'validadores-pt';

formatNIF('123456789');                   // "123 456 789"
formatIBAN('PT50000201231234567890154');  // "PT50 0002 0123 1234 5678 9015 4"

Algorithms

| Document | Check digit rule | |---|---| | NIF | Modulo 11, weights 9 to 2 over the first 8 digits | | NISS | Prime weights [29,23,19,17,13,11,7,5,3,2], check digit = 9 − (sum mod 10) | | Citizen Card | Modulo 11 (NIC, former ID card rule) + base-36 Luhn (final check digit) | | IBAN / NIB | 98 − (mod 97) for the NIB · ISO 13616 (mod 97 = 1) for the full IBAN |

Full explanation of each, with a digit-by-digit worked example, at geranif.pt.

Try the generators and validators online

No installation needed: geranif.pt generates up to 100 numbers of each type at once, ready to export.

License

MIT