UNPKG

@tk007/sa-id-validator

Version:

A simple TypeScript library to validate South African ID numbers.

96 lines (68 loc) β€’ 2.72 kB
<p align="center"> <img src="./src/assets/logo.svg" width="300" alt="SA ID Validator"> </p> <p align="center"> <a href="https://www.npmjs.com/package/@tk007/sa-id-validator"> <img src="https://img.shields.io/npm/v/@tk007/sa-id-validator.svg?style=flat-square" alt="npm version" /> </a> <a href="https://github.com/tkmateka/sa-id-validator/actions"> <img src="https://github.com/tkmateka/sa-id-validator/workflows/CI/badge.svg" alt="build status" /> </a> </p> # πŸ‡ΏπŸ‡¦ SA ID Validator [![npm version](https://img.shields.io/npm/v/@tk007/sa-id-validator)](https://www.npmjs.com/package/@tk007/sa-id-validator) [![CI](https://img.shields.io/github/actions/workflow/status/tk007/sa-id-validator/ci.yml?branch=main)](https://github.com/tk007/sa-id-validator/actions) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE) > Validate South African ID Numbers easily using TypeScript. --- ## ✨ Features - Validate if a South African ID number is correct - Extract Gender - Extract Date of Birth - Calculate Age - Fully typed with TypeScript - Zero dependencies --- ## πŸ“¦ Install ```bash npm install @tk007/sa-id-validator ## OR with yarn yarn add @tk007/sa-id-validator πŸš€ Usage import { validateSouthAfricanID } from '@tk007/sa-id-validator'; const result = validateSouthAfricanID('8001015009087'); console.log(result); // Output: // { // isValid: true, // gender: "Male", // dateOfBirth: "1980-01-01", // age: 45 // } πŸ“‹ API validateSouthAfricanID(idNumber: string): ValidationResult | Field | Type | Description | | ------------- | -------- | ----------------------------------- | | `isValid` | `boolean`| Whether the ID number is valid | | `gender` | `string` | "Male" or "Female" | | `dateOfBirth` | `string` | Date of birth in `YYYY-MM-DD` format | | `age` | `number` | Current age based on today | πŸ› οΈ Development Clone the repo and install dependencies: git clone https://github.com/tk007/sa-id-validator.git cd sa-id-validator npm install ### Build: npm run build ### Run tests: npm run test πŸ“œ License MIT Β© tk007 πŸ™Œ Contributing Contributions, issues, and feature requests are welcome! Feel free to open an issue or submit a pull request. --- ### πŸš€ If you add this, your package page will look **so much more professional and polished**! Would you like me to also give you a matching **`package.json` metadata improvement** (description, homepage, repository fields, etc)? πŸ“¦ It'll make your npm page even better! πŸš€ Want it?