Open-Source npm Package for Polish PESEL, NIP and REGON Numbers

pl-identifiers is a free, zero-dependency npm package that validates and generates Polish PESEL, NIP, REGON, IBAN and ID card numbers.

pl-identifiers is a free, MIT-licensed JavaScript package that validates and generates five Polish identifiers: PESEL (national ID), NIP (tax ID), REGON (business registry number), NRB/IBAN (bank account) and the ID card number. Install it with npm install pl-identifiers. It has zero dependencies and ships with TypeScript types. The source is on GitHub and the package is on npm.

If you build software for the Polish market (an ERP integration or a KYC form), you will run into these numbers in your forms and test fixtures. Each one has its own checksum rule, and the snippets you find online tend to cover a single number and skip the edge cases. The same code already runs in the browser-based test data generator and PESEL generator on WuseBox. The package gives you the same logic as functions you can call from your test suite.

What does pl-identifiers validate and generate?

Identifier Validate Generate Notes
PESEL isValidPesel, decodePesel generatePesel decodes birth date and gender, explains why a number fails
NIP isValidNip generateNip accepts dashes and the PL VAT prefix
REGON isValidRegon generateRegon 9-digit and 14-digit formats
NRB / IBAN isValidNrb, isValidIban generateNrb, generateIban ISO 7064 mod 97 check, groups of four
ID card isValidIdCard generateIdCard 3 letters + 6 digits, with or without a space

Every validator strips spaces and dashes and accepts any input type. For null, a number or an empty string it returns false and never throws, so you can wire it straight into a form field.

Install and validate in two lines

npm install pl-identifiers
import { isValidPesel, isValidNip, isValidIban, generatePesel } from "pl-identifiers";

isValidPesel("44051401359");                        // true
isValidNip("PL 123-456-32-18");                     // true
isValidIban("PL61 1090 1014 0000 0712 1981 2874");  // true

generatePesel({ birthDate: "1990-05-14", gender: "female" }); // e.g. "90051437627"

The package is plain ES modules with a .d.ts file. It runs in Node.js 20+ and in modern browsers without a bundler.

How to decode a PESEL and see why it is invalid

A bare false does not help much when a user reports that your form rejects their PESEL. decodePesel returns a reason field and the data encoded in the number:

import { decodePesel } from "pl-identifiers";

decodePesel("44051401359");
// { valid: true, reason: null, value: "44051401359",
//   gender: "male", birthDate: 1944-05-14T00:00:00.000Z }

decodePesel("01023012345").reason; // "date" (February 30 does not exist)
decodePesel("44051401358").reason; // "checksum"

The possible reasons are format, month, date, future and checksum. PESEL encodes the century in the month field: 1900s births use months 01-12, 2000s births add 20 (so May 2005 is stored as month 25), and 1800s births add 80. The package supports birth years 1800-2099.

Generate realistic test data for fixtures and seeds

generatePesel accepts an exact date, a date range or a gender, which is what you need to test rules such as "the customer must be 18 or older":

import { generatePesel, generateNip, generateRegon, generateIban, generateIdCard } from "pl-identifiers";

const adult = generatePesel({ from: "1950-01-01", to: "2000-12-31" });
const minor = generatePesel({ from: "2015-01-01", to: "2020-12-31" });

const customers = Array.from({ length: 100 }, () => ({
  pesel: generatePesel(),
  nip: generateNip(),
  regon: generateRegon({ length: 14 }),
  iban: generateIban({ formatted: true }),
  idCard: generateIdCard()
}));

All randomness comes from crypto.getRandomValues, not Math.random. The generator uses rejection sampling, so every serial digit is equally likely (no modulo bias).

Pro-Tip: the NIP remainder-10 bug. Some NIP validators you find online compute the check digit as sum % 11 % 10. When the remainder is 10, that code turns it into 0 and accepts a NIP the tax office would never issue, because numbers with remainder 10 are skipped. isValidNip rejects them and generateNip never produces them.

There is a similar trap in the 14-digit REGON used for local branches. Its first nine digits are the parent company's REGON, which has its own check digit. pl-identifiers verifies both checksums, not just the last digit.

Limitations to know before you use it

  • The package is ESM-only. From CommonJS, load it with await import("pl-identifiers").
  • Validation checks structure and checksums. It does not confirm that a company with a given NIP exists or is an active VAT payer. For that, query the Polish Ministry of Finance VAT payer register (the "white list").
  • Generated numbers have valid checksums but are random, so one may match a real person by chance. Use them in test environments only. A real PESEL is personal data under the GDPR.

If you also build SQL queries from long ID lists, the companion package sql-in-chunker splits SQL IN lists into chunks of 1,000. The IBAN check is explained step by step in How IBAN and Luhn checksum algorithms prevent errors.

Frequently Asked Questions (FAQ)

Can I use pl-identifiers in a commercial project?

Yes. The MIT license lets you use, modify and ship the code in closed-source software. You only need to keep the copyright notice.

Does it work in the browser?

Yes. The code does not import any Node.js modules, and crypto.getRandomValues is available in every modern browser. You can validate a PESEL or NIP in the form itself without sending the value to a server.

Does a generated PESEL belong to a real person?

It can, but only by coincidence. The generator picks a random date and serial number and never reads the PESEL registry. Keep generated numbers out of production data.

References & Official Sources