@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.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- export { NIKInfo, MaskOptions as NIKMaskOptions, formatBirthDate, formatNIK, getAge, isValidForBirthDate, isValidForGender, maskNIK, parseNIK, validateNIK } from './nik/index.cjs';
1
+ export { N as NIKInfo, M as NIKMaskOptions, a as formatBirthDate, f as formatNIK, g as getAge, b as isValidForBirthDate, i as isValidForGender, m as maskNIK, p as parseNIK, v as validateNIK } from './utils-DT8-jt63.cjs';
2
2
  export { P as PhoneFormat, l as PhoneInfo, M as PhoneMaskOptions, d as cleanPhoneNumber, f as formatPhoneNumber, h as generateSmsLink, j as generateTelLink, e as generateWALink, g as getOperator, a as isLandlineNumber, i as isMobileNumber, k as isProvider, m as maskPhoneNumber, p as parsePhoneNumber, c as toE164, t as toInternational, b as toNational, v as validatePhoneNumber } from './parse-BmmsNlJt.cjs';
3
3
  export { NPWPInfo, MaskOptions as NPWPMaskOptions, formatNPWP, maskNPWP, parseNPWP, validateNPWP } from './npwp/index.cjs';
4
4
  export { f as formatPlate, g as getRegionFromPlate, v as validatePlate } from './utils-DDVlOusI.cjs';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { NIKInfo, MaskOptions as NIKMaskOptions, formatBirthDate, formatNIK, getAge, isValidForBirthDate, isValidForGender, maskNIK, parseNIK, validateNIK } from './nik/index.js';
1
+ export { N as NIKInfo, M as NIKMaskOptions, a as formatBirthDate, f as formatNIK, g as getAge, b as isValidForBirthDate, i as isValidForGender, m as maskNIK, p as parseNIK, v as validateNIK } from './utils-DT8-jt63.js';
2
2
  export { P as PhoneFormat, l as PhoneInfo, M as PhoneMaskOptions, d as cleanPhoneNumber, f as formatPhoneNumber, h as generateSmsLink, j as generateTelLink, e as generateWALink, g as getOperator, a as isLandlineNumber, i as isMobileNumber, k as isProvider, m as maskPhoneNumber, p as parsePhoneNumber, c as toE164, t as toInternational, b as toNational, v as validatePhoneNumber } from './parse-BmmsNlJt.js';
3
3
  export { NPWPInfo, MaskOptions as NPWPMaskOptions, formatNPWP, maskNPWP, parseNPWP, validateNPWP } from './npwp/index.js';
4
4
  export { f as formatPlate, g as getRegionFromPlate, v as validatePlate } from './utils-DDVlOusI.js';
package/dist/index.js CHANGED
@@ -216,29 +216,61 @@ function maskNIK(nik, options = {}) {
216
216
  }
217
217
 
218
218
  // src/nik/utils.ts
219
- function getAge(nik, referenceDate = /* @__PURE__ */ new Date()) {
219
+ function getAge(nik, options = {}) {
220
+ const { referenceDate = /* @__PURE__ */ new Date(), asString = false } = options;
220
221
  const info = parseNIK(nik);
221
222
  if (!info || !info.birthDate) {
222
223
  return null;
223
224
  }
224
225
  const birthDate = info.birthDate;
225
- let age = referenceDate.getFullYear() - birthDate.getFullYear();
226
- const m = referenceDate.getMonth() - birthDate.getMonth();
227
- if (m < 0 || m === 0 && referenceDate.getDate() < birthDate.getDate()) {
228
- age--;
229
- }
230
- return age;
231
- }
232
- function formatBirthDate(nik, options = {
233
- day: "numeric",
234
- month: "long",
235
- year: "numeric"
236
- }, locale = "id-ID") {
226
+ let years = referenceDate.getFullYear() - birthDate.getFullYear();
227
+ let months = referenceDate.getMonth() - birthDate.getMonth();
228
+ let days = referenceDate.getDate() - birthDate.getDate();
229
+ if (days < 0) {
230
+ months--;
231
+ const prevMonth = new Date(
232
+ referenceDate.getFullYear(),
233
+ referenceDate.getMonth(),
234
+ 0
235
+ );
236
+ days += prevMonth.getDate();
237
+ }
238
+ if (months < 0) {
239
+ years--;
240
+ months += 12;
241
+ }
242
+ if (asString) {
243
+ const parts = [];
244
+ if (years > 0) parts.push(`${years} Tahun`);
245
+ if (months > 0) parts.push(`${months} Bulan`);
246
+ if (days > 0 || parts.length === 0) parts.push(`${days} Hari`);
247
+ return parts.join(" ");
248
+ }
249
+ return { years, months, days };
250
+ }
251
+ function formatBirthDate(nik) {
237
252
  const info = parseNIK(nik);
238
253
  if (!info || !info.birthDate) {
239
254
  return null;
240
255
  }
241
- return new Intl.DateTimeFormat(locale, options).format(info.birthDate);
256
+ const day = info.birthDate.getDate();
257
+ const month = info.birthDate.getMonth();
258
+ const year = info.birthDate.getFullYear();
259
+ const monthNames = [
260
+ "Januari",
261
+ "Februari",
262
+ "Maret",
263
+ "April",
264
+ "Mei",
265
+ "Juni",
266
+ "Juli",
267
+ "Agustus",
268
+ "September",
269
+ "Oktober",
270
+ "November",
271
+ "Desember"
272
+ ];
273
+ return `${day} ${monthNames[month]} ${year}`;
242
274
  }
243
275
  function isValidForGender(nik, gender) {
244
276
  const info = parseNIK(nik);