@tk007/sa-id-validator
Version:
A simple TypeScript library to validate South African ID numbers.
96 lines (68 loc) β’ 2.72 kB
Markdown
<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
[](https://www.npmjs.com/package/@tk007/sa-id-validator)
[](https://github.com/tk007/sa-id-validator/actions)
[](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?