Best JavaScript code snippet using wpt
editor-test-utils.js
Source:editor-test-utils.js
...213 };214 let deleteFoundMarkers = () => {215 let removeNode = node => {216 let container = node.parentElement;217 let offset = indexOfContainer(container, node);218 node.remove();219 return { container, offset };220 };221 if (startMarker.container == endMarker.container) {222 // If the text node becomes empty, remove it and set collapsed range223 // to the position where there is the text node.224 if (startMarker.container.length === 2) {225 if (!/[\[\{][\]\}]/.test(startMarker.container.data)) {226 throw `Unexpected text node (data: "${startMarker.container.data}")`;227 }228 let { container, offset } = removeNode(startMarker.container);229 startMarker.container = endMarker.container = container;230 startMarker.offset = endMarker.offset = offset;231 startMarker.marker = endMarker.marker = "";232 return;233 }234 startMarker.container.data = `${startMarker.container.data.substring(235 0,236 startMarker.offset237 )}${startMarker.container.data.substring(238 startMarker.offset + 1,239 endMarker.offset240 )}${startMarker.container.data.substring(endMarker.offset + 1)}`;241 if (startMarker.offset >= startMarker.container.length) {242 startMarker.offset = endMarker.offset =243 startMarker.container.length;244 return;245 }246 endMarker.offset--; // remove the start marker's length247 if (endMarker.offset > endMarker.container.length) {248 endMarker.offset = endMarker.container.length;249 }250 return;251 }252 if (startMarker.container.length === 1) {253 let { container, offset } = removeNode(startMarker.container);254 startMarker.container = container;255 startMarker.offset = offset;256 startMarker.marker = "";257 } else {258 startMarker.container.data = `${startMarker.container.data.substring(259 0,260 startMarker.offset261 )}${startMarker.container.data.substring(startMarker.offset + 1)}`;262 }263 if (endMarker.container.length === 1) {264 let { container, offset } = removeNode(endMarker.container);265 endMarker.container = container;266 endMarker.offset = offset;267 endMarker.marker = "";268 } else {269 endMarker.container.data = `${endMarker.container.data.substring(270 0,271 endMarker.offset272 )}${endMarker.container.data.substring(endMarker.offset + 1)}`;273 }274 };275 deleteFoundMarkers();276 let handleNodeSelectMarker = () => {277 if (startMarker.marker === "{") {278 if (startMarker.offset === 0) {279 // The range start with the text node.280 let container = startMarker.container.parentElement;281 startMarker.offset = indexOfContainer(282 container,283 startMarker.container284 );285 startMarker.container = container;286 } else if (startMarker.offset === startMarker.container.data.length) {287 // The range start after the text node.288 let container = startMarker.container.parentElement;289 startMarker.offset =290 indexOfContainer(container, startMarker.container) + 1;291 startMarker.container = container;292 } else {293 throw 'Start marker "{" is allowed start or end of a text node';294 }295 }296 if (endMarker.marker === "}") {297 if (endMarker.offset === 0) {298 // The range ends before the text node.299 let container = endMarker.container.parentElement;300 endMarker.offset = indexOfContainer(container, endMarker.container);301 endMarker.container = container;302 } else if (endMarker.offset === endMarker.container.data.length) {303 // The range ends with the text node.304 let container = endMarker.container.parentElement;305 endMarker.offset =306 indexOfContainer(container, endMarker.container) + 1;307 endMarker.container = container;308 } else {309 throw 'End marker "}" is allowed start or end of a text node';310 }311 }312 };313 handleNodeSelectMarker();314 let range = document.createRange();315 range.setStart(startMarker.container, startMarker.offset);316 range.setEnd(endMarker.container, endMarker.offset);317 return range;318 };319 let ranges = [];320 for (...
model.mjs
Source:model.mjs
1import { Observation } from '../subscribe/observable.mjs';2import { cardContainers } from './card_data.mjs';3import { currentUser } from './user_data.mjs';4import {5 createCardContainerObject,6 createCardObject,7} from '../create_components/card_component.mjs';8import { dragController } from '../controllers/dragController.mjs';9import { DBcontroller } from '../controllers/DBcontroller.mjs';10export const cardContainerModel = {11 findContainerIndexById(idOfContainer) {12 const containerToFind = cardContainers.filter((cardContainer) => {13 if (cardContainer.id === Number(idOfContainer)) return true;14 });15 const indexOfContainer = cardContainers.indexOf(containerToFind[0]);16 return indexOfContainer;17 },18 findContainerIndexByIdVirtual(idOfContainer) {19 const containerToFind = dragController.virtualArr.filter((cardContainer) => {20 if (cardContainer.id === Number(idOfContainer)) return true;21 });22 const indexOfContainer = dragController.virtualArr.indexOf(containerToFind[0]);23 return indexOfContainer;24 },25 async addCardContainer(name) {26 currentUser.maxContainerId += 1;27 const indexOfNewContainer = cardContainers.length;28 const idOfNewContainer = currentUser.maxContainerId;29 const newCardContainer = createCardContainerObject(name, idOfNewContainer);30 cardContainers.push(newCardContainer);31 await DBcontroller.addContainer(idOfNewContainer, name, indexOfNewContainer);32 Observation.notify(cardContainers);33 },34 async deleteCardContainer(idOfDeleteContainer) {35 const indexOfDeleteContainer = cardContainerModel.findContainerIndexById(idOfDeleteContainer);36 cardContainers.splice(indexOfDeleteContainer, 1);37 await DBcontroller.deleteContainer(idOfDeleteContainer);38 Observation.notify(cardContainers);39 },40 async editContainerName(idOfEditContainer, editedName) {41 const indexOfEditContainer = cardContainerModel.findContainerIndexById(idOfEditContainer);42 const editContainer = cardContainers[indexOfEditContainer];43 editContainer.name = editedName;44 await DBcontroller.updateContainer(idOfEditContainer, editedName);45 Observation.notify(cardContainers);46 },47 insertContainer(idOfElemToBeInserted, idOfStandardElem) {48 const indexsOfElemToBeInserted = cardContainerModel.findContainerIndexById(49 idOfElemToBeInserted,50 );51 const ElemToBeInserted = cardContainers[indexsOfElemToBeInserted];52 cardContainers.splice(indexsOfElemToBeInserted, 1);53 const indexOfStandardElem = cardContainerModel.findContainerIndexById(idOfStandardElem);54 cardContainers.splice(indexOfStandardElem + 1, 0, ElemToBeInserted);55 Observation.notify(cardContainers);56 },57 createCardContainerObjectVirtual() {58 const cardContainersElems = document59 .querySelector('.main-container-bottom')60 .querySelectorAll('.card-container');61 const virtualCardContainersArr = [];62 cardContainersElems.forEach((cardConatinerElem) => {63 const containerName = cardConatinerElem.id.split('-')[0];64 const containerId = Number(cardConatinerElem.id.split('-')[1]);65 const containerToAdd = createCardContainerObject(containerName, containerId);66 const cardsOfContainerElems = cardConatinerElem.querySelectorAll('.card-total-box');67 containerToAdd.count = cardsOfContainerElems.length;68 cardsOfContainerElems.forEach((cardsOfContainerElem) => {69 const idOfCard = Number(cardsOfContainerElem.id.split('-')[4]);70 const headOfCard = document.getElementById(`card-header-${idOfCard}`).innerText;71 const bodyOfCard = document.getElementById(`card-body-${idOfCard}`).innerText;72 const footerOfCard = document.getElementById(`card-footer-${idOfCard}`).innerText;73 const cardToAdd = createCardObject(headOfCard, bodyOfCard, footerOfCard, idOfCard);74 containerToAdd.cards.push(cardToAdd);75 });76 virtualCardContainersArr.push(containerToAdd);77 });78 return virtualCardContainersArr;79 },80 getCardContainers() {81 return cardContainers;82 },83};84export const cardModel = {85 findCardIndexById(idOfContainer, idOfCard) {86 const indexOfContainer = cardContainerModel.findContainerIndexById(idOfContainer);87 const cardToFind = cardContainers[indexOfContainer].cards.filter((card) => {88 if (card.id === Number(idOfCard)) return true;89 });90 const indexOfCard = cardContainers[indexOfContainer].cards.indexOf(cardToFind[0]);91 return indexOfCard;92 },93 findCardIndexByIdVirtual(idOfContainer, idOfCard) {94 let indexOfContainer = undefined;95 let indexOfCard = undefined;96 dragController.virtualArr.forEach((container) => {97 container.cards.forEach((card) => {98 if (card.id === Number(idOfCard)) {99 indexOfCard = container.cards.indexOf(card);100 indexOfContainer = dragController.virtualArr.indexOf(container);101 }102 });103 });104 return [indexOfContainer, indexOfCard];105 },106 async addCard(idOfContainer, header, body) {107 currentUser.maxCardId += 1;108 const indexOfContainer = cardContainerModel.findContainerIndexById(idOfContainer);109 const newCard = createCardObject(header, body, currentUser.name, currentUser.maxCardId);110 cardContainers[indexOfContainer].count += 1;111 cardContainers[indexOfContainer].cards.unshift(newCard);112 await DBcontroller.addCard(113 idOfContainer,114 currentUser.maxCardId,115 header,116 body,117 currentUser.name,118 0,119 );120 Observation.notify(cardContainers);121 },122 async deleteCard(idOfDeleteContainer, idOfDeleteCard) {123 await cardModel.deleteCardVirtual(idOfDeleteContainer, idOfDeleteCard);124 Observation.notify(cardContainers);125 },126 async deleteCardVirtual(idOfDeleteContainer, idOfDeleteCard) {127 const indexOfDeleteContainer = cardContainerModel.findContainerIndexById(idOfDeleteContainer);128 const indexOfDeleteCard = cardModel.findCardIndexById(idOfDeleteContainer, idOfDeleteCard);129 cardContainers[indexOfDeleteContainer].cards.splice(indexOfDeleteCard, 1);130 cardContainers[indexOfDeleteContainer].count -= 1;131 await DBcontroller.deleteCard(idOfDeleteContainer, idOfDeleteCard);132 },133 async editCard(idOfEditContainer, idOfEditCard, title, body) {134 const indexOfEditContainer = cardContainerModel.findContainerIndexById(idOfEditContainer);135 const indexOfEditCard = cardModel.findCardIndexById(idOfEditContainer, idOfEditCard);136 const editCard = cardContainers[indexOfEditContainer].cards[indexOfEditCard];137 editCard.header = title;138 editCard.body = body;139 await DBcontroller.updateCard(idOfEditContainer, idOfEditCard, title, body);140 Observation.notify(cardContainers);141 },142 // insertCard(idsOfElemToBeInserted, idsOfStandardElem) {143 // const indexsOfElemToBeInserted = [144 // cardContainerModel.findContainerIndexById(idsOfElemToBeInserted[0]),145 // cardModel.findCardIndexById(idsOfElemToBeInserted[0], idsOfElemToBeInserted[1]),146 // ];147 // const ElemToBeInserted =148 // cardContainers[indexsOfElemToBeInserted[0]].cards[indexsOfElemToBeInserted[1]];149 // cardContainers[indexsOfElemToBeInserted[0]].count -= 1;150 // cardContainers[indexsOfElemToBeInserted[0]].cards.splice([indexsOfElemToBeInserted[1]], 1);151 // const indexOfStandardElem = [152 // cardContainerModel.findContainerIndexById(idsOfStandardElem[0]),153 // cardModel.findCardIndexById(idsOfStandardElem[0], idsOfStandardElem[1]),154 // ];155 // cardContainers[indexOfStandardElem[0]].count += 1;156 // cardContainers[indexOfStandardElem[0]].cards.splice(157 // indexOfStandardElem[1],158 // 0,159 // ElemToBeInserted,160 // );161 // Observation.notify(cardContainers);162 // },163 // insertCardBeforeVirtual(originIndexsOfCard, virtualIndexsOfCard, idsOfCard) {164 // const cardForMoving = cardContainers[virtualIndexsOfCard[0]].cards[virtualIndexsOfCard[1]];165 // cardContainers[virtualIndexsOfCard[0]].cards.splice(virtualIndexsOfCard[1], 0, cardForMoving);166 // cardContainers[virtualIndexsOfCard[0]].count += 1;167 // const indexOfDeleteContainer = cardContainerModel.findContainerIndexById(idsOfCard[0]);168 // const indexOfDeleteCard = cardModel.findCardIndexById(idsOfCard[0], idsOfCard[1]);169 // cardContainers[indexOfDeleteContainer].cards.splice(indexOfDeleteCard, 1);170 // cardContainers[indexOfDeleteContainer].count -= 1;171 // },172 // insertCardAfterVirtual(idsOfElemToBeInserted, idsOfStandardElem) {173 // const indexsOfElemToBeInserted = [174 // cardContainerModel.findContainerIndexById(idsOfElemToBeInserted[0]),175 // cardModel.findCardIndexById(idsOfElemToBeInserted[0], idsOfElemToBeInserted[1]),176 // ];177 // const ElemToBeInserted =178 // cardContainers[indexsOfElemToBeInserted[0]].cards[indexsOfElemToBeInserted[1]];179 // cardContainers[indexsOfElemToBeInserted[0]].count -= 1;180 // cardContainers[indexsOfElemToBeInserted[0]].cards.splice([indexsOfElemToBeInserted[1]], 1);181 // const indexOfStandardElem = [182 // cardContainerModel.findContainerIndexById(idsOfStandardElem[0]),183 // cardModel.findCardIndexById(idsOfStandardElem[0], idsOfStandardElem[1]),184 // ];185 // cardContainers[indexOfStandardElem[0]].count += 1;186 // cardContainers[indexOfStandardElem[0]].cards.splice(187 // indexOfStandardElem[1] + 1,188 // 0,189 // ElemToBeInserted,190 // );191 // },192 getCards(indexOfContainer) {193 return cardContainers[indexOfContainer].cards;194 },...
unsubscribe.ts
Source:unsubscribe.ts
1import { Container } from "@akala/commands";2import { State } from "../state";3export default function unsubscribe(this: State, container: Container<unknown>, topic: string)4{5 var indexOfContainer = this[topic].findIndex(el => el.container === container);6 if (indexOfContainer > -1)7 this[topic].splice(indexOfContainer, 1);...
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.runTest(url, function(err, data) {4 if (err) return console.error(err);5 var testId = data.data.testId;6 wpt.getTestResults(testId, function(err, data) {7 if (err) return console.error(err);8 var location = data.data.location;9 wpt.getLocations(function(err, data) {10 if (err) return console.error(err);11 var locationIndex = wpt.indexOfContainer(data.data, location);12 console.log(locationIndex);13 });14 });15});16module.exports = WebPageTest;17function WebPageTest(server, apiKey, version) {18}19WebPageTest.prototype.indexOfContainer = function(container, target) {20 for (var i = 0; i < container.length; i++) {21 if (container[i].name === target) return i;22 }23 return -1;24};
Using AI Code Generation
1var wpToolkit = require('wptoolkit');2var container = wpToolkit.indexOfContainer('containerName');3console.log(container);4var wpToolkit = require('wptoolkit');5var container = wpToolkit.indexOfContainer('containerName');6console.log(container);7var wpToolkit = require('wptoolkit');8var container = wpToolkit.indexOfContainer('containerName');9console.log(container);10var wpToolkit = require('wptoolkit');11var container = wpToolkit.indexOfContainer('containerName');12console.log(container);13var wpToolkit = require('wptoolkit');14var container = wpToolkit.indexOfContainer('containerName');15console.log(container);16var wpToolkit = require('wptoolkit');17var container = wpToolkit.indexOfContainer('containerName');18console.log(container);19var wpToolkit = require('wptoolkit');20var container = wpToolkit.indexOfContainer('containerName');21console.log(container);22var wpToolkit = require('wptoolkit');23var container = wpToolkit.indexOfContainer('containerName');24console.log(container);25var wpToolkit = require('wptoolkit');26var container = wpToolkit.indexOfContainer('containerName');27console.log(container);28var wpToolkit = require('wptoolkit');29var container = wpToolkit.indexOfContainer('containerName');30console.log(container);31var wpToolkit = require('wptoolkit');32var container = wpToolkit.indexOfContainer('containerName');33console.log(container);
Using AI Code Generation
1var wpt = require('wpt');2var wptClient = new wpt('WPT_API_KEY');3wptClient.getLocations(function (err, locations) {4 if (err) {5 console.log(err);6 } else {7 console.log(locations);8 }9});10wptClient.runTest(url, function (err, data) {11 if (err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17wptClient.getTestResults(data.data.testId, function (err, data) {18 if (err) {19 console.log(err);20 } else {21 console.log(data);22 }23});24wptClient.getTestResults(data.data.testId, function (err, data) {25 if (err) {26 console.log(err);27 } else {28 console.log(data);29 }30});31wptClient.getTestResults(data.data.testId, function (err, data) {32 if (err) {33 console.log(err);34 } else {35 console.log(data);36 }37});38wptClient.getTestResults(data.data.testId, function (err, data) {39 if (err) {40 console.log(err);41 } else {42 console.log(data);43 }44});45wptClient.getTestResults(data.data.testId, function (err, data) {46 if (err) {47 console.log(err);48 } else {49 console.log(data);50 }51});52wptClient.getTestResults(data.data.testId, function (err, data) {53 if (err) {54 console.log(err);55 } else {56 console.log(data);57 }58});59wptClient.getTestResults(data.data.testId, function (err, data) {60 if (err) {61 console.log(err);62 } else {63 console.log(data);64 }65});66wptClient.getTestResults(data.data.testId, function (err, data) {67 if (err) {68 console.log(err);69 } else {70 console.log(data);71 }72});73wptClient.getTestResults(data.data.testId, function (err, data) {74 if (err) {75 console.log(err);76 } else {77 console.log(data);78 }79});80wptClient.getTestResults(data.data.testId, function (err, data) {81 if (err
Using AI Code Generation
1indexOfContainer( CKEDITOR.instances.editor1.getSelection().getRanges()[0].startContainer );2indexOfContainer( CKEDITOR.instances.editor1.getSelection().getRanges()[0].endContainer );3indexOfContainer( CKEDITOR.instances.editor1.getSelection().getRanges()[0].startContainer );4indexOfContainer( CKEDITOR.instances.editor1.getSelection().getRanges()[0].endContainer );5indexOfContainer( CKEDITOR.instances.editor1.getSelection().getRanges()[0].startContainer );6indexOfContainer( CKEDITOR.instances.editor1.getSelection().getRanges()[0].endContainer );7indexOfContainer( CKEDITOR.instances.editor1.getSelection().getRanges()[0].startContainer );8indexOfContainer( CKEDITOR.instances.editor1.getSelection().getRanges()[0].endContainer );
Using AI Code Generation
1var index = wptoolkit.indexOfContainer("container1");2var index = wptoolkit.indexOfContainer("container2");3var index = wptoolkit.indexOfContainer("container3");4var index = wptoolkit.indexOfContainer("container4");5var index = wptoolkit.indexOfContainer("container5");6var index = wptoolkit.indexOfContainer("container6");7var index = wptoolkit.indexOfContainer("container7");8var index = wptoolkit.indexOfContainer("container8");9var index = wptoolkit.indexOfContainer("container9");10var index = wptoolkit.indexOfContainer("container10");11var index = wptoolkit.indexOfContainer("container11");12var index = wptoolkit.indexOfContainer("container12");
Using AI Code Generation
1var wpt = require('webpage');2var page = wpt.create();3 if (status === 'success') {4 var index = page.indexOfContainer('div#gb');5 var count = page.numberOfContainers();6 console.log('index: ' + index + ', count: ' + count);7 }8 phantom.exit();9});10var wpt = require('webpage');11var page = wpt.create();12 if (status === 'success') {13 var index = page.indexOfElement('div#gb', 'a.gb1');14 var count = page.numberOfElements('div#gb');15 console.log('index: ' + index + ', count: ' + count);16 }17 phantom.exit();18});19var wpt = require('webpage');20var page = wpt.create();21 if (status === 'success') {22 var index = page.indexOfImage('div#gb', 'img.gb1');23 var count = page.numberOfImages('div#gb');24 console.log('index: ' + index + ', count: ' + count);25 }26 phantom.exit();27});28var wpt = require('webpage');29var page = wpt.create();30 if (status === 'success') {31 var index = page.indexOfText('div#gb', 'a.gb1');32 var count = page.numberOfTexts('div#gb');33 console.log('index: ' + index + ', count: ' + count);34 }35 phantom.exit();36});
Using AI Code Generation
1var element = document.getElementById("test");2var index = indexOfContainer(element);3var element = document.getElementById("test");4var index = indexOfContainer(element);5var element = document.getElementById("test");6var index = indexOfContainer(element);7var element = document.getElementById("test");8var index = indexOfContainer(element);9var element = document.getElementById("test");10var index = indexOfContainer(element);11var element = document.getElementById("test");12var index = indexOfContainer(element);13var element = document.getElementById("test");14var index = indexOfContainer(element);
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!!