nidx
Validate and extract information from national ID numbers across multiple countries.
The core library is written in Rust with zero dependencies and provides bindings for Python and JavaScript/WASM.
Supported countries
| Country | Module | Extracted fields |
|---|---|---|
| Albania | albania |
Date of birth, sex, national status |
| Kosovo | kosovo |
Validation only |
Installation
Rust
[]
= "0.2"
Optional serde support:
[]
= { = "0.2", = ["serde"] }
Python
JavaScript / TypeScript
Usage
Rust
use albania;
use kosovo;
use Sex;
Python
# Albania: decode extracts structured data
=
# 1990-01-01
# M
# True
assert
# Kosovo: validation only
# raises on invalid input
assert
validate and decode raise ValueError on invalid input.
JavaScript
import { Albania, Kosovo } from "nidx";
// Albania: decode extracts structured data
const info = Albania.decode("J00101999W");
console.log(info.birthday); // "1990-01-01"
console.log(info.sex); // "M"
console.log(info.isNational); // true
Albania.validate("J00101999W"); // throws on invalid input
console.log(Albania.isValid("J00101999W")); // true
// Kosovo: validation only
Kosovo.validate("1234567892"); // throws on invalid input
console.log(Kosovo.isValid("1234567892")); // true
validate and decode throw on invalid input.
API
Every country exposes validate(nid) and is_valid(nid). Countries with extractable data also expose decode(nid).
Albania
albania::validate(nid) checks a 10-character Albanian NID. Returns an error (or throws) on invalid input.
albania::decode(nid) validates and decodes a 10-character Albanian NID string. Input is case-insensitive.
NidInfo fields:
| Field | Rust | Python | JavaScript |
|---|---|---|---|
| Date of birth (ISO 8601) | birthday: Date |
birthday: str |
birthday: string |
| Year | birthday.year: u16 |
year: int |
year: number |
| Month | birthday.month: u8 |
month: int |
month: number |
| Day | birthday.day: u8 |
day: int |
day: number |
| Sex | sex: Sex |
sex: str |
sex: string |
| National | is_national: bool |
is_national: bool |
isNational: boolean |
Kosovo
kosovo::validate(nid) checks a 10-digit Kosovo personal number. Returns an error (or throws) on invalid input.
Contributing
See CONTRIBUTING.md.