@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.
@@ -0,0 +1,718 @@
1
+ // src/phone/constants.ts
2
+ var OPERATOR_PREFIXES = {
3
+ // Telkomsel (Halo, Simpati, by.U)
4
+ "0811": "Telkomsel",
5
+ "0812": "Telkomsel",
6
+ "0813": "Telkomsel",
7
+ "0821": "Telkomsel",
8
+ "0822": "Telkomsel",
9
+ "0823": "Telkomsel",
10
+ "0851": "Telkomsel",
11
+ "0852": "Telkomsel",
12
+ "0853": "Telkomsel",
13
+ // XL Axiata (XL Prepaid, XL Prioritas, LIVE.ON)
14
+ "0817": "XL",
15
+ "0818": "XL",
16
+ "0819": "XL",
17
+ "0859": "XL",
18
+ "0877": "XL",
19
+ "0878": "XL",
20
+ "0879": "XL",
21
+ // Indosat Ooredoo (IM3, Mentari)
22
+ // Note: Tri (3 Indonesia) merged with Indosat
23
+ "0814": "Indosat",
24
+ "0815": "Indosat",
25
+ "0816": "Indosat",
26
+ "0855": "Indosat",
27
+ "0856": "Indosat",
28
+ "0857": "Indosat",
29
+ "0858": "Indosat",
30
+ "0895": "Indosat",
31
+ "0896": "Indosat",
32
+ "0897": "Indosat",
33
+ "0898": "Indosat",
34
+ "0899": "Indosat",
35
+ // Smartfren (Smartfren Power Up)
36
+ "0881": "Smartfren",
37
+ "0882": "Smartfren",
38
+ "0883": "Smartfren",
39
+ "0884": "Smartfren",
40
+ "0885": "Smartfren",
41
+ "0886": "Smartfren",
42
+ "0887": "Smartfren",
43
+ "0888": "Smartfren",
44
+ "0889": "Smartfren",
45
+ // Axis (Acquired by XL but maintains separate branding)
46
+ "0831": "Axis",
47
+ "0832": "Axis",
48
+ "0833": "Axis",
49
+ "0838": "Axis"
50
+ };
51
+ var AREA_CODES = {
52
+ // ========================================
53
+ // JAKARTA, BANTEN & WEST JAVA
54
+ // ========================================
55
+ // Jakarta & Greater Jakarta
56
+ "021": "Jakarta",
57
+ // Banten
58
+ "0252": "Lebak",
59
+ "0253": "Pandeglang",
60
+ "0254": "Cilegon & Serang",
61
+ // West Java
62
+ "022": "Bandung",
63
+ "0231": "Cirebon",
64
+ "0232": "Kuningan",
65
+ "0233": "Majalengka",
66
+ "0234": "Indramayu",
67
+ "0251": "Bogor",
68
+ "0260": "Subang",
69
+ "0261": "Sumedang",
70
+ "0262": "Garut",
71
+ "0263": "Cianjur",
72
+ "0264": "Purwakarta",
73
+ "0265": "Tasikmalaya",
74
+ "0266": "Sukabumi",
75
+ "0267": "Karawang",
76
+ // ========================================
77
+ // CENTRAL JAVA & YOGYAKARTA
78
+ // ========================================
79
+ // Central Java
80
+ "024": "Semarang",
81
+ "0271": "Solo",
82
+ "0272": "Klaten",
83
+ "0273": "Wonogiri",
84
+ "0275": "Purworejo",
85
+ "0276": "Boyolali",
86
+ "0280": "Cilacap",
87
+ "0281": "Banyumas & Purbalingga",
88
+ "0282": "Cilacap",
89
+ "0283": "Tegal & Brebes",
90
+ "0284": "Pemalang",
91
+ "0285": "Pekalongan",
92
+ "0286": "Banjarnegara & Wonosobo",
93
+ "0287": "Kebumen",
94
+ "0289": "Bumiayu",
95
+ "0291": "Kudus & Jepara",
96
+ "0292": "Grobogan",
97
+ "0293": "Magelang",
98
+ "0294": "Kendal",
99
+ "0295": "Pati & Rembang",
100
+ "0296": "Blora",
101
+ "0297": "Karimun Jawa",
102
+ "0298": "Salatiga",
103
+ // Yogyakarta
104
+ "0274": "Yogyakarta",
105
+ // ========================================
106
+ // EAST JAVA, BALI & NUSA TENGGARA
107
+ // ========================================
108
+ // East Java
109
+ "031": "Surabaya",
110
+ "0321": "Mojokerto & Jombang",
111
+ "0322": "Lamongan",
112
+ "0323": "Sampang",
113
+ "0324": "Pamekasan",
114
+ "0325": "Bawean",
115
+ "0326": "Masalembu",
116
+ "0327": "Kangean",
117
+ "0328": "Sumenep",
118
+ "0331": "Jember",
119
+ "0332": "Bondowoso",
120
+ "0333": "Banyuwangi",
121
+ "0334": "Lumajang",
122
+ "0335": "Probolinggo",
123
+ "0336": "Jember",
124
+ "0338": "Situbondo",
125
+ "0341": "Malang",
126
+ "0342": "Blitar",
127
+ "0343": "Pasuruan",
128
+ "0351": "Madiun",
129
+ "0352": "Ponorogo",
130
+ "0353": "Bojonegoro",
131
+ "0354": "Kediri",
132
+ "0355": "Tulungagung",
133
+ "0356": "Tuban",
134
+ "0357": "Pacitan",
135
+ "0358": "Nganjuk",
136
+ // Bali
137
+ "0361": "Denpasar",
138
+ "0362": "Singaraja",
139
+ "0363": "Amlapura",
140
+ "0365": "Negara",
141
+ "0366": "Tabanan",
142
+ "0368": "Gianyar",
143
+ // Nusa Tenggara Barat (NTB)
144
+ "0370": "Mataram",
145
+ "0371": "Sumbawa",
146
+ "0372": "West Sumbawa",
147
+ "0373": "Dompu",
148
+ "0374": "Bima",
149
+ "0376": "East Lombok",
150
+ // Nusa Tenggara Timur (NTT)
151
+ "0379": "Alor",
152
+ "0380": "Kupang",
153
+ "0381": "Ende",
154
+ "0382": "Sikka",
155
+ "0383": "East Flores",
156
+ "0384": "Ngada",
157
+ "0385": "Manggarai",
158
+ "0386": "West Manggarai",
159
+ "0387": "Sumba",
160
+ "0388": "North & South Central Timor",
161
+ "0389": "Belu",
162
+ // ========================================
163
+ // SULAWESI
164
+ // ========================================
165
+ // South Sulawesi
166
+ "0410": "Pangkajene",
167
+ "0411": "Makassar",
168
+ "0413": "Bantaeng & Bulukumba",
169
+ "0414": "Selayar",
170
+ "0417": "Malino",
171
+ "0418": "Takalar",
172
+ "0419": "Jeneponto",
173
+ "0420": "Enrekang",
174
+ "0421": "Pare Pare",
175
+ "0423": "Tana Toraja",
176
+ "0427": "Barru",
177
+ "0471": "Luwu",
178
+ "0472": "Wajo (Pitumpanua)",
179
+ "0473": "North Luwu",
180
+ "0474": "East Luwu",
181
+ "0475": "Sorowako",
182
+ "0481": "Bone",
183
+ "0482": "Sinjai",
184
+ "0484": "Soppeng",
185
+ "0485": "Wajo",
186
+ // West Sulawesi
187
+ "0422": "Majene",
188
+ "0426": "Mamuju",
189
+ "0428": "Polewali",
190
+ "0429": "Central Mamuju",
191
+ // Central Sulawesi
192
+ "0409": "Morowali",
193
+ "0445": "Buol",
194
+ "0450": "Parigi Moutong",
195
+ "0451": "Palu",
196
+ "0452": "Poso",
197
+ "0453": "Toli-Toli",
198
+ "0454": "Tinombo",
199
+ "0455": "Moutong",
200
+ "0457": "Donggala",
201
+ "0458": "Tentena",
202
+ "0461": "Banggai",
203
+ "0462": "Banggai Island",
204
+ "0463": "Bunta",
205
+ "0464": "Tojo Una-Una",
206
+ "0465": "North Morowali",
207
+ // Southeast Sulawesi
208
+ "0401": "Kendari",
209
+ "0402": "Buton",
210
+ "0403": "Muna",
211
+ "0404": "Wakatobi",
212
+ "0405": "Kolaka",
213
+ "0408": "Konawe",
214
+ // North Sulawesi
215
+ "0430": "South Minahasa",
216
+ "0431": "Manado",
217
+ "0432": "Sangihe",
218
+ "0433": "Talaud",
219
+ "0434": "Bolaang Mongondow",
220
+ "0438": "Bitung",
221
+ // Gorontalo
222
+ "0435": "Gorontalo",
223
+ "0442": "North Gorontalo",
224
+ "0443": "Pohuwato",
225
+ // ========================================
226
+ // KALIMANTAN
227
+ // ========================================
228
+ // West Kalimantan
229
+ "0534": "Ketapang",
230
+ "0535": "Kayong Utara",
231
+ "0561": "Pontianak",
232
+ "0562": "Sambas & Singkawang",
233
+ "0563": "Landak",
234
+ "0564": "Sanggau",
235
+ "0565": "Sintang",
236
+ "0567": "Kapuas Hulu",
237
+ "0568": "Melawi",
238
+ // Central Kalimantan
239
+ "0513": "Kapuas",
240
+ "0519": "North Barito",
241
+ "0526": "South & East Barito",
242
+ "0528": "Murung Raya",
243
+ "0531": "East Kotawaringin",
244
+ "0532": "West Kotawaringin",
245
+ "0536": "Palangka Raya",
246
+ "0537": "Gunung Mas",
247
+ "0538": "Seruyan",
248
+ "0539": "Seruyan & East Kotawaringin",
249
+ // South Kalimantan
250
+ "0511": "Banjarmasin",
251
+ "0512": "Tanah Laut",
252
+ "0517": "Hulu Sungai Selatan",
253
+ "0518": "Tanah Bumbu",
254
+ "0527": "Hulu Sungai Utara",
255
+ // East Kalimantan
256
+ "0541": "Samarinda",
257
+ "0542": "Balikpapan",
258
+ "0543": "Paser",
259
+ "0545": "West Kutai",
260
+ "0548": "Bontang",
261
+ "0549": "East Kutai",
262
+ "0554": "Berau",
263
+ // North Kalimantan
264
+ "0551": "Tarakan",
265
+ "0552": "Bulungan",
266
+ "0553": "Malinau",
267
+ "0556": "Nunukan",
268
+ // ========================================
269
+ // SUMATRA
270
+ // ========================================
271
+ // Aceh
272
+ "0627": "Subulussalam & Dairi (North Sumatra)",
273
+ "0629": "Southeast Aceh",
274
+ "0641": "Langsa",
275
+ "0642": "Gayo Lues",
276
+ "0643": "Central Aceh",
277
+ "0644": "Bireuen",
278
+ "0645": "Lhokseumawe",
279
+ "0646": "East Aceh",
280
+ "0650": "Simeulue",
281
+ "0651": "Banda Aceh",
282
+ "0652": "Sabang",
283
+ "0653": "Pidie",
284
+ "0654": "Aceh Jaya",
285
+ "0655": "West Aceh",
286
+ "0656": "South Aceh",
287
+ "0657": "South Aceh",
288
+ "0658": "Singkil",
289
+ "0659": "Southwest Aceh",
290
+ // North Sumatra
291
+ "061": "Medan",
292
+ "0620": "Pangkalan Brandan",
293
+ "0621": "Tebing Tinggi",
294
+ "0622": "Pematang Siantar",
295
+ "0623": "Asahan",
296
+ "0624": "Labuhan Batu",
297
+ "0625": "Parapat",
298
+ "0626": "Samosir",
299
+ // '0627': 'Dairi', // for this prefix, it same with Subulussalam (Aceh)
300
+ "0628": "Karo",
301
+ "0630": "South Nias",
302
+ "0631": "Sibolga",
303
+ "0632": "Toba Samosir",
304
+ "0633": "North Tapanuli",
305
+ "0634": "Padang Sidempuan",
306
+ "0635": "South Tapanuli",
307
+ "0636": "Mandailing Natal",
308
+ "0638": "Barus",
309
+ "0639": "Nias",
310
+ // West Sumatra
311
+ "0751": "Padang",
312
+ "0752": "Bukittinggi",
313
+ "0753": "Pasaman",
314
+ "0754": "Sawahlunto",
315
+ "0755": "Solok",
316
+ "0756": "South Pesisir",
317
+ "0757": "South Pesisir",
318
+ "0759": "Mentawai",
319
+ // Riau
320
+ "0760": "Kuantan Singingi",
321
+ "0761": "Pekanbaru",
322
+ "0762": "Kampar",
323
+ "0763": "Bengkalis",
324
+ "0764": "Siak",
325
+ "0765": "Dumai",
326
+ "0766": "Bengkalis",
327
+ "0767": "Rokan Hulu",
328
+ "0768": "Indragiri Hilir",
329
+ "0769": "Indragiri Hulu",
330
+ // Riau Islands
331
+ "0770": "Muka Kuning Batamindo",
332
+ "0771": "Tanjungpinang",
333
+ "0772": "Anambas",
334
+ "0773": "Natuna",
335
+ "0776": "Lingga",
336
+ "0777": "Great Karimun",
337
+ "0778": "Batam",
338
+ "0779": "Kundur",
339
+ // Jambi
340
+ "0741": "Jambi",
341
+ "0742": "West Tanjung Jabung",
342
+ "0743": "Batanghari",
343
+ "0744": "Tebo",
344
+ "0745": "Sarolangun",
345
+ "0746": "Merangin",
346
+ "0747": "Bungo",
347
+ "0748": "Kerinci",
348
+ // South Sumatra
349
+ "0702": "Empat Lawang",
350
+ "0711": "Palembang",
351
+ "0712": "Ogan Komering Ilir",
352
+ "0713": "Prabumulih",
353
+ "0714": "Musi Banyuasin",
354
+ "0730": "Pagar Alam",
355
+ "0731": "Lahat",
356
+ "0733": "Lubuklinggau",
357
+ "0734": "Muara Enim",
358
+ "0735": "Ogan Komering Ulu",
359
+ // Bangka Belitung
360
+ "0715": "Belinyu",
361
+ "0716": "West Bangka",
362
+ "0717": "Pangkal Pinang",
363
+ "0718": "Central & South Bangka",
364
+ "0719": "Belitung",
365
+ // Bengkulu
366
+ "0732": "Rejang Lebong",
367
+ "0736": "Bengkulu",
368
+ "0737": "North Bengkulu",
369
+ "0739": "South Bengkulu",
370
+ // Lampung
371
+ "0721": "Bandar Lampung",
372
+ "0722": "Tanggamus",
373
+ "0723": "Way Kanan",
374
+ "0724": "North Lampung",
375
+ "0725": "Metro",
376
+ "0726": "Tulang Bawang",
377
+ "0727": "South Lampung",
378
+ "0728": "West Lampung",
379
+ "0729": "Pringsewu",
380
+ // ========================================
381
+ // MALUKU & PAPUA
382
+ // ========================================
383
+ // Maluku
384
+ "0910": "Ambon",
385
+ "0911": "Southeast Maluku",
386
+ "0913": "Tual",
387
+ "0914": "Saumlaki",
388
+ "0916": "Namlea",
389
+ "0918": "Ternate",
390
+ "0921": "Sanana",
391
+ "0924": "Tobelo",
392
+ // Papua & West Papua
393
+ "0901": "Timika",
394
+ "0902": "Agats",
395
+ "0951": "Sorong",
396
+ "0952": "South Sorong",
397
+ "0967": "Manokwari",
398
+ "0969": "Sorong",
399
+ "0971": "Merauke",
400
+ "0975": "Boven Digoel",
401
+ "0979": "Tembagapura",
402
+ "0981": "Jayapura",
403
+ "0986": "Wamena"
404
+ };
405
+
406
+ // src/phone/validate.ts
407
+ function validatePhoneNumber(phone) {
408
+ if (!phone || typeof phone !== "string") {
409
+ return false;
410
+ }
411
+ if (!/^[\d\s\-+().]+$/.test(phone)) {
412
+ return false;
413
+ }
414
+ const cleaned = phone.replace(/[\s\-().]/g, "");
415
+ let normalized;
416
+ if (cleaned.startsWith("+62")) {
417
+ normalized = "0" + cleaned.substring(3);
418
+ } else if (cleaned.startsWith("62") && !cleaned.startsWith("620")) {
419
+ normalized = "0" + cleaned.substring(2);
420
+ } else if (cleaned.startsWith("0")) {
421
+ normalized = cleaned;
422
+ } else {
423
+ return false;
424
+ }
425
+ if (normalized.startsWith("08")) {
426
+ return validateMobileNumber(normalized);
427
+ }
428
+ if (normalized.startsWith("0")) {
429
+ return validateLandlineNumber(normalized);
430
+ }
431
+ return false;
432
+ }
433
+ function validateMobileNumber(phone) {
434
+ if (phone.length < 10 || phone.length > 13) {
435
+ return false;
436
+ }
437
+ const prefix = phone.substring(0, 4);
438
+ if (!OPERATOR_PREFIXES[prefix]) {
439
+ return false;
440
+ }
441
+ if (!/^\d+$/.test(phone)) {
442
+ return false;
443
+ }
444
+ return true;
445
+ }
446
+ function validateLandlineNumber(phone) {
447
+ if (phone.length < 9 || phone.length > 11) {
448
+ return false;
449
+ }
450
+ const areaCode3 = phone.substring(0, 3);
451
+ const areaCode4 = phone.substring(0, 4);
452
+ if (AREA_CODES[areaCode3] || AREA_CODES[areaCode4]) {
453
+ return true;
454
+ }
455
+ if (/^0[2-9]\d{7,9}$/.test(phone)) {
456
+ return true;
457
+ }
458
+ return false;
459
+ }
460
+ function isMobileNumber(phone) {
461
+ if (!validatePhoneNumber(phone)) {
462
+ return false;
463
+ }
464
+ const cleaned = phone.replace(/[^\d+]/g, "");
465
+ let normalized;
466
+ if (cleaned.startsWith("+62")) {
467
+ normalized = "0" + cleaned.substring(3);
468
+ } else if (cleaned.startsWith("62")) {
469
+ normalized = "0" + cleaned.substring(2);
470
+ } else {
471
+ normalized = cleaned;
472
+ }
473
+ return normalized.startsWith("08");
474
+ }
475
+ function isLandlineNumber(phone) {
476
+ if (!validatePhoneNumber(phone)) {
477
+ return false;
478
+ }
479
+ return !isMobileNumber(phone);
480
+ }
481
+
482
+ // src/phone/format.ts
483
+ function formatPhoneNumber(phone, format = "national") {
484
+ if (!validatePhoneNumber(phone)) {
485
+ return phone;
486
+ }
487
+ const cleaned = cleanPhoneNumber(phone);
488
+ let normalized;
489
+ if (cleaned.startsWith("+62")) {
490
+ normalized = "0" + cleaned.substring(3);
491
+ } else if (cleaned.startsWith("62") && !cleaned.startsWith("620")) {
492
+ normalized = "0" + cleaned.substring(2);
493
+ } else {
494
+ normalized = cleaned;
495
+ }
496
+ switch (format) {
497
+ case "international":
498
+ return toInternational(normalized);
499
+ case "national":
500
+ case "display":
501
+ return toNational(normalized);
502
+ case "e164":
503
+ return toE164(normalized);
504
+ default:
505
+ return phone;
506
+ }
507
+ }
508
+ function toInternational(phone) {
509
+ const cleaned = cleanPhoneNumber(phone);
510
+ if (!cleaned) {
511
+ return phone;
512
+ }
513
+ const normalized = normalizeToNational(cleaned);
514
+ if (!normalized) {
515
+ return phone;
516
+ }
517
+ const withoutZero = normalized.substring(1);
518
+ if (normalized.startsWith("08")) {
519
+ if (withoutZero.length === 11) {
520
+ return `+62 ${withoutZero.substring(0, 3)}-${withoutZero.substring(3, 7)}-${withoutZero.substring(7)}`;
521
+ } else if (withoutZero.length === 10) {
522
+ return `+62 ${withoutZero.substring(0, 3)}-${withoutZero.substring(3, 6)}-${withoutZero.substring(6)}`;
523
+ } else if (withoutZero.length === 9) {
524
+ return `+62 ${withoutZero.substring(0, 3)}-${withoutZero.substring(3)}`;
525
+ } else if (withoutZero.length === 12) {
526
+ return `+62 ${withoutZero.substring(0, 3)}-${withoutZero.substring(3, 7)}-${withoutZero.substring(7)}`;
527
+ }
528
+ }
529
+ const areaCodeLength = getAreaCodeLength(normalized);
530
+ const areaCode = normalized.substring(1, areaCodeLength + 1);
531
+ const localNumber = normalized.substring(areaCodeLength + 1);
532
+ return `+62 ${areaCode}-${localNumber}`;
533
+ }
534
+ function toNational(phone) {
535
+ const cleaned = cleanPhoneNumber(phone);
536
+ if (!cleaned) {
537
+ return phone;
538
+ }
539
+ const normalized = normalizeToNational(cleaned);
540
+ if (!normalized) {
541
+ return phone;
542
+ }
543
+ if (normalized.startsWith("08")) {
544
+ if (normalized.length === 12) {
545
+ return `${normalized.substring(0, 4)}-${normalized.substring(4, 8)}-${normalized.substring(8)}`;
546
+ } else if (normalized.length === 11) {
547
+ return `${normalized.substring(0, 4)}-${normalized.substring(4, 7)}-${normalized.substring(7)}`;
548
+ } else if (normalized.length === 10) {
549
+ return `${normalized.substring(0, 4)}-${normalized.substring(4)}`;
550
+ } else if (normalized.length === 13) {
551
+ return `${normalized.substring(0, 4)}-${normalized.substring(4, 8)}-${normalized.substring(8)}`;
552
+ }
553
+ }
554
+ const areaCodeLength = getAreaCodeLength(normalized);
555
+ const areaCodeWithZero = normalized.substring(0, areaCodeLength + 1);
556
+ const localNumber = normalized.substring(areaCodeLength + 1);
557
+ return `${areaCodeWithZero}-${localNumber}`;
558
+ }
559
+ function toE164(phone) {
560
+ const cleaned = cleanPhoneNumber(phone);
561
+ if (!cleaned) {
562
+ return phone;
563
+ }
564
+ const normalized = normalizeToNational(cleaned);
565
+ if (!normalized) {
566
+ return phone;
567
+ }
568
+ return "62" + normalized.substring(1);
569
+ }
570
+ function cleanPhoneNumber(phone) {
571
+ if (!phone || typeof phone !== "string") {
572
+ return "";
573
+ }
574
+ return phone.replace(/[^\d+]/g, "");
575
+ }
576
+ function normalizeToNational(phone) {
577
+ if (phone.startsWith("+62")) {
578
+ return "0" + phone.substring(3);
579
+ } else if (phone.startsWith("62") && !phone.startsWith("620")) {
580
+ return "0" + phone.substring(2);
581
+ } else if (phone.startsWith("0")) {
582
+ return phone;
583
+ }
584
+ return "";
585
+ }
586
+ function getAreaCodeLength(normalized) {
587
+ const fourDigitCode = normalized.substring(0, 5);
588
+ if (AREA_CODES[fourDigitCode]) {
589
+ return 4;
590
+ }
591
+ const threeDigitCode = normalized.substring(0, 4);
592
+ if (AREA_CODES[threeDigitCode]) {
593
+ return 3;
594
+ }
595
+ const twoDigitCode = normalized.substring(0, 3);
596
+ if (AREA_CODES[twoDigitCode]) {
597
+ return 2;
598
+ }
599
+ return 2;
600
+ }
601
+ function maskPhoneNumber(phone, options = {}) {
602
+ const cleaned = cleanPhoneNumber(phone);
603
+ if (!cleaned) {
604
+ return phone;
605
+ }
606
+ const isInternational = cleaned.startsWith("+");
607
+ let toMask;
608
+ if (isInternational) {
609
+ toMask = cleaned;
610
+ } else {
611
+ const normalized = normalizeToNational(cleaned);
612
+ toMask = normalized || cleaned;
613
+ }
614
+ if (toMask.length < 4) {
615
+ return phone;
616
+ }
617
+ const { char = "*", separator } = options;
618
+ let { start = 4, end = 4 } = options;
619
+ if (start + end >= toMask.length) {
620
+ if (toMask.length < 10) {
621
+ const minMaskLength = 1;
622
+ const availableForVisible = toMask.length - minMaskLength;
623
+ if (availableForVisible >= 2) {
624
+ start = Math.floor(availableForVisible / 2);
625
+ end = availableForVisible - start;
626
+ } else {
627
+ return toMask;
628
+ }
629
+ } else {
630
+ return toMask;
631
+ }
632
+ }
633
+ const startPart = toMask.substring(0, start);
634
+ const endPart = toMask.substring(toMask.length - end);
635
+ const maskLength = toMask.length - start - end;
636
+ const masked = startPart + char.repeat(maskLength) + endPart;
637
+ if (separator) {
638
+ return `${masked.substring(0, start)}${separator}${masked.substring(start, masked.length - end)}${separator}${masked.substring(masked.length - end)}`;
639
+ }
640
+ return masked;
641
+ }
642
+
643
+ // src/phone/parse.ts
644
+ function parsePhoneNumber(phone) {
645
+ if (!validatePhoneNumber(phone)) {
646
+ return null;
647
+ }
648
+ const cleaned = cleanPhoneNumber(phone);
649
+ const normalized = normalizeToNational2(cleaned);
650
+ if (!normalized) {
651
+ return null;
652
+ }
653
+ const countryCode = "62";
654
+ const number = normalized.substring(1);
655
+ const isMobile = normalized.startsWith("08");
656
+ const isLandline = !isMobile;
657
+ let operator = null;
658
+ let region = null;
659
+ if (isMobile) {
660
+ operator = getOperator(normalized);
661
+ } else {
662
+ region = getRegion(normalized);
663
+ }
664
+ return {
665
+ countryCode,
666
+ operator,
667
+ number,
668
+ formatted: {
669
+ international: toInternational(normalized),
670
+ national: toNational(normalized),
671
+ e164: toE164(normalized)
672
+ },
673
+ isValid: true,
674
+ isMobile,
675
+ isLandline,
676
+ region
677
+ };
678
+ }
679
+ function getOperator(phone) {
680
+ if (!isMobileNumber(phone)) {
681
+ return null;
682
+ }
683
+ const cleaned = cleanPhoneNumber(phone);
684
+ const normalized = normalizeToNational2(cleaned);
685
+ if (!normalized || normalized.length < 4) {
686
+ return null;
687
+ }
688
+ const prefix = normalized.substring(0, 4);
689
+ return OPERATOR_PREFIXES[prefix] || null;
690
+ }
691
+ function getRegion(phone) {
692
+ if (!phone.startsWith("0")) {
693
+ return null;
694
+ }
695
+ const areaCode4 = phone.substring(0, 4);
696
+ if (AREA_CODES[areaCode4]) {
697
+ return AREA_CODES[areaCode4];
698
+ }
699
+ const areaCode3 = phone.substring(0, 3);
700
+ if (AREA_CODES[areaCode3]) {
701
+ return AREA_CODES[areaCode3];
702
+ }
703
+ return null;
704
+ }
705
+ function normalizeToNational2(phone) {
706
+ if (phone.startsWith("+62")) {
707
+ return "0" + phone.substring(3);
708
+ } else if (phone.startsWith("62")) {
709
+ return "0" + phone.substring(2);
710
+ } else if (phone.startsWith("0")) {
711
+ return phone;
712
+ }
713
+ return "";
714
+ }
715
+
716
+ export { cleanPhoneNumber, formatPhoneNumber, getOperator, isLandlineNumber, isMobileNumber, maskPhoneNumber, parsePhoneNumber, toE164, toInternational, toNational, validatePhoneNumber };
717
+ //# sourceMappingURL=index.js.map
718
+ //# sourceMappingURL=index.js.map