A library for validating numbers of:
- identity card (Polish: dowód osobisty),
- NIP,
- passport (Polish: paszport),
- PESEL,
- REGON.
Simple and written in TypeScript. Bundled with tsup.
Inspired by radarsu's validate-polish library. I didn't like the API, so I decided to create one from scratch.
# NPM
$ npm install polish-identification-numbers
# Yarn
$ yarn add polish-identification-numbers
Returns boolean
. Supports lower case letters.
import { isValidIdentityCardNumber } from "polish-identification-numbers";
isValidIdentityCardNumber("AAA000000"); // -> true
isValidIdentityCardNumber("aaa000000"); // -> true
Returns boolean
. NIP with hyphens is not supported. Use the built-in replaceAll
method to remove them.
import { isValidNip } from "polish-identification-numbers";
isValidNip("9165459461");
isValidNip("123-456-32-18".replaceAll("-", ""));
Returns boolean
. Supports lower case letters.
import { isValidPassportNumber } from "polish-identification-numbers";
isValidPassportNumber("CC7999486"); // -> true
isValidPassportNumber("cc7999486"); // -> true
Returns Date
object or null
if PESEL is invalid.
import { getDateOfBirthFromPesel } from "polish-identification-numbers";
getDateOfBirthFromPesel("91042336426"); // -> new Date(1991, 3, 23)
Returns Gender
type ("female"
, "male"
or null
if PESEL is invalid).
import { getGenderFromPesel, Gender } from "polish-identification-numbers";
const gender: Gender = getGenderFromPesel("02321144427"); // -> "female"
Returns boolean
.
import { isValidPesel } from "polish-identification-numbers";
isValidPesel("02261773497");
Returns boolean
. Supports both 9 and 14 digit numbers.
import { isValidRegon } from "polish-identification-numbers";
isValidRegon("095895365");
isValidRegon("09796377087762");
- no dependencies
- small size
- tree-shakeable
MIT