polish-identification-numbers
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

🇵🇱 Polish Identification Numbers

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.

Motivation

Inspired by radarsu's validate-polish library. I didn't like the API, so I decided to create one from scratch.

Installation

# NPM
$ npm install polish-identification-numbers

# Yarn
$ yarn add polish-identification-numbers

API

isValidIdentityCardNumber

Returns boolean. Supports lower case letters.

import { isValidIdentityCardNumber } from "polish-identification-numbers";

isValidIdentityCardNumber("AAA000000"); // -> true
isValidIdentityCardNumber("aaa000000"); // -> true

isValidNip

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("-", ""));

isValidPassportNumber

Returns boolean. Supports lower case letters.

import { isValidPassportNumber } from "polish-identification-numbers";

isValidPassportNumber("CC7999486"); // -> true
isValidPassportNumber("cc7999486"); // -> true

getDateOfBirthFromPesel

Returns Date object or null if PESEL is invalid.

import { getDateOfBirthFromPesel } from "polish-identification-numbers";

getDateOfBirthFromPesel("91042336426"); // -> new Date(1991, 3, 23)

getGenderFromPesel

Returns Gender type ("female", "male" or null if PESEL is invalid).

import { getGenderFromPesel, Gender } from "polish-identification-numbers";

const gender: Gender = getGenderFromPesel("02321144427"); // -> "female"

isValidPesel

Returns boolean.

import { isValidPesel } from "polish-identification-numbers";

isValidPesel("02261773497");

isValidRegon

Returns boolean. Supports both 9 and 14 digit numbers.

import { isValidRegon } from "polish-identification-numbers";

isValidRegon("095895365");
isValidRegon("09796377087762");

Features

  • no dependencies
  • small size
  • tree-shakeable

License

MIT

Package Sidebar

Install

npm i polish-identification-numbers

Weekly Downloads

20

Version

3.0.0

License

MIT

Unpacked Size

16.6 kB

Total Files

6

Last publish

Collaborators

  • sitemax