Skip to content

Latest commit

 

History

History
112 lines (71 loc) · 2.29 KB

README.md

File metadata and controls

112 lines (71 loc) · 2.29 KB

🇵🇱 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