Best JavaScript code snippet using wpt
custom_script.js
Source:custom_script.js
1//set select2's default theme2//$.fn.select2.defaults.set( "theme", "bootstrap4" );3//$.fn.select2.defaults.set( "theme", "bootstrap" );4/*select2 plugin for set options' data attribute */5(function($) {6 //$('#element').val('val_id').trigger('change');7 //$('#element').select2('val', 'val_id', true).trigger('change');8 //$(element).select2('data', newObject, true);9 //$("#element").select2("trigger", "select", { data: { id: "val_id" } });10 $.fn.setSelect2OptionDataAttribute = function(newData) {11 //newData = [];12 try{13 var origOptions = this.data("select2").options.options;14 origOptions.data = [];15 var newOptions = $.extend(origOptions, {data: newData});16 this.empty().select2(newOptions);17 }catch(e){18 console.log("error");19 }20 return this;21 };22})(jQuery);23(function($){24 //25 /*26 //window.localStorage - "stores data with no expiration date"27 //window.sessionStorage - "stores data for one session (data is lost when the browser tab is closed)"28 //localStorage.setItem("key", "value");29 //window.localStorage.setItem('key', JSON.stringify({}));30 //localStorage.getItem("key");31 //localStorage.removeItem("key");32 //localStorage.clear();33 */34 /*35 if ( (typeof(Storage) !== void(0)) && (typeof(Storage) !== "undefined") ) {36 // Code for localStorage/sessionStorage.37 } else {38 // Sorry! No Web Storage support..39 }40 */41 42 /**43 * Set an item to a storage() object44 * @param {String} name The storage() key45 * @param {String} key The storage() value object key46 * @param {String} value The storage() value object value47 */48 $.fn.setMyStorageData = function (key_1, value, key_2 = null) {49 var myStorageObject = window.sessionStorage;50 if( (key_2 != null) && (key_2 != void(0)) ){51 var existing = myStorageObject.getItem(key_2);52 existing = (existing) ? JSON.parse(existing) : new Object;53 if( (key_1 != null) && (key_1 != void(0)) ){54 existing[key_1] = value;55 }else{56 existing = value;57 }58 myStorageObject.setItem(key_2, JSON.stringify(existing));59 }else{60 myStorageObject.setItem(key_1, JSON.stringify(value));61 }62 };63})(jQuery);64(function($){65 //66 /*67 //window.localStorage - "stores data with no expiration date"68 //window.sessionStorage - "stores data for one session (data is lost when the browser tab is closed)"69 //localStorage.setItem("key", "value");70 //window.localStorage.setItem('key', JSON.stringify({}));71 //localStorage.getItem("key");72 //localStorage.removeItem("key");73 //localStorage.clear();74 */75 /*76 if ( (typeof(Storage) !== void(0)) && (typeof(Storage) !== "undefined") ) {77 // Code for localStorage/sessionStorage.78 } else {79 // Sorry! No Web Storage support..80 }81 */82 83 /**84 * Get an item from a storage() object85 * @param {String} name The storage() key86 * @param {String} key The storage() value object key87 */88 $.fn.getMyStorageData = function (key_1, key_2 = null) {89 var myStorageObject = window.sessionStorage;90 var myStorageObjectData = null;91 if( (key_2 != null) && (key_2 != void(0)) ){92 var existing = myStorageObject.getItem(name);93 existing = (existing) ? JSON.parse(existing) : new Object;94 if( (key_1 != null) && (key_1 != void(0)) ){95 myStorageObjectData = existing[key_1];96 }else{97 myStorageObjectData = existing;98 }99 }else{100 myStorageObjectData = JSON.parse(myStorageObject.getItem(key_1));101 }102 return myStorageObjectData;103 };104})(jQuery);105(function($){106 //107 /*108 //window.localStorage - "stores data with no expiration date"109 //window.sessionStorage - "stores data for one session (data is lost when the browser tab is closed)"110 //localStorage.setItem("key", "value");111 //window.localStorage.setItem('key', JSON.stringify({}));112 //localStorage.getItem("key");113 //localStorage.removeItem("key");114 //localStorage.clear();115 */116 /*117 if ( (typeof(Storage) !== void(0)) && (typeof(Storage) !== "undefined") ) {118 // Code for localStorage/sessionStorage.119 } else {120 // Sorry! No Web Storage support..121 }122 */123 124 /**125 * Remove an item from a storage() object126 * @param {String} name The storage() key127 * @param {String} key The storage() value object key128 */129 $.fn.removeMyStorageData = function (key_1, key_2 = null) {130 var myStorageObject = window.sessionStorage;131 if( (key_2 != null) && (key_2 != void(0)) ){132 var existing = myStorageObject.getItem(key_2);133 existing = (existing) ? JSON.parse(existing) : new Object;134 if( (key_1 != null) && (key_1 != void(0)) ){135 //console.log( Object.keys(existing) );136 delete existing[key_1];137 var existingFiltered = existing.filter(function(element, index, filterArray, optionalData){138 return index != key_1;139 });140 key_1 = null;141 $(document).setMyStorageData(key_1, existingFiltered, key_2);142 }else{143 myStorageObject.removeItem(key_2);144 }145 }else{146 myStorageObject.removeItem(key_1);147 }148 };149})(jQuery);150$(function(){151 "use strict";152 var myStorageObject = window.sessionStorage;153 myStorageObject.clear();...
Retrieve_Where_Composite_Key.spec.ts
Source:Retrieve_Where_Composite_Key.spec.ts
1import { createStore } from 'test/support/Helpers'2import Model from '@/model/Model'3describe('Feature â Retrieve â Where - Composite Keys', () => {4 class User extends Model {5 static entity = 'users'6 static primaryKey = ['key_1', 'key_2']7 static fields() {8 return {9 key_1: this.attr(null),10 key_2: this.attr(null)11 }12 }13 }14 it('can retrieve records that matches the whereId clause', async () => {15 const store = createStore([{ model: User }])16 await store.dispatch('entities/users/create', {17 data: [18 { key_1: 1, key_2: 2 },19 { key_1: 2, key_2: 2 }20 ]21 })22 const expected = { $id: '[1,2]', key_1: 1, key_2: 2 }23 const user = store.getters['entities/users/query']()24 .whereId([1, 2])25 .first()26 expect(user).toEqual(expected)27 })28 it('can retrieve records that matches the whereId clause using intersection ("and" boolean)', async () => {29 const store = createStore([{ model: User }])30 await store.dispatch('entities/users/create', {31 data: [32 { key_1: 1, key_2: 2 },33 { key_1: 2, key_2: 2 }34 ]35 })36 const users = store.getters['entities/users/query']()37 .whereId([1, 2])38 .whereId([2, 2])39 .get()40 expect(users).toEqual([])41 })42 it('can retrieve records that matches the whereId and orWhere', async () => {43 const store = createStore([{ model: User }])44 await store.dispatch('entities/users/create', {45 data: [46 { key_1: 1, key_2: 2 },47 { key_1: 2, key_2: 2 }48 ]49 })50 const expected = [51 { $id: '[1,2]', key_1: 1, key_2: 2 },52 { $id: '[2,2]', key_1: 2, key_2: 2 }53 ]54 const users = store.getters['entities/users/query']()55 .whereId([1, 2])56 .orWhere('key_1', 2)57 .get()58 expect(users).toEqual(expected)59 })60 it('can retrieve records that matches the whereIdIn clause', async () => {61 const store = createStore([{ model: User }])62 await store.dispatch('entities/users/create', {63 data: [64 { key_1: 1, key_2: 2 },65 { key_1: 2, key_2: 2 },66 { key_1: 3, key_2: 2 }67 ]68 })69 const expected = [70 { $id: '[2,2]', key_1: 2, key_2: 2 },71 { $id: '[3,2]', key_1: 3, key_2: 2 }72 ]73 const users = store.getters['entities/users/query']()74 .whereIdIn([75 [2, 2],76 [3, 2]77 ])78 .get()79 expect(users).toEqual(expected)80 })81 it('can retrieve records that matches the whereIdIn clause using intersection ("and" boolean)', async () => {82 const store = createStore([{ model: User }])83 await store.dispatch('entities/users/create', {84 data: [85 { key_1: 1, key_2: 2 },86 { key_1: 2, key_2: 2 },87 { key_1: 3, key_2: 2 }88 ]89 })90 const expected = [{ $id: '[2,2]', key_1: 2, key_2: 2 }]91 const users = store.getters['entities/users/query']()92 .whereIdIn([93 [2, 2],94 [3, 2]95 ])96 .whereIdIn([97 [1, 2],98 [2, 2]99 ])100 .get()101 expect(users).toEqual(expected)102 })103 it('can retrieve records that matches the whereIdIn and orWhere', async () => {104 const store = createStore([{ model: User }])105 await store.dispatch('entities/users/create', {106 data: [107 { key_1: 1, key_2: 2 },108 { key_1: 2, key_2: 2 },109 { key_1: 3, key_2: 2 }110 ]111 })112 const expected = [113 { $id: '[1,2]', key_1: 1, key_2: 2 },114 { $id: '[2,2]', key_1: 2, key_2: 2 },115 { $id: '[3,2]', key_1: 3, key_2: 2 }116 ]117 const users = store.getters['entities/users/query']()118 .whereIdIn([119 [2, 2],120 [3, 2]121 ])122 .orWhere('key_1', 1)123 .get()124 expect(users).toEqual(expected)125 })126 it('throws error when passing value other than an array to `whereId`', () => {127 const store = createStore([{ model: User }])128 expect(() => {129 store.getters['entities/users/query']()130 .whereId(2)131 .get()132 }).toThrowError('[Vuex ORM]')133 })134 it('throws error when passing value other than a nested array to `whereIdIn`', () => {135 const store = createStore([{ model: User }])136 expect(() => {137 store.getters['entities/users/query']()138 .whereIdIn([2, 2])139 .get()140 }).toThrowError('[Vuex ORM]')141 })...
data.js
Source:data.js
1var data = [2{"key_0":"广ä¸","key_1":"æ·±å³","key_2":"æ·±å³å¥¥é¾"},3{"key_0":"广ä¸","key_1":"æ·±å³","key_2":"æ·±å³é¦é¾"},4{"key_0":"广ä¸","key_1":"æ·±å³","key_2":"æ·±å³é¹å³°"},5{"key_0":"广ä¸","key_1":"æ·±å³","key_2":"æ·±å³å奥"},6{"key_0":"广ä¸","key_1":"æ·±å³","key_2":"æ·±å³å¢ç¹"},7{"key_0":"广ä¸","key_1":"ä¸è","key_2":"ä¸èä¸å¥¥"},8{"key_0":"广ä¸","key_1":"ä¸è","key_2":"ä¸èæ·ä¸ä¸°"},9{"key_0":"广ä¸","key_1":"ä¸è","key_2":"ä¸è奥å©"},10{"key_0":"广ä¸","key_1":"ä¸è","key_2":"ä¸èä¸å¥¥"},11{"key_0":"广ä¸","key_1":"ä¸å±±","key_2":"ä¸å±±å¹¿ç©å奥"},12{"key_0":"广ä¸","key_1":"ä¸å±±","key_2":"ä¸å±±å°æ¦åºä¸°å¥¥è¾¾"},13{"key_0":"广ä¸","key_1":"ç æµ·","key_2":"ç æµ·ç å
"},14{"key_0":"广ä¸","key_1":"ç æµ·","key_2":"ç æµ·å©æ"},15{"key_0":"广ä¸","key_1":"广å·","key_2":"广å·åè±å¥¥æ¬£"},16{"key_0":"广ä¸","key_1":"广å·","key_2":"广ä¸é¦æ³°"},17{"key_0":"广ä¸","key_1":"广å·","key_2":"广å·é¦é¾"},18{"key_0":"广ä¸","key_1":"广å·","key_2":"广ä¸ç²¤å¥¥"},19{"key_0":"广ä¸","key_1":"广å·","key_2":"广å·ä¸ç"},20{"key_0":"广ä¸","key_1":"ä½å±±","key_2":"ä½å±±é¦æ³°"},21{"key_0":"广ä¸","key_1":"ä½å±±","key_2":"ä½å±±å奥"},22{"key_0":"广ä¸","key_1":"ä½å±±","key_2":"ä½å±±åè¾"},23{"key_0":"广ä¸","key_1":"ä½å±±","key_2":"顺德ä¸é¦"},24{"key_0":"广ä¸","key_1":"æ±é¨","key_2":"æ±é¨åå®"},25{"key_0":"广ä¸","key_1":"æ å·","key_2":"æ å·åè±"},26{"key_0":"æ¹å","key_1":"é¿æ²","key_2":"é¿æ²æä¿¡"},27{"key_0":"æ¹å","key_1":"é¿æ²","key_2":"åæ´å¥¥é"},28{"key_0":"æ¹å","key_1":"é¿æ²","key_2":"åæ´å迪"},29{"key_0":"æ¹å","key_1":"æ¦æ±","key_2":"æ¦æ±è¿é"},30{"key_0":"æ¹å","key_1":"æ¦æ±","key_2":"æ¹åä¸åº"},31{"key_0":"æ¹å","key_1":"æ¦æ±","key_2":"æ信奥é¾"}...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.1b2c3d4e5f6g7h8i9j0');3wpt.getLocations(function(err, data) {4 if (err) {5 console.log('Error: ' + err);6 } else {7 console.log(JSON.stringify(data));8 }9});
Using AI Code Generation
1var wpt = require('webpagetest');2var options = {3};4var test = new wpt('www.webpagetest.org', options);5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 }10});
Using AI Code Generation
1var wpt = require('wpt');2 if (err) {3 console.log(err);4 } else {5 console.log(data);6 }7});8var wpt = require('wpt');9 if (err) {10 console.log(err);11 } else {12 console.log(data);13 }14});15var wpt = require('wpt');16 if (err) {17 console.log(err);18 } else {19 console.log(data);20 }21});22var wpt = require('wpt');23 if (err) {24 console.log(err);25 } else {26 console.log(data);27 }28});29var wpt = require('wpt');30 if (err) {31 console.log(err);32 } else {33 console.log(data);34 }35});36var wpt = require('wpt');37 if (err) {38 console.log(err);39 } else {40 console.log(data);41 }42});43var wpt = require('wpt');44 if (err) {
Using AI Code Generation
1wpt.key_2("value_2");2wpt.key_1("value_1");3var wpt = {4 key_1: function(value_1) {5 console.log(value_1);6 },7 key_2: function(value_2) {8 console.log(value_2);9 }10};11wpt.key_2("value_2");12wpt.key_1("value_1");13var wpt = (function() {14 var key_1 = function(value_1) {15 console.log(value_1);16 };17 var key_2 = function(value_2) {18 console.log(value_2);19 };20 return {21 };22})();23wpt.key_2("value_2");24wpt.key_1("value_1");25var wpt = (function() {26 var key_1 = function(value_1) {27 console.log(value_1);28 };29 var key_2 = function(value_2) {30 console.log(value_2);31 };32 return {33 };34})();35wpt.key_2("value_2");36wpt.key_1("value_1");37var wpt = (function() {38 var key_1 = function(value_1) {39 console.log(value_1);40 };41 var key_2 = function(value_2) {42 console.log(value_2);43 };44 return {45 };46})();47wpt.key_2("value_2");48wpt.key_1("value_1");49var wpt = (function() {50 var key_1 = function(value_1) {51 console.log(value_1);52 };53 var key_2 = function(value_2) {54 console.log(value_2);55 };56 return {
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.3b4e4b4e4b4e4b4e4b4e4b4e4b4e4b4e4');3 if (err) return console.error(err);4 console.log('Test submitted to WebPageTest for %s', data.data.url);5 console.log('Test ID: %s', data.data.testId);6 console.log('View test at %s', data.data.summary);7});8var wpt = require('webpagetest');9var wpt = new WebPageTest('www.webpagetest.org', 'B.3b4e4b4e4b4e4b4e4b4e4b4e4b4e4b4');10 if (err) return console.error(err);11 console.log('Test submitted to WebPageTest for %s', data.data.url);12 console.log('Test ID: %s', data.data.testId);13 console.log('View test at %s', data.data.summary);14});15var cp = require('child_process');16cp.spawn('node', ['test2.js']);
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!!