@indodev/toolkit 0.5.0 → 0.6.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 +46 -14
- 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 +46 -14
- package/dist/index.js.map +1 -1
- package/dist/nik/index.cjs +156 -12
- package/dist/nik/index.cjs.map +1 -1
- package/dist/nik/index.d.cts +24 -330
- package/dist/nik/index.d.ts +24 -330
- package/dist/nik/index.js +153 -13
- package/dist/nik/index.js.map +1 -1
- package/dist/utils-DT8-jt63.d.cts +495 -0
- package/dist/utils-DT8-jt63.d.ts +495 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -218,29 +218,61 @@ function maskNIK(nik, options = {}) {
|
|
|
218
218
|
}
|
|
219
219
|
|
|
220
220
|
// src/nik/utils.ts
|
|
221
|
-
function getAge(nik,
|
|
221
|
+
function getAge(nik, options = {}) {
|
|
222
|
+
const { referenceDate = /* @__PURE__ */ new Date(), asString = false } = options;
|
|
222
223
|
const info = parseNIK(nik);
|
|
223
224
|
if (!info || !info.birthDate) {
|
|
224
225
|
return null;
|
|
225
226
|
}
|
|
226
227
|
const birthDate = info.birthDate;
|
|
227
|
-
let
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
228
|
+
let years = referenceDate.getFullYear() - birthDate.getFullYear();
|
|
229
|
+
let months = referenceDate.getMonth() - birthDate.getMonth();
|
|
230
|
+
let days = referenceDate.getDate() - birthDate.getDate();
|
|
231
|
+
if (days < 0) {
|
|
232
|
+
months--;
|
|
233
|
+
const prevMonth = new Date(
|
|
234
|
+
referenceDate.getFullYear(),
|
|
235
|
+
referenceDate.getMonth(),
|
|
236
|
+
0
|
|
237
|
+
);
|
|
238
|
+
days += prevMonth.getDate();
|
|
239
|
+
}
|
|
240
|
+
if (months < 0) {
|
|
241
|
+
years--;
|
|
242
|
+
months += 12;
|
|
243
|
+
}
|
|
244
|
+
if (asString) {
|
|
245
|
+
const parts = [];
|
|
246
|
+
if (years > 0) parts.push(`${years} Tahun`);
|
|
247
|
+
if (months > 0) parts.push(`${months} Bulan`);
|
|
248
|
+
if (days > 0 || parts.length === 0) parts.push(`${days} Hari`);
|
|
249
|
+
return parts.join(" ");
|
|
250
|
+
}
|
|
251
|
+
return { years, months, days };
|
|
252
|
+
}
|
|
253
|
+
function formatBirthDate(nik) {
|
|
239
254
|
const info = parseNIK(nik);
|
|
240
255
|
if (!info || !info.birthDate) {
|
|
241
256
|
return null;
|
|
242
257
|
}
|
|
243
|
-
|
|
258
|
+
const day = info.birthDate.getDate();
|
|
259
|
+
const month = info.birthDate.getMonth();
|
|
260
|
+
const year = info.birthDate.getFullYear();
|
|
261
|
+
const monthNames = [
|
|
262
|
+
"Januari",
|
|
263
|
+
"Februari",
|
|
264
|
+
"Maret",
|
|
265
|
+
"April",
|
|
266
|
+
"Mei",
|
|
267
|
+
"Juni",
|
|
268
|
+
"Juli",
|
|
269
|
+
"Agustus",
|
|
270
|
+
"September",
|
|
271
|
+
"Oktober",
|
|
272
|
+
"November",
|
|
273
|
+
"Desember"
|
|
274
|
+
];
|
|
275
|
+
return `${day} ${monthNames[month]} ${year}`;
|
|
244
276
|
}
|
|
245
277
|
function isValidForGender(nik, gender) {
|
|
246
278
|
const info = parseNIK(nik);
|