-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTools.js
More file actions
5454 lines (4641 loc) · 200 KB
/
Tools.js
File metadata and controls
5454 lines (4641 loc) · 200 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//////////// Tools ////////////
/**# tools for Javascript
* @version 2.12.14
* for Node.js >= 16.x.x
* @module Tools
* @changes
* - add: JSComments Regex
* - update: IPC
* - optimize: strWrap()
* - add: class ConsoleTime
* - fix: types error
* - remove: modification of Object prototypes
*
* DISCLAIMER: parts of this code are based on or copied (with slight modification) from other sources.
* for license information, please refer to the respective sources.
*/
"use strict";
const onJSRuntime = (typeof window === 'undefined'||typeof process !== 'undefined');
var _modules = {
dgram: null,
worker_threads: null,
os: null,
fs: null,
/**3rd party Module*/
mathjs: null,
};
let _global = {
consoleTimeInstances: null
}
/**
* Created by Wiktor Stribiżew, Sep 9, 2021
* Matching all 4590 emoji characters defined in the Emoji Keyboard/Display Test Data for UTR #51 (Version: 13.1).
*
* @from [stribizhev/Emojis](https://github.com/stribizhev/Emojis/tree/main)
*/
const EMOJI_MATCHER_TOKEN = "[#*0-9]\\uFE0F?\\u20E3|©\\uFE0F?|[®\\u203C\\u2049\\u2122\\u2139\\u2194-\\u2199\\u21A9\\u21AA]\\uFE0F?|[\\u231A\\u231B]|[\\u2328\\u23CF]\\uFE0F?|[\\u23E9-\\u23EC]|[\\u23ED-\\u23EF]\\uFE0F?|\\u23F0|[\\u23F1\\u23F2]\\uFE0F?|\\u23F3|[\\u23F8-\\u23FA\\u24C2\\u25AA\\u25AB\\u25B6\\u25C0\\u25FB\\u25FC]\\uFE0F?|[\\u25FD\\u25FE]|[\\u2600-\\u2604\\u260E\\u2611]\\uFE0F?|[\\u2614\\u2615]|\\u2618\\uFE0F?|\\u261D(?:\\uD83C[\\uDFFB-\\uDFFF]|\\uFE0F)?|[\\u2620\\u2622\\u2623\\u2626\\u262A\\u262E\\u262F\\u2638-\\u263A\\u2640\\u2642]\\uFE0F?|[\\u2648-\\u2653]|[\\u265F\\u2660\\u2663\\u2665\\u2666\\u2668\\u267B\\u267E]\\uFE0F?|\\u267F|\\u2692\\uFE0F?|\\u2693|[\\u2694-\\u2697\\u2699\\u269B\\u269C\\u26A0]\\uFE0F?|\\u26A1|\\u26A7\\uFE0F?|[\\u26AA\\u26AB]|[\\u26B0\\u26B1]\\uFE0F?|[\\u26BD\\u26BE\\u26C4\\u26C5]|\\u26C8\\uFE0F?|\\u26CE|[\\u26CF\\u26D1\\u26D3]\\uFE0F?|\\u26D4|\\u26E9\\uFE0F?|\\u26EA|[\\u26F0\\u26F1]\\uFE0F?|[\\u26F2\\u26F3]|\\u26F4\\uFE0F?|\\u26F5|[\\u26F7\\u26F8]\\uFE0F?|\\u26F9(?:\\u200D[\\u2640\\u2642]\\uFE0F?|\\uD83C[\\uDFFB-\\uDFFF](?:\\u200D[\\u2640\\u2642]\\uFE0F?)?|\\uFE0F(?:\\u200D[\\u2640\\u2642]\\uFE0F?)?)?|[\\u26FA\\u26FD]|\\u2702\\uFE0F?|\\u2705|[\\u2708\\u2709]\\uFE0F?|[\\u270A\\u270B](?:\\uD83C[\\uDFFB-\\uDFFF])?|[\\u270C\\u270D](?:\\uD83C[\\uDFFB-\\uDFFF]|\\uFE0F)?|\\u270F\\uFE0F?|[\\u2712\\u2714\\u2716\\u271D\\u2721]\\uFE0F?|\\u2728|[\\u2733\\u2734\\u2744\\u2747]\\uFE0F?|[\\u274C\\u274E\\u2753-\\u2755\\u2757]|\\u2763\\uFE0F?|\\u2764(?:\\u200D(?:\\uD83D\\uDD25|\\uD83E\\uDE79)|\\uFE0F(?:\\u200D(?:\\uD83D\\uDD25|\\uD83E\\uDE79))?)?|[\\u2795-\\u2797]|\\u27A1\\uFE0F?|[\\u27B0\\u27BF]|[\\u2934\\u2935\\u2B05-\\u2B07]\\uFE0F?|[\\u2B1B\\u2B1C\\u2B50\\u2B55]|[\\u3030\\u303D\\u3297\\u3299]\\uFE0F?|\\uD83C(?:[\\uDC04\\uDCCF]|[\\uDD70\\uDD71\\uDD7E\\uDD7F]\\uFE0F?|[\\uDD8E\\uDD91-\\uDD9A]|\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D83C[\\uDFFB-\\uDFFF](?:\\u200D[\\u2640\\u2642]\\uFE0F?)?)?|[\\uDFC5\\uDFC6]|\\uDFC7(?:\\uD83C[\\uDFFB-\\uDFFF])?|[\\uDFC8\\uDFC9]|\\uDFCA(?:\\u200D[\\u2640\\u2642]\\uFE0F?|\\uD83C[\\uDFFB-\\uDFFF](?:\\u200D[\\u2640\\u2642]\\uFE0F?)?)?|[\\uDFCB\\uDFCC](?:\\u200D[\\u2640\\u2642]\\uFE0F?|\\uD83C[\\uDFFB-\\uDFFF](?:\\u200D[\\u2640\\u2642]\\uFE0F?)?|\\uFE0F(?:\\u200D[\\u2640\\u2642]\\uFE0F?)?)?|[\\uDFCD\\uDFCE]\\uFE0F?|[\\uDFCF-\\uDFD3]|[\\uDFD4-\\uDFDF]\\uFE0F?|[\\uDFE0-\\uDFF0]|\\uDFF3(?:\\u200D(?:\\u26A7\\uFE0F?|\\uD83C\\uDF08)|\\uFE0F(?:\\u200D(?:\\u26A7\\uFE0F?|\\uD83C\\uDF08))?)?|\\uDFF4(?:\\u200D\\u2620\\uFE0F?|\\uDB40\\uDC67\\uDB40\\uDC62\\uDB40(?:\\uDC65\\uDB40\\uDC6E\\uDB40\\uDC67|\\uDC73\\uDB40\\uDC63\\uDB40\\uDC74|\\uDC77\\uDB40\\uDC6C\\uDB40\\uDC73)\\uDB40\\uDC7F)?|[\\uDFF5\\uDFF7]\\uFE0F?|[\\uDFF8-\\uDFFF])|\\uD83D(?:[\\uDC00-\\uDC07]|\\uDC08(?:\\u200D\\u2B1B)?|[\\uDC09-\\uDC14]|\\uDC15(?:\\u200D\\uD83E\\uDDBA)?|[\\uDC16-\\uDC3A]|\\uDC3B(?:\\u200D\\u2744\\uFE0F?)?|[\\uDC3C-\\uDC3E]|\\uDC3F\\uFE0F?|\\uDC40|\\uDC41(?:\\u200D\\uD83D\\uDDE8\\uFE0F?|\\uFE0F(?:\\u200D\\uD83D\\uDDE8\\uFE0F?)?)?|[\\uDC42\\uDC43](?:\\uD83C[\\uDFFB-\\uDFFF])?|[\\uDC44\\uDC45]|[\\uDC46-\\uDC50](?:\\uD83C[\\uDFFB-\\uDFFF])?|[\\uDC51-\\uDC65]|[\\uDC66\\uDC67](?:\\uD83C[\\uDFFB-\\uDFFF])?|\\uDC68(?:\\u200D(?:[\\u2695\\u2696\\u2708]\\uFE0F?|\\u2764\\uFE0F?\\u200D\\uD83D(?:\\uDC8B\\u200D\\uD83D)?\\uDC68|\\uD83C[\\uDF3E\\uDF73\\uDF7C\\uDF93\\uDFA4\\uDFA8\\uDFEB\\uDFED]|\\uD83D(?:\\uDC66(?:\\u200D\\uD83D\\uDC66)?|\\uDC67(?:\\u200D\\uD83D[\\uDC66\\uDC67])?|[\\uDC68\\uDC69]\\u200D\\uD83D(?:\\uDC66(?:\\u200D\\uD83D\\uDC66)?|\\uDC67(?:\\u200D\\uD83D[\\uDC66\\uDC67])?)|[\\uDCBB\\uDCBC\\uDD27\\uDD2C\\uDE80\\uDE92])|\\uD83E[\\uDDAF-\\uDDB3\\uDDBC\\uDDBD])|\\uD83C(?:\\uDFFB(?:\\u200D(?:[\\u2695\\u2696\\u2708]\\uFE0F?|\\u2764\\uFE0F?\\u200D\\uD83D(?:\\uDC8B\\u200D\\uD83D)?\\uDC68\\uD83C[\\uDFFB-\\uDFFF]|\\uD83C[\\uDF3E\\uDF73\\uDF7C\\uDF93\\uDFA4\\uDFA8\\uDFEB\\uDFED]|\\uD83D[\\uDCBB\\uDCBC\\uDD27\\uDD2C\\uDE80\\uDE92]|\\uD83E(?:\\uDD1D\\u200D\\uD83D\\uDC68\\uD83C[\\uDFFC-\\uDFFF]|[\\uDDAF-\\uDDB3\\uDDBC\\uDDBD])))?|\\uDFFC(?:\\u200D(?:[\\u2695\\u2696\\u2708]\\uFE0F?|\\u2764\\uFE0F?\\u200D\\uD83D(?:\\uDC8B\\u200D\\uD83D)?\\uDC68\\uD83C[\\uDFFB-\\uDFFF]|\\uD83C[\\uDF3E\\uDF73\\uDF7C\\uDF93\\uDFA4\\uDFA8\\uDFEB\\uDFED]|\\uD83D[\\uDCBB\\uDCBC\\uDD27\\uDD2C\\uDE80\\uDE92]|\\uD83E(?:\\uDD1D\\u200D\\uD83D\\uDC68\\uD83C[\\uDFFB\\uDFFD-\\uDFFF]|[\\uDDAF-\\uDDB3\\uDDBC\\uDDBD])))?|\\uDFFD(?:\\u200D(?:[\\u2695\\u2696\\u2708]\\uFE0F?|\\u2764\\uFE0F?\\u200D\\uD83D(?:\\uDC8B\\u200D\\uD83D)?\\uDC68\\uD83C[\\uDFFB-\\uDFFF]|\\uD83C[\\uDF3E\\uDF73\\uDF7C\\uDF93\\uDFA4\\uDFA8\\uDFEB\\uDFED]|\\uD83D[\\uDCBB\\uDCBC\\uDD27\\uDD2C\\uDE80\\uDE92]|\\uD83E(?:\\uDD1D\\u200D\\uD83D\\uDC68\\uD83C[\\uDFFB\\uDFFC\\uDFFE\\uDFFF]|[\\uDDAF-\\uDDB3\\uDDBC\\uDDBD])))?|\\uDFFE(?:\\u200D(?:[\\u2695\\u2696\\u2708]\\uFE0F?|\\u2764\\uFE0F?\\u200D\\uD83D(?:\\uDC8B\\u200D\\uD83D)?\\uDC68\\uD83C[\\uDFFB-\\uDFFF]|\\uD83C[\\uDF3E\\uDF73\\uDF7C\\uDF93\\uDFA4\\uDFA8\\uDFEB\\uDFED]|\\uD83D[\\uDCBB\\uDCBC\\uDD27\\uDD2C\\uDE80\\uDE92]|\\uD83E(?:\\uDD1D\\u200D\\uD83D\\uDC68\\uD83C[\\uDFFB-\\uDFFD\\uDFFF]|[\\uDDAF-\\uDDB3\\uDDBC\\uDDBD])))?|\\uDFFF(?:\\u200D(?:[\\u2695\\u2696\\u2708]\\uFE0F?|\\u2764\\uFE0F?\\u200D\\uD83D(?:\\uDC8B\\u200D\\uD83D)?\\uDC68\\uD83C[\\uDFFB-\\uDFFF]|\\uD83C[\\uDF3E\\uDF73\\uDF7C\\uDF93\\uDFA4\\uDFA8\\uDFEB\\uDFED]|\\uD83D[\\uDCBB\\uDCBC\\uDD27\\uDD2C\\uDE80\\uDE92]|\\uD83E(?:\\uDD1D\\u200D\\uD83D\\uDC68\\uD83C[\\uDFFB-\\uDFFE]|[\\uDDAF-\\uDDB3\\uDDBC\\uDDBD])))?))?|\\uDC69(?:\\u200D(?:[\\u2695\\u2696\\u2708]\\uFE0F?|\\u2764\\uFE0F?\\u200D\\uD83D(?:\\uDC8B\\u200D\\uD83D)?[\\uDC68\\uDC69]|\\uD83C[\\uDF3E\\uDF73\\uDF7C\\uDF93\\uDFA4\\uDFA8\\uDFEB\\uDFED]|\\uD83D(?:\\uDC66(?:\\u200D\\uD83D\\uDC66)?|\\uDC67(?:\\u200D\\uD83D[\\uDC66\\uDC67])?|\\uDC69\\u200D\\uD83D(?:\\uDC66(?:\\u200D\\uD83D\\uDC66)?|\\uDC67(?:\\u200D\\uD83D[\\uDC66\\uDC67])?)|[\\uDCBB\\uDCBC\\uDD27\\uDD2C\\uDE80\\uDE92])|\\uD83E[\\uDDAF-\\uDDB3\\uDDBC\\uDDBD])|\\uD83C(?:\\uDFFB(?:\\u200D(?:[\\u2695\\u2696\\u2708]\\uFE0F?|\\u2764\\uFE0F?\\u200D\\uD83D(?:[\\uDC68\\uDC69]\\uD83C[\\uDFFB-\\uDFFF]|\\uDC8B\\u200D\\uD83D[\\uDC68\\uDC69]\\uD83C[\\uDFFB-\\uDFFF])|\\uD83C[\\uDF3E\\uDF73\\uDF7C\\uDF93\\uDFA4\\uDFA8\\uDFEB\\uDFED]|\\uD83D[\\uDCBB\\uDCBC\\uDD27\\uDD2C\\uDE80\\uDE92]|\\uD83E(?:\\uDD1D\\u200D\\uD83D[\\uDC68\\uDC69]\\uD83C[\\uDFFC-\\uDFFF]|[\\uDDAF-\\uDDB3\\uDDBC\\uDDBD])))?|\\uDFFC(?:\\u200D(?:[\\u2695\\u2696\\u2708]\\uFE0F?|\\u2764\\uFE0F?\\u200D\\uD83D(?:[\\uDC68\\uDC69]\\uD83C[\\uDFFB-\\uDFFF]|\\uDC8B\\u200D\\uD83D[\\uDC68\\uDC69]\\uD83C[\\uDFFB-\\uDFFF])|\\uD83C[\\uDF3E\\uDF73\\uDF7C\\uDF93\\uDFA4\\uDFA8\\uDFEB\\uDFED]|\\uD83D[\\uDCBB\\uDCBC\\uDD27\\uDD2C\\uDE80\\uDE92]|\\uD83E(?:\\uDD1D\\u200D\\uD83D[\\uDC68\\uDC69]\\uD83C[\\uDFFB\\uDFFD-\\uDFFF]|[\\uDDAF-\\uDDB3\\uDDBC\\uDDBD])))?|\\uDFFD(?:\\u200D(?:[\\u2695\\u2696\\u2708]\\uFE0F?|\\u2764\\uFE0F?\\u200D\\uD83D(?:[\\uDC68\\uDC69]\\uD83C[\\uDFFB-\\uDFFF]|\\uDC8B\\u200D\\uD83D[\\uDC68\\uDC69]\\uD83C[\\uDFFB-\\uDFFF])|\\uD83C[\\uDF3E\\uDF73\\uDF7C\\uDF93\\uDFA4\\uDFA8\\uDFEB\\uDFED]|\\uD83D[\\uDCBB\\uDCBC\\uDD27\\uDD2C\\uDE80\\uDE92]|\\uD83E(?:\\uDD1D\\u200D\\uD83D[\\uDC68\\uDC69]\\uD83C[\\uDFFB\\uDFFC\\uDFFE\\uDFFF]|[\\uDDAF-\\uDDB3\\uDDBC\\uDDBD])))?|\\uDFFE(?:\\u200D(?:[\\u2695\\u2696\\u2708]\\uFE0F?|\\u2764\\uFE0F?\\u200D\\uD83D(?:[\\uDC68\\uDC69]\\uD83C[\\uDFFB-\\uDFFF]|\\uDC8B\\u200D\\uD83D[\\uDC68\\uDC69]\\uD83C[\\uDFFB-\\uDFFF])|\\uD83C[\\uDF3E\\uDF73\\uDF7C\\uDF93\\uDFA4\\uDFA8\\uDFEB\\uDFED]|\\uD83D[\\uDCBB\\uDCBC\\uDD27\\uDD2C\\uDE80\\uDE92]|\\uD83E(?:\\uDD1D\\u200D\\uD83D[\\uDC68\\uDC69]\\uD83C[\\uDFFB-\\uDFFD\\uDFFF]|[\\uDDAF-\\uDDB3\\uDDBC\\uDDBD])))?|\\uDFFF(?:\\u200D(?:[\\u2695\\u2696\\u2708]\\uFE0F?|\\u2764\\uFE0F?\\u200D\\uD83D(?:[\\uDC68\\uDC69]\\uD83C[\\uDFFB-\\uDFFF]|\\uDC8B\\u200D\\uD83D[\\uDC68\\uDC69]\\uD83C[\\uDFFB-\\uDFFF])|\\uD83C[\\uDF3E\\uDF73\\uDF7C\\uDF93\\uDFA4\\uDFA8\\uDFEB\\uDFED]|\\uD83D[\\uDCBB\\uDCBC\\uDD27\\uDD2C\\uDE80\\uDE92]|\\uD83E(?:\\uDD1D\\u200D\\uD83D[\\uDC68\\uDC69]\\uD83C[\\uDFFB-\\uDFFE]|[\\uDDAF-\\uDDB3\\uDDBC\\uDDBD])))?))?|\\uDC6A|[\\uDC6B-\\uDC6D](?:\\uD83C[\\uDFFB-\\uDFFF])?|\\uDC6E(?:\\u200D[\\u2640\\u2642]\\uFE0F?|\\uD83C[\\uDFFB-\\uDFFF](?:\\u200D[\\u2640\\u2642]\\uFE0F?)?)?|\\uDC6F(?:\\u200D[\\u2640\\u2642]\\uFE0F?)?|[\\uDC70\\uDC71](?:\\u200D[\\u2640\\u2642]\\uFE0F?|\\uD83C[\\uDFFB-\\uDFFF](?:\\u200D[\\u2640\\u2642]\\uFE0F?)?)?|\\uDC72(?:\\uD83C[\\uDFFB-\\uDFFF])?|\\uDC73(?:\\u200D[\\u2640\\u2642]\\uFE0F?|\\uD83C[\\uDFFB-\\uDFFF](?:\\u200D[\\u2640\\u2642]\\uFE0F?)?)?|[\\uDC74-\\uDC76](?:\\uD83C[\\uDFFB-\\uDFFF])?|\\uDC77(?:\\u200D[\\u2640\\u2642]\\uFE0F?|\\uD83C[\\uDFFB-\\uDFFF](?:\\u200D[\\u2640\\u2642]\\uFE0F?)?)?|\\uDC78(?:\\uD83C[\\uDFFB-\\uDFFF])?|[\\uDC79-\\uDC7B]|\\uDC7C(?:\\uD83C[\\uDFFB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DDE3\\uDDE8\\uDDEF\\uDDF3\\uDDFA]\\uFE0F?|[\\uDDFB-\\uDE2D]|\\uDE2E(?:\\u200D\\uD83D\\uDCA8)?|[\\uDE2F-\\uDE34]|\\uDE35(?:\\u200D\\uD83D\\uDCAB)?|\\uDE36(?:\\u200D\\uD83C\\uDF2B\\uFE0F?)?|[\\uDE37-\\uDE44]|[\\uDE45-\\uDE47](?:\\u200D[\\u2640\\u2642]\\uFE0F?|\\uD83C[\\uDFFB-\\uDFFF](?:\\u200D[\\u2640\\u2642]\\uFE0F?)?)?|[\\uDE48-\\uDE4A]|\\uDE4B(?:\\u200D[\\u2640\\u2642]\\uFE0F?|\\uD83C[\\uDFFB-\\uDFFF](?:\\u200D[\\u2640\\u2642]\\uFE0F?)?)?|\\uDE4C(?:\\uD83C[\\uDFFB-\\uDFFF])?|[\\uDE4D\\uDE4E](?:\\u200D[\\u2640\\u2642]\\uFE0F?|\\uD83C[\\uDFFB-\\uDFFF](?:\\u200D[\\u2640\\u2642]\\uFE0F?)?)?|\\uDE4F(?:\\uD83C[\\uDFFB-\\uDFFF])?|[\\uDE80-\\uDEA2]|\\uDEA3(?:\\u200D[\\u2640\\u2642]\\uFE0F?|\\uD83C[\\uDFFB-\\uDFFF](?:\\u200D[\\u2640\\u2642]\\uFE0F?)?)?|[\\uDEA4-\\uDEB3]|[\\uDEB4-\\uDEB6](?:\\u200D[\\u2640\\u2642]\\uFE0F?|\\uD83C[\\uDFFB-\\uDFFF](?:\\u200D[\\u2640\\u2642]\\uFE0F?)?)?|[\\uDEB7-\\uDEBF]|\\uDEC0(?:\\uD83C[\\uDFFB-\\uDFFF])?|[\\uDEC1-\\uDEC5]|\\uDECB\\uFE0F?|\\uDECC(?:\\uD83C[\\uDFFB-\\uDFFF])?|[\\uDECD-\\uDECF]\\uFE0F?|[\\uDED0-\\uDED2\\uDED5-\\uDED7]|[\\uDEE0-\\uDEE5\\uDEE9]\\uFE0F?|[\\uDEEB\\uDEEC]|[\\uDEF0\\uDEF3]\\uFE0F?|[\\uDEF4-\\uDEFC\\uDFE0-\\uDFEB])|\\uD83E(?:\\uDD0C(?:\\uD83C[\\uDFFB-\\uDFFF])?|[\\uDD0D\\uDD0E]|\\uDD0F(?:\\uD83C[\\uDFFB-\\uDFFF])?|[\\uDD10-\\uDD17]|[\\uDD18-\\uDD1C](?:\\uD83C[\\uDFFB-\\uDFFF])?|\\uDD1D|[\\uDD1E\\uDD1F](?:\\uD83C[\\uDFFB-\\uDFFF])?|[\\uDD20-\\uDD25]|\\uDD26(?:\\u200D[\\u2640\\u2642]\\uFE0F?|\\uD83C[\\uDFFB-\\uDFFF](?:\\u200D[\\u2640\\u2642]\\uFE0F?)?)?|[\\uDD27-\\uDD2F]|[\\uDD30-\\uDD34](?:\\uD83C[\\uDFFB-\\uDFFF])?|\\uDD35(?:\\u200D[\\u2640\\u2642]\\uFE0F?|\\uD83C[\\uDFFB-\\uDFFF](?:\\u200D[\\u2640\\u2642]\\uFE0F?)?)?|\\uDD36(?:\\uD83C[\\uDFFB-\\uDFFF])?|[\\uDD37-\\uDD39](?:\\u200D[\\u2640\\u2642]\\uFE0F?|\\uD83C[\\uDFFB-\\uDFFF](?:\\u200D[\\u2640\\u2642]\\uFE0F?)?)?|\\uDD3A|\\uDD3C(?:\\u200D[\\u2640\\u2642]\\uFE0F?)?|[\\uDD3D\\uDD3E](?:\\u200D[\\u2640\\u2642]\\uFE0F?|\\uD83C[\\uDFFB-\\uDFFF](?:\\u200D[\\u2640\\u2642]\\uFE0F?)?)?|[\\uDD3F-\\uDD45\\uDD47-\\uDD76]|\\uDD77(?:\\uD83C[\\uDFFB-\\uDFFF])?|[\\uDD78\\uDD7A-\\uDDB4]|[\\uDDB5\\uDDB6](?:\\uD83C[\\uDFFB-\\uDFFF])?|\\uDDB7|[\\uDDB8\\uDDB9](?:\\u200D[\\u2640\\u2642]\\uFE0F?|\\uD83C[\\uDFFB-\\uDFFF](?:\\u200D[\\u2640\\u2642]\\uFE0F?)?)?|\\uDDBA|\\uDDBB(?:\\uD83C[\\uDFFB-\\uDFFF])?|[\\uDDBC-\\uDDCB]|[\\uDDCD-\\uDDCF](?:\\u200D[\\u2640\\u2642]\\uFE0F?|\\uD83C[\\uDFFB-\\uDFFF](?:\\u200D[\\u2640\\u2642]\\uFE0F?)?)?|\\uDDD0|\\uDDD1(?:\\u200D(?:[\\u2695\\u2696\\u2708]\\uFE0F?|\\uD83C[\\uDF3E\\uDF73\\uDF7C\\uDF84\\uDF93\\uDFA4\\uDFA8\\uDFEB\\uDFED]|\\uD83D[\\uDCBB\\uDCBC\\uDD27\\uDD2C\\uDE80\\uDE92]|\\uD83E(?:\\uDD1D\\u200D\\uD83E\\uDDD1|[\\uDDAF-\\uDDB3\\uDDBC\\uDDBD]))|\\uD83C(?:\\uDFFB(?:\\u200D(?:[\\u2695\\u2696\\u2708]\\uFE0F?|\\u2764\\uFE0F?\\u200D(?:\\uD83D\\uDC8B\\u200D)?\\uD83E\\uDDD1\\uD83C[\\uDFFC-\\uDFFF]|\\uD83C[\\uDF3E\\uDF73\\uDF7C\\uDF84\\uDF93\\uDFA4\\uDFA8\\uDFEB\\uDFED]|\\uD83D[\\uDCBB\\uDCBC\\uDD27\\uDD2C\\uDE80\\uDE92]|\\uD83E(?:\\uDD1D\\u200D\\uD83E\\uDDD1\\uD83C[\\uDFFB-\\uDFFF]|[\\uDDAF-\\uDDB3\\uDDBC\\uDDBD])))?|\\uDFFC(?:\\u200D(?:[\\u2695\\u2696\\u2708]\\uFE0F?|\\u2764\\uFE0F?\\u200D(?:\\uD83D\\uDC8B\\u200D)?\\uD83E\\uDDD1\\uD83C[\\uDFFB\\uDFFD-\\uDFFF]|\\uD83C[\\uDF3E\\uDF73\\uDF7C\\uDF84\\uDF93\\uDFA4\\uDFA8\\uDFEB\\uDFED]|\\uD83D[\\uDCBB\\uDCBC\\uDD27\\uDD2C\\uDE80\\uDE92]|\\uD83E(?:\\uDD1D\\u200D\\uD83E\\uDDD1\\uD83C[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F]|[\\uDDAF-\\uDDB3\\uDDBC\\uDDBD])))?))?|[\\uDDD2\\uDDD3](?:\\uD83C[\\uDFFB-\\uDFFF])?|\\uDDD4(?:\\u200D[\\u2640\\u2642]\\uFE0F?|\\uD83C[\\uDFFB-\\uDFFF](?:\\u200D[\\u2640\\u2642]\\uFE0F?)?)?|\\uDDD5(?:\\uD83C[\\uDFFB-\\uDFFF])?|[\\uDDD6-\\uDDDD](?:\\u200D[\\u2640\\u2642]\\uFE0F?|\\uD83C[\\uDFFB-\\uDFFF](?:\\u200D[\\u2640\\u2642]\\uFE0F?)?)?|[\\uDDDE\\uDDDF](?:\\u200D[\\u2640\\u2642]\\uFE0F?)?|[\\uDDE0-\\uDDFF\\uDE70-\\uDE74\\uDE78-\\uDE7A\\uDE80-\\uDE86\\uDE90-\\uDEA8\\uDEB0-\\uDEB6\\uDEC0-\\uDEC2\\uDED0-\\uDED6])";
/**for `Tools.getMatchAllResult()`
*/
class MatchResult {
/**the matched string
* @type {string}
*/
value;
/**start index
* @type {number}
*/
start;
/**end index
* @type {number}
*/
end;
constructor(v, s, e){
this.value = v;
this.start = s;
this.end = e;
}
}
class TFIDFValues {
TF;
IDF;
TF_IDF;
constructor(TF){
this.TF = TF;
}
}
/**represents a Point in 1 - 3d space
*/
class Point {
/**@type {number} */
x;
/**@type {number} */
y;
/**@type {number} */
z;
/**@type {number} */
r;
/**theta angle
* @type {number} */
t;
/**unit of `t` **R**adians or **D**egrees
* @type {'r'|'d'}
*/
get unit(){
return this.#_unit;
}
/**dimension that this Point is stored in
* @type {number}
*/
get dimension(){
return this.#_d;
}
#_unit;
#_d = 0;
constructor(x, y, z = null){
this.x = x;
this.y = y;
this.z = z;
if(z) this.#_d = 3;
else if(y) this.#_d = 2;
else if(x) this.#_d = 1;
}
/**Convert from Cartesian to Polar coordinates where **Theta** (t) units is specified by `unit`
* @param {'r'|'d'} [unit='r'] unit of `t` **R**adians or **D**egrees (default to Radians)
*/
toPolarCoords(unit = 'r'){
this.#_unit = unit;
const { r, t } = Tools.MathKit.toPolarCoords(
this.x, this.y, unit
);
this.r = r;
this.t = t;
return this;
}
/**Convert from Polar to Cartesian coordinates
*/
toCartesianCoords(){
if(!this.#_unit&&this.x){
return this;
}
const { x, y } = Tools.MathKit.toCartesianCoords(
this.r, this.t, this.#_unit
);
this.x = x;
this.y = y;
return this;
}
/**set unit of **Theta** (t) and convert its value to reflects the changes
*
* units is specified by `unit`
* @param {'r'|'d'} [unit] unit of `t` **R**adians or **D**egrees (default to Radians)
*/
setUnit(unit){
if(!unit||(unit != 'd'&&unit != 'r')) throw new Error("unit must be 'r' or 'd', given: " + unit);
if(this.#_unit == unit) return;
if(unit == 'r'){
this.#_unit = unit;
this.t = Tools.MathKit.radians(this.t);
}else{
this.#_unit = unit;
this.t = Tools.MathKit.degrees(this.t);
}
}
}
class Dopri {
/**## Dormand-Prince method
*
* a type of Runge-Kutta method used for solving ordinary differential equations (ODEs).
*
* ## This Class is used by `MathKit.dopri()` function.
*
* ## use `Dopri.at()` to get the result of the integration.
*
* @from [npm-numeric](https://github.com/sloisel/numeric/tree/master)
*
* for more info on how the calculation is done, visit [Numerary](https://numerary.readthedocs.io/en/latest/dormand-prince-method.html).
*
* for more info on **Butcher tableau** and the method, visit [Dormand-Prince method Wiki](https://en.wikipedia.org/wiki/Dormand%E2%80%93Prince_method)
*
*/
constructor(x,y,f,ymid,iterations,msg,events) {
this.x = x;
this.y = y;
this.f = f;
this.ymid = ymid;
this.iterations = iterations;
this.events = events;
this.msg = msg;
}
_at(xi, j) {
function sqr(x) { return x * x; }
let x0, x1, xh, y0, y1, yh;
let h;
let p, q, w;
x0 = this.x[j];
x1 = this.x[j + 1];
y0 = this.y[j];
y1 = this.y[j + 1];
h = x1 - x0;
xh = x0 + 0.5 * h;
yh = this.ymid[j];
p = this.f[j] - (y0 * (1 / (x0 - xh) + 2 / (x0 - x1)));
q = this.f[j + 1] - (y1 * (1 / (x1 - xh) + 2 / (x1 - x0)));
w = [
sqr(xi - x1) * (xi - xh) / sqr(x0 - x1) / (x0 - xh),
sqr(xi - x0) * sqr(xi - x1) / sqr(x0 - xh) / sqr(x1 - xh),
sqr(xi - x0) * (xi - xh) / sqr(x1 - x0) / (x1 - xh),
(xi - x0) * sqr(xi - x1) * (xi - xh) / sqr(x0 - x1) / (x0 - xh),
(xi - x1) * sqr(xi - x0) * (xi - xh) / sqr(x0 - x1) / (x1 - xh)
];
return (((y0 * w[0] + yh * w[1]) + y1 * w[2]) + (p * w[3])) + (q * w[4]);
}
/**
* @param {number|number[]} x
* @returns {number|number[]}
*/
at(x) {
let i, j, k;
if (typeof x !== "number") {
let n = x.length, ret = Array(n);
for (i = n - 1; i !== -1; --i) {
ret[i] = this.at(x[i]);
}
return ret;
}
let x0 = this.x;
i = 0; j = x0.length - 1;
while (j - i > 1) {
k = Math.floor(0.5 * (i + j));
if (x0[k] <= x) i = k;
else j = k;
}
return this._at(x, i);
}
}
class ParseArg_Arg {
value;
index;
type;
constructor(value, index = -1, type) {
this.value = value;
this.type = type;
this.index = index;
}
valueOf() {
return this.value;
}
toString() {
return this.value.toString();
}
}
function isWorkerTransferable(obj){
return obj == null
|| typeof obj == 'number'
|| typeof obj == 'string'
|| typeof obj == 'boolean'
|| obj instanceof ArrayBuffer
|| obj instanceof MessagePort
|| obj instanceof ReadableStream
|| obj instanceof WritableStream
|| obj instanceof TransformStream
}
const Tools = {
_modules,
/**
* @typedef {Object} ArrToStringOptions
* @property {number} [maxDepth=4] maximum depth to parse, "depth" represent layers of the array (e.g. depth of 3 is a 3D array)
* @property {number|string} [indent=3] indentation, `number` represent number of spaces, `string` represent the string to use for indentation
* @property {number} [maxRow=10] maximum number of displayable "rows" of each layer
* @property {number} [maxCol=20] maximum number of displayable "columns" of each layer
* @property {boolean} [color=false] enable syntax highlighting
* @property {number|string} [defColor] default color: color used for reseting foreground color,
* without this option will reset all color and formatting
* @property {boolean} [noHeader] disable type heading that shows the type and dimensions of the given array.
*
* this does not affect values inside the array
*/
/**
* parse Array-Like object to string representation of it's values
* with syntax highlighting
*
* @param {any[]|any} arr - Array-Like object
* @param {ArrToStringOptions} [options] - options
* @returns {string} string representation of the array
*/
arrToString(arr, options = {}){
let {
maxDepth = 4,
indent = 3,
maxRow = 10,
maxCol = 20,
color = false,
defColor = undefined,
noHeader = false
} = options;
if(maxDepth < 1) maxDepth = 1;
const yuStringOptions = { color, defColor };
const dim = Tools.getDimensions(arr, 'max');
const dimScanThreshold = dim.length * .4;
const _indent = typeof indent == 'number'? ' '.repeat(indent): indent;
let nccColor = null;
if(color){
nccColor = {
magenta: Tools.ncc(0xb03fba),
gray: Tools.ncc(0x494949),
_default: Tools.ncc(defColor)
};
}
if(!noHeader&&(!(arr instanceof Array)||(dim.length > 2||Math.max(...dim) > 5))){
return getHeaderName(arr) + traverse(arr, 0);
}
else return traverse(arr, 0);
function traverse(arr, depth, indentCount = 0){
let str = '';
if(depth > maxDepth - 1){
if(color) return nccColor.gray + `... [${getArrTypeName(arr) || 'Array'}]` + nccColor._default;
else return `... [${getArrTypeName(arr) || 'Array'}]`;
}
if(!Tools.isArrayLike(arr))
return str + Tools.yuString(arr, yuStringOptions);
let dimIn;
if(depth > dimScanThreshold)
dimIn = Tools.getDimensions(arr, 'max'); // <- resources intensive, use only when needed
else dimIn = dim.slice(depth);
const newLine = dim[depth + 1] != null&&(dimIn[2] != null||dimIn[1] > 2)&&depth < maxDepth - 1;
const indent = indentCount? _indent.repeat(indentCount): '';
const indentIn = indent + _indent;
const LBrack = (newLine ? '[\n' + indentIn: '[');
const RBrack = (newLine ? '\n' + indent + ']': ']');
const arrLen = arr.length;
str += LBrack;
for(let i = 0; i < arrLen; i++){
if(Tools.isArrayLike(arr[i])){
str += getArrTypeName(arr[i]) + traverse(arr[i], depth + 1, newLine? indentCount + 1: indentCount);
}
else str += Tools.yuString(arr[i], yuStringOptions);
if(newLine){
if(i >= maxRow - 2){
str += ',\n' + indentIn;
if(color) str += nccColor.gray + '... (' + (arrLen - maxRow + 1) + ' more)' + nccColor._default;
else str += '... (' + (arrLen - maxRow + 1) + ' more)';
break;
}
}else{
if(i >= maxCol - 2){
if(color) str += ', ' + nccColor.gray + '... (' + (arrLen - maxCol + 1) + ' more)' + nccColor._default;
else str += ', ' + '... (' + (arrLen - maxCol + 1) + ' more)';
break;
}
}
if(i != arrLen - 1) str += newLine? ',\n' + indentIn: ', ';
}
str += RBrack;
return str;
}
function getArrTypeName(arr){
if(arr instanceof Array) return '';
if(color)
return nccColor.magenta + `${arr.constructor.name}: ` + nccColor._default;
else return `${arr.constructor.name}: `;
}
function getHeaderName(arr){
if(!Tools.isArrayLike(arr)) return '';
if(color)
return nccColor.magenta + `${arr.constructor.name}(${dim}): ` + nccColor._default;
else return `${arr.constructor.name}(${dim}): `;
}
},
/**
Check if [`argv`](https://nodejs.org/docs/latest/api/process.html#process_process_argv) has a specific flag.
@from npm package [has-flag](https://www.npmjs.com/package/has-flag)
@param {string} flag
@param {string[]} [argv=process?.argv] arguments Array
@param flag - CLI flag to look for. The `--` prefix is optional.
@param argv - CLI arguments. Default: `process.argv`.
@returns Whether the flag exists.
@example
```
// $ ts-node foo.ts -f --unicorn --foo=bar -- --rainbow
// foo.ts
import { argvHasFlag } from 'Tools';
argvHasFlag('unicorn');
//=> true
argvHasFlag('--unicorn');
//=> true
argvHasFlag('f');
//=> true
argvHasFlag('-f');
//=> true
argvHasFlag('foo=bar');
//=> true
argvHasFlag('foo');
//=> false
argvHasFlag('rainbow');
//=> false
```
*/
argvHasFlag(flag, argv = process?.argv) {
if(!argv||typeof flag != 'string') return false;
const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--');
const position = argv.indexOf(prefix + flag);
const terminatorPosition = argv.indexOf('--');
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
},
/**similar to `sleep()` but this won't block the synchronous thread
* @param {number}milliseconds how long the sleep last in milliseconds
*/
async asyncSleep(milliseconds){
return new Promise((resolve, reject) => {
if(!milliseconds||milliseconds < 0||typeof milliseconds != 'number') resolve();
const date = Date.now();
const checkTime_inter = setInterval(checkTime, 1);
function checkTime(){
if(Date.now() - date >= milliseconds){
clearInterval(checkTime_inter);
resolve();
}
}
});
},
/**format JSON string to make it more human-readable
* ***Waring:* in the current version this function will remove any White-Space in the string which can cause MASSIVE INFORMATION LOSS!!**
* @param {string}JsonString
* @returns {string} the beautified JSON string
*/
beautifyJson(JsonString){
JsonString = JsonString.replace(/\s/, ""); //remove SPACE
let _string = JsonString + "";
let openBrackets = Tools.getMatchAllIndexes(JsonString.matchAll(/[{\[]/g))
.sort((a, b) => a - b);
let closeBrackets = Tools.getMatchAllIndexes(JsonString.matchAll(/[}\]]/g))
.sort((a, b) => a - b);
for(let layer = 0, addedLength = 0, reading = 0; reading < JsonString.length; ){
let nearestOpen = openBrackets[findNearestBrack(openBrackets, reading)];
let nearestClose = closeBrackets[findNearestBrack(closeBrackets, reading)];
nearestOpen = nearestOpen == undefined? Infinity: nearestOpen;
// console.log(nearestClose, nearestOpen);
if(nearestOpen < nearestClose){
layer++;
reading = nearestOpen + 1;
}
else{
layer--;
reading = nearestClose + 1;
}
const nextNearestO = openBrackets[findNearestBrack(openBrackets, reading)];
const nextNearestC = closeBrackets[findNearestBrack(closeBrackets, reading)];
// console.log(nextNearestO);
// console.log(nextNearestC);
const nextNearest = nextNearestO < nextNearestC? nextNearestO: nextNearestC;
const indent = "".padEnd(layer, "\t");
if(isOpenBrack(_string[reading+addedLength-1])){
_string = Tools.strSplice(_string, reading + addedLength, 0, '\n');
}else{
_string = Tools.strSplice(_string, reading + addedLength - 1, 0, '\n');
_string = Tools.strSplice(_string, reading + addedLength, 0, indent);
addedLength += indent.length;
}
addedLength++;
// console.log(`S > "${_string}"`);
//add \n
// console.log(reading, nextNearest);
let isolated = JsonString.substring(reading, nextNearest);
let quoteIndex = Tools.getMatchAllIndexes(isolated.matchAll(/"/g))
.filter(i => i != 0? isolated[i - 1] != "\\": true); //remove index of " that has \ as prefix
if((quoteIndex.length % 2) != 0)
throw new Error("cannot match Double-Quote correctly from string: \"" + isolated + '\"');
let needNewLine = Tools.getMatchAllIndexes(isolated.matchAll(/[,]/g))
.filter(i => {
// remove commas that were inside any of ""
for (let l = 0; l < quoteIndex.length; l += 2)
if (i > quoteIndex[l] && i < quoteIndex[l + 1]) return false;
return true;
});
// const needSpace = Tools.getMatchAllIndexes(isolated.matchAll(/[:]/g))
// .filter(i => {
// // remove commas that were inside any of ""
// for (let l = 0; l < quoteIndex.length; l += 2)
// if (i > quoteIndex[l] && i < quoteIndex[l + 1]) return false;
// return true;
// });
for(let i = 0; i < needNewLine.length + 1; i++){
const writeIndex = i == 0? reading + addedLength: needNewLine[i - 1] + addedLength + reading + 1;
if(isOpenBrack( _string[writeIndex - 1]) == null){
_string = Tools.strSplice(_string, writeIndex, 0, indent);
addedLength += indent.length;
}
if(!_string[(needNewLine[i]) + addedLength + reading]) break; // end of content...
// add \n for each elements
_string = Tools.strSplice(_string, (needNewLine[i] + 1) + addedLength + reading, 0, '\n');
addedLength++;
}
}
return _string;
// Local Functions
function isOpenBrack(str){
const open = new RegExp(/[\{\[]/);
const close = new RegExp(/[}\]]/);
if(open.test(str)) return 1;
if(close.test(str)) return 0;
return null;
}
function findNearestBrack(brackets, reading) {
let shortestGap = Infinity;
let nearestIndex;
for (let i = 0, n = brackets[i]; i < brackets.length; n = brackets[++i]) {
const gap = n - reading;
if (!gap) return i;
if (gap < 0) continue;
if (gap < shortestGap) {
shortestGap = gap;
nearestIndex = i;
}
}
return nearestIndex;
}
},
/**
* call a function before the process exit
* usefull for cleaning up resources before the process exit
* @param {(eventType: 'exit'|'SIGINT'|'SIGUSR1'|'SIGUSR2'|'uncaughtException'|'SIGTERM', ...args: any) => void} callback callback function to call before exit
*/
beforeExit(callback, preventImmediateExit = false){
if(preventImmediateExit)
process.stdin.resume();
let secondSigInt = false;
[`exit`, `SIGINT`, `SIGUSR1`, `SIGUSR2`, `uncaughtException`, `SIGTERM`].forEach((eventType) => {
process.on(eventType, (...args) => {
if([`SIGINT`, `SIGUSR1`, `SIGUSR2`].includes(eventType)){
if(secondSigInt){
console.log('Forcefully Exiting...');
process.exit(1);
} else secondSigInt = true;
}
callback(eventType, ...args);
});
});
},
/**
* change the timezone of the given date object
* @param {Date} date
* @param {string} timezone IANA timezone string see list of timezone from this [wiki](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)
*
* to get the local timezone of the machine, you can use `Intl.DateTimeFormat().resolvedOptions().timeZone`
* @from [stackoverflow](https://stackoverflow.com/a/53652131)
*/
changeDateTimezone(date, timezone) {
// calculate the target date
// (`invdate` will think it's UTC but the actual date will be in the target timezone)
const invdate = new Date(`${date.toLocaleString('en-US', {
timeZone: timezone
})}`);
// so we calculate the time difference between the given `date` and `invdate`
const diff = date.getTime() - invdate.getTime();
// then subtract that difference from the given `date`
// to get the corect date with correct timezone
return new Date(date.getTime() - diff);
},
/**get type of the character at the given index
* @param {number} index
* @param {string} str
*/
charTypeAt(index, str){
const table = Tools.CONSTS.UNICODES_RANGE_TABLE;
if(index < 0) index = str.length + index;
const code = str.charCodeAt(index);
if(isNaN(code)) return null;
for(let i = table.length >> 1, opt = 0; i >= 0&&i < table.length; opt++){
if(opt > (table.length >> 1) + 1) break;
if(Tools.isArrayLike(table[i].to)){
for(let j = 0; j < table[i].to.length; j++){
if(code >= table[i].from[j]&&code <= table[i].to[j]){
return table[i].type;
}
}
if(code > table[i].from[0]) i++;
else i--;
}else{
if(code >= table[i].from&&code <= table[i].to){
return table[i].type;
}
if(code > table[i].from) i++;
else i--;
}
}
return null;
},
CheckCache: class CheckCache {
/**@type {null|boolean} */
static #supportsColor = null;
/**@type {null|boolean} */
static #supportsHyperlink = null;
/**@type {null|boolean} */
static #forceColor = null;
static get supportsColor(){
if(this.#supportsColor == null)
this.#supportsColor = Tools.supportsColor();
return this.#supportsColor;
}
static get supportsHyperlink(){
if(this.#supportsHyperlink == null)
this.#supportsHyperlink = Tools.supportsHyperlink();
return this.#supportsHyperlink;
}
/**@param {null|boolean} value */
static set supportsColor(value){
this.#supportsColor = value;
}
/**@param {null|boolean} value */
static set supportsHyperlink(value){
this.#supportsHyperlink = value;
}
static get forceColor(){
if(!onJSRuntime) this.#forceColor = false;
if(this.#forceColor === undefined){
const env = process.env;
if (
Tools.argvHasFlag('no-color') ||
Tools.argvHasFlag('no-colors') ||
Tools.argvHasFlag('color=false')
) {
this.#forceColor = false;
}
else if (
Tools.argvHasFlag('color') ||
Tools.argvHasFlag('colors') ||
Tools.argvHasFlag('color=true') ||
Tools.argvHasFlag('color=always')
) {
this.#forceColor = true;
}
if ('FORCE_COLOR' in env) {
this.#forceColor = env.FORCE_COLOR.length === 0 || parseInt(env.FORCE_COLOR, 10) !== 0;
}
}
return this.#forceColor;
}
static set forceColor(value){
this.#forceColor = value;
}
},
/**clean array
* @template T
* @param {T[]} arr array to clean
* @param {T|T[]} itemToClean items to wipe off, optional(if None is provide,
* will remove empty string, Array, Object),
* can be array EX: ['0', '', 'g'] (those are Black-Listed items)
* @returns new cleaned array
*/
cleanArr(arr, itemToClean = null){
if(itemToClean && itemToClean instanceof Array){
return arr.filter((itemInArr) => {
return !itemToClean.includes(itemInArr);
});
}
if(itemToClean !== null){
return arr.filter((itemInArr) => {
return itemInArr !== itemToClean;
});
}
return arr.filter(itemInArr =>
(itemInArr !== ''&&itemInArr !== '\r'&&!Tools.isEmptyArray(itemInArr)&&!Tools.isEmptyObject(itemInArr))
);
},
/**
* clean Javascript style Comments from the given string
* @from [stackoverflow](https://stackoverflow.com/a/62945875)
*/
cleanComments(str){
return str.replace(Tools.REGEXP.JSComments, (m, g) => g ? "" : m);
},
/**
* remove terminal controll code from the string (e.g. color, hyperlink)
* @param {string} str
*/
cleanString(str){
return str.normalize().replace(Tools.REGEXP.ANSICode, '');
},
CONSTS: Object.freeze({
/**
* # Unicode range table
* ## Sources
* - japanese: [localizingjapan](https://www.localizingjapan.com/blog/2012/01/20/regular-expressions-for-japanese-text/)
*/
UNICODES_RANGE_TABLE: [
Object.freeze({
type: 'generic.en.upper',
regex: /[\x41-\x5a]/g,
from: 0x41,
to: 0x5a
}),
Object.freeze({
type: 'generic.en.lower',
regex: /[\x61-\x7a]/g,
from: 0x61,
to: 0x7a
}),
Object.freeze({
type: 'generic.jp.full',
regex: /[\u2E80-\u2FD5\u3400-\u4DB5\u4E00-\u9FCB\uF900-\uFA6A\u3000-\u303f\u3041-\u3096\u30a0-\u30ff]/g,
from: new Int16Array([0x2e80, 0x3400, 0x4e00, 0xf900, 0x3000, 0x3041, 0x30a0]),
to: new Int16Array([0x2fd5, 0x4db5, 0x9fcb, 0xfa6a, 0x303f, 0x3096, 0x30ff])
}),
Object.freeze({
type: 'generic.cn.full',
regex: /[\u4e00-\u9fff]/g,
from: 0x4e00,
to: 0x9fff
}),
Object.freeze({
type: 'generic.jp.half',
regex: /[\uff5f-\uff9f]/g,
from: 0xff5f,
to: 0xff9f
}),
],
AsyncFunction: (async () => {}).constructor,
GeneratorFunction: (function* (){}).constructor,
}),
Convert: {
/**Convert Decimal Color Code to RGB
*
* useful for working with literal Hex Color
* @example
* const color = 0xc28cb7; // what's the RGB for this?
* const RGBColor = decimalColorToRGB(color);
* console.log(RGBColor);
* // {r: 194, g:140, b: 183}
* @param {number} decimal Decimal Color Code
*/
decimalColorToRGB(decimal){
return {
r: (decimal >> 16) & 0xff,
g: (decimal >> 8) & 0xff,
b: decimal & 0xff
}
}
},
/**
* mesure the amount of time it takes from the start to the end of the label
* similar to `console.time()` but with more control
*
* **requires JavaScript runtime environment**
*
* @example
* // messure average time in a loop
* for(const match of myString.matchAll(/a/g)){
Tools.ConsoleTime.elipsedStart('push');
indexes.push(match.index);
Tools.ConsoleTime.elipsedEnd('push');
}
Tools.ConsoleTime.condense('push')?.print(); // -> push: 1.23ms
*/
ConsoleTime: class ConsoleTime {
static lookbackLimit = 100;
static elipsedStart(label){
if(_global.consoleTimeInstances == null){
_global.consoleTimeInstances = new Map([
[label, [Tools.getProcessTime()]]
]);
return;
}
if(!_global.consoleTimeInstances.has(label)){
_global.consoleTimeInstances.set(label, [Tools.getProcessTime()]);
return;
}
const elipsed = _global.consoleTimeInstances.get(label);
elipsed.unshift(Tools.getProcessTime());
if(this.lookbackLimit > 0&&elipsed.length >= this.lookbackLimit)
elipsed.pop();
}
static elipsedEnd(label){
if(!_global.consoleTimeInstances.has(label)) return;
const elipsed = _global.consoleTimeInstances.get(label);
const start = elipsed[0];
elipsed[0] = Tools.getProcessTime() - start;
}
static condense(label){
const elipsed = _global.consoleTimeInstances.get(label);
if(!elipsed) return null;
let avg = 0;
for(const eachTime of elipsed){
avg += eachTime;
}
avg /= elipsed.length;
_global.consoleTimeInstances.delete(label);
return {
print(){
console.log(label + ': ' + Tools.toShortNum(avg) + 's');
},
valueOf: () => avg,
toString: () => label + ': ' + Tools.toShortNum(avg) + 's',
value: avg
}
}
},
DataScienceKit: {
/**calculate how many times each unique elements
* appears in the given array
* @template T
* @param {T[]|string} arr
* @returns {Map<T|string, number>} frequency of each unique elements
*/
frequencyOf(arr){
if(!arr||(typeof arr != 'string'&&!Tools.isArrayLike(arr)))
return new Map();
const uniqueElems = [...new Set(arr)];
let fqMap = new Map(
uniqueElems.map(v => [v, 0])
);
for(const eachElem of arr){
uniqueElems.forEach((e, i, a) => {
if(e == eachElem){
fqMap.set(e, fqMap.get(e) + 1);
}
});
}
return fqMap;
},
/**## **Longest Common Subsequence**
*
* return **Longest Common Subsequence** of two string or array
* where each value can be compare with each other;
* this is useful for determining how close those
* Arrays/string are in terms of equality
* @template T_valueA, T_valueB
* @param {string|T_valueA[]} arrA
* @param {string|T_valueB[]} arrB
* @param {(a: T_valueA|string, b: T_valueB|string) => boolean} comparator function that return `true` when the given values is considered Equal
* @returns {T_valueA[]} Longest Common Subsequence from the given arrays
*/
LCS_of(arrA, arrB, comparator = (a, b) => a === b){
if(!(arrA?.length&&arrB?.length)) return [];
/**3d matrix:
* row: representative of strA
* col: representative of strB
* depth: [value, arrowDirection]
* arrowRotation: (1: up (row--), 2: left (col--), 3: up left (row--, col--))
* @type {number[][][]}
*/
let lcsMatrix = [];
const matrixWidth = arrB.length;
const matrixHeight = arrA.length;
while(lcsMatrix.length < matrixHeight) lcsMatrix.push(
new Array(matrixWidth)
);
// fill matrix
for(let row = 0; row < lcsMatrix.length; row++){
for(let col = 0; col < lcsMatrix[row].length; col++){
if(comparator(arrA[row], arrB[col])){
const upLeft_v = getValue(row - 1, col - 1);
lcsMatrix[row][col] = [upLeft_v + 1, 3];
continue;
}
const left_v = getValue(row, col - 1);
const up_v = getValue(row - 1, col);
if(left_v > up_v)
lcsMatrix[row][col] = [left_v, 2];
else lcsMatrix[row][col] = [up_v, 1];
}
}
let lcs = [];