Best JavaScript code snippet using wpt
Clock.js
Source:Clock.js
1import React from "react";2export class Clock extends React.Component{3 constructor(props) {4 super(props);5 this.state = {date: new Date()};6 }7 componentDidMount() {8 this.timerID = setInterval(9 () => this.newTime(),10 70011 );12 }13 componentWillUnmount() {14 clearInterval(this.timerID);15 }16 newTime(){17 this.setState({18 date: new Date()19 });20 this.makeElectricStyle(this.props.type);21 }22 makeElectricStyle(type){23 const clock = this.refs.canvas.getContext('2d');24 let width = this.refs.canvas.width;25 clock.clearRect(0,0,width,width);26 clock.fillStyle = 'black';27 let now = new Date();28 let date =now.toDateString();29 let hours = now.getHours();30 let minutes = now.getMinutes();31 let firstCountHours = Math.floor(hours/10);32 let secondCountHours = hours%10;33 let firstCountMinutes = Number(Math.floor(minutes/10));34 let secondCountMinutes = Number(minutes%10);35 switch (type) {36 case 1:37 width = width/2;38 this.paintCount(clock,50*width/1000,160*width/1000,firstCountHours,800,width);39 this.paintCount(clock,250*width/1000,160*width/1000,secondCountHours,800,width);40 this.paintStick(clock,465*width/1000,260*width/1000,6,800,width);41 // switch (firstCountMinutes) {42 // case 1:43 // this.paintCount(clock,450*width/1000,160*width/1000,firstCountMinutes,800,width);44 // this.paintCount(clock,650*width/1000,160*width/1000,secondCountMinutes,800,width);45 // break;46 // case 2 :47 this.paintCount(clock,550*width/1000,160*width/1000,firstCountMinutes,800,width);48 this.paintCount(clock,750*width/1000,160*width/1000,secondCountMinutes,800,width);49 // break;50 // case 0:51 // this.paintCount(clock,550*width/1000,160*width/1000,firstCountMinutes,800,width);52 // this.paintCount(clock,750*width/1000,160*width/1000,secondCountMinutes,800,width);53 // break;54 // }55 clock.font = 0.08 * width + 'px Arial';56 clock.fillText('Now is:' + date,0.05*width,0.6*width,4000);57 break;58 case 2:59 this.paintCount(clock,280*width/1000,50*width/1000,firstCountHours,700,width);60 this.paintCount(clock,520*width/1000,50*width/1000,secondCountHours,700,width);61 this.paintCount(clock,280*width/1000,450*width/1000,firstCountMinutes,700,width);62 this.paintCount(clock,520*width/1000,450*width/1000,secondCountMinutes,700,width);63 clock.font = 0.08 * width + 'px Arial';64 let arr = date.split(" ");65 clock.fillText( arr[1]+" "+arr[2]+" "+arr[3],0.27*width,910*width/1000,4000);66 break;67 default:68 break69 }70 }71 paintStick(clock,x,y,type,coef,width){72 let cof = coef;73 switch (type) {74 case 1:75 clock.fillStyle = 'black';76 clock.beginPath();77 clock.moveTo(x,y+5*width/cof);78 clock.lineTo(x+10*width/cof,y);79 clock.lineTo(x+100*width/cof,y);80 clock.lineTo(x+110*width/cof,y+5*width/cof);81 clock.lineTo(x+95*width/cof,y+10*2*width/cof);82 clock.lineTo(x+15*width/cof,y+10*2*width/cof);83 clock.closePath();84 clock.fill();85 break;86 case 2:87 clock.fillStyle = 'black';88 clock.beginPath();89 clock.moveTo(x+5*width/cof,y);90 clock.lineTo(x,y+10*width/cof);91 clock.lineTo(x,y+100*width/cof);92 clock.lineTo(x+5*width/cof,y+110*width/cof);93 clock.lineTo(x+10*2*width/cof,y+95*width/cof);94 clock.lineTo(x+10*2*width/cof,y+15*width/cof);95 clock.closePath();96 clock.fill();97 break;98 case 3:99 clock.fillStyle ='black';100 clock.beginPath();101 clock.moveTo(x+15*width/cof,y);102 clock.lineTo(x+20*width/cof,y+10*width/cof);103 clock.lineTo(x+20*width/cof,y+100*width/cof);104 clock.lineTo(x+15*width/cof,y+110*width/cof);105 clock.lineTo(x,y+95*width/cof);106 clock.lineTo(x,y+15*width/cof);107 clock.closePath();108 clock.fill();109 break;110 case 4:111 clock.fillStyle = 'black';112 clock.beginPath();113 clock.moveTo(x,y+10*width/cof);114 clock.lineTo(x+10*width/cof,y);115 clock.lineTo(x+100*width/cof,y);116 clock.lineTo(x+110*width/cof,y+10*width/cof);117 clock.lineTo(x+100*width/cof,y+10*2*width/cof);118 clock.lineTo(x+10*width/cof,y+10*2*width/cof);119 clock.closePath();120 clock.fill();121 break;122 case 5:123 clock.fillStyle = 'black';124 clock.beginPath();125 clock.moveTo(x,y+15*width/cof);126 clock.lineTo(x+15*width/cof,y);127 clock.lineTo(x+95*width/cof,y);128 clock.lineTo(x+110*width/cof,y+15*width/cof);129 clock.lineTo(x+100*width/cof,y+10*2*width/cof);130 clock.lineTo(x+10*width/cof,y+10*2*width/cof);131 clock.closePath();132 clock.fill();133 break;134 case 6:135 clock.fillStyle = 'black';136 clock.beginPath();137 clock.fillRect(x+width/(cof),y+width/(cof),width/(cof/25),width/(cof/25));138 clock.fillRect(x+width/(cof),y+100*width/(cof),width/(cof/25),width/(cof/25));139 clock.closePath();140 clock.fill();141 break;142 default:break;143 }144 }145 paintCount(clock,x,y,count,coef,width){146 let cof=coef;147 switch (count) {148 case 0:149 this.paintStick(clock,x+10*width/cof,y+10*width/cof,1,cof,width);150 this.paintStick(clock,x,y+20*width/cof,2,cof,width);151 this.paintStick(clock,x,y+150*width/cof,2,cof,width);152 this.paintStick(clock,x+110*width/cof,y+20*width/cof,3,cof,width);153 this.paintStick(clock,x+110*width/cof,y+150*width/cof,3,cof,width);154 this.paintStick(clock,x+10*width/cof,y+250*width/cof,5,cof,width);155 break;156 case 1:157 this.paintStick(clock,x+110*width/cof,y+20*width/cof,3,cof,width);158 this.paintStick(clock,x+110*width/cof,y+150*width/cof,3,cof,width);159 break;160 break;161 case 2:162 this.paintStick(clock,x+10*width/cof,y+10*width/cof,1,cof,width);163 this.paintStick(clock,x,y+150*width/cof,2,cof,width);164 this.paintStick(clock,x+110*width/cof,y+20*width/cof,3,cof,width);165 this.paintStick(clock,x+10*width/cof,y+130*width/cof,4,cof,width);166 this.paintStick(clock,x+10*width/cof,y+250*width/cof,5,cof,width);167 break;168 case 3:169 this.paintStick(clock,x+10*width/cof,y+10*width/cof,1,cof,width);170 this.paintStick(clock,x+110*width/cof,y+20*width/cof,3,cof,width);171 this.paintStick(clock,x+110*width/cof,y+150*width/cof,3,cof,width);172 this.paintStick(clock,x+10*width/cof,y+130*width/cof,4,cof,width);173 this.paintStick(clock,x+10*width/cof,y+250*width/cof,5,cof,width);174 break;175 case 4:176 this.paintStick(clock,x,y+20*width/cof,2,cof,width);177 this.paintStick(clock,x+110*width/cof,y+20*width/cof,3,cof,width);178 this.paintStick(clock,x+110*width/cof,y+150*width/cof,3,cof,width);179 this.paintStick(clock,x+10*width/cof,y+130*width/cof,4,cof,width);180 break;181 case 5:182 this.paintStick(clock,x+10*width/cof,y+10*width/cof,1,cof,width);183 this.paintStick(clock,x,y+20*width/cof,2,cof,width);184 this.paintStick(clock,x+110*width/cof,y+150*width/cof,3,cof,width);185 this.paintStick(clock,x+10*width/cof,y+130*width/cof,4,cof,width);186 this.paintStick(clock,x+10*width/cof,y+250*width/cof,5,cof,width);187 break;188 case 6:189 this.paintStick(clock,x+10*width/cof,y+10*width/cof,1,cof,width);190 this.paintStick(clock,x,y+20*width/cof,2,cof,width);191 this.paintStick(clock,x,y+150*width/cof,2,cof,width);192 this.paintStick(clock,x+110*width/cof,y+150*width/cof,3,cof,width);193 this.paintStick(clock,x+10*width/cof,y+130*width/cof,4,cof,width);194 this.paintStick(clock,x+10*width/cof,y+250*width/cof,5,cof,width);195 break;196 case 7:197 this.paintStick(clock,x+10*width/cof,y+10*width/cof,1,cof,width);198 this.paintStick(clock,x+110*width/cof,y+20*width/cof,3,cof,width);199 this.paintStick(clock,x+110*width/cof,y+150*width/cof,3,cof,width);200 break;201 case 8:202 this.paintStick(clock,x+10*width/cof,y+10*width/cof,1,cof,width);203 this.paintStick(clock,x,y+20*width/cof,2,cof,width);204 this.paintStick(clock,x,y+150*width/cof,2,cof,width);205 this.paintStick(clock,x+110*width/cof,y+20*width/cof,3,cof,width);206 this.paintStick(clock,x+110*width/cof,y+150*width/cof,3,cof,width);207 this.paintStick(clock,x+10*width/cof,y+130*width/cof,4,cof,width);208 this.paintStick(clock,x+10*width/cof,y+250*width/cof,5,cof,width);209 break;210 case 9:211 this.paintStick(clock,x+10*width/cof,y+10*width/cof,1,cof,width);212 this.paintStick(clock,x,y+20*width/cof,2,cof,width);213 this.paintStick(clock,x+110*width/cof,y+20*width/cof,3,cof,width);214 this.paintStick(clock,x+110*width/cof,y+150*width/cof,3,cof,width);215 this.paintStick(clock,x+10*width/cof,y+130*width/cof,4,cof,width);216 this.paintStick(clock,x+10*width/cof,y+250*width/cof,5,cof,width);217 break;218 }219 }220 render() {221 const {clockSize} = this.props;222 return(223 <div id={'clockPlace'}>224 <canvas ref={'canvas'} id={'clock'} width={clockSize} height={clockSize} />225 </div>226 )227 }...
FuncCode.js
Source:FuncCode.js
1export default {2 cof_f_auth_tpl_add:'cof-f-auth-tpl-add', //æ·»å æéæ¨¡æ¿ function3 cof_f_auth_tpl_add_res_group:'cof-f-auth-tpl-add-res-group', //æé模æ¿æ·»å èµæºç» function4 cof_f_auth_tpl_del:'cof-f-auth-tpl-del', //å é¤æéæ¨¡æ¿ function5 cof_f_auth_tpl_edit:'cof-f-auth-tpl-edit', //ç¼è¾æéæ¨¡æ¿ function6 cof_f_auth_tpl_rm_res_group:'cof-f-auth-tpl-rm-res-group', //æé模æ¿ç§»é¤èµæºç» function7 cof_f_dict_download_tpl:'cof-f-dict-download-tpl', //ä¸è½½å¯¼å
¥æ¨¡æ¿ function8 cof_f_dict_entry_add:'cof-f-dict-entry-add', //æ·»å åå
¸é¡¹ function9 cof_f_dict_entry_del:'cof-f-dict-entry-del', //å é¤åå
¸é¡¹ function10 cof_f_dict_entry_edit:'cof-f-dict-entry-edit', //ç¼è¾åå
¸é¡¹ function11 cof_f_dict_export:'cof-f-dict-export', //导åºæ°æ®åå
¸ function12 cof_f_dict_import:'cof-f-dict-import', //导å
¥æ°æ®åå
¸ function13 cof_f_dict_type_add:'cof-f-dict-type-add', //æ·»å åå
¸ç±»å function14 cof_f_dict_type_del:'cof-f-dict-type-del', //å é¤åå
¸ç±»å function15 cof_f_dict_type_edit:'cof-f-dict-type-edit', //ç¼è¾åå
¸ç±»å function16 cof_f_dimension_add:'cof-f-dimension-add', //æ·»å æºææ function17 cof_f_dimension_del:'cof-f-dimension-del', //å é¤æºææ function18 cof_f_dimension_edit:'cof-f-dimension-edit', //ç¼è¾æºææ function19 cof_f_emp_add:'cof-f-emp-add', //æ·»å åå·¥ function20 cof_f_emp_del:'cof-f-emp-del', //å é¤åå·¥ function21 cof_f_emp_edit:'cof-f-emp-edit', //ç¼è¾åå·¥ function22 cof_f_function_add:'cof-f-function-add', //æ·»å åè½ function23 cof_f_function_del:'cof-f-function-del', //å é¤åè½ function24 cof_f_function_edit:'cof-f-function-edit', //ç¼è¾åè½ function25 cof_f_function_scan:'cof-f-function-scan', //åè½æ«æ function26 cof_f_member_add:'cof-f-member-add', //æ·»å æå function27 cof_f_member_del:'cof-f-member-del', //å é¤æå function28 cof_f_menu_add:'cof-f-menu-add', //æ·»å èå function29 cof_f_menu_del:'cof-f-menu-del', //å é¤èå function30 cof_f_menu_edit:'cof-f-menu-edit', //ç¼è¾èå function31 cof_f_optlog_detail_get:'cof-f-optlog-detail-get', //æ¥çæä½æ¥å¿è¯¦æ
function32 cof_f_optlog_search:'cof-f-optlog-search', //æ¥è¯¢æä½æ¥å¿ function33 cof_f_org_add:'cof-f-org-add', //æ·»å æºæ function34 cof_f_org_del:'cof-f-org-del', //å é¤æºæ function35 cof_f_org_edit:'cof-f-org-edit', //ç¼è¾æºæ function36 cof_f_org_emp_add:'cof-f-org-emp-add', //æ·»å æºæåå·¥ function37 cof_f_org_emp_del:'cof-f-org-emp-del', //移é¤æºæåå·¥ function38 cof_f_position_add:'cof-f-position-add', //æ·»å å²ä½ function39 cof_f_position_del:'cof-f-position-del', //å é¤å²ä½ function40 cof_f_position_edit:'cof-f-position-edit', //ç¼è¾å²ä½ function41 cof_f_position_emp_add:'cof-f-position-emp-add', //å²ä½æ·»å åå·¥ function42 cof_f_position_emp_del:'cof-f-position-emp-del', //å²ä½ç§»é¤åå·¥ function43 cof_f_res_group_add:'cof-f-res-group-add', //æ·»å èµæºç» function44 cof_f_res_group_del:'cof-f-res-group-del', //å é¤èµæºç» function45 cof_f_res_group_edit:'cof-f-res-group-edit', //ç¼è¾èµæºç» function46 cof_f_role_add:'cof-f-role-add', //æ·»å è§è² function47 cof_f_role_bind:'cof-f-role-bind', //è§è²ç»å®ç¨æ· function48 cof_f_role_del:'cof-f-role-del', //å é¤è§è² function49 cof_f_role_edit:'cof-f-role-edit', //ç¼è¾è§è² function50 cof_f_role_edit_res:'cof-f-role-edit-res', //è§è²ææ function51 cof_f_role_tpl_add:'cof-f-role-tpl-add', //æ·»å è§è²æ¨¡æ¿ function52 cof_f_role_tpl_del:'cof-f-role-tpl-del', //å é¤è§è²æ¨¡æ¿ function53 cof_f_role_tpl_edit:'cof-f-role-tpl-edit', //ç¼è¾è§è²æ¨¡æ¿ function54 cof_f_role_tpl_edit_res:'cof-f-role-tpl-edit-res', //è§è²æ¨¡æ¿ææ function55 cof_f_role_tpl_grp_add:'cof-f-role-tpl-grp-add', //æ·»å è§è²æ¨¡æ¿ç» function56 cof_f_role_tpl_grp_del:'cof-f-role-tpl-grp-del', //å é¤è§è²æ¨¡æ¿ç» function57 cof_f_role_tpl_grp_edit:'cof-f-role-tpl-grp-edit', //ç¼è¾è§è²æ¨¡æ¿ç» function58 cof_f_role_unbind:'cof-f-role-unbind', //è§è²ä¸ç¨æ·è§£ç» function59 cof_f_user_add:'cof-f-user-add', //æ·»å ç¨æ· function60 cof_f_user_change_pw:'cof-f-user-change-pw', //ä¿®æ¹ç¨æ·å¯ç function61 cof_f_user_del:'cof-f-user-del', //å é¤ç¨æ· function62 cof_f_user_edit:'cof-f-user-edit', //ç¼è¾ç¨æ· function63 cof_f_user_edit_status:'cof-f-user-edit-status', //å¯ç¨/ç¦ç¨ç¨æ· function64 cof_f_user_reset_pw:'cof-f-user-reset-pw', //éç½®ç¨æ·å¯ç function65 cof_f_workgroup_add:'cof-f-workgroup-add', //æ·»å å·¥ä½ç» function66 cof_f_workgroup_add_emp:'cof-f-workgroup-add-emp', //æ·»å å·¥ä½ç»åå·¥ function67 cof_f_workgroup_del:'cof-f-workgroup-del', //å é¤å·¥ä½ç» function68 cof_f_workgroup_edit:'cof-f-workgroup-edit', //ç¼è¾å·¥ä½ç» function69 cof_f_workgroup_rm_emp:'cof-f-workgroup-rm-emp', //移é¤å·¥ä½ç»åå·¥ function70 cof_m_audit:'cof-m-audit', //å®å
¨å®¡è®¡ menu71 cof_m_auth:'cof-m-auth', //æé管ç menu72 cof_m_dict:'cof-m-dict', //ä¸å¡åå
¸ menu73 cof_m_emp:'cof-m-emp', //人å管ç menu74 cof_m_member:'cof-m-member', //å¹³å°æå menu75 cof_m_opt_log:'cof-m-opt-log', //æä½æ¥å¿ menu76 cof_m_org:'cof-m-org', //ç»ç»æºæ menu77 cof_m_org_tree:'cof-m-org-tree', //æºæå²ä½ menu78 cof_m_resouce_right:'cof-m-resouce-right', //èµæºæé menu79 cof_m_role:'cof-m-role', //å¹³å°è§è² menu80 cof_m_role_template:'cof-m-role-template', //è§è²æ¨¡æ¿ menu81 cof_m_sys:'cof-m-sys', //ç³»ç»é
ç½® menu82 cof_m_user:'cof-m-user', //ç¨æ·ç®¡ç menu83 fl:'fl', //æµè¯ menu84 // fl2:'fl2', //æµè¯ menu85 // fl2Delete:'fl2Delete',//86 // sousuo:'sousuo', //æµè¯ menu87 // shujubaobiao:'shujubaobiao', //æµè¯ menu88 // fl3:'fl3', //æµè¯ menu89 // fl4:'fl4', //æµè¯ menu90 // fl5:'fl5', //æµè¯ menu91 role3: 'role3', // llpæµè¯ menu92 // role2: 'role2', // llpæµè¯ menu93 // m2role1: 'm2role1', // llpæµè¯ menu94 // m2role2: 'm2role2' // llpæµè¯ menu...
calculatorReducer.js
Source:calculatorReducer.js
1import { createSlice } from '@reduxjs/toolkit';2const initialState = {3 usagePriceIs: 0,4 registrationPriceIs: 0,5 euroStandard: '',6 co2Amount: '',7 co2Coefficient: { registrationCof: 0, useCof: 0 },8 carType: {9 diesel: { checked: false, Euro6: 1.7, Euro5: 2, Euro43: 2.3, Euro21: 2.5 },10 petrol: { checked: false, Euro6: 0.9, Euro5: 1, Euro43: 1.1, Euro21: 1.4 },11 gas: { checked: false, Euro6: 0.8, Euro5: 0.9, Euro43: 1, Euro21: 1.3 },12 },13};14const calculatorReducer = createSlice({15 name: 'calculator',16 initialState,17 reducers: {18 setCo2Amount(state, action) {19 state.co2Amount = action.payload;20 //Set correct Co2 and registration coefficients (registrationCof, useCof) depending on Co2Amount value.21 let [regCof, useCof] = [0, 0];22 action.payload >= 251 && ([regCof, useCof] = [3, 0.36]);23 action.payload <= 250 &&24 action.payload >= 201 &&25 ([regCof, useCof] = [2.2, 0.28]);26 action.payload <= 200 &&27 action.payload >= 161 &&28 ([regCof, useCof] = [1.5, 0.19]);29 action.payload <= 160 &&30 action.payload >= 131 &&31 ([regCof, useCof] = [1.1, 0.14]);32 action.payload <= 130 && ([regCof, useCof] = [0, 0]);33 [state.co2Coefficient.registrationCof, state.co2Coefficient.useCof] = [34 regCof,35 useCof,36 ];37 },38 setEuroStandard(state, action) {39 state.euroStandard = action.payload;40 },41 setCarType(state, action) {42 //Allow a single checkbox to be checked.43 for (const key in state.carType) {44 key === action.payload45 ? (state.carType[key].checked = !state.carType[key].checked)46 : (state.carType[key].checked = false);47 }48 },49 calculateCost(state) {50 for (const key in state.carType) {51 if (state.carType[key].checked) {52 const euroStandard = state.euroStandard;53 const euroStandCof = state.carType[key][euroStandard];54 state.registrationPriceIs =55 state.co2Amount *56 state.co2Coefficient.registrationCof *57 euroStandCof;58 state.usagePriceIs =59 state.co2Amount * state.co2Coefficient.useCof * euroStandCof;60 }61 }62 },63 },64});65export const { setEuroStandard, setCo2Amount, setCarType, calculateCost } =66 calculatorReducer.actions;...
Using AI Code Generation
1var wpt = require('wpt');2var config = {3};4var test = new wpt(config);5}, function(err, data) {6 if (err) {7 console.log(err);8 }9 console.log(data);10});11var wpt = require('wpt');12var config = {13};14var test = new wpt(config);15}, function(err, data) {16 if (err) {17 console.log(err);18 }19 console.log(data);20});21test.getTestStatus('testid', function(err, data) {22 if (err) {23 console.log(err);24 }25 console.log(data);26});27test.getTestResults('testid', function(err, data) {28 if (err) {29 console.log(err);30 }31 console.log(data);32});33test.getTestResultsByLocation('testid', function(err, data) {34 if (err) {35 console.log(err);36 }37 console.log(data);38});39test.getTestRequests('testid', function(err, data) {40 if (err) {41 console.log(err);42 }43 console.log(data);44});45test.getTestBreakdown('testid', function(err, data) {46 if (err) {47 console.log(err);48 }49 console.log(data);50});51test.getTestPageSpeed('testid', function(err, data) {52 if (err) {53 console.log(err);54 }55 console.log(data);56});
Using AI Code Generation
1var wpt = require('webpagetest');2var options = {3};4var test = wpt(options);5 if (err) return console.error(err);6 console.log('Test started: ' + data.data.testId);7 test.getTestResults(data.data.testId, function(err, data) {8 if (err) return console.error(err);9 console.log('Test completed');10 console.log(data.data.median.firstView.SpeedIndex);11 });12});
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!