Logo Lanfrica

CBYMachumbe/rsa-id-parser

Type de record:

software
Créateur:
CBY
Hôte:
npm package that parses South African ID numbers # rsa-id-parser Parse and validate South African ID numbers — date of birth, age, gender, citizenship, and checksum — with zero dependencies. Works with `import`, `require()`, and TypeScript out of the box. ## Install ```bash npm install rsa-id-parser ``` ## Usage ### ESM ```js import parseSouthAfricanId from "rsa-id-parser"; const result = parseSouthAfricanId("9202205720082"); ``` ### CommonJS ```js const parseSouthAfricanId = require("rsa-id-parser"); const result = parseSouthAfricanId("9202205720082"); ``` ### TypeScript Type declarations are bundled — no `@types` package needed. ```ts import parseSouthAfricanId, { ParsedSouthAfricanId } from "rsa-id-parser"; const result: ParsedSouthAfricanId = parseSouthAfricanId("9202205720082"); ``` ## How it works A South African ID number is 13 digits, structured as `YYMMDDSSSSCAZ`: | Segment | Digits | Meaning | | ---------- | ------ | ----------------------------------------------------------------- | | `YYMMDD` | 1–6 | Date of birth (year is inferred as 1900s or 2000s, see below) | | `SSSS` | 7–10 | Gender sequence: `0000`–`4999` is female, `5000`–`9999` is male | | `C` | 11 | Citizenship: `0` is SA citizen, `1` is permanent resident | | `A` | 12 | Historically an "8" — not used by this parser | | `Z` | 13 | Checksum digit, validated with the Luhn algorithm | `parseSouthAfricanId` reads each segment and returns a structured result rather than throwing — invalid input produces `isValid: false` plus a list of human-readable `errors`, so you can always inspect what went wrong. **Century inference:** since the ID number only encodes a two-digit year, the parser compares it to the current two-digit year. If the ID's `YY` is greater than today's `YY`, it's assumed to be a 1900s birth year; otherwise it's assumed to be 2000s. This is a heuristic — it can be wrong …

Licenses