GithubHelp home page GithubHelp logo

hadimazalan / mykad Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wmthor/mykad

1.0 2.0 0.0 20 KB

Library to validate, parse, generate, and format Malaysian Identity Card (MyKad) numbers.

JavaScript 100.00%

mykad's Introduction

MyKad

The MyKad library provides tools to validate, parse, generate, and format Malaysian Identity Card (MyKad) numbers.

Installation

Using npm:

npm install mykad

Importing

const mykad = require('mykad');

Features

Validation

MyKad numbers can be checked for validity. It ensures correct 12-digits, valid date of birth, and place of birth code.

if (mykad.isValid('560224108354')) {
    console.log('Valid MyKad number');
}

if (mykad.isValid('560224-10-8354')) {
    console.log('Also valid...');
}

// Not valid. Invalid date of birth and place of birth code.
mykad.isValid('561372-70-7953')

Formatting

MyKad numbers can be formatted to either have dash or without. Note that this simply formats without validation (date/place of birth code). You can use isValid() if you need to check for validity.

mykad.format('111013018934', (err, formatted) => {
    if (err) throw error;
    console.log(formatted); // 111013-01-8934
});

mykad.unformat('111013-01-8934', (err, unformatted) => {
    if (err) throw error;
    console.log(unformatted); // 111013018934
});

Generate

You can generate random MyKad numbers. All generate numbers are valid MyKad numbers.

const randomIcNum = mykad.generateRandom();
console.log(randomIcNum);

Parsing

MyKad numbers contain information about the holder's date of birth, place of birth, and gender. Date of birth assumes the age is under 100 years old. For example, the birth year '12' is 2012 instead of 1912.

mykad.parse('890724-01-2498', (err, data) => {
    if (err) throw err;
    console.log(data);
});

Parsed data is as the following:

{
    birthDate: 1989-07-23T16:00:00.000Z,
    birthPlace: { region: 'SOUTHEAST_ASIA', country: 'MY', state: 'JHR' },
    gender: 'female'
}

Birthplace

State information is available for those born in Malaysia. For others, it either contains the specific country information or only an approximation of the region. However, some countries are uncategorized.

States

['JHR', 'KDH', 'KTN', 'MLK', 'NSN', 'PHG', 'PNG', 'PRK', 'PLS', 'SBH', 'SWK', 'SGR', 'TRG', 'KUL', 'LBN', 'PJY', 'UNKNOWN_STATE']

Countries

Refer to ISO 3166-1 for country codes. Country codes can also contain these following status.

['FOREIGN_UNKNOWN', 'STATELESS', 'UNSPECIFIED']

Region

Some codes for place of birth only contain information of the approximate region or some only an approximate country. The list of regions are the following:

['SOUTHEAST_ASIA', 'BRITISH_ISLES', 'SOVIET_REPUBLIC', 'EAST_ASIA', 'SOUTH_ASIA', 'AFRICA', 'SOUTH_AMERICA', 'CENTRAL_AMERICA', 'OCEANIA', 'MIDDLE_EAST', 'EUROPE', 'MIDDLE_AMERICA', 'MISCELLANEOUS']

Known regions data contains the list of the countries as documented in the official registry. For example:

{
    region: 'NORTH_AMERICA',
    country: 'CA|GL|AN|PM|US',
    state: null
}

Gender

Gender information is provided in the form of the following values:

['male', 'female']

More info: twm

mykad's People

Contributors

wmthor avatar

Stargazers

Anas Abdrahman avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.