tui-code-snippet.js
117 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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
/*!
* tui-code-snippet.js
* @version 1.5.2
* @author NHN. FE Development Lab <dl_javascript@nhn.com>
* @license MIT
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["util"] = factory();
else
root["tui"] = root["tui"] || {}, root["tui"]["util"] = factory();
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "dist";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
/**
* @fileoverview
* @author NHN.
* FE Development Lab <dl_javascript@nhn.com>
* @namespace tui.util
* @example
* // node, commonjs
* var util = require('tui-code-snippet');
* @example
* // distribution file, script
* <script src='path-to/tui-code-snippt.js'></script>
* <script>
* var util = tui.util;
* <script>
*/
var util = {};
var object = __webpack_require__(1);
var extend = object.extend;
extend(util, object);
extend(util, __webpack_require__(3));
extend(util, __webpack_require__(2));
extend(util, __webpack_require__(4));
extend(util, __webpack_require__(5));
extend(util, __webpack_require__(6));
extend(util, __webpack_require__(7));
extend(util, __webpack_require__(8));
extend(util, __webpack_require__(9));
util.browser = __webpack_require__(10);
util.popup = __webpack_require__(11);
util.formatDate = __webpack_require__(12);
util.defineClass = __webpack_require__(13);
util.defineModule = __webpack_require__(14);
util.defineNamespace = __webpack_require__(15);
util.CustomEvents = __webpack_require__(16);
util.Enum = __webpack_require__(17);
util.ExMap = __webpack_require__(18);
util.HashMap = __webpack_require__(20);
util.Map = __webpack_require__(19);
module.exports = util;
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
/**
* @fileoverview This module has some functions for handling a plain object, json.
* @author NHN.
* FE Development Lab <dl_javascript@nhn.com>
*/
'use strict';
var type = __webpack_require__(2);
var array = __webpack_require__(3);
/**
* The last id of stamp
* @type {number}
* @private
*/
var lastId = 0;
/**
* Extend the target object from other objects.
* @param {object} target - Object that will be extended
* @param {...object} objects - Objects as sources
* @returns {object} Extended object
* @memberof tui.util
*/
function extend(target, objects) { // eslint-disable-line no-unused-vars
var hasOwnProp = Object.prototype.hasOwnProperty;
var source, prop, i, len;
for (i = 1, len = arguments.length; i < len; i += 1) {
source = arguments[i];
for (prop in source) {
if (hasOwnProp.call(source, prop)) {
target[prop] = source[prop];
}
}
}
return target;
}
/**
* Assign a unique id to an object
* @param {object} obj - Object that will be assigned id.
* @returns {number} Stamped id
* @memberof tui.util
*/
function stamp(obj) {
if (!obj.__fe_id) {
lastId += 1;
obj.__fe_id = lastId; // eslint-disable-line camelcase
}
return obj.__fe_id;
}
/**
* Verify whether an object has a stamped id or not.
* @param {object} obj - adjusted object
* @returns {boolean}
* @memberof tui.util
*/
function hasStamp(obj) {
return type.isExisty(pick(obj, '__fe_id'));
}
/**
* Reset the last id of stamp
* @private
*/
function resetLastId() {
lastId = 0;
}
/**
* Return a key-list(array) of a given object
* @param {object} obj - Object from which a key-list will be extracted
* @returns {Array} A key-list(array)
* @memberof tui.util
*/
function keys(obj) {
var keyArray = [];
var key;
for (key in obj) {
if (obj.hasOwnProperty(key)) {
keyArray.push(key);
}
}
return keyArray;
}
/**
* Return the equality for multiple objects(jsonObjects).<br>
* See {@link http://stackoverflow.com/questions/1068834/object-comparison-in-javascript}
* @param {...object} object - Multiple objects for comparing.
* @returns {boolean} Equality
* @memberof tui.util
* @example
* //-- #1. Get Module --//
* var util = require('tui-code-snippet'); // node, commonjs
* var util = tui.util; // distribution file
*
* //-- #2. Use property --//
* var jsonObj1 = {name:'milk', price: 1000};
* var jsonObj2 = {name:'milk', price: 1000};
* var jsonObj3 = {name:'milk', price: 1000};
* util.compareJSON(jsonObj1, jsonObj2, jsonObj3); // true
*
* var jsonObj4 = {name:'milk', price: 1000};
* var jsonObj5 = {name:'beer', price: 3000};
* util.compareJSON(jsonObj4, jsonObj5); // false
*/
function compareJSON(object) {
var argsLen = arguments.length;
var i = 1;
if (argsLen < 1) {
return true;
}
for (; i < argsLen; i += 1) {
if (!isSameObject(object, arguments[i])) {
return false;
}
}
return true;
}
/**
* @param {*} x - object to compare
* @param {*} y - object to compare
* @returns {boolean} - whether object x and y is same or not
* @private
*/
function isSameObject(x, y) { // eslint-disable-line complexity
var leftChain = [];
var rightChain = [];
var p;
// remember that NaN === NaN returns false
// and isNaN(undefined) returns true
if (isNaN(x) &&
isNaN(y) &&
type.isNumber(x) &&
type.isNumber(y)) {
return true;
}
// Compare primitives and functions.
// Check if both arguments link to the same object.
// Especially useful on step when comparing prototypes
if (x === y) {
return true;
}
// Works in case when functions are created in constructor.
// Comparing dates is a common scenario. Another built-ins?
// We can even handle functions passed across iframes
if ((type.isFunction(x) && type.isFunction(y)) ||
(x instanceof Date && y instanceof Date) ||
(x instanceof RegExp && y instanceof RegExp) ||
(x instanceof String && y instanceof String) ||
(x instanceof Number && y instanceof Number)) {
return x.toString() === y.toString();
}
// At last checking prototypes as good a we can
if (!(x instanceof Object && y instanceof Object)) {
return false;
}
if (x.isPrototypeOf(y) ||
y.isPrototypeOf(x) ||
x.constructor !== y.constructor ||
x.prototype !== y.prototype) {
return false;
}
// check for infinitive linking loops
if (array.inArray(x, leftChain) > -1 ||
array.inArray(y, rightChain) > -1) {
return false;
}
// Quick checking of one object beeing a subset of another.
for (p in y) {
if (y.hasOwnProperty(p) !== x.hasOwnProperty(p)) {
return false;
} else if (typeof y[p] !== typeof x[p]) {
return false;
}
}
// This for loop executes comparing with hasOwnProperty() and typeof for each property in 'x' object,
// and verifying equality for x[property] and y[property].
for (p in x) {
if (y.hasOwnProperty(p) !== x.hasOwnProperty(p)) {
return false;
} else if (typeof y[p] !== typeof x[p]) {
return false;
}
if (typeof (x[p]) === 'object' || typeof (x[p]) === 'function') {
leftChain.push(x);
rightChain.push(y);
if (!isSameObject(x[p], y[p])) {
return false;
}
leftChain.pop();
rightChain.pop();
} else if (x[p] !== y[p]) {
return false;
}
}
return true;
}
/* eslint-enable complexity */
/**
* Retrieve a nested item from the given object/array
* @param {object|Array} obj - Object for retrieving
* @param {...string|number} paths - Paths of property
* @returns {*} Value
* @memberof tui.util
* @example
* //-- #1. Get Module --//
* var util = require('tui-code-snippet'); // node, commonjs
* var util = tui.util; // distribution file
*
* //-- #2. Use property --//
* var obj = {
* 'key1': 1,
* 'nested' : {
* 'key1': 11,
* 'nested': {
* 'key1': 21
* }
* }
* };
* util.pick(obj, 'nested', 'nested', 'key1'); // 21
* util.pick(obj, 'nested', 'nested', 'key2'); // undefined
*
* var arr = ['a', 'b', 'c'];
* util.pick(arr, 1); // 'b'
*/
function pick(obj, paths) { // eslint-disable-line no-unused-vars
var args = arguments;
var target = args[0];
var i = 1;
var length = args.length;
for (; i < length; i += 1) {
if (type.isUndefined(target) ||
type.isNull(target)) {
return;
}
target = target[args[i]];
}
return target; // eslint-disable-line consistent-return
}
module.exports = {
extend: extend,
stamp: stamp,
hasStamp: hasStamp,
resetLastId: resetLastId,
keys: Object.prototype.keys || keys,
compareJSON: compareJSON,
pick: pick
};
/***/ }),
/* 2 */
/***/ (function(module, exports) {
/**
* @fileoverview This module provides some functions to check the type of variable
* @author NHN.
* FE Development Lab <dl_javascript@nhn.com>
*/
'use strict';
var toString = Object.prototype.toString;
/**
* Check whether the given variable is existing or not.<br>
* If the given variable is not null and not undefined, returns true.
* @param {*} param - Target for checking
* @returns {boolean} Is existy?
* @memberof tui.util
* @example
* //-- #1. Get Module --//
* var util = require('tui-code-snippet'); // node, commonjs
* var util = tui.util; // distribution file
*
* //-- #2. Use property --//
* util.isExisty(''); //true
* util.isExisty(0); //true
* util.isExisty([]); //true
* util.isExisty({}); //true
* util.isExisty(null); //false
* util.isExisty(undefined); //false
*/
function isExisty(param) {
return !isUndefined(param) && !isNull(param);
}
/**
* Check whether the given variable is undefined or not.<br>
* If the given variable is undefined, returns true.
* @param {*} obj - Target for checking
* @returns {boolean} Is undefined?
* @memberof tui.util
*/
function isUndefined(obj) {
return obj === undefined; // eslint-disable-line no-undefined
}
/**
* Check whether the given variable is null or not.<br>
* If the given variable(arguments[0]) is null, returns true.
* @param {*} obj - Target for checking
* @returns {boolean} Is null?
* @memberof tui.util
*/
function isNull(obj) {
return obj === null;
}
/**
* Check whether the given variable is truthy or not.<br>
* If the given variable is not null or not undefined or not false, returns true.<br>
* (It regards 0 as true)
* @param {*} obj - Target for checking
* @returns {boolean} Is truthy?
* @memberof tui.util
*/
function isTruthy(obj) {
return isExisty(obj) && obj !== false;
}
/**
* Check whether the given variable is falsy or not.<br>
* If the given variable is null or undefined or false, returns true.
* @param {*} obj - Target for checking
* @returns {boolean} Is falsy?
* @memberof tui.util
*/
function isFalsy(obj) {
return !isTruthy(obj);
}
/**
* Check whether the given variable is an arguments object or not.<br>
* If the given variable is an arguments object, return true.
* @param {*} obj - Target for checking
* @returns {boolean} Is arguments?
* @memberof tui.util
*/
function isArguments(obj) {
var result = isExisty(obj) &&
((toString.call(obj) === '[object Arguments]') || !!obj.callee);
return result;
}
/**
* Check whether the given variable is an instance of Array or not.<br>
* If the given variable is an instance of Array, return true.
* @param {*} obj - Target for checking
* @returns {boolean} Is array instance?
* @memberof tui.util
*/
function isArray(obj) {
return obj instanceof Array;
}
/**
* Check whether the given variable is an object or not.<br>
* If the given variable is an object, return true.
* @param {*} obj - Target for checking
* @returns {boolean} Is object?
* @memberof tui.util
*/
function isObject(obj) {
return obj === Object(obj);
}
/**
* Check whether the given variable is a function or not.<br>
* If the given variable is a function, return true.
* @param {*} obj - Target for checking
* @returns {boolean} Is function?
* @memberof tui.util
*/
function isFunction(obj) {
return obj instanceof Function;
}
/**
* Check whether the given variable is a number or not.<br>
* If the given variable is a number, return true.
* @param {*} obj - Target for checking
* @returns {boolean} Is number?
* @memberof tui.util
*/
function isNumber(obj) {
return typeof obj === 'number' || obj instanceof Number;
}
/**
* Check whether the given variable is a string or not.<br>
* If the given variable is a string, return true.
* @param {*} obj - Target for checking
* @returns {boolean} Is string?
* @memberof tui.util
*/
function isString(obj) {
return typeof obj === 'string' || obj instanceof String;
}
/**
* Check whether the given variable is a boolean or not.<br>
* If the given variable is a boolean, return true.
* @param {*} obj - Target for checking
* @returns {boolean} Is boolean?
* @memberof tui.util
*/
function isBoolean(obj) {
return typeof obj === 'boolean' || obj instanceof Boolean;
}
/**
* Check whether the given variable is an instance of Array or not.<br>
* If the given variable is an instance of Array, return true.<br>
* (It is used for multiple frame environments)
* @param {*} obj - Target for checking
* @returns {boolean} Is an instance of array?
* @memberof tui.util
*/
function isArraySafe(obj) {
return toString.call(obj) === '[object Array]';
}
/**
* Check whether the given variable is a function or not.<br>
* If the given variable is a function, return true.<br>
* (It is used for multiple frame environments)
* @param {*} obj - Target for checking
* @returns {boolean} Is a function?
* @memberof tui.util
*/
function isFunctionSafe(obj) {
return toString.call(obj) === '[object Function]';
}
/**
* Check whether the given variable is a number or not.<br>
* If the given variable is a number, return true.<br>
* (It is used for multiple frame environments)
* @param {*} obj - Target for checking
* @returns {boolean} Is a number?
* @memberof tui.util
*/
function isNumberSafe(obj) {
return toString.call(obj) === '[object Number]';
}
/**
* Check whether the given variable is a string or not.<br>
* If the given variable is a string, return true.<br>
* (It is used for multiple frame environments)
* @param {*} obj - Target for checking
* @returns {boolean} Is a string?
* @memberof tui.util
*/
function isStringSafe(obj) {
return toString.call(obj) === '[object String]';
}
/**
* Check whether the given variable is a boolean or not.<br>
* If the given variable is a boolean, return true.<br>
* (It is used for multiple frame environments)
* @param {*} obj - Target for checking
* @returns {boolean} Is a boolean?
* @memberof tui.util
*/
function isBooleanSafe(obj) {
return toString.call(obj) === '[object Boolean]';
}
/**
* Check whether the given variable is a instance of HTMLNode or not.<br>
* If the given variables is a instance of HTMLNode, return true.
* @param {*} html - Target for checking
* @returns {boolean} Is HTMLNode ?
* @memberof tui.util
*/
function isHTMLNode(html) {
if (typeof HTMLElement === 'object') {
return (html && (html instanceof HTMLElement || !!html.nodeType));
}
return !!(html && html.nodeType);
}
/**
* Check whether the given variable is a HTML tag or not.<br>
* If the given variables is a HTML tag, return true.
* @param {*} html - Target for checking
* @returns {Boolean} Is HTML tag?
* @memberof tui.util
*/
function isHTMLTag(html) {
if (typeof HTMLElement === 'object') {
return (html && (html instanceof HTMLElement));
}
return !!(html && html.nodeType && html.nodeType === 1);
}
/**
* Check whether the given variable is empty(null, undefined, or empty array, empty object) or not.<br>
* If the given variables is empty, return true.
* @param {*} obj - Target for checking
* @returns {boolean} Is empty?
* @memberof tui.util
*/
function isEmpty(obj) {
if (!isExisty(obj) || _isEmptyString(obj)) {
return true;
}
if (isArray(obj) || isArguments(obj)) {
return obj.length === 0;
}
if (isObject(obj) && !isFunction(obj)) {
return !_hasOwnProperty(obj);
}
return true;
}
/**
* Check whether given argument is empty string
* @param {*} obj - Target for checking
* @returns {boolean} whether given argument is empty string
* @memberof tui.util
* @private
*/
function _isEmptyString(obj) {
return isString(obj) && obj === '';
}
/**
* Check whether given argument has own property
* @param {Object} obj - Target for checking
* @returns {boolean} - whether given argument has own property
* @memberof tui.util
* @private
*/
function _hasOwnProperty(obj) {
var key;
for (key in obj) {
if (obj.hasOwnProperty(key)) {
return true;
}
}
return false;
}
/**
* Check whether the given variable is not empty
* (not null, not undefined, or not empty array, not empty object) or not.<br>
* If the given variables is not empty, return true.
* @param {*} obj - Target for checking
* @returns {boolean} Is not empty?
* @memberof tui.util
*/
function isNotEmpty(obj) {
return !isEmpty(obj);
}
/**
* Check whether the given variable is an instance of Date or not.<br>
* If the given variables is an instance of Date, return true.
* @param {*} obj - Target for checking
* @returns {boolean} Is an instance of Date?
* @memberof tui.util
*/
function isDate(obj) {
return obj instanceof Date;
}
/**
* Check whether the given variable is an instance of Date or not.<br>
* If the given variables is an instance of Date, return true.<br>
* (It is used for multiple frame environments)
* @param {*} obj - Target for checking
* @returns {boolean} Is an instance of Date?
* @memberof tui.util
*/
function isDateSafe(obj) {
return toString.call(obj) === '[object Date]';
}
module.exports = {
isExisty: isExisty,
isUndefined: isUndefined,
isNull: isNull,
isTruthy: isTruthy,
isFalsy: isFalsy,
isArguments: isArguments,
isArray: isArray,
isArraySafe: isArraySafe,
isObject: isObject,
isFunction: isFunction,
isFunctionSafe: isFunctionSafe,
isNumber: isNumber,
isNumberSafe: isNumberSafe,
isDate: isDate,
isDateSafe: isDateSafe,
isString: isString,
isStringSafe: isStringSafe,
isBoolean: isBoolean,
isBooleanSafe: isBooleanSafe,
isHTMLNode: isHTMLNode,
isHTMLTag: isHTMLTag,
isEmpty: isEmpty,
isNotEmpty: isNotEmpty
};
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
/**
* @fileoverview This module has some functions for handling array.
* @author NHN.
* FE Development Lab <dl_javascript@nhn.com>
*/
'use strict';
var collection = __webpack_require__(4);
var type = __webpack_require__(2);
var aps = Array.prototype.slice;
var util;
/**
* Generate an integer Array containing an arithmetic progression.
* @param {number} start - start index
* @param {number} stop - stop index
* @param {number} step - next visit index = current index + step
* @returns {Array}
* @memberof tui.util
* @example
* //-- #1. Get Module --//
* var util = require('tui-code-snippet'); // node, commonjs
* var util = tui.util; // distribution file
*
* //-- #2. Use property --//
* util.range(5); // [0, 1, 2, 3, 4]
* util.range(1, 5); // [1,2,3,4]
* util.range(2, 10, 2); // [2,4,6,8]
* util.range(10, 2, -2); // [10,8,6,4]
*/
var range = function(start, stop, step) {
var arr = [];
var flag;
if (type.isUndefined(stop)) {
stop = start || 0;
start = 0;
}
step = step || 1;
flag = step < 0 ? -1 : 1;
stop *= flag;
for (; start * flag < stop; start += step) {
arr.push(start);
}
return arr;
};
/* eslint-disable valid-jsdoc */
/**
* Zip together multiple lists into a single array
* @param {...Array}
* @returns {Array}
* @memberof tui.util
* @example
* //-- #1. Get Module --//
* var util = require('tui-code-snippet'); // node, commonjs
* var util = tui.util; // distribution file
*
* //-- #2. Use property --//
* var result = util.zip([1, 2, 3], ['a', 'b','c'], [true, false, true]);
* console.log(result[0]); // [1, 'a', true]
* console.log(result[1]); // [2, 'b', false]
* console.log(result[2]); // [3, 'c', true]
*/
var zip = function() {/* eslint-enable valid-jsdoc */
var arr2d = aps.call(arguments);
var result = [];
collection.forEach(arr2d, function(arr) {
collection.forEach(arr, function(value, index) {
if (!result[index]) {
result[index] = [];
}
result[index].push(value);
});
});
return result;
};
/**
* Returns the first index at which a given element can be found in the array
* from start index(default 0), or -1 if it is not present.<br>
* It compares searchElement to elements of the Array using strict equality
* (the same method used by the ===, or triple-equals, operator).
* @param {*} searchElement Element to locate in the array
* @param {Array} array Array that will be traversed.
* @param {number} startIndex Start index in array for searching (default 0)
* @returns {number} the First index at which a given element, or -1 if it is not present
* @memberof tui.util
* @example
* //-- #1. Get Module --//
* var util = require('tui-code-snippet'); // node, commonjs
* var util = tui.util; // distribution file
*
* //-- #2. Use property --//
* var arr = ['one', 'two', 'three', 'four'];
* var idx1 = util.inArray('one', arr, 3); // -1
* var idx2 = util.inArray('one', arr); // 0
*/
var inArray = function(searchElement, array, startIndex) {
var i;
var length;
startIndex = startIndex || 0;
if (!type.isArray(array)) {
return -1;
}
if (Array.prototype.indexOf) {
return Array.prototype.indexOf.call(array, searchElement, startIndex);
}
length = array.length;
for (i = startIndex; startIndex >= 0 && i < length; i += 1) {
if (array[i] === searchElement) {
return i;
}
}
return -1;
};
util = {
inArray: inArray,
range: range,
zip: zip
};
module.exports = util;
/***/ }),
/* 4 */
/***/ (function(module, exports, __webpack_require__) {
/**
* @fileoverview This module has some functions for handling object as collection.
* @author NHN.
* FE Development Lab <dl_javascript@nhn.com>
*/
'use strict';
var type = __webpack_require__(2);
var object = __webpack_require__(1);
/**
* Execute the provided callback once for each element present
* in the array(or Array-like object) in ascending order.<br>
* If the callback function returns false, the loop will be stopped.<br>
* Callback function(iteratee) is invoked with three arguments:
* - The value of the element
* - The index of the element
* - The array(or Array-like object) being traversed
* @param {Array} arr The array(or Array-like object) that will be traversed
* @param {function} iteratee Callback function
* @param {Object} [context] Context(this) of callback function
* @memberof tui.util
* @example
* //-- #1. Get Module --//
* var util = require('tui-code-snippet'); // node, commonjs
* var util = tui.util; // distribution file
*
* //-- #2. Use property --//
* var sum = 0;
*
* util.forEachArray([1,2,3], function(value){
* sum += value;
* });
* alert(sum); // 6
*/
function forEachArray(arr, iteratee, context) {
var index = 0;
var len = arr.length;
context = context || null;
for (; index < len; index += 1) {
if (iteratee.call(context, arr[index], index, arr) === false) {
break;
}
}
}
/**
* Execute the provided callback once for each property of object which actually exist.<br>
* If the callback function returns false, the loop will be stopped.<br>
* Callback function(iteratee) is invoked with three arguments:
* - The value of the property
* - The name of the property
* - The object being traversed
* @param {Object} obj The object that will be traversed
* @param {function} iteratee Callback function
* @param {Object} [context] Context(this) of callback function
* @memberof tui.util
* @example
* //-- #1. Get Module --//
* var util = require('tui-code-snippet'); // node, commonjs
* var util = tui.util; // distribution file
*
* //-- #2. Use property --//
* var sum = 0;
*
* util.forEachOwnProperties({a:1,b:2,c:3}, function(value){
* sum += value;
* });
* alert(sum); // 6
**/
function forEachOwnProperties(obj, iteratee, context) {
var key;
context = context || null;
for (key in obj) {
if (obj.hasOwnProperty(key)) {
if (iteratee.call(context, obj[key], key, obj) === false) {
break;
}
}
}
}
/**
* Execute the provided callback once for each property of object(or element of array) which actually exist.<br>
* If the object is Array-like object(ex-arguments object), It needs to transform to Array.(see 'ex2' of example).<br>
* If the callback function returns false, the loop will be stopped.<br>
* Callback function(iteratee) is invoked with three arguments:
* - The value of the property(or The value of the element)
* - The name of the property(or The index of the element)
* - The object being traversed
* @param {Object} obj The object that will be traversed
* @param {function} iteratee Callback function
* @param {Object} [context] Context(this) of callback function
* @memberof tui.util
* @example
* //-- #1. Get Module --//
* var util = require('tui-code-snippet'); // node, commonjs
* var util = tui.util; // distribution file
*
* //-- #2. Use property --//
* var sum = 0;
*
* util.forEach([1,2,3], function(value){
* sum += value;
* });
* alert(sum); // 6
*
* // In case of Array-like object
* var array = Array.prototype.slice.call(arrayLike); // change to array
* util.forEach(array, function(value){
* sum += value;
* });
*/
function forEach(obj, iteratee, context) {
if (type.isArray(obj)) {
forEachArray(obj, iteratee, context);
} else {
forEachOwnProperties(obj, iteratee, context);
}
}
/**
* Execute the provided callback function once for each element in an array, in order,
* and constructs a new array from the results.<br>
* If the object is Array-like object(ex-arguments object),
* It needs to transform to Array.(see 'ex2' of forEach example)<br>
* Callback function(iteratee) is invoked with three arguments:
* - The value of the property(or The value of the element)
* - The name of the property(or The index of the element)
* - The object being traversed
* @param {Object} obj The object that will be traversed
* @param {function} iteratee Callback function
* @param {Object} [context] Context(this) of callback function
* @returns {Array} A new array composed of returned values from callback function
* @memberof tui.util
* @example
* //-- #1. Get Module --//
* var util = require('tui-code-snippet'); // node, commonjs
* var util = tui.util; // distribution file
*
* //-- #2. Use property --//
* var result = util.map([0,1,2,3], function(value) {
* return value + 1;
* });
*
* alert(result); // 1,2,3,4
*/
function map(obj, iteratee, context) {
var resultArray = [];
context = context || null;
forEach(obj, function() {
resultArray.push(iteratee.apply(context, arguments));
});
return resultArray;
}
/**
* Execute the callback function once for each element present in the array(or Array-like object or plain object).<br>
* If the object is Array-like object(ex-arguments object),
* It needs to transform to Array.(see 'ex2' of forEach example)<br>
* Callback function(iteratee) is invoked with four arguments:
* - The previousValue
* - The currentValue
* - The index
* - The object being traversed
* @param {Object} obj The object that will be traversed
* @param {function} iteratee Callback function
* @param {Object} [context] Context(this) of callback function
* @returns {*} The result value
* @memberof tui.util
* @example
* //-- #1. Get Module --//
* var util = require('tui-code-snippet'); // node, commonjs
* var util = tui.util; // distribution file
*
* //-- #2. Use property --//
* var result = util.reduce([0,1,2,3], function(stored, value) {
* return stored + value;
* });
*
* alert(result); // 6
*/
function reduce(obj, iteratee, context) {
var index = 0;
var keys, length, store;
context = context || null;
if (!type.isArray(obj)) {
keys = object.keys(obj);
length = keys.length;
store = obj[keys[index += 1]];
} else {
length = obj.length;
store = obj[index];
}
index += 1;
for (; index < length; index += 1) {
store = iteratee.call(context, store, obj[keys ? keys[index] : index]);
}
return store;
}
/**
* Transform the Array-like object to Array.<br>
* In low IE (below 8), Array.prototype.slice.call is not perfect. So, try-catch statement is used.
* @param {*} arrayLike Array-like object
* @returns {Array} Array
* @memberof tui.util
* @example
* //-- #1. Get Module --//
* var util = require('tui-code-snippet'); // node, commonjs
* var util = tui.util; // distribution file
*
* //-- #2. Use property --//
* var arrayLike = {
* 0: 'one',
* 1: 'two',
* 2: 'three',
* 3: 'four',
* length: 4
* };
* var result = util.toArray(arrayLike);
*
* alert(result instanceof Array); // true
* alert(result); // one,two,three,four
*/
function toArray(arrayLike) {
var arr;
try {
arr = Array.prototype.slice.call(arrayLike);
} catch (e) {
arr = [];
forEachArray(arrayLike, function(value) {
arr.push(value);
});
}
return arr;
}
/**
* Create a new array or plain object with all elements(or properties)
* that pass the test implemented by the provided function.<br>
* Callback function(iteratee) is invoked with three arguments:
* - The value of the property(or The value of the element)
* - The name of the property(or The index of the element)
* - The object being traversed
* @param {Object} obj Object(plain object or Array) that will be traversed
* @param {function} iteratee Callback function
* @param {Object} [context] Context(this) of callback function
* @returns {Object} plain object or Array
* @memberof tui.util
* @example
* //-- #1. Get Module --//
* var util = require('tui-code-snippet'); // node, commonjs
* var util = tui.util; // distribution file
*
* //-- #2. Use property --//
* var result1 = util.filter([0,1,2,3], function(value) {
* return (value % 2 === 0);
* });
* alert(result1); // [0, 2]
*
* var result2 = util.filter({a : 1, b: 2, c: 3}, function(value) {
* return (value % 2 !== 0);
* });
* alert(result2.a); // 1
* alert(result2.b); // undefined
* alert(result2.c); // 3
*/
function filter(obj, iteratee, context) {
var result, add;
context = context || null;
if (!type.isObject(obj) || !type.isFunction(iteratee)) {
throw new Error('wrong parameter');
}
if (type.isArray(obj)) {
result = [];
add = function(subResult, args) {
subResult.push(args[0]);
};
} else {
result = {};
add = function(subResult, args) {
subResult[args[1]] = args[0];
};
}
forEach(obj, function() {
if (iteratee.apply(context, arguments)) {
add(result, arguments);
}
}, context);
return result;
}
/**
* fetching a property
* @param {Array} arr target collection
* @param {String|Number} property property name
* @returns {Array}
* @memberof tui.util
* @example
* //-- #1. Get Module --//
* var util = require('tui-code-snippet'); // node, commonjs
* var util = tui.util; // distribution file
*
* //-- #2. Use property --//
* var objArr = [
* {'abc': 1, 'def': 2, 'ghi': 3},
* {'abc': 4, 'def': 5, 'ghi': 6},
* {'abc': 7, 'def': 8, 'ghi': 9}
* ];
* var arr2d = [
* [1, 2, 3],
* [4, 5, 6],
* [7, 8, 9]
* ];
* util.pluck(objArr, 'abc'); // [1, 4, 7]
* util.pluck(arr2d, 2); // [3, 6, 9]
*/
function pluck(arr, property) {
var result = map(arr, function(item) {
return item[property];
});
return result;
}
module.exports = {
forEachOwnProperties: forEachOwnProperties,
forEachArray: forEachArray,
forEach: forEach,
toArray: toArray,
map: map,
reduce: reduce,
filter: filter,
pluck: pluck
};
/***/ }),
/* 5 */
/***/ (function(module, exports) {
/**
* @fileoverview This module provides a bind() function for context binding.
* @author NHN.
* FE Development Lab <dl_javascript@nhn.com>
*/
'use strict';
/**
* Create a new function that, when called, has its this keyword set to the provided value.
* @param {function} fn A original function before binding
* @param {*} obj context of function in arguments[0]
* @returns {function()} A new bound function with context that is in arguments[1]
* @memberof tui.util
*/
function bind(fn, obj) {
var slice = Array.prototype.slice;
var args;
if (fn.bind) {
return fn.bind.apply(fn, slice.call(arguments, 1));
}
/* istanbul ignore next */
args = slice.call(arguments, 2);
/* istanbul ignore next */
return function() {
/* istanbul ignore next */
return fn.apply(obj, args.length ? args.concat(slice.call(arguments)) : arguments);
};
}
module.exports = {
bind: bind
};
/***/ }),
/* 6 */
/***/ (function(module, exports) {
/**
* @fileoverview This module provides some simple function for inheritance.
* @author NHN.
* FE Development Lab <dl_javascript@nhn.com>
*/
'use strict';
/**
* Create a new object with the specified prototype object and properties.
* @param {Object} obj This object will be a prototype of the newly-created object.
* @returns {Object}
* @memberof tui.util
*/
function createObject(obj) {
function F() {} // eslint-disable-line require-jsdoc
F.prototype = obj;
return new F();
}
/**
* Provide a simple inheritance in prototype-oriented.<br>
* Caution :
* Don't overwrite the prototype of child constructor.
*
* @param {function} subType Child constructor
* @param {function} superType Parent constructor
* @memberof tui.util
* @example
* //-- #1. Get Module --//
* var util = require('tui-code-snippet'); // node, commonjs
* var util = tui.util; // distribution file
*
* //-- #2. Use property --//
* // Parent constructor
* function Animal(leg) {
* this.leg = leg;
* }
* Animal.prototype.growl = function() {
* // ...
* };
*
* // Child constructor
* function Person(name) {
* this.name = name;
* }
*
* // Inheritance
* util.inherit(Person, Animal);
*
* // After this inheritance, please use only the extending of property.
* // Do not overwrite prototype.
* Person.prototype.walk = function(direction) {
* // ...
* };
*/
function inherit(subType, superType) {
var prototype = createObject(superType.prototype);
prototype.constructor = subType;
subType.prototype = prototype;
}
module.exports = {
createObject: createObject,
inherit: inherit
};
/***/ }),
/* 7 */
/***/ (function(module, exports, __webpack_require__) {
/**
* @fileoverview This module has some functions for handling the string.
* @author NHN.
* FE Development Lab <dl_javascript@nhn.com>
*/
'use strict';
var collection = __webpack_require__(4);
var object = __webpack_require__(1);
/**
* Transform the given HTML Entity string into plain string
* @param {String} htmlEntity - HTML Entity type string
* @returns {String} Plain string
* @memberof tui.util
* @example
* //-- #1. Get Module --//
* var util = require('tui-code-snippet'); // node, commonjs
* var util = tui.util; // distribution file
*
* //-- #2. Use property --//
* var htmlEntityString = "A 'quote' is <b>bold</b>"
* var result = util.decodeHTMLEntity(htmlEntityString); //"A 'quote' is <b>bold</b>"
*/
function decodeHTMLEntity(htmlEntity) {
var entities = {
'"': '"',
'&': '&',
'<': '<',
'>': '>',
''': '\'',
' ': ' '
};
return htmlEntity.replace(/&|<|>|"|'| /g, function(m0) {
return entities[m0] ? entities[m0] : m0;
});
}
/**
* Transform the given string into HTML Entity string
* @param {String} html - String for encoding
* @returns {String} HTML Entity
* @memberof tui.util
* @example
* //-- #1. Get Module --//
* var util = require('tui-code-snippet'); // node, commonjs
* var util = tui.util; // distribution file
*
* //-- #2. Use property --//
* var htmlEntityString = "<script> alert('test');</script><a href='test'>";
* var result = util.encodeHTMLEntity(htmlEntityString);
* //"<script> alert('test');</script><a href='test'>"
*/
function encodeHTMLEntity(html) {
var entities = {
'"': 'quot',
'&': 'amp',
'<': 'lt',
'>': 'gt',
'\'': '#39'
};
return html.replace(/[<>&"']/g, function(m0) {
return entities[m0] ? '&' + entities[m0] + ';' : m0;
});
}
/**
* Return whether the string capable to transform into plain string is in the given string or not.
* @param {String} string - test string
* @memberof tui.util
* @returns {boolean}
*/
function hasEncodableString(string) {
return (/[<>&"']/).test(string);
}
/**
* Return duplicate charters
* @param {string} operandStr1 The operand string
* @param {string} operandStr2 The operand string
* @private
* @memberof tui.util
* @returns {string}
* @example
* //-- #1. Get Module --//
* var util = require('tui-code-snippet'); // node, commonjs
* var util = tui.util; // distribution file
*
* //-- #2. Use property --//
* util.getDuplicatedChar('fe dev', 'nhn entertainment'); // 'e'
* util.getDuplicatedChar('fdsa', 'asdf'); // 'asdf'
*/
function getDuplicatedChar(operandStr1, operandStr2) {
var i = 0;
var len = operandStr1.length;
var pool = {};
var dupl, key;
for (; i < len; i += 1) {
key = operandStr1.charAt(i);
pool[key] = 1;
}
for (i = 0, len = operandStr2.length; i < len; i += 1) {
key = operandStr2.charAt(i);
if (pool[key]) {
pool[key] += 1;
}
}
pool = collection.filter(pool, function(item) {
return item > 1;
});
pool = object.keys(pool).sort();
dupl = pool.join('');
return dupl;
}
module.exports = {
decodeHTMLEntity: decodeHTMLEntity,
encodeHTMLEntity: encodeHTMLEntity,
hasEncodableString: hasEncodableString,
getDuplicatedChar: getDuplicatedChar
};
/***/ }),
/* 8 */
/***/ (function(module, exports) {
/**
* @fileoverview collections of some technic methods.
* @author NHN.
* FE Development Lab <dl_javascript.nhn.com>
*/
'use strict';
var tricks = {};
var aps = Array.prototype.slice;
/**
* Creates a debounced function that delays invoking fn until after delay milliseconds has elapsed
* since the last time the debouced function was invoked.
* @param {function} fn The function to debounce.
* @param {number} [delay=0] The number of milliseconds to delay
* @memberof tui.util
* @returns {function} debounced function.
* @example
* //-- #1. Get Module --//
* var util = require('tui-code-snippet'); // node, commonjs
* var util = tui.util; // distribution file
*
* //-- #2. Use property --//
* function someMethodToInvokeDebounced() {}
*
* var debounced = util.debounce(someMethodToInvokeDebounced, 300);
*
* // invoke repeatedly
* debounced();
* debounced();
* debounced();
* debounced();
* debounced();
* debounced(); // last invoke of debounced()
*
* // invoke someMethodToInvokeDebounced() after 300 milliseconds.
*/
function debounce(fn, delay) {
var timer, args;
/* istanbul ignore next */
delay = delay || 0;
function debounced() { // eslint-disable-line require-jsdoc
args = aps.call(arguments);
window.clearTimeout(timer);
timer = window.setTimeout(function() {
fn.apply(null, args);
}, delay);
}
return debounced;
}
/**
* return timestamp
* @memberof tui.util
* @returns {number} The number of milliseconds from Jan. 1970 00:00:00 (GMT)
*/
function timestamp() {
return Number(new Date());
}
/**
* Creates a throttled function that only invokes fn at most once per every interval milliseconds.
*
* You can use this throttle short time repeatedly invoking functions. (e.g MouseMove, Resize ...)
*
* if you need reuse throttled method. you must remove slugs (e.g. flag variable) related with throttling.
* @param {function} fn function to throttle
* @param {number} [interval=0] the number of milliseconds to throttle invocations to.
* @memberof tui.util
* @returns {function} throttled function
* @example
* //-- #1. Get Module --//
* var util = require('tui-code-snippet'); // node, commonjs
* var util = tui.util; // distribution file
*
* //-- #2. Use property --//
* function someMethodToInvokeThrottled() {}
*
* var throttled = util.throttle(someMethodToInvokeThrottled, 300);
*
* // invoke repeatedly
* throttled(); // invoke (leading)
* throttled();
* throttled(); // invoke (near 300 milliseconds)
* throttled();
* throttled();
* throttled(); // invoke (near 600 milliseconds)
* // ...
* // invoke (trailing)
*
* // if you need reuse throttled method. then invoke reset()
* throttled.reset();
*/
function throttle(fn, interval) {
var base;
var isLeading = true;
var tick = function(_args) {
fn.apply(null, _args);
base = null;
};
var debounced, stamp, args;
/* istanbul ignore next */
interval = interval || 0;
debounced = tricks.debounce(tick, interval);
function throttled() { // eslint-disable-line require-jsdoc
args = aps.call(arguments);
if (isLeading) {
tick(args);
isLeading = false;
return;
}
stamp = tricks.timestamp();
base = base || stamp;
// pass array directly because `debounce()`, `tick()` are already use
// `apply()` method to invoke developer's `fn` handler.
//
// also, this `debounced` line invoked every time for implements
// `trailing` features.
debounced(args);
if ((stamp - base) >= interval) {
tick(args);
}
}
function reset() { // eslint-disable-line require-jsdoc
isLeading = true;
base = null;
}
throttled.reset = reset;
return throttled;
}
tricks.timestamp = timestamp;
tricks.debounce = debounce;
tricks.throttle = throttle;
module.exports = tricks;
/***/ }),
/* 9 */
/***/ (function(module, exports, __webpack_require__) {
/**
* @fileoverview This module has some functions for handling object as collection.
* @author NHN.
* FE Development Lab <dl_javascript@nhn.com>
*/
'use strict';
var object = __webpack_require__(1);
var collection = __webpack_require__(4);
var type = __webpack_require__(2);
var ms7days = 7 * 24 * 60 * 60 * 1000;
/**
* Check if the date has passed 7 days
* @param {number} date - milliseconds
* @returns {boolean}
* @ignore
*/
function isExpired(date) {
var now = new Date().getTime();
return now - date > ms7days;
}
/**
* Send hostname on DOMContentLoaded.
* To prevent hostname set tui.usageStatistics to false.
* @param {string} appName - application name
* @param {string} trackingId - GA tracking ID
* @ignore
*/
function sendHostname(appName, trackingId) {
var url = 'https://www.google-analytics.com/collect';
var hostname = location.hostname;
var hitType = 'event';
var eventCategory = 'use';
var applicationKeyForStorage = 'TOAST UI ' + appName + ' for ' + hostname + ': Statistics';
var date = window.localStorage.getItem(applicationKeyForStorage);
// skip if the flag is defined and is set to false explicitly
if (!type.isUndefined(window.tui) && window.tui.usageStatistics === false) {
return;
}
// skip if not pass seven days old
if (date && !isExpired(date)) {
return;
}
window.localStorage.setItem(applicationKeyForStorage, new Date().getTime());
setTimeout(function() {
if (document.readyState === 'interactive' || document.readyState === 'complete') {
imagePing(url, {
v: 1,
t: hitType,
tid: trackingId,
cid: hostname,
dp: hostname,
dh: appName,
el: appName,
ec: eventCategory
});
}
}, 1000);
}
/**
* Request image ping.
* @param {String} url url for ping request
* @param {Object} trackingInfo infos for make query string
* @returns {HTMLElement}
* @memberof tui.util
* @example
* //-- #1. Get Module --//
* var util = require('tui-code-snippet'); // node, commonjs
* var util = tui.util; // distribution file
*
* //-- #2. Use property --//
* util.imagePing('https://www.google-analytics.com/collect', {
* v: 1,
* t: 'event',
* tid: 'trackingid',
* cid: 'cid',
* dp: 'dp',
* dh: 'dh'
* });
*/
function imagePing(url, trackingInfo) {
var queryString = collection.map(object.keys(trackingInfo), function(key, index) {
var startWith = index === 0 ? '' : '&';
return startWith + key + '=' + trackingInfo[key];
}).join('');
var trackingElement = document.createElement('img');
trackingElement.src = url + '?' + queryString;
trackingElement.style.display = 'none';
document.body.appendChild(trackingElement);
document.body.removeChild(trackingElement);
return trackingElement;
}
module.exports = {
imagePing: imagePing,
sendHostname: sendHostname
};
/***/ }),
/* 10 */
/***/ (function(module, exports) {
/**
* @fileoverview This module detects the kind of well-known browser and version.
* @author NHN.
* FE Development Lab <dl_javascript@nhn.com>
*/
'use strict';
/**
* This object has an information that indicate the kind of browser.<br>
* The list below is a detectable browser list.
* - ie8 ~ ie11
* - chrome
* - firefox
* - safari
* - edge
* @memberof tui.util
* @example
* //-- #1. Get Module --//
* var util = require('tui-code-snippet'); // node, commonjs
* var util = tui.util; // distribution file
*
* //-- #2. Use property --//
* util.browser.chrome === true; // chrome
* util.browser.firefox === true; // firefox
* util.browser.safari === true; // safari
* util.browser.msie === true; // IE
* util.browser.edge === true; // edge
* util.browser.others === true; // other browser
* util.browser.version; // browser version
*/
var browser = {
chrome: false,
firefox: false,
safari: false,
msie: false,
edge: false,
others: false,
version: 0
};
if (window && window.navigator) {
detectBrowser();
}
/**
* Detect the browser.
* @private
*/
function detectBrowser() {
var nav = window.navigator;
var appName = nav.appName.replace(/\s/g, '_');
var userAgent = nav.userAgent;
var rIE = /MSIE\s([0-9]+[.0-9]*)/;
var rIE11 = /Trident.*rv:11\./;
var rEdge = /Edge\/(\d+)\./;
var versionRegex = {
firefox: /Firefox\/(\d+)\./,
chrome: /Chrome\/(\d+)\./,
safari: /Version\/([\d.]+).*Safari\/(\d+)/
};
var key, tmp;
var detector = {
Microsoft_Internet_Explorer: function() { // eslint-disable-line camelcase
var detectedVersion = userAgent.match(rIE);
if (detectedVersion) { // ie8 ~ ie10
browser.msie = true;
browser.version = parseFloat(detectedVersion[1]);
} else { // no version information
browser.others = true;
}
},
Netscape: function() { // eslint-disable-line complexity
var detected = false;
if (rIE11.exec(userAgent)) {
browser.msie = true;
browser.version = 11;
detected = true;
} else if (rEdge.exec(userAgent)) {
browser.edge = true;
browser.version = userAgent.match(rEdge)[1];
detected = true;
} else {
for (key in versionRegex) {
if (versionRegex.hasOwnProperty(key)) {
tmp = userAgent.match(versionRegex[key]);
if (tmp && tmp.length > 1) { // eslint-disable-line max-depth
browser[key] = detected = true;
browser.version = parseFloat(tmp[1] || 0);
break;
}
}
}
}
if (!detected) {
browser.others = true;
}
}
};
var fn = detector[appName];
if (fn) {
detector[appName]();
}
}
module.exports = browser;
/***/ }),
/* 11 */
/***/ (function(module, exports, __webpack_require__) {
/**
* @fileoverview This module has some methods for handling popup-window
* @author NHN.
* FE Development Lab <dl_javascript@nhn.com>
*/
'use strict';
var collection = __webpack_require__(4);
var type = __webpack_require__(2);
var func = __webpack_require__(5);
var browser = __webpack_require__(10);
var object = __webpack_require__(1);
var popupId = 0;
/**
* Popup management class
* @constructor
* @memberof tui.util
* @example
* // node, commonjs
* var popup = require('tui-code-snippet').popup;
* @example
* // distribution file, script
* <script src='path-to/tui-code-snippt.js'></script>
* <script>
* var popup = tui.util.popup;
* <script>
*/
function Popup() {
/**
* Caching the window-contexts of opened popups
* @type {Object}
*/
this.openedPopup = {};
/**
* In IE7, an error occurs when the closeWithParent property attaches to window object.<br>
* So, It is for saving the value of closeWithParent instead of attaching to window object.
* @type {Object}
*/
this.closeWithParentPopup = {};
/**
* Post data bridge for IE11 popup
* @type {string}
*/
this.postBridgeUrl = '';
}
/**********
* public methods
**********/
/**
* Returns a popup-list administered by current window.
* @param {string} [key] The key of popup.
* @returns {Object} popup window list object
*/
Popup.prototype.getPopupList = function(key) {
var target;
if (type.isExisty(key)) {
target = this.openedPopup[key];
} else {
target = this.openedPopup;
}
return target;
};
/**
* Open popup
* Caution:
* In IE11, when transfer data to popup by POST, must set the postBridgeUrl.
*
* @param {string} url - popup url
* @param {Object} options - popup options
* @param {string} [options.popupName] - Key of popup window.<br>
* If the key is set, when you try to open by this key, the popup of this key is focused.<br>
* Or else a new popup window having this key is opened.
*
* @param {string} [options.popupOptionStr=""] - Option string of popup window<br>
* It is same with the third parameter of window.open() method.<br>
* See {@link http://www.w3schools.com/jsref/met_win_open.asp}
*
* @param {boolean} [options.closeWithParent=true] - Is closed when parent window closed?
*
* @param {boolean} [options.useReload=false] - This property indicates whether reload the popup or not.<br>
* If true, the popup will be reloaded when you try to re-open the popup that has been opened.<br>
* When transmit the POST-data, some browsers alert a message for confirming whether retransmit or not.
*
* @param {string} [options.postBridgeUrl='']
* Use this url to avoid a certain bug occuring when transmitting POST data to the popup in IE11.<br>
* This specific buggy situation is known to happen because IE11 tries to open the requested url<br>
* not in a new popup window as intended, but in a new tab.<br>
* See {@link http://wiki.nhnent.com/pages/viewpage.action?pageId=240562844}
*
* @param {string} [options.method=get]
* The method of transmission when the form-data is transmitted to popup-window.
*
* @param {Object} [options.param=null]
* Using as parameters for transmission when the form-data is transmitted to popup-window.
*/
Popup.prototype.openPopup = function(url, options) { // eslint-disable-line complexity
var popup, formElement, useIEPostBridge;
options = object.extend({
popupName: 'popup_' + popupId + '_' + Number(new Date()),
popupOptionStr: '',
useReload: true,
closeWithParent: true,
method: 'get',
param: {}
}, options || {});
options.method = options.method.toUpperCase();
this.postBridgeUrl = options.postBridgeUrl || this.postBridgeUrl;
useIEPostBridge = options.method === 'POST' && options.param &&
browser.msie && browser.version === 11;
if (!type.isExisty(url)) {
throw new Error('Popup#open() need popup url.');
}
popupId += 1;
/*
* In form-data transmission
* 1. Create a form before opening a popup.
* 2. Transmit the form-data.
* 3. Remove the form after transmission.
*/
if (options.param) {
if (options.method === 'GET') {
url = url + (/\?/.test(url) ? '&' : '?') + this._parameterize(options.param);
} else if (options.method === 'POST') {
if (!useIEPostBridge) {
formElement = this.createForm(url, options.param, options.method, options.popupName);
url = 'about:blank';
}
}
}
popup = this.openedPopup[options.popupName];
if (!type.isExisty(popup)) {
this.openedPopup[options.popupName] = popup = this._open(useIEPostBridge, options.param,
url, options.popupName, options.popupOptionStr);
} else if (popup.closed) {
this.openedPopup[options.popupName] = popup = this._open(useIEPostBridge, options.param,
url, options.popupName, options.popupOptionStr);
} else {
if (options.useReload) {
popup.location.replace(url);
}
popup.focus();
}
this.closeWithParentPopup[options.popupName] = options.closeWithParent;
if (!popup || popup.closed || type.isUndefined(popup.closed)) {
alert('please enable popup windows for this website');
}
if (options.param && options.method === 'POST' && !useIEPostBridge) {
if (popup) {
formElement.submit();
}
if (formElement.parentNode) {
formElement.parentNode.removeChild(formElement);
}
}
window.onunload = func.bind(this.closeAllPopup, this);
};
/**
* Close the popup
* @param {boolean} [skipBeforeUnload] - If true, the 'window.onunload' will be null and skip unload event.
* @param {Window} [popup] - Window-context of popup for closing. If omit this, current window-context will be closed.
*/
Popup.prototype.close = function(skipBeforeUnload, popup) {
var target = popup || window;
skipBeforeUnload = type.isExisty(skipBeforeUnload) ? skipBeforeUnload : false;
if (skipBeforeUnload) {
window.onunload = null;
}
if (!target.closed) {
target.opener = window.location.href;
target.close();
}
};
/**
* Close all the popups in current window.
* @param {boolean} closeWithParent - If true, popups having the closeWithParentPopup property as true will be closed.
*/
Popup.prototype.closeAllPopup = function(closeWithParent) {
var hasArg = type.isExisty(closeWithParent);
collection.forEachOwnProperties(this.openedPopup, function(popup, key) {
if ((hasArg && this.closeWithParentPopup[key]) || !hasArg) {
this.close(false, popup);
}
}, this);
};
/**
* Activate(or focus) the popup of the given name.
* @param {string} popupName - Name of popup for activation
*/
Popup.prototype.focus = function(popupName) {
this.getPopupList(popupName).focus();
};
/**
* Return an object made of parsing the query string.
* @returns {Object} An object having some information of the query string.
* @private
*/
Popup.prototype.parseQuery = function() {
var param = {};
var search, pair;
search = window.location.search.substr(1);
collection.forEachArray(search.split('&'), function(part) {
pair = part.split('=');
param[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
});
return param;
};
/**
* Create a hidden form from the given arguments and return this form.
* @param {string} action - URL for form transmission
* @param {Object} [data] - Data for form transmission
* @param {string} [method] - Method of transmission
* @param {string} [target] - Target of transmission
* @param {HTMLElement} [container] - Container element of form.
* @returns {HTMLElement} Form element
*/
Popup.prototype.createForm = function(action, data, method, target, container) {
var form = document.createElement('form'),
input;
container = container || document.body;
form.method = method || 'POST';
form.action = action || '';
form.target = target || '';
form.style.display = 'none';
collection.forEachOwnProperties(data, function(value, key) {
input = document.createElement('input');
input.name = key;
input.type = 'hidden';
input.value = value;
form.appendChild(input);
});
container.appendChild(form);
return form;
};
/**********
* private methods
**********/
/**
* Return an query string made by parsing the given object
* @param {Object} obj - An object that has information for query string
* @returns {string} - Query string
* @private
*/
Popup.prototype._parameterize = function(obj) {
var query = [];
collection.forEachOwnProperties(obj, function(value, key) {
query.push(encodeURIComponent(key) + '=' + encodeURIComponent(value));
});
return query.join('&');
};
/**
* Open popup
* @param {boolean} useIEPostBridge - A switch option whether to use alternative
* of tossing POST data to the popup window in IE11
* @param {Object} param - A data for tossing to popup
* @param {string} url - Popup url
* @param {string} popupName - Popup name
* @param {string} optionStr - Setting for popup, ex) 'width=640,height=320,scrollbars=yes'
* @returns {Window} Window context of popup
* @private
*/
Popup.prototype._open = function(useIEPostBridge, param, url, popupName, optionStr) {
var popup;
if (useIEPostBridge) {
popup = window.open(this.postBridgeUrl, popupName, optionStr);
setTimeout(function() {
popup.redirect(url, param);
}, 100);
} else {
popup = window.open(url, popupName, optionStr);
}
return popup;
};
module.exports = new Popup();
/***/ }),
/* 12 */
/***/ (function(module, exports, __webpack_require__) {
/**
* @fileoverview This module has a function for date format.
* @author NHN.
* FE Development Lab <dl_javascript@nhn.com>
*/
'use strict';
var type = __webpack_require__(2);
var object = __webpack_require__(1);
var tokens = /[\\]*YYYY|[\\]*YY|[\\]*MMMM|[\\]*MMM|[\\]*MM|[\\]*M|[\\]*DD|[\\]*D|[\\]*HH|[\\]*H|[\\]*A/gi;
var MONTH_STR = [
'Invalid month', 'January', 'February', 'March', 'April', 'May',
'June', 'July', 'August', 'September', 'October', 'November', 'December'
];
var MONTH_DAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
var replaceMap = {
M: function(date) {
return Number(date.month);
},
MM: function(date) {
var month = date.month;
return (Number(month) < 10) ? '0' + month : month;
},
MMM: function(date) {
return MONTH_STR[Number(date.month)].substr(0, 3);
},
MMMM: function(date) {
return MONTH_STR[Number(date.month)];
},
D: function(date) {
return Number(date.date);
},
d: function(date) {
return replaceMap.D(date); // eslint-disable-line new-cap
},
DD: function(date) {
var dayInMonth = date.date;
return (Number(dayInMonth) < 10) ? '0' + dayInMonth : dayInMonth;
},
dd: function(date) {
return replaceMap.DD(date); // eslint-disable-line new-cap
},
YY: function(date) {
return Number(date.year) % 100;
},
yy: function(date) {
return replaceMap.YY(date); // eslint-disable-line new-cap
},
YYYY: function(date) {
var prefix = '20',
year = date.year;
if (year > 69 && year < 100) {
prefix = '19';
}
return (Number(year) < 100) ? prefix + String(year) : year;
},
yyyy: function(date) {
return replaceMap.YYYY(date); // eslint-disable-line new-cap
},
A: function(date) {
return date.meridiem;
},
a: function(date) {
return date.meridiem;
},
hh: function(date) {
var hour = date.hour;
return (Number(hour) < 10) ? '0' + hour : hour;
},
HH: function(date) {
return replaceMap.hh(date);
},
h: function(date) {
return String(Number(date.hour));
},
H: function(date) {
return replaceMap.h(date);
},
m: function(date) {
return String(Number(date.minute));
},
mm: function(date) {
var minute = date.minute;
return (Number(minute) < 10) ? '0' + minute : minute;
}
};
/**
* Check whether the given variables are valid date or not.
* @param {number} year - Year
* @param {number} month - Month
* @param {number} date - Day in month.
* @returns {boolean} Is valid?
* @private
*/
function isValidDate(year, month, date) { // eslint-disable-line complexity
var isValidYear, isValidMonth, isValid, lastDayInMonth;
year = Number(year);
month = Number(month);
date = Number(date);
isValidYear = (year > -1 && year < 100) || ((year > 1969) && (year < 2070));
isValidMonth = (month > 0) && (month < 13);
if (!isValidYear || !isValidMonth) {
return false;
}
lastDayInMonth = MONTH_DAYS[month];
if (month === 2 && year % 4 === 0) {
if (year % 100 !== 0 || year % 400 === 0) {
lastDayInMonth = 29;
}
}
isValid = (date > 0) && (date <= lastDayInMonth);
return isValid;
}
/**
* Return a string that transformed from the given form and date.
* @param {string} form - Date form
* @param {Date|Object} date - Date object
* @param {{meridiemSet: {AM: string, PM: string}}} option - Option
* @returns {boolean|string} A transformed string or false.
* @memberof tui.util
* @example
* // key | Shorthand
* // --------------- |-----------------------
* // years | YY / YYYY / yy / yyyy
* // months(n) | M / MM
* // months(str) | MMM / MMMM
* // days | D / DD / d / dd
* // hours | H / HH / h / hh
* // minutes | m / mm
* // meridiem(AM,PM) | A / a
*
* //-- #1. Get Module --//
* var util = require('tui-code-snippet'); // node, commonjs
* var util = tui.util; // distribution file
*
* //-- #2. Use property --//
* var dateStr1 = util.formatDate('yyyy-MM-dd', {
* year: 2014,
* month: 12,
* date: 12
* });
* alert(dateStr1); // '2014-12-12'
*
* var dateStr2 = util.formatDate('MMM DD YYYY HH:mm', {
* year: 1999,
* month: 9,
* date: 9,
* hour: 0,
* minute: 2
* });
* alert(dateStr2); // 'Sep 09 1999 00:02'
*
* var dt = new Date(2010, 2, 13),
* dateStr3 = util.formatDate('yyyy년 M월 dd일', dt);
* alert(dateStr3); // '2010년 3월 13일'
*
* var option4 = {
* meridiemSet: {
* AM: '오전',
* PM: '오후'
* }
* };
* var date4 = {year: 1999, month: 9, date: 9, hour: 13, minute: 2};
* var dateStr4 = util.formatDate('yyyy-MM-dd A hh:mm', date4, option4));
* alert(dateStr4); // '1999-09-09 오후 01:02'
*/
function formatDate(form, date, option) { // eslint-disable-line complexity
var am = object.pick(option, 'meridiemSet', 'AM') || 'AM';
var pm = object.pick(option, 'meridiemSet', 'PM') || 'PM';
var meridiem, nDate, resultStr;
if (type.isDate(date)) {
nDate = {
year: date.getFullYear(),
month: date.getMonth() + 1,
date: date.getDate(),
hour: date.getHours(),
minute: date.getMinutes()
};
} else {
nDate = {
year: date.year,
month: date.month,
date: date.date,
hour: date.hour,
minute: date.minute
};
}
if (!isValidDate(nDate.year, nDate.month, nDate.date)) {
return false;
}
nDate.meridiem = '';
if (/([^\\]|^)[aA]\b/.test(form)) {
meridiem = (nDate.hour > 11) ? pm : am;
if (nDate.hour > 12) { // See the clock system: https://en.wikipedia.org/wiki/12-hour_clock
nDate.hour %= 12;
}
if (nDate.hour === 0) {
nDate.hour = 12;
}
nDate.meridiem = meridiem;
}
resultStr = form.replace(tokens, function(key) {
if (key.indexOf('\\') > -1) { // escape character
return key.replace(/\\/, '');
}
return replaceMap[key](nDate) || '';
});
return resultStr;
}
module.exports = formatDate;
/***/ }),
/* 13 */
/***/ (function(module, exports, __webpack_require__) {
/**
* @fileoverview
* This module provides a function to make a constructor
* that can inherit from the other constructors like the CLASS easily.
* @author NHN.
* FE Development Lab <dl_javascript@nhn.com>
*/
'use strict';
var inherit = __webpack_require__(6).inherit;
var extend = __webpack_require__(1).extend;
/**
* Help a constructor to be defined and to inherit from the other constructors
* @param {*} [parent] Parent constructor
* @param {Object} props Members of constructor
* @param {Function} props.init Initialization method
* @param {Object} [props.static] Static members of constructor
* @returns {*} Constructor
* @memberof tui.util
* @example
* //-- #1. Get Module --//
* var util = require('tui-code-snippet'); // node, commonjs
* var util = tui.util; // distribution file
*
* //-- #2. Use property --//
* var Parent = util.defineClass({
* init: function() { // constuructor
* this.name = 'made by def';
* },
* method: function() {
* // ...
* },
* static: {
* staticMethod: function() {
* // ...
* }
* }
* });
*
* var Child = util.defineClass(Parent, {
* childMethod: function() {}
* });
*
* Parent.staticMethod();
*
* var parentInstance = new Parent();
* console.log(parentInstance.name); //made by def
* parentInstance.staticMethod(); // Error
*
* var childInstance = new Child();
* childInstance.method();
* childInstance.childMethod();
*/
function defineClass(parent, props) {
var obj;
if (!props) {
props = parent;
parent = null;
}
obj = props.init || function() {};
if (parent) {
inherit(obj, parent);
}
if (props.hasOwnProperty('static')) {
extend(obj, props['static']);
delete props['static'];
}
extend(obj.prototype, props);
return obj;
}
module.exports = defineClass;
/***/ }),
/* 14 */
/***/ (function(module, exports, __webpack_require__) {
/**
* @fileoverview Define module
* @author NHN.
* FE Development Lab <dl_javscript@nhn.com>
* @dependency type.js, defineNamespace.js
*/
'use strict';
var defineNamespace = __webpack_require__(15);
var type = __webpack_require__(2);
var INITIALIZATION_METHOD_NAME = 'initialize';
/**
* Define module
* @param {string} namespace - Namespace of module
* @param {Object} moduleDefinition - Object literal for module
* @returns {Object} Defined module
* @memberof tui.util
* @example
* //-- #1. Get Module --//
* var util = require('tui-code-snippet'); // node, commonjs
* var util = tui.util; // distribution file
*
* //-- #2. Use property --//
* var myModule = util.defineModule('modules.myModule', {
* name: 'john',
* message: '',
* initialize: function() {
* this.message = 'hello world';
* },
* getMessage: function() {
* return this.name + ': ' + this.message
* }
* });
*
* console.log(myModule.getMessage()); // 'john: hello world';
*/
function defineModule(namespace, moduleDefinition) {
var base = moduleDefinition || {};
if (type.isFunction(base[INITIALIZATION_METHOD_NAME])) {
base[INITIALIZATION_METHOD_NAME]();
}
return defineNamespace(namespace, base);
}
module.exports = defineModule;
/***/ }),
/* 15 */
/***/ (function(module, exports, __webpack_require__) {
/**
* @fileoverview Define namespace
* @author NHN.
* FE Development Lab <dl_javascript@nhn.com>
* @dependency object.js, collection.js
*/
'use strict';
var collection = __webpack_require__(4);
var object = __webpack_require__(1);
/**
* Define namespace
* @param {string} namespace - Namespace (ex- 'foo.bar.baz')
* @param {(object|function)} props - A set of modules or one module
* @param {boolean} [isOverride] - Override the props to the namespace.<br>
* (It removes previous properties of this namespace)
* @returns {(object|function)} Defined namespace
* @memberof tui.util
* @example
* //-- #1. Get Module --//
* var util = require('tui-code-snippet'); // node, commonjs
* var util = tui.util; // distribution file
*
* //-- #2. Use property --//
* var neComp = util.defineNamespace;
* neComp.listMenu = defineClass({
* init: function() {
* // ...
* }
* });
*/
function defineNamespace(namespace, props, isOverride) {
var names, result, prevLast, last;
names = namespace.split('.');
names.unshift(window);
result = collection.reduce(names, function(obj, name) {
obj[name] = obj[name] || {};
return obj[name];
});
if (isOverride) {
last = names.pop();
prevLast = object.pick.apply(null, names);
result = prevLast[last] = props;
} else {
object.extend(result, props);
}
return result;
}
module.exports = defineNamespace;
/***/ }),
/* 16 */
/***/ (function(module, exports, __webpack_require__) {
/**
* @fileoverview
* This module provides some functions for custom events.<br>
* And it is implemented in the observer design pattern.
* @author NHN.
* FE Development Lab <dl_javascript@nhn.com>
*/
'use strict';
var collection = __webpack_require__(4);
var type = __webpack_require__(2);
var object = __webpack_require__(1);
var R_EVENTNAME_SPLIT = /\s+/g;
/**
* A unit of event handler item.
* @ignore
* @typedef {object} HandlerItem
* @property {function} fn - event handler
* @property {object} ctx - context of event handler
*/
/**
* @class
* @memberof tui.util
* @example
* // node, commonjs
* var CustomEvents = require('tui-code-snippet').CustomEvents;
* @example
* // distribution file, script
* <script src='path-to/tui-code-snippt.js'></script>
* <script>
* var CustomEvents = tui.util.CustomEvents;
* </script>
*/
function CustomEvents() {
/**
* @type {HandlerItem[]}
*/
this.events = null;
/**
* only for checking specific context event was binded
* @type {object[]}
*/
this.contexts = null;
}
/**
* Mixin custom events feature to specific constructor
* @param {function} func - constructor
* @example
* //-- #1. Get Module --//
* var CustomEvents = require('tui-code-snippet').CustomEvents; // node, commonjs
* var CustomEvents = tui.util.CustomEvents; // distribution file
*
* //-- #2. Use property --//
* var model;
* function Model() {
* this.name = '';
* }
* CustomEvents.mixin(Model);
*
* model = new Model();
* model.on('change', function() { this.name = 'model'; }, this);
* model.fire('change');
* alert(model.name); // 'model';
*/
CustomEvents.mixin = function(func) {
object.extend(func.prototype, CustomEvents.prototype);
};
/**
* Get HandlerItem object
* @param {function} handler - handler function
* @param {object} [context] - context for handler
* @returns {HandlerItem} HandlerItem object
* @private
*/
CustomEvents.prototype._getHandlerItem = function(handler, context) {
var item = {handler: handler};
if (context) {
item.context = context;
}
return item;
};
/**
* Get event object safely
* @param {string} [eventName] - create sub event map if not exist.
* @returns {(object|array)} event object. if you supplied `eventName`
* parameter then make new array and return it
* @private
*/
CustomEvents.prototype._safeEvent = function(eventName) {
var events = this.events;
var byName;
if (!events) {
events = this.events = {};
}
if (eventName) {
byName = events[eventName];
if (!byName) {
byName = [];
events[eventName] = byName;
}
events = byName;
}
return events;
};
/**
* Get context array safely
* @returns {array} context array
* @private
*/
CustomEvents.prototype._safeContext = function() {
var context = this.contexts;
if (!context) {
context = this.contexts = [];
}
return context;
};
/**
* Get index of context
* @param {object} ctx - context that used for bind custom event
* @returns {number} index of context
* @private
*/
CustomEvents.prototype._indexOfContext = function(ctx) {
var context = this._safeContext();
var index = 0;
while (context[index]) {
if (ctx === context[index][0]) {
return index;
}
index += 1;
}
return -1;
};
/**
* Memorize supplied context for recognize supplied object is context or
* name: handler pair object when off()
* @param {object} ctx - context object to memorize
* @private
*/
CustomEvents.prototype._memorizeContext = function(ctx) {
var context, index;
if (!type.isExisty(ctx)) {
return;
}
context = this._safeContext();
index = this._indexOfContext(ctx);
if (index > -1) {
context[index][1] += 1;
} else {
context.push([ctx, 1]);
}
};
/**
* Forget supplied context object
* @param {object} ctx - context object to forget
* @private
*/
CustomEvents.prototype._forgetContext = function(ctx) {
var context, contextIndex;
if (!type.isExisty(ctx)) {
return;
}
context = this._safeContext();
contextIndex = this._indexOfContext(ctx);
if (contextIndex > -1) {
context[contextIndex][1] -= 1;
if (context[contextIndex][1] <= 0) {
context.splice(contextIndex, 1);
}
}
};
/**
* Bind event handler
* @param {(string|{name:string, handler:function})} eventName - custom
* event name or an object {eventName: handler}
* @param {(function|object)} [handler] - handler function or context
* @param {object} [context] - context for binding
* @private
*/
CustomEvents.prototype._bindEvent = function(eventName, handler, context) {
var events = this._safeEvent(eventName);
this._memorizeContext(context);
events.push(this._getHandlerItem(handler, context));
};
/**
* Bind event handlers
* @param {(string|{name:string, handler:function})} eventName - custom
* event name or an object {eventName: handler}
* @param {(function|object)} [handler] - handler function or context
* @param {object} [context] - context for binding
* //-- #1. Get Module --//
* var CustomEvents = require('tui-code-snippet').CustomEvents; // node, commonjs
* var CustomEvents = tui.util.CustomEvents; // distribution file
*
* //-- #2. Use property --//
* // # 2.1 Basic Usage
* CustomEvents.on('onload', handler);
*
* // # 2.2 With context
* CustomEvents.on('onload', handler, myObj);
*
* // # 2.3 Bind by object that name, handler pairs
* CustomEvents.on({
* 'play': handler,
* 'pause': handler2
* });
*
* // # 2.4 Bind by object that name, handler pairs with context object
* CustomEvents.on({
* 'play': handler
* }, myObj);
*/
CustomEvents.prototype.on = function(eventName, handler, context) {
var self = this;
if (type.isString(eventName)) {
// [syntax 1, 2]
eventName = eventName.split(R_EVENTNAME_SPLIT);
collection.forEach(eventName, function(name) {
self._bindEvent(name, handler, context);
});
} else if (type.isObject(eventName)) {
// [syntax 3, 4]
context = handler;
collection.forEach(eventName, function(func, name) {
self.on(name, func, context);
});
}
};
/**
* Bind one-shot event handlers
* @param {(string|{name:string,handler:function})} eventName - custom
* event name or an object {eventName: handler}
* @param {function|object} [handler] - handler function or context
* @param {object} [context] - context for binding
*/
CustomEvents.prototype.once = function(eventName, handler, context) {
var self = this;
if (type.isObject(eventName)) {
context = handler;
collection.forEach(eventName, function(func, name) {
self.once(name, func, context);
});
return;
}
function onceHandler() { // eslint-disable-line require-jsdoc
handler.apply(context, arguments);
self.off(eventName, onceHandler, context);
}
this.on(eventName, onceHandler, context);
};
/**
* Splice supplied array by callback result
* @param {array} arr - array to splice
* @param {function} predicate - function return boolean
* @private
*/
CustomEvents.prototype._spliceMatches = function(arr, predicate) {
var i = 0;
var len;
if (!type.isArray(arr)) {
return;
}
for (len = arr.length; i < len; i += 1) {
if (predicate(arr[i]) === true) {
arr.splice(i, 1);
len -= 1;
i -= 1;
}
}
};
/**
* Get matcher for unbind specific handler events
* @param {function} handler - handler function
* @returns {function} handler matcher
* @private
*/
CustomEvents.prototype._matchHandler = function(handler) {
var self = this;
return function(item) {
var needRemove = handler === item.handler;
if (needRemove) {
self._forgetContext(item.context);
}
return needRemove;
};
};
/**
* Get matcher for unbind specific context events
* @param {object} context - context
* @returns {function} object matcher
* @private
*/
CustomEvents.prototype._matchContext = function(context) {
var self = this;
return function(item) {
var needRemove = context === item.context;
if (needRemove) {
self._forgetContext(item.context);
}
return needRemove;
};
};
/**
* Get matcher for unbind specific hander, context pair events
* @param {function} handler - handler function
* @param {object} context - context
* @returns {function} handler, context matcher
* @private
*/
CustomEvents.prototype._matchHandlerAndContext = function(handler, context) {
var self = this;
return function(item) {
var matchHandler = (handler === item.handler);
var matchContext = (context === item.context);
var needRemove = (matchHandler && matchContext);
if (needRemove) {
self._forgetContext(item.context);
}
return needRemove;
};
};
/**
* Unbind event by event name
* @param {string} eventName - custom event name to unbind
* @param {function} [handler] - handler function
* @private
*/
CustomEvents.prototype._offByEventName = function(eventName, handler) {
var self = this;
var forEach = collection.forEachArray;
var andByHandler = type.isFunction(handler);
var matchHandler = self._matchHandler(handler);
eventName = eventName.split(R_EVENTNAME_SPLIT);
forEach(eventName, function(name) {
var handlerItems = self._safeEvent(name);
if (andByHandler) {
self._spliceMatches(handlerItems, matchHandler);
} else {
forEach(handlerItems, function(item) {
self._forgetContext(item.context);
});
self.events[name] = [];
}
});
};
/**
* Unbind event by handler function
* @param {function} handler - handler function
* @private
*/
CustomEvents.prototype._offByHandler = function(handler) {
var self = this;
var matchHandler = this._matchHandler(handler);
collection.forEach(this._safeEvent(), function(handlerItems) {
self._spliceMatches(handlerItems, matchHandler);
});
};
/**
* Unbind event by object(name: handler pair object or context object)
* @param {object} obj - context or {name: handler} pair object
* @param {function} handler - handler function
* @private
*/
CustomEvents.prototype._offByObject = function(obj, handler) {
var self = this;
var matchFunc;
if (this._indexOfContext(obj) < 0) {
collection.forEach(obj, function(func, name) {
self.off(name, func);
});
} else if (type.isString(handler)) {
matchFunc = this._matchContext(obj);
self._spliceMatches(this._safeEvent(handler), matchFunc);
} else if (type.isFunction(handler)) {
matchFunc = this._matchHandlerAndContext(handler, obj);
collection.forEach(this._safeEvent(), function(handlerItems) {
self._spliceMatches(handlerItems, matchFunc);
});
} else {
matchFunc = this._matchContext(obj);
collection.forEach(this._safeEvent(), function(handlerItems) {
self._spliceMatches(handlerItems, matchFunc);
});
}
};
/**
* Unbind custom events
* @param {(string|object|function)} eventName - event name or context or
* {name: handler} pair object or handler function
* @param {(function)} handler - handler function
* @example
* //-- #1. Get Module --//
* var CustomEvents = require('tui-code-snippet').CustomEvents; // node, commonjs
* var CustomEvents = tui.util.CustomEvents; // distribution file
*
* //-- #2. Use property --//
* // # 2.1 off by event name
* CustomEvents.off('onload');
*
* // # 2.2 off by event name and handler
* CustomEvents.off('play', handler);
*
* // # 2.3 off by handler
* CustomEvents.off(handler);
*
* // # 2.4 off by context
* CustomEvents.off(myObj);
*
* // # 2.5 off by context and handler
* CustomEvents.off(myObj, handler);
*
* // # 2.6 off by context and event name
* CustomEvents.off(myObj, 'onload');
*
* // # 2.7 off by an Object.<string, function> that is {eventName: handler}
* CustomEvents.off({
* 'play': handler,
* 'pause': handler2
* });
*
* // # 2.8 off the all events
* CustomEvents.off();
*/
CustomEvents.prototype.off = function(eventName, handler) {
if (type.isString(eventName)) {
// [syntax 1, 2]
this._offByEventName(eventName, handler);
} else if (!arguments.length) {
// [syntax 8]
this.events = {};
this.contexts = [];
} else if (type.isFunction(eventName)) {
// [syntax 3]
this._offByHandler(eventName);
} else if (type.isObject(eventName)) {
// [syntax 4, 5, 6]
this._offByObject(eventName, handler);
}
};
/**
* Fire custom event
* @param {string} eventName - name of custom event
*/
CustomEvents.prototype.fire = function(eventName) { // eslint-disable-line
this.invoke.apply(this, arguments);
};
/**
* Fire a event and returns the result of operation 'boolean AND' with all
* listener's results.
*
* So, It is different from {@link CustomEvents#fire}.
*
* In service code, use this as a before event in component level usually
* for notifying that the event is cancelable.
* @param {string} eventName - Custom event name
* @param {...*} data - Data for event
* @returns {boolean} The result of operation 'boolean AND'
* @example
* var map = new Map();
* map.on({
* 'beforeZoom': function() {
* // It should cancel the 'zoom' event by some conditions.
* if (that.disabled && this.getState()) {
* return false;
* }
* return true;
* }
* });
*
* if (this.invoke('beforeZoom')) { // check the result of 'beforeZoom'
* // if true,
* // doSomething
* }
*/
CustomEvents.prototype.invoke = function(eventName) {
var events, args, index, item;
if (!this.hasListener(eventName)) {
return true;
}
events = this._safeEvent(eventName);
args = Array.prototype.slice.call(arguments, 1);
index = 0;
while (events[index]) {
item = events[index];
if (item.handler.apply(item.context, args) === false) {
return false;
}
index += 1;
}
return true;
};
/**
* Return whether at least one of the handlers is registered in the given
* event name.
* @param {string} eventName - Custom event name
* @returns {boolean} Is there at least one handler in event name?
*/
CustomEvents.prototype.hasListener = function(eventName) {
return this.getListenerLength(eventName) > 0;
};
/**
* Return a count of events registered.
* @param {string} eventName - Custom event name
* @returns {number} number of event
*/
CustomEvents.prototype.getListenerLength = function(eventName) {
var events = this._safeEvent(eventName);
return events.length;
};
module.exports = CustomEvents;
/***/ }),
/* 17 */
/***/ (function(module, exports, __webpack_require__) {
/**
* @fileoverview This module provides a Enum Constructor.
* @author NHN.
* FE Development Lab <dl_javascript@nhn.com>
* @example
* // node, commonjs
* var Enum = require('tui-code-snippet').Enum;
* @example
* // distribution file, script
* <script src='path-to/tui-code-snippt.js'></script>
* <script>
* var Enum = tui.util.Enum;
* <script>
*/
'use strict';
var collection = __webpack_require__(4);
var type = __webpack_require__(2);
/**
* Check whether the defineProperty() method is supported.
* @type {boolean}
* @ignore
*/
var isSupportDefinedProperty = (function() {
try {
Object.defineProperty({}, 'x', {});
return true;
} catch (e) {
return false;
}
})();
/**
* A unique value of a constant.
* @type {number}
* @ignore
*/
var enumValue = 0;
/**
* Make a constant-list that has unique values.<br>
* In modern browsers (except IE8 and lower),<br>
* a value defined once can not be changed.
*
* @param {...string|string[]} itemList Constant-list (An array of string is available)
* @class
* @memberof tui.util
* @example
* //-- #1. Get Module --//
* var Enum = require('tui-code-snippet').Enum; // node, commonjs
* var Enum = tui.util.Enum; // distribution file
*
* //-- #2. Use property --//
* var MYENUM = new Enum('TYPE1', 'TYPE2');
* var MYENUM2 = new Enum(['TYPE1', 'TYPE2']);
*
* //usage
* if (value === MYENUM.TYPE1) {
* ....
* }
*
* //add (If a duplicate name is inputted, will be disregarded.)
* MYENUM.set('TYPE3', 'TYPE4');
*
* //get name of a constant by a value
* MYENUM.getName(MYENUM.TYPE1); // 'TYPE1'
*
* // In modern browsers (except IE8 and lower), a value can not be changed in constants.
* var originalValue = MYENUM.TYPE1;
* MYENUM.TYPE1 = 1234; // maybe TypeError
* MYENUM.TYPE1 === originalValue; // true
**/
function Enum(itemList) {
if (itemList) {
this.set.apply(this, arguments);
}
}
/**
* Define a constants-list
* @param {...string|string[]} itemList Constant-list (An array of string is available)
*/
Enum.prototype.set = function(itemList) {
var self = this;
if (!type.isArray(itemList)) {
itemList = collection.toArray(arguments);
}
collection.forEach(itemList, function itemListIteratee(item) {
self._addItem(item);
});
};
/**
* Return a key of the constant.
* @param {number} value A value of the constant.
* @returns {string|undefined} Key of the constant.
*/
Enum.prototype.getName = function(value) {
var self = this;
var foundedKey;
collection.forEach(this, function(itemValue, key) { // eslint-disable-line consistent-return
if (self._isEnumItem(key) && value === itemValue) {
foundedKey = key;
return false;
}
});
return foundedKey;
};
/**
* Create a constant.
* @private
* @param {string} name Constant name. (It will be a key of a constant)
*/
Enum.prototype._addItem = function(name) {
var value;
if (!this.hasOwnProperty(name)) {
value = this._makeEnumValue();
if (isSupportDefinedProperty) {
Object.defineProperty(this, name, {
enumerable: true,
configurable: false,
writable: false,
value: value
});
} else {
this[name] = value;
}
}
};
/**
* Return a unique value for assigning to a constant.
* @private
* @returns {number} A unique value
*/
Enum.prototype._makeEnumValue = function() {
var value;
value = enumValue;
enumValue += 1;
return value;
};
/**
* Return whether a constant from the given key is in instance or not.
* @param {string} key - A constant key
* @returns {boolean} Result
* @private
*/
Enum.prototype._isEnumItem = function(key) {
return type.isNumber(this[key]);
};
module.exports = Enum;
/***/ }),
/* 18 */
/***/ (function(module, exports, __webpack_require__) {
/**
* @fileoverview
* Implements the ExMap (Extended Map) object.
* @author NHN.
* FE Development Lab <dl_javascript@nhn.com>
*/
'use strict';
var collection = __webpack_require__(4);
var Map = __webpack_require__(19);
// Caching tui.util for performance enhancing
var mapAPIsForRead = ['get', 'has', 'forEach', 'keys', 'values', 'entries'];
var mapAPIsForDelete = ['delete', 'clear'];
/**
* The ExMap object is Extended Version of the tui.util.Map object.<br>
* and added some useful feature to make it easy to manage the Map object.
* @constructor
* @param {Array} initData - Array of key-value pairs (2-element Arrays).
* Each key-value pair will be added to the new Map
* @memberof tui.util
* @example
* // node, commonjs
* var ExMap = require('tui-code-snippet').ExMap;
* @example
* // distribution file, script
* <script src='path-to/tui-code-snippt.js'></script>
* <script>
* var ExMap = tui.util.ExMap;
* <script>
*/
function ExMap(initData) {
this._map = new Map(initData);
this.size = this._map.size;
}
collection.forEachArray(mapAPIsForRead, function(name) {
ExMap.prototype[name] = function() {
return this._map[name].apply(this._map, arguments);
};
});
collection.forEachArray(mapAPIsForDelete, function(name) {
ExMap.prototype[name] = function() {
var result = this._map[name].apply(this._map, arguments);
this.size = this._map.size;
return result;
};
});
ExMap.prototype.set = function() {
this._map.set.apply(this._map, arguments);
this.size = this._map.size;
return this;
};
/**
* Sets all of the key-value pairs in the specified object to the Map object.
* @param {Object} object - Plain object that has a key-value pair
*/
ExMap.prototype.setObject = function(object) {
collection.forEachOwnProperties(object, function(value, key) {
this.set(key, value);
}, this);
};
/**
* Removes the elements associated with keys in the specified array.
* @param {Array} keys - Array that contains keys of the element to remove
*/
ExMap.prototype.deleteByKeys = function(keys) {
collection.forEachArray(keys, function(key) {
this['delete'](key);
}, this);
};
/**
* Sets all of the key-value pairs in the specified Map object to this Map object.
* @param {Map} map - Map object to be merged into this Map object
*/
ExMap.prototype.merge = function(map) {
map.forEach(function(value, key) {
this.set(key, value);
}, this);
};
/**
* Looks through each key-value pair in the map and returns the new ExMap object of
* all key-value pairs that pass a truth test implemented by the provided function.
* @param {function} predicate - Function to test each key-value pair of the Map object.<br>
* Invoked with arguments (value, key). Return true to keep the element, false otherwise.
* @returns {ExMap} A new ExMap object
*/
ExMap.prototype.filter = function(predicate) {
var filtered = new ExMap();
this.forEach(function(value, key) {
if (predicate(value, key)) {
filtered.set(key, value);
}
});
return filtered;
};
module.exports = ExMap;
/***/ }),
/* 19 */
/***/ (function(module, exports, __webpack_require__) {
/**
* @fileoverview
* Implements the Map object.
* @author NHN.
* FE Development Lab <dl_javascript@nhn.com>
*/
'use strict';
var collection = __webpack_require__(4);
var type = __webpack_require__(2);
var array = __webpack_require__(3);
var browser = __webpack_require__(10);
var func = __webpack_require__(5);
/**
* Using undefined for a key can be ambiguous if there's deleted item in the array,<br>
* which is also undefined when accessed by index.<br>
* So use this unique object as an undefined key to distinguish it from deleted keys.
* @private
* @constant
*/
var _KEY_FOR_UNDEFINED = {};
/**
* For using NaN as a key, use this unique object as a NaN key.<br>
* This makes it easier and faster to compare an object with each keys in the array<br>
* through no exceptional comapring for NaN.
* @private
* @constant
*/
var _KEY_FOR_NAN = {};
/**
* Constructor of MapIterator<br>
* Creates iterator object with new keyword.
* @constructor
* @param {Array} keys - The array of keys in the map
* @param {function} valueGetter - Function that returns certain value,
* taking key and keyIndex as arguments.
* @ignore
*/
function MapIterator(keys, valueGetter) {
this._keys = keys;
this._valueGetter = valueGetter;
this._length = this._keys.length;
this._index = -1;
this._done = false;
}
/**
* Implementation of Iterator protocol.
* @returns {{done: boolean, value: *}} Object that contains done(boolean) and value.
*/
MapIterator.prototype.next = function() {
var data = {};
do {
this._index += 1;
} while (type.isUndefined(this._keys[this._index]) && this._index < this._length);
if (this._index >= this._length) {
data.done = true;
} else {
data.done = false;
data.value = this._valueGetter(this._keys[this._index], this._index);
}
return data;
};
/**
* The Map object implements the ES6 Map specification as closely as possible.<br>
* For using objects and primitive values as keys, this object uses array internally.<br>
* So if the key is not a string, get(), set(), has(), delete() will operates in O(n),<br>
* and it can cause performance issues with a large dataset.
*
* Features listed below are not supported. (can't be implented without native support)
* - Map object is iterable<br>
* - Iterable object can be used as an argument of constructor
*
* If the browser supports full implementation of ES6 Map specification, native Map obejct
* will be used internally.
* @class
* @param {Array} initData - Array of key-value pairs (2-element Arrays).
* Each key-value pair will be added to the new Map
* @memberof tui.util
* @example
* // node, commonjs
* var Map = require('tui-code-snippet').Map;
* @example
* // distribution file, script
* <script src='path-to/tui-code-snippt.js'></script>
* <script>
* var Map = tui.util.Map;
* <script>
*/
function Map(initData) {
this._valuesForString = {};
this._valuesForIndex = {};
this._keys = [];
if (initData) {
this._setInitData(initData);
}
this.size = 0;
}
/* eslint-disable no-extend-native */
/**
* Add all elements in the initData to the Map object.
* @private
* @param {Array} initData - Array of key-value pairs to add to the Map object
*/
Map.prototype._setInitData = function(initData) {
if (!type.isArray(initData)) {
throw new Error('Only Array is supported.');
}
collection.forEachArray(initData, function(pair) {
this.set(pair[0], pair[1]);
}, this);
};
/**
* Returns true if the specified value is NaN.<br>
* For unsing NaN as a key, use this method to test equality of NaN<br>
* because === operator doesn't work for NaN.
* @private
* @param {*} value - Any object to be tested
* @returns {boolean} True if value is NaN, false otherwise.
*/
Map.prototype._isNaN = function(value) {
return typeof value === 'number' && value !== value; // eslint-disable-line no-self-compare
};
/**
* Returns the index of the specified key.
* @private
* @param {*} key - The key object to search for.
* @returns {number} The index of the specified key
*/
Map.prototype._getKeyIndex = function(key) {
var result = -1;
var value;
if (type.isString(key)) {
value = this._valuesForString[key];
if (value) {
result = value.keyIndex;
}
} else {
result = array.inArray(key, this._keys);
}
return result;
};
/**
* Returns the original key of the specified key.
* @private
* @param {*} key - key
* @returns {*} Original key
*/
Map.prototype._getOriginKey = function(key) {
var originKey = key;
if (key === _KEY_FOR_UNDEFINED) {
originKey = undefined; // eslint-disable-line no-undefined
} else if (key === _KEY_FOR_NAN) {
originKey = NaN;
}
return originKey;
};
/**
* Returns the unique key of the specified key.
* @private
* @param {*} key - key
* @returns {*} Unique key
*/
Map.prototype._getUniqueKey = function(key) {
var uniqueKey = key;
if (type.isUndefined(key)) {
uniqueKey = _KEY_FOR_UNDEFINED;
} else if (this._isNaN(key)) {
uniqueKey = _KEY_FOR_NAN;
}
return uniqueKey;
};
/**
* Returns the value object of the specified key.
* @private
* @param {*} key - The key of the value object to be returned
* @param {number} keyIndex - The index of the key
* @returns {{keyIndex: number, origin: *}} Value object
*/
Map.prototype._getValueObject = function(key, keyIndex) { // eslint-disable-line consistent-return
if (type.isString(key)) {
return this._valuesForString[key];
}
if (type.isUndefined(keyIndex)) {
keyIndex = this._getKeyIndex(key);
}
if (keyIndex >= 0) {
return this._valuesForIndex[keyIndex];
}
};
/**
* Returns the original value of the specified key.
* @private
* @param {*} key - The key of the value object to be returned
* @param {number} keyIndex - The index of the key
* @returns {*} Original value
*/
Map.prototype._getOriginValue = function(key, keyIndex) {
return this._getValueObject(key, keyIndex).origin;
};
/**
* Returns key-value pair of the specified key.
* @private
* @param {*} key - The key of the value object to be returned
* @param {number} keyIndex - The index of the key
* @returns {Array} Key-value Pair
*/
Map.prototype._getKeyValuePair = function(key, keyIndex) {
return [this._getOriginKey(key), this._getOriginValue(key, keyIndex)];
};
/**
* Creates the wrapper object of original value that contains a key index
* and returns it.
* @private
* @param {type} origin - Original value
* @param {type} keyIndex - Index of the key
* @returns {{keyIndex: number, origin: *}} Value object
*/
Map.prototype._createValueObject = function(origin, keyIndex) {
return {
keyIndex: keyIndex,
origin: origin
};
};
/**
* Sets the value for the key in the Map object.
* @param {*} key - The key of the element to add to the Map object
* @param {*} value - The value of the element to add to the Map object
* @returns {Map} The Map object
*/
Map.prototype.set = function(key, value) {
var uniqueKey = this._getUniqueKey(key);
var keyIndex = this._getKeyIndex(uniqueKey);
var valueObject;
if (keyIndex < 0) {
keyIndex = this._keys.push(uniqueKey) - 1;
this.size += 1;
}
valueObject = this._createValueObject(value, keyIndex);
if (type.isString(key)) {
this._valuesForString[key] = valueObject;
} else {
this._valuesForIndex[keyIndex] = valueObject;
}
return this;
};
/**
* Returns the value associated to the key, or undefined if there is none.
* @param {*} key - The key of the element to return
* @returns {*} Element associated with the specified key
*/
Map.prototype.get = function(key) {
var uniqueKey = this._getUniqueKey(key);
var value = this._getValueObject(uniqueKey);
return value && value.origin;
};
/**
* Returns a new Iterator object that contains the keys for each element
* in the Map object in insertion order.
* @returns {Iterator} A new Iterator object
*/
Map.prototype.keys = function() {
return new MapIterator(this._keys, func.bind(this._getOriginKey, this));
};
/**
* Returns a new Iterator object that contains the values for each element
* in the Map object in insertion order.
* @returns {Iterator} A new Iterator object
*/
Map.prototype.values = function() {
return new MapIterator(this._keys, func.bind(this._getOriginValue, this));
};
/**
* Returns a new Iterator object that contains the [key, value] pairs
* for each element in the Map object in insertion order.
* @returns {Iterator} A new Iterator object
*/
Map.prototype.entries = function() {
return new MapIterator(this._keys, func.bind(this._getKeyValuePair, this));
};
/**
* Returns a boolean asserting whether a value has been associated to the key
* in the Map object or not.
* @param {*} key - The key of the element to test for presence
* @returns {boolean} True if an element with the specified key exists;
* Otherwise false
*/
Map.prototype.has = function(key) {
return !!this._getValueObject(key);
};
/**
* Removes the specified element from a Map object.
* @param {*} key - The key of the element to remove
* @function delete
* @memberof tui.util.Map.prototype
*/
// cannot use reserved keyword as a property name in IE8 and under.
Map.prototype['delete'] = function(key) {
var keyIndex;
if (type.isString(key)) {
if (this._valuesForString[key]) {
keyIndex = this._valuesForString[key].keyIndex;
delete this._valuesForString[key];
}
} else {
keyIndex = this._getKeyIndex(key);
if (keyIndex >= 0) {
delete this._valuesForIndex[keyIndex];
}
}
if (keyIndex >= 0) {
delete this._keys[keyIndex];
this.size -= 1;
}
};
/**
* Executes a provided function once per each key/value pair in the Map object,
* in insertion order.
* @param {function} callback - Function to execute for each element
* @param {thisArg} thisArg - Value to use as this when executing callback
*/
Map.prototype.forEach = function(callback, thisArg) {
thisArg = thisArg || this;
collection.forEachArray(this._keys, function(key) {
if (!type.isUndefined(key)) {
callback.call(thisArg, this._getValueObject(key).origin, key, this);
}
}, this);
};
/**
* Removes all elements from a Map object.
*/
Map.prototype.clear = function() {
Map.call(this);
};
/* eslint-enable no-extend-native */
// Use native Map object if exists.
// But only latest versions of Chrome and Firefox support full implementation.
(function() {
if (window.Map && (
(browser.firefox && browser.version >= 37) ||
(browser.chrome && browser.version >= 42)
)
) {
Map = window.Map; // eslint-disable-line no-func-assign
}
})();
module.exports = Map;
/***/ }),
/* 20 */
/***/ (function(module, exports, __webpack_require__) {
/**
* @fileoverview This module provides the HashMap constructor.
* @author NHN.
* FE Development Lab <dl_javascript@nhn.com>
*/
'use strict';
var collection = __webpack_require__(4);
var type = __webpack_require__(2);
/**
* All the data in hashMap begin with _MAPDATAPREFIX;
* @type {string}
* @private
*/
var _MAPDATAPREFIX = 'å';
/**
* HashMap can handle the key-value pairs.<br>
* Caution:<br>
* HashMap instance has a length property but is not an instance of Array.
* @param {Object} [obj] A initial data for creation.
* @constructor
* @memberof tui.util
* @deprecated since version 1.3.0
* @example
* // node, commonjs
* var HashMap = require('tui-code-snippet').HashMap;
* var hm = new tui.util.HashMap({
'mydata': {
'hello': 'imfine'
},
'what': 'time'
});
* @example
* // distribution file, script
* <script src='path-to/tui-code-snippt.js'></script>
* <script>
* var HashMap = tui.util.HashMap;
* <script>
* var hm = new tui.util.HashMap({
'mydata': {
'hello': 'imfine'
},
'what': 'time'
});
*/
function HashMap(obj) {
/**
* size
* @type {number}
*/
this.length = 0;
if (obj) {
this.setObject(obj);
}
}
/**
* Set a data from the given key with value or the given object.
* @param {string|Object} key A string or object for key
* @param {*} [value] A data
* @example
* //-- #1. Get Module --//
* var HashMap = require('tui-code-snippet').HashMap; // node, commonjs
* var HashMap = tui.util.HashMap; // distribution file
*
* //-- #2. Use property --//
* var hm = new HashMap();
* hm.set('key', 'value');
* hm.set({
* 'key1': 'data1',
* 'key2': 'data2'
* });
*/
HashMap.prototype.set = function(key, value) {
if (arguments.length === 2) {
this.setKeyValue(key, value);
} else {
this.setObject(key);
}
};
/**
* Set a data from the given key with value.
* @param {string} key A string for key
* @param {*} value A data
* @example
* //-- #1. Get Module --//
* var HashMap = require('tui-code-snippet').HashMap; // node, commonjs
* var HashMap = tui.util.HashMap; // distribution file
*
* //-- #2. Use property --//
* var hm = new HashMap();
* hm.setKeyValue('key', 'value');
*/
HashMap.prototype.setKeyValue = function(key, value) {
if (!this.has(key)) {
this.length += 1;
}
this[this.encodeKey(key)] = value;
};
/**
* Set a data from the given object.
* @param {Object} obj A object for data
* @example
* //-- #1. Get Module --//
* var HashMap = require('tui-code-snippet').HashMap; // node, commonjs
* var HashMap = tui.util.HashMap; // distribution file
*
* //-- #2. Use property --//
* var hm = new HashMap();
* hm.setObject({
* 'key1': 'data1',
* 'key2': 'data2'
* });
*/
HashMap.prototype.setObject = function(obj) {
var self = this;
collection.forEachOwnProperties(obj, function(value, key) {
self.setKeyValue(key, value);
});
};
/**
* Merge with the given another hashMap.
* @param {HashMap} hashMap Another hashMap instance
*/
HashMap.prototype.merge = function(hashMap) {
var self = this;
hashMap.each(function(value, key) {
self.setKeyValue(key, value);
});
};
/**
* Encode the given key for hashMap.
* @param {string} key A string for key
* @returns {string} A encoded key
* @private
*/
HashMap.prototype.encodeKey = function(key) {
return _MAPDATAPREFIX + key;
};
/**
* Decode the given key in hashMap.
* @param {string} key A string for key
* @returns {string} A decoded key
* @private
*/
HashMap.prototype.decodeKey = function(key) {
var decodedKey = key.split(_MAPDATAPREFIX);
return decodedKey[decodedKey.length - 1];
};
/**
* Return the value from the given key.
* @param {string} key A string for key
* @returns {*} The value from a key
* @example
* //-- #1. Get Module --//
* var HashMap = require('tui-code-snippet').HashMap; // node, commonjs
* var HashMap = tui.util.HashMap; // distribution file
*
* //-- #2. Use property --//
* var hm = new HashMap();
* hm.set('key', 'value');
* hm.get('key') // value
*/
HashMap.prototype.get = function(key) {
return this[this.encodeKey(key)];
};
/**
* Check the existence of a value from the key.
* @param {string} key A string for key
* @returns {boolean} Indicating whether a value exists or not.
* @example
* //-- #1. Get Module --//
* var HashMap = require('tui-code-snippet').HashMap; // node, commonjs
* var HashMap = tui.util.HashMap; // distribution file
*
* //-- #2. Use property --//
* var hm = new HashMap();
* hm.set('key', 'value');
* hm.has('key') // true
*/
HashMap.prototype.has = function(key) {
return this.hasOwnProperty(this.encodeKey(key));
};
/**
* Remove a data(key-value pairs) from the given key or the given key-list.
* @param {...string|string[]} key A string for key
* @returns {string|string[]} A removed data
* @example
* //-- #1. Get Module --//
* var HashMap = require('tui-code-snippet').HashMap; // node, commonjs
* var HashMap = tui.util.HashMap; // distribution file
*
* //-- #2. Use property --//
* var hm = new HashMap();
* hm.set('key', 'value');
* hm.set('key2', 'value');
*
* hm.remove('key');
* hm.remove('key', 'key2');
* hm.remove(['key', 'key2']);
*/
HashMap.prototype.remove = function(key) {
if (arguments.length > 1) {
key = collection.toArray(arguments);
}
return type.isArray(key) ? this.removeByKeyArray(key) : this.removeByKey(key);
};
/**
* Remove data(key-value pair) from the given key.
* @param {string} key A string for key
* @returns {*|null} A removed data
* @example
* //-- #1. Get Module --//
* var HashMap = require('tui-code-snippet').HashMap; // node, commonjs
* var HashMap = tui.util.HashMap; // distribution file
*
* //-- #2. Use property --//
* var hm = new HashMap();
* hm.set('key', 'value');
* hm.removeByKey('key')
*/
HashMap.prototype.removeByKey = function(key) {
var data = this.has(key) ? this.get(key) : null;
if (data !== null) {
delete this[this.encodeKey(key)];
this.length -= 1;
}
return data;
};
/**
* Remove a data(key-value pairs) from the given key-list.
* @param {string[]} keyArray An array of keys
* @returns {string[]} A removed data
* @example
* //-- #1. Get Module --//
* var HashMap = require('tui-code-snippet').HashMap; // node, commonjs
* var HashMap = tui.util.HashMap; // distribution file
*
* //-- #2. Use property --//
* var hm = new HashMap();
* hm.set('key', 'value');
* hm.set('key2', 'value');
* hm.removeByKeyArray(['key', 'key2']);
*/
HashMap.prototype.removeByKeyArray = function(keyArray) {
var data = [];
var self = this;
collection.forEach(keyArray, function(key) {
data.push(self.removeByKey(key));
});
return data;
};
/**
* Remove all the data
*/
HashMap.prototype.removeAll = function() {
var self = this;
this.each(function(value, key) {
self.remove(key);
});
};
/**
* Execute the provided callback once for each all the data.
* @param {Function} iteratee Callback function
* @example
* //-- #1. Get Module --//
* var HashMap = require('tui-code-snippet').HashMap; // node, commonjs
* var HashMap = tui.util.HashMap; // distribution file
*
* //-- #2. Use property --//
* var hm = new HashMap();
* hm.set('key', 'value');
* hm.set('key2', 'value');
*
* hm.each(function(value, key) {
* //do something...
* });
*/
HashMap.prototype.each = function(iteratee) {
var self = this;
var flag;
collection.forEachOwnProperties(this, function(value, key) { // eslint-disable-line consistent-return
if (key.charAt(0) === _MAPDATAPREFIX) {
flag = iteratee(value, self.decodeKey(key));
}
if (flag === false) {
return flag;
}
});
};
/**
* Return the key-list stored.
* @returns {Array} A key-list
* @example
* //-- #1. Get Module --//
* var HashMap = require('tui-code-snippet').HashMap; // node, commonjs
* var HashMap = tui.util.HashMap; // distribution file
*
* //-- #2. Use property --//
* var hm = new HashMap();
* hm.set('key', 'value');
* hm.set('key2', 'value');
* hm.keys(); //['key', 'key2');
*/
HashMap.prototype.keys = function() {
var keys = [];
var self = this;
this.each(function(value, key) {
keys.push(self.decodeKey(key));
});
return keys;
};
/**
* Work similarly to Array.prototype.map().<br>
* It executes the provided callback that checks conditions once for each element of hashMap,<br>
* and returns a new array having elements satisfying the conditions
* @param {Function} condition A function that checks conditions
* @returns {Array} A new array having elements satisfying the conditions
* @example
* //-- #1. Get Module --//
* var HashMap = require('tui-code-snippet').HashMap; // node, commonjs
* var HashMap = tui.util.HashMap; // distribution file
*
* //-- #2. Use property --//
* var hm1 = new HashMap();
* hm1.set('key', 'value');
* hm1.set('key2', 'value');
*
* hm1.find(function(value, key) {
* return key === 'key2';
* }); // ['value']
*
* var hm2 = new HashMap({
* 'myobj1': {
* visible: true
* },
* 'mybobj2': {
* visible: false
* }
* });
*
* hm2.find(function(obj, key) {
* return obj.visible === true;
* }); // [{visible: true}];
*/
HashMap.prototype.find = function(condition) {
var founds = [];
this.each(function(value, key) {
if (condition(value, key)) {
founds.push(value);
}
});
return founds;
};
/**
* Return a new Array having all values.
* @returns {Array} A new array having all values
*/
HashMap.prototype.toArray = function() {
var result = [];
this.each(function(v) {
result.push(v);
});
return result;
};
module.exports = HashMap;
/***/ })
/******/ ])
});
;