How to use delta method in mountebank

Best JavaScript code snippet using mountebank

CachedMap.js

Source:CachedMap.js Github

copy

Full Screen

1import React from 'react';2import {3 Text,4 View,5 Dimensions,6 StyleSheet,7 ListView,8 TouchableOpacity,9} from 'react-native';10import MapView, { ProviderPropType, Marker } from 'react-native-maps';11import flagImg from './assets/flag-blue.png';12const HORIZONTAL_PADDING = 12;13const VERTICAL_PADDING = 6;14class CachedMap extends React.Component {15 constructor(props) {16 super(props);17 const ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1 !== r2 });18 this.state = {19 dataSource: ds.cloneWithRows(COUNTRIES),20 cache: true,21 };22 }23 toggleCache() {24 // a hack to force listview to reload with the same data25 this.setState({26 dataSource: this.state.dataSource.cloneWithRows([]),27 });28 this.setState({29 cache: !this.state.cache,30 dataSource: this.state.dataSource.cloneWithRows(COUNTRIES),31 });32 }33 render() {34 const { width } = Dimensions.get('window');35 const mapSize = width - (HORIZONTAL_PADDING * 2);36 return (37 <View style={styles.container}>38 <View style={styles.buttonContainer}>39 <TouchableOpacity40 onPress={() => this.toggleCache()}41 style={[styles.bubble, styles.button]}42 >43 <Text style={styles.buttonText}>{this.state.cache ? 'Cached' : 'Not cached'}</Text>44 </TouchableOpacity>45 </View>46 <ListView47 dataSource={this.state.dataSource}48 renderRow={(region) =>49 <View50 style={styles.item}51 >52 <Text>{region.name}</Text>53 <MapView54 provider={this.props.provider}55 style={{56 width: mapSize,57 height: mapSize,58 }}59 initialRegion={region}60 cacheEnabled={this.state.cache}61 zoomEnabled62 scrollingEnabled63 loadingIndicatorColor="#666666"64 loadingBackgroundColor="#eeeeee"65 >66 <Marker67 coordinate={region}68 centerOffset={{ x: -18, y: -60 }}69 anchor={{ x: 0.69, y: 1 }}70 image={flagImg}71 />72 </MapView>73 <View style={styles.divider} />74 </View>75 }76 />77 </View>78 );79 }80}81CachedMap.propTypes = {82 provider: ProviderPropType,83};84const styles = StyleSheet.create({85 container: {86 flex: 1,87 },88 item: {89 backgroundColor: 'white',90 paddingHorizontal: HORIZONTAL_PADDING,91 paddingVertical: VERTICAL_PADDING,92 },93 bubble: {94 backgroundColor: 'rgba(0,128,255,1.0)',95 paddingHorizontal: 18,96 paddingVertical: 12,97 borderRadius: 20,98 },99 button: {100 width: 100,101 paddingHorizontal: 12,102 alignItems: 'center',103 marginHorizontal: 10,104 },105 buttonContainer: {106 flexDirection: 'row',107 marginVertical: 20,108 backgroundColor: 'transparent',109 justifyContent: 'flex-end',110 },111 buttonText: {112 color: 'white',113 },114});115const COUNTRIES = [116 {117 latitude: 33.93911,118 longitudeDelta: 10.0,119 name: 'Afghanistan',120 longitude: 67.709953,121 latitudeDelta: 10.0,122 },123 {124 latitude: 41.153332,125 longitudeDelta: 10.0,126 name: 'Albania',127 longitude: 20.168331,128 latitudeDelta: 10.0,129 },130 {131 latitude: 28.033886,132 longitudeDelta: 10.0,133 name: 'Algeria',134 longitude: 1.659626,135 latitudeDelta: 10.0,136 },137 {138 latitude: -14.270972,139 longitudeDelta: 10.0,140 name: 'American Samoa',141 longitude: -170.132217,142 latitudeDelta: 10.0,143 },144 {145 latitude: 42.546245,146 longitudeDelta: 10.0,147 name: 'Andorra',148 longitude: 1.601554,149 latitudeDelta: 10.0,150 },151 {152 latitude: -11.202692,153 longitudeDelta: 10.0,154 name: 'Angola',155 longitude: 17.873887,156 latitudeDelta: 10.0,157 },158 {159 latitude: 18.220554,160 longitudeDelta: 10.0,161 name: 'Anguilla',162 longitude: -63.068615,163 latitudeDelta: 10.0,164 },165 {166 latitude: -75.250973,167 longitudeDelta: 10.0,168 name: 'Antarctica',169 longitude: -0.071389,170 latitudeDelta: 10.0,171 },172 {173 latitude: 17.060816,174 longitudeDelta: 10.0,175 name: 'Antigua and Barbuda',176 longitude: -61.796428,177 latitudeDelta: 10.0,178 },179 {180 latitude: -38.416097,181 longitudeDelta: 10.0,182 name: 'Argentina',183 longitude: -63.616672,184 latitudeDelta: 10.0,185 },186 {187 latitude: 40.069099,188 longitudeDelta: 10.0,189 name: 'Armenia',190 longitude: 45.038189,191 latitudeDelta: 10.0,192 },193 {194 latitude: 12.52111,195 longitudeDelta: 10.0,196 name: 'Aruba',197 longitude: -69.968338,198 latitudeDelta: 10.0,199 },200 {201 latitude: -25.274398,202 longitudeDelta: 10.0,203 name: 'Australia',204 longitude: 133.775136,205 latitudeDelta: 10.0,206 },207 {208 latitude: 47.516231,209 longitudeDelta: 10.0,210 name: 'Austria',211 longitude: 14.550072,212 latitudeDelta: 10.0,213 },214 {215 latitude: 40.143105,216 longitudeDelta: 10.0,217 name: 'Azerbaijan',218 longitude: 47.576927,219 latitudeDelta: 10.0,220 },221 {222 latitude: 25.03428,223 longitudeDelta: 10.0,224 name: 'Bahamas',225 longitude: -77.39628,226 latitudeDelta: 10.0,227 },228 {229 latitude: 25.930414,230 longitudeDelta: 10.0,231 name: 'Bahrain',232 longitude: 50.637772,233 latitudeDelta: 10.0,234 },235 {236 latitude: 23.684994,237 longitudeDelta: 10.0,238 name: 'Bangladesh',239 longitude: 90.356331,240 latitudeDelta: 10.0,241 },242 {243 latitude: 13.193887,244 longitudeDelta: 10.0,245 name: 'Barbados',246 longitude: -59.543198,247 latitudeDelta: 10.0,248 },249 {250 latitude: 53.709807,251 longitudeDelta: 10.0,252 name: 'Belarus',253 longitude: 27.953389,254 latitudeDelta: 10.0,255 },256 {257 latitude: 50.503887,258 longitudeDelta: 10.0,259 name: 'Belgium',260 longitude: 4.469936,261 latitudeDelta: 10.0,262 },263 {264 latitude: 17.189877,265 longitudeDelta: 10.0,266 name: 'Belize',267 longitude: -88.49765,268 latitudeDelta: 10.0,269 },270 {271 latitude: 9.30769,272 longitudeDelta: 10.0,273 name: 'Benin',274 longitude: 2.315834,275 latitudeDelta: 10.0,276 },277 {278 latitude: 32.321384,279 longitudeDelta: 10.0,280 name: 'Bermuda',281 longitude: -64.75737,282 latitudeDelta: 10.0,283 },284 {285 latitude: 27.514162,286 longitudeDelta: 10.0,287 name: 'Bhutan',288 longitude: 90.433601,289 latitudeDelta: 10.0,290 },291 {292 latitude: -16.290154,293 longitudeDelta: 10.0,294 name: 'Bolivia',295 longitude: -63.588653,296 latitudeDelta: 10.0,297 },298 {299 latitude: 43.915886,300 longitudeDelta: 10.0,301 name: 'Bosnia and Herzegovina',302 longitude: 17.679076,303 latitudeDelta: 10.0,304 },305 {306 latitude: -22.328474,307 longitudeDelta: 10.0,308 name: 'Botswana',309 longitude: 24.684866,310 latitudeDelta: 10.0,311 },312 {313 latitude: -54.423199,314 longitudeDelta: 10.0,315 name: 'Bouvet Island',316 longitude: 3.413194,317 latitudeDelta: 10.0,318 },319 {320 latitude: -14.235004,321 longitudeDelta: 10.0,322 name: 'Brazil',323 longitude: -51.92528,324 latitudeDelta: 10.0,325 },326 {327 latitude: -6.343194,328 longitudeDelta: 10.0,329 name: 'British Indian Ocean Territory',330 longitude: 71.876519,331 latitudeDelta: 10.0,332 },333 {334 latitude: 18.420695,335 longitudeDelta: 10.0,336 name: 'British Virgin Islands',337 longitude: -64.639968,338 latitudeDelta: 10.0,339 },340 {341 latitude: 4.535277,342 longitudeDelta: 10.0,343 name: 'Brunei',344 longitude: 114.727669,345 latitudeDelta: 10.0,346 },347 {348 latitude: 42.733883,349 longitudeDelta: 10.0,350 name: 'Bulgaria',351 longitude: 25.48583,352 latitudeDelta: 10.0,353 },354 {355 latitude: 12.238333,356 longitudeDelta: 10.0,357 name: 'Burkina Faso',358 longitude: -1.561593,359 latitudeDelta: 10.0,360 },361 {362 latitude: -3.373056,363 longitudeDelta: 10.0,364 name: 'Burundi',365 longitude: 29.918886,366 latitudeDelta: 10.0,367 },368 {369 latitude: 12.565679,370 longitudeDelta: 10.0,371 name: 'Cambodia',372 longitude: 104.990963,373 latitudeDelta: 10.0,374 },375 {376 latitude: 7.369722,377 longitudeDelta: 10.0,378 name: 'Cameroon',379 longitude: 12.354722,380 latitudeDelta: 10.0,381 },382 {383 latitude: 56.130366,384 longitudeDelta: 10.0,385 name: 'Canada',386 longitude: -106.346771,387 latitudeDelta: 10.0,388 },389 {390 latitude: 16.002082,391 longitudeDelta: 10.0,392 name: 'Cape Verde',393 longitude: -24.013197,394 latitudeDelta: 10.0,395 },396 {397 latitude: 19.513469,398 longitudeDelta: 10.0,399 name: 'Cayman Islands',400 longitude: -80.566956,401 latitudeDelta: 10.0,402 },403 {404 latitude: 6.611111,405 longitudeDelta: 10.0,406 name: 'Central African Republic',407 longitude: 20.939444,408 latitudeDelta: 10.0,409 },410 {411 latitude: 15.454166,412 longitudeDelta: 10.0,413 name: 'Chad',414 longitude: 18.732207,415 latitudeDelta: 10.0,416 },417 {418 latitude: -35.675147,419 longitudeDelta: 10.0,420 name: 'Chile',421 longitude: -71.542969,422 latitudeDelta: 10.0,423 },424 {425 latitude: 35.86166,426 longitudeDelta: 10.0,427 name: 'China',428 longitude: 104.195397,429 latitudeDelta: 10.0,430 },431 {432 latitude: -10.447525,433 longitudeDelta: 10.0,434 name: 'Christmas Island',435 longitude: 105.690449,436 latitudeDelta: 10.0,437 },438 {439 latitude: -12.164165,440 longitudeDelta: 10.0,441 name: 'Cocos [Keeling] Islands',442 longitude: 96.870956,443 latitudeDelta: 10.0,444 },445 {446 latitude: 4.570868,447 longitudeDelta: 10.0,448 name: 'Colombia',449 longitude: -74.297333,450 latitudeDelta: 10.0,451 },452 {453 latitude: -11.875001,454 longitudeDelta: 10.0,455 name: 'Comoros',456 longitude: 43.872219,457 latitudeDelta: 10.0,458 },459 {460 latitude: -4.038333,461 longitudeDelta: 10.0,462 name: 'Congo [DRC]',463 longitude: 21.758664,464 latitudeDelta: 10.0,465 },466 {467 latitude: -0.228021,468 longitudeDelta: 10.0,469 name: 'Congo [Republic]',470 longitude: 15.827659,471 latitudeDelta: 10.0,472 },473 {474 latitude: -21.236736,475 longitudeDelta: 10.0,476 name: 'Cook Islands',477 longitude: -159.777671,478 latitudeDelta: 10.0,479 },480 {481 latitude: 9.748917,482 longitudeDelta: 10.0,483 name: 'Costa Rica',484 longitude: -83.753428,485 latitudeDelta: 10.0,486 },487 {488 latitude: 45.1,489 longitudeDelta: 10.0,490 name: 'Croatia',491 longitude: 15.2,492 latitudeDelta: 10.0,493 },494 {495 latitude: 21.521757,496 longitudeDelta: 10.0,497 name: 'Cuba',498 longitude: -77.781167,499 latitudeDelta: 10.0,500 },501 {502 latitude: 35.126413,503 longitudeDelta: 10.0,504 name: 'Cyprus',505 longitude: 33.429859,506 latitudeDelta: 10.0,507 },508 {509 latitude: 49.817492,510 longitudeDelta: 10.0,511 name: 'Czech Republic',512 longitude: 15.472962,513 latitudeDelta: 10.0,514 },515 {516 latitude: 7.539989,517 longitudeDelta: 10.0,518 name: "C\u00f4te d'Ivoire",519 longitude: -5.54708,520 latitudeDelta: 10.0,521 },522 {523 latitude: 56.26392,524 longitudeDelta: 10.0,525 name: 'Denmark',526 longitude: 9.501785,527 latitudeDelta: 10.0,528 },529 {530 latitude: 11.825138,531 longitudeDelta: 10.0,532 name: 'Djibouti',533 longitude: 42.590275,534 latitudeDelta: 10.0,535 },536 {537 latitude: 15.414999,538 longitudeDelta: 10.0,539 name: 'Dominica',540 longitude: -61.370976,541 latitudeDelta: 10.0,542 },543 {544 latitude: 18.735693,545 longitudeDelta: 10.0,546 name: 'Dominican Republic',547 longitude: -70.162651,548 latitudeDelta: 10.0,549 },550 {551 latitude: -1.831239,552 longitudeDelta: 10.0,553 name: 'Ecuador',554 longitude: -78.183406,555 latitudeDelta: 10.0,556 },557 {558 latitude: 26.820553,559 longitudeDelta: 10.0,560 name: 'Egypt',561 longitude: 30.802498,562 latitudeDelta: 10.0,563 },564 {565 latitude: 13.794185,566 longitudeDelta: 10.0,567 name: 'El Salvador',568 longitude: -88.89653,569 latitudeDelta: 10.0,570 },571 {572 latitude: 1.650801,573 longitudeDelta: 10.0,574 name: 'Equatorial Guinea',575 longitude: 10.267895,576 latitudeDelta: 10.0,577 },578 {579 latitude: 15.179384,580 longitudeDelta: 10.0,581 name: 'Eritrea',582 longitude: 39.782334,583 latitudeDelta: 10.0,584 },585 {586 latitude: 58.595272,587 longitudeDelta: 10.0,588 name: 'Estonia',589 longitude: 25.013607,590 latitudeDelta: 10.0,591 },592 {593 latitude: 9.145,594 longitudeDelta: 10.0,595 name: 'Ethiopia',596 longitude: 40.489673,597 latitudeDelta: 10.0,598 },599 {600 latitude: -51.796253,601 longitudeDelta: 10.0,602 name: 'Falkland Islands [Islas Malvinas]',603 longitude: -59.523613,604 latitudeDelta: 10.0,605 },606 {607 latitude: 61.892635,608 longitudeDelta: 10.0,609 name: 'Faroe Islands',610 longitude: -6.911806,611 latitudeDelta: 10.0,612 },613 {614 latitude: -16.578193,615 longitudeDelta: 10.0,616 name: 'Fiji',617 longitude: 179.414413,618 latitudeDelta: 10.0,619 },620 {621 latitude: 61.92411,622 longitudeDelta: 10.0,623 name: 'Finland',624 longitude: 25.748151,625 latitudeDelta: 10.0,626 },627 {628 latitude: 46.227638,629 longitudeDelta: 10.0,630 name: 'France',631 longitude: 2.213749,632 latitudeDelta: 10.0,633 },634 {635 latitude: 3.933889,636 longitudeDelta: 10.0,637 name: 'French Guiana',638 longitude: -53.125782,639 latitudeDelta: 10.0,640 },641 {642 latitude: -17.679742,643 longitudeDelta: 10.0,644 name: 'French Polynesia',645 longitude: -149.406843,646 latitudeDelta: 10.0,647 },648 {649 latitude: -49.280366,650 longitudeDelta: 10.0,651 name: 'French Southern Territories',652 longitude: 69.348557,653 latitudeDelta: 10.0,654 },655 {656 latitude: -0.803689,657 longitudeDelta: 10.0,658 name: 'Gabon',659 longitude: 11.609444,660 latitudeDelta: 10.0,661 },662 {663 latitude: 13.443182,664 longitudeDelta: 10.0,665 name: 'Gambia',666 longitude: -15.310139,667 latitudeDelta: 10.0,668 },669 {670 latitude: 31.354676,671 longitudeDelta: 10.0,672 name: 'Gaza Strip',673 longitude: 34.308825,674 latitudeDelta: 10.0,675 },676 {677 latitude: 42.315407,678 longitudeDelta: 10.0,679 name: 'Georgia',680 longitude: 43.356892,681 latitudeDelta: 10.0,682 },683 {684 latitude: 51.165691,685 longitudeDelta: 10.0,686 name: 'Germany',687 longitude: 10.451526,688 latitudeDelta: 10.0,689 },690 {691 latitude: 7.946527,692 longitudeDelta: 10.0,693 name: 'Ghana',694 longitude: -1.023194,695 latitudeDelta: 10.0,696 },697 {698 latitude: 36.137741,699 longitudeDelta: 10.0,700 name: 'Gibraltar',701 longitude: -5.345374,702 latitudeDelta: 10.0,703 },704 {705 latitude: 39.074208,706 longitudeDelta: 10.0,707 name: 'Greece',708 longitude: 21.824312,709 latitudeDelta: 10.0,710 },711 {712 latitude: 71.706936,713 longitudeDelta: 10.0,714 name: 'Greenland',715 longitude: -42.604303,716 latitudeDelta: 10.0,717 },718 {719 latitude: 12.262776,720 longitudeDelta: 10.0,721 name: 'Grenada',722 longitude: -61.604171,723 latitudeDelta: 10.0,724 },725 {726 latitude: 16.995971,727 longitudeDelta: 10.0,728 name: 'Guadeloupe',729 longitude: -62.067641,730 latitudeDelta: 10.0,731 },732 {733 latitude: 13.444304,734 longitudeDelta: 10.0,735 name: 'Guam',736 longitude: 144.793731,737 latitudeDelta: 10.0,738 },739 {740 latitude: 15.783471,741 longitudeDelta: 10.0,742 name: 'Guatemala',743 longitude: -90.230759,744 latitudeDelta: 10.0,745 },746 {747 latitude: 49.465691,748 longitudeDelta: 10.0,749 name: 'Guernsey',750 longitude: -2.585278,751 latitudeDelta: 10.0,752 },753 {754 latitude: 9.945587,755 longitudeDelta: 10.0,756 name: 'Guinea',757 longitude: -9.696645,758 latitudeDelta: 10.0,759 },760 {761 latitude: 11.803749,762 longitudeDelta: 10.0,763 name: 'Guinea-Bissau',764 longitude: -15.180413,765 latitudeDelta: 10.0,766 },767 {768 latitude: 4.860416,769 longitudeDelta: 10.0,770 name: 'Guyana',771 longitude: -58.93018,772 latitudeDelta: 10.0,773 },774 {775 latitude: 18.971187,776 longitudeDelta: 10.0,777 name: 'Haiti',778 longitude: -72.285215,779 latitudeDelta: 10.0,780 },781 {782 latitude: -53.08181,783 longitudeDelta: 10.0,784 name: 'Heard Island and McDonald Islands',785 longitude: 73.504158,786 latitudeDelta: 10.0,787 },788 {789 latitude: 15.199999,790 longitudeDelta: 10.0,791 name: 'Honduras',792 longitude: -86.241905,793 latitudeDelta: 10.0,794 },795 {796 latitude: 22.396428,797 longitudeDelta: 10.0,798 name: 'Hong Kong',799 longitude: 114.109497,800 latitudeDelta: 10.0,801 },802 {803 latitude: 47.162494,804 longitudeDelta: 10.0,805 name: 'Hungary',806 longitude: 19.503304,807 latitudeDelta: 10.0,808 },809 {810 latitude: 64.963051,811 longitudeDelta: 10.0,812 name: 'Iceland',813 longitude: -19.020835,814 latitudeDelta: 10.0,815 },816 {817 latitude: 20.593684,818 longitudeDelta: 10.0,819 name: 'India',820 longitude: 78.96288,821 latitudeDelta: 10.0,822 },823 {824 latitude: -0.789275,825 longitudeDelta: 10.0,826 name: 'Indonesia',827 longitude: 113.921327,828 latitudeDelta: 10.0,829 },830 {831 latitude: 32.427908,832 longitudeDelta: 10.0,833 name: 'Iran',834 longitude: 53.688046,835 latitudeDelta: 10.0,836 },837 {838 latitude: 33.223191,839 longitudeDelta: 10.0,840 name: 'Iraq',841 longitude: 43.679291,842 latitudeDelta: 10.0,843 },844 {845 latitude: 53.41291,846 longitudeDelta: 10.0,847 name: 'Ireland',848 longitude: -8.24389,849 latitudeDelta: 10.0,850 },851 {852 latitude: 54.236107,853 longitudeDelta: 10.0,854 name: 'Isle of Man',855 longitude: -4.548056,856 latitudeDelta: 10.0,857 },858 {859 latitude: 31.046051,860 longitudeDelta: 10.0,861 name: 'Israel',862 longitude: 34.851612,863 latitudeDelta: 10.0,864 },865 {866 latitude: 41.87194,867 longitudeDelta: 10.0,868 name: 'Italy',869 longitude: 12.56738,870 latitudeDelta: 10.0,871 },872 {873 latitude: 18.109581,874 longitudeDelta: 10.0,875 name: 'Jamaica',876 longitude: -77.297508,877 latitudeDelta: 10.0,878 },879 {880 latitude: 36.204824,881 longitudeDelta: 10.0,882 name: 'Japan',883 longitude: 138.252924,884 latitudeDelta: 10.0,885 },886 {887 latitude: 49.214439,888 longitudeDelta: 10.0,889 name: 'Jersey',890 longitude: -2.13125,891 latitudeDelta: 10.0,892 },893 {894 latitude: 30.585164,895 longitudeDelta: 10.0,896 name: 'Jordan',897 longitude: 36.238414,898 latitudeDelta: 10.0,899 },900 {901 latitude: 48.019573,902 longitudeDelta: 10.0,903 name: 'Kazakhstan',904 longitude: 66.923684,905 latitudeDelta: 10.0,906 },907 {908 latitude: -0.023559,909 longitudeDelta: 10.0,910 name: 'Kenya',911 longitude: 37.906193,912 latitudeDelta: 10.0,913 },914 {915 latitude: -3.370417,916 longitudeDelta: 10.0,917 name: 'Kiribati',918 longitude: -168.734039,919 latitudeDelta: 10.0,920 },921 {922 latitude: 42.602636,923 longitudeDelta: 10.0,924 name: 'Kosovo',925 longitude: 20.902977,926 latitudeDelta: 10.0,927 },928 {929 latitude: 29.31166,930 longitudeDelta: 10.0,931 name: 'Kuwait',932 longitude: 47.481766,933 latitudeDelta: 10.0,934 },935 {936 latitude: 41.20438,937 longitudeDelta: 10.0,938 name: 'Kyrgyzstan',939 longitude: 74.766098,940 latitudeDelta: 10.0,941 },942 {943 latitude: 19.85627,944 longitudeDelta: 10.0,945 name: 'Laos',946 longitude: 102.495496,947 latitudeDelta: 10.0,948 },949 {950 latitude: 56.879635,951 longitudeDelta: 10.0,952 name: 'Latvia',953 longitude: 24.603189,954 latitudeDelta: 10.0,955 },956 {957 latitude: 33.854721,958 longitudeDelta: 10.0,959 name: 'Lebanon',960 longitude: 35.862285,961 latitudeDelta: 10.0,962 },963 {964 latitude: -29.609988,965 longitudeDelta: 10.0,966 name: 'Lesotho',967 longitude: 28.233608,968 latitudeDelta: 10.0,969 },970 {971 latitude: 6.428055,972 longitudeDelta: 10.0,973 name: 'Liberia',974 longitude: -9.429499,975 latitudeDelta: 10.0,976 },977 {978 latitude: 26.3351,979 longitudeDelta: 10.0,980 name: 'Libya',981 longitude: 17.228331,982 latitudeDelta: 10.0,983 },984 {985 latitude: 47.166,986 longitudeDelta: 10.0,987 name: 'Liechtenstein',988 longitude: 9.555373,989 latitudeDelta: 10.0,990 },991 {992 latitude: 55.169438,993 longitudeDelta: 10.0,994 name: 'Lithuania',995 longitude: 23.881275,996 latitudeDelta: 10.0,997 },998 {999 latitude: 49.815273,1000 longitudeDelta: 10.0,1001 name: 'Luxembourg',1002 longitude: 6.129583,1003 latitudeDelta: 10.0,1004 },1005 {1006 latitude: 22.198745,1007 longitudeDelta: 10.0,1008 name: 'Macau',1009 longitude: 113.543873,1010 latitudeDelta: 10.0,1011 },1012 {1013 latitude: 41.608635,1014 longitudeDelta: 10.0,1015 name: 'Macedonia [FYROM]',1016 longitude: 21.745275,1017 latitudeDelta: 10.0,1018 },1019 {1020 latitude: -18.766947,1021 longitudeDelta: 10.0,1022 name: 'Madagascar',1023 longitude: 46.869107,1024 latitudeDelta: 10.0,1025 },1026 {1027 latitude: -13.254308,1028 longitudeDelta: 10.0,1029 name: 'Malawi',1030 longitude: 34.301525,1031 latitudeDelta: 10.0,1032 },1033 {1034 latitude: 4.210484,1035 longitudeDelta: 10.0,1036 name: 'Malaysia',1037 longitude: 101.975766,1038 latitudeDelta: 10.0,1039 },1040 {1041 latitude: 3.202778,1042 longitudeDelta: 10.0,1043 name: 'Maldives',1044 longitude: 73.22068,1045 latitudeDelta: 10.0,1046 },1047 {1048 latitude: 17.570692,1049 longitudeDelta: 10.0,1050 name: 'Mali',1051 longitude: -3.996166,1052 latitudeDelta: 10.0,1053 },1054 {1055 latitude: 35.937496,1056 longitudeDelta: 10.0,1057 name: 'Malta',1058 longitude: 14.375416,1059 latitudeDelta: 10.0,1060 },1061 {1062 latitude: 7.131474,1063 longitudeDelta: 10.0,1064 name: 'Marshall Islands',1065 longitude: 171.184478,1066 latitudeDelta: 10.0,1067 },1068 {1069 latitude: 14.641528,1070 longitudeDelta: 10.0,1071 name: 'Martinique',1072 longitude: -61.024174,1073 latitudeDelta: 10.0,1074 },1075 {1076 latitude: 21.00789,1077 longitudeDelta: 10.0,1078 name: 'Mauritania',1079 longitude: -10.940835,1080 latitudeDelta: 10.0,1081 },1082 {1083 latitude: -20.348404,1084 longitudeDelta: 10.0,1085 name: 'Mauritius',1086 longitude: 57.552152,1087 latitudeDelta: 10.0,1088 },1089 {1090 latitude: -12.8275,1091 longitudeDelta: 10.0,1092 name: 'Mayotte',1093 longitude: 45.166244,1094 latitudeDelta: 10.0,1095 },1096 {1097 latitude: 23.634501,1098 longitudeDelta: 10.0,1099 name: 'Mexico',1100 longitude: -102.552784,1101 latitudeDelta: 10.0,1102 },1103 {1104 latitude: 7.425554,1105 longitudeDelta: 10.0,1106 name: 'Micronesia',1107 longitude: 150.550812,1108 latitudeDelta: 10.0,1109 },1110 {1111 latitude: 47.411631,1112 longitudeDelta: 10.0,1113 name: 'Moldova',1114 longitude: 28.369885,1115 latitudeDelta: 10.0,1116 },1117 {1118 latitude: 43.750298,1119 longitudeDelta: 10.0,1120 name: 'Monaco',1121 longitude: 7.412841,1122 latitudeDelta: 10.0,1123 },1124 {1125 latitude: 46.862496,1126 longitudeDelta: 10.0,1127 name: 'Mongolia',1128 longitude: 103.846656,1129 latitudeDelta: 10.0,1130 },1131 {1132 latitude: 42.708678,1133 longitudeDelta: 10.0,1134 name: 'Montenegro',1135 longitude: 19.37439,1136 latitudeDelta: 10.0,1137 },1138 {1139 latitude: 16.742498,1140 longitudeDelta: 10.0,1141 name: 'Montserrat',1142 longitude: -62.187366,1143 latitudeDelta: 10.0,1144 },1145 {1146 latitude: 31.791702,1147 longitudeDelta: 10.0,1148 name: 'Morocco',1149 longitude: -7.09262,1150 latitudeDelta: 10.0,1151 },1152 {1153 latitude: -18.665695,1154 longitudeDelta: 10.0,1155 name: 'Mozambique',1156 longitude: 35.529562,1157 latitudeDelta: 10.0,1158 },1159 {1160 latitude: 21.913965,1161 longitudeDelta: 10.0,1162 name: 'Myanmar [Burma]',1163 longitude: 95.956223,1164 latitudeDelta: 10.0,1165 },1166 {1167 latitude: -22.95764,1168 longitudeDelta: 10.0,1169 name: 'Namibia',1170 longitude: 18.49041,1171 latitudeDelta: 10.0,1172 },1173 {1174 latitude: -0.522778,1175 longitudeDelta: 10.0,1176 name: 'Nauru',1177 longitude: 166.931503,1178 latitudeDelta: 10.0,1179 },1180 {1181 latitude: 28.394857,1182 longitudeDelta: 10.0,1183 name: 'Nepal',1184 longitude: 84.124008,1185 latitudeDelta: 10.0,1186 },1187 {1188 latitude: 52.132633,1189 longitudeDelta: 10.0,1190 name: 'Netherlands',1191 longitude: 5.291266,1192 latitudeDelta: 10.0,1193 },1194 {1195 latitude: 12.226079,1196 longitudeDelta: 10.0,1197 name: 'Netherlands Antilles',1198 longitude: -69.060087,1199 latitudeDelta: 10.0,1200 },1201 {1202 latitude: -20.904305,1203 longitudeDelta: 10.0,1204 name: 'New Caledonia',1205 longitude: 165.618042,1206 latitudeDelta: 10.0,1207 },1208 {1209 latitude: -40.900557,1210 longitudeDelta: 10.0,1211 name: 'New Zealand',1212 longitude: 174.885971,1213 latitudeDelta: 10.0,1214 },1215 {1216 latitude: 12.865416,1217 longitudeDelta: 10.0,1218 name: 'Nicaragua',1219 longitude: -85.207229,1220 latitudeDelta: 10.0,1221 },1222 {1223 latitude: 17.607789,1224 longitudeDelta: 10.0,1225 name: 'Niger',1226 longitude: 8.081666,1227 latitudeDelta: 10.0,1228 },1229 {1230 latitude: 9.081999,1231 longitudeDelta: 10.0,1232 name: 'Nigeria',1233 longitude: 8.675277,1234 latitudeDelta: 10.0,1235 },1236 {1237 latitude: -19.054445,1238 longitudeDelta: 10.0,1239 name: 'Niue',1240 longitude: -169.867233,1241 latitudeDelta: 10.0,1242 },1243 {1244 latitude: -29.040835,1245 longitudeDelta: 10.0,1246 name: 'Norfolk Island',1247 longitude: 167.954712,1248 latitudeDelta: 10.0,1249 },1250 {1251 latitude: 40.339852,1252 longitudeDelta: 10.0,1253 name: 'North Korea',1254 longitude: 127.510093,1255 latitudeDelta: 10.0,1256 },1257 {1258 latitude: 17.33083,1259 longitudeDelta: 10.0,1260 name: 'Northern Mariana Islands',1261 longitude: 145.38469,1262 latitudeDelta: 10.0,1263 },1264 {1265 latitude: 60.472024,1266 longitudeDelta: 10.0,1267 name: 'Norway',1268 longitude: 8.468946,1269 latitudeDelta: 10.0,1270 },1271 {1272 latitude: 21.512583,1273 longitudeDelta: 10.0,1274 name: 'Oman',1275 longitude: 55.923255,1276 latitudeDelta: 10.0,1277 },1278 {1279 latitude: 30.375321,1280 longitudeDelta: 10.0,1281 name: 'Pakistan',1282 longitude: 69.345116,1283 latitudeDelta: 10.0,1284 },1285 {1286 latitude: 7.51498,1287 longitudeDelta: 10.0,1288 name: 'Palau',1289 longitude: 134.58252,1290 latitudeDelta: 10.0,1291 },1292 {1293 latitude: 31.952162,1294 longitudeDelta: 10.0,1295 name: 'Palestinian Territories',1296 longitude: 35.233154,1297 latitudeDelta: 10.0,1298 },1299 {1300 latitude: 8.537981,1301 longitudeDelta: 10.0,1302 name: 'Panama',1303 longitude: -80.782127,1304 latitudeDelta: 10.0,1305 },1306 {1307 latitude: -6.314993,1308 longitudeDelta: 10.0,1309 name: 'Papua New Guinea',1310 longitude: 143.95555,1311 latitudeDelta: 10.0,1312 },1313 {1314 latitude: -23.442503,1315 longitudeDelta: 10.0,1316 name: 'Paraguay',1317 longitude: -58.443832,1318 latitudeDelta: 10.0,1319 },1320 {1321 latitude: -9.189967,1322 longitudeDelta: 10.0,1323 name: 'Peru',1324 longitude: -75.015152,1325 latitudeDelta: 10.0,1326 },1327 {1328 latitude: 12.879721,1329 longitudeDelta: 10.0,1330 name: 'Philippines',1331 longitude: 121.774017,1332 latitudeDelta: 10.0,1333 },1334 {1335 latitude: -24.703615,1336 longitudeDelta: 10.0,1337 name: 'Pitcairn Islands',1338 longitude: -127.439308,1339 latitudeDelta: 10.0,1340 },1341 {1342 latitude: 51.919438,1343 longitudeDelta: 10.0,1344 name: 'Poland',1345 longitude: 19.145136,1346 latitudeDelta: 10.0,1347 },1348 {1349 latitude: 39.399872,1350 longitudeDelta: 10.0,1351 name: 'Portugal',1352 longitude: -8.224454,1353 latitudeDelta: 10.0,1354 },1355 {1356 latitude: 18.220833,1357 longitudeDelta: 10.0,1358 name: 'Puerto Rico',1359 longitude: -66.590149,1360 latitudeDelta: 10.0,1361 },1362 {1363 latitude: 25.354826,1364 longitudeDelta: 10.0,1365 name: 'Qatar',1366 longitude: 51.183884,1367 latitudeDelta: 10.0,1368 },1369 {1370 latitude: 45.943161,1371 longitudeDelta: 10.0,1372 name: 'Romania',1373 longitude: 24.96676,1374 latitudeDelta: 10.0,1375 },1376 {1377 latitude: 61.52401,1378 longitudeDelta: 10.0,1379 name: 'Russia',1380 longitude: 105.318756,1381 latitudeDelta: 10.0,1382 },1383 {1384 latitude: -1.940278,1385 longitudeDelta: 10.0,1386 name: 'Rwanda',1387 longitude: 29.873888,1388 latitudeDelta: 10.0,1389 },1390 {1391 latitude: -21.115141,1392 longitudeDelta: 10.0,1393 name: 'R\u00e9union',1394 longitude: 55.536384,1395 latitudeDelta: 10.0,1396 },1397 {1398 latitude: -24.143474,1399 longitudeDelta: 10.0,1400 name: 'Saint Helena',1401 longitude: -10.030696,1402 latitudeDelta: 10.0,1403 },1404 {1405 latitude: 17.357822,1406 longitudeDelta: 10.0,1407 name: 'Saint Kitts and Nevis',1408 longitude: -62.782998,1409 latitudeDelta: 10.0,1410 },1411 {1412 latitude: 13.909444,1413 longitudeDelta: 10.0,1414 name: 'Saint Lucia',1415 longitude: -60.978893,1416 latitudeDelta: 10.0,1417 },1418 {1419 latitude: 46.941936,1420 longitudeDelta: 10.0,1421 name: 'Saint Pierre and Miquelon',1422 longitude: -56.27111,1423 latitudeDelta: 10.0,1424 },1425 {1426 latitude: 12.984305,1427 longitudeDelta: 10.0,1428 name: 'Saint Vincent and the Grenadines',1429 longitude: -61.287228,1430 latitudeDelta: 10.0,1431 },1432 {1433 latitude: -13.759029,1434 longitudeDelta: 10.0,1435 name: 'Samoa',1436 longitude: -172.104629,1437 latitudeDelta: 10.0,1438 },1439 {1440 latitude: 43.94236,1441 longitudeDelta: 10.0,1442 name: 'San Marino',1443 longitude: 12.457777,1444 latitudeDelta: 10.0,1445 },1446 {1447 latitude: 23.885942,1448 longitudeDelta: 10.0,1449 name: 'Saudi Arabia',1450 longitude: 45.079162,1451 latitudeDelta: 10.0,1452 },1453 {1454 latitude: 14.497401,1455 longitudeDelta: 10.0,1456 name: 'Senegal',1457 longitude: -14.452362,1458 latitudeDelta: 10.0,1459 },1460 {1461 latitude: 44.016521,1462 longitudeDelta: 10.0,1463 name: 'Serbia',1464 longitude: 21.005859,1465 latitudeDelta: 10.0,1466 },1467 {1468 latitude: -4.679574,1469 longitudeDelta: 10.0,1470 name: 'Seychelles',1471 longitude: 55.491977,1472 latitudeDelta: 10.0,1473 },1474 {1475 latitude: 8.460555,1476 longitudeDelta: 10.0,1477 name: 'Sierra Leone',1478 longitude: -11.779889,1479 latitudeDelta: 10.0,1480 },1481 {1482 latitude: 1.352083,1483 longitudeDelta: 10.0,1484 name: 'Singapore',1485 longitude: 103.819836,1486 latitudeDelta: 10.0,1487 },1488 {1489 latitude: 48.669026,1490 longitudeDelta: 10.0,1491 name: 'Slovakia',1492 longitude: 19.699024,1493 latitudeDelta: 10.0,1494 },1495 {1496 latitude: 46.151241,1497 longitudeDelta: 10.0,1498 name: 'Slovenia',1499 longitude: 14.995463,1500 latitudeDelta: 10.0,1501 },1502 {1503 latitude: -9.64571,1504 longitudeDelta: 10.0,1505 name: 'Solomon Islands',1506 longitude: 160.156194,1507 latitudeDelta: 10.0,1508 },1509 {1510 latitude: 5.152149,1511 longitudeDelta: 10.0,1512 name: 'Somalia',1513 longitude: 46.199616,1514 latitudeDelta: 10.0,1515 },1516 {1517 latitude: -30.559482,1518 longitudeDelta: 10.0,1519 name: 'South Africa',1520 longitude: 22.937506,1521 latitudeDelta: 10.0,1522 },1523 {1524 latitude: -54.429579,1525 longitudeDelta: 10.0,1526 name: 'South Georgia and the South Sandwich Islands',1527 longitude: -36.587909,1528 latitudeDelta: 10.0,1529 },1530 {1531 latitude: 35.907757,1532 longitudeDelta: 10.0,1533 name: 'South Korea',1534 longitude: 127.766922,1535 latitudeDelta: 10.0,1536 },1537 {1538 latitude: 40.463667,1539 longitudeDelta: 10.0,1540 name: 'Spain',1541 longitude: -3.74922,1542 latitudeDelta: 10.0,1543 },1544 {1545 latitude: 7.873054,1546 longitudeDelta: 10.0,1547 name: 'Sri Lanka',1548 longitude: 80.771797,1549 latitudeDelta: 10.0,1550 },1551 {1552 latitude: 12.862807,1553 longitudeDelta: 10.0,1554 name: 'Sudan',1555 longitude: 30.217636,1556 latitudeDelta: 10.0,1557 },1558 {1559 latitude: 3.919305,1560 longitudeDelta: 10.0,1561 name: 'Suriname',1562 longitude: -56.027783,1563 latitudeDelta: 10.0,1564 },1565 {1566 latitude: 77.553604,1567 longitudeDelta: 10.0,1568 name: 'Svalbard and Jan Mayen',1569 longitude: 23.670272,1570 latitudeDelta: 10.0,1571 },1572 {1573 latitude: -26.522503,1574 longitudeDelta: 10.0,1575 name: 'Swaziland',1576 longitude: 31.465866,1577 latitudeDelta: 10.0,1578 },1579 {1580 latitude: 60.128161,1581 longitudeDelta: 10.0,1582 name: 'Sweden',1583 longitude: 18.643501,1584 latitudeDelta: 10.0,1585 },1586 {1587 latitude: 46.818188,1588 longitudeDelta: 10.0,1589 name: 'Switzerland',1590 longitude: 8.227512,1591 latitudeDelta: 10.0,1592 },1593 {1594 latitude: 34.802075,1595 longitudeDelta: 10.0,1596 name: 'Syria',1597 longitude: 38.996815,1598 latitudeDelta: 10.0,1599 },1600 {1601 latitude: 0.18636,1602 longitudeDelta: 10.0,1603 name: 'S\u00e3o Tom\u00e9 and Pr\u00edncipe',1604 longitude: 6.613081,1605 latitudeDelta: 10.0,1606 },1607 {1608 latitude: 23.69781,1609 longitudeDelta: 10.0,1610 name: 'Taiwan',1611 longitude: 120.960515,1612 latitudeDelta: 10.0,1613 },1614 {1615 latitude: 38.861034,1616 longitudeDelta: 10.0,1617 name: 'Tajikistan',1618 longitude: 71.276093,1619 latitudeDelta: 10.0,1620 },1621 {1622 latitude: -6.369028,1623 longitudeDelta: 10.0,1624 name: 'Tanzania',1625 longitude: 34.888822,1626 latitudeDelta: 10.0,1627 },1628 {1629 latitude: 15.870032,1630 longitudeDelta: 10.0,1631 name: 'Thailand',1632 longitude: 100.992541,1633 latitudeDelta: 10.0,1634 },1635 {1636 latitude: -8.874217,1637 longitudeDelta: 10.0,1638 name: 'Timor-Leste',1639 longitude: 125.727539,1640 latitudeDelta: 10.0,1641 },1642 {1643 latitude: 8.619543,1644 longitudeDelta: 10.0,1645 name: 'Togo',1646 longitude: 0.824782,1647 latitudeDelta: 10.0,1648 },1649 {1650 latitude: -8.967363,1651 longitudeDelta: 10.0,1652 name: 'Tokelau',1653 longitude: -171.855881,1654 latitudeDelta: 10.0,1655 },1656 {1657 latitude: -21.178986,1658 longitudeDelta: 10.0,1659 name: 'Tonga',1660 longitude: -175.198242,1661 latitudeDelta: 10.0,1662 },1663 {1664 latitude: 10.691803,1665 longitudeDelta: 10.0,1666 name: 'Trinidad and Tobago',1667 longitude: -61.222503,1668 latitudeDelta: 10.0,1669 },1670 {1671 latitude: 33.886917,1672 longitudeDelta: 10.0,1673 name: 'Tunisia',1674 longitude: 9.537499,1675 latitudeDelta: 10.0,1676 },1677 {1678 latitude: 38.963745,1679 longitudeDelta: 10.0,1680 name: 'Turkey',1681 longitude: 35.243322,1682 latitudeDelta: 10.0,1683 },1684 {1685 latitude: 38.969719,1686 longitudeDelta: 10.0,1687 name: 'Turkmenistan',1688 longitude: 59.556278,1689 latitudeDelta: 10.0,1690 },1691 {1692 latitude: 21.694025,1693 longitudeDelta: 10.0,1694 name: 'Turks and Caicos Islands',1695 longitude: -71.797928,1696 latitudeDelta: 10.0,1697 },1698 {1699 latitude: -7.109535,1700 longitudeDelta: 10.0,1701 name: 'Tuvalu',1702 longitude: 177.64933,1703 latitudeDelta: 10.0,1704 },1705 {1706 latitude: 18.335765,1707 longitudeDelta: 10.0,1708 name: 'U.S. Virgin Islands',1709 longitude: -64.896335,1710 latitudeDelta: 10.0,1711 },1712 {1713 latitude: 1.373333,1714 longitudeDelta: 10.0,1715 name: 'Uganda',1716 longitude: 32.290275,1717 latitudeDelta: 10.0,1718 },1719 {1720 latitude: 48.379433,1721 longitudeDelta: 10.0,1722 name: 'Ukraine',1723 longitude: 31.16558,1724 latitudeDelta: 10.0,1725 },1726 {1727 latitude: 23.424076,1728 longitudeDelta: 10.0,1729 name: 'United Arab Emirates',1730 longitude: 53.847818,1731 latitudeDelta: 10.0,1732 },1733 {1734 latitude: 55.378051,1735 longitudeDelta: 10.0,1736 name: 'United Kingdom',1737 longitude: -3.435973,1738 latitudeDelta: 10.0,1739 },1740 {1741 latitude: 37.09024,1742 longitudeDelta: 10.0,1743 name: 'United States',1744 longitude: -95.712891,1745 latitudeDelta: 10.0,1746 },1747 {1748 latitude: -32.522779,1749 longitudeDelta: 10.0,1750 name: 'Uruguay',1751 longitude: -55.765835,1752 latitudeDelta: 10.0,1753 },1754 {1755 latitude: 41.377491,1756 longitudeDelta: 10.0,1757 name: 'Uzbekistan',1758 longitude: 64.585262,1759 latitudeDelta: 10.0,1760 },1761 {1762 latitude: -15.376706,1763 longitudeDelta: 10.0,1764 name: 'Vanuatu',1765 longitude: 166.959158,1766 latitudeDelta: 10.0,1767 },1768 {1769 latitude: 41.902916,1770 longitudeDelta: 10.0,1771 name: 'Vatican City',1772 longitude: 12.453389,1773 latitudeDelta: 10.0,1774 },1775 {1776 latitude: 6.42375,1777 longitudeDelta: 10.0,1778 name: 'Venezuela',1779 longitude: -66.58973,1780 latitudeDelta: 10.0,1781 },1782 {1783 latitude: 14.058324,1784 longitudeDelta: 10.0,1785 name: 'Vietnam',1786 longitude: 108.277199,1787 latitudeDelta: 10.0,1788 },1789 {1790 latitude: -13.768752,1791 longitudeDelta: 10.0,1792 name: 'Wallis and Futuna',1793 longitude: -177.156097,1794 latitudeDelta: 10.0,1795 },1796 {1797 latitude: 24.215527,1798 longitudeDelta: 10.0,1799 name: 'Western Sahara',1800 longitude: -12.885834,1801 latitudeDelta: 10.0,1802 },1803 {1804 latitude: 15.552727,1805 longitudeDelta: 10.0,1806 name: 'Yemen',1807 longitude: 48.516388,1808 latitudeDelta: 10.0,1809 },1810 {1811 latitude: -13.133897,1812 longitudeDelta: 10.0,1813 name: 'Zambia',1814 longitude: 27.849332,1815 latitudeDelta: 10.0,1816 },1817 {1818 latitude: -19.015438,1819 longitudeDelta: 10.0,1820 name: 'Zimbabwe',1821 longitude: 29.154857,1822 latitudeDelta: 10.0,1823 },1824];...

Full Screen

Full Screen

utils.js

Source:utils.js Github

copy

Full Screen

1export const getLength = (x, y) => Math.sqrt(x * x + y * y);2export const getAngle = ({ x: x1, y: y1 }, { x: x2, y: y2 }) => {3 const dot = x1 * x2 + y1 * y2;4 const det = x1 * y2 - y1 * x2;5 const angle = (Math.atan2(det, dot) / Math.PI) * 180;6 return (angle + 360) % 360;7};8export const degToRadian = (deg) => (deg * Math.PI) / 180;9const cos = (deg) => Math.cos(degToRadian(deg));10const sin = (deg) => Math.sin(degToRadian(deg));11const setWidthAndDeltaW = (width, deltaW, minWidth) => {12 const expectedWidth = width + deltaW;13 if (expectedWidth > minWidth) {14 width = expectedWidth;15 } else {16 deltaW = minWidth - width;17 width = minWidth;18 }19 return { width, deltaW };20};21const setHeightAndDeltaH = (height, deltaH, minHeight) => {22 const expectedHeight = height + deltaH;23 if (expectedHeight > minHeight) {24 height = expectedHeight;25 } else {26 deltaH = minHeight - height;27 height = minHeight;28 }29 return { height, deltaH };30};31export const getNewStyle = (32 type,33 rect,34 deltaW,35 deltaH,36 ratio,37 minWidth,38 minHeight39) => {40 let { width, height, centerX, centerY, rotateAngle } = rect;41 const widthFlag = width < 0 ? -1 : 1;42 const heightFlag = height < 0 ? -1 : 1;43 width = Math.abs(width);44 height = Math.abs(height);45 switch (type) {46 case "r": {47 const widthAndDeltaW = setWidthAndDeltaW(width, deltaW, minWidth);48 width = widthAndDeltaW.width;49 deltaW = widthAndDeltaW.deltaW;50 if (ratio) {51 deltaH = deltaW / ratio;52 height = width / ratio;53 // 左上角固定54 centerX +=55 (deltaW / 2) * cos(rotateAngle) - (deltaH / 2) * sin(rotateAngle);56 centerY +=57 (deltaW / 2) * sin(rotateAngle) + (deltaH / 2) * cos(rotateAngle);58 } else {59 // 左边固定60 centerX += (deltaW / 2) * cos(rotateAngle);61 centerY += (deltaW / 2) * sin(rotateAngle);62 }63 break;64 }65 case "tr": {66 deltaH = -deltaH;67 const widthAndDeltaW = setWidthAndDeltaW(width, deltaW, minWidth);68 width = widthAndDeltaW.width;69 deltaW = widthAndDeltaW.deltaW;70 const heightAndDeltaH = setHeightAndDeltaH(height, deltaH, minHeight);71 height = heightAndDeltaH.height;72 deltaH = heightAndDeltaH.deltaH;73 if (ratio) {74 deltaW = deltaH * ratio;75 width = height * ratio;76 }77 centerX +=78 (deltaW / 2) * cos(rotateAngle) + (deltaH / 2) * sin(rotateAngle);79 centerY +=80 (deltaW / 2) * sin(rotateAngle) - (deltaH / 2) * cos(rotateAngle);81 break;82 }83 case "br": {84 const widthAndDeltaW = setWidthAndDeltaW(width, deltaW, minWidth);85 width = widthAndDeltaW.width;86 deltaW = widthAndDeltaW.deltaW;87 const heightAndDeltaH = setHeightAndDeltaH(height, deltaH, minHeight);88 height = heightAndDeltaH.height;89 deltaH = heightAndDeltaH.deltaH;90 if (ratio) {91 deltaW = deltaH * ratio;92 width = height * ratio;93 }94 centerX +=95 (deltaW / 2) * cos(rotateAngle) - (deltaH / 2) * sin(rotateAngle);96 centerY +=97 (deltaW / 2) * sin(rotateAngle) + (deltaH / 2) * cos(rotateAngle);98 break;99 }100 case "b": {101 const heightAndDeltaH = setHeightAndDeltaH(height, deltaH, minHeight);102 height = heightAndDeltaH.height;103 deltaH = heightAndDeltaH.deltaH;104 if (ratio) {105 deltaW = deltaH * ratio;106 width = height * ratio;107 // 左上角固定108 centerX +=109 (deltaW / 2) * cos(rotateAngle) - (deltaH / 2) * sin(rotateAngle);110 centerY +=111 (deltaW / 2) * sin(rotateAngle) + (deltaH / 2) * cos(rotateAngle);112 } else {113 // 上边固定114 centerX -= (deltaH / 2) * sin(rotateAngle);115 centerY += (deltaH / 2) * cos(rotateAngle);116 }117 break;118 }119 case "bl": {120 deltaW = -deltaW;121 const widthAndDeltaW = setWidthAndDeltaW(width, deltaW, minWidth);122 width = widthAndDeltaW.width;123 deltaW = widthAndDeltaW.deltaW;124 const heightAndDeltaH = setHeightAndDeltaH(height, deltaH, minHeight);125 height = heightAndDeltaH.height;126 deltaH = heightAndDeltaH.deltaH;127 if (ratio) {128 height = width / ratio;129 deltaH = deltaW / ratio;130 }131 centerX -=132 (deltaW / 2) * cos(rotateAngle) + (deltaH / 2) * sin(rotateAngle);133 centerY -=134 (deltaW / 2) * sin(rotateAngle) - (deltaH / 2) * cos(rotateAngle);135 break;136 }137 case "l": {138 deltaW = -deltaW;139 const widthAndDeltaW = setWidthAndDeltaW(width, deltaW, minWidth);140 width = widthAndDeltaW.width;141 deltaW = widthAndDeltaW.deltaW;142 if (ratio) {143 height = width / ratio;144 deltaH = deltaW / ratio;145 // 右上角固定146 centerX -=147 (deltaW / 2) * cos(rotateAngle) + (deltaH / 2) * sin(rotateAngle);148 centerY -=149 (deltaW / 2) * sin(rotateAngle) - (deltaH / 2) * cos(rotateAngle);150 } else {151 // 右边固定152 centerX -= (deltaW / 2) * cos(rotateAngle);153 centerY -= (deltaW / 2) * sin(rotateAngle);154 }155 break;156 }157 case "tl": {158 deltaW = -deltaW;159 deltaH = -deltaH;160 const widthAndDeltaW = setWidthAndDeltaW(width, deltaW, minWidth);161 width = widthAndDeltaW.width;162 deltaW = widthAndDeltaW.deltaW;163 const heightAndDeltaH = setHeightAndDeltaH(height, deltaH, minHeight);164 height = heightAndDeltaH.height;165 deltaH = heightAndDeltaH.deltaH;166 if (ratio) {167 width = height * ratio;168 deltaW = deltaH * ratio;169 }170 centerX -=171 (deltaW / 2) * cos(rotateAngle) - (deltaH / 2) * sin(rotateAngle);172 centerY -=173 (deltaW / 2) * sin(rotateAngle) + (deltaH / 2) * cos(rotateAngle);174 break;175 }176 case "t": {177 deltaH = -deltaH;178 const heightAndDeltaH = setHeightAndDeltaH(height, deltaH, minHeight);179 height = heightAndDeltaH.height;180 deltaH = heightAndDeltaH.deltaH;181 if (ratio) {182 width = height * ratio;183 deltaW = deltaH * ratio;184 // 左下角固定185 centerX +=186 (deltaW / 2) * cos(rotateAngle) + (deltaH / 2) * sin(rotateAngle);187 centerY +=188 (deltaW / 2) * sin(rotateAngle) - (deltaH / 2) * cos(rotateAngle);189 } else {190 centerX += (deltaH / 2) * sin(rotateAngle);191 centerY -= (deltaH / 2) * cos(rotateAngle);192 }193 break;194 }195 }196 return {197 position: {198 centerX,199 centerY,200 },201 size: {202 width: width * widthFlag,203 height: height * heightFlag,204 },205 };206};207const cursorStartMap = { n: 0, ne: 1, e: 2, se: 3, s: 4, sw: 5, w: 6, nw: 7 };208const cursorDirectionArray = ["n", "ne", "e", "se", "s", "sw", "w", "nw"];209const cursorMap = {210 0: 0,211 1: 1,212 2: 2,213 3: 2,214 4: 3,215 5: 4,216 6: 4,217 7: 5,218 8: 6,219 9: 6,220 10: 7,221 11: 8,222};223export const getCursor = (rotateAngle, d) => {224 const increment = cursorMap[Math.floor(rotateAngle / 30)];225 const index = cursorStartMap[d];226 const newIndex = (index + increment) % 8;227 return cursorDirectionArray[newIndex];228};229export const centerToTL = ({230 centerX,231 centerY,232 width,233 height,234 rotateAngle,235}) => ({236 top: centerY - height / 2,237 left: centerX - width / 2,238 width,239 height,240 rotateAngle,241});242export const tLToCenter = ({ top, left, width, height, rotateAngle }) => ({243 position: {244 centerX: left + width / 2,245 centerY: top + height / 2,246 },247 size: {248 width,249 height,250 },251 transform: {252 rotateAngle,253 },...

Full Screen

Full Screen

jquery-mousewheel.js

Source:jquery-mousewheel.js Github

copy

Full Screen

1/*! Copyright (c) 2013 Brandon Aaron (http://brandon.aaron.sh)2 * Licensed under the MIT License (LICENSE.txt).3 *4 * Version: 3.1.95 *6 * Requires: jQuery 1.2.2+7 */8(function (factory) {9 if ( typeof define === 'function' && define.amd ) {10 // AMD. Register as an anonymous module.11 define(['jquery'], factory);12 } else if (typeof exports === 'object') {13 // Node/CommonJS style for Browserify14 module.exports = factory;15 } else {16 // Browser globals17 factory(jQuery);18 }19}(function ($) {20 var toFix = ['wheel', 'mousewheel', 'DOMMouseScroll', 'MozMousePixelScroll'],21 toBind = ( 'onwheel' in document || document.documentMode >= 9 ) ?22 ['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'],23 slice = Array.prototype.slice,24 nullLowestDeltaTimeout, lowestDelta;25 if ( $.event.fixHooks ) {26 for ( var i = toFix.length; i; ) {27 $.event.fixHooks[ toFix[--i] ] = $.event.mouseHooks;28 }29 }30 var special = $.event.special.mousewheel = {31 version: '3.1.9',32 setup: function() {33 if ( this.addEventListener ) {34 for ( var i = toBind.length; i; ) {35 this.addEventListener( toBind[--i], handler, false );36 }37 } else {38 this.onmousewheel = handler;39 }40 // Store the line height and page height for this particular element41 $.data(this, 'mousewheel-line-height', special.getLineHeight(this));42 $.data(this, 'mousewheel-page-height', special.getPageHeight(this));43 },44 teardown: function() {45 if ( this.removeEventListener ) {46 for ( var i = toBind.length; i; ) {47 this.removeEventListener( toBind[--i], handler, false );48 }49 } else {50 this.onmousewheel = null;51 }52 },53 getLineHeight: function(elem) {54 return parseInt($(elem)['offsetParent' in $.fn ? 'offsetParent' : 'parent']().css('fontSize'), 10);55 },56 getPageHeight: function(elem) {57 return $(elem).height();58 },59 settings: {60 adjustOldDeltas: true61 }62 };63 $.fn.extend({64 mousewheel: function(fn) {65 return fn ? this.bind('mousewheel', fn) : this.trigger('mousewheel');66 },67 unmousewheel: function(fn) {68 return this.unbind('mousewheel', fn);69 }70 });71 function handler(event) {72 var orgEvent = event || window.event,73 args = slice.call(arguments, 1),74 delta = 0,75 deltaX = 0,76 deltaY = 0,77 absDelta = 0;78 event = $.event.fix(orgEvent);79 event.type = 'mousewheel';80 // Old school scrollwheel delta81 if ( 'detail' in orgEvent ) { deltaY = orgEvent.detail * -1; }82 if ( 'wheelDelta' in orgEvent ) { deltaY = orgEvent.wheelDelta; }83 if ( 'wheelDeltaY' in orgEvent ) { deltaY = orgEvent.wheelDeltaY; }84 if ( 'wheelDeltaX' in orgEvent ) { deltaX = orgEvent.wheelDeltaX * -1; }85 // Firefox < 17 horizontal scrolling related to DOMMouseScroll event86 if ( 'axis' in orgEvent && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) {87 deltaX = deltaY * -1;88 deltaY = 0;89 }90 // Set delta to be deltaY or deltaX if deltaY is 0 for backwards compatabilitiy91 delta = deltaY === 0 ? deltaX : deltaY;92 // New school wheel delta (wheel event)93 if ( 'deltaY' in orgEvent ) {94 deltaY = orgEvent.deltaY * -1;95 delta = deltaY;96 }97 if ( 'deltaX' in orgEvent ) {98 deltaX = orgEvent.deltaX;99 if ( deltaY === 0 ) { delta = deltaX * -1; }100 }101 // No change actually happened, no reason to go any further102 if ( deltaY === 0 && deltaX === 0 ) { return; }103 // Need to convert lines and pages to pixels if we aren't already in pixels104 // There are three delta modes:105 // * deltaMode 0 is by pixels, nothing to do106 // * deltaMode 1 is by lines107 // * deltaMode 2 is by pages108 if ( orgEvent.deltaMode === 1 ) {109 var lineHeight = $.data(this, 'mousewheel-line-height');110 delta *= lineHeight;111 deltaY *= lineHeight;112 deltaX *= lineHeight;113 } else if ( orgEvent.deltaMode === 2 ) {114 var pageHeight = $.data(this, 'mousewheel-page-height');115 delta *= pageHeight;116 deltaY *= pageHeight;117 deltaX *= pageHeight;118 }119 // Store lowest absolute delta to normalize the delta values120 absDelta = Math.max( Math.abs(deltaY), Math.abs(deltaX) );121 if ( !lowestDelta || absDelta < lowestDelta ) {122 lowestDelta = absDelta;123 // Adjust older deltas if necessary124 if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) {125 lowestDelta /= 40;126 }127 }128 // Adjust older deltas if necessary129 if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) {130 // Divide all the things by 40!131 delta /= 40;132 deltaX /= 40;133 deltaY /= 40;134 }135 // Get a whole, normalized value for the deltas136 delta = Math[ delta >= 1 ? 'floor' : 'ceil' ](delta / lowestDelta);137 deltaX = Math[ deltaX >= 1 ? 'floor' : 'ceil' ](deltaX / lowestDelta);138 deltaY = Math[ deltaY >= 1 ? 'floor' : 'ceil' ](deltaY / lowestDelta);139 // Add information to the event object140 event.deltaX = deltaX;141 event.deltaY = deltaY;142 event.deltaFactor = lowestDelta;143 // Go ahead and set deltaMode to 0 since we converted to pixels144 // Although this is a little odd since we overwrite the deltaX/Y145 // properties with normalized deltas.146 event.deltaMode = 0;147 // Add event and delta to the front of the arguments148 args.unshift(event, delta, deltaX, deltaY);149 // Clearout lowestDelta after sometime to better150 // handle multiple device types that give different151 // a different lowestDelta152 // Ex: trackpad = 3 and mouse wheel = 120153 if (nullLowestDeltaTimeout) { clearTimeout(nullLowestDeltaTimeout); }154 nullLowestDeltaTimeout = setTimeout(nullLowestDelta, 200);155 return ($.event.dispatch || $.event.handle).apply(this, args);156 }157 function nullLowestDelta() {158 lowestDelta = null;159 }160 function shouldAdjustOldDeltas(orgEvent, absDelta) {161 // If this is an older event and the delta is divisable by 120,162 // then we are assuming that the browser is treating this as an163 // older mouse wheel event and that we should divide the deltas164 // by 40 to try and get a more usable deltaFactor.165 // Side note, this actually impacts the reported scroll distance166 // in older browsers and can cause scrolling to be slower than native.167 // Turn this off by setting $.event.special.mousewheel.settings.adjustOldDeltas to false.168 return special.settings.adjustOldDeltas && orgEvent.type === 'mousewheel' && absDelta % 120 === 0;169 }...

Full Screen

Full Screen

jquery.mousewheel.min.js

Source:jquery.mousewheel.min.js Github

copy

Full Screen

1/*! Copyright (c) 2013 Brandon Aaron (http://brandon.aaron.sh)2 * Licensed under the MIT License (LICENSE.txt).3 *4 * Version: 3.1.85 *6 * Requires: jQuery 1.2.2+7 */8(function (factory) {9 if ( typeof define === 'function' && define.amd ) {10 // AMD. Register as an anonymous module.11 define(['jquery'], factory);12 } else if (typeof exports === 'object') {13 // Node/CommonJS style for Browserify14 module.exports = factory;15 } else {16 // Browser globals17 factory(jQuery);18 }19}(function ($) {20 var toFix = ['wheel', 'mousewheel', 'DOMMouseScroll', 'MozMousePixelScroll'],21 toBind = ( 'onwheel' in document || document.documentMode >= 9 ) ?22 ['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'],23 slice = Array.prototype.slice,24 oldMode, nullLowestDeltaTimeout, lowestDelta;25 if ( $.event.fixHooks ) {26 for ( var i = toFix.length; i; ) {27 $.event.fixHooks[ toFix[--i] ] = $.event.mouseHooks;28 }29 }30 var special = $.event.special.mousewheel = {31 version: '3.1.8',32 setup: function() {33 if ( this.addEventListener ) {34 for ( var i = toBind.length; i; ) {35 this.addEventListener( toBind[--i], handler, false );36 }37 } else {38 this.onmousewheel = handler;39 }40 // Store the line height and page height for this particular element41 $.data(this, 'mousewheel-line-height', special.getLineHeight(this));42 $.data(this, 'mousewheel-page-height', special.getPageHeight(this));43 },44 teardown: function() {45 if ( this.removeEventListener ) {46 for ( var i = toBind.length; i; ) {47 this.removeEventListener( toBind[--i], handler, false );48 }49 } else {50 this.onmousewheel = null;51 }52 },53 getLineHeight: function(elem) {54 return parseInt($(elem)['offsetParent' in $.fn ? 'offsetParent' : 'parent']().css('fontSize'), 10);55 },56 getPageHeight: function(elem) {57 return $(elem).height();58 }59 };60 $.fn.extend({61 mousewheel: function(fn) {62 return fn ? this.bind('mousewheel', fn) : this.trigger('mousewheel');63 },64 unmousewheel: function(fn) {65 return this.unbind('mousewheel', fn);66 }67 });68 function handler(event) {69 var orgEvent = event || window.event,70 args = slice.call(arguments, 1),71 delta = 0,72 deltaX = 0,73 deltaY = 0,74 absDelta = 0;75 event = $.event.fix(orgEvent);76 event.type = 'mousewheel';77 // Old school scrollwheel delta78 if ( 'detail' in orgEvent ) { deltaY = orgEvent.detail * -1; }79 if ( 'wheelDelta' in orgEvent ) { deltaY = orgEvent.wheelDelta; }80 if ( 'wheelDeltaY' in orgEvent ) { deltaY = orgEvent.wheelDeltaY; }81 if ( 'wheelDeltaX' in orgEvent ) { deltaX = orgEvent.wheelDeltaX * -1; }82 // Firefox < 17 horizontal scrolling related to DOMMouseScroll event83 if ( 'axis' in orgEvent && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) {84 deltaX = deltaY * -1;85 deltaY = 0;86 }87 // Set delta to be deltaY or deltaX if deltaY is 0 for backwards compatabilitiy88 delta = deltaY === 0 ? deltaX : deltaY;89 // New school wheel delta (wheel event)90 if ( 'deltaY' in orgEvent ) {91 deltaY = orgEvent.deltaY * -1;92 delta = deltaY;93 }94 if ( 'deltaX' in orgEvent ) {95 deltaX = orgEvent.deltaX;96 if ( deltaY === 0 ) { delta = deltaX * -1; }97 }98 // No change actually happened, no reason to go any further99 if ( deltaY === 0 && deltaX === 0 ) { return; }100 // Need to convert lines and pages to pixels if we aren't already in pixels101 // There are three delta modes:102 // * deltaMode 0 is by pixels, nothing to do103 // * deltaMode 1 is by lines104 // * deltaMode 2 is by pages105 if ( orgEvent.deltaMode === 1 ) {106 var lineHeight = $.data(this, 'mousewheel-line-height');107 delta *= lineHeight;108 deltaY *= lineHeight;109 deltaX *= lineHeight;110 } else if ( orgEvent.deltaMode === 2 ) {111 var pageHeight = $.data(this, 'mousewheel-page-height');112 delta *= pageHeight;113 deltaY *= pageHeight;114 deltaX *= pageHeight;115 }116 // Store lowest absolute delta to normalize the delta values117 absDelta = Math.max( Math.abs(deltaY), Math.abs(deltaX) );118 if ( !lowestDelta || absDelta < lowestDelta ) {119 lowestDelta = absDelta;120 // Assuming that if the lowestDelta is 120, then that the browser121 // is treating this as an older mouse wheel event.122 // We'll divide it by 40 to try and get a more usable deltaFactor.123 if ( lowestDelta === 120 ) {124 oldMode = true;125 lowestDelta /= 40;126 }127 }128 // When in oldMode the delta is based on 120.129 // Dividing by 40 to try and get a more usable deltaFactor.130 if ( oldMode ) {131 // Divide all the things by 40!132 delta /= 40;133 deltaX /= 40;134 deltaY /= 40;135 }136 // Get a whole, normalized value for the deltas137 delta = Math[ delta >= 1 ? 'floor' : 'ceil' ](delta / lowestDelta);138 deltaX = Math[ deltaX >= 1 ? 'floor' : 'ceil' ](deltaX / lowestDelta);139 deltaY = Math[ deltaY >= 1 ? 'floor' : 'ceil' ](deltaY / lowestDelta);140 // Add information to the event object141 event.deltaX = deltaX;142 event.deltaY = deltaY;143 event.deltaFactor = lowestDelta;144 // Go ahead and set deltaMode to 0 since we converted to pixels145 // Although this is a little odd since we overwrite the deltaX/Y146 // properties with normalized deltas.147 event.deltaMode = 0;148 // Add event and delta to the front of the arguments149 args.unshift(event, delta, deltaX, deltaY);150 // Clearout lowestDelta after sometime to better151 // handle multiple device types that give different152 // a different lowestDelta153 // Ex: trackpad = 3 and mouse wheel = 120154 if (nullLowestDeltaTimeout) { clearTimeout(nullLowestDeltaTimeout); }155 nullLowestDeltaTimeout = setTimeout(nullLowestDelta, 200);156 return ($.event.dispatch || $.event.handle).apply(this, args);157 }158 function nullLowestDelta() {159 lowestDelta = null;160 oldMode = null;161 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var port = 2525;3var imposter = {4 {5 {6 is: {7 }8 }9 }10};11mb.create(imposter).then(function () {12 console.log('Imposter created at port %d', port);13});14var mb = require('mountebank');15var port = 2525;16var imposter = {17 {18 {19 is: {20 }21 }22 }23};24mb.create(imposter).then(function () {25 console.log('Imposter created at port %d', port);26 return mb.del(port);27}).then(function () {28 console.log('Imposter deleted at port %d', port);29});30### mb.create(imposter)31### mb.del(port)32### mb.delAll()33### mb.get(port)34### mb.getAll()35### mb.put(port, imposter)36### mb.post(port, imposter)37### mb.reset()38### mb.verify()39### mb.verifyAll()

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2mb.start({3}, function (error) {4 console.log('mountebank started on port 2525');5});6mb.create({7 {8 { equals: { method: 'GET', path: '/test' } }9 { is: { body: 'Hello World' } }10 }11}, function (error, imposter) {12 console.log('imposter created');13});14mb.create({15 {16 { equals: { method: 'GET', path: '/test' } }17 { is: { body: 'Hello World' } }18 }19}, function (error, imposter) {20 console.log('imposter created');21});22mb.create({23 {24 { equals: { method: 'GET', path: '/test' } }25 { is: { body: 'Hello World' } }26 }27}, function (error, imposter) {28 console.log('imposter created');29});30mb.create({31 {32 { equals: { method: 'GET', path: '/test' } }33 { is: { body: 'Hello World' } }34 }35}, function (error, imposter) {36 console.log('imposter created');37});38mb.create({39 {40 { equals: { method: 'GET', path: '/test' } }41 { is: { body: 'Hello World' } }42 }43}, function (error, imposter) {44 console.log('imposter created');45});46mb.create({

Full Screen

Using AI Code Generation

copy

Full Screen

1const assert = require('assert');2const mb = require('mountebank');3mb.start({4}).then(() => {5 return mb.post('/imposters', {6 {7 {8 is: {9 }10 }11 }12 });13}).then(response => {14 assert.strictEqual(response.statusCode, 201);15 return mb.get('/imposters/3000');16}).then(response => {17 assert.strictEqual(response.statusCode, 200);18 return mb.del('/imposters/3000');19}).then(response => {20 assert.strictEqual(response.statusCode, 200);21 return mb.stop();22}).then(() => {23 console.log('done');24}).catch(error => {25 console.error(error);26 mb.stop();27});

Full Screen

Using AI Code Generation

copy

Full Screen

1const mb = require('mountebank');2const port = 2525;3const imposters = [{4 stubs: [{5 responses: [{6 is: {7 }8 }]9 }]10}];11mb.start({12}, function () {13 mb.createImposter(imposters, function () {14 console.log('Imposter created');15 });16});17const mb = require('mountebank');18const port = 2525;19const imposters = [{20 stubs: [{21 responses: [{22 is: {23 }24 }]25 }]26}];27mb.start({28}, function () {29 mb.createImposter(imposters, function () {30 console.log('Imposter created');31 });32});33const mb = require('mountebank');34const port = 2525;35const imposters = [{36 stubs: [{37 responses: [{38 is: {39 }40 }]41 }]42}];43mb.start({44}, function () {45 mb.createImposter(imposters, function () {46 console.log('Imposter created');47 });48});49const mb = require('mountebank');50const port = 2525;51const imposters = [{52 stubs: [{53 responses: [{54 is: {55 }56 }]57 }]58}];59mb.start({

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var port = 2525;3var imposters = [{4 stubs: [{5 predicates: [{6 equals: {7 }8 }],9 responses: [{10 is: {11 }12 }]13 }]14}];15mb.start({ port: port, pidfile: 'mb.pid', logfile: 'mb.log', ipWhitelist: ['*'] }, function () {16 mb.createImposters(imposters, function (error, imposters) {17 console.log('Imposters created');18 });19});20mb.stop(port, function () {21 console.log('Imposters deleted');22});

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var stub = {3 { equals: { method: 'GET', path: '/test' } }4 { is: { statusCode: 200, body: 'Hello world!' } }5};6mb.create({7}, function (error, server) {8 console.log('MB server created', error || '');9});10var mb = require('mountebank');11var stub = {12 { equals: { method: 'GET', path: '/test' } }13 { is: { statusCode: 200, body: 'Hello world!' } }14};15mb.create({16}, function (error, server) {17 console.log('MB server created', error || '');18});19var mb = require('mountebank');20var stub = {21 { equals: { method: 'GET', path: '/test' } }22 { is: { statusCode: 200, body: 'Hello world!' } }23};24mb.create({25}, function (error, server) {26 console.log('MB server created', error || '');27});28var mb = require('mountebank');29var stub = {30 { equals: { method: 'GET', path: '/test' } }31 { is: { statusCode: 200, body: 'Hello world!' } }32};33mb.create({34}, function (error, server) {35 console.log('MB server created', error || '');36});

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var fs = require('fs');3var imposter = JSON.parse(fs.readFileSync('imposter.json', 'utf8'));4var imposters = [imposter];5mb.start({port:2525, allowInjection:true, pidfile:'mb.pid', logfile:'mb.log', imposters:imposters}, function (error) {6 if (error) {7 console.error(error);8 } else {9 console.info('running on port 2525');10 }11});12var request = require('request');13var assert = require('assert');14var mb = require('mountebank');15var fs = require('fs');16var imposter = JSON.parse(fs.readFileSync('imposter.json', 'utf8'));17var imposters = [imposter];18describe('Test Suite 1', function() {19 before(function(done) {20 mb.start({port:2525, allowInjection:true, pidfile:'mb.pid', logfile:'mb.log', imposters:imposters}, function (error) {21 if (error) {22 console.error(error);23 done(error);24 } else {25 console.info('running on port 2525');26 done();27 }28 });29 });30 after(function(done) {31 mb.stop({pidfile:'mb.pid'}, function (error) {32 if (error) {33 console.error(error);34 done(error);35 } else {36 console.info('stopped');37 done();38 }39 });40 });41 it('Test 1', function(done)

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var port = 2525;3var protocol = 'http';4var path = '/api';5var stub = {6 {7 equals: {8 }9 }10 {11 is: {12 headers: {13 },14 body: JSON.stringify(15 {16 }17 }18 }19};20var imposter = {21};22mb.create(imposter).then(function () {23 console.log('imposter created');24}, function (error) {25 console.error('error creating imposter', error);26});27error creating imposter { Error: connect ECONNREFUSED

Full Screen

Using AI Code Generation

copy

Full Screen

1const { createServer } = require('http');2const { createClient } = require('mbjs');3const fs = require('fs');4const path = require('path');5const mbServer = createServer();6const mbClient = createClient({ server: mbServer });7const mbPort = 2525;8const mbConfig = {9};10const stubs = require('./stubs');11const mbStart = async () => {12 await mbClient.start(mbConfig);13 await mbClient.createImposter({ port: 3000, protocol: 'http' });14 await mbClient.addStubs({ port: 3000, stubs: stubs });15};16mbStart()17 .then(() => {18 console.log('Imposter created');19 })20 .catch(err => {21 console.error(err);22 });23const fs = require('fs');24const path = require('path');25 {26 {27 equals: {28 }29 }30 {31 is: {32 headers: {33 },34 body: fs.readFileSync(path.resolve(__dirname, './responses/login.json'), 'utf8')35 }36 }37 }38];39module.exports = stubs;40### createClient(options)41- `logger` - a custom logger that implements the methods `error`, `warn`, `info`, `debug`, and `trace`. By default, the client will use a [bunyan](

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run mountebank automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful