@indodev/toolkit 0.4.1 → 0.5.0
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 +43 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +43 -48
- 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/dist/{parse-BDfy3aQw.d.cts → parse-BmmsNlJt.d.cts} +20 -4
- package/dist/{parse-BDfy3aQw.d.ts → parse-BmmsNlJt.d.ts} +20 -4
- package/dist/phone/index.cjs +8 -18
- package/dist/phone/index.cjs.map +1 -1
- package/dist/phone/index.d.cts +6 -4
- package/dist/phone/index.d.ts +6 -4
- package/dist/phone/index.js +8 -18
- package/dist/phone/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,
|
|
@@ -747,24 +754,12 @@ function normalizePhoneNumber(phone) {
|
|
|
747
754
|
}
|
|
748
755
|
return "";
|
|
749
756
|
}
|
|
750
|
-
function normalizeToNational(phone) {
|
|
751
|
-
if (phone.startsWith("+62")) {
|
|
752
|
-
return "0" + phone.substring(3);
|
|
753
|
-
}
|
|
754
|
-
if (phone.startsWith("62") && !phone.startsWith("620")) {
|
|
755
|
-
return "0" + phone.substring(2);
|
|
756
|
-
}
|
|
757
|
-
if (phone.startsWith("0")) {
|
|
758
|
-
return phone;
|
|
759
|
-
}
|
|
760
|
-
return "";
|
|
761
|
-
}
|
|
762
757
|
function getLandlineRegion(phone) {
|
|
763
758
|
if (!phone || typeof phone !== "string") {
|
|
764
759
|
return null;
|
|
765
760
|
}
|
|
766
761
|
const cleaned = phone.replace(/[^\d+]/g, "");
|
|
767
|
-
const normalized =
|
|
762
|
+
const normalized = normalizePhoneNumber(cleaned);
|
|
768
763
|
if (!normalized || !normalized.startsWith("0")) {
|
|
769
764
|
return null;
|
|
770
765
|
}
|
|
@@ -935,7 +930,7 @@ function maskPhoneNumber(phone, options = {}) {
|
|
|
935
930
|
|
|
936
931
|
// src/phone/links.ts
|
|
937
932
|
function generateWALink(phone, message) {
|
|
938
|
-
if (!validatePhoneNumber(phone)) {
|
|
933
|
+
if (!validatePhoneNumber(phone) || !isMobileNumber(phone)) {
|
|
939
934
|
return "";
|
|
940
935
|
}
|
|
941
936
|
const e164 = toE164(phone);
|
|
@@ -946,7 +941,7 @@ function generateWALink(phone, message) {
|
|
|
946
941
|
return link;
|
|
947
942
|
}
|
|
948
943
|
function generateSmsLink(phone, body) {
|
|
949
|
-
if (!validatePhoneNumber(phone)) {
|
|
944
|
+
if (!validatePhoneNumber(phone) || !isMobileNumber(phone)) {
|
|
950
945
|
return "";
|
|
951
946
|
}
|
|
952
947
|
const e164 = toE164(phone);
|