How to use parseText method in Playwright Internal

Best JavaScript code snippet using playwright-internal

parseItem.js

Source:parseItem.js Github

copy

Full Screen

...39 // Informational Item we can ignore40 return null;41 // Message-Types42 case 'backgroundPromoRenderer':43 if (UTIL.parseText(item[type].title) === 'No results found') return null;44 throw new Error('unknown message in backgroundPromoRenderer');45 case 'messageRenderer':46 // Skip all messages, since "no more results" changes with the language47 return null;48 case 'clarificationRenderer':49 return parseClarification(item[type]);50 // Skip Adds for now51 case 'carouselAdRenderer':52 case 'searchPyvRenderer':53 case 'promotedVideoRenderer':54 case 'promotedSparklesTextSearchRenderer':55 case 'compactPromotedItemRenderer':56 return null;57 // Skip emergencyOneboxRenderer (for now?)58 case 'emergencyOneboxRenderer':59 // Emergency Notifications like: Thinking about suicide? Call xxxx60 return null;61 // For debugging purpose62 case 'debug#previewCardRenderer':63 return parseHorizontalChannelListItem(item[type]);64 // New type & file without json until now => save65 default:66 throw new Error(`type ${type} is not known`);67 }68};69const catchAndLogFunc = (func, params = []) => {70 if (!Array.isArray(params)) throw new Error('params has to be an (optionally empty) array');71 try {72 return func(...params);73 } catch (e) {74 const dir = PATH.resolve(__dirname, '../dumps/');75 const file = PATH.resolve(dir, `${Math.random().toString(36).substr(3)}-${Date.now()}.txt`);76 const cfg = PATH.resolve(__dirname, '../package.json');77 const bugsRef = require(cfg).bugs.url;78 if (!FS.existsSync(dir)) FS.mkdirSync(dir);79 FS.writeFileSync(file, JSON.stringify(params, null, 2));80 /* eslint-disable no-console */81 console.error(e.stack);82 console.error(`\n/${'*'.repeat(200)}`);83 console.error(`failed at func ${func.name}: ${e.message}`);84 console.error(`pls post the the files in ${dir} to ${bugsRef}`);85 let info = `os: ${process.platform}-${process.arch}, `;86 info += `node.js: ${process.version}, `;87 info += `ytsr: ${require('../package.json').version}`;88 console.error(info);89 console.error(`${'*'.repeat(200)}\\`);90 /* eslint-enable no-console */91 return null;92 }93};94const main = module.exports = (...params) => catchAndLogFunc(parseItem, params);95main._hidden = { catchAndLogFunc, parseItem };96// TYPES:97const parseVideo = obj => {98 const author = obj.ownerText && obj.ownerText.runs[0];99 let authorUrl = null;100 if (author) {101 authorUrl = author.navigationEndpoint.browseEndpoint.canonicalBaseUrl ||102 author.navigationEndpoint.commandMetadata.webCommandMetadata.url;103 }104 const badges = Array.isArray(obj.badges) ? obj.badges.map(a => a.metadataBadgeRenderer.label) : [];105 const isLive = badges.some(b => b === 'LIVE NOW');106 const upcoming = obj.upcomingEventData ? Number(`${obj.upcomingEventData.startTime}000`) : null;107 const authorImg = !author ? null : obj.channelThumbnailSupportedRenderers.channelThumbnailWithLinkRenderer;108 const isOfficial = !!(obj.ownerBadges && JSON.stringify(obj.ownerBadges).includes('OFFICIAL'));109 const isVerified = !!(obj.ownerBadges && JSON.stringify(obj.ownerBadges).includes('VERIFIED'));110 const lengthFallback = obj.thumbnailOverlays.find(x => Object.keys(x)[0] === 'thumbnailOverlayTimeStatusRenderer');111 const length = obj.lengthText || (lengthFallback && lengthFallback.thumbnailOverlayTimeStatusRenderer.text);112 return {113 type: 'video',114 title: UTIL.parseText(obj.title, ''),115 id: obj.videoId,116 url: BASE_VIDEO_URL + obj.videoId,117 bestThumbnail: prepImg(obj.thumbnail.thumbnails)[0],118 thumbnails: prepImg(obj.thumbnail.thumbnails),119 isUpcoming: !!upcoming,120 upcoming,121 isLive,122 badges,123 // Author can be null for shows like whBqghP5Oow124 author: author ? {125 name: author.text,126 channelID: author.navigationEndpoint.browseEndpoint.browseId,127 url: new URL(authorUrl, BASE_VIDEO_URL).toString(),128 bestAvatar: prepImg(authorImg.thumbnail.thumbnails)[0],129 avatars: prepImg(authorImg.thumbnail.thumbnails),130 ownerBadges: Array.isArray(obj.ownerBadges) ? obj.ownerBadges.map(a => a.metadataBadgeRenderer.tooltip) : [],131 verified: isOfficial || isVerified,132 } : null,133 description: UTIL.parseText(obj.descriptionSnippet),134 views: !obj.viewCountText ? null : UTIL.parseIntegerFromText(obj.viewCountText),135 // Duration not provided for live & sometimes with upcoming & sometimes randomly136 duration: UTIL.parseText(length),137 // UploadedAt not provided for live & upcoming & sometimes randomly138 uploadedAt: UTIL.parseText(obj.publishedTimeText),139 };140};141const parseChannel = obj => {142 const targetUrl = obj.navigationEndpoint.browseEndpoint.canonicalBaseUrl ||143 obj.navigationEndpoint.commandMetadata.webCommandMetadata.url;144 const isOfficial = !!(obj.ownerBadges && JSON.stringify(obj.ownerBadges).includes('OFFICIAL'));145 const isVerified = !!(obj.ownerBadges && JSON.stringify(obj.ownerBadges).includes('VERIFIED'));146 return {147 type: 'channel',148 name: UTIL.parseText(obj.title, ''),149 channelID: obj.channelId,150 url: new URL(targetUrl, BASE_VIDEO_URL).toString(),151 bestAvatar: prepImg(obj.thumbnail.thumbnails)[0],152 avatars: prepImg(obj.thumbnail.thumbnails),153 verified: isOfficial || isVerified,154 subscribers: UTIL.parseText(obj.subscriberCountText),155 descriptionShort: UTIL.parseText(obj.descriptionSnippet),156 videos: obj.videoCountText ? UTIL.parseIntegerFromText(obj.videoCountText) : null,157 };158};159const parsePlaylist = obj => ({160 type: 'playlist',161 title: UTIL.parseText(obj.title, ''),162 playlistID: obj.playlistId,163 url: `https://www.youtube.com/playlist?list=${obj.playlistId}`,164 firstVideo: Array.isArray(obj.videos) && obj.videos.length > 0 ? {165 id: obj.navigationEndpoint.watchEndpoint.videoId,166 shortURL: BASE_VIDEO_URL + obj.navigationEndpoint.watchEndpoint.videoId,167 url: new URL(obj.navigationEndpoint.commandMetadata.webCommandMetadata.url, BASE_VIDEO_URL).toString(),168 title: UTIL.parseText(obj.videos[0].childVideoRenderer.title, ''),169 length: UTIL.parseText(obj.videos[0].childVideoRenderer.lengthText, ''),170 thumbnails: prepImg(obj.thumbnails[0].thumbnails),171 bestThumbnail: prepImg(obj.thumbnails[0].thumbnails)[0],172 } : null,173 // Some Playlists starting with OL only provide a simple string174 owner: obj.shortBylineText.simpleText ? null : _parseOwner(obj),175 publishedAt: UTIL.parseText(obj.publishedTimeText),176 length: Number(obj.videoCount),177});178const parseMix = obj => ({179 type: 'mix',180 title: UTIL.parseText(obj.title, ''),181 url: new URL(obj.navigationEndpoint.commandMetadata.webCommandMetadata.url, BASE_VIDEO_URL).toString(),182 firstVideo: {183 id: obj.navigationEndpoint.watchEndpoint.videoId,184 shortURL: BASE_VIDEO_URL + obj.navigationEndpoint.watchEndpoint.videoId,185 url: new URL(obj.navigationEndpoint.commandMetadata.webCommandMetadata.url, BASE_VIDEO_URL).toString(),186 text: UTIL.parseText(obj.videos[0].childVideoRenderer.title, ''),187 length: UTIL.parseText(obj.videos[0].childVideoRenderer.lengthText, ''),188 thumbnails: prepImg(obj.thumbnail.thumbnails),189 bestThumbnail: prepImg(obj.thumbnail.thumbnails)[0],190 },191});192const parseDidYouMeanRenderer = (obj, resp) => {193 // Add as the first item in refinements194 if (resp && Array.isArray(resp.refinements)) {195 resp.refinements.unshift({196 q: UTIL.parseText(obj.correctedQuery, ''),197 url: new URL(obj.correctedQueryEndpoint.commandMetadata.webCommandMetadata.url, BASE_VIDEO_URL).toString(),198 bestThumbnail: null,199 thumbnails: null,200 });201 }202 return null;203};204const parseShowingResultsFor = (obj, resp) => {205 // Add as resultsFor206 const cor = obj.showingResultsForRenderer.correctedQuery || obj.correctedQuery;207 if (resp) resp.correctedQuery = UTIL.parseText(cor);208 return null;209};210const parseClarification = obj => ({211 type: 'clarification',212 title: UTIL.parseText(obj.contentTitle, ''),213 text: UTIL.parseText(obj.text, ''),214 sources: [215 {216 text: UTIL.parseText(obj.source, ''),217 url: new URL(obj.endpoint.urlEndpoint.url, BASE_VIDEO_URL).toString(),218 },219 !obj.secondarySource ? null : {220 text: UTIL.parseText(obj.secondarySource, ''),221 url: new URL(obj.secondaryEndpoint.urlEndpoint.url, BASE_VIDEO_URL).toString(),222 },223 ].filter(a => a),224});225const parseHorizontalCardListRenderer = (obj, resp) => {226 const subType = Object.keys(obj.cards[0])[0];227 switch (subType) {228 case 'searchRefinementCardRenderer':229 return parseHorizontalRefinements(obj, resp);230 case 'previewCardRenderer':231 return parseHorizontalChannelList(obj);232 default:233 throw new Error(`subType ${subType} of type horizontalCardListRenderer not known`);234 }235};236const parseHorizontalRefinements = (obj, resp) => {237 // Add to refinements238 if (resp && Array.isArray(resp.refinements)) {239 resp.refinements.push(...obj.cards.map(c => {240 const targetUrl = c.searchRefinementCardRenderer.searchEndpoint.commandMetadata.webCommandMetadata.url;241 return {242 q: UTIL.parseText(c.searchRefinementCardRenderer.query, ''),243 url: new URL(targetUrl, BASE_VIDEO_URL).toString(),244 bestThumbnail: prepImg(c.searchRefinementCardRenderer.thumbnail.thumbnails)[0],245 thumbnails: prepImg(c.searchRefinementCardRenderer.thumbnail.thumbnails),246 };247 }));248 }249 return null;250};251const parseHorizontalChannelList = obj => {252 if (!JSON.stringify(obj.style).includes('CHANNELS')) {253 // Not sure if this is always a channel + videos254 throw new Error(`unknown style in horizontalCardListRenderer`);255 }256 return {257 type: 'horizontalChannelList',258 title: UTIL.parseText(obj.header.richListHeaderRenderer.title, ''),259 channels: obj.cards.map(i => parseHorizontalChannelListItem(i.previewCardRenderer)).filter(a => a),260 };261};262const parseHorizontalChannelListItem = obj => {263 const thumbnailRenderer = obj.header.richListHeaderRenderer.channelThumbnail.channelThumbnailWithLinkRenderer;264 return {265 type: 'channelPreview',266 name: UTIL.parseText(obj.header.richListHeaderRenderer.title, ''),267 channelID: obj.header.richListHeaderRenderer.endpoint.browseEndpoint.browseId,268 url: new URL(269 obj.header.richListHeaderRenderer.endpoint.commandMetadata.webCommandMetadata.url,270 BASE_VIDEO_URL,271 ).toString(),272 bestAvatar: prepImg(thumbnailRenderer.thumbnail.thumbnails)[0],273 avatars: prepImg(thumbnailRenderer.thumbnail.thumbnails),274 subscribers: UTIL.parseText(obj.header.richListHeaderRenderer.subtitle, ''),275 // Type: gridVideoRenderer276 videos: obj.contents.map(i => parseVideo(i.gridVideoRenderer)).filter(a => a),277 };278};279const parseGridMovie = obj => ({280 // Movie which can be found in horizontalMovieListRenderer281 type: 'gridMovie',282 title: UTIL.parseText(obj.title),283 videoID: obj.videoId,284 url: new URL(obj.navigationEndpoint.commandMetadata.webCommandMetadata.url, BASE_VIDEO_URL).toString(),285 bestThumbnail: prepImg(obj.thumbnail.thumbnails)[0],286 thumbnails: prepImg(obj.thumbnail.thumbnails),287 duration: UTIL.parseText(obj.lengthText),288});289const parseMovie = obj => {290 // Normalize291 obj.bottomMetadataItems = (obj.bottomMetadataItems || []).map(x => UTIL.parseText(x));292 const actorsString = obj.bottomMetadataItems.find(x => x.startsWith('Actors'));293 const directorsString = obj.bottomMetadataItems.find(x => x.startsWith('Director'));294 return {295 type: 'movie',296 title: UTIL.parseText(obj.title, ''),297 videoID: obj.videoId,298 url: new URL(obj.navigationEndpoint.commandMetadata.webCommandMetadata.url, BASE_VIDEO_URL).toString(),299 bestThumbnail: prepImg(obj.thumbnail.thumbnails)[0],300 thumbnails: prepImg(obj.thumbnail.thumbnails),301 owner: _parseOwner(obj),302 description: UTIL.parseText(obj.descriptionSnippet),303 meta: UTIL.parseText(obj.topMetadataItems[0], '').split(' · '),304 actors: !actorsString ? [] : actorsString.split(': ')[1].split(', '),305 directors: !directorsString ? [] : directorsString.split(': ')[1].split(', '),306 duration: UTIL.parseText(obj.lengthText, ''),307 };308};309const parseShow = obj => {310 const thumbnails = obj.thumbnailRenderer.showCustomThumbnailRenderer.thumbnail.thumbnails;311 const owner = _parseOwner(obj);312 delete owner.ownerBadges;313 delete owner.verified;314 return {315 type: 'show',316 title: UTIL.parseText(obj.title, ''),317 bestThumbnail: prepImg(thumbnails)[0],318 thumbnails: prepImg(thumbnails),319 url: new URL(obj.navigationEndpoint.commandMetadata.webCommandMetadata.url, BASE_VIDEO_URL).toString(),320 videoID: obj.navigationEndpoint.watchEndpoint.videoId,321 playlistID: obj.navigationEndpoint.watchEndpoint.playlistId,322 episodes: UTIL.parseIntegerFromText(obj.thumbnailOverlays[0].thumbnailOverlayBottomPanelRenderer.text),323 owner,324 };325};326const parseShelf = obj => {327 let rawItems = [];328 if (Array.isArray(obj.contents)) {329 rawItems = obj.contents.map(x => x.richItemRenderer.content);330 } else {331 rawItems = (obj.content.verticalListRenderer || obj.content.horizontalMovieListRenderer).items;332 }333 // Optional obj.thumbnail is ignored334 return {335 type: 'shelf',336 title: UTIL.parseText(obj.title, 'Show More'),337 items: rawItems.map(i => parseItem(i)).filter(a => a),338 };339};340/**341 * Generalised Method342 *343 * used in Playlist, Movie and Show344 * show does never provide badges thou345 *346 * @param {Object} obj the full Renderer Object provided by YouTube347 * @returns {Object} the parsed owner348 */349const _parseOwner = obj => {350 const owner = (obj.shortBylineText && obj.shortBylineText.runs[0]) ||...

Full Screen

Full Screen

sage-controls-namepanel.js

Source:sage-controls-namepanel.js Github

copy

Full Screen

12function NamePanel (clientId, prefix, first, middle, last, suffix, autoPostBack)3{4 this.ClientId = clientId;5 this.nameDivId = clientId + "_outerDiv";6 this.displayID = clientId + "_displayText";7 this.returnValueId = clientId + "_nameResult";8 this.prefix = prefix;9 this.first = first;10 this.middle = middle;11 this.last = last;12 this.suffix = suffix;13 this.AutoPostBack = autoPostBack;14 this.TextChanged = false;15 this.panel = null;16}17function NamePanel_Show()18{19 if ((this.panel == null) || (this.panel.element.parentNode == null))20 {21 var dlgDiv = document.getElementById(this.nameDivId);22 dlgDiv.style.display = "block";23 this.panel = new YAHOO.widget.Panel(this.nameDivId, { visible:false, width:"300px", height:"250px", /*x:250, y:200,*/ fixedcenter:true, constraintoviewport:true, underlay:"shadow", draggable:true });24 this.panel.render();25 }26 this.panel.show();27 document.getElementById(this.ClientId + "_first").focus();28}29function NamePanel_Cancel()30{31 this.panel.hide();32 document.getElementById(this.ClientId + "_prefix_Text").value = this.prefix;33 document.getElementById(this.ClientId + "_first").value = this.first;34 document.getElementById(this.ClientId + "_middle").value = this.middle;35 document.getElementById(this.ClientId + "_last").value = this.last;36 document.getElementById(this.ClientId + "_suffix_Text").value = this.suffix;37}38function NamePanel_Ok()39{40 this.panel.hide();41 this.prefix = document.getElementById(this.ClientId + "_prefix_Text").value;42 this.first = document.getElementById(this.ClientId + "_first").value;43 this.middle = document.getElementById(this.ClientId + "_middle").value;44 this.last = document.getElementById(this.ClientId + "_last").value;45 this.suffix = document.getElementById(this.ClientId + "_suffix_Text").value;46 var returnValue = document.getElementById(this.returnValueId);47 returnValue.value = this.prefix + "|" + this.first + "|" + this.middle + "|" + this.last + "|" + this.suffix;48 this.FormatName();49}50function NamePanel_HandleKeyEvent(evt)51{52 if (!evt) {53 evt = window.event;54 }55 if (evt.keyCode == 13) //Enter56 {57 this.Ok();58 }59 else if (evt.keyCode == 27) //Esc60 {61 this.Cancel();62 }63}64function NamePanel_Trim(stringToTrim) {65 return stringToTrim.replace(/^\s+|\s+$/g,"");66}67function NamePanel_NameChanged()68{69 this.TextChanged = true;70}71function NamePanel_FormatName()72{73 var name = ((this.prefix == "") ? "" : this.prefix + ' ');74 name += ((this.first == "") ? "" : this.first + ' ');75 name += ((this.middle == "") ? "" : this.middle + ' ');76 name += ((this.last == "") ? "" : this.last + ' ');77 name += ((this.suffix == "") ? "" : this.suffix);78 name = this.Trim(name);79 80 var elem = document.getElementById(this.displayID);81 elem.value = name;82 this.TextChanged = false;83 if (this.AutoPostBack)84 {85 if (Sys)86 {87 Sys.WebForms.PageRequestManager.getInstance()._doPostBack(this.displayID, null);88 }89 else90 {91 document.forms(0).submit();92 }93 }94}95function NamePanel_ParseName()96{97 if (!this.TextChanged) { return; }98 var longest = 0;99 var elem = document.getElementById(this.displayID);100 var parseText = elem.value;101 var prefixes = document.getElementById(this.ClientId + "_prefix_Items");102 var suffixes = document.getElementById(this.ClientId + "_suffix_Items");103 var lastNamePrefixes = document.getElementById(this.ClientId + "_lastNamePrefixes");104 var testValue = "";105 //Reset all values106 this.prefix = "";107 this.first = "";108 this.middle = "";109 this.last = "";110 this.suffix = "";111 document.getElementById(this.ClientId + "_prefix_Text").value = this.prefix;112 document.getElementById(this.ClientId + "_suffix_Text").value = this.suffix;113 document.getElementById(this.ClientId + "_last").value = this.last;114 document.getElementById(this.ClientId + "_first").value = this.first;115 document.getElementById(this.ClientId + "_middle").value = this.middle;116 117 //Start with prefixes118 if (prefixes.options.length == 0)119 {120 eval(this.ClientId + "_prefix_obj.GetList();");121 }122 for (var i = 0; i < prefixes.options.length; i++)123 {124 var testPrefix = prefixes.options[i].text.toUpperCase() + " ";125 testValue = parseText.substr(0, testPrefix.length).toUpperCase();126 if (testValue.localeCompare(testPrefix) == 0)127 {128 if (prefixes.options[i].text.length > longest)129 {130 this.prefix = this.Trim(prefixes.options[i].text);131 document.getElementById(this.ClientId + "_prefix_Text").value = this.prefix;132 longest = this.prefix.length;133 break;134 }135 }136 else137 {138 testPrefix = testPrefix.replace(/\./g, "");139 testValue = parseText.substr(0, testPrefix.length).toUpperCase();140 if (testValue.localeCompare(testPrefix) == 0)141 {142 if (prefixes.options[i].text.length > longest)143 {144 this.prefix = this.Trim(prefixes.options[i].text);145 document.getElementById(this.ClientId + "_prefix_Text").value = this.prefix;146 longest = testPrefix.length;147 break;148 }149 }150 }151 }152 if (longest > 0)153 {154 parseText = parseText.substr(longest);155 }156 157 //Now check for suffixes158 longest = 0;159 lastSpaceIdx = parseText.lastIndexOf(" ");160 testValue = parseText.substr(lastSpaceIdx +1).replace(/\./g, "");161 testValue = testValue.toUpperCase();162 if (suffixes.options.length == 0)163 {164 eval(this.ClientId + "_suffix_obj.GetList();");165 }166 for (var i = 0; i < suffixes.options.length; i++)167 {168 var suffixWithoutDots = suffixes.options[i].text.replace(/\./g, "");169 suffixWithoutDots = suffixWithoutDots.toUpperCase();170 if (parseText.length > suffixes.options[i].text.length +1)171 {172 if (testValue.localeCompare(suffixWithoutDots) == 0)173 {174 if (suffixWithoutDots.length > 0)175 {176 this.suffix = this.Trim(suffixes.options[i].text);177 document.getElementById(this.ClientId + "_suffix_Text").value = this.suffix;178 longest = this.suffix.length;179 }180 parseText = parseText.substr(0, lastSpaceIdx) + " " + this.suffix;181 }182 }183 else184 {185 testValue = testValue.substr(testValue.length - suffixWithoutDots.length, suffixWithoutDots.length +1);186 if (testValue.localeCompare(" " + suffixWithoutDots) == 0)187 {188 if (suffixWithoutDots.length > 0)189 {190 this.suffix = this.Trim(suffixes.options[i].text);191 document.getElementById(this.ClientId + "_suffix_Text").value = this.suffix;192 longest = suffixWithoutDots.length;193 break;194 }195 }196 }197 }198 //alert(parseText + " " + longest);199 if (longest > 0)200 {201 longest++;202 parseText = parseText.substr(0, parseText.length - longest);203 }204 205 //Set Last Name206 lastSpaceIdx = parseText.lastIndexOf(" ");207 //Trim spaces from the end.208 while ((lastSpaceIdx == parseText.length -1) && (lastSpaceIdx > 0))209 {210 parseText = parseText.substr(0, lastSpaceIdx);211 lastSpaceIdx = parseText.lastIndexOf(" ");212 }213 if (lastSpaceIdx > 0)214 {215 this.last = parseText.substr(lastSpaceIdx +1);216 document.getElementById(this.ClientId + "_last").value = this.last;217 parseText = parseText.substr(0, lastSpaceIdx);218 }219 else220 {221 this.last = this.Trim(parseText);222 document.getElementById(this.ClientId + "_last").value = this.last;223 parseText = "";224 }225 226 //Set Middle/Two Word Last227 lastSpaceIdx = parseText.lastIndexOf(" ");228 //alert(parseText + ": last space index: " + lastSpaceIdx);229 if (lastSpaceIdx > 0)230 {231 testValue = parseText.substr(lastSpaceIdx +1).toUpperCase();232 //alert("TestValue: " + testValue);233 for (var i = 0; i < lastNamePrefixes.options.length; i++)234 {235 if (testValue.localeCompare(lastNamePrefixes.options[i].text.toUpperCase()) == 0)236 {237 this.last = lastNamePrefixes.options[i].text + " " + this.last;238 document.getElementById(this.ClientId + "_last").value = this.last;239 parseText = parseText.substr(0, lastSpaceIdx);240 break;241 }242 }243 }244 245 if ((this.last != "") && (this.last[this.last.length-1] == ","))246 {247 this.last = this.last.substr(0, this.last.length -1);248 }249 //Set First Name250 parseText = this.Trim(parseText);251 lastSpaceIdx = parseText.indexOf(" ");252 //alert(parseText + ": last space index: " + lastSpaceIdx);253 if (lastSpaceIdx > 0)254 {255 this.first = this.Trim(parseText.substr(0, lastSpaceIdx));256 this.middle = this.Trim(parseText.substr(lastSpaceIdx +1));257 }258 else { this.first = this.Trim(parseText); }259 document.getElementById(this.ClientId + "_first").value = this.first;260 document.getElementById(this.ClientId + "_middle").value = this.middle;261 var returnValue = document.getElementById(this.returnValueId);262 returnValue.value = this.prefix + "|" + this.first + "|" + this.middle + "|" + this.last + "|" + this.suffix;263 this.FormatName();264}265NamePanel.prototype.FormatName = NamePanel_FormatName;266NamePanel.prototype.Show = NamePanel_Show;267NamePanel.prototype.Cancel = NamePanel_Cancel;268NamePanel.prototype.Ok = NamePanel_Ok;269NamePanel.prototype.HandleKeyEvent = NamePanel_HandleKeyEvent;270NamePanel.prototype.NameChanged = NamePanel_NameChanged;271NamePanel.prototype.ParseName = NamePanel_ParseName;...

Full Screen

Full Screen

sage-controls-namepanel-min.js

Source:sage-controls-namepanel-min.js Github

copy

Full Screen

1/*2 * Sage SalesLogix Web Controls3 * Copyright(c) 2009, Sage Software.4 */5function NamePanel(clientId,prefix,first,middle,last,suffix,autoPostBack)6{this.ClientId=clientId;this.nameDivId=clientId+"_outerDiv";this.displayID=clientId+"_displayText";this.returnValueId=clientId+"_nameResult";this.prefix=prefix;this.first=first;this.middle=middle;this.last=last;this.suffix=suffix;this.AutoPostBack=autoPostBack;this.TextChanged=false;this.panel=null;}7function NamePanel_Show()8{if((this.panel==null)||(this.panel.element.parentNode==null))9{var dlgDiv=document.getElementById(this.nameDivId);dlgDiv.style.display="block";this.panel=new YAHOO.widget.Panel(this.nameDivId,{visible:false,width:"300px",height:"250px",fixedcenter:true,constraintoviewport:true,underlay:"shadow",draggable:true});this.panel.render();}10this.panel.show();document.getElementById(this.ClientId+"_first").focus();}11function NamePanel_Cancel()12{this.panel.hide();document.getElementById(this.ClientId+"_prefix_Text").value=this.prefix;document.getElementById(this.ClientId+"_first").value=this.first;document.getElementById(this.ClientId+"_middle").value=this.middle;document.getElementById(this.ClientId+"_last").value=this.last;document.getElementById(this.ClientId+"_suffix_Text").value=this.suffix;}13function NamePanel_Ok()14{this.panel.hide();this.prefix=document.getElementById(this.ClientId+"_prefix_Text").value;this.first=document.getElementById(this.ClientId+"_first").value;this.middle=document.getElementById(this.ClientId+"_middle").value;this.last=document.getElementById(this.ClientId+"_last").value;this.suffix=document.getElementById(this.ClientId+"_suffix_Text").value;var returnValue=document.getElementById(this.returnValueId);returnValue.value=this.prefix+"|"+this.first+"|"+this.middle+"|"+this.last+"|"+this.suffix;this.FormatName();}15function NamePanel_HandleKeyEvent(evt)16{if(!evt){evt=window.event;}17if(evt.keyCode==13)18{this.Ok();}19else if(evt.keyCode==27)20{this.Cancel();}}21function NamePanel_Trim(stringToTrim){return stringToTrim.replace(/^\s+|\s+$/g,"");}22function NamePanel_NameChanged()23{this.TextChanged=true;}24function NamePanel_FormatName()25{var name=((this.prefix=="")?"":this.prefix+' ');name+=((this.first=="")?"":this.first+' ');name+=((this.middle=="")?"":this.middle+' ');name+=((this.last=="")?"":this.last+' ');name+=((this.suffix=="")?"":this.suffix);name=this.Trim(name);var elem=document.getElementById(this.displayID);elem.value=name;this.TextChanged=false;if(this.AutoPostBack)26{if(Sys)27{Sys.WebForms.PageRequestManager.getInstance()._doPostBack(this.displayID,null);}28else29{document.forms(0).submit();}}}30function NamePanel_ParseName()31{if(!this.TextChanged){return;}32var longest=0;var elem=document.getElementById(this.displayID);var parseText=elem.value;var prefixes=document.getElementById(this.ClientId+"_prefix_Items");var suffixes=document.getElementById(this.ClientId+"_suffix_Items");var lastNamePrefixes=document.getElementById(this.ClientId+"_lastNamePrefixes");var testValue="";this.prefix="";this.first="";this.middle="";this.last="";this.suffix="";document.getElementById(this.ClientId+"_prefix_Text").value=this.prefix;document.getElementById(this.ClientId+"_suffix_Text").value=this.suffix;document.getElementById(this.ClientId+"_last").value=this.last;document.getElementById(this.ClientId+"_first").value=this.first;document.getElementById(this.ClientId+"_middle").value=this.middle;if(prefixes.options.length==0)33{eval(this.ClientId+"_prefix_obj.GetList();");}34for(var i=0;i<prefixes.options.length;i++)35{var testPrefix=prefixes.options[i].text.toUpperCase()+" ";testValue=parseText.substr(0,testPrefix.length).toUpperCase();if(testValue.localeCompare(testPrefix)==0)36{if(prefixes.options[i].text.length>longest)37{this.prefix=this.Trim(prefixes.options[i].text);document.getElementById(this.ClientId+"_prefix_Text").value=this.prefix;longest=this.prefix.length;break;}}38else39{testPrefix=testPrefix.replace(/\./g,"");testValue=parseText.substr(0,testPrefix.length).toUpperCase();if(testValue.localeCompare(testPrefix)==0)40{if(prefixes.options[i].text.length>longest)41{this.prefix=this.Trim(prefixes.options[i].text);document.getElementById(this.ClientId+"_prefix_Text").value=this.prefix;longest=testPrefix.length;break;}}}}42if(longest>0)43{parseText=parseText.substr(longest);}44longest=0;lastSpaceIdx=parseText.lastIndexOf(" ");testValue=parseText.substr(lastSpaceIdx+1).replace(/\./g,"");testValue=testValue.toUpperCase();if(suffixes.options.length==0)45{eval(this.ClientId+"_suffix_obj.GetList();");}46for(var i=0;i<suffixes.options.length;i++)47{var suffixWithoutDots=suffixes.options[i].text.replace(/\./g,"");suffixWithoutDots=suffixWithoutDots.toUpperCase();if(parseText.length>suffixes.options[i].text.length+1)48{if(testValue.localeCompare(suffixWithoutDots)==0)49{if(suffixWithoutDots.length>0)50{this.suffix=this.Trim(suffixes.options[i].text);document.getElementById(this.ClientId+"_suffix_Text").value=this.suffix;longest=this.suffix.length;}51parseText=parseText.substr(0,lastSpaceIdx)+" "+this.suffix;}}52else53{testValue=testValue.substr(testValue.length-suffixWithoutDots.length,suffixWithoutDots.length+1);if(testValue.localeCompare(" "+suffixWithoutDots)==0)54{if(suffixWithoutDots.length>0)55{this.suffix=this.Trim(suffixes.options[i].text);document.getElementById(this.ClientId+"_suffix_Text").value=this.suffix;longest=suffixWithoutDots.length;break;}}}}56if(longest>0)57{longest++;parseText=parseText.substr(0,parseText.length-longest);}58lastSpaceIdx=parseText.lastIndexOf(" ");while((lastSpaceIdx==parseText.length-1)&&(lastSpaceIdx>0))59{parseText=parseText.substr(0,lastSpaceIdx);lastSpaceIdx=parseText.lastIndexOf(" ");}60if(lastSpaceIdx>0)61{this.last=parseText.substr(lastSpaceIdx+1);document.getElementById(this.ClientId+"_last").value=this.last;parseText=parseText.substr(0,lastSpaceIdx);}62else63{this.last=this.Trim(parseText);document.getElementById(this.ClientId+"_last").value=this.last;parseText="";}64lastSpaceIdx=parseText.lastIndexOf(" ");if(lastSpaceIdx>0)65{testValue=parseText.substr(lastSpaceIdx+1).toUpperCase();for(var i=0;i<lastNamePrefixes.options.length;i++)66{if(testValue.localeCompare(lastNamePrefixes.options[i].text.toUpperCase())==0)67{this.last=lastNamePrefixes.options[i].text+" "+this.last;document.getElementById(this.ClientId+"_last").value=this.last;parseText=parseText.substr(0,lastSpaceIdx);break;}}}68if((this.last!="")&&(this.last[this.last.length-1]==","))69{this.last=this.last.substr(0,this.last.length-1);}70parseText=this.Trim(parseText);lastSpaceIdx=parseText.indexOf(" ");if(lastSpaceIdx>0)71{this.first=this.Trim(parseText.substr(0,lastSpaceIdx));this.middle=this.Trim(parseText.substr(lastSpaceIdx+1));}72else{this.first=this.Trim(parseText);}73document.getElementById(this.ClientId+"_first").value=this.first;document.getElementById(this.ClientId+"_middle").value=this.middle;var returnValue=document.getElementById(this.returnValueId);returnValue.value=this.prefix+"|"+this.first+"|"+this.middle+"|"+this.last+"|"+this.suffix;this.FormatName();}...

Full Screen

Full Screen

rtf-parser.js

Source:rtf-parser.js Github

copy

Full Screen

...104 this.controlWord += char105 } else {106 this.emitControlWord()107 this.parserState = this.parseText108 this.parseText(char)109 }110 }111 parseControlWordParam (char) {112 if (/^\d$/.test(char)) {113 this.controlWordParam += char114 } else if (char === ' ') {115 this.emitControlWord()116 this.parserState = this.parseText117 } else {118 this.emitControlWord()119 this.parserState = this.parseText120 this.parseText(char)121 }122 }123 emitText () {124 if (this.text === '') return125 this.push({type: 'text', value: this.text, pos: this.char, row: this.row, col: this.col})126 this.text = ''127 }128 emitControlWord () {129 this.emitText()130 if (this.controlWord === '') {131 this.emitError('empty control word')132 } else {133 this.push({134 type: 'control-word',...

Full Screen

Full Screen

syntax_highlighter_tests.js

Source:syntax_highlighter_tests.js Github

copy

Full Screen

...5describe("SyntaxHighlighter", function() {6 var assert = chai.assert;7 it("should highlight basic code", function() {8 var highlighter = new SyntaxHighlighter("cpp");9 assert.equal(highlighter.parseText("void main(const char* argv, int argc) {"), '<span class="hljs-keyword">void</span> main(<span class="hljs-keyword">const</span> <span class="hljs-keyword">char</span>* argv, <span class="hljs-keyword">int</span> argc) {');10 assert.equal(highlighter.parseText('return printf("%d arg count", argc);'), '<span class="hljs-keyword">return</span> <span class="hljs-built_in">printf</span>(<span class="hljs-string">"%d arg count"</span>, argc);');11 assert.equal(highlighter.parseText("}"), '}');12 });13 it("should return null when no language", function() {14 var highlighter = new SyntaxHighlighter("");15 assert.isNull(highlighter.parseText("void main(const char* argv, int argc) {"));16 });17 it("should highlight multi line comments", function() {18 var highlighter = new SyntaxHighlighter("javascript");19 assert.equal(highlighter.parseText("/*"), '<span class="hljs-comment">/*</span>');20 assert.equal(highlighter.parseText("still a comment"), '<span class="hljs-comment">still a comment</span>');21 assert.equal(highlighter.parseText("end */"), '<span class="hljs-comment">end */</span>');22 assert.equal(highlighter.parseText("not a comment"), 'not a comment');23 });24 it("should allow highlighter resetting", function() {25 var highlighter = new SyntaxHighlighter("javascript");26 assert.equal(highlighter.parseText("not a comment"), 'not a comment');27 assert.equal(highlighter.parseText("/*"), '<span class="hljs-comment">/*</span>');28 highlighter.resetSyntaxState();29 assert.equal(highlighter.parseText("not a comment"), 'not a comment');30 });31 it("should support embedded script", function() {32 var highlighter = new SyntaxHighlighter("html");33 assert.equal(highlighter.parseText('<script type="test">'), '<span class="hljs-tag">&lt;<span class="hljs-title">script</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">"test"</span>&gt;</span><span class="javascript"></span>');34 assert.equal(highlighter.parseText('new F(); document'), '<span class="javascript"><span class="hljs-keyword">new</span> F(); <span class="hljs-built_in">document</span></span>');35 assert.equal(highlighter.parseText("</script>"), '<span class="javascript"></span><span class="hljs-tag">&lt;/<span class="hljs-title">script</span>&gt;</span>');36 });37 it("should support embedded style", function() {38 var highlighter = new SyntaxHighlighter("html");39 assert.equal(highlighter.parseText('<style type="test">'), '<span class="hljs-tag">&lt;<span class="hljs-title">style</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">"test"</span>&gt;</span><span class="css"></span>');40 assert.equal(highlighter.parseText('.foo { color: "<style>"; }'), '<span class="css"><span class="hljs-class">.foo</span> <span class="hljs-rules">{ <span class="hljs-rule"><span class="hljs-attribute">color</span>:<span class="hljs-value"> <span class="hljs-string">"&lt;style&gt;"</span></span></span>; <span class="hljs-rule">}</span></span></span>');41 assert.equal(highlighter.parseText("</style>"), '<span class="css"></span><span class="hljs-tag">&lt;/<span class="hljs-title">style</span>&gt;</span>');42 });...

Full Screen

Full Screen

descParser.js

Source:descParser.js Github

copy

Full Screen

...3let allFleet = [];4for(let i = 0; i < abc.length; i++) {5 let vsls = JSON.parse(fs.readFileSync(`./vsl-descr/fleet_${abc[i]}.json`));6 vsls = vsls.filter(vsl => {7 const name = parseText(vsl.description, /<B>MV<\/B>\s"([\d\w\s\-\.']*)"/);8 if(name !== '')9 return true10 });11 allFleet = allFleet.concat(vsls.map((vsl, index) => {12 console.log(index, vsl.imo);13 14 const descText = vsl.description; 15 const name = parseText(descText, /<B>MV<\/B>\s"([\d\w\s\-\.']*)"/);16 const type = parseText(descText, /<B>Type :<\/B>([\w\s]*)</); 17 const subType = parseText(descText, /<B>Sub type :<\/B>([\w\s\-\/]*)</); 18 const build = parseText(descText, /<B>Built :<\/B>\s*(\d*)/);19 const flag = parseText(descText, /<B>Flag :<\/B>([\w\s\(\)&]*)</);20 const vslClass = parseText(descText, /<B>Class :<\/B>([\w\s]*)</);21 const dwt = parseText(descText, /<B>DWT\/Draft:<\/B>([\d\,\s]*)M/);22 const draft = parseText(descText, /<B>DWT\/Draft:<\/B>[\d\,\s]*MT DWT \/([\d\.\s]*) m/);23 const tpc = parseText(descText, /TPC \/ TPI :([\d\.\s]*)MT/);24 const loa = parseText(descText, /([\d\.]*) m \(loa\)/);25 const beam = parseText(descText, /([\d\.]*) m \(beam\)/); 26 const lbp = parseText(descText, /LBP :\s*([\d\.]*) m/);27 const grt = parseText(descText, /Int'l tonnage : ([\d\,]*) GT/); 28 const nrt = parseText(descText, /Int'l tonnage : [\d\,]* GT \/ ([\d\,]*) NT/);29 const shipowner = parseText(descText, /Shipowner :([\w\s&\-]*)\s\-{2}/);30 const gears = descText.includes('Gearless')? 'Gearless': 'Geared';31 console.log(index, name);32 33 return {34 name,35 build,36 type,37 subType, 38 gears,39 imo: vsl.imo,40 callsign: vsl.callsign,41 mmsi: vsl.mmsi,42 flag, 43 vslClass, 44 dwt, 45 draft, 46 tpc, 47 loa, 48 beam, 49 lbp, 50 grt,51 nrt, 52 shipowner, 53 fullDescription: vsl.description54 }55 }));56 console.log(allFleet.length);57}58fs.writeFile("./vsl-descr/parsed/allFleet.json", JSON.stringify(allFleet), err => {59 if (err) throw err;60 61 console.log('The file has been saved!');62});63function parseText(text, regexp) {64 const match = text.match(regexp);65 if(match) 66 return match[1].trim();67 68 return 0;...

Full Screen

Full Screen

parse-text.test.js

Source:parse-text.test.js Github

copy

Full Screen

1import test from 'ava';2import { parseText } from '../src/scripts/parse-text';3test('Parser should parse middle', t => {4 const arr = parseText('first *second* third');5 t.deepEqual(arr, ['first ', '*second*', ' third']);6});7test('Parser should parse first and last', t => {8 const arr = parseText('*first* second *third*');9 t.deepEqual(arr, ['*first*', ' second ', '*third*']);10});11test('Parser should allow same draggable multiple times', t => {12 const arr = parseText('*first* second *first* third');13 t.deepEqual(arr, ['*first*', ' second ', '*first*', ' third']);14});15test('Parser should allow black space in draggables', t => {16 const arr = parseText('*first second* third');17 t.deepEqual(arr, ['*first second*', ' third']);18});19test('Parser should allow draggables next to each other', t => {20 const arr = parseText('*first**second**third*');21 t.deepEqual(arr, ['*first*', '*second*', '*third*']);22});23test('Parser should allow reserved characters', t => {24 const arr = parseText('*first/1st* *second:tip* *third/3rd:tip*');25 t.deepEqual(arr, ['*first/1st*', ' ', '*second:tip*', ' ', '*third/3rd:tip*']);26});27test('Parser should allow empty string', t => {28 const arr = parseText('');29 t.deepEqual(arr, []);...

Full Screen

Full Screen

ParseText.test.js

Source:ParseText.test.js Github

copy

Full Screen

1import parseText from './parseText'2test("converts codes into the correct punctuation", () => {3 expect(parseText('&quot;')).toBe('"');4 expect(parseText('&#039;')).toBe('\'');5 expect(parseText('&#039;')).toBe('\'');6 expect(parseText('&amp;')).toBe('&');7 expect(parseText('&lrm;')).toBe('');8 expect(parseText('&shy;')).toBe('');9 expect(parseText('&oacute;')).toBe('ó');10 expect(parseText('&ldquo;')).toBe('“');11 expect(parseText('&rsquo;')).toBe('’');12 expect(parseText('&hellip;')).toBe('…');13 expect(parseText('&rdquo;')).toBe('”');14 expect(parseText('&Eacute;')).toBe('É');...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const path = require('path');2const { parseText } = require(path.join(__dirname, '../node_modules/playwright/lib/server/supplements/recorder/recorderApp.js'));3console.log(parseText('Click "text=Sign In"'));4console.log(parseText('Click "text=Sign In" >> "text=Sign In"'));5console.log(parseText('Click "text=Sign In" >> "text=Sign In" >> "text=Sign In"'));6const path = require('path');7const { parseText } = require(path.join(__dirname, '../node_modules/playwright/lib/server/supplements/recorder/recorderApp.js'));8console.log(parseText('Click "text=Sign In"'));9console.log(parseText('Click "text=Sign In" >> "text=Sign In"'));10console.log(parseText('Click "text=Sign In" >> "text=Sign In" >> "text=Sign In"'));11{ action: 'click', selector: '"text=Sign In"' }12{ action: 'click', selector: '"text=Sign In" >> "text=Sign In"' }13{ action: 'click', selector: '"text=Sign In" >>

Full Screen

Using AI Code Generation

copy

Full Screen

1const { parseText } = require('playwright/lib/utils/selectorParser');2const { parseSelector } = require('playwright/lib/client/selectorEngine');3const selector = parseSelector('text=foo');4const parsed = parseText(selector.text);5console.log(parsed);6{ body: 'foo', exact: true }7{ body: 'foo', exact: true }8{ body: 'foo bar', exact: true }9{ body: 'foo', exact: false }10{ body: 'foo bar', exact: false }11{ body: 'foo', exact: false }12{ body: 'foo', exact: false }

Full Screen

Using AI Code Generation

copy

Full Screen

1const { parseText } = require('playwright-core/lib/utils/parseText');2const text = 'Hello World!';3const result = parseText(text);4console.log(result);5const { parseSelector } = require('playwright-core/lib/utils/parseSelector');6const selector = 'text=Hello World!';7const result = parseSelector(selector);8console.log(result);9const { parseSelector } = require('playwright-core/lib/utils/parseSelector');10const selector = 'id=hello-world';11const result = parseSelector(selector);12console.log(result);13const { parseSelector } = require('playwright-core/lib/utils/parseSelector');14const selector = 'css=div#hello-world';15const result = parseSelector(selector);16console.log(result);17const { parseSelector } = require('playwright-core/lib/utils/parseSelector');18const result = parseSelector(selector);19console.log(result);20const { parseSelector } = require('playwright-core/lib/utils/parseSelector');21const selector = 'data-testid=hello-world';22const result = parseSelector(selector);23console.log(result);24const { parseSelector } = require('playwright-core/lib/utils/parseSelector');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { parseText } = require('playwright/lib/utils/parseText');2const text = parseText('text');3console.log(text);4const { parseText } = require('playwright/lib/utils/parseText');5const text = 'Hello World!';6const parsedText = parseText(text);7console.log(parsedText);8- [parseText](

Full Screen

Using AI Code Generation

copy

Full Screen

1const { parseText } = require('playwright/lib/server/speechSynthesis');2const fs = require('fs');3const path = require('path');4const text = 'Hello World';5const output = parseText(text);6fs.writeFileSync(path.join(__dirname, 'output.wav'), output);7If you are interested in contributing, please read our [contributing guide](

Full Screen

Playwright tutorial

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.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal 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