@indodev/toolkit 0.4.1 → 0.4.2
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/dist/index.cjs +40 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +40 -33
- package/dist/index.js.map +1 -1
- package/dist/nik/index.cjs +51 -33
- package/dist/nik/index.cjs.map +1 -1
- package/dist/nik/index.d.cts +23 -1
- package/dist/nik/index.d.ts +23 -1
- package/dist/nik/index.js +51 -34
- package/dist/nik/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -59,53 +59,66 @@ var REGENCIES = {
|
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
61
|
|
|
62
|
-
// src/nik/
|
|
63
|
-
function
|
|
64
|
-
if (
|
|
65
|
-
return
|
|
66
|
-
}
|
|
67
|
-
const provinceCode = nik.substring(0, 2);
|
|
68
|
-
if (!PROVINCES[provinceCode]) {
|
|
69
|
-
return false;
|
|
62
|
+
// src/nik/utils/date.ts
|
|
63
|
+
function parseNIKDate(nik) {
|
|
64
|
+
if (nik.length !== 16) {
|
|
65
|
+
return null;
|
|
70
66
|
}
|
|
71
67
|
const yearStr = nik.substring(6, 8);
|
|
72
68
|
const monthStr = nik.substring(8, 10);
|
|
73
|
-
const
|
|
69
|
+
const dayEncodedStr = nik.substring(10, 12);
|
|
74
70
|
const year = parseInt(yearStr, 10);
|
|
71
|
+
if (isNaN(year)) return null;
|
|
75
72
|
const fullYear = year > 30 ? 1900 + year : 2e3 + year;
|
|
76
73
|
const month = parseInt(monthStr, 10);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
74
|
+
if (isNaN(month)) return null;
|
|
75
|
+
const dayEncoded = parseInt(dayEncodedStr, 10);
|
|
76
|
+
if (isNaN(dayEncoded)) return null;
|
|
77
|
+
const gender = dayEncoded > 40 ? "female" : "male";
|
|
78
|
+
const day = dayEncoded > 40 ? dayEncoded - 40 : dayEncoded;
|
|
79
|
+
return { year, fullYear, month, day, gender, dayEncoded };
|
|
80
|
+
}
|
|
81
|
+
function validateNIKDateComponents(year, month, day) {
|
|
82
|
+
if (month < 1 || month > 12) return false;
|
|
83
|
+
if (day < 1 || day > 31) return false;
|
|
84
|
+
const testDate = new Date(year, month - 1, day);
|
|
85
|
+
return testDate.getFullYear() === year && testDate.getMonth() === month - 1 && testDate.getDate() === day;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// src/nik/validate.ts
|
|
89
|
+
var NIK_PATTERN = /^\d{16}$/;
|
|
90
|
+
function validateNIK(nik) {
|
|
91
|
+
if (!NIK_PATTERN.test(nik)) {
|
|
92
|
+
return false;
|
|
80
93
|
}
|
|
81
|
-
|
|
94
|
+
const provinceCode = nik.substring(0, 2);
|
|
95
|
+
if (!PROVINCES[provinceCode]) {
|
|
82
96
|
return false;
|
|
83
97
|
}
|
|
84
|
-
|
|
98
|
+
const parsed = parseNIKDate(nik);
|
|
99
|
+
if (!parsed) {
|
|
85
100
|
return false;
|
|
86
101
|
}
|
|
87
|
-
const
|
|
88
|
-
if (
|
|
102
|
+
const { fullYear, month, day } = parsed;
|
|
103
|
+
if (!validateNIKDateComponents(fullYear, month, day)) {
|
|
89
104
|
return false;
|
|
90
105
|
}
|
|
91
106
|
const now = /* @__PURE__ */ new Date();
|
|
92
|
-
if (
|
|
107
|
+
if (new Date(fullYear, month - 1, day) > now || fullYear < 1900) {
|
|
93
108
|
return false;
|
|
94
109
|
}
|
|
95
110
|
return true;
|
|
96
111
|
}
|
|
97
112
|
|
|
98
113
|
// src/nik/parse.ts
|
|
114
|
+
var NIK_PATTERN2 = /^\d{16}$/;
|
|
99
115
|
function parseNIK(nik) {
|
|
100
|
-
if (
|
|
116
|
+
if (!NIK_PATTERN2.test(nik)) {
|
|
101
117
|
return null;
|
|
102
118
|
}
|
|
103
119
|
const provinceCode = nik.substring(0, 2);
|
|
104
120
|
const regencyCode = nik.substring(2, 4);
|
|
105
121
|
const districtCode = nik.substring(4, 6);
|
|
106
|
-
const yearStr = nik.substring(6, 8);
|
|
107
|
-
const monthStr = nik.substring(8, 10);
|
|
108
|
-
const dayStr = nik.substring(10, 12);
|
|
109
122
|
const serialNumber = nik.substring(12, 16);
|
|
110
123
|
const province = PROVINCES[provinceCode];
|
|
111
124
|
if (!province) {
|
|
@@ -113,21 +126,15 @@ function parseNIK(nik) {
|
|
|
113
126
|
}
|
|
114
127
|
const regencies = REGENCIES[provinceCode] || {};
|
|
115
128
|
const regency = regencies[regencyCode] || "Unknown";
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
let gender = null;
|
|
120
|
-
if (day > 40) {
|
|
121
|
-
gender = "female";
|
|
122
|
-
day -= 40;
|
|
123
|
-
} else {
|
|
124
|
-
gender = "male";
|
|
129
|
+
const parsed = parseNIKDate(nik);
|
|
130
|
+
if (!parsed) {
|
|
131
|
+
return null;
|
|
125
132
|
}
|
|
126
|
-
const fullYear
|
|
127
|
-
|
|
128
|
-
if (birthDate.getFullYear() !== fullYear || birthDate.getMonth() !== month - 1 || birthDate.getDate() !== day) {
|
|
133
|
+
const { fullYear, month, day, gender } = parsed;
|
|
134
|
+
if (!validateNIKDateComponents(fullYear, month, day)) {
|
|
129
135
|
return null;
|
|
130
136
|
}
|
|
137
|
+
const birthDate = new Date(fullYear, month - 1, day);
|
|
131
138
|
return {
|
|
132
139
|
province: {
|
|
133
140
|
code: provinceCode,
|