singapore-nric
Advanced tools
Comparing version 1.0.0 to 1.1.0
{ | ||
"name": "singapore-nric", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Generate & Validate Singapore NRIC (National Registration Identity Card) Numbers", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -52,3 +52,3 @@ # singapore-nric | ||
@param `{string|string[]} nric` - single or array of NRIC strings<br> | ||
@param `{string|string[]|NRIC|NRIC[]} nric` - (single or array of) NRIC strings or NRIC instances<br> | ||
@returns `{boolean}` - true if all are valid NRICs | ||
@@ -65,3 +65,3 @@ | ||
@param `{string} firstchar` - (optional) set first character<br> | ||
@returns `{string}` - NRIC number | ||
@returns `{NRIC}` - NRIC number | ||
@@ -78,3 +78,3 @@ ``` | ||
@param `{number} amount` - number to generate<br> | ||
@returns `{string[]}` - an array of NRIC numbers | ||
@returns `{NRIC[]}` - an array of NRIC numbers | ||
@@ -84,1 +84,5 @@ ``` | ||
``` | ||
## Further Examples | ||
See [tests](https://github.com/samliew/singapore-nric/tree/master/tests). |
@@ -33,2 +33,6 @@ 'use strict'; | ||
get value() { | ||
return this.#nric; | ||
} | ||
get length() { | ||
@@ -38,6 +42,2 @@ return this.#nric.length; | ||
get value() { | ||
return this.#nric; | ||
} | ||
get firstchar() { | ||
@@ -103,7 +103,9 @@ return this.isCorrectFormat ? this.#nric.slice(0, 1) : null; | ||
* | ||
* @param {string|string[]} nric single or 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 | ||
*/ | ||
static Validate(value) { | ||
return Array.isArray(value) ? value.every(item => new NRIC(item).isValid) : new NRIC(value).isValid; | ||
return Array.isArray(value) ? | ||
value.every(item => item instanceof NRIC ? item.isValid : new NRIC(item).isValid) : | ||
(value instanceof NRIC ? value.isValid : new NRIC(value).isValid); | ||
} | ||
@@ -110,0 +112,0 @@ |
@@ -20,2 +20,3 @@ import NRIC from '../src/nric'; | ||
const nric = Generate('M'); | ||
expect(nric.firstchar).toEqual('M'); | ||
@@ -25,2 +26,3 @@ expect(nric.isValid).toEqual(true); | ||
const nric2 = Generate('F'); | ||
expect(nric2.firstchar).toEqual('F'); | ||
@@ -30,2 +32,3 @@ expect(nric2.isValid).toEqual(true); | ||
const nric3 = Generate('G'); | ||
expect(nric3.firstchar).toEqual('G'); | ||
@@ -32,0 +35,0 @@ expect(nric3.isValid).toEqual(true); |
@@ -10,7 +10,17 @@ import NRIC from '../src/nric'; | ||
it('should pass a single valid NRIC', () => { | ||
// string | ||
expect(Validate('S1234567D')).toEqual(true); | ||
// instance of class NRIC | ||
const nric = new NRIC('S1234567D'); | ||
expect(Validate(nric)).toEqual(true); | ||
}); | ||
it('should fail a single invalid NRIC', () => { | ||
// string | ||
expect(Validate('S1234567A')).toEqual(false); | ||
// instance of class NRIC | ||
const nric = new NRIC('S1234567A'); | ||
expect(Validate(nric)).toEqual(false); | ||
}); | ||
@@ -32,3 +42,3 @@ | ||
'S0000006Z', | ||
'S0000007H', | ||
new NRIC('S0000007H'), | ||
]; | ||
@@ -62,3 +72,3 @@ expect(Validate(validItems)).toEqual(true); | ||
'G1166318A', | ||
'M1134985A', | ||
new NRIC('M1134985A'), | ||
]; | ||
@@ -65,0 +75,0 @@ expect(Validate(invalidItems)).toEqual(false); |
17073
401
84