Best JavaScript code snippet using wpt
request.js
Source:request.js
1import axios from 'axios'2import { loadProgressBar } from 'axios-progress-bar'3import 'axios-progress-bar/dist/nprogress.css'4import { throttleAdapterEnhancer } from 'axios-extensions'5import flatry from '@core/utils/flatry'6class Request {7 constructor(options) {8 const opt = {9 ...{10 baseUrl: '',11 timeout: 10 * 1000,12 withCredentials: false,13 paramsSerializer: null,14 beforeRequest: (config) => {15 return config16 },17 onSuccess: (response) => Promise.resolve(response),18 onError: (error) => Promise.reject(error),19 },20 ...options,21 }22 const axiosConfig = {23 baseURL: opt.baseUrl,24 timeout: opt.timeout,25 withCredentials: opt.withCredentials,26 paramsSerializer: opt.paramsSerializer,27 adapter: throttleAdapterEnhancer(axios.defaults.adapter),28 }29 const httpClient = axios.create(axiosConfig)30 loadProgressBar({ showSpinner: false }, httpClient)31 httpClient.interceptors.request.use(32 (config) => {33 return opt.beforeRequest(config)34 },35 (error) => {36 return opt.onError(error)37 }38 )39 httpClient.interceptors.response.use(40 (response) => {41 return opt.onSuccess(response)42 },43 (error) => {44 return opt.onError(error)45 }46 )47 this.httpClient = httpClient48 }49 request(50 method,51 url,52 params = null,53 data = null,54 historyBack = false,55 cancelIgnore = false56 ) {57 const config = {58 url: url,59 method: method,60 historyBack: historyBack,61 cancelIgnore: cancelIgnore,62 }63 if (params) {64 config.params = params65 }66 if (data) {67 config.data = data68 }69 return flatry(this.httpClient.request(config))70 }71 get(url, params = null, historyBack = true, cancelIgnore = false) {72 return this.request('GET', url, params, null, historyBack, cancelIgnore)73 }74 post(url, data = null, params = null, historyBack = false) {75 return this.request('POST', url, params, data, historyBack)76 }77 put(url, data = null, params = null, historyBack = false) {78 return this.request('PUT', url, params, data, historyBack)79 }80 path(url, data = null, params = null, historyBack = false) {81 return this.request('PATH', url, params, data, historyBack)82 }83 delete(url, params = null, historyBack = false) {84 return this.request('DELETE', url, params, null, historyBack)85 }86 download(method, url, params = null, data = null, historyBack = false) {87 const config = {88 url: url,89 method: method,90 timeout: 120 * 1000,91 responseType: 'blob',92 historyBack: historyBack,93 onDownloadProgress: (progressEvent) => {94 console.log(progressEvent)95 },96 }97 if (params) {98 config.params = params99 }100 if (data) {101 config.data = data102 }103 return flatry(104 this.httpClient.request(config).then((response) => {105 let filename = response.headers['x-suggested-filename']106 if (!filename) {107 filename = response.headers['content-disposition'].match(108 /filename="(.+)"/109 )[1]110 }111 if (filename) {112 const url = window.URL.createObjectURL(113 new Blob([response.data], {114 type: response.headers['content-type'],115 })116 )117 const link = document.createElement('a')118 link.href = url119 link.setAttribute('download', decodeURIComponent(filename))120 link.click()121 window.URL.revokeObjectURL(url)122 return true123 } else {124 return false125 }126 })127 )128 }129}...
history-back.js
Source:history-back.js
1import BaseComponent from 'bootstrap/js/src/base-component.js'2import EventHandler from 'bootstrap/js/src/dom/event-handler'3import SelectorEngine from 'bootstrap/js/src/dom/selector-engine'4const NAME = 'historyback'5const DATA_KEY = 'bs.historyback'6const EVENT_KEY = `.${DATA_KEY}`7const DATA_API_KEY = '.data-api'8const EVENT_CLICK = `click${EVENT_KEY}`9const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`10const SELECTOR_TOGGLE = '[data-bs-toggle="historyback"]'11class HistoryBack extends BaseComponent {12 constructor(element) {13 super(element)14 this._bindEvents()15 }16 // Getters17 static get NAME() {18 return NAME19 }20 // Public21 back() {22 window.history.back()23 }24 // Private25 _bindEvents() {26 EventHandler.on(this._element, EVENT_CLICK, (evt) => {27 evt.preventDefault()28 this.back()29 })30 }31}32/**33 * ------------------------------------------------------------------------34 * Data Api implementation35 * ------------------------------------------------------------------------36 */37const toggles = SelectorEngine.find(SELECTOR_TOGGLE)38toggles.forEach((toggle) => {39 EventHandler.one(toggle, EVENT_CLICK_DATA_API, (evt) => {40 evt.preventDefault()41 const historyBack = HistoryBack.getOrCreateInstance(toggle)42 historyBack.back()43 })44})...
historyBack.js
Source:historyBack.js
2 'use strict';3 angular.module('app.directives')4 .directive('historyBack', historyBack);5 historyBack.$inject = ['$window'];6 function historyBack($window) {7 return {8 restrict: 'AE',9 scope: {},10 replace:true,11 template:'<a tooltip="Back" class="btn btn-sm btn-default w-xxs w-auto-xs"><i class="fa fa-long-arrow-left"></i></a>',12 link: link13 }14 function link($scope, $elems, $attrs) {15 $elems.bind('click', function () {16 $window.history.back();17 });18 }19 }20})();
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2wptoolkit.historyBack();3var wptoolkit = require('wptoolkit');4wptoolkit.historyForward();5var wptoolkit = require('wptoolkit');6wptoolkit.historyGo(2);7var wptoolkit = require('wptoolkit');8wptoolkit.historyLength();9var wptoolkit = require('wptoolkit');10wptoolkit.historyState();11var wptoolkit = require('wptoolkit');12wptoolkit.historyReplaceState({foo:'bar'},'title','url');13var wptoolkit = require('wptoolkit');14wptoolkit.historyPushState({foo:'bar'},'title','url');15var wptoolkit = require('wptoolkit');16wptoolkit.historyState();17var wptoolkit = require('wptoolkit');18wptoolkit.getHistoryState();19var wptoolkit = require('wptoolkit');20wptoolkit.getHistoryState();21var wptoolkit = require('wptoolkit');22wptoolkit.getHistoryState();23var wptoolkit = require('wptoolkit');24wptoolkit.getHistoryState();
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2wptoolkit.historyBack();3var wptoolkit = require('wptoolkit');4wptoolkit.historyForward();5var wptoolkit = require('wptoolkit');6wptoolkit.historyGo(2);7var wptoolkit = require('wptoolkit');8wptoolkit.historyGoBack();9var wptoolkit = require('wptoolkit');10wptoolkit.historyGoForward();11var wptoolkit = require('wptoolkit');12wptoolkit.historyLength();13var wptoolkit = require('wptoolkit');14wptoolkit.historyPushState('data', 'title', 'url');15var wptoolkit = require('wptoolkit');16wptoolkit.historyReplaceState('data', 'title', 'url');17var wptoolkit = require('wptoolkit');18wptoolkit.historyState();19var wptoolkit = require('wptoolkit');20wptoolkit.historyStateData();21var wptoolkit = require('wptoolkit');22wptoolkit.historyStateTitle();23var wptoolkit = require('wptoolkit');24wptoolkit.historyStateUrl();
Using AI Code Generation
1var historyBack = require("wptoolkit").historyBack;2historyBack();3var historyForward = require("wptoolkit").historyForward;4historyForward();5var historyGo = require("wptoolkit").historyGo;6historyGo(2);7var historyLength = require("wptoolkit").historyLength;8historyLength();9var historyState = require("wptoolkit").historyState;10historyState();11var historyReplaceState = require("wptoolkit").historyReplaceState;12historyReplaceState({foo: "bar"}, "foo", "/foo");13var historyPushState = require("wptoolkit").historyPushState;14historyPushState({foo: "bar"}, "foo", "/foo");15var historyPopState = require("wptoolkit").historyPopState;16historyPopState();17var historyStateChange = require("wptoolkit").historyStateChange;18historyStateChange(function (e) {19 console.log(e.state);20});21var historyStateChangeOnce = require("wptoolkit").historyStateChangeOnce;22historyStateChangeOnce(function (e) {23 console.log(e.state);24});25var historyStateChangeOff = require("wptoolkit").historyStateChangeOff;26historyStateChangeOff();27var historyStateChangeOnceOff = require("wptoolkit").historyStateChangeOnceOff
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2wptoolkit.historyBack();3var wptoolkit = require('wptoolkit');4wptoolkit.historyForward();5var wptoolkit = require('wptoolkit');6wptoolkit.historyGo(-1);7var wptoolkit = require('wptoolkit');8wptoolkit.historyLength();9var wptoolkit = require('wptoolkit');10wptoolkit.historyState();11var wptoolkit = require('wptoolkit');12wptoolkit.historyUrl();13var wptoolkit = require('wptoolkit');14wptoolkit.historyPush('/test', { test: 'test' });15var wptoolkit = require('wptoolkit');16wptoolkit.historyReplace('/test', { test: 'test' });17var wptoolkit = require('wptoolkit');18wptoolkit.historyPop();19var wptoolkit = require('wptoolkit');20wptoolkit.historyClear();
Using AI Code Generation
1var wptjs = require('wptjs');2var wpt = new wptjs();3 if(err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var wptjs = require('wptjs');10var wpt = new wptjs();11 if(err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17var wptjs = require('wptjs');18var wpt = new wptjs();19 if(err) {20 console.log(err);21 } else {22 console.log(data);23 }24});25var wptjs = require('wptjs');26var wpt = new wptjs();27 if(err) {28 console.log(err);29 } else {30 console.log(data);31 }32});33var wptjs = require('wptjs');34var wpt = new wptjs();35wpt.getLocations(function(err, data) {36 if(err) {37 console.log(err);38 } else {39 console.log(data);40 }41});42var wptjs = require('wptjs');43var wpt = new wptjs();44wpt.getTesters(function(err, data) {45 if(err) {46 console.log(err);47 } else {48 console.log(data);49 }50});
Using AI Code Generation
1var wptoolkit = require('com.wp.wptoolkit');2wptoolkit.historyBack();3### historyForward()4var wptoolkit = require('com.wp.wptoolkit');5wptoolkit.historyForward();6### canGoBack()7var wptoolkit = require('com.wp.wptoolkit');8var canGoBack = wptoolkit.canGoBack();9### canGoForward()10var wptoolkit = require('com.wp.wptoolkit');11var canGoForward = wptoolkit.canGoForward();12### setWebViewZoom()13var wptoolkit = require('com.wp.wptoolkit');14wptoolkit.setWebViewZoom(2.0);15### getWebViewZoom()16var wptoolkit = require('com.wp.wptoolkit');17var zoom = wptoolkit.getWebViewZoom();18### setWebViewZoomControlsEnabled()19var wptoolkit = require('com.wp.wptoolkit');20wptoolkit.setWebViewZoomControlsEnabled(true);21### getWebViewZoomControlsEnabled()
Using AI Code Generation
1var wpt = require('webpagetest');2var webpagetest = new wpt('www.webpagetest.org');3var testId = '160711_7H_1c0f8b1d9e9a1b7f0a1a2c2d2d2f2e2f';4webpagetest.historyBack(testId, function(err, data) {5 if (err) return console.error(err);6 console.log(data);7});8var wpt = require('webpagetest');9var webpagetest = new wpt('www.webpagetest.org');10var testId = '160711_7H_1c0f8b1d9e9a1b7f0a1a2c2d2d2f2e2f';11webpagetest.historyForward(testId, function(err, data) {12 if (err) return console.error(err);13 console.log(data);14});15var wpt = require('webpagetest');16var webpagetest = new wpt('www.webpagetest.org');17var testId = '160711_7H_1c0f8b1d9e9a1b7f0a1a2c2d2d2f2e2f';18webpagetest.clearCache(testId, function(err, data) {19 if (err) return console.error(err);20 console.log(data);21});22var wpt = require('webpagetest');23var webpagetest = new wpt('www.webpagetest.org');24var testId = '160711_7H_1c0f8b1d9e9a1b7f0a1a2c2d2d2f2e2f';25webpagetest.setScript(testId, function(err, data) {26 if (err) return console.error(err);27 console.log(data);28});
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!!