zimbabwean-id-number-validator 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -8
- package/constants.js +75 -65
- package/index.js +17 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,10 +8,10 @@ The ID numbers issued in Zimbabwe consist of either 11 or 12 alphanumeric charac
|
|
|
8
8
|
|
|
9
9
|
| ID | Description |
|
|
10
10
|
| ------- | --------------------- |
|
|
11
|
-
| 08 | District Code
|
|
11
|
+
| 08 | Application Center District Code |
|
|
12
12
|
| 2047823 | 6 or 7 digit sequence |
|
|
13
13
|
| Q | Alphabetic letter |
|
|
14
|
-
| 29 | District Code
|
|
14
|
+
| 29 | Place of Origin District Code |
|
|
15
15
|
|
|
16
16
|
---
|
|
17
17
|
|
|
@@ -62,7 +62,10 @@ The validator provides detailed response objects
|
|
|
62
62
|
```javascript
|
|
63
63
|
{
|
|
64
64
|
isIdNumberValid: true,
|
|
65
|
-
description: "id number is valid"
|
|
65
|
+
description: "id number is valid",
|
|
66
|
+
isApplicationCentreCodeValid: true,
|
|
67
|
+
isPlaceOfOriginCodeValid: true,
|
|
68
|
+
isIdLetterValid: true
|
|
66
69
|
}
|
|
67
70
|
```
|
|
68
71
|
|
|
@@ -73,7 +76,10 @@ When using NO_HYPHENS
|
|
|
73
76
|
```javascript
|
|
74
77
|
{
|
|
75
78
|
isIdNumberValid: false,
|
|
76
|
-
description: "id number must be in the format: 082047823Q29"
|
|
79
|
+
description: "id number must be in the format: 082047823Q29",
|
|
80
|
+
isApplicationCentreCodeValid: false,
|
|
81
|
+
isPlaceOfOriginCodeValid: false,
|
|
82
|
+
isIdLetterValid: false
|
|
77
83
|
}
|
|
78
84
|
```
|
|
79
85
|
|
|
@@ -82,7 +88,10 @@ When using HYPHEN_AFTER_DISTRICT
|
|
|
82
88
|
```javascript
|
|
83
89
|
{
|
|
84
90
|
isIdNumberValid: false,
|
|
85
|
-
description: "id number must be in the format: 08-2047823Q29"
|
|
91
|
+
description: "id number must be in the format: 08-2047823Q29",
|
|
92
|
+
isApplicationCentreCodeValid: false,
|
|
93
|
+
isPlaceOfOriginCodeValid: false,
|
|
94
|
+
isIdLetterValid: false
|
|
86
95
|
}
|
|
87
96
|
```
|
|
88
97
|
|
|
@@ -91,7 +100,10 @@ When using FULL_HYPHENS
|
|
|
91
100
|
```javascript
|
|
92
101
|
{
|
|
93
102
|
isIdNumberValid: false,
|
|
94
|
-
description: "id number must be in the format: 08-2047823-Q-29"
|
|
103
|
+
description: "id number must be in the format: 08-2047823-Q-29",
|
|
104
|
+
isApplicationCentreCodeValid: false,
|
|
105
|
+
isPlaceOfOriginCodeValid: false,
|
|
106
|
+
isIdLetterValid: false
|
|
95
107
|
}
|
|
96
108
|
```
|
|
97
109
|
|
|
@@ -99,7 +111,11 @@ When using FULL_HYPHENS
|
|
|
99
111
|
```javascript
|
|
100
112
|
{
|
|
101
113
|
isIdNumberValid: false,
|
|
102
|
-
description: "id number is invalid"
|
|
114
|
+
description: "id number is invalid",
|
|
115
|
+
isApplicationCentreCodeValid: false,
|
|
116
|
+
isPlaceOfOriginCodeValid: false,
|
|
117
|
+
isIdLetterValid: false,
|
|
118
|
+
detailedDescription: "Application Centre Code: invalid, Place of Origin Code: valid, ID Letter: invalid"
|
|
103
119
|
}
|
|
104
120
|
```
|
|
105
121
|
|
|
@@ -110,6 +126,9 @@ When no specific format is specified, the validator provides general guidance:
|
|
|
110
126
|
```javascript
|
|
111
127
|
{
|
|
112
128
|
isIdNumberValid: false,
|
|
113
|
-
description: "id number must be in one of the formats: 082047823Q29, 08-2047823Q29, or 08-2047823-Q-29"
|
|
129
|
+
description: "id number must be in one of the formats: 082047823Q29, 08-2047823Q29, or 08-2047823-Q-29",
|
|
130
|
+
isApplicationCentreCodeValid: false,
|
|
131
|
+
isPlaceOfOriginCodeValid: false,
|
|
132
|
+
isIdLetterValid: false
|
|
114
133
|
}
|
|
115
134
|
```
|
package/constants.js
CHANGED
|
@@ -25,71 +25,81 @@ const validLetters = {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
const zimDistricts = {
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
|
|
28
|
+
"FOREIGNER": "00",
|
|
29
|
+
"BEITBRIDGE": "02",
|
|
30
|
+
"MBERENGWA": "03",
|
|
31
|
+
"BIKITA": "04",
|
|
32
|
+
"BINDURA": "05",
|
|
33
|
+
"BINGA": "06",
|
|
34
|
+
"BUHERA": "07",
|
|
35
|
+
"BULAWAYO": "08",
|
|
36
|
+
"BORROWDALE": "09",
|
|
37
|
+
"MONDORO-NGEZI": "10",
|
|
38
|
+
"MUZARABANI": "11",
|
|
39
|
+
"CHIBI": "12",
|
|
40
|
+
"CHIPINGE": "13",
|
|
41
|
+
"CHIREDZI": "14",
|
|
42
|
+
"MAZOWE": "15",
|
|
43
|
+
"FILABUSI": "17",
|
|
44
|
+
"CHIKOMBA": "18",
|
|
45
|
+
"UMZINGWANE": "19",
|
|
46
|
+
"INSIZA": "21",
|
|
47
|
+
"MASVINGO": "22",
|
|
48
|
+
"GOKWE SOUTH": "23",
|
|
49
|
+
"KADOMA": "24",
|
|
50
|
+
"GOROMONZI": "25",
|
|
51
|
+
"GOKWE NORTH": "26",
|
|
52
|
+
"GUTU": "27",
|
|
53
|
+
"GWANDA": "28",
|
|
54
|
+
"GWERU": "29",
|
|
55
|
+
"CHIREDZII": "31", //
|
|
56
|
+
"CHEGUTU": "32",
|
|
57
|
+
"NYANGA": "34",
|
|
58
|
+
"BUBI": "35",
|
|
59
|
+
"KARIBA": "37",
|
|
60
|
+
"HURUNGWE": "38",
|
|
61
|
+
"MATOBO": "39",
|
|
62
|
+
"LUPANE": "41",
|
|
63
|
+
"MAKONI": "42",
|
|
64
|
+
"MARONDERA": "43",
|
|
65
|
+
"CHIMANIMANI": "44",
|
|
66
|
+
"MT DARWIN": "45",
|
|
67
|
+
"MBIRE": "46",
|
|
68
|
+
"MUREHWA": "47",
|
|
69
|
+
"MUTOKO": "48",
|
|
70
|
+
"MUDZI": "49",
|
|
71
|
+
"MUTASA": "50",
|
|
72
|
+
"ZENGEZA": "52",
|
|
73
|
+
"NKAYI": "53",
|
|
74
|
+
"MWENEZI": "54",
|
|
75
|
+
"BULILIMAMANGWE": "56",
|
|
76
|
+
"TAFARA-MABVUKU": "57",
|
|
77
|
+
"KWEKWE": "58",
|
|
78
|
+
"SEKE": "59",
|
|
79
|
+
"EPOWORTH-RUWA": "60",
|
|
80
|
+
"RUSHINGA": "61",
|
|
81
|
+
"HARARE": "63",
|
|
82
|
+
"HIGHFIELD": "64",
|
|
83
|
+
"BEATRICE": "65", //
|
|
84
|
+
"SHURUGWI": "66",
|
|
85
|
+
"ZVISHAVANE": "67",
|
|
86
|
+
"SHAMVA": "68",
|
|
87
|
+
"SANYATI": "69",
|
|
88
|
+
"MAKONDE": "70",
|
|
89
|
+
"GURUVE": "71",
|
|
90
|
+
"TSHOLOTSHO": "73",
|
|
91
|
+
"MUTARE": "75",
|
|
92
|
+
"MOUNT DARWIN": "76",
|
|
93
|
+
"CHIRUMANZU": "77",
|
|
94
|
+
"WATERFALLS": "78",
|
|
95
|
+
"HWANGE": "79",
|
|
96
|
+
"WEDZA": "80",
|
|
97
|
+
"SEKE URBAN": "81",
|
|
98
|
+
"ZAKA": "83",
|
|
99
|
+
"UMGUZA": "84",
|
|
100
|
+
"UZUMBA MARAMBA PFUNGWE": "85",
|
|
101
|
+
"ZVIMBA": "86"
|
|
102
|
+
};
|
|
93
103
|
|
|
94
104
|
const validDistrictCodes = Object.values(zimDistricts)
|
|
95
105
|
|
package/index.js
CHANGED
|
@@ -15,7 +15,10 @@ const validateIdNumber = (idNumber, formatOption) => {
|
|
|
15
15
|
// initialize id validation results
|
|
16
16
|
const idValidationResults = {
|
|
17
17
|
isIdNumberValid: false,
|
|
18
|
-
description: validationErrors[formatOption] || defaultValidationError
|
|
18
|
+
description: validationErrors[formatOption] || defaultValidationError,
|
|
19
|
+
isApplicationCentreCodeValid: false,
|
|
20
|
+
isPlaceOfOriginCodeValid: false,
|
|
21
|
+
isIdLetterValid: false
|
|
19
22
|
}
|
|
20
23
|
|
|
21
24
|
// check if the id number is formatted correctly
|
|
@@ -35,18 +38,23 @@ const validateIdNumber = (idNumber, formatOption) => {
|
|
|
35
38
|
const idDigitsBeforeLetter = parseInt(idNumberArray[0])
|
|
36
39
|
const numericLetterValue = idDigitsBeforeLetter % 23 // represents a key in the validLetters object
|
|
37
40
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
const isApplicationCentreCodeValid = validDistrictCodes.includes(applicationCentreCode)
|
|
42
|
+
const isPlaceOfOriginCodeValid = validDistrictCodes.includes(placeOfOriginCode)
|
|
43
|
+
const isIdLetterValid = idLetter === validLetters[numericLetterValue]
|
|
44
|
+
|
|
45
|
+
idValidationResults.isApplicationCentreCodeValid = isApplicationCentreCodeValid
|
|
46
|
+
idValidationResults.isPlaceOfOriginCodeValid = isPlaceOfOriginCodeValid
|
|
47
|
+
idValidationResults.isIdLetterValid = isIdLetterValid
|
|
48
|
+
|
|
49
|
+
if (isApplicationCentreCodeValid && isIdLetterValid && isPlaceOfOriginCodeValid) {
|
|
43
50
|
// update idValidationResults and set the id number to valid
|
|
44
|
-
idValidationResults
|
|
45
|
-
idValidationResults
|
|
51
|
+
idValidationResults.isIdNumberValid = true
|
|
52
|
+
idValidationResults.description = "id number is valid"
|
|
46
53
|
}
|
|
47
54
|
else {
|
|
48
55
|
// update the invalid id number's description
|
|
49
|
-
idValidationResults
|
|
56
|
+
idValidationResults.description = "id number is invalid"
|
|
57
|
+
idValidationResults.detailedDescription = `Application Centre Code: ${isApplicationCentreCodeValid ? 'valid' : 'invalid'}, Place of Origin Code: ${isPlaceOfOriginCodeValid ? 'valid' : 'invalid'}, ID Letter: ${isIdLetterValid ? 'valid' : 'invalid'}`
|
|
50
58
|
}
|
|
51
59
|
}
|
|
52
60
|
|