@indodev/toolkit 0.4.2 → 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,5 +1,5 @@
1
- export { NIKInfo, MaskOptions as NIKMaskOptions, formatBirthDate, formatNIK, getAge, isValidForBirthDate, isValidForGender, maskNIK, parseNIK, validateNIK } from './nik/index.cjs';
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-BDfy3aQw.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
+ 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';
5
5
  export { V as VINOptions, a as VINValidationResult, v as validateVIN } from './types-i5e6R0AS.cjs';
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export { NIKInfo, MaskOptions as NIKMaskOptions, formatBirthDate, formatNIK, getAge, isValidForBirthDate, isValidForGender, maskNIK, parseNIK, validateNIK } from './nik/index.js';
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-BDfy3aQw.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
+ 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';
5
5
  export { V as VINOptions, a as VINValidationResult, v as validateVIN } from './types-i5e6R0AS.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);
@@ -752,24 +784,12 @@ function normalizePhoneNumber(phone) {
752
784
  }
753
785
  return "";
754
786
  }
755
- function normalizeToNational(phone) {
756
- if (phone.startsWith("+62")) {
757
- return "0" + phone.substring(3);
758
- }
759
- if (phone.startsWith("62") && !phone.startsWith("620")) {
760
- return "0" + phone.substring(2);
761
- }
762
- if (phone.startsWith("0")) {
763
- return phone;
764
- }
765
- return "";
766
- }
767
787
  function getLandlineRegion(phone) {
768
788
  if (!phone || typeof phone !== "string") {
769
789
  return null;
770
790
  }
771
791
  const cleaned = phone.replace(/[^\d+]/g, "");
772
- const normalized = normalizeToNational(cleaned);
792
+ const normalized = normalizePhoneNumber(cleaned);
773
793
  if (!normalized || !normalized.startsWith("0")) {
774
794
  return null;
775
795
  }
@@ -940,7 +960,7 @@ function maskPhoneNumber(phone, options = {}) {
940
960
 
941
961
  // src/phone/links.ts
942
962
  function generateWALink(phone, message) {
943
- if (!validatePhoneNumber(phone)) {
963
+ if (!validatePhoneNumber(phone) || !isMobileNumber(phone)) {
944
964
  return "";
945
965
  }
946
966
  const e164 = toE164(phone);
@@ -951,7 +971,7 @@ function generateWALink(phone, message) {
951
971
  return link;
952
972
  }
953
973
  function generateSmsLink(phone, body) {
954
- if (!validatePhoneNumber(phone)) {
974
+ if (!validatePhoneNumber(phone) || !isMobileNumber(phone)) {
955
975
  return "";
956
976
  }
957
977
  const e164 = toE164(phone);