How to use datautil method in devicefarmer-stf

Best JavaScript code snippet using devicefarmer-stf

dataUtil.ts

Source:dataUtil.ts Github

copy

Full Screen

1export = class DataUtil {2 public static converterISOParaNumero(dataISO: string | null): number {3 return (dataISO && dataISO.length >= 10) ? (((10000 * parseInt(dataISO.substring(0, 4))) +4 (100 * parseInt(dataISO.substring(5, 7))) +5 parseInt(dataISO.substring(8, 10))) | 0) : 0;6 }7 public static converterNumeroParaISO(dataISONumerica: number): string {8 return DataUtil.formatar((dataISONumerica / 10000) | 0, ((dataISONumerica / 100) | 0) % 100, dataISONumerica % 100);9 }10 public static formatarBr(ano: number, mes: number, dia: number): string {11 return ((dia < 10) ? ("0" + dia) : dia) + "/" + ((mes < 10) ? ("0" + mes) : mes) + "/" + ano;12 }13 public static formatarBrComHorario(ano: number, mes: number, dia: number, hora: number, minuto: number, segundo: number): string {14 return ((dia < 10) ? ("0" + dia) : dia) + "/" + ((mes < 10) ? ("0" + mes) : mes) + "/" + ano + " " + ((hora < 10) ? ("0" + hora) : hora) + ":" + ((minuto < 10) ? ("0" + minuto) : minuto) + ":" + ((segundo < 10) ? ("0" + segundo) : segundo);15 }16 public static formatar(ano: number, mes: number, dia: number): string {17 return ano + "-" + ((mes < 10) ? ("0" + mes) : mes) + "-" + ((dia < 10) ? ("0" + dia) : dia);18 }19 public static formatarComHorario(ano: number, mes: number, dia: number, hora: number, minuto: number, segundo: number): string {20 return ano + "-" + ((mes < 10) ? ("0" + mes) : mes) + "-" + ((dia < 10) ? ("0" + dia) : dia) + " " + ((hora < 10) ? ("0" + hora) : hora) + ":" + ((minuto < 10) ? ("0" + minuto) : minuto) + ":" + ((segundo < 10) ? ("0" + segundo) : segundo);21 }22 public static converterDataISO(dataComOuSemHorario: string | null, formatoBr?: boolean): string | null {23 if (!dataComOuSemHorario || !(dataComOuSemHorario = dataComOuSemHorario.trim()))24 return null;25 let b1 = dataComOuSemHorario.indexOf("/");26 let b2 = dataComOuSemHorario.lastIndexOf("/");27 let dia: number, mes: number, ano: number;28 if (b1 <= 0 || b2 <= b1) {29 let b1 = dataComOuSemHorario.indexOf("-");30 let b2 = dataComOuSemHorario.lastIndexOf("-");31 if (b1 <= 0 || b2 <= b1)32 return null;33 ano = parseInt(dataComOuSemHorario.substring(0, b1));34 mes = parseInt(dataComOuSemHorario.substring(b1 + 1, b2));35 dia = parseInt(dataComOuSemHorario.substring(b2 + 1));36 } else {37 dia = parseInt(dataComOuSemHorario.substring(0, b1));38 mes = parseInt(dataComOuSemHorario.substring(b1 + 1, b2));39 ano = parseInt(dataComOuSemHorario.substring(b2 + 1));40 }41 if (isNaN(dia) || isNaN(mes) || isNaN(ano) ||42 dia < 1 || mes < 1 || ano < 1 ||43 dia > 31 || mes > 12 || ano > 9999)44 return null;45 switch (mes) {46 case 2:47 if (!(ano % 4) && ((ano % 100) || !(ano % 400))) {48 if (dia > 29)49 return null;50 } else {51 if (dia > 28)52 return null;53 }54 break;55 case 4:56 case 6:57 case 9:58 case 11:59 if (dia > 30)60 return null;61 break;62 }63 let sepHorario = dataComOuSemHorario.indexOf(" ");64 if (sepHorario < 0)65 sepHorario = dataComOuSemHorario.indexOf("T");66 if (sepHorario >= 0) {67 const horario = dataComOuSemHorario.substring(sepHorario + 1);68 const sepMinuto = horario.indexOf(":");69 if (sepMinuto >= 0) {70 const hora = parseInt(horario);71 const minuto = parseInt(horario.substring(sepMinuto + 1));72 if (hora >= 0 && hora <= 23 && minuto >= 0 && minuto <= 59) {73 const sepSegundo = horario.indexOf(":", sepMinuto + 1);74 if (sepSegundo >= 0) {75 const segundo = parseInt(horario.substring(sepSegundo + 1));76 if (segundo >= 0 && segundo <= 59)77 return (formatoBr ?78 DataUtil.formatarBrComHorario(ano, mes, dia, hora, minuto, segundo) :79 DataUtil.formatarComHorario(ano, mes, dia, hora, minuto, segundo));80 } else {81 return (formatoBr ?82 DataUtil.formatarBrComHorario(ano, mes, dia, hora, minuto, 0) :83 DataUtil.formatarComHorario(ano, mes, dia, hora, minuto, 0));84 }85 }86 }87 return null;88 }89 return (formatoBr ?90 DataUtil.formatarBr(ano, mes, dia) :91 DataUtil.formatar(ano, mes, dia));92 }93 public static removerHorario(dataISOOuBrComHorario: string): string {94 return ((!dataISOOuBrComHorario || dataISOOuBrComHorario.length < 10) ? "" : dataISOOuBrComHorario.substring(0, 10));95 }96 public static obterHorario(dataISOOuBrComHorario: string): string {97 return ((!dataISOOuBrComHorario || dataISOOuBrComHorario.length < 16) ? "" : dataISOOuBrComHorario.substring(11));98 }99 public static obterHorarioSemSegundos(dataISOOuBrComHorario: string): string {100 return ((!dataISOOuBrComHorario || dataISOOuBrComHorario.length < 16) ? "" : dataISOOuBrComHorario.substring(11, 16));101 }102 public static dateUTC(deltaSegundos?: number): Date {103 return (deltaSegundos ? new Date((new Date()).getTime() + (deltaSegundos * 1000)) : new Date());104 }105 public static horarioDeBrasiliaComoDateUTC(deltaSegundos?: number): Date {106 let time = (new Date()).getTime();107 if (deltaSegundos)108 time += (deltaSegundos * 1000);109 return new Date(time - (180 * 60000));110 }111 public static horarioDeBrasiliaBr(deltaSegundos?: number): string {112 const hoje = DataUtil.horarioDeBrasiliaComoDateUTC(deltaSegundos);113 return DataUtil.formatarBr(hoje.getUTCFullYear(), hoje.getUTCMonth() + 1, hoje.getUTCDate());114 }115 public static horarioDeBrasiliaBrComHorario(deltaSegundos?: number): string {116 const hoje = DataUtil.horarioDeBrasiliaComoDateUTC(deltaSegundos);117 return DataUtil.formatarBrComHorario(hoje.getUTCFullYear(), hoje.getUTCMonth() + 1, hoje.getUTCDate(), hoje.getUTCHours(), hoje.getUTCMinutes(), hoje.getUTCSeconds());118 }119 public static horarioDeBrasiliaBrInicioDoDia(deltaSegundos?: number): string {120 const hoje = DataUtil.horarioDeBrasiliaComoDateUTC(deltaSegundos);121 return DataUtil.formatarBrComHorario(hoje.getUTCFullYear(), hoje.getUTCMonth() + 1, hoje.getUTCDate(), 0, 0, 0);122 }123 public static horarioDeBrasiliaBrFimDoDia(deltaSegundos?: number): string {124 const hoje = DataUtil.horarioDeBrasiliaComoDateUTC(deltaSegundos);125 return DataUtil.formatarBrComHorario(hoje.getUTCFullYear(), hoje.getUTCMonth() + 1, hoje.getUTCDate(), 23, 59, 59);126 }127 public static horarioDeBrasiliaISO(deltaSegundos?: number): string {128 const hoje = DataUtil.horarioDeBrasiliaComoDateUTC(deltaSegundos);129 return DataUtil.formatar(hoje.getUTCFullYear(), hoje.getUTCMonth() + 1, hoje.getUTCDate());130 }131 public static horarioDeBrasiliaISOComHorario(deltaSegundos?: number): string {132 const hoje = DataUtil.horarioDeBrasiliaComoDateUTC(deltaSegundos);133 return DataUtil.formatarComHorario(hoje.getUTCFullYear(), hoje.getUTCMonth() + 1, hoje.getUTCDate(), hoje.getUTCHours(), hoje.getUTCMinutes(), hoje.getUTCSeconds());134 }135 public static horarioDeBrasiliaISOInicioDoDia(deltaSegundos?: number): string {136 const hoje = DataUtil.horarioDeBrasiliaComoDateUTC(deltaSegundos);137 return DataUtil.formatarComHorario(hoje.getUTCFullYear(), hoje.getUTCMonth() + 1, hoje.getUTCDate(), 0, 0, 0);138 }139 public static horarioDeBrasiliaISOFimDoDia(deltaSegundos?: number): string {140 const hoje = DataUtil.horarioDeBrasiliaComoDateUTC(deltaSegundos);141 return DataUtil.formatarComHorario(hoje.getUTCFullYear(), hoje.getUTCMonth() + 1, hoje.getUTCDate(), 23, 59, 59);142 }143 public static horarioUTCISO(deltaSegundos?: number): string {144 const hoje = DataUtil.dateUTC(deltaSegundos);145 return DataUtil.formatar(hoje.getUTCFullYear(), hoje.getUTCMonth() + 1, hoje.getUTCDate());146 }147 public static horarioUTCISOComHorario(deltaSegundos?: number): string {148 const hoje = DataUtil.dateUTC(deltaSegundos);149 return DataUtil.formatarComHorario(hoje.getUTCFullYear(), hoje.getUTCMonth() + 1, hoje.getUTCDate(), hoje.getUTCHours(), hoje.getUTCMinutes(), hoje.getUTCSeconds());150 }151 public static horarioLocalISO(deltaSegundos?: number): string {152 const hoje = DataUtil.dateUTC(deltaSegundos);153 return DataUtil.formatar(hoje.getFullYear(), hoje.getMonth() + 1, hoje.getDate());154 }155 public static horarioLocalISOComHorario(deltaSegundos?: number): string {156 const hoje = DataUtil.dateUTC(deltaSegundos);157 return DataUtil.formatarComHorario(hoje.getFullYear(), hoje.getMonth() + 1, hoje.getDate(), hoje.getHours(), hoje.getMinutes(), hoje.getSeconds());158 }159 public static horarioLocalBr(deltaSegundos?: number): string {160 const hoje = DataUtil.dateUTC(deltaSegundos);161 return DataUtil.formatarBr(hoje.getFullYear(), hoje.getMonth() + 1, hoje.getDate());162 }163 public static horarioLocalBrComHorario(deltaSegundos?: number): string {164 const hoje = DataUtil.dateUTC(deltaSegundos);165 return DataUtil.formatarBrComHorario(hoje.getFullYear(), hoje.getMonth() + 1, hoje.getDate(), hoje.getHours(), hoje.getMinutes(), hoje.getSeconds());166 }...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1// CMSC 389K - Midterm Project2// Priyanka Kishore, 04/10/20203var express = require('express'); // install Express module4var bodyParser = require('body-parser'); // Middleware = decodes and converts requests into readable format5var logger = require('morgan'); // Middleware = logs HTTP request details for debugging6var exphbs = require('express-handlebars'); // install Handlebars module for dynamic webpages7var dataUtil = require('./data-util');8var app = express();9var PORT = 6969;10var _DATA = dataUtil.loadData().all_reviews;11app.use(logger('dev'));12app.use(bodyParser.json());13app.use(bodyParser.urlencoded({ extended: false }));14app.engine('handlebars', exphbs({ defaultLayout: 'main' }));15app.set('view engine', 'handlebars');16app.use('/public', express.static('public'));17// -----------------------------------------------------------------------------------------18// GET home endpoint19app.get('/',function(req,res){20 res.render('home', {21 data: _DATA22 });23})24// GET endpoint to start write a review25app.get('/writeReview', function(req, res) {26 res.render('writereview')27})28// POST endpoint to post new restaurant review29app.post('/writeReview', function(req, res) {30 var body = req.body; // input from the form!31 console.log(body);32 body.tags = body.tags.split(",");33 dataUtil.cleanData(body, _DATA);34 // save data to database (aka JSON file)35 _DATA.push(req.body);36 dataUtil.saveData(_DATA);37 res.redirect('/');38})39// GET API endpoint, returns all data points as JSON40app.get('/api/getReviews', function(req, res) {41 res.json(_DATA);42})43app.get('/restaurant/:name', function(req, res) {44 // compile all ratings for this rest. and give average stats45 var name = req.params.name;46 var ratings = dataUtil.getAvgRating(name, _DATA);47 var price = dataUtil.getAvgPrice(name, _DATA);48 var all = dataUtil.getReviewsFor(name, _DATA);49 res.render('restaurant', {50 all: all,51 name: name,52 ratings: ratings,53 price: price54 })55})56// GET nav filter on top 3 restaurants57app.get('/Top3', function(req, res) {58 var data = dataUtil.getTop3(_DATA); // returns array of 59 res.render('home', {60 data: data,61 filter: "Top Three Restaurants"62 })63})64// GET nav filter on low costs65app.get('/LowCost', function(req, res) {66 var data = dataUtil.getLowCost(_DATA); // returns array of 67 res.render('home', {68 data: data,69 filter: "Not Pricey Restaurants"70 }) 71})72// GET nav filter on med costs73app.get('/MedCost', function(req, res) {74 var data = dataUtil.getMedCost(_DATA); // returns array of 75 res.render('home', {76 data: data,77 filter: "Kinda Pricey Restaurants"78 }) 79})80// GET nav filter on high costs81app.get('/HighCost', function(req, res) {82 var data = dataUtil.getHighCost(_DATA); // returns array of 83 res.render('home', {84 data: data,85 filter: "Hella Pricey Restaurants"86 }) 87})88// GET nav filter: all restaurants in alphabetical order89app.get('/Alphabetical', function(req, res) {90 var data = dataUtil.getAlphabetized(_DATA); // returns array of 91 res.render('home', {92 data: data,93 filter: "All Restaurants Alphabetized",94 abc: "yes"95 }) 96})97app.listen(PORT, function() {98 console.log('Listening on port:', PORT);...

Full Screen

Full Screen

datautil.js

Source:datautil.js Github

copy

Full Screen

1var deviceData = require('stf-device-db')2var browserData = require('stf-browser-db')3var logger = require('./logger')4var log = logger.createLogger('util:datautil')5var datautil = module.exports = Object.create(null)6datautil.applyData = function(device) {7 var match = deviceData.find({8 model: device.model9 , name: device.product10 })11 if (match) {12 device.name = match.name.id13 device.releasedAt = match.date14 device.image = match.image15 device.cpu = match.cpu16 device.memory = match.memory17 if (match.display && match.display.s) {18 device.display = device.display || {}19 device.display.inches = match.display.s20 }21 }22 return device23}24datautil.applyBrowsers = function(device) {25 if (device.browser) {26 device.browser.apps.forEach(function(app) {27 var data = browserData[app.type]28 if (data) {29 app.developer = data.developer30 }31 })32 }33 return device34}35datautil.applyOwner = function(device, user) {36 device.using = !!device.owner && device.owner.email === user.email37 return device38}39// Only owner can see this information40datautil.applyOwnerOnlyInfo = function(device, user) {41 if (device.owner && device.owner.email === user.email) {42 // No-op43 }44 else {45 device.remoteConnect = false46 device.remoteConnectUrl = null47 }48}49datautil.normalize = function(device, user) {50 datautil.applyData(device)51 datautil.applyBrowsers(device)52 datautil.applyOwner(device, user)53 datautil.applyOwnerOnlyInfo(device, user)54 if (!device.present) {55 device.owner = null56 }...

Full Screen

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 devicefarmer-stf 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