singapore-nric
Advanced tools
Comparing version 1.1.0 to 1.2.0
{ | ||
"name": "singapore-nric", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Generate & Validate Singapore NRIC (National Registration Identity Card) Numbers", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -67,4 +67,4 @@ # singapore-nric | ||
``` | ||
NRIC.Generate(); // e.g.: 'S1234567D' | ||
NRIC.Generate('M'); // e.g.: 'M1235467X' | ||
NRIC.Generate().value; // e.g.: 'S1234567D' | ||
NRIC.Generate('M').value; // e.g.: 'M1235467X' | ||
``` | ||
@@ -80,3 +80,4 @@ | ||
``` | ||
NRIC.GenerateMany(3); // e.g.: [ 'S1234567D', 'S1234567D', 'S1234567D' ] | ||
const nrics = NRIC.GenerateMany(3); // e.g.: [ NRIC, NRIC, NRIC ] | ||
nrics[0].value; // e.g.: 'S1234567D' | ||
``` | ||
@@ -83,0 +84,0 @@ |
@@ -9,28 +9,47 @@ import NRIC from '../src/nric'; | ||
it('can generate a single NRIC', () => { | ||
const nric = Generate(); | ||
expect(nric).toBeDefined(); | ||
expect(nric.length).toEqual(9); | ||
expect(nric.isCorrectFormat).toEqual(true); | ||
expect(nric.isValid).toEqual(true); | ||
// Returned type should be NRIC | ||
expect(nric instanceof NRIC).toEqual(true); | ||
// Call Generate and get value or property | ||
expect(Generate().value).toBeDefined(); | ||
expect(Generate().isValid).toEqual(true); | ||
}); | ||
it('can generate NRIC with set starting character', () => { | ||
it('can generate NRIC with a set starting character', () => { | ||
// Starts with M | ||
const nric = Generate('M'); | ||
expect(nric.firstchar).toEqual('M'); | ||
expect(nric.isValid).toEqual(true); | ||
// Starts with F | ||
const nric2 = Generate('F'); | ||
expect(nric2.firstchar).toEqual('F'); | ||
expect(nric2.isValid).toEqual(true); | ||
// Starts with G | ||
const nric3 = Generate('G'); | ||
expect(nric3.firstchar).toEqual('G'); | ||
expect(nric3.isValid).toEqual(true); | ||
// Starts with S | ||
const nric4 = Generate('S'); | ||
expect(nric4.firstchar).toEqual('S'); | ||
expect(nric4.isValid).toEqual(true); | ||
// Starts with T | ||
const nric5 = Generate('T'); | ||
expect(nric5.firstchar).toEqual('T'); | ||
expect(nric5.isValid).toEqual(true); | ||
}); | ||
it('can generate multiple NRICs', () => { | ||
@@ -40,7 +59,10 @@ const arr = GenerateMany(5); | ||
// invalid parameter should return an array of length 1 | ||
// Invalid parameter should return an array of length 1 | ||
const arr2 = GenerateMany(null); | ||
expect(arr2.length).toEqual(1); | ||
// Returned type should be NRIC | ||
expect(arr2[0] instanceof NRIC).toEqual(true); | ||
}); | ||
}); |
@@ -28,2 +28,3 @@ import NRIC from '../src/nric'; | ||
it('should not return values if invalid format', () => { | ||
@@ -36,2 +37,3 @@ const nric = new NRIC('123456'); | ||
it('validFormat should pass valid formats', () => { | ||
@@ -51,2 +53,3 @@ const items = [ | ||
it('validFormat should fail invalid formats', () => { | ||
@@ -87,2 +90,3 @@ | ||
it('should pass valid NRICs', () => { | ||
@@ -112,2 +116,3 @@ // Correct format and checksum | ||
it('should fail invalid NRICs', () => { | ||
@@ -114,0 +119,0 @@ // Correct format but invalid checksum |
@@ -9,2 +9,3 @@ import NRIC from '../src/nric'; | ||
it('should pass a single valid NRIC', () => { | ||
@@ -19,2 +20,3 @@ // string | ||
it('should fail a single invalid NRIC', () => { | ||
@@ -29,2 +31,3 @@ // string | ||
it('should pass an array of valid NRICs', () => { | ||
@@ -49,2 +52,3 @@ const validItems = [ | ||
it('should fail an array of invalid NRICs', () => { | ||
@@ -51,0 +55,0 @@ const invalidItems = [ |
17776
418
85