npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mzantsi/id-verifier

v1.0.1

Published

South African Identity Document verifier and parser

Readme

🇿🇦 @mzantsi/id-verifier

A lightweight, dependency-free South African ID number validator and parser with a fluent API.

Built for correctness, clarity, and real-world usage.


✨ Features

  • ✅ Validates South African ID numbers
  • 🔍 Parses birth date, gender, and citizenship
  • 🧮 Calculates age correctly
  • 🧱 Fluent (builder-style) API
  • ⚡ Zero dependencies
  • 📦 ESM + CJS support
  • 🧾 Strict TypeScript types

📦 Installation

pnpm add @mzantsi/id-verifier
# or
npm install @mzantsi/id-verifier
# or
yarn add @mzantsi/id-verifier

🚀 Quick Start

import { id } from "@mzantsi/id-verifier";

const person = id("8001015009087");

if (person.isValid()) {
  console.log(person.parse());
  console.log("Age:", person.age());
}

🧠 What is a South African ID?

A South African ID number is a 13-digit string:

YYMMDD SSSS C A Z

| Part | Meaning | | -------- | ------------------------------------------------- | | YYMMDD | Date of birth | | SSSS | Gender (0000–4999 female, 5000–9999 male) | | C | Citizenship (0 = citizen, 1 = permanent resident) | | A | Usually 8 or 9 | | Z | Luhn checksum |

This library validates all of the above, including the checksum.


🧱 Fluent API (recommended)

Validate

id("8001015009087").isValid(); // true | false

Parse

const parsed = id("8001015009087").parse();

if (parsed) {
  console.log(parsed.birthDate);
  console.log(parsed.gender);
  console.log(parsed.citizenship);
}

Age calculation

const age = id("8001015009087").age(); // number | null

Age is calculated correctly based on the current date (birthday-aware).


Strict mode

Throw immediately if invalid:

id("123").assertValid().parse();

Useful in trusted or internal flows.


🔧 Functional API (alternative)

If you prefer plain functions:

import { verifyId, parseId } from "@mzantsi/id-verifier";

verifyId("8001015009087"); // boolean

parseId("8001015009087");
/*
{
  isValid: true,
  birthDate: Date,
  gender: "male",
  citizenship: "citizen"
}
*/

📄 Example script

See examples/example.ts:

import { id } from "../src";

const person = id("8001015009087");

console.log("Valid:", person.isValid());
console.log("Parsed:", person.parse());
console.log("Age:", person.age());

Run it with:

pnpm add -D tsx
pnpm tsx examples/example.ts

🛡️ Edge cases handled

  • ❌ Invalid dates (e.g. 991332)
  • 📆 Leap years (Feb 29 handled correctly)
  • 🧮 Proper Luhn checksum validation
  • 🕰️ Correct century resolution (1900 vs 2000)
  • 🪪 Citizenship digit validation

📐 Design philosophy

  • No external validation libraries
  • One source of truth for validation
  • Explicit over implicit
  • Safe defaults, strict when requested

This library is intentionally small and boring — because identity validation should be.


🧪 Testing

Tests are not bundled yet. The logic is deterministic and designed to be easily testable.

(Contributions welcome.)


📜 License

MIT © Gradiate OSS


🤝 Contributing

Issues and PRs are welcome. If you’re extending this, please keep the API small and predictable.