src/virama.ts   A
last analyzed

Complexity

Total Complexity 12
Complexity/F 0

Size

Lines of Code 914
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 693
dl 0
loc 914
rs 9.907
c 0
b 0
f 0
wmc 12
mnd 12
bc 12
fnc 0
bpm 0
cpm 0
noi 0
1
const testerID: string = 'fontTester';
2
let browserFont: string;
3
4
const addTestDivToBody = () => {
5
  const newDiv = document.createElement('div');
6
  newDiv.style.cssText =
7
    'position:absolute;width:100%;opacity:0.3;z-index:-10; top: -50px; height: 20px; display: none';
8
  newDiv.id = testerID;
9
  const spanCss = 'font-family: initial; margin: 0; padding: 0; font-size: 20px; line-height: 20px; height: 20px;';
10
  const testSpans =
11
    '<span style="' +
12
    spanCss +
13
    '" id="one_ka">&#x1000;</span>\n' +
14
    '<span style="' +
15
    spanCss +
16
    '" id="two_ka">&#x1000;&#x1039;&#x1000;</span>\n';
17
  newDiv.innerHTML = testSpans;
18
  document.body.appendChild(newDiv);
19
20
  return true;
21
};
22
23
const detectBrowserFont = (): string => {
24
  const testDiv = document.getElementById(testerID);
25
  if (testDiv) {
26
    testDiv.style.display = '';
27
  }
28
  const oneKa = document.getElementById('one_ka');
29
  const twoKa = document.getElementById('two_ka');
30
31
  if (oneKa && twoKa) {
32
    browserFont = oneKa.offsetWidth * 1.5 > twoKa.offsetWidth ? 'Unicode' : 'Zawgyi';
33
    if (testDiv) {
34
      testDiv.style.display = 'none';
35
    }
36
  }
37
38
  return browserFont;
39
};
40
41
const init = async () => {
42
  if (document.getElementById(testerID)) {
43
    browserFont = detectBrowserFont();
44
  } else {
45
    await addTestDivToBody();
46
    browserFont = detectBrowserFont();
47
  }
48
};
49
init();
50
51
const replaceWithRule = (rule: any[], output: string): string => {
52
  const maxLoop = rule.length;
53
  for (let i = 0; i < maxLoop; i++) {
54
    const data = rule[i];
55
    const from = data.from;
56
    const to = data.to;
57
58
    const fromRegex = new RegExp(from, 'g');
59
    output = output.replace(fromRegex, to);
60
  }
61
62
  return output;
63
};
64
65
export const getBrowserFont = (): string => {
66
  return browserFont;
67
};
68
69
export const isMyanmarText = (text: string): boolean => {
70
  const MyanmarReg = new RegExp('[\u1000-\u1021]');
71
  return MyanmarReg.test(text) ? true : false;
72
};
73
74
export const uni2zg = (output: string): string => {
75
  if (!isMyanmarText(output)) {
76
    return output;
77
  }
78
79
  const rule = [
80
    {
81
      from: '\u1004\u103a\u1039',
82
      to: '\u1064',
83
    },
84
    {
85
      from: '\u1039\u1010\u103d',
86
      to: '\u1096',
87
    },
88
    {
89
      from: '\u102b\u103a',
90
      to: '\u105a',
91
    },
92
    {
93
      from: '\u100b\u1039\u100c',
94
      to: '\u1092',
95
    },
96
    {
97
      from: '\u102d\u1036',
98
      to: '\u108e',
99
    },
100
    {
101
      from: '\u104e\u1004\u103a\u1038',
102
      to: '\u104e',
103
    },
104
    {
105
      from: '[\u1025\u1009](?=[\u1039\u102f\u1030])',
106
      to: '\u106a',
107
    },
108
    {
109
      from: '[\u1025\u1009](?=[\u1037]?[\u103a])',
110
      to: '\u1025',
111
    },
112
    {
113
      from: '\u100a(?=[\u1039\u103d])',
114
      to: '\u106b',
115
    },
116
    {
117
      from: '(\u1039[\u1000-\u1021])(\u102D){0,1}\u102f',
118
      to: '$1$2\u1033',
119
    },
120
    {
121
      from: '(\u1039[\u1000-\u1021])\u1030',
122
      to: '$1\u1034',
123
    },
124
    {
125
      from: '\u1014(?=[\u102d\u102e\u103a]?[\u102f\u1030\u103d\u103e\u1039])',
126
      to: '\u108f',
127
    },
128
    {
129
      from: '\u1014\u103c',
130
      to: '\u108f\u103c',
131
    },
132
    {
133
      from: '\u1039\u1000',
134
      to: '\u1060',
135
    },
136
    {
137
      from: '\u1039\u1001',
138
      to: '\u1061',
139
    },
140
    {
141
      from: '\u1039\u1002',
142
      to: '\u1062',
143
    },
144
    {
145
      from: '\u1039\u1003',
146
      to: '\u1063',
147
    },
148
    {
149
      from: '\u1039\u1005',
150
      to: '\u1065',
151
    },
152
    {
153
      from: '\u1039\u1006',
154
      to: '\u1066',
155
    },
156
    {
157
      from: '\u1039\u1007',
158
      to: '\u1068',
159
    },
160
    {
161
      from: '\u1039\u1008',
162
      to: '\u1069',
163
    },
164
    {
165
      from: '\u1039\u100b',
166
      to: '\u106c',
167
    },
168
    {
169
      from: '\u1039\u100c',
170
      to: '\u106d',
171
    },
172
    {
173
      from: '\u100d\u1039\u100d',
174
      to: '\u106e',
175
    },
176
    {
177
      from: '\u100e\u1039\u100d',
178
      to: '\u106f',
179
    },
180
    {
181
      from: '\u1039\u100f',
182
      to: '\u1070',
183
    },
184
    {
185
      from: '\u1039\u1010',
186
      to: '\u1071',
187
    },
188
    {
189
      from: '\u1039\u1011',
190
      to: '\u1073',
191
    },
192
    {
193
      from: '\u1039\u1012',
194
      to: '\u1075',
195
    },
196
    {
197
      from: '\u1039\u1013',
198
      to: '\u1076',
199
    },
200
    {
201
      from: '\u1039[\u1014\u108f]',
202
      to: '\u1077',
203
    },
204
    {
205
      from: '\u1039\u1015',
206
      to: '\u1078',
207
    },
208
    {
209
      from: '\u1039\u1016',
210
      to: '\u1079',
211
    },
212
    {
213
      from: '\u1039\u1017',
214
      to: '\u107a',
215
    },
216
    {
217
      from: '\u1039\u1018',
218
      to: '\u107b',
219
    },
220
    {
221
      from: '\u1039\u1019',
222
      to: '\u107c',
223
    },
224
    {
225
      from: '\u1039\u101c',
226
      to: '\u1085',
227
    },
228
    {
229
      from: '\u103f',
230
      to: '\u1086',
231
    },
232
    {
233
      from: '\u103d\u103e',
234
      to: '\u108a',
235
    },
236
    {
237
      from: '(\u1064)([\u1000-\u1021])([\u103b\u103c]?)\u102d',
238
      to: '$2$3\u108b',
239
    },
240
    {
241
      from: '(\u1064)([\u1000-\u1021])([\u103b\u103c]?)\u102e',
242
      to: '$2$3\u108c',
243
    },
244
    {
245
      from: '(\u1064)([\u1000-\u1021])([\u103b\u103c]?)\u1036',
246
      to: '$2$3\u108d',
247
    },
248
    {
249
      from: '(\u1064)([\u1000-\u1021])([\u103b\u103c]?)([\u1031]?)',
250
      to: '$2$3$4$1',
251
    },
252
    {
253
      from: '\u101b(?=([\u102d\u102e]?)[\u102f\u1030\u103d\u108a])',
254
      to: '\u1090',
255
    },
256
    {
257
      from: '\u100f\u1039\u100d',
258
      to: '\u1091',
259
    },
260
    {
261
      from: '\u100b\u1039\u100b',
262
      to: '\u1097',
263
    },
264
    {
265
      from:
266
        '([\u1000-\u1021\u108f\u1029\u1090])([\u1060-\u1069\u106c\u106d\u1070-\u107c\u1085\u108a])?([\u103b-\u103e]*)?\u1031',
267
      to: '\u1031$1$2$3',
268
    },
269
    {
270
      from: '\u103c\u103e',
271
      to: '\u103c\u1087',
272
    },
273
    {
274
      from: '([\u1000-\u1021\u108f\u1029])([\u1060-\u1069\u106c\u106d\u1070-\u107c\u1085])?(\u103c)',
275
      to: '$3$1$2',
276
    },
277
    {
278
      from: '\u103a',
279
      to: '\u1039',
280
    },
281
    {
282
      from: '\u103b',
283
      to: '\u103a',
284
    },
285
    {
286
      from: '\u103c',
287
      to: '\u103b',
288
    },
289
    {
290
      from: '\u103d',
291
      to: '\u103c',
292
    },
293
    {
294
      from: '\u103e',
295
      to: '\u103d',
296
    },
297
    {
298
      from: '([^\u103a\u100a])\u103d([\u102d\u102e]?)\u102f',
299
      to: '$1\u1088$2',
300
    },
301
    {
302
      from:
303
        '([\u101b\u103a\u103c\u108a\u1088\u1090])([\u1030\u103d])?([\u1032\u1036\u1039\u102d\u102e\u108b\u108c\u108d\u108e]?)(\u102f)?\u1037',
304
      to: '$1$2$3$4\u1095',
305
    },
306
    {
307
      from: '([\u102f\u1014\u1030\u103d])([\u1032\u1036\u1039\u102d\u102e\u108b\u108c\u108d\u108e]?)\u1037',
308
      to: '$1$2\u1094',
309
    },
310
    {
311
      from: '([\u103b])([\u1000-\u1021])([\u1087]?)([\u1036\u102d\u102e\u108b\u108c\u108d\u108e]?)\u102f',
312
      to: '$1$2$3$4\u1033',
313
    },
314
    {
315
      from: '([\u103b])([\u1000-\u1021])([\u1087]?)([\u1036\u102d\u102e\u108b\u108c\u108d\u108e]?)\u1030',
316
      to: '$1$2$3$4\u1034',
317
    },
318
    {
319
      from: '([\u103a\u103c\u100a\u1020\u1025])([\u103d]?)([\u1036\u102d\u102e\u108b\u108c\u108d\u108e]?)\u102f',
320
      to: '$1$2$3\u1033',
321
    },
322
    {
323
      from: '([\u103a\u103c\u100a\u101b])(\u103d?)([\u1036\u102d\u102e\u108b\u108c\u108d\u108e]?)\u1030',
324
      to: '$1$2$3\u1034',
325
    },
326
    {
327
      from: '\u100a\u103d',
328
      to: '\u100a\u1087',
329
    },
330
    {
331
      from: '\u103d\u1030',
332
      to: '\u1089',
333
    },
334
    {
335
      from: '\u103b([\u1000\u1003\u1006\u100f\u1010\u1011\u1018\u101a\u101c\u101a\u101e\u101f])',
336
      to: '\u107e$1',
337
    },
338
    {
339
      from:
340
        '\u107e([\u1000\u1003\u1006\u100f\u1010\u1011\u1018\u101a\u101c\u101a\u101e\u101f])([\u103c\u108a])([\u1032\u1036\u102d\u102e\u108b\u108c\u108d\u108e])',
341
      to: '\u1084$1$2$3',
342
    },
343
    {
344
      from: '\u107e([\u1000\u1003\u1006\u100f\u1010\u1011\u1018\u101a\u101c\u101a\u101e\u101f])([\u103c\u108a])',
345
      to: '\u1082$1$2',
346
    },
347
    {
348
      from:
349
        '\u107e([\u1000\u1003\u1006\u100f\u1010\u1011\u1018\u101a\u101c\u101a\u101e\u101f])([\u1033\u1034]?)([\u1032\u1036\u102d\u102e\u108b\u108c\u108d\u108e])',
350
      to: '\u1080$1$2$3',
351
    },
352
    {
353
      from: '\u103b([\u1000-\u1021])([\u103c\u108a])([\u1032\u1036\u102d\u102e\u108b\u108c\u108d\u108e])',
354
      to: '\u1083$1$2$3',
355
    },
356
    {
357
      from: '\u103b([\u1000-\u1021])([\u103c\u108a])',
358
      to: '\u1081$1$2',
359
    },
360
    {
361
      from: '\u103b([\u1000-\u1021])([\u1033\u1034]?)([\u1032\u1036\u102d\u102e\u108b\u108c\u108d\u108e])',
362
      to: '\u107f$1$2$3',
363
    },
364
    {
365
      from: '\u103a\u103d',
366
      to: '\u103d\u103a',
367
    },
368
    {
369
      from: '\u103a([\u103c\u108a])',
370
      to: '$1\u107d',
371
    },
372
    {
373
      from: '([\u1033\u1034])(\u1036?)\u1094',
374
      to: '$1$2\u1095',
375
    },
376
    {
377
      from: '\u108F\u1071',
378
      to: '\u108F\u1072',
379
    },
380
    {
381
      from: '([\u1000-\u1021])([\u107B\u1066])\u102C',
382
      to: '$1\u102C$2',
383
    },
384
    {
385
      from: '\u102C([\u107B\u1066])\u1037',
386
      to: '\u102C$1\u1094',
387
    },
388
  ];
389
  return replaceWithRule(rule, output);
390
};
391
392
export const zg2uni = (output: string): string => {
393
  if (!isMyanmarText(output)) {
394
    return output;
395
  }
396
397
  const rule = [
398
    {
399
      from: '\u102f\u102f',
400
      to: '\u102f',
401
    },
402
    {
403
      from: '\u200B',
404
      to: '',
405
    },
406
    {
407
      from: '(\u103d|\u1087)',
408
      to: '\u103e',
409
    },
410
    {
411
      from: '\u103c',
412
      to: '\u103d',
413
    },
414
    {
415
      from: '(\u103b|\u107e|\u107f|\u1080|\u1081|\u1082|\u1083|\u1084)',
416
      to: '\u103c',
417
    },
418
    {
419
      from: '(\u103a|\u107d)',
420
      to: '\u103b',
421
    },
422
    {
423
      from: '\u1039',
424
      to: '\u103a',
425
    },
426
    {
427
      from: '(\u1066|\u1067)',
428
      to: '\u1039\u1006',
429
    },
430
    {
431
      from: '\u106a',
432
      to: '\u1009',
433
    },
434
    {
435
      from: '\u106b',
436
      to: '\u100a',
437
    },
438
    {
439
      from: '\u106c',
440
      to: '\u1039\u100b',
441
    },
442
    {
443
      from: '\u106d',
444
      to: '\u1039\u100c',
445
    },
446
    {
447
      from: '\u106e',
448
      to: '\u100d\u1039\u100d',
449
    },
450
    {
451
      from: '\u106f',
452
      to: '\u100d\u1039\u100e',
453
    },
454
    {
455
      from: '\u1070',
456
      to: '\u1039\u100f',
457
    },
458
    {
459
      from: '(\u1071|\u1072)',
460
      to: '\u1039\u1010',
461
    },
462
    {
463
      from: '\u1060',
464
      to: '\u1039\u1000',
465
    },
466
    {
467
      from: '\u1061',
468
      to: '\u1039\u1001',
469
    },
470
    {
471
      from: '\u1062',
472
      to: '\u1039\u1002',
473
    },
474
    {
475
      from: '\u1063',
476
      to: '\u1039\u1003',
477
    },
478
    {
479
      from: '\u1065',
480
      to: '\u1039\u1005',
481
    },
482
    {
483
      from: '\u1068',
484
      to: '\u1039\u1007',
485
    },
486
    {
487
      from: '\u1069',
488
      to: '\u1039\u1008',
489
    },
490
    {
491
      from: '(\u1073|\u1074)',
492
      to: '\u1039\u1011',
493
    },
494
    {
495
      from: '\u1075',
496
      to: '\u1039\u1012',
497
    },
498
    {
499
      from: '\u1076',
500
      to: '\u1039\u1013',
501
    },
502
    {
503
      from: '\u1077',
504
      to: '\u1039\u1014',
505
    },
506
    {
507
      from: '\u1078',
508
      to: '\u1039\u1015',
509
    },
510
    {
511
      from: '\u1079',
512
      to: '\u1039\u1016',
513
    },
514
    {
515
      from: '\u107a',
516
      to: '\u1039\u1017',
517
    },
518
    {
519
      from: '\u107c',
520
      to: '\u1039\u1019',
521
    },
522
    {
523
      from: '\u1085',
524
      to: '\u1039\u101c',
525
    },
526
    {
527
      from: '\u1033',
528
      to: '\u102f',
529
    },
530
    {
531
      from: '\u1034',
532
      to: '\u1030',
533
    },
534
    {
535
      from: '\u103f',
536
      to: '\u1030',
537
    },
538
    {
539
      from: '\u1086',
540
      to: '\u103f',
541
    },
542
    {
543
      from: '\u1036\u1088',
544
      to: '\u1088\u1036',
545
    },
546
    {
547
      from: '\u1088',
548
      to: '\u103e\u102f',
549
    },
550
    {
551
      from: '\u1089',
552
      to: '\u103e\u1030',
553
    },
554
    {
555
      from: '\u108a',
556
      to: '\u103d\u103e',
557
    },
558
    {
559
      from: '\u103B\u1064',
560
      to: '\u1064\u103B',
561
    },
562
    {
563
      from: '(\u1031)?([\u1000-\u1021])\u1064',
564
      to: '\u1004\u103a\u1039$1$2',
565
    },
566
    {
567
      from: '(\u1031)?([\u1000-\u1021])\u108b',
568
      to: '\u1004\u103a\u1039$1$2\u102d',
569
    },
570
    {
571
      from: '(\u1031)?([\u1000-\u1021])\u108c',
572
      to: '\u1004\u103a\u1039$1$2\u102e',
573
    },
574
    {
575
      from: '(\u1031)?([\u1000-\u1021])\u108d',
576
      to: '\u1004\u103a\u1039$1$2\u1036',
577
    },
578
    {
579
      from: '\u108e',
580
      to: '\u102d\u1036',
581
    },
582
    {
583
      from: '\u108f',
584
      to: '\u1014',
585
    },
586
    {
587
      from: '\u1090',
588
      to: '\u101b',
589
    },
590
    {
591
      from: '\u1091',
592
      to: '\u100f\u1039\u100d',
593
    },
594
    {
595
      from: '\u1019\u102c(\u107b|\u1093)',
596
      to: '\u1019\u1039\u1018\u102c',
597
    },
598
    {
599
      from: '(\u107b|\u1093)',
600
      to: '\u1039\u1018',
601
    },
602
    {
603
      from: '(\u1094|\u1095)',
604
      to: '\u1037',
605
    },
606
    {
607
      from: '([\u1000-\u1021])\u1037\u1032',
608
      to: '$1\u1032\u1037',
609
    },
610
    {
611
      from: '\u1096',
612
      to: '\u1039\u1010\u103d',
613
    },
614
    {
615
      from: '\u1097',
616
      to: '\u100b\u1039\u100b',
617
    },
618
    {
619
      from: '\u103c([\u1000-\u1021])([\u1000-\u1021])?',
620
      to: '$1\u103c$2',
621
    },
622
    {
623
      from: '([\u1000-\u1021])\u103c\u103a',
624
      to: '\u103c$1\u103a',
625
    },
626
    {
627
      from: '\u1047(?=[\u102c-\u1030\u1032\u1036-\u1038\u103d\u1038])',
628
      to: '\u101b',
629
    },
630
    {
631
      from: '\u1031\u1047',
632
      to: '\u1031\u101b',
633
    },
634
    {
635
      from: '\u1040(\u102e|\u102f|\u102d\u102f|\u1030|\u1036|\u103d|\u103e)',
636
      to: '\u101d$1',
637
    },
638
    {
639
      from: '([^\u1040\u1041\u1042\u1043\u1044\u1045\u1046\u1047\u1048\u1049])\u1040\u102b',
640
      to: '$1\u101d\u102b',
641
    },
642
    {
643
      from: '([\u1040\u1041\u1042\u1043\u1044\u1045\u1046\u1047\u1048\u1049])\u1040\u102b(?!\u1038)',
644
      to: '$1\u101d\u102b',
645
    },
646
    {
647
      from: '^\u1040(?=\u102b)',
648
      to: '\u101d',
649
    },
650
    {
651
      from: '\u1040\u102d(?!\u0020?/)',
652
      to: '\u101d\u102d',
653
    },
654
    {
655
      from: '([^\u1040-\u1049])\u1040([^\u1040-\u1049\u0020]|[\u104a\u104b])',
656
      to: '$1\u101d$2',
657
    },
658
    {
659
      from: '([^\u1040-\u1049])\u1040(?=[\\f\\n\\r])',
660
      to: '$1\u101d',
661
    },
662
    {
663
      from: '([^\u1040-\u1049])\u1040$',
664
      to: '$1\u101d',
665
    },
666
    {
667
      from: '\u1031([\u1000-\u1021])(\u103e)?(\u103b)?',
668
      to: '$1$2$3\u1031',
669
    },
670
    {
671
      from: '([\u1000-\u1021])\u1031([\u103b\u103c\u103d\u103e]+)',
672
      to: '$1$2\u1031',
673
    },
674
    {
675
      from: '\u1032\u103d',
676
      to: '\u103d\u1032',
677
    },
678
    {
679
      from: '([\u102d\u102e])\u103b',
680
      to: '\u103b$1',
681
    },
682
    {
683
      from: '\u103d\u103b',
684
      to: '\u103b\u103d',
685
    },
686
    {
687
      from: '\u103a\u1037',
688
      to: '\u1037\u103a',
689
    },
690
    {
691
      from: '\u102f(\u102d|\u102e|\u1036|\u1037)\u102f',
692
      to: '\u102f$1',
693
    },
694
    {
695
      from: '(\u102f|\u1030)(\u102d|\u102e)',
696
      to: '$2$1',
697
    },
698
    {
699
      from: '(\u103e)(\u103b|\u103c)',
700
      to: '$2$1',
701
    },
702
    {
703
      from: '\u1025(?=[\u1037]?[\u103a\u102c])',
704
      to: '\u1009',
705
    },
706
    {
707
      from: '\u1025\u102e',
708
      to: '\u1026',
709
    },
710
    {
711
      from: '\u1005\u103b',
712
      to: '\u1008',
713
    },
714
    {
715
      from: '\u1036(\u102f|\u1030)',
716
      to: '$1\u1036',
717
    },
718
    {
719
      from: '\u1031\u1037\u103e',
720
      to: '\u103e\u1031\u1037',
721
    },
722
    {
723
      from: '\u1031\u103e\u102c',
724
      to: '\u103e\u1031\u102c',
725
    },
726
    {
727
      from: '\u105a',
728
      to: '\u102b\u103a',
729
    },
730
    {
731
      from: '\u1031\u103b\u103e',
732
      to: '\u103b\u103e\u1031',
733
    },
734
    {
735
      from: '(\u102d|\u102e)(\u103d|\u103e)',
736
      to: '$2$1',
737
    },
738
    {
739
      from: '\u102c\u1039([\u1000-\u1021])',
740
      to: '\u1039$1\u102c',
741
    },
742
    {
743
      from: '\u103c\u1004\u103a\u1039([\u1000-\u1021])',
744
      to: '\u1004\u103a\u1039$1\u103c',
745
    },
746
    {
747
      from: '\u1039\u103c\u103a\u1039([\u1000-\u1021])',
748
      to: '\u103a\u1039$1\u103c',
749
    },
750
    {
751
      from: '\u103c\u1039([\u1000-\u1021])',
752
      to: '\u1039$1\u103c',
753
    },
754
    {
755
      from: '\u1036\u1039([\u1000-\u1021])',
756
      to: '\u1039$1\u1036',
757
    },
758
    {
759
      from: '\u1092',
760
      to: '\u100b\u1039\u100c',
761
    },
762
    {
763
      from: '\u104e',
764
      to: '\u104e\u1004\u103a\u1038',
765
    },
766
    {
767
      from: '\u1040(\u102b|\u102c|\u1036)',
768
      to: '\u101d$1',
769
    },
770
    {
771
      from: '\u1025\u1039',
772
      to: '\u1009\u1039',
773
    },
774
    {
775
      from: '([\u1000-\u1021])\u103c\u1031\u103d',
776
      to: '$1\u103c\u103d\u1031',
777
    },
778
    {
779
      from: '([\u1000-\u1021])\u103b\u1031\u103d(\u103e)?',
780
      to: '$1\u103b\u103d$2\u1031',
781
    },
782
    {
783
      from: '([\u1000-\u1021])\u103d\u1031\u103b',
784
      to: '$1\u103b\u103d\u1031',
785
    },
786
    {
787
      from: '([\u1000-\u1021])\u1031(\u1039[\u1000-\u1021])',
788
      to: '$1$2\u1031',
789
    },
790
    {
791
      from: '\u1038\u103a',
792
      to: '\u103a\u1038',
793
    },
794
    {
795
      from: '\u102d\u103a|\u103a\u102d',
796
      to: '\u102d',
797
    },
798
    {
799
      from: '\u102d\u102f\u103a',
800
      to: '\u102d\u102f',
801
    },
802
    {
803
      from: '\u0020\u1037',
804
      to: '\u1037',
805
    },
806
    {
807
      from: '\u1037\u1036',
808
      to: '\u1036\u1037',
809
    },
810
    {
811
      from: ' \u1037',
812
      to: '\u1037',
813
    },
814
    {
815
      from: '[\u102d]+',
816
      to: '\u102d',
817
    },
818
    {
819
      from: '[\u103a]+',
820
      to: '\u103a',
821
    },
822
    {
823
      from: '[\u103d]+',
824
      to: '\u103d',
825
    },
826
    {
827
      from: '[\u1037]+',
828
      to: '\u1037',
829
    },
830
    {
831
      from: '[\u102e]+',
832
      to: '\u102e',
833
    },
834
    {
835
      from: '\u102d\u102e|\u102e\u102d',
836
      to: '\u102e',
837
    },
838
    {
839
      from: '\u102f\u102d',
840
      to: '\u102d\u102f',
841
    },
842
    {
843
      from: '\u1037\u1037',
844
      to: '\u1037',
845
    },
846
    {
847
      from: '\u1032\u1032',
848
      to: '\u1032',
849
    },
850
    {
851
      from: '\u1044\u1004\u103a\u1038',
852
      to: '\u104E\u1004\u103a\u1038',
853
    },
854
    {
855
      from: '([\u102d\u102e])\u1039([\u1000-\u1021])',
856
      to: '\u1039$2$1',
857
    },
858
    {
859
      from: '\u1036\u103d',
860
      to: '\u103d\u1036',
861
    },
862
  ];
863
  return replaceWithRule(rule, output);
864
};
865
866
const uniNormalize = (output: string): string => {
867
  if (!isMyanmarText(output)) {
868
    return output;
869
  }
870
871
  const rule = [
872
    {
873
      from: '\u1025\u1013',
874
      to: '\u1026',
875
    },
876
    {
877
      from: '\u101e\u103c',
878
      to: '\u1029',
879
    },
880
    {
881
      from: '\u101e\u103c\u1031\u102c\u103A',
882
      to: '\u102A',
883
    },
884
    {
885
      from: '\u102F\u102D',
886
      to: '\u102D\u102F',
887
    },
888
  ];
889
  return replaceWithRule(rule, output);
890
};
891
892
export const isUnicodeUser = (): boolean => {
893
  return getBrowserFont() === 'Unicode';
894
};
895
896
export const textToWrite = (output: string): string => {
897
  return isUnicodeUser() ? uniNormalize(output) : uniNormalize(zg2uni(output));
898
};
899
900
export const textToRead = (output: string): string => {
901
  return isUnicodeUser() ? output : uni2zg(output);
902
};
903
904
export const Virama = {
905
  getBrowserFont,
906
  init,
907
  isMyanmarText,
908
  isUnicodeUser,
909
  textToRead,
910
  textToWrite,
911
  uni2zg,
912
  zg2uni,
913
};
914