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 🙏

© 2024 – Pkg Stats / Ryan Hefner

south-african-id-parser

v2.0.0

Published

A library for parsing and validating South African ID Numbers.

Downloads

34,519

Readme

South African ID Number Parser

status-badge npm

The ID Numbers issued in South Africa follow a regular format that you can use to derive some information about them. The following information is available:

  • Date of Birth
  • Sex
  • Citizenship

This library can also check if the ID number supplied is a valid South African ID number.

More information on the ID number format can be found here and here.

API Docs

API docs are available here;

Usage

Download the library from NPM using the following command in a terminal:

npm install --save south-african-id-parser

Usage In NodeJS

var saIdParser = require('south-african-id-parser');
var info = saIdParser.parse('9001049818080');

Usage In the Browser

When used in the browser, the library will add the saIdParser object to the window for you to use.

<script src="south-african-id-parser.js"></script>
<script>
    var info = saIdParser.parse('9001049818080');
</script>

Parse Everything

The package exposes the .parse(idNumber) method for calling all of the validation and parsing in one.

If validation fails, the resulting object only has the isValid property.

var saIdParser = require('south-african-id-parser');
var validIdNumber = '9001049818080';

var info = saIdParser.parse(validIdNumber);
// info === {
//   isValid: true,
//   dateOfBirth: new Date(1990, 0, 4),
//   isMale: true,
//   isFemale: false,
//   isSouthAfricanCitizen: true
// }

var invalidIdNumber = '1234567';
info = saIdParser.parse(invalidIdNumber);
// info === {
//   isValid: false
// }

Only Validate

.validate(idNumber) only checks if the ID number is valid.

var saIdParser = require('south-african-id-parser');
var validIdNumber = '9001049818080';
var isValid = saIdParser.validate(validIdNumber);

// valid === true

Only Parse Date of Birth

The method does not do a full validation on the ID number, but it will return undefined if either the number supplied is not a 13 digit number string or the date section of the ID number is invalid.

var saIdParser = require('south-african-id-parser');
var validIdNumber = '9001049818080';
var dateOfBirth = saIdParser.parseDateOfBirth(validIdNumber);

// dateOfBirth === new Date(1990, 0, 4)

The date of birth included in the ID number has a two digit year. For example, 90 instead of 1990.

This is handled by comparing the date of birth to the current date, and choosing the century that gives the person the lowest age, while still putting their age in the past.

For example, assuming that the current date is 10 December 2015. If the date of birth parsed is 10 December 15, it will be interpreted as 10 December 2015. If, on the other hand, the date of birth is parsed as 11 December 15, that will be interpreted as 10 December 1915.

Only Parse Sex

The method does not do a full validation on the ID number, but it will return undefined if the number supplied is not a 13 digit number string.

var saIdParser = require('south-african-id-parser');
var validIdNumber = '9001049818080';
var isFemale = saIdParser.parseIsFemale(validIdNumber);
var isMale = saIdParser.parseIsMale(validIdNumber);

// isFemale === false
// isMale === true

Only Parse Citizenship

The method does not do a full validation on the ID number, but it will return undefined if the number supplied is not a 13 digit number string.

var saIdParser = require('south-african-id-parser');
var validIdNumber = '9001049818080';
var isSouthAfricanCitizen = saIdParser.parseIsSouthAfricanCitizen(validIdNumber);

// isSouthAfricanCitizen === true

Releases

See CHANGELOG.md for release notes.

Releases are also available on NPM and Codeberg.

Reporting issues

Please report any issues on the project's issue tracker.

Roadmap

This library is considered to be feature complete, so there are no new planned features.

This project is still actively maintained. Reported issues will be addressed, and dependencies will be kept up to date.

Contributing

See CONTRIBUTING.md for instructions on setting up a development environment to make changes and submit contributions.

Support

If you get value from this project, consider supporting me on Patreon. Support via Patreon will allow me to spend more time writing and publishing open source software.

License

Copyright 2017-2023, Justin Wernick.

Licensed under either of

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.