identification-validator
v3.0.2
Published
TypeScript utility library to validate and generate Singapore NRIC and FIN numbers
Readme
identification-validator
A simple TypeScript utility library to validate Singapore NRIC or FIN.
Features
- Validates NRIC and FIN numbers, or both (including M series)
- Strongly typed
- Tested with Vitest
Installation
npm install identification-validatorUsage
Validate an NRIC or FIN (or both)
import { Validator } from 'identification-validator'; // import the library
// validation of NRIC
console.log(Validator.isValidNRIC("S1234567D")) // will return true
// validation of FIN
console.log(Validator.isValidFIN("F1234567N")) // will return true
// validation of FIN / NRIC
console.log(Validator.isValidId("F1234567N")) // will return trueGenerate a random NRIC / FIN
import { Validator } from 'identification-validator'; // import the library
// generate a random NRIC
console.log(Validator.generateNRIC()); // give a random NRIC, with a random starting valid series
// generate a random FIN
console.log(Validator.generateFIN()) // give a random FIN, with a random starting valid series
Methods
| Name | Arguments | Example | Remarks |
|---------------|---------------|-----------|-------|
| isValidNRIC | string | Validator.isValidNRIC("S1234567D") | Checks whether the given string is a valid NRIC and return a boolean response|
| isValidFIN | string | Validator.isValidFIN("F1234567N") |Checks whether the given string is a valid NRIC and return a boolean response |
| isValidId | string | Validator.isValidId("F1234567N") |Checks whether the given string is a valid NRIC/ FIN and return a boolean response |
| generateNRIC | - | Validator.generateNRIC() |Generates a random NRIC and returns as a string |
| generateFIN | - | Validator.generateFIN() |Generates a random FIN and returns as a string |
