Best JavaScript code snippet using playwright-internal
EncodingUtilTest.js
Source:EncodingUtilTest.js
...18 19 testEscapeTextWithNull : function() {20 var EncodingUtil = org.eclipse.rwt.protocol.EncodingUtil;21 try {22 EncodingUtil.escapeText( null, true );23 EncodingUtil.escapeText( null, true );24 fail();25 } catch( e ) {26 // expected27 }28 },29 30 testEscapeTextNoChanges : function() {31 var EncodingUtil = org.eclipse.rwt.protocol.EncodingUtil;32 assertEquals( "Test", EncodingUtil.escapeText( "Test", false ) );33 assertEquals( "Test", EncodingUtil.escapeText( "Test", true ) );34 assertEquals( "", EncodingUtil.escapeText( "", false ) );35 assertEquals( "", EncodingUtil.escapeText( "", true ) );36 },37 testEscapeBrackets : function() {38 var EncodingUtil = org.eclipse.rwt.protocol.EncodingUtil;39 assertEquals( "<", EncodingUtil.escapeText( "<", false ) );40 assertEquals( ">", EncodingUtil.escapeText( ">", false ) );41 assertEquals( "<<<", EncodingUtil.escapeText( "<<<", false ) );42 var expected = "<File >";43 assertEquals( expected, EncodingUtil.escapeText( "<File >", false ) );44 assertEquals( expected, EncodingUtil.escapeText( "<File >", true ) );45 },46 testEscapeAmps : function() {47 var EncodingUtil = org.eclipse.rwt.protocol.EncodingUtil;48 assertEquals( "&&&File", EncodingUtil.escapeText( "&&&File", false ) );49 },50 testEscapeMnemonics : function() {51 var EncodingUtil = org.eclipse.rwt.protocol.EncodingUtil;52 assertEquals( "Open & Close", EncodingUtil.escapeText( "Open && Close", true ) );53 assertEquals( "E<s>ca'pe" & me",54 EncodingUtil.escapeText( "&E<s>ca'pe\" && me", true ) );55 // Explicitly call it twice to check that _mnemonicFound is reset56 assertEquals( "E<s>ca'pe" & me",57 EncodingUtil.escapeText( "&E<s>ca'pe\" && me", true ) );58 },59 testEscapeQuotes : function() {60 var EncodingUtil = org.eclipse.rwt.protocol.EncodingUtil;61 assertEquals( ""File"", EncodingUtil.escapeText( "\"File\"", false ) );62 assertEquals( """File", EncodingUtil.escapeText( "\"\"File", false ) );63 assertEquals( ""File"", EncodingUtil.escapeText( "\"File\"", true ) );64 assertEquals( """File", EncodingUtil.escapeText( "\"\"File", true ) );65 },66 testDontEscapeBackslash: function() {67 var EncodingUtil = org.eclipse.rwt.protocol.EncodingUtil;68 assertEquals( "Test\\", EncodingUtil.escapeText( "Test\\", false ) );69 },70 testTruncateAtZero : function() {71 var EncodingUtil = org.eclipse.rwt.protocol.EncodingUtil;72 assertEquals( String.fromCharCode( 0 ), "\000" );73 assertEquals( "foo ", EncodingUtil.escapeText( "foo \000 bar", false ) );74 assertEquals( "foo", EncodingUtil.escapeText( "foo\000", false ) );75 assertEquals( "", EncodingUtil.escapeText( "\000foo", false ) );76 assertEquals( "<foo", EncodingUtil.escapeText( "<foo\000>", false ) );77 assertEquals( "<foo", EncodingUtil.escapeText( "<foo\000>", true ) );78 },79 80 /////////////////////////////////////////////////////////81 // Tests ported from EncodingUtilTest#testReplaceNewLines82 testReplaceNewLines : function() {83 var EncodingUtil = org.eclipse.rwt.protocol.EncodingUtil;84 var stringToReplace = "First line.\nSecond line.\nThird line.";85 var expected = "First line.\\nSecond line.\\nThird line.";86 assertEquals( expected, EncodingUtil.replaceNewLines( stringToReplace ) );87 },88 testReplaceCarriageReturns : function() {89 var EncodingUtil = org.eclipse.rwt.protocol.EncodingUtil;90 var stringToReplace = "First line.\rSecond line.\rThird line.";91 var expected = "First line.\\nSecond line.\\nThird line.";...
calit2map.js
Source:calit2map.js
1function escapeText(t){2 return document.createTextNode(t).textContent;3}4function myGoodLoadXML(data) {5 $("div.dataXML").html("<h1>Global EarthQuakes From the Last 7 Days</h1>");6 var newTable = "<table id=\"newTable\" border=\"2\"><tr><th>Magnitude, Location</th><th>Date</th><th>LAT</th><th>LONG</th></tr></table>";7 $("div.dataXML").append(newTable);8 $(data).find("item").each(function(){9 $("#newTable").append("<tr><td>" + escapeText($(this).find("title").text()) + "</td><td>" + escapeText($(this).find("pubDate").text()) + "</td><td>" + escapeText($(this).find("lat").text()) + "</td><td>" + escapeText($(this).find("long").text()) + "</td></tr>");10 });11}12function myGoodLoadXML2(data) {13 $("div.dataXML2").html("<h1>mttaborstudio's flickr photostream</h1>");14 var newTable = "<table id=\"newTable2\" border=\"2\"><tr><th>Title</th><th>Date</th><th>LAT</th><th>LONG</th></tr></table>";15 $("div.dataXML2").append(newTable);16 $(data).find("entry").each(function(){17 $("#newTable2").append("<tr><td>" + escapeText($(this).find("title").text()) + "</td><td>" + escapeText($(this).find("date_taken").text()) + "</td><td>" + escapeText($(this).find("lat").text()) + "</td><td>" + escapeText($(this).find("long").text()) + "</td></tr>");18 });19}20var myPoint = [];21function myGoodLoadXML3(data) {22 $("div.rockets").html("<h1>Houston Rockets Game Locations</h1>");23 var newTable = "<table id=\"newTable3\" style=\"width:800px\" border=\"2\"><tr><th>Address</th><th>Games</th><th>Location</th></tr></table>";24 $("div.rockets").append(newTable);25 $(data).find("item").each(function(){26 var title = escapeText($(this).find("title").text());27 var titleSplit = title.split(': ');28 var point = escapeText($(this).find("point").text());29 point.slice(0,-2);30 var pointSplit = point.split(',');31 myPoint.push(pointSplit[0]);32 myPoint.push(pointSplit[1]);33 $("#newTable3").append("<tr><td>" + titleSplit[1] + "</td><td>" + escapeText($(this).find("description").text()) + "</td><td><a href=\"#\" id=\"point\" onclick=\"clickCenterPoint("+pointSplit[0]+","+pointSplit[1]+");\"><span id=\"lat\">" + pointSplit[0] + ", </span><span id=\"lng\">" + pointSplit[1] + "</span></a></td></tr>");34 //contentString = '<div><p>'+escapeText($(this).find("description").text())+'</p><p><a href=\"'+escapeText($(this).find("link").text())+'\">Go to mapchannels.com</a></p></div>';35 });36 37}38//var geoClick = document.getElementById('point');39//geoClick.onclick = clickCenterPoint;40function clickCenterPoint(lat,lng){41 //var preClickLat = escapeText($(this).find('#lat').text());42 //var clickLat = pointSplit[0];43 //var clickLat = preClickLat.slice(0,-2);44 console.log(lat);45 //var clickLng = escapeText($(this).find('#lng').text());46 //var clickLng = pointSplit[1];47 console.log(lng);48 var clickCenterPoint = new google.maps.LatLng(lat, lng);49 map.setCenter(clickCenterPoint);50}51/*52function myGoodLoadJSON(data) {53 $("div.dataJSON").html("<h1>Global EarthQuakes From the Last 7 Days</h1>");54 var newHTML= "<div style=\"margin-left:10px;padding:5px;border:solid 1px green\">";55 newHTML += escapeText(data.postal);56 newHTML += +"</div>";57 $("div.dataJSON").append(newHTML);58}59function myGoodLoadJSONP(data) {60 $("div.dataJSONP").html("<h1>AJAX JSONP call returned:</h1>");61 for(var i = 0; i< data.feed.entry.length; i++){62 var newHTML= "<div style=\"margin-left:10px;padding:5px;border:solid 1px blue\">";63 newHTML += escapeText(data.feed.entry[i].title.$t);64 newHTML += +"</div>";65 $("div.dataJSONP").append(newHTML);66 }67}68*/69function myBadLoadFunction(myXMLHttpRequest,myErrorMessage,myErrorThrown) {70 alert('status: ' + myErrorMessage + '\n' + myXMLHttpRequest.responseText);71}72 73var map;74var centerPoint = new google.maps.LatLng(29.7507, -95.3621);75var gameLocations = [];76function getGameLocations(data) {77 var temp = [];78 $(data).find("item").each(function(){79 var title = escapeText($(this).find("title").text());80 var titleSplit = title.split(': ');81 temp.push(titleSplit[1]);82 var point = escapeText($(this).find("point").text());83 point.slice(0,-2);84 var pointSplit = point.split(',');85 temp.push(pointSplit[0]);86 temp.push(pointSplit[1]);87 var description = escapeText($(this).find("description").text());88 temp.push(description);89 var link = escapeText($(this).find("link").text());90 temp.push(link);91 gameLocations.push(temp);92 temp = [];93 });94 for(var i=0;i<gameLocations.length;i++){95 console.log(gameLocations[i]);96 }97}98function initializeMap(){99 var myOptions = {100 zoom: 8,101 center: centerPoint,102 mapTypeId: google.maps.MapTypeId.ROADMAP103 };104 map = new google.maps.Map($('#map_canvas').get(0), myOptions);105 setMarkers(map,gameLocations);106}107function setMarkers(map,locations) {108 //var latlng = new google.maps.LatLng(33.643298,-117.841983);109 var image = new google.maps.MarkerImage('images/icon.png',110 // This marker is 32 pixels wide by 32 pixels tall.111 new google.maps.Size(50, 50),112 // The origin for this image is 0,0.113 new google.maps.Point(0,0),114 // The anchor for this image is at 0,16.115 new google.maps.Point(30,45));116 // The shadow image is larger in the horizontal dimension117 // while the position and offset are the same as for the main image.118 var shadow = new google.maps.MarkerImage('images/shadow.png',119 new google.maps.Size(80, 50),120 new google.maps.Point(0,0),121 new google.maps.Point(30,45));122 var infowindow = null;123 var contentString = "";124 for(var i=0;i<locations.length;i++) {125 var gamePlace = locations[i];126 console.log(gamePlace[0]);127 console.log(gamePlace[1]);128 console.log(gamePlace[2]);129 console.log(gamePlace[3]);130 //contentString = '<div><p>'+gamePlace[3]+'</p><p><a href=\"'+gamePlace[4]+'\">Go to mapchannels.com</a></p></div>';131 infowindow = new google.maps.InfoWindow({132 content: ""133 });134 var gameLatLng = new google.maps.LatLng(gamePlace[1],gamePlace[2]);135 var marker = new google.maps.Marker({136 position: gameLatLng,137 map: map,138 shadow: shadow,139 icon: image,140 title: gamePlace[0]141 });142 143 google.maps.event.addListener(marker,'click',(function(marker,i){144 return function(){145 infowindow.setContent('<div><p>'+locations[i][3]+'</p><p><a href=\"'+locations[i][4]+'\">Go to mapchannels.com</a></p><iframe width=\"300\" height=\"169\" src=\"https://www.youtube.com/embed/Ttw6RBYGPOM\" frameborder=\"0\" allowfullscreen></iframe></div>');146 infowindow.open(map,marker);147 }148 })(marker,i));149 } 150}151function myReadyFunction(){152 $.ajax({153 url: "https://students.ics.uci.edu/~vcustodi/133/myProxy.php?http://earthquake.usgs.gov/eqcenter/catalogs/eqs7day-M5.xml",154 dataType: "xml",155 success: myGoodLoadXML,156 error: myBadLoadFunction157 });158 $.ajax({159 url: "https://students.ics.uci.edu/~vcustodi/133/myProxy.php?http://api.flickr.com/services/feeds/geo/?id=55859022@N06&lang=en-us",160 dataType: "xml",161 success: myGoodLoadXML2,162 error: myBadLoadFunction163 });164 $.ajax({165 url: "https://students.ics.uci.edu/~vcustodi/133/myProxy.php?http://events.mapchannels.com/entrss/438.rss",166 dataType: "xml",167 success: myGoodLoadXML3,168 error: myBadLoadFunction169 });170 $.ajax({171 url: "https://students.ics.uci.edu/~vcustodi/133/myProxy.php?http://events.mapchannels.com/entrss/438.rss",172 dataType: "xml",173 success: getGameLocations,174 error: myBadLoadFunction175 });176/*177 $.ajax({178 url: "https://students.ics.uci.edu/~vcustodi/133/myProxy.php?http://static.batchgeo.com/map/json/7b80089aed1792d280c61c0b0f952d56/1351101106",179 dataType: "json",180 success: myGoodLoadJSON,181 error: myBadLoadFunction182 });183 $("div.dataJSON").html("AJAX JSON call initiated:<br/>");184 $.ajax({185 url: "https://gdata.youtube.com/feeds/base/users/djp3/uploads?alt=json-in-script&client=ytapi-youtube-profile",186 dataType: "jsonp",187 success: myGoodLoadJSONP,188 error: myBadLoadFunction189 });190 $("div.dataJSONP").html("AJAX JSONP call initiated:<br/>");191*/192}193$(document).ready(194 myReadyFunction195/* 196$('#point').click(function(){197 var clickLat = escapeText($(this).find('#lat').text());198 console.log(clickLat);199 var clickLng = escapeText($(this).find('#lng').text());200 console.log(clickLng);201 var clickCenterPoint = new google.maps.LatLng(clickLat, clickLng);202 map.setCenter(clickCenterPoint);203});204*/...
templates.js
Source:templates.js
...20<package xmlns="http://www.idpf.org/2007/opf" version="3.0" unique-identifier="${idType}"21 xml:lang="${language}" prefix="cc: http://creativecommons.org/ns#">22 <metadata xmlns:dc="http://purl.org/dc/elements/1.1/">23 <dc:identifier id="${idType}">${book.id}</dc:identifier>24 <dc:title>${escapeText(book.title)}</dc:title>25 <dc:creator>26 ${27 book.metadata.author && book.metadata.author.length ?28 escapeText(book.metadata.author) :29 escapeText(user.name)30}31 </dc:creator>32 <dc:language>${language}</dc:language>33 <meta property="dcterms:modified">${modified}</meta>34 <dc:date>${date}</dc:date>35 ${36 book.metadata.copyright && book.metadata.copyright.length ?37 `<dc:rights>${escapeText(book.metadata.copyright)}</dc:rights>` :38 ''39}40 ${41 book.metadata.publisher && book.metadata.publisher.length ?42 `<dc:publisher>${escapeText(book.metadata.publisher)}</dc:publisher>` :43 ''44}45 ${46 book.metadata.keywords && book.metadata.keywords.length ?47 book.metadata.keywords.split(',').map(keyword =>48 `<dc:subject>${escapeText(keyword.trim())}</dc:subject>`49 ).join('') :50 ''51}52 </metadata>53 <manifest>54 ${55 coverImage ?56 `<item id="cover" href="cover.xhtml" media-type="application/xhtml+xml"/>` :57 ''58}59 <item id="titlepage" href="titlepage.xhtml" media-type="application/xhtml+xml"/>60 ${61 chapters.map(chapter =>62 `<item id="t${chapter.number}" href="document-${chapter.number}.xhtml"63 media-type="application/xhtml+xml" />`64 ).join('')65}66 <item id="nav" href="document-nav.xhtml" properties="nav"67 media-type="application/xhtml+xml" />68 <item id="copyright" href="copyright.xhtml" media-type="application/xhtml+xml"/>69 ${70 images.map((image, index) =>71 `<item ${72 image.coverImage ?73 `id="cover-image" properties="cover-image"` :74 `id="img${index}"`75 } href="${image.filename}" media-type="image/${76 image.filename.split(".")[1] === "png" ?77 'png' :78 image.filename.split(".")[1] === "svg" ?79 'svg+xml' :80 'jpeg'81 }"/>`82 ).join('')83}84 ${85 fontFiles.map((fontFile, index) =>86 `<item ${87 `id="font${index}"`88 } href="${89 fontFile.filename90 }" media-type="font/${91 fontFile.filename.split(".")[1] === "woff" ?92 'woff' :93 fontFile.filename.split(".")[1] === "woff2" ?94 'woff2' :95 'sfnt'96 }" />`97 ).join('')98}99 ${100 styleSheets.map((sheet, index) =>101 `<item id="css${index}" href="${escapeText(sheet.filename)}"102 media-type="text/css" />`103 ).join('')104}105 ${106 math ?107 mathliveOpfIncludes :108 ''109}110 <!-- ncx included for 2.0 reading system compatibility: -->111 <item id="ncx" href="document.ncx" media-type="application/x-dtbncx+xml" />112 </manifest>113 <spine toc="ncx">114 ${115 coverImage ?116 '<itemref idref="cover" linear="no"/>' :117 ''118}119 <itemref idref="titlepage" linear="yes"/>120 ${121 chapters.map(122 chapter => `<itemref idref="t${chapter.number}" linear="yes" />`123 ).join('')124}125 <itemref idref="copyright" linear="yes"/>126 <itemref idref="nav" linear="no"/>127 </spine>128</package>`129/** A template to create the book epub cover XML. */130export const epubBookCoverTemplate = ({131 book,132 coverImage133}) =>134 `<?xml version="1.0" encoding="UTF-8"?>135<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">136 <head>137 <title>${book.title}</title>138 <meta charset="utf-8"/>139 </head>140 <body>141 <div id="cover">142 <img src="${coverImage.image.split("/").pop().split("?")[0]}"143 alt="${gettext('Cover Image')}" title="Cover Image"/>144 </div>145 </body>146</html>`147/** A template to create the book epub titlepage XML. */148export const epubBookTitlepageTemplate = ({149 book150}) =>151 `<?xml version="1.0" encoding="UTF-8"?>152<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">153 <head>154 <title>${escapeText(book.title)}</title>155 <meta charset="utf-8"/>156 </head>157 <body style="text-align: center;">158 <div id="title" epub:type="frontmatter titlepage">159 <h1 class="booktitle">${escapeText(book.title)}</h1>160 ${161 book.metadata.subtitle.length ?162 `<h2 class="booksubtitle">${escapeText(book.metadata.subtitle)}</h2>` :163 ''164}165 ${166 book.metadata.version?.length ?167 `<h4 class="bookversion">${escapeText(book.metadata.version)}</h4>` :168 ''169}170 ${171 book.metadata.author.length ?172 `<h3 class="bookauthor">${gettext('by')} ${escapeText(book.metadata.author)}</h3>` :173 ''174}175 </div>176 </body>177</html>`178/** A template to create the book epub copyright page XML. */179export const epubBookCopyrightTemplate = ({180 book,181 languages,182 creator183}) =>184 `<?xml version="1.0" encoding="UTF-8"?>185<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">186 <head>187 <title>${escapeText(book.title)}</title>188 <meta charset="utf-8"/>189 </head>190 <body>191 <section epub:type="frontmatter copyright-page">192 <div id="copyright">193 <p>194 ${escapeText(book.title)}195 ${196 book.metadata.author.length ?197 `${gettext('by')} ${escapeText(book.metadata.author)}` :198 ''199}200 </p>201 ${202 book.metadata.copyright.length ?203 `<p>${escapeText(book.metadata.copyright)}</p>` :204 ''205}206 <p>${gettext('Title')}: ${escapeText(book.title)}</p>207 ${208 book.metadata.author.length ?209 `<p>${gettext('Author')}: ${escapeText(book.metadata.author)}</p>` :210 ''211}212 ${213 book.metadata.publisher && book.metadata.publisher.length ?214 `<p>${gettext('Published by')}: ${escapeText(book.metadata.publisher)}</p>` :215 ''216}217 <p>${gettext('Last Updated')}: ${book.updated}</p>218 <p>${gettext('Created')}: ${book.added}</p>219 ${220 languages.length ?221 `<p>${languages.length === 1 ? gettext('Language') : gettext('Languages')}: ${languages.map(language => LANGUAGES.find(lang => lang[0] === language)[1]).join(', ')}</p>` :222 ''223}224 <p>${gettext('Created by')}: ${escapeText(creator)}</p>225 </div>226 </section>227 </body>...
hoptoad-notifier.js
Source:hoptoad-notifier.js
...55 }).map(function(line) {56 var matches = line.match(Hoptoad.BACKTRACE_MATCHER);57 if (matches) {58 var file = matches[2].replace(Hoptoad.root, '[PROJECT_ROOT]');59 return '<line method="' + Hoptoad.escapeText(matches[1] || '') +60 '" file="' + Hoptoad.escapeText(file) +61 '" number="' + matches[3] + '" />';62 }63 }).filter(function(line) {64 return line !== undefined;65 });66 },67 generateXML: function(error) {68 var xml = Hoptoad.NOTICE_XML;69 var root = Hoptoad.escapeText(Hoptoad.root);70 var url = Hoptoad.escapeText(error.url || '');71 var type = Hoptoad.escapeText(error.type || 'Error');72 var action = Hoptoad.escapeText(error.action || '');73 var message = Hoptoad.escapeText(error.message || 'Unknown error.');74 var component = Hoptoad.escapeText(error.component || '');75 var backtrace = Hoptoad.generateBacktrace(error);76 if (url.trim() == '' && component.trim() == '') {77 xml = xml.replace(/<request>.*<\/request>/, '');78 } else {79 var data = '';80 ['params', 'session', 'cgi-data'].forEach(function(type) {81 if (error[type]) {82 data += '<' + type + '>';83 data += Hoptoad.generateVariables(error[type]);84 data += '</' + type + '>';85 }86 });87 xml = xml.replace('</request>', data + '</request>')88 .replace('REQUEST_URL', url)89 .replace('REQUEST_ACTION', action)90 .replace('REQUEST_COMPONENT', component);91 }92 return xml.replace('PROJECT_ROOT', root)93 .replace('EXCEPTION_CLASS', type)94 .replace('EXCEPTION_MESSAGE', message)95 .replace('BACKTRACE_LINES', backtrace.join(''));96 },97 generateVariables: function(parameters) {98 var key;99 var result = '';100 for (key in parameters) {101 result += '<var key="' + Hoptoad.escapeText(key) + '">' +102 Hoptoad.escapeText(parameters[key]) +103 '</var>';104 }105 return result;106 },107 escapeText: function(text) {108 return text.replace(/&/g, '&')109 .replace(/</g, '<')110 .replace(/>/g, '>')111 .replace(/'/g, ''')112 .replace(/"/g, '"');113 }114};...
jsdiff.js
Source:jsdiff.js
...7 *8 * More Info:9 * http://ejohn.org/projects/javascript-diff-algorithm/10 */11function escapeText(s) {12 return s;13/* var n = s;14 n = n.replace(/&/g, "&");15 n = n.replace(/</g, "<");16 n = n.replace(/>/g, ">");17 n = n.replace(/"/g, """);18 return n;*/19}20function diffString( o, n ) {21 o = o.replace(/\s+$/, '');22 n = n.replace(/\s+$/, '');23 var out = diff(o == "" ? [] : o.split(/\s+/), n == "" ? [] : n.split(/\s+/) );24 var str = "";25 var oSpace = o.match(/\s+/g);26 if (oSpace == null) {27 oSpace = ["\n"];28 } else {29 oSpace.push("\n");30 }31 var nSpace = n.match(/\s+/g);32 if (nSpace == null) {33 nSpace = ["\n"];34 } else {35 nSpace.push("\n");36 }37 if (out.n.length == 0) {38 for (var i = 0; i < out.o.length; i++) {39 str += '<del>' + escapeText(out.o[i]) + oSpace[i] + "</del>";40 }41 } else {42 if (out.n[0].text == null) {43 for (n = 0; n < out.o.length && out.o[n].text == null; n++) {44 str += '<del>' + escapeText(out.o[n]) + oSpace[n] + "</del>";45 }46 }47 for ( var i = 0; i < out.n.length; i++ ) {48 if (out.n[i].text == null) {49 str += '<ins>' + escapeText(out.n[i]) + nSpace[i] + "</ins>";50 } else {51 var pre = "";52 for (n = out.n[i].row + 1; n < out.o.length && out.o[n].text == null; n++ ) {53 pre += '<del>' + escapeText(out.o[n]) + oSpace[n] + "</del>";54 }55 str += " " + out.n[i].text + nSpace[i] + pre;56 }57 }58 }59 60 return str;61}62function randomColor() {63 return "rgb(" + (Math.random() * 100) + "%, " + 64 (Math.random() * 100) + "%, " + 65 (Math.random() * 100) + "%)";66}67function diffString2( o, n ) {68 o = o.replace(/\s+$/, '');69 n = n.replace(/\s+$/, '');70 var out = diff(o == "" ? [] : o.split(/\s+/), n == "" ? [] : n.split(/\s+/) );71 var oSpace = o.match(/\s+/g);72 if (oSpace == null) {73 oSpace = ["\n"];74 } else {75 oSpace.push("\n");76 }77 var nSpace = n.match(/\s+/g);78 if (nSpace == null) {79 nSpace = ["\n"];80 } else {81 nSpace.push("\n");82 }83 var os = "";84 var colors = new Array();85 for (var i = 0; i < out.o.length; i++) {86 colors[i] = randomColor();87 if (out.o[i].text != null) {88 os += '<span style="background-color: ' +colors[i]+ '">' + 89 escapeText(out.o[i].text) + oSpace[i] + "</span>";90 } else {91 os += "<del>" + escapeText(out.o[i]) + oSpace[i] + "</del>";92 }93 }94 var ns = "";95 for (var i = 0; i < out.n.length; i++) {96 if (out.n[i].text != null) {97 ns += '<span style="background-color: ' +colors[out.n[i].row]+ '">' + 98 escapeText(out.n[i].text) + nSpace[i] + "</span>";99 } else {100 ns += "<ins>" + escapeText(out.n[i]) + nSpace[i] + "</ins>";101 }102 }103 return { o : os , n : ns };104}105function diff( o, n ) {106 var ns = new Object();107 var os = new Object();108 109 for ( var i = 0; i < n.length; i++ ) {110 if ( ns[ n[i] ] == null )111 ns[ n[i] ] = { rows: new Array(), o: null };112 ns[ n[i] ].rows.push( i );113 }114 ...
bugsense.js
Source:bugsense.js
...44 remote_ip: '0.0.0.0',45 url: window.location.href,46 custom_data: {47 // You can remove & add custom data here from session/localStorage, cookies, geolocation, language, mimetypes,â¦48 document_referrer : that.escapeText(document.referrer),49 navigator_user_agent : that.escapeText(navigator.userAgent),50 navigator_platform : that.escapeText(navigator.platform),51 navigator_vendor : that.escapeText(navigator.vendor),52 navigator_language : that.escapeText(navigator.language),53 screen_width : that.escapeText(screen.width),54 screen_height : that.escapeText(screen.height),55 page : (main && main.currentPage) || "boot",56 error_code : that.notice.code,57 request : {}58 }59 };60 61 // stringify it 62 request.custom_data.request = JSON.stringify(request.custom_data.request);63 return request;64 }())65 };66 // all ready? lets make a get request with the data67 console.log(JSON.stringify(this.data));68 if (this.data && this.defaults.url && this.defaults.apiKey) {69 var url = this.defaults.url + this.defaults.apiKey + '&data=' + escape( JSON.stringify(this.data) );70 jQuery.post(url)71 .success(function(){console.log("all ok " + JSON.stringify(this));})72 .error(function(){console.log("problems " + JSON.stringify(arguments));});73 }74 },75 76 escapeText: function(text) {77 text = text.toString() || '';78 return text.replace(/&/g, '&')79 .replace(/</g, '<')80 .replace(/>/g, '>')81 .replace(/'/g, ''')82 .replace(/"/g, '"');83 },84 generateBackTrace: function(stack) {85 if (stack) {86 return stack.file + ':' + stack.line;87 }88 try {89 throw new Error();90 } catch (e) {91 if (e.stack) {92 var matcher = /\s+at\s(.+)\s\((.+?):(\d+)(:\d+)?\)/;93 return jQuery.map(e.stack.split("\n").slice(4), _.bind(function(line) {94 var match = line.match(matcher);95 var method = escapeText(match[1]);96 var file = escapeText(match[2]);97 var number = match[3];98 return file + ':' + number + 'in' + method;99 }, this)).join("\n");100 } else if (e.sourceURL) {101 // note: this is completely useless, as it just points back at itself but is needed on Safari102 // keeping it around in case they ever end up providing actual stacktraces103 return e.sourceURL + ':' + e.line;104 }105 }106 return 'n/a:0';107 }...
createQuiz.js
Source:createQuiz.js
...23 const wrongAnswers1 = $("[name='wrong_1']");24 const wrongAnswers2 = $("[name='wrong_2']");25 const wrongAnswers3 = $("[name='wrong_3']");26 const quiz = new Quiz();27 quiz.addQuizDetails(escapeText(title), escapeText(description), !isPublic);28 //iterate over jQuery "arrays" and create associated classes as they are added to the quiz29 for (let i = 0; i < prompts.length; i++) {30 const question = new Question(escapeText($(prompts[i]).val()));31 question.addAnswer(32 new Answer(escapeText($(correctAnswers[i]).val()), true)33 );34 question.addAnswer(35 new Answer(escapeText($(wrongAnswers1[i]).val()), false)36 );37 question.addAnswer(38 new Answer(escapeText($(wrongAnswers2[i]).val()), false)39 );40 question.addAnswer(41 new Answer(escapeText($(wrongAnswers3[i]).val()), false)42 );43 quiz.addQuestion(question);44 }45 $.ajax({46 url: "/quizzes",47 method: "POST",48 contentType: "application/json",49 data: JSON.stringify(quiz),50 }).done((response) => {51 const quizId = response.quizId;52 window.location.href = `/quizzes/${quizId}`;53 $("#new_quiz").trigger("reset");54 });55};...
escapeText.js
Source:escapeText.js
1import escapeText from '../escapeText';2describe('escapeText', () => {3 it('should escape boolean to string', function() {4 expect(escapeText(true)).toBe('true');5 expect(escapeText(false)).toBe('false');6 });7 it('should escape object to string', function() {8 let escaped = escapeText({9 toString: function() {10 return 'ponys';11 },12 });13 expect(escaped).toBe('ponys');14 });15 it('should escape number to string', function() {16 expect(escapeText(42)).toBe('42');17 });18 it('should escape string', function() {19 let escaped = escapeText('<script type=\'\' src=""></script>');20 expect(escaped).not.toContain('<');21 expect(escaped).not.toContain('>');22 expect(escaped).not.toContain('\'');23 expect(escaped).not.toContain('\"');24 escaped = escapeText('&');25 expect(escaped).toBe('&');26 });...
Using AI Code Generation
1const { escapeText } = require('playwright/lib/server/dom.js');2const { escapeText } = require('puppeteer/lib/cjs/puppeteer/common/DOMWorld.js');3const { escapeText } = require('playwright/lib/server/dom.js');4const { escapeText } = require('puppeteer/lib/cjs/puppeteer/common/DOMWorld.js');5const { escapeText } = require('playwright/lib/server/dom.js');6const { escapeText } = require('puppeteer/lib/cjs/puppeteer/common/DOMWorld.js');7const { escapeText } = require('playwright/lib/server/dom.js');8const { escapeText } = require('puppeteer/lib/cjs/puppeteer/common/DOMWorld.js');9const { escapeText } = require('playwright/lib/server/dom.js');10const { escapeText } = require('puppeteer/lib/cjs/puppeteer/common/DOMWorld.js');11const { escapeText } = require('playwright/lib/server/dom.js');12const { escapeText } = require('puppeteer/lib/cjs/puppeteer/common/DOMWorld.js');13const { escapeText } = require('playwright/lib/server/dom.js');14const { escapeText } = require('puppeteer/lib/cjs/puppeteer/common/DOMWorld.js');15const { escapeText } = require
Using AI Code Generation
1const { escapeText } = require('@playwright/test/lib/utils/escapeText');2console.log(escapeText("test"));3const { escapeText } = require('@playwright/test/lib/utils/escapeText');4console.log(escapeText("test"));5const { escapeText } = require('@playwright/test/lib/utils/escapeText');6console.log(escapeText("test"));7const { escapeText } = require('@playwright/test/lib/utils/escapeText');8console.log(escapeText("test"));9const { escapeText } = require('@playwright/test/lib/utils/escapeText');10console.log(escapeText("test"));11const { escapeText } = require('@playwright/test/lib/utils/escapeText');12console.log(escapeText("test"));13const { escapeText } = require('@playwright/test/lib/utils/escapeText');14console.log(escapeText("test"));15const { escapeText } = require('@playwright/test/lib/utils/escapeText');16console.log(escapeText("test"));17const { escapeText } = require('@playwright/test/lib/utils/escapeText');18console.log(escapeText("test"));19const { escapeText } = require('@playwright/test/lib/utils/escapeText');20console.log(escapeText("test"));21const { escapeText } = require
Using AI Code Generation
1const { escapeText } = require('playwright/lib/internal/utils/escapeText');2const escapedText = escapeText('Hello World');3const { escapeText } = require('playwright/lib/internal/utils/escapeText');4const escapedText = escapeText('Hello World');5const { escapeText } = require('playwright/lib/internal/utils/escapeText');6const escapedText = escapeText('Hello World');7const { escapeText } = require('playwright/lib/internal/utils/escapeText');8const escapedText = escapeText('Hello World');9const { escapeText } = require('playwright/lib/internal/utils/escapeText');10const escapedText = escapeText('Hello World');11const { escapeText } = require('playwright/lib/internal/utils/escapeText');12const escapedText = escapeText('Hello World');13const { escapeText } = require('playwright/lib/internal/utils/escapeText');14const escapedText = escapeText('Hello World');15const { escapeText } = require('playwright/lib/internal/utils/escapeText');16const escapedText = escapeText('Hello World');17const { escapeText } = require('playwright/lib/internal/utils/escapeText');18const escapedText = escapeText('Hello World');19const { escapeText } = require('playwright/lib/internal/utils/escapeText');20const escapedText = escapeText('Hello World');21const { escapeText } = require('playwright/lib/internal/utils/escapeText');22const escapedText = escapeText('Hello World');23const { escapeText } = require('playwright/lib/internal/utils/escapeText');24const escapedText = escapeText('Hello World');25const { escapeText } = require('playwright/lib/internal/utils/escapeText');
Using AI Code Generation
1const { escapeText } = require('playwright/lib/utils/escape');2console.log(escapeText('Hello World'));3const { escape } = require('lodash');4console.log(escape('Hello World'));5const { escape } = require('escape-html');6console.log(escape('Hello World'));7const { escape } = require('escape-string-regexp');8console.log(escape('Hello World'));9const { escape } = require('escape-string-applescript');10console.log(escape('Hello World'));11const { escape } = require('escape-html-entities');12console.log(escape('Hello World'));
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!