@indodev/toolkit 0.0.1

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 ADDED
@@ -0,0 +1,1173 @@
1
+ 'use strict';
2
+
3
+ // src/nik/constants.ts
4
+ var PROVINCES = {
5
+ "11": "Aceh",
6
+ "12": "Sumatera Utara",
7
+ "13": "Sumatera Barat",
8
+ "14": "Riau",
9
+ "15": "Jambi",
10
+ "16": "Sumatera Selatan",
11
+ "17": "Bengkulu",
12
+ "18": "Lampung",
13
+ "19": "Kepulauan Bangka Belitung",
14
+ "21": "Kepulauan Riau",
15
+ "31": "DKI Jakarta",
16
+ "32": "Jawa Barat",
17
+ "33": "Jawa Tengah",
18
+ "34": "DI Yogyakarta",
19
+ "35": "Jawa Timur",
20
+ "36": "Banten",
21
+ "51": "Bali",
22
+ "52": "Nusa Tenggara Barat",
23
+ "53": "Nusa Tenggara Timur",
24
+ "61": "Kalimantan Barat",
25
+ "62": "Kalimantan Tengah",
26
+ "63": "Kalimantan Selatan",
27
+ "64": "Kalimantan Timur",
28
+ "65": "Kalimantan Utara",
29
+ "71": "Sulawesi Utara",
30
+ "72": "Sulawesi Tengah",
31
+ "73": "Sulawesi Selatan",
32
+ "74": "Sulawesi Tenggara",
33
+ "75": "Gorontalo",
34
+ "76": "Sulawesi Barat",
35
+ "81": "Maluku",
36
+ "82": "Maluku Utara",
37
+ "91": "Papua",
38
+ "92": "Papua Barat",
39
+ "93": "Papua Selatan",
40
+ "94": "Papua Tengah",
41
+ "95": "Papua Pegunungan",
42
+ "96": "Papua Barat Daya"
43
+ };
44
+ var REGENCIES = {
45
+ "32": {
46
+ "01": "Kab. Bogor",
47
+ "02": "Kab. Sukabumi",
48
+ "03": "Kab. Cianjur",
49
+ "71": "Kota Bandung",
50
+ "72": "Kota Bekasi",
51
+ "73": "Kota Depok"
52
+ },
53
+ "31": {
54
+ "01": "Kota Jakarta Selatan",
55
+ "02": "Kota Jakarta Timur",
56
+ "03": "Kota Jakarta Pusat",
57
+ "04": "Kota Jakarta Barat",
58
+ "05": "Kota Jakarta Utara"
59
+ }
60
+ };
61
+
62
+ // src/nik/validate.ts
63
+ function validateNIK(nik) {
64
+ if (!/^\d{16}$/.test(nik)) {
65
+ return false;
66
+ }
67
+ const provinceCode = nik.substring(0, 2);
68
+ if (!PROVINCES[provinceCode]) {
69
+ return false;
70
+ }
71
+ const yearStr = nik.substring(6, 8);
72
+ const monthStr = nik.substring(8, 10);
73
+ const dayStr = nik.substring(10, 12);
74
+ const year = parseInt(yearStr, 10);
75
+ const fullYear = year > 30 ? 1900 + year : 2e3 + year;
76
+ const month = parseInt(monthStr, 10);
77
+ let day = parseInt(dayStr, 10);
78
+ if (day > 40) {
79
+ day = day - 40;
80
+ }
81
+ if (month < 1 || month > 12) {
82
+ return false;
83
+ }
84
+ if (day < 1 || day > 31) {
85
+ return false;
86
+ }
87
+ const testDate = new Date(fullYear, month - 1, day);
88
+ if (testDate.getFullYear() !== fullYear || testDate.getMonth() !== month - 1 || testDate.getDate() !== day) {
89
+ return false;
90
+ }
91
+ const now = /* @__PURE__ */ new Date();
92
+ if (testDate > now || testDate < new Date(1900, 0, 1)) {
93
+ return false;
94
+ }
95
+ return true;
96
+ }
97
+
98
+ // src/nik/parse.ts
99
+ function parseNIK(nik) {
100
+ if (!/^\d{16}$/.test(nik)) {
101
+ return null;
102
+ }
103
+ const provinceCode = nik.substring(0, 2);
104
+ const regencyCode = nik.substring(2, 4);
105
+ 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
+ const serialNumber = nik.substring(12, 16);
110
+ const province = PROVINCES[provinceCode];
111
+ if (!province) {
112
+ return null;
113
+ }
114
+ const regencies = REGENCIES[provinceCode] || {};
115
+ const regency = regencies[regencyCode] || "Unknown";
116
+ let day = parseInt(dayStr, 10);
117
+ const month = parseInt(monthStr, 10);
118
+ const year = parseInt(yearStr, 10);
119
+ let gender = null;
120
+ if (day > 40) {
121
+ gender = "female";
122
+ day -= 40;
123
+ } else {
124
+ gender = "male";
125
+ }
126
+ const fullYear = year > 30 ? 1900 + year : 2e3 + year;
127
+ const birthDate = new Date(fullYear, month - 1, day);
128
+ if (birthDate.getFullYear() !== fullYear || birthDate.getMonth() !== month - 1 || birthDate.getDate() !== day) {
129
+ return null;
130
+ }
131
+ return {
132
+ province: {
133
+ code: provinceCode,
134
+ name: province
135
+ },
136
+ regency: {
137
+ code: regencyCode,
138
+ name: regency
139
+ },
140
+ district: {
141
+ code: districtCode,
142
+ name: null
143
+ },
144
+ birthDate,
145
+ gender,
146
+ serialNumber,
147
+ isValid: true
148
+ };
149
+ }
150
+
151
+ // src/nik/format.ts
152
+ function formatNIK(nik, separator = "-") {
153
+ if (!/^\d{16}$/.test(nik)) {
154
+ return nik;
155
+ }
156
+ return [
157
+ nik.substring(0, 2),
158
+ // Province
159
+ nik.substring(2, 4),
160
+ // Regency
161
+ nik.substring(4, 6),
162
+ // District
163
+ nik.substring(6, 8),
164
+ // Year
165
+ nik.substring(8, 10),
166
+ // Month
167
+ nik.substring(10, 12),
168
+ // Day
169
+ nik.substring(12, 16)
170
+ // Serial
171
+ ].join(separator);
172
+ }
173
+ function maskNIK(nik, options = {}) {
174
+ if (!/^\d{16}$/.test(nik)) {
175
+ return nik;
176
+ }
177
+ const { start = 4, end = 4, char = "*", separator } = options;
178
+ if (start + end >= 16) {
179
+ return nik;
180
+ }
181
+ if (separator) {
182
+ const formatted = formatNIK(nik, separator);
183
+ const parts = formatted.split(separator);
184
+ let charCount = 0;
185
+ const maskedParts = parts.map((part) => {
186
+ const partStart = charCount;
187
+ const partEnd = charCount + part.length;
188
+ charCount += part.length;
189
+ if (partEnd <= start) {
190
+ return part;
191
+ } else if (partStart >= 16 - end) {
192
+ return part;
193
+ } else if (partStart >= start && partEnd <= 16 - end) {
194
+ return char.repeat(part.length);
195
+ } else {
196
+ return part.split("").map((ch, idx) => {
197
+ const pos = partStart + idx;
198
+ if (pos < start || pos >= 16 - end) {
199
+ return ch;
200
+ }
201
+ return char;
202
+ }).join("");
203
+ }
204
+ });
205
+ return maskedParts.join(separator);
206
+ }
207
+ const startPart = nik.substring(0, start);
208
+ const endPart = nik.substring(16 - end);
209
+ const maskLength = 16 - start - end;
210
+ return startPart + char.repeat(maskLength) + endPart;
211
+ }
212
+
213
+ // src/phone/constants.ts
214
+ var OPERATOR_PREFIXES = {
215
+ // Telkomsel (Halo, Simpati, by.U)
216
+ "0811": "Telkomsel",
217
+ "0812": "Telkomsel",
218
+ "0813": "Telkomsel",
219
+ "0821": "Telkomsel",
220
+ "0822": "Telkomsel",
221
+ "0823": "Telkomsel",
222
+ "0851": "Telkomsel",
223
+ "0852": "Telkomsel",
224
+ "0853": "Telkomsel",
225
+ // XL Axiata (XL Prepaid, XL Prioritas, LIVE.ON)
226
+ "0817": "XL",
227
+ "0818": "XL",
228
+ "0819": "XL",
229
+ "0859": "XL",
230
+ "0877": "XL",
231
+ "0878": "XL",
232
+ "0879": "XL",
233
+ // Indosat Ooredoo (IM3, Mentari)
234
+ // Note: Tri (3 Indonesia) merged with Indosat
235
+ "0814": "Indosat",
236
+ "0815": "Indosat",
237
+ "0816": "Indosat",
238
+ "0855": "Indosat",
239
+ "0856": "Indosat",
240
+ "0857": "Indosat",
241
+ "0858": "Indosat",
242
+ "0895": "Indosat",
243
+ "0896": "Indosat",
244
+ "0897": "Indosat",
245
+ "0898": "Indosat",
246
+ "0899": "Indosat",
247
+ // Smartfren (Smartfren Power Up)
248
+ "0881": "Smartfren",
249
+ "0882": "Smartfren",
250
+ "0883": "Smartfren",
251
+ "0884": "Smartfren",
252
+ "0885": "Smartfren",
253
+ "0886": "Smartfren",
254
+ "0887": "Smartfren",
255
+ "0888": "Smartfren",
256
+ "0889": "Smartfren",
257
+ // Axis (Acquired by XL but maintains separate branding)
258
+ "0831": "Axis",
259
+ "0832": "Axis",
260
+ "0833": "Axis",
261
+ "0838": "Axis"
262
+ };
263
+ var AREA_CODES = {
264
+ // ========================================
265
+ // JAKARTA, BANTEN & WEST JAVA
266
+ // ========================================
267
+ // Jakarta & Greater Jakarta
268
+ "021": "Jakarta",
269
+ // Banten
270
+ "0252": "Lebak",
271
+ "0253": "Pandeglang",
272
+ "0254": "Cilegon & Serang",
273
+ // West Java
274
+ "022": "Bandung",
275
+ "0231": "Cirebon",
276
+ "0232": "Kuningan",
277
+ "0233": "Majalengka",
278
+ "0234": "Indramayu",
279
+ "0251": "Bogor",
280
+ "0260": "Subang",
281
+ "0261": "Sumedang",
282
+ "0262": "Garut",
283
+ "0263": "Cianjur",
284
+ "0264": "Purwakarta",
285
+ "0265": "Tasikmalaya",
286
+ "0266": "Sukabumi",
287
+ "0267": "Karawang",
288
+ // ========================================
289
+ // CENTRAL JAVA & YOGYAKARTA
290
+ // ========================================
291
+ // Central Java
292
+ "024": "Semarang",
293
+ "0271": "Solo",
294
+ "0272": "Klaten",
295
+ "0273": "Wonogiri",
296
+ "0275": "Purworejo",
297
+ "0276": "Boyolali",
298
+ "0280": "Cilacap",
299
+ "0281": "Banyumas & Purbalingga",
300
+ "0282": "Cilacap",
301
+ "0283": "Tegal & Brebes",
302
+ "0284": "Pemalang",
303
+ "0285": "Pekalongan",
304
+ "0286": "Banjarnegara & Wonosobo",
305
+ "0287": "Kebumen",
306
+ "0289": "Bumiayu",
307
+ "0291": "Kudus & Jepara",
308
+ "0292": "Grobogan",
309
+ "0293": "Magelang",
310
+ "0294": "Kendal",
311
+ "0295": "Pati & Rembang",
312
+ "0296": "Blora",
313
+ "0297": "Karimun Jawa",
314
+ "0298": "Salatiga",
315
+ // Yogyakarta
316
+ "0274": "Yogyakarta",
317
+ // ========================================
318
+ // EAST JAVA, BALI & NUSA TENGGARA
319
+ // ========================================
320
+ // East Java
321
+ "031": "Surabaya",
322
+ "0321": "Mojokerto & Jombang",
323
+ "0322": "Lamongan",
324
+ "0323": "Sampang",
325
+ "0324": "Pamekasan",
326
+ "0325": "Bawean",
327
+ "0326": "Masalembu",
328
+ "0327": "Kangean",
329
+ "0328": "Sumenep",
330
+ "0331": "Jember",
331
+ "0332": "Bondowoso",
332
+ "0333": "Banyuwangi",
333
+ "0334": "Lumajang",
334
+ "0335": "Probolinggo",
335
+ "0336": "Jember",
336
+ "0338": "Situbondo",
337
+ "0341": "Malang",
338
+ "0342": "Blitar",
339
+ "0343": "Pasuruan",
340
+ "0351": "Madiun",
341
+ "0352": "Ponorogo",
342
+ "0353": "Bojonegoro",
343
+ "0354": "Kediri",
344
+ "0355": "Tulungagung",
345
+ "0356": "Tuban",
346
+ "0357": "Pacitan",
347
+ "0358": "Nganjuk",
348
+ // Bali
349
+ "0361": "Denpasar",
350
+ "0362": "Singaraja",
351
+ "0363": "Amlapura",
352
+ "0365": "Negara",
353
+ "0366": "Tabanan",
354
+ "0368": "Gianyar",
355
+ // Nusa Tenggara Barat (NTB)
356
+ "0370": "Mataram",
357
+ "0371": "Sumbawa",
358
+ "0372": "West Sumbawa",
359
+ "0373": "Dompu",
360
+ "0374": "Bima",
361
+ "0376": "East Lombok",
362
+ // Nusa Tenggara Timur (NTT)
363
+ "0379": "Alor",
364
+ "0380": "Kupang",
365
+ "0381": "Ende",
366
+ "0382": "Sikka",
367
+ "0383": "East Flores",
368
+ "0384": "Ngada",
369
+ "0385": "Manggarai",
370
+ "0386": "West Manggarai",
371
+ "0387": "Sumba",
372
+ "0388": "North & South Central Timor",
373
+ "0389": "Belu",
374
+ // ========================================
375
+ // SULAWESI
376
+ // ========================================
377
+ // South Sulawesi
378
+ "0410": "Pangkajene",
379
+ "0411": "Makassar",
380
+ "0413": "Bantaeng & Bulukumba",
381
+ "0414": "Selayar",
382
+ "0417": "Malino",
383
+ "0418": "Takalar",
384
+ "0419": "Jeneponto",
385
+ "0420": "Enrekang",
386
+ "0421": "Pare Pare",
387
+ "0423": "Tana Toraja",
388
+ "0427": "Barru",
389
+ "0471": "Luwu",
390
+ "0472": "Wajo (Pitumpanua)",
391
+ "0473": "North Luwu",
392
+ "0474": "East Luwu",
393
+ "0475": "Sorowako",
394
+ "0481": "Bone",
395
+ "0482": "Sinjai",
396
+ "0484": "Soppeng",
397
+ "0485": "Wajo",
398
+ // West Sulawesi
399
+ "0422": "Majene",
400
+ "0426": "Mamuju",
401
+ "0428": "Polewali",
402
+ "0429": "Central Mamuju",
403
+ // Central Sulawesi
404
+ "0409": "Morowali",
405
+ "0445": "Buol",
406
+ "0450": "Parigi Moutong",
407
+ "0451": "Palu",
408
+ "0452": "Poso",
409
+ "0453": "Toli-Toli",
410
+ "0454": "Tinombo",
411
+ "0455": "Moutong",
412
+ "0457": "Donggala",
413
+ "0458": "Tentena",
414
+ "0461": "Banggai",
415
+ "0462": "Banggai Island",
416
+ "0463": "Bunta",
417
+ "0464": "Tojo Una-Una",
418
+ "0465": "North Morowali",
419
+ // Southeast Sulawesi
420
+ "0401": "Kendari",
421
+ "0402": "Buton",
422
+ "0403": "Muna",
423
+ "0404": "Wakatobi",
424
+ "0405": "Kolaka",
425
+ "0408": "Konawe",
426
+ // North Sulawesi
427
+ "0430": "South Minahasa",
428
+ "0431": "Manado",
429
+ "0432": "Sangihe",
430
+ "0433": "Talaud",
431
+ "0434": "Bolaang Mongondow",
432
+ "0438": "Bitung",
433
+ // Gorontalo
434
+ "0435": "Gorontalo",
435
+ "0442": "North Gorontalo",
436
+ "0443": "Pohuwato",
437
+ // ========================================
438
+ // KALIMANTAN
439
+ // ========================================
440
+ // West Kalimantan
441
+ "0534": "Ketapang",
442
+ "0535": "Kayong Utara",
443
+ "0561": "Pontianak",
444
+ "0562": "Sambas & Singkawang",
445
+ "0563": "Landak",
446
+ "0564": "Sanggau",
447
+ "0565": "Sintang",
448
+ "0567": "Kapuas Hulu",
449
+ "0568": "Melawi",
450
+ // Central Kalimantan
451
+ "0513": "Kapuas",
452
+ "0519": "North Barito",
453
+ "0526": "South & East Barito",
454
+ "0528": "Murung Raya",
455
+ "0531": "East Kotawaringin",
456
+ "0532": "West Kotawaringin",
457
+ "0536": "Palangka Raya",
458
+ "0537": "Gunung Mas",
459
+ "0538": "Seruyan",
460
+ "0539": "Seruyan & East Kotawaringin",
461
+ // South Kalimantan
462
+ "0511": "Banjarmasin",
463
+ "0512": "Tanah Laut",
464
+ "0517": "Hulu Sungai Selatan",
465
+ "0518": "Tanah Bumbu",
466
+ "0527": "Hulu Sungai Utara",
467
+ // East Kalimantan
468
+ "0541": "Samarinda",
469
+ "0542": "Balikpapan",
470
+ "0543": "Paser",
471
+ "0545": "West Kutai",
472
+ "0548": "Bontang",
473
+ "0549": "East Kutai",
474
+ "0554": "Berau",
475
+ // North Kalimantan
476
+ "0551": "Tarakan",
477
+ "0552": "Bulungan",
478
+ "0553": "Malinau",
479
+ "0556": "Nunukan",
480
+ // ========================================
481
+ // SUMATRA
482
+ // ========================================
483
+ // Aceh
484
+ "0627": "Subulussalam & Dairi (North Sumatra)",
485
+ "0629": "Southeast Aceh",
486
+ "0641": "Langsa",
487
+ "0642": "Gayo Lues",
488
+ "0643": "Central Aceh",
489
+ "0644": "Bireuen",
490
+ "0645": "Lhokseumawe",
491
+ "0646": "East Aceh",
492
+ "0650": "Simeulue",
493
+ "0651": "Banda Aceh",
494
+ "0652": "Sabang",
495
+ "0653": "Pidie",
496
+ "0654": "Aceh Jaya",
497
+ "0655": "West Aceh",
498
+ "0656": "South Aceh",
499
+ "0657": "South Aceh",
500
+ "0658": "Singkil",
501
+ "0659": "Southwest Aceh",
502
+ // North Sumatra
503
+ "061": "Medan",
504
+ "0620": "Pangkalan Brandan",
505
+ "0621": "Tebing Tinggi",
506
+ "0622": "Pematang Siantar",
507
+ "0623": "Asahan",
508
+ "0624": "Labuhan Batu",
509
+ "0625": "Parapat",
510
+ "0626": "Samosir",
511
+ // '0627': 'Dairi', // for this prefix, it same with Subulussalam (Aceh)
512
+ "0628": "Karo",
513
+ "0630": "South Nias",
514
+ "0631": "Sibolga",
515
+ "0632": "Toba Samosir",
516
+ "0633": "North Tapanuli",
517
+ "0634": "Padang Sidempuan",
518
+ "0635": "South Tapanuli",
519
+ "0636": "Mandailing Natal",
520
+ "0638": "Barus",
521
+ "0639": "Nias",
522
+ // West Sumatra
523
+ "0751": "Padang",
524
+ "0752": "Bukittinggi",
525
+ "0753": "Pasaman",
526
+ "0754": "Sawahlunto",
527
+ "0755": "Solok",
528
+ "0756": "South Pesisir",
529
+ "0757": "South Pesisir",
530
+ "0759": "Mentawai",
531
+ // Riau
532
+ "0760": "Kuantan Singingi",
533
+ "0761": "Pekanbaru",
534
+ "0762": "Kampar",
535
+ "0763": "Bengkalis",
536
+ "0764": "Siak",
537
+ "0765": "Dumai",
538
+ "0766": "Bengkalis",
539
+ "0767": "Rokan Hulu",
540
+ "0768": "Indragiri Hilir",
541
+ "0769": "Indragiri Hulu",
542
+ // Riau Islands
543
+ "0770": "Muka Kuning Batamindo",
544
+ "0771": "Tanjungpinang",
545
+ "0772": "Anambas",
546
+ "0773": "Natuna",
547
+ "0776": "Lingga",
548
+ "0777": "Great Karimun",
549
+ "0778": "Batam",
550
+ "0779": "Kundur",
551
+ // Jambi
552
+ "0741": "Jambi",
553
+ "0742": "West Tanjung Jabung",
554
+ "0743": "Batanghari",
555
+ "0744": "Tebo",
556
+ "0745": "Sarolangun",
557
+ "0746": "Merangin",
558
+ "0747": "Bungo",
559
+ "0748": "Kerinci",
560
+ // South Sumatra
561
+ "0702": "Empat Lawang",
562
+ "0711": "Palembang",
563
+ "0712": "Ogan Komering Ilir",
564
+ "0713": "Prabumulih",
565
+ "0714": "Musi Banyuasin",
566
+ "0730": "Pagar Alam",
567
+ "0731": "Lahat",
568
+ "0733": "Lubuklinggau",
569
+ "0734": "Muara Enim",
570
+ "0735": "Ogan Komering Ulu",
571
+ // Bangka Belitung
572
+ "0715": "Belinyu",
573
+ "0716": "West Bangka",
574
+ "0717": "Pangkal Pinang",
575
+ "0718": "Central & South Bangka",
576
+ "0719": "Belitung",
577
+ // Bengkulu
578
+ "0732": "Rejang Lebong",
579
+ "0736": "Bengkulu",
580
+ "0737": "North Bengkulu",
581
+ "0739": "South Bengkulu",
582
+ // Lampung
583
+ "0721": "Bandar Lampung",
584
+ "0722": "Tanggamus",
585
+ "0723": "Way Kanan",
586
+ "0724": "North Lampung",
587
+ "0725": "Metro",
588
+ "0726": "Tulang Bawang",
589
+ "0727": "South Lampung",
590
+ "0728": "West Lampung",
591
+ "0729": "Pringsewu",
592
+ // ========================================
593
+ // MALUKU & PAPUA
594
+ // ========================================
595
+ // Maluku
596
+ "0910": "Ambon",
597
+ "0911": "Southeast Maluku",
598
+ "0913": "Tual",
599
+ "0914": "Saumlaki",
600
+ "0916": "Namlea",
601
+ "0918": "Ternate",
602
+ "0921": "Sanana",
603
+ "0924": "Tobelo",
604
+ // Papua & West Papua
605
+ "0901": "Timika",
606
+ "0902": "Agats",
607
+ "0951": "Sorong",
608
+ "0952": "South Sorong",
609
+ "0967": "Manokwari",
610
+ "0969": "Sorong",
611
+ "0971": "Merauke",
612
+ "0975": "Boven Digoel",
613
+ "0979": "Tembagapura",
614
+ "0981": "Jayapura",
615
+ "0986": "Wamena"
616
+ };
617
+
618
+ // src/phone/validate.ts
619
+ function validatePhoneNumber(phone) {
620
+ if (!phone || typeof phone !== "string") {
621
+ return false;
622
+ }
623
+ if (!/^[\d\s\-+().]+$/.test(phone)) {
624
+ return false;
625
+ }
626
+ const cleaned = phone.replace(/[\s\-().]/g, "");
627
+ let normalized;
628
+ if (cleaned.startsWith("+62")) {
629
+ normalized = "0" + cleaned.substring(3);
630
+ } else if (cleaned.startsWith("62") && !cleaned.startsWith("620")) {
631
+ normalized = "0" + cleaned.substring(2);
632
+ } else if (cleaned.startsWith("0")) {
633
+ normalized = cleaned;
634
+ } else {
635
+ return false;
636
+ }
637
+ if (normalized.startsWith("08")) {
638
+ return validateMobileNumber(normalized);
639
+ }
640
+ if (normalized.startsWith("0")) {
641
+ return validateLandlineNumber(normalized);
642
+ }
643
+ return false;
644
+ }
645
+ function validateMobileNumber(phone) {
646
+ if (phone.length < 10 || phone.length > 13) {
647
+ return false;
648
+ }
649
+ const prefix = phone.substring(0, 4);
650
+ if (!OPERATOR_PREFIXES[prefix]) {
651
+ return false;
652
+ }
653
+ if (!/^\d+$/.test(phone)) {
654
+ return false;
655
+ }
656
+ return true;
657
+ }
658
+ function validateLandlineNumber(phone) {
659
+ if (phone.length < 9 || phone.length > 11) {
660
+ return false;
661
+ }
662
+ const areaCode3 = phone.substring(0, 3);
663
+ const areaCode4 = phone.substring(0, 4);
664
+ if (AREA_CODES[areaCode3] || AREA_CODES[areaCode4]) {
665
+ return true;
666
+ }
667
+ if (/^0[2-9]\d{7,9}$/.test(phone)) {
668
+ return true;
669
+ }
670
+ return false;
671
+ }
672
+ function isMobileNumber(phone) {
673
+ if (!validatePhoneNumber(phone)) {
674
+ return false;
675
+ }
676
+ const cleaned = phone.replace(/[^\d+]/g, "");
677
+ let normalized;
678
+ if (cleaned.startsWith("+62")) {
679
+ normalized = "0" + cleaned.substring(3);
680
+ } else if (cleaned.startsWith("62")) {
681
+ normalized = "0" + cleaned.substring(2);
682
+ } else {
683
+ normalized = cleaned;
684
+ }
685
+ return normalized.startsWith("08");
686
+ }
687
+ function isLandlineNumber(phone) {
688
+ if (!validatePhoneNumber(phone)) {
689
+ return false;
690
+ }
691
+ return !isMobileNumber(phone);
692
+ }
693
+
694
+ // src/phone/format.ts
695
+ function formatPhoneNumber(phone, format = "national") {
696
+ if (!validatePhoneNumber(phone)) {
697
+ return phone;
698
+ }
699
+ const cleaned = cleanPhoneNumber(phone);
700
+ let normalized;
701
+ if (cleaned.startsWith("+62")) {
702
+ normalized = "0" + cleaned.substring(3);
703
+ } else if (cleaned.startsWith("62") && !cleaned.startsWith("620")) {
704
+ normalized = "0" + cleaned.substring(2);
705
+ } else {
706
+ normalized = cleaned;
707
+ }
708
+ switch (format) {
709
+ case "international":
710
+ return toInternational(normalized);
711
+ case "national":
712
+ case "display":
713
+ return toNational(normalized);
714
+ case "e164":
715
+ return toE164(normalized);
716
+ default:
717
+ return phone;
718
+ }
719
+ }
720
+ function toInternational(phone) {
721
+ const cleaned = cleanPhoneNumber(phone);
722
+ if (!cleaned) {
723
+ return phone;
724
+ }
725
+ const normalized = normalizeToNational(cleaned);
726
+ if (!normalized) {
727
+ return phone;
728
+ }
729
+ const withoutZero = normalized.substring(1);
730
+ if (normalized.startsWith("08")) {
731
+ if (withoutZero.length === 11) {
732
+ return `+62 ${withoutZero.substring(0, 3)}-${withoutZero.substring(3, 7)}-${withoutZero.substring(7)}`;
733
+ } else if (withoutZero.length === 10) {
734
+ return `+62 ${withoutZero.substring(0, 3)}-${withoutZero.substring(3, 6)}-${withoutZero.substring(6)}`;
735
+ } else if (withoutZero.length === 9) {
736
+ return `+62 ${withoutZero.substring(0, 3)}-${withoutZero.substring(3)}`;
737
+ } else if (withoutZero.length === 12) {
738
+ return `+62 ${withoutZero.substring(0, 3)}-${withoutZero.substring(3, 7)}-${withoutZero.substring(7)}`;
739
+ }
740
+ }
741
+ const areaCodeLength = getAreaCodeLength(normalized);
742
+ const areaCode = normalized.substring(1, areaCodeLength + 1);
743
+ const localNumber = normalized.substring(areaCodeLength + 1);
744
+ return `+62 ${areaCode}-${localNumber}`;
745
+ }
746
+ function toNational(phone) {
747
+ const cleaned = cleanPhoneNumber(phone);
748
+ if (!cleaned) {
749
+ return phone;
750
+ }
751
+ const normalized = normalizeToNational(cleaned);
752
+ if (!normalized) {
753
+ return phone;
754
+ }
755
+ if (normalized.startsWith("08")) {
756
+ if (normalized.length === 12) {
757
+ return `${normalized.substring(0, 4)}-${normalized.substring(4, 8)}-${normalized.substring(8)}`;
758
+ } else if (normalized.length === 11) {
759
+ return `${normalized.substring(0, 4)}-${normalized.substring(4, 7)}-${normalized.substring(7)}`;
760
+ } else if (normalized.length === 10) {
761
+ return `${normalized.substring(0, 4)}-${normalized.substring(4)}`;
762
+ } else if (normalized.length === 13) {
763
+ return `${normalized.substring(0, 4)}-${normalized.substring(4, 8)}-${normalized.substring(8)}`;
764
+ }
765
+ }
766
+ const areaCodeLength = getAreaCodeLength(normalized);
767
+ const areaCodeWithZero = normalized.substring(0, areaCodeLength + 1);
768
+ const localNumber = normalized.substring(areaCodeLength + 1);
769
+ return `${areaCodeWithZero}-${localNumber}`;
770
+ }
771
+ function toE164(phone) {
772
+ const cleaned = cleanPhoneNumber(phone);
773
+ if (!cleaned) {
774
+ return phone;
775
+ }
776
+ const normalized = normalizeToNational(cleaned);
777
+ if (!normalized) {
778
+ return phone;
779
+ }
780
+ return "62" + normalized.substring(1);
781
+ }
782
+ function cleanPhoneNumber(phone) {
783
+ if (!phone || typeof phone !== "string") {
784
+ return "";
785
+ }
786
+ return phone.replace(/[^\d+]/g, "");
787
+ }
788
+ function normalizeToNational(phone) {
789
+ if (phone.startsWith("+62")) {
790
+ return "0" + phone.substring(3);
791
+ } else if (phone.startsWith("62") && !phone.startsWith("620")) {
792
+ return "0" + phone.substring(2);
793
+ } else if (phone.startsWith("0")) {
794
+ return phone;
795
+ }
796
+ return "";
797
+ }
798
+ function getAreaCodeLength(normalized) {
799
+ const fourDigitCode = normalized.substring(0, 5);
800
+ if (AREA_CODES[fourDigitCode]) {
801
+ return 4;
802
+ }
803
+ const threeDigitCode = normalized.substring(0, 4);
804
+ if (AREA_CODES[threeDigitCode]) {
805
+ return 3;
806
+ }
807
+ const twoDigitCode = normalized.substring(0, 3);
808
+ if (AREA_CODES[twoDigitCode]) {
809
+ return 2;
810
+ }
811
+ return 2;
812
+ }
813
+ function maskPhoneNumber(phone, options = {}) {
814
+ const cleaned = cleanPhoneNumber(phone);
815
+ if (!cleaned) {
816
+ return phone;
817
+ }
818
+ const isInternational = cleaned.startsWith("+");
819
+ let toMask;
820
+ if (isInternational) {
821
+ toMask = cleaned;
822
+ } else {
823
+ const normalized = normalizeToNational(cleaned);
824
+ toMask = normalized || cleaned;
825
+ }
826
+ if (toMask.length < 4) {
827
+ return phone;
828
+ }
829
+ const { char = "*", separator } = options;
830
+ let { start = 4, end = 4 } = options;
831
+ if (start + end >= toMask.length) {
832
+ if (toMask.length < 10) {
833
+ const minMaskLength = 1;
834
+ const availableForVisible = toMask.length - minMaskLength;
835
+ if (availableForVisible >= 2) {
836
+ start = Math.floor(availableForVisible / 2);
837
+ end = availableForVisible - start;
838
+ } else {
839
+ return toMask;
840
+ }
841
+ } else {
842
+ return toMask;
843
+ }
844
+ }
845
+ const startPart = toMask.substring(0, start);
846
+ const endPart = toMask.substring(toMask.length - end);
847
+ const maskLength = toMask.length - start - end;
848
+ const masked = startPart + char.repeat(maskLength) + endPart;
849
+ if (separator) {
850
+ return `${masked.substring(0, start)}${separator}${masked.substring(start, masked.length - end)}${separator}${masked.substring(masked.length - end)}`;
851
+ }
852
+ return masked;
853
+ }
854
+
855
+ // src/phone/parse.ts
856
+ function parsePhoneNumber(phone) {
857
+ if (!validatePhoneNumber(phone)) {
858
+ return null;
859
+ }
860
+ const cleaned = cleanPhoneNumber(phone);
861
+ const normalized = normalizeToNational2(cleaned);
862
+ if (!normalized) {
863
+ return null;
864
+ }
865
+ const countryCode = "62";
866
+ const number = normalized.substring(1);
867
+ const isMobile = normalized.startsWith("08");
868
+ const isLandline = !isMobile;
869
+ let operator = null;
870
+ let region = null;
871
+ if (isMobile) {
872
+ operator = getOperator(normalized);
873
+ } else {
874
+ region = getRegion(normalized);
875
+ }
876
+ return {
877
+ countryCode,
878
+ operator,
879
+ number,
880
+ formatted: {
881
+ international: toInternational(normalized),
882
+ national: toNational(normalized),
883
+ e164: toE164(normalized)
884
+ },
885
+ isValid: true,
886
+ isMobile,
887
+ isLandline,
888
+ region
889
+ };
890
+ }
891
+ function getOperator(phone) {
892
+ if (!isMobileNumber(phone)) {
893
+ return null;
894
+ }
895
+ const cleaned = cleanPhoneNumber(phone);
896
+ const normalized = normalizeToNational2(cleaned);
897
+ if (!normalized || normalized.length < 4) {
898
+ return null;
899
+ }
900
+ const prefix = normalized.substring(0, 4);
901
+ return OPERATOR_PREFIXES[prefix] || null;
902
+ }
903
+ function getRegion(phone) {
904
+ if (!phone.startsWith("0")) {
905
+ return null;
906
+ }
907
+ const areaCode4 = phone.substring(0, 4);
908
+ if (AREA_CODES[areaCode4]) {
909
+ return AREA_CODES[areaCode4];
910
+ }
911
+ const areaCode3 = phone.substring(0, 3);
912
+ if (AREA_CODES[areaCode3]) {
913
+ return AREA_CODES[areaCode3];
914
+ }
915
+ return null;
916
+ }
917
+ function normalizeToNational2(phone) {
918
+ if (phone.startsWith("+62")) {
919
+ return "0" + phone.substring(3);
920
+ } else if (phone.startsWith("62")) {
921
+ return "0" + phone.substring(2);
922
+ } else if (phone.startsWith("0")) {
923
+ return phone;
924
+ }
925
+ return "";
926
+ }
927
+
928
+ // src/currency/format.ts
929
+ function formatRupiah(amount, options) {
930
+ const {
931
+ symbol = true,
932
+ decimal = false,
933
+ separator = ".",
934
+ decimalSeparator = ",",
935
+ spaceAfterSymbol = true
936
+ } = options || {};
937
+ const precision = options?.precision !== void 0 ? options.precision : decimal ? 2 : 0;
938
+ const isNegative = amount < 0;
939
+ const absAmount = Math.abs(amount);
940
+ let result;
941
+ if (decimal) {
942
+ const factor = Math.pow(10, precision);
943
+ const rounded = Math.round(absAmount * factor) / factor;
944
+ if (precision > 0) {
945
+ const [intPart, decPart] = rounded.toFixed(precision).split(".");
946
+ const formattedInt = intPart.replace(/\B(?=(\d{3})+(?!\d))/g, separator);
947
+ result = `${formattedInt}${decimalSeparator}${decPart}`;
948
+ } else {
949
+ const intPart = rounded.toString();
950
+ result = intPart.replace(/\B(?=(\d{3})+(?!\d))/g, separator);
951
+ }
952
+ } else {
953
+ const intAmount = Math.floor(absAmount);
954
+ result = intAmount.toString().replace(/\B(?=(\d{3})+(?!\d))/g, separator);
955
+ }
956
+ if (isNegative) {
957
+ result = `-${result}`;
958
+ }
959
+ if (symbol) {
960
+ const space = spaceAfterSymbol ? " " : "";
961
+ result = `Rp${space}${result}`;
962
+ }
963
+ return result;
964
+ }
965
+ function formatCompact(amount) {
966
+ const isNegative = amount < 0;
967
+ const abs = Math.abs(amount);
968
+ let result;
969
+ if (abs >= 1e12) {
970
+ result = formatCompactValue(abs / 1e12, "triliun");
971
+ } else if (abs >= 1e9) {
972
+ result = formatCompactValue(abs / 1e9, "miliar");
973
+ } else if (abs >= 1e6) {
974
+ result = formatCompactValue(abs / 1e6, "juta");
975
+ } else if (abs >= 1e5) {
976
+ result = formatCompactValue(abs / 1e3, "ribu");
977
+ } else if (abs >= 1e3) {
978
+ result = abs.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".");
979
+ } else {
980
+ result = abs.toString();
981
+ }
982
+ if (isNegative) {
983
+ result = `-${result}`;
984
+ }
985
+ return `Rp ${result}`;
986
+ }
987
+ function formatCompactValue(value, unit) {
988
+ const rounded = Math.round(value * 10) / 10;
989
+ if (rounded % 1 === 0) {
990
+ return `${rounded.toFixed(0)} ${unit}`;
991
+ }
992
+ return `${rounded.toString().replace(".", ",")} ${unit}`;
993
+ }
994
+
995
+ // src/currency/parse.ts
996
+ function parseRupiah(formatted) {
997
+ if (!formatted || typeof formatted !== "string") {
998
+ return null;
999
+ }
1000
+ const cleaned = formatted.trim().toLowerCase();
1001
+ const compactUnits = {
1002
+ triliun: 1e12,
1003
+ miliar: 1e9,
1004
+ juta: 1e6,
1005
+ ribu: 1e3
1006
+ };
1007
+ for (const [unit, multiplier] of Object.entries(compactUnits)) {
1008
+ if (cleaned.includes(unit)) {
1009
+ const match = cleaned.match(/(-?\d+[,.]?\d*)/);
1010
+ if (match) {
1011
+ const num = parseFloat(match[1].replace(",", "."));
1012
+ return num * multiplier;
1013
+ }
1014
+ }
1015
+ }
1016
+ let numStr = cleaned.replace(/rp/gi, "").trim();
1017
+ const hasDot = numStr.includes(".");
1018
+ const hasComma = numStr.includes(",");
1019
+ if (hasDot && hasComma) {
1020
+ const lastDot = numStr.lastIndexOf(".");
1021
+ const lastComma = numStr.lastIndexOf(",");
1022
+ if (lastComma > lastDot) {
1023
+ numStr = numStr.replace(/\./g, "").replace(",", ".");
1024
+ } else {
1025
+ numStr = numStr.replace(/,/g, "");
1026
+ }
1027
+ } else if (hasComma) {
1028
+ const parts = numStr.split(",");
1029
+ if (parts.length === 2 && parts[1].length <= 2) {
1030
+ numStr = numStr.replace(",", ".");
1031
+ } else {
1032
+ numStr = numStr.replace(/,/g, "");
1033
+ }
1034
+ } else if (hasDot) {
1035
+ const parts = numStr.split(".");
1036
+ if (parts.length > 2 || parts.length === 2 && parts[1].length > 2) {
1037
+ numStr = numStr.replace(/\./g, "");
1038
+ }
1039
+ }
1040
+ const parsed = parseFloat(numStr);
1041
+ return isNaN(parsed) ? null : parsed;
1042
+ }
1043
+
1044
+ // src/currency/words.ts
1045
+ var BASIC_NUMBERS = [
1046
+ "",
1047
+ "satu",
1048
+ "dua",
1049
+ "tiga",
1050
+ "empat",
1051
+ "lima",
1052
+ "enam",
1053
+ "tujuh",
1054
+ "delapan",
1055
+ "sembilan"
1056
+ ];
1057
+ var TEENS = [
1058
+ "sepuluh",
1059
+ "sebelas",
1060
+ "dua belas",
1061
+ "tiga belas",
1062
+ "empat belas",
1063
+ "lima belas",
1064
+ "enam belas",
1065
+ "tujuh belas",
1066
+ "delapan belas",
1067
+ "sembilan belas"
1068
+ ];
1069
+ var TENS = [
1070
+ "",
1071
+ "",
1072
+ "dua puluh",
1073
+ "tiga puluh",
1074
+ "empat puluh",
1075
+ "lima puluh",
1076
+ "enam puluh",
1077
+ "tujuh puluh",
1078
+ "delapan puluh",
1079
+ "sembilan puluh"
1080
+ ];
1081
+ function toWords(amount, options) {
1082
+ const { uppercase = false, withCurrency = true } = options || {};
1083
+ if (amount === 0) {
1084
+ let result = "nol";
1085
+ if (withCurrency) result += " rupiah";
1086
+ return uppercase ? capitalize(result) : result;
1087
+ }
1088
+ const isNegative = amount < 0;
1089
+ const absAmount = Math.floor(Math.abs(amount));
1090
+ let words = "";
1091
+ const triliun = Math.floor(absAmount / 1e12);
1092
+ const miliar = Math.floor(absAmount % 1e12 / 1e9);
1093
+ const juta = Math.floor(absAmount % 1e9 / 1e6);
1094
+ const ribu = Math.floor(absAmount % 1e6 / 1e3);
1095
+ const sisa = absAmount % 1e3;
1096
+ if (triliun > 0) {
1097
+ words += convertGroup(triliun) + " triliun";
1098
+ }
1099
+ if (miliar > 0) {
1100
+ if (words) words += " ";
1101
+ words += convertGroup(miliar) + " miliar";
1102
+ }
1103
+ if (juta > 0) {
1104
+ if (words) words += " ";
1105
+ words += convertGroup(juta) + " juta";
1106
+ }
1107
+ if (ribu > 0) {
1108
+ if (words) words += " ";
1109
+ words += ribu === 1 ? "seribu" : convertGroup(ribu) + " ribu";
1110
+ }
1111
+ if (sisa > 0) {
1112
+ if (words) words += " ";
1113
+ words += convertGroup(sisa);
1114
+ }
1115
+ if (isNegative) {
1116
+ words = "minus " + words;
1117
+ }
1118
+ if (withCurrency) {
1119
+ words += " rupiah";
1120
+ }
1121
+ return uppercase ? capitalize(words) : words;
1122
+ }
1123
+ function convertGroup(num) {
1124
+ if (num === 0) return "";
1125
+ let result = "";
1126
+ const hundreds = Math.floor(num / 100);
1127
+ if (hundreds > 0) {
1128
+ result = hundreds === 1 ? "seratus" : BASIC_NUMBERS[hundreds] + " ratus";
1129
+ }
1130
+ const remainder = num % 100;
1131
+ if (remainder > 0) {
1132
+ if (result) result += " ";
1133
+ result += convertTwoDigits(remainder);
1134
+ }
1135
+ return result;
1136
+ }
1137
+ function convertTwoDigits(num) {
1138
+ if (num === 0) return "";
1139
+ if (num < 10) return BASIC_NUMBERS[num];
1140
+ if (num >= 10 && num < 20) return TEENS[num - 10];
1141
+ const tens = Math.floor(num / 10);
1142
+ const ones = num % 10;
1143
+ let result = TENS[tens];
1144
+ if (ones > 0) {
1145
+ result += " " + BASIC_NUMBERS[ones];
1146
+ }
1147
+ return result;
1148
+ }
1149
+ function capitalize(str) {
1150
+ return str.charAt(0).toUpperCase() + str.slice(1);
1151
+ }
1152
+
1153
+ exports.cleanPhoneNumber = cleanPhoneNumber;
1154
+ exports.formatCompact = formatCompact;
1155
+ exports.formatNIK = formatNIK;
1156
+ exports.formatPhoneNumber = formatPhoneNumber;
1157
+ exports.formatRupiah = formatRupiah;
1158
+ exports.getOperator = getOperator;
1159
+ exports.isLandlineNumber = isLandlineNumber;
1160
+ exports.isMobileNumber = isMobileNumber;
1161
+ exports.maskNIK = maskNIK;
1162
+ exports.maskPhoneNumber = maskPhoneNumber;
1163
+ exports.parseNIK = parseNIK;
1164
+ exports.parsePhoneNumber = parsePhoneNumber;
1165
+ exports.parseRupiah = parseRupiah;
1166
+ exports.toE164 = toE164;
1167
+ exports.toInternational = toInternational;
1168
+ exports.toNational = toNational;
1169
+ exports.toWords = toWords;
1170
+ exports.validateNIK = validateNIK;
1171
+ exports.validatePhoneNumber = validatePhoneNumber;
1172
+ //# sourceMappingURL=index.cjs.map
1173
+ //# sourceMappingURL=index.cjs.map