Best JavaScript code snippet using wpt
route.js
Source:route.js
1"use strict";2const fStation = require("./station.js");3const fJourney = require("./journey.js");4const sRouteHTMLHeader1 ={5 "en": '<tr><th align="center">Departure</th><th align="center">Arrival</th></tr>',6 "de": '<tr><th align="center">Abfahrt</th><th align="center">Ankunft</th></tr>',7 "ru": '<tr><th align="center">ÐÑÐ»ÐµÑ Ð¸Ð·</th><th align="center">ÐÑибÑÑие</th></tr>',8 "pt": '<tr><th align="center">SaÃda</th><th align="center">Chegada</th></tr>',9 "nl": '<tr><th align="center">Vertrek</th><th align="center">Aankomst</th></tr>',10 "fr": '<tr><th align="center">Départ</th><th align="center">Arrivée</th></tr>',11 "it": '<tr><th align="center">Partenza</th><th align="center">Arrivo</th></tr>',12 "es": '<tr><th align="center">Salida</th><th align="center">Llegada</th></tr>',13 "pl": '<tr><th align="center">wyjazd</th><th align="center">Przyjazd</th></tr>',14 "zh-cn": '<tr><th align="center">离å¼</th><th align="center">å°è¾¾</th></tr>'15};16const sRouteHTMLHeader2 ={17 "en": '<tr><th align="center">Departure</th><th align="center">Delay</th><th align="center">Arrival</th><th align="center">Delay</th></tr>',18 "de": '<tr><th align="center">Abfahrt</th><th align="center">Verspätung</th><th align="center">Ankunft</th><th align="center">Verspätung</th></tr>',19 "ru": '<tr><th align="center">ÐÑÐ»ÐµÑ Ð¸Ð·</th><th align="center">задеÑжка</th><th align="center">ÐÑибÑÑие</th><th align="center">задеÑжка</th></tr>',20 "pt": '<tr><th align="center">SaÃda</th><th align="center">Demora</th><th align="center">Chegada</th><th align="center">Demora</th></tr>',21 "nl": '<tr><th align="center">Vertrek</th><th align="center">Vertraging</th><th align="center">Aankomst</th><th align="center">Vertraging</th></tr>',22 "fr": '<tr><th align="center">Départ</th><th align="center">Retard</th><th align="center">Arrivée</th><th align="center">Retard</th></tr>',23 "it": '<tr><th align="center">Partenza</th><th align="center">Ritardo</th><th align="center">Arrivo</th><th align="center">Ritardo</th></tr>',24 "es": '<tr><th align="center">Salida</th><th align="center">Retrasar</th><th align="center">Llegada</th><th align="center">Retrasar</th></tr>',25 "pl": '<tr><th align="center">wyjazd</th><th align="center">Opóźnienie</th><th align="center">Przyjazd</th><th align="center">Opóźnienie</th></tr>',26 "zh-cn": '<tr><th align="center">离å¼</th><th align="center">延è¿</th><th align="center">å°è¾¾</th><th align="center">延è¿</th></tr>'27};28const sRouteHTMLHeader3 ={29 "en": '<tr><th align="center">Departure</th><th align="center">Delay</th><th align="center">Platform</th><th align="center">Arrival</th><th align="center">Delay</th><th align="center">Platform</th></tr>',30 "de": '<tr><th align="center">Abfahrt</th><th align="center">Verspätung</th><th align="center">Plattform</th><th align="center">Ankunft</th><th align="center">Verspätung</th><th align="center">Plattform</th></tr>',31 "ru": '<tr><th align="center">ÐÑÐ»ÐµÑ Ð¸Ð·</th><th align="center">задеÑжка</th><th align="center">ÐлаÑÑоÑма</th><th align="center">ÐÑибÑÑие</th><th align="center">задеÑжка</th><th align="center">ÐлаÑÑоÑма</th></tr>',32 "pt": '<tr><th align="center">SaÃda</th><th align="center">Demora</th><th align="center">Plataforma</th><th align="center">Chegada</th><th align="center">Demora</th><th align="center">Plataforma</th></tr>',33 "nl": '<tr><th align="center">Vertrek</th><th align="center">Vertraging</th><th align="center">Platform</th><th align="center">Aankomst</th><th align="center">Vertraging</th><th align="center">Platform</th></tr>',34 "fr": '<tr><th align="center">Départ</th><th align="center">Retard</th><th align="center">Plate-forme</th><th align="center">Arrivée</th><th align="center">Retard</th><th align="center">Plate-forme</th></tr>',35 "it": '<tr><th align="center">Partenza</th><th align="center">Ritardo</th><th align="center">piattaforma</th><th align="center">Arrivo</th><th align="center">Ritardo</th><th align="center">piattaforma</th></tr>',36 "es": '<tr><th align="center">Salida</th><th align="center">Retrasar</th><th align="center">Plataforma</th><th align="center">Llegada</th><th align="center">Retrasar</th><th align="center">Plataforma</th></tr>',37 "pl": '<tr><th align="center">wyjazd</th><th align="center">Opóźnienie</th><th align="center">Platforma</th><th align="center">Przyjazd</th><th align="center">Opóźnienie</th><th align="center">Platforma</th></tr>',38 "zh-cn": '<tr><th align="center">离å¼</th><th align="center">延è¿</th><th align="center">å¹³å°</th><th align="center">å°è¾¾</th><th align="center">延è¿</th><th align="center">å¹³å°</th></tr>'39};40class fRoute{41 constructor(helper){42 this.helper = helper;43 this.StationFrom = new fStation(this.helper);44 this.StationTo = new fStation(this.helper);45 this.StationVia = new fStation(this.helper);46 this.Journeys = new Array();47 this.enabled = false;48 this.html = "";49 this.json = "";50 this.index = 0;51 this.NumDeps = 3;52 this.JourneysFound = true;53 }54 /**55 * Writes basic states for Route to ioBroker56 */57 async writeBaseStates(){58 try {59 if (this.enabled === true) {60 await this.helper.SetChannel(this.index.toString(), `Route #${this.index.toString()} - ${this.StationFrom.name} - ${this.StationTo.name}`, "Route from Adapter configuration");61 }62 await this.helper.SetBoolState(`${this.index.toString()}.Enabled`, `Configuration State of Route #${this.index.toString()}`, "Route State from Adapter configuration", this.enabled);63 } catch (e){64 this.helper.ReportingError(e, `Exception in Route`, "fRoute", "writeBaseStates");65 throw this.helper.ErrorCustom("HANDLED");66 }67 }68 /**69 * Writes states for Route to ioBroker70 */71 async writeStates(){72 try {73 for (const iJourneysCurrent in this.Journeys) {74 await this.Journeys[iJourneysCurrent].writeJourney(`${this.index}.${iJourneysCurrent}`, this.index, iJourneysCurrent);75 }76 //await this.helper.deleteUnusedConnections(this.index, this.Journeys.length);77 await this.helper.deleteUnusedConnections(this.index, this.NumDeps);78 } catch (e){79 this.helper.ReportingError(e, `Exception in Route`, "fRoute", "writeStates", "", {json: this.json} );80 throw this.helper.ErrorCustom("HANDLED");81 }82 }83 /**84 * Writes HTML for Route to ioBroker85 */86 async writeHTML(){87 try {88 if (this.helper.Fahrplan.config.CreateHTML > 0){89 this.html = `<table width="100%"><tr><th align="left" colspan="${this.helper.Fahrplan.config.CreateHTML + 1}">${this.StationFrom.customname} - ${this.StationTo.customname}</th></tr>`;90 if (this.helper.Fahrplan.config.CreateHTMLHeadlines === 1){91 switch (this.helper.Fahrplan.config.CreateHTML){92 case 2:93 this.html = `${this.html}${sRouteHTMLHeader2[this.helper.Fahrplan.SysLang]}`;94 break;95 case 3:96 this.html = `${this.html}${sRouteHTMLHeader3[this.helper.Fahrplan.SysLang]}`;97 break;98 default:99 this.html = `${this.html}${sRouteHTMLHeader1[this.helper.Fahrplan.SysLang]}`;100 break;101 }102 }103 for (const iJourneysCurrent in this.Journeys) {104 this.html = `${this.html}${this.Journeys[iJourneysCurrent].createHTML()}`;105 }106 this.html = `${this.html}</table>`;107 await this.helper.SetTextState(`${this.index.toString()}.HTML`, "HTML", "HTML", this.html, "html");108 } else{109 await this.helper.deleteObject(`${this.index.toString()}.HTML`);110 }111 // Create HTML states per Journey if configured112 for (const iJourneysCurrent in this.Journeys) {113 this.Journeys[iJourneysCurrent].writeJourneyHTML(`${this.index}.${iJourneysCurrent}`);114 }115 } catch (e){116 this.helper.ReportingError(e, `Exception in Route`, "fRoute", "writeHTML", "", {json: this.json} );117 throw this.helper.ErrorCustom("HANDLED");118 }119 }120 /**121 * Gets Route information from Website and extracts informations122 * @typedef {import('./options')} fOptions123 * @param {fOptions} RouteOptions Single configuration entry for route124 */125 async getRoute(RouteOptions){126 let aRouteResult = null;127 // RouteSearch128 try{129 this.helper.ReportingInfo("Debug", "Route", `Executing HAFAS search for Route #${this.index.toString()}`, "fRoute", "getRoute", "RouteSearch", JSON.stringify(RouteOptions.returnRouteOptions()));130 aRouteResult = await this.helper.hClient.journeys(this.StationFrom.id.toString(), this.StationTo.id.toString(), RouteOptions.returnRouteOptions());131 this.json = JSON.stringify(aRouteResult);132 this.helper.ReportingInfo("Debug", "Route", `Result received for Route #${this.index.toString()}: ${JSON.stringify(aRouteResult)}`, "fRoute", "getRoute", "RouteSearch", JSON.stringify(aRouteResult));133 if (this.helper.Fahrplan.config.SaveJSON !== false){134 await this.helper.SetTextState(`${this.index.toString()}.JSON`, "Route JSON", "Route JSON", JSON.stringify(aRouteResult), "json");135 }136 } catch (e){137 if (e.hafasErrorCode === "H890"){138 this.helper.Fahrplan.log.error(`No journeys found for route ${this.index} (HAFAS-Error H890)`);139 this.JourneysFound = false;140 } else if (e.isHafasError === true){141 this.helper.ReportingError(e, `HAFAS error in Route`, "fRoute", "getRoute", "", {hafas: {request: e.request, url: e.url, statusCode: e.statusCode, code: e.code, responseId: e.responseId} });142 // this.helper.Fahrplan.log.error(`Error at HAFAS (${e.message})`);143 this.JourneysFound = false;144 } else if ( e.code === "EAI_AGAIN" ||145 e.name === "FetchError" ||146 e.code === "CGI_READ_FAILED" ||147 e.message === "HCI Service: request failed" ||148 e.message === "HCI Service: problems during service execution" ||149 e.message === "Bad Gateway" ||150 e.message === "Gateway Timeout" ||151 e.message === "Gateway Time-out"){152 this.helper.Fahrplan.log.error(`Connection error to HAFAS (${e.message})`);153 this.JourneysFound = false;154 } else if (e.name === "TypeError" && e.stack.includes("at applyRemarks") === true){155 // See issue: https://github.com/public-transport/hafas-client/issues/196156 this.helper.Fahrplan.log.error(`Unknown error to HAFAS (${e.message})`);157 this.JourneysFound = false;158 }else{159 this.helper.ReportingError(e, `Exception in Route`, "fRoute", "getRoute", "RouteSearch");160 throw this.helper.ErrorCustom("HANDLED");161 }162 }163 // Iterating Journey results164 try{165 if (this.JourneysFound === true){166 for (const iJourneysCurrent in aRouteResult.journeys) {167 if (parseInt(iJourneysCurrent) < this.NumDeps){168 const aConn = aRouteResult.journeys[iJourneysCurrent];169 this.helper.ReportingInfo("Debug", "Route", `Route #${this.index.toString()} running on Journey #${iJourneysCurrent}: ${JSON.stringify(aConn)}`, "fRoute", "getRoute", "Iteration", JSON.stringify(aConn));170 const CurrentJourney = new fJourney(this.helper);171 CurrentJourney.StationFrom = this.StationFrom;172 CurrentJourney.StationTo = this.StationTo;173 CurrentJourney.parseJourney(aConn);174 await CurrentJourney.checkDelay(`${this.index}.${iJourneysCurrent}`, this.index);175 this.Journeys.push(CurrentJourney);176 }177 }178 }179 }catch (e) {180 this.helper.ReportingError(e, `Exception in Route`, "fRoute", "getRoute", "Iteration", {json: this.json});181 throw this.helper.ErrorCustom("HANDLED");182 }183 }184}...
angular-locale_vi.js
Source:angular-locale_vi.js
1'use strict';2angular.module("ngLocale", [], ["$provide", function($provide) {3var PLURAL_CATEGORY = {ZERO: "zero", ONE: "one", TWO: "two", FEW: "few", MANY: "many", OTHER: "other"};4$provide.value("$locale", {5 "DATETIME_FORMATS": {6 "AMPMS": [7 "SA",8 "CH"9 ],10 "DAY": [11 "Ch\u1ee7 Nh\u1eadt",12 "Th\u1ee9 Hai",13 "Th\u1ee9 Ba",14 "Th\u1ee9 T\u01b0",15 "Th\u1ee9 N\u0103m",16 "Th\u1ee9 S\u00e1u",17 "Th\u1ee9 B\u1ea3y"18 ],19 "ERANAMES": [20 "tr. CN",21 "sau CN"22 ],23 "ERAS": [24 "tr. CN",25 "sau CN"26 ],27 "FIRSTDAYOFWEEK": 0,28 "MONTH": [29 "th\u00e1ng 1",30 "th\u00e1ng 2",31 "th\u00e1ng 3",32 "th\u00e1ng 4",33 "th\u00e1ng 5",34 "th\u00e1ng 6",35 "th\u00e1ng 7",36 "th\u00e1ng 8",37 "th\u00e1ng 9",38 "th\u00e1ng 10",39 "th\u00e1ng 11",40 "th\u00e1ng 12"41 ],42 "SHORTDAY": [43 "CN",44 "Th 2",45 "Th 3",46 "Th 4",47 "Th 5",48 "Th 6",49 "Th 7"50 ],51 "SHORTMONTH": [52 "thg 1",53 "thg 2",54 "thg 3",55 "thg 4",56 "thg 5",57 "thg 6",58 "thg 7",59 "thg 8",60 "thg 9",61 "thg 10",62 "thg 11",63 "thg 12"64 ],65 "STANDALONEMONTH": [66 "Th\u00e1ng 1",67 "Th\u00e1ng 2",68 "Th\u00e1ng 3",69 "Th\u00e1ng 4",70 "Th\u00e1ng 5",71 "Th\u00e1ng 6",72 "Th\u00e1ng 7",73 "Th\u00e1ng 8",74 "Th\u00e1ng 9",75 "Th\u00e1ng 10",76 "Th\u00e1ng 11",77 "Th\u00e1ng 12"78 ],79 "WEEKENDRANGE": [80 5,81 682 ],83 "fullDate": "EEEE, 'ng\u00e0y' dd MMMM 'n\u0103m' y",84 "longDate": "'Ng\u00e0y' dd 'th\u00e1ng' MM 'n\u0103m' y",85 "medium": "dd-MM-y HH:mm:ss",86 "mediumDate": "dd-MM-y",87 "mediumTime": "HH:mm:ss",88 "short": "dd/MM/y HH:mm",89 "shortDate": "dd/MM/y",90 "shortTime": "HH:mm"91 },92 "NUMBER_FORMATS": {93 "CURRENCY_SYM": "\u20ab",94 "DECIMAL_SEP": ",",95 "GROUP_SEP": ".",96 "PATTERNS": [97 {98 "gSize": 3,99 "lgSize": 3,100 "maxFrac": 3,101 "minFrac": 0,102 "minInt": 1,103 "negPre": "-",104 "negSuf": "",105 "posPre": "",106 "posSuf": ""107 },108 {109 "gSize": 3,110 "lgSize": 3,111 "maxFrac": 2,112 "minFrac": 2,113 "minInt": 1,114 "negPre": "-",115 "negSuf": "\u00a0\u00a4",116 "posPre": "",117 "posSuf": "\u00a0\u00a4"118 }119 ]120 },121 "id": "vi",122 "localeID": "vi",123 "pluralCat": function(n, opt_precision) { return PLURAL_CATEGORY.OTHER;}124});...
BookingList.js
Source:BookingList.js
1const React = require('react');2import Booking from './Booking.js';3class BookingList extends React.Component {4 5 constructor(props) {6 super(props);7 }8 render() {9 var bookings = this.props.bookings.map(booking => 10 <Booking key={booking.entity._links.self.href}11 booking={booking}12 attributes={this.props.attributes}13 onUpdate={this.props.onUpdate}14 onDelete={this.props.onDelete}/>15 );16 return (17 <div>18 <table id="DataTable">19 <tbody>20 <tr>21 <th>kreuzfahrt</th> 22 <th>flug</th>23 <th>hotel</th>24 <th>versicherung</th>25 <th>total</th>26 <th>dayDeparture</th> 27 <th>monthDeparture</th>28 <th>yearDeparture</th>29 <th>surname</th>30 <th>firstName</th>31 <th>bookingNumber</th> 32 <th>storno</th>33 <th>comment</th>34 <th>booking date</th>35 <th>manager</th>36 <th></th>37 <th></th>38 </tr>39 {bookings}40 </tbody>41 </table>42 </div>43 )44 }45}...
Using AI Code Generation
1var wpt = require('webpagetest');2var webPageTest = new wpt('www.webpagetest.org');3var options = {4};5webPageTest.runTest(url, options, function(err, data) {6 if (err) return console.error(err);7 console.log(data);8});9var wpt = require('webpagetest');10var webPageTest = new wpt('www.webpagetest.org');11var options = {12};13webPageTest.runTest(url, options, function(err, data) {14 if (err) return console.error(err);15 console.log(data);16});17var wpt = require('webpagetest');18var webPageTest = new wpt('www.webpagetest.org');19var options = {20};21webPageTest.runTest(url, options, function(err, data) {22 if (err) return console.error(err);23 console.log(data);24});25var wpt = require('webpagetest');26var webPageTest = new wpt('www.webpagetest.org');27var options = {28};29webPageTest.runTest(url, options, function(err, data) {30 if (err) return console.error(err);31 console.log(data);32});33var wpt = require('webpagetest');34var webPageTest = new wpt('www.webpagetest.org');35var options = {
Using AI Code Generation
1const wpt = require('webpagetest');2const wptClient = wpt('www.webpagetest.org');3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});
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!!