Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

singapore-nric

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

singapore-nric

Generate & Validate Singapore NRIC (National Registration Identity Card) Numbers

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

singapore-nric

GitHub

A Singapore NRIC Validator & Generator class, by Samuel Liew
This library supports the validation and generation of M-series NRIC numbers.

You can also use these pages on my website to generate or validate manually.


Installation

npm install singapore-nric

Class Usage

import NRIC from 'singapore-nric';

const n = new NRIC('S1234567D');

Properties

PropertyTypeDescription
valuestringentire value of NRIC
firstcharstringfirst character
identifierstringlast four alphanumeric characters
checksumstringchecksum (last character)
isCorrectFormatbooleanformat is valid
isValidbooleanchecksum is valid

Examples

n.value;           // 'S1234567D'
n.firstchar;       // 'S'
n.identifier;      // '567D'
n.checksum;        // 'D'
n.isCorrectFormat; // true
n.isValid;         // true

Static Methods

Validate( nric )

Validate a single NRIC, or an array of NRIC strings

@param {string|string[]|NRIC|NRIC[]} nric - (single or array of) NRIC strings or NRIC instances
@returns {boolean} - true if all are valid NRICs

NRIC.Validate('S1234567D');  // true
NRIC.Validate([ 'S1234567D', 'S1234567D' ]);  // true

Generate( firstchar? )

Returns a random NRIC with valid checksum

@param {string} firstchar - (optional) set first character
@returns {NRIC} - NRIC number

NRIC.Generate().value;     // e.g.: 'S1234567D'
NRIC.Generate('M').value;  // e.g.: 'M1235467X'

GenerateMany( amount )

Generate an array of NRICs with valid checksum

@param {number} amount - number to generate
@returns {NRIC[]} - an array of NRIC numbers

const nrics = NRIC.GenerateMany(3);  // e.g.: [ NRIC, NRIC, NRIC ]
nrics[0].value; // e.g.: 'S1234567D'

Further Examples

See tests.

Keywords

FAQs

Package last updated on 12 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc