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

my-nric

v2.0.6

Published

Malaysia NRIC validation and formatter

Downloads

33

Readme

Validation and Formatter for Malaysian NRIC

Installation

yarn add my-nric or npm i my-nric

Usage

import { nric } from 'my-nric';

const { data, error, isValid } = nric('950721-12-1234');
const { data, error, isValid } = nric('950721121234');

Config Option

option.includeDash (defaults to false)

Returns a formatted IC Number with dash separator

const result = nric('950721-12-1234', { includeDash: true, });

{
  error: null,
  data: {
    formatted: '950721-12-1234',
    dateOfBirth: 1995-07-20T16:00:00.000Z,
    gender: 'Female',
    placeOfBirth: 'Sabah',
    currentAge: 27
  },
  isValid: true
},

option.partialAge (defaults to false)

Returns a floating point number of the age

const result = nric('950721-12-1234',{
  includeDash: true,
  partialAge: true,
});

{
  error: null,
  data: {
    formatted: '950721-12-1234',
    dateOfBirth: 1995-07-20T16:00:00.000Z,
    gender: 'Female',
    placeOfBirth: 'Sabah',
    currentAge: 27.618831219308035
  },
  isValid: true
},

Error Example

Invalid Birth Date

const result = nric('959921-12-1234');

// Output:
{ error: 'Invalid Birth Date', data: {}, isValid: false },

Invalid State Code

const result = nric('950821-99-1234');

// Output:
{
  error: 'Invalid State Code',
  data: {},
  isValid: false
}

Data Object

Valid NRIC Numbers would have these following properties:

  • formatted (String): A formatted nric based on given option
  • dateOfBirth (Date): Date of birth;
  • placeOfBirth (String): Place of Birth;
  • currentAge (Number): Current age;
  • gender (String): Gender ('Male' | 'Female')

NRIC Object

Returns an object that contains these properties:

  • isValid (boolean) Wether the NRIC Number is valid
  • error (string | null)
  • data (Data | {})
  isValid: boolean;
  error: string | null;
  data: Data | {};

Test Suite

 PASS  src/test/index.test.ts (170 MB heap size)
  General Format
    ✓ Accept 14 Characters (4 ms)
    ✓ Accept 12 Characters (1 ms)
    ✓ Throws Error When 14 Characters of Alphabets (1 ms)
    ✓ Throws Error When 14 Characters of Symbols (1 ms)
    ✓ Throws Error When 12 Characters of Alphabets (2 ms)
    ✓ Throws Error When 12 Characters of Symbols
  Validate Date Of Birth Format
    ✓ On Dash Format, Returns Error When Month Is Invalid (10 ms)
    ✓ On Non-Dash Format, Returns Error When Month Is Invalid (9 ms)
    ✓ On Dash Format, Returns Error When Day Is Invalid (64 ms)
    ✓ On Non-Dash Format, Returns Error When Day Is Invalid (13 ms)
  Validate Place Of Birth Format
    ✓ On Dash Format, Throw Errors When Place Of Birth Code Is Invalid (1 ms)
    ✓ On Non-Dash Format, Throw Errors When Place Of Birth Code Is Invalid
    ✓ On Dash Format, Returns Correct Place Of Birth (17 ms)
    ✓ On Non-Dash Format, Returns Correct Place Of Birth (15 ms)
  Returns Correct Gender
    ✓ On Dash Format, Returns Correct Gender (4 ms)
    ✓ On Non-Dash Format, Returns Correct Gender (4 ms)

Test Suites: 1 passed, 1 total
Tests:       16 passed, 16 total
Snapshots:   0 total
Time:        0.943 s, estimated 1 s
Ran all test suites.
✨  Done in 1.57s.