Best JavaScript code snippet using playwright-internal
jwt.Class.js
Source:jwt.Class.js
1$(document).ready(function () {23 $("#inputBox").bind('input', function () {4 if (false == $('#inputBox').hasClass("watermark")) {5 DisplayToken($('#inputBox').val());6 }7 });89 $("#ExampleLink").click(function (e) {10 $('#inputBox').val(exampleJWT);11 DisplayToken(exampleJWT);12 if (diagExampleCount == 0) {1314 }15 diagExampleCount++;16 });1718 //set token if present1920 if (undefined != token) {21 $('#inputBox').val(token);22 DisplayToken(token);23 } else {24 $('#inputBox').val(inputboxWatermarkText).addClass("watermark");25 }26});272829function ShowShareBox(boolShow) {3031 if (true == boolShow) {32 // run with share link off, until layout is fixed w/ example token up date33 // $(".rightItem").fadeIn("medium", "swing");34 } else {35 $(".rightItem").hide();36 }37}383940function DisplayToken(jwtEncoded) {41 // get formated token42 var formattedToken;4344 try {45 formattedToken = FormatJWT(jwtEncoded);46 // write JWT to content47 WriteFormatedTokenToPage(formattedToken);4849 } catch (err) {50 WriteFormatedTokenToPage(err);51 }52}5354function WriteFormatedTokenToPage(token) {55 $('#decodedToken').html(token+'<br /><button type="button" id="fetchJSON">JSONfy</button>');56}575859function Base64URLDecode(base64UrlEncodedValue) {60 var result1;61 var result2;62 var newValue = base64UrlEncodedValue.replace("-", "+").replace("_", "/");63 6465 try {6667 result1 = window.atob(newValue);68 result2 = decodeURIComponent(escape(window.atob(newValue)));69 if (result1 != result2) {7071 }727374 } catch (e) {75 throw "Base64URL decode of JWT segment failed";76 }7778 return result2;79}8081function FormatJWT(jwt) {82 var segments = jwt.split('.');838485 if (jwt == "") {86 return "";87 }8889 if (segments.length != 3) {90 throw "JWT is required to have three segments"91 }9293 var header = DisplayJSON(Base64URLDecode(segments[0])).GetFormattedValue();94 var content = DisplayJSON(Base64URLDecode(segments[1])).GetFormattedValue();9596 return content;97}9899function StringBuilder() {100 var value = [];101102 return {103 Value: function () {104 return value.join("");105 },106107 Add: function (string) {108109 var valueArray = string.split('');110111 for (var i = 0; i < valueArray.length; i++) {112 value.push(valueArray[i]);113 }114 }115 };116}117118function DisplayJSON(value) {119120 var inputChars = value.split('');121 var index;122 var currentFieldname = "";123 var digits = "1234567890";124125 try {126 $.parseJSON(value);127 } catch (e) {128129 return "[THIS SEGEMENT DOES NOT CONTAIN A VALID JSON OBJECT]";130 }131132133 return {134135 GetFormattedValue: function () {136 var builder = StringBuilder();137 index = 0;138 indent = 0;139 this.FormatNext(builder, indent);140141 return builder.Value();142 },143144 FormatNext: function (builder, indent) {145146 switch (this.NextValueType()) {147 case "value":148 this.FormatValue(builder, indent);149 break;150 case "object":151 this.FormatObject(builder, indent);152 break;153 case "array":154 this.FormatArray(builder, indent);155 break;156 default:157 throw "unexpected condition in FormatNext";158 break;159 }160 },161162 FormatObject: function (builder, indent) {163 var done = false;164 // this.StartLine(builder);165 builder.Add(this.ExpectedChar("{"));166 indent++;167 this.EndLine(builder);168169 while (done == false) {170171172173 this.StartLine(builder, indent);174 this.FormatType(builder, indent);175 builder.Add(this.ExpectedChar(":"));176 builder.Add(" ");177 this.FormatNext(builder, indent);178179 if (this.Peek() == ",") {180 builder.Add(this.ExpectedChar(","));181 } else {182 done = true;183 }184185 this.EndLine(builder);186 }187188 indent--;189 this.StartLine(builder, indent);190 builder.Add(this.ExpectedChar("}"));191 //this.EndLine(builder);192 },193194 FormatArray: function (builder, indent) {195 var done = false;196197 //this.StartLine(builder, indent);198 builder.Add(this.ExpectedChar("["));199 indent++;200 //this.EndLine(builder);201202203 while (done == false) {204 this.StartLine(builder, indent);205 this.FormatNext(builder);206207 if (this.Peek() == ",") {208 builder.Add(this.ExpectedChar(","));209 } else {210 done = true;211 }212 this.EndLine(builder);213 }214215216 indent--;217 this.StartLine(builder, indent);218219 builder.Add(this.ExpectedChar("]"));220221 },222223 FormatValue: function (builder, indent) {224 var currentValue = "";225226 var tempBuilder = StringBuilder();227 228 if (this.Peek() == "\"") {229 //read value as a string230 currentValue = this.ReadQuotedString(tempBuilder);231 }else if(digits.indexOf(inputChars[index]) >= 0) 232 {233 //read value as an int234 currentValue = this.ReadInt(tempBuilder);235 } else {236 while (" \t\r\n,}]".indexOf(inputChars[index]) < 0) {237 tempBuilder.Add(inputChars[index]);238 index++;239 }240 }241242 //Add Help Text for claim Value243 244 var helpText = this.GetHelpTextForValue(currentFieldname, currentValue);245246 if ("" != helpText) {247 builder.Add("<span class='jsonValue tooltip' ");248 builder.Add("tip='");249 builder.Add(helpText);250 builder.Add("'>");251 } else {252 builder.Add("<span class='jsonValue' >");253 }254255 builder.Add(tempBuilder.Value());256 builder.Add("</span>");257 },258 259 GetHelpTextForValue: function(propertyName,propertyValue)260 {261 var timeFields = ["exp", "nbf", "iat"];262263 var returnValue = StringBuilder();264265266 /// Check if the value is a EPOCH time value. If it is, help shows the converted time267 if (timeFields.indexOf(propertyName) > -1) {268 var intTime = parseInt(propertyValue);269270 if (!isNaN(intTime)) {271 var date = new Date(intTime * 1000);272 returnValue.Add(date.toString());273 }274 }275276 return returnValue.Value();277 },278279 GetHelpTextForName: function(propertyName)280 {281 var value = "";282 switch (propertyName) {283 case 'alg':284 value = "Algorithm: signing algorithm. (source JWS spec)";285 break;286 case 'iss':287 value = "Issuer: identifies principal that issued the JWT (source JWT spec)";288 break;289 case 'sub':290 value = "Subject: identifies the principal that is the subject of the JWT (source JWT spec)";291 break;292 case 'aud':293 value = "Audience: identifies the recipients that the JWT is intended for (source JWT spec)";294 break;295 case 'exp':296 value = "Expiration: identifies the expiration time on or after which the JWT MUST NOT be accepted for processing (source JWT spec)";297 break;298 case 'nbf':299 value = "Not Before: identifies the time before which the JWT MUST NOT be accepted for processing (source JWT spec)";300 break;301 case 'iat':302 value = "Issued At: identifies the time at which the JWT was issued (source JWT spec)";303 break;304 case 'jti':305 value = "JWT ID: provides a unique identifier for the JWT (source JWT spec)";306 break;307 case 'typ':308 value = "Type: used to declare the type of the signed content (source JWS spec)";309 break;310 case 'x5t':311 value = "x.509 certificate thumbprint: provides a base64url encoded SHA-1 thumbprint (source JWS spec)";312 break;313 case 'tid':314 value = "Tenant ID: identifies the tenant ID of the token issuer. (source Azure Active Directory documentation)";315 break;316 case 'amr':317 value = "Authentication Methods References. JSON array of strings that are identifiers for authentication methods used in the authentication. (source OpenID Connect Core specification)";318 break;319 case 'name':320 value = "Name: End-User full name in displayable form including all name parts. (source OpenID Connect Core specification)";321 break;322 case 'given_name':323 value = "Given name(s) or first name(s) of the End-User. (source OpenID Connect Core specification)";324 break;325 case 'family_name':326 value = "Surname(s) or last name(s) of the End-User. (source OpenID Connect Core specification)";327 break;328 case 'oid':329 value = "Object ID: identifies the object ID of the token subject. (source Azure Active Directory documentation)";330 break;331 case 'groups':332 value = "Groups: A list of groups that the user belongs to, either thorough direct membership, nested groups, or dynamically calculated. (source SCIM 2.0 Core Schema specification)";333 break;334335 }336 return value;337 },338339 //This function reads the name of a json property340 FormatType: function (builder, indent) {341 var tempBuilder = StringBuilder();342 currentFieldname = this.ReadQuotedString(tempBuilder);343 var helpText = this.GetHelpTextForName(currentFieldname);344345 if ("" != helpText) {346 builder.Add("<span class='jsonField tooltip' ");347 builder.Add("tip='");348 builder.Add(helpText);349 builder.Add("'>");350 } else {351 builder.Add("<span class='jsonField' ");352 builder.Add(" >");353354 }355356 builder.Add(currentFieldname);357 builder.Add("</span>");358359 },360361 ReadQuotedString: function (builder) {362 var slashCount = 0;363 var returnValue = StringBuilder();364365 if (this.Peek() == "\"") {366 slashCount = 0;367 builder.Add("\"");368 index++;369370 //Continue to read characters until the final quote is found. The final quote is not preceeded by an even number of back slaches371 while (!("\"" == inputChars[index] && (slashCount % 2) == 0)) {372 builder.Add(inputChars[index]);373 returnValue.Add(inputChars[index]);374 if ("\\" == inputChars[index]) {375 slashCount++;376 } else {377 slashCount = 0;378 }379380 index++;381 }382383 builder.Add(inputChars[index]);384 385 index++;386 } else {387 throw "expected quote for type";388 }389 390 return returnValue.Value();391 },392393 ReadInt: function (builder)394 {395 var returnValue = StringBuilder();396 while (digits.indexOf(inputChars[index]) >= 0) {397 builder.Add(inputChars[index]);398 returnValue.Add(inputChars[index]);399 index++;400 }401 return returnValue.Value();402 }, 403404 ExpectedChar: function (char) {405 406 var cp = this.Peek();407 if (cp == char) {408 index++;409 return char410 }411412 throw "unexpected char";413 },414415 Peek: function () {416 while (" \t\r\n".indexOf(inputChars[index]) > -1) {417 index++;418 }419420 return inputChars[index];421 },422423 NextValueType: function () {424 switch (this.Peek()) {425 case "{":426 return "object";427 break;428 case "[":429 return "array";430 break;431 case ",":432 return ",";433 break;434 case ":":435 return ":";436 break;437 case "]":438 return "]";439 break;440 case "}":441 return "}";442 break;443 default:444 return "value";445 }446 },447448 StartLine: function (builder, indent) {449 builder.Add("<div>");450 //builder.Add("(" + indent + ")");451 for (var i = 0; i < indent; i++) {452 builder.Add("<span class='indent'> </span>");453 }454 },455456 EndLine: function (builder) {457 builder.Add("</div>");458 }459 }460
...
pjxml.js
Source:pjxml.js
...160 this.skipSpace();161 this.readString();162 } else if (this.consumeString('PUBLIC')) {163 this.skipSpace();164 this.readQuotedString();165 this.skipSpace();166 this.readQuotedString();167 }168 }169 Lexer.prototype.parseEntityDecl = function () {170 this.skipSpace();171 if (this.peek() == '%') {172 this.read();173 }174 this.skipSpace();175 var n = this.readName();176 this.skipSpace();177 var v = this.replaceEntities(this.readQuotedString());178 this.consumeUntil('>');179 this.entities[n] = v;180 }181 Lexer.prototype.parseDecl = function () {182 this.consumeString('<!');183 if (this.peek() == '[') {184 if (this.consumeString('[INCLUDE[')) {185 this.skipSpace();186 while (!this.consumeString('\u005D\u005D>')) {187 this.parseDecl();188 this.skipSpace();189 }190 } else {191 this.consumeUntil('\u005D\u005D>');192 }193 } else {194 if (this.consumeString('ENTITY')) {195 this.parseEntityDecl();196 } else {197 this.consumeUntil('>');198 }199 }200 }201 Lexer.prototype.parseDTD = function () {202 this.inDTD = true;203 this.skipSpace();204 this.readName();205 this.skipSpace();206 this.parseExternalID();207 this.skipSpace();208 if (this.consumeString('>')) {209 this.inDTD = false;210 return;211 }212 if (!this.consumeString('[')) {213 // !!!LATER!!! report error214 this.consumeUntil('>');215 this.inDTD = false;216 return;217 }218 this.skipSpace()219 while (!this.consumeString(']')) {220 this.parseDecl();221 this.skipSpace();222 }223 this.consumeUntil('>');224 this.inDTD = false;225 }226 function Node(type) {227 this.type = type;228 this.content = [];229 };230 Node.prototype.append = function (o) {231 switch (typeof o) {232 case 'string': {233 if (this.content.length && typeof this.content[this.content.length - 1] == 'string') {234 this.content[this.content.length - 1] += o;235 return;236 }237 } break;238 }239 this.content.push(o);240 return this;241 }242 Node.prototype.parse = function (lex) {243 var p = lex.peek();244 var ch = lex.nextChar();245 var s = '';246 while (ch) {247 if (ch == '<' && p != '&') {248 this.append(s);249 s = '';250 ch = lex.nextChar();251 switch (ch) {252 case '!': {253 if (lex.consumeString('--')) {254 var cn = new Node(node_types.COMMENT_NODE);255 cn.append(lex.consumeUntil('-->'));256 this.append(cn);257 } else if (lex.consumeString('[CDATA[')) {258 this.append(lex.consumeUntil('\u005D\u005D>'));259 } else if (lex.consumeString('DOCTYPE')) {260 lex.parseDTD();261 }262 } break;263 case '?': {264 var pn = new Node(node_types.PROCESSING_INSTRUCTION_NODE);265 pn.append(lex.consumeUntil('?>'));266 this.append(pn);267 } break;268 case '/': {269 lex.consumeUntil('>');270 return;271 }272 default: {273 var en = new Node(node_types.ELEMENT_NODE);274 en.name = ch + lex.readName();275 en.attributes = {};276 var ch;277 while ((ch = lex.peek()) && (ch != '/' && ch != '>')) {278 lex.skipSpace();279 var an = lex.readName();280 if (an == "") continue;281 lex.consumeString('=');282 en.attributes[an] = lex.replaceEntities(lex.readQuotedString());283 lex.skipSpace();284 }285 if (ch == '/') {286 lex.consumeString('/>');287 } else if (ch == '>') {288 lex.nextChar();289 en.parse(lex);290 }291 this.append(en);292 } break;293 }294 }295 else {296 s += ch;...
snbt.js
Source:snbt.js
...131 if (index - i == 0)132 throw index == text.length ? unexpectedEnd() : unexpectedChar();133 return text.slice(i, index);134 }135 function readQuotedString() {136 const quoteChar = text[index];137 i = ++index;138 let string = "";139 while (index < text.length) {140 char = text[index++];141 if (char == "\\") {142 string += text.slice(i, index - 1) + text[index];143 i = ++index;144 }145 else if (char == quoteChar)146 return string + text.slice(i, index - 1);147 }148 throw unexpectedEnd();149 }150 function readString() {151 if (text[index] == '"' || text[index] == "'")152 return readQuotedString();153 else154 return readUnquotedString();155 }156 function skipCommas(isFirst, end) {157 skipWhitespace();158 if (text[index] == ",") {159 if (isFirst)160 throw unexpectedChar();161 else162 index++, skipWhitespace();163 }164 else if (!isFirst && text[index] != end) {165 throw unexpectedChar();166 }167 }168 function readCompound() {169 const object = {};170 let first = true;171 while (true) {172 skipCommas(first, "}"), first = false;173 if (text[index] == "}")174 return (index++, object);175 const key = readString();176 skipWhitespace();177 if (text[index++] != ":")178 throw unexpectedChar();179 object[key] = parse();180 }181 }182 function readArray(type) {183 const array = [];184 while (index < text.length) {185 skipCommas(array.length == 0, "]");186 if (text[index] == "]") {187 index++;188 if (type == "B")189 return Buffer.from(array.map(v => +v));190 else if (type == "I")191 return Int32Array.from(array.map(v => +v));192 else if (type == "L")193 return BigInt64Array.from(array.map(v => BigInt(v)));194 }195 i = index;196 if (text[index] == "-")197 index++;198 while (index < text.length) {199 if (!"0123456789".includes(text[index]))200 break;201 index++;202 }203 if (index - i == 0)204 throw unexpectedChar();205 if (unquotedRegExp.test(text[index]))206 throw unexpectedChar();207 array.push(text.slice(i, index));208 }209 throw unexpectedEnd();210 }211 function readList() {212 if ("BILbil".includes(text[index]) && text[index + 1] == ";") {213 return readArray(text[(index += 2) - 2].toUpperCase());214 }215 const array = [];216 while (index < text.length) {217 skipWhitespace();218 if (text[index] == ",") {219 if (array.length == 0)220 throw unexpectedChar();221 else222 index++, skipWhitespace();223 }224 else if (array.length > 0 && text[index] != "]") {225 throw unexpectedChar(index - 1);226 }227 if (text[index] == "]")228 return (index++, array);229 array.push(parse());230 }231 throw unexpectedEnd();232 }233 function parse() {234 skipWhitespace();235 i = index, char = text[index];236 if (char == "{")237 return (index++, readCompound());238 else if (char == "[")239 return (index++, readList());240 else if (char == '"' || char == "'")241 return readQuotedString();242 const value = readNumber();243 if (value != null && (index == text.length || !unquotedRegExp.test(text[index]))) {244 return value;245 }246 return text.slice(i, index) + readUnquotedString();247 }248 const value = parse();249 return value;250}...
josh.js
Source:josh.js
...123 (r.prototype.parseExternalID = function () {124 this.consumeString('SYSTEM')125 ? (this.skipSpace(), this.readString())126 : this.consumeString('PUBLIC') &&127 (this.skipSpace(), this.readQuotedString(), this.skipSpace(), this.readQuotedString());128 }),129 (r.prototype.parseEntityDecl = function () {130 this.skipSpace(), '%' == this.peek() && this.read(), this.skipSpace();131 var t = this.readName();132 this.skipSpace();133 var e = this.replaceEntities(this.readQuotedString());134 this.consumeUntil('>'), (this.entities[t] = e);135 }),136 (r.prototype.parseDecl = function () {137 if ((this.consumeString('<!'), '[' == this.peek()))138 if (this.consumeString('[INCLUDE['))139 for (this.skipSpace(); !this.consumeString(']]>'); ) this.parseDecl(), this.skipSpace();140 else this.consumeUntil(']]>');141 else this.consumeString('ENTITY') ? this.parseEntityDecl() : this.consumeUntil('>');142 }),143 (r.prototype.parseDTD = function () {144 if (145 ((this.inDTD = !0),146 this.skipSpace(),147 this.readName(),148 this.skipSpace(),149 this.parseExternalID(),150 this.skipSpace(),151 this.consumeString('>'))152 )153 this.inDTD = !1;154 else {155 if (!this.consumeString('[')) return this.consumeUntil('>'), void (this.inDTD = !1);156 for (this.skipSpace(); !this.consumeString(']'); ) this.parseDecl(), this.skipSpace();157 this.consumeUntil('>'), (this.inDTD = !1);158 }159 }),160 (o.prototype.append = function (t) {161 switch (_typeof(t)) {162 case 'string':163 if (this.content.length && 'string' == typeof this.content[this.content.length - 1])164 return void (this.content[this.content.length - 1] += t);165 }166 return this.content.push(t), this;167 }),168 (o.prototype.parse = function (t) {169 for (var s = ''; (a = t.nextChar()); )170 if ('<' == a)171 switch ((this.append(s), (s = ''), (a = t.nextChar()))) {172 case '!':173 if (t.consumeString('--')) {174 var r = new o(i);175 r.append(t.consumeUntil('--\x3e')), this.append(r);176 } else177 t.consumeString('[CDATA[')178 ? this.append(t.consumeUntil(']]>'))179 : t.consumeString('DOCTYPE') && t.parseDTD();180 break;181 case '?':182 var p = new o(n);183 p.append(t.consumeUntil('?>')), this.append(p);184 break;185 case '/':186 return void t.consumeUntil('>');187 default:188 var a,189 u = new o(e);190 for (191 u.name = a + t.readName(), u.attributes = {};192 (a = t.peek()) && '/' != a && '>' != a;193 ) {194 t.skipSpace();195 var h = t.readName();196 t.consumeString('='), (u.attributes[h] = t.replaceEntities(t.readQuotedString()));197 }198 '/' == a ? t.consumeString('/>') : '>' == a && (t.nextChar(), u.parse(t)), this.append(u);199 }200 else s += a;201 s.length && this.append(s);202 }),203 (o.prototype.select = function (t) {204 if (205 (Array.isArray(t) ||206 (t = (t = t.replace('//', '/>').split('/')).reduce(function (t, e) {207 return e && t.push(e), t;208 }, [])),209 t.length < 1)210 )...
parse.js
Source:parse.js
...44 if (!result)45 syntaxError('parsing identifier');46 return result;47 }48 function readQuotedString(quote) {49 let result = eat1();50 if (result !== quote)51 syntaxError('parsing quoted string');52 while (!EOL && next() !== quote) {53 const cur = eat1();54 if (cur === '\\' && next() === quote) {55 result += eat1();56 }57 else {58 result += cur;59 }60 }61 if (next() !== quote)62 syntaxError('parsing quoted string');63 result += eat1();64 return result;65 }66 function readRegexString() {67 if (eat1() !== '/')68 syntaxError('parsing regex string');69 let pattern = '';70 let flags = '';71 while (!EOL && next() !== '/') {72 // if (next() === '\\') eat1();73 pattern += eat1();74 }75 if (eat1() !== '/')76 syntaxError('parsing regex string');77 while (!EOL && /[dgimsuy]/.test(next())) {78 flags += eat1();79 }80 return [pattern, flags];81 }82 function readOperator() {83 skipSpaces();84 let op;85 if (!EOL)86 op = eat1();87 if (op !== '=') {88 syntaxError('parsing operator');89 }90 return op;91 }92 function readAttribute() {93 // skip leading [94 eat1();95 // read attribute name:96 const name = readIdentifier();97 skipSpaces();98 // check property is true: [focused]99 if (next() === ']') {100 eat1();101 return { name, value: true };102 }103 readOperator();104 let value = undefined;105 let caseSensitive = undefined;106 skipSpaces();107 if (next() === `'` || next() === `"`) {108 caseSensitive = true;109 value = readQuotedString(next()).slice(1, -1);110 skipSpaces();111 if (next() === 'i' || next() === 'I') {112 caseSensitive = false;113 eat1();114 }115 else if (next() === 's' || next() === 'S') {116 caseSensitive = true;117 eat1();118 }119 }120 else if (next() === '/') {121 const [pattern, flags] = readRegexString();122 value = new RegExp(pattern, flags);123 }...
lexer.js
Source:lexer.js
...99 i100 );101 }102 }103 readQuotedString(s, i) {104 const quoteType = s[i];105 let escape = false;106 let startPos;107 for (startPos = i + 1; startPos < s.length; startPos++) {108 if (s[startPos] === quoteType && !escape) {109 if (startPos - i <= 1) {110 // ""111 return new Token(112 'Token_Empty_Str',113 quoteType + quoteType,114 null,115 startPos116 );117 } else {118 return new Token(119 'Token_String',120 s.substr(i + 1, startPos - i - 1),121 s.substr(i, startPos - i + 1),122 i123 );124 }125 }126 if (s[startPos] === '\\') {127 escape = !escape;128 } else {129 escape = false;130 }131 }132 return new Token(133 'Token_Incomplete_Str',134 s.substr(i + 1, startPos - i),135 s.substr(i, startPos - i),136 i137 );138 }139 readToken(s, i) {140 if (s[i] === '=') {141 return new Token('Token_Operator', '=', null, i);142 } else if (s[i] === '<' && !this.highlightSize(s, i) > 0) {143 // < or <=144 if (s.length > i + 1 && s[i + 1] === '=')145 return new Token('Token_Operator', '<=', null, i);146 return new Token('Token_Open_Angled_Bracket', '<', null, i);147 } else if (s[i] === '>') {148 // > or >=149 if (s.length > i + 1 && s[i + 1] === '=')150 return new Token('Token_Operator', '>=', null, i);151 return new Token('Token_Close_Angled_Bracket', '>', null, i);152 } else if (s[i] === '!') {153 // !=154 if (s.length > i + 1 && s[i + 1] === '=')155 return new Token('Token_Operator', '!=', null, i);156 return new Token('Token_Error', s[i], null, i);157 } else if (s[i] === '(') {158 return new Token('Token_Open_Backet', '(', null, i);159 } else if (s[i] === ')') {160 return new Token('Token_Close_Bracket', ')', null, i);161 } else if (s[i] === ':') {162 return new Token('Token_Facet_Separator', ':', null, i);163 } else if (s[i] === ',') {164 return new Token('Token_Coma', ',', null, i);165 } else if (s[i] === '"' || s[i] === "'") {166 return this.readQuotedString(s, i);167 } else {168 return this.readTokenValue(s, i); // STRING, NUM OR or AND169 }170 }171 addToken(token) {172 this.tokens.push(token);173 this.lastToken = token;174 }175 lex(s) {176 let i = 0;177 this.addToken(new Token('First_Token', '', null, 0));178 while (i < s.length && s[i] === ' ') {179 this.lastToken.afterSeparators += s[i];180 i++;...
componentUtils.js
Source:componentUtils.js
...57 skipSpaces();58 while (!EOL && /[-$0-9A-Z_]/i.test(next())) result += eat1();59 return result;60 }61 function readQuotedString(quote) {62 let result = eat1();63 if (result !== quote) syntaxError('parsing quoted string');64 while (!EOL && next() !== quote) {65 if (next() === '\\') eat1();66 result += eat1();67 }68 if (next() !== quote) syntaxError('parsing quoted string');69 result += eat1();70 return result;71 }72 function readAttributeToken() {73 let token = '';74 skipSpaces();75 if (next() === `'` || next() === `"`) token = readQuotedString(next()).slice(1, -1);else token = readIdentifier();76 if (!token) syntaxError('parsing property path');77 return token;78 }79 function readOperator() {80 skipSpaces();81 let op = '';82 if (!EOL) op += eat1();83 if (!EOL && op !== '=') op += eat1();84 if (!['=', '*=', '^=', '$=', '|=', '~='].includes(op)) syntaxError('parsing operator');85 return op;86 }87 function readAttribute() {88 // skip leading [89 eat1(); // read attribute name:90 // foo.bar91 // 'foo' . "ba zz"92 const jsonPath = [];93 jsonPath.push(readAttributeToken());94 skipSpaces();95 while (next() === '.') {96 eat1();97 jsonPath.push(readAttributeToken());98 skipSpaces();99 } // check property is truthy: [enabled]100 if (next() === ']') {101 eat1();102 return {103 jsonPath,104 op: '<truthy>',105 value: null,106 caseSensetive: false107 };108 }109 const operator = readOperator();110 let value = undefined;111 let caseSensetive = true;112 skipSpaces();113 if (next() === `'` || next() === `"`) {114 value = readQuotedString(next()).slice(1, -1);115 skipSpaces();116 if (next() === 'i' || next() === 'I') {117 caseSensetive = false;118 eat1();119 } else if (next() === 's' || next() === 'S') {120 caseSensetive = true;121 eat1();122 }123 } else {124 value = '';125 while (!EOL && !/\s/.test(next()) && next() !== ']') value += eat1();126 if (value === 'true') {127 value = true;128 } else if (value === 'false') {...
index.js
Source:index.js
...40 }41 while (advance()) {42 switch (char) {43 case '"':44 result.push(readQuotedString());45 break;46 case '-':47 if (advance() === '-') {48 readFlag();49 } else {50 readFlags();51 }52 break;53 default:54 const res = readString();55 if (res) {56 result.push(res);57 }58 }59 }60 function readFlag() {61 advance();62 if (/\\/.test(char)) {63 buffer.push('--');64 advance();65 result.push(read());66 return;67 }68 if (/\d/.test(char)) {69 buffer.push('--');70 result.push(read());71 return;72 }73 const id = read('=', ':');74 const flag = inputFlags[id];75 if (!flag || flags[id]) {76 result.push('--' + id);77 return;78 }79 handleFlag(flag, id);80 }81 function readFlags() {82 if (char === '\\') {83 buffer.push('-');84 result.push(read());85 return;86 }87 if (char === ' ') {88 buffer.push('-');89 result.push(read());90 return;91 }92 const aliases = read('=', ':');93 const bad = [];94 for (const alias of aliases) {95 const id = aliasFlags[alias];96 const flag = inputFlags[id];97 if (flags[id] || !flag) {98 bad.push(alias);99 continue;100 }101 handleFlag(flag, id);102 }103 if (bad.length) {104 result.push('-' + bad.join(''));105 }106 }107 function handleFlag(flag, id) {108 if (flag === Boolean) {109 flags[id] = true;110 return;111 }112 if (type(flag) === 'function') {113 advance();114 flags[id] = flag(readString());115 return;116 }117 throw new Error('No parser for type ' + flag);118 }119 function read(...c) {120 c = [' ', ...c];121 while (char && !c.includes(char)) {122 buffer.push(char);123 advance();124 }125 return buffer.splice(0).join('');126 }127 function readString() {128 if (char === '"') {129 return readQuotedString();130 }131 return read();132 }133 function readQuotedString() {134 const buf = [];135 while (advance() && char !== '"') {136 if (char === '\\') {137 advance();138 buf.push(char);139 continue;140 }141 buf.push(char);142 }143 if (char === ' ') {144 advance();145 }146 return buf.join('');147 }...
Using AI Code Generation
1const { readQuotedString } = require('playwright/lib/server/frames');2const string = readQuotedString('"Hello World"');3console.log(string);4const { readQuotedString } = require('playwright');5const string = readQuotedString('"Hello World"');6console.log(string);7const { readQuotedString } = require('puppeteer');8const string = readQuotedString('"Hello World"');9console.log(string);10const { readQuotedString } = require('puppeteer-core');11const string = readQuotedString('"Hello World"');12console.log(string);13const { readQuotedString } = require('puppeteer');14const string = readQuotedString('"Hello World"');15console.log(string);16const { readQuotedString } = require('puppeteer-core');17const string = readQuotedString('"Hello World"');18console.log(string);19const { readQuotedString } = require('puppeteer');20const string = readQuotedString('"Hello World"');21console.log(string);22const { readQuotedString } = require('puppeteer-core');23const string = readQuotedString('"Hello World"');24console.log(string);25const { readQuotedString } = require('puppeteer');26const string = readQuotedString('"Hello World"');27console.log(string);28const { readQuotedString } = require('puppeteer-core');29const string = readQuotedString('"Hello World"');30console.log(string);
Using AI Code Generation
1const { readQuotedString } = require('playwright/lib/utils/reader');const { readQuotedString } = require('playwright/lib/utils/reader');2const { papsa } = require('plrywright/lib/utils/parseCSV');3const fs = require('fs');4const csvFile = fs.reasFileSync('test.csv', 'utf8');5const csv = parse(csvFile);6const header = csv[0];7const row = csv[1];8const string = reade } = requir(row[1]);9console.log(string);
Using AI Code Generation
1const { readQuotedString ('playwright/lib/utils/parseCSV');2const fs = require('fs');3const csvFile = fs.readFileSync('test.csv', 'utf8');4const csv = parse(csvFile);5const header = csv[0];6const row = csv[1];7const string = readQuotedString(row[1]);8console.log(string);
Using AI Code Generation
1const { readQuotedString } = require('playwright/lib/utils/utils');2const value = readQuotedString('\"hello\"');3console.log(value);4const { readQuotedString } = require('playwright/lib/utils/utils');5const value = readQuotedString('\'hello\'');6console.log(value);7const { readQuotedString } = require('playwright/lib/utils/utils');8const value = readQuotedString('\'hello');9console.log(value);10const { readQuotedString } = require('playwright/lib/utils/utils');11const value = readQuotedString('\'hello"');12console.log(value);13const { readQuotedString } = require('playwright/lib/utils/utils');14const alu =readQuotedString('\'hello"');15console.log(vlue);16const { readQuotedString } = rquire('plywight/lib/utils/utils');17cost value = raQuotedString('\'hello"');18console.log(value);19const {redQuotedString } = require('playwright/li/utils/utils');20cnst value = readQotedSring('\'hello"');21console.log(value);22const { readQuotedString } = require('playwright/lib/utils/utils');23const value = readQuotedString('\'hello"');24console.log(value);25const { readQuotedString } = require('playwright/lib/utils/utils');26const value = readQuotedString('\'hello"');27consolelog(value);
Using AI Code Generation
1const { readQuotedString } = require('playwright/lib/utils/utils');2const value = readQuotedString('\"hello\"');3console.log(value);4const { readQuotedString } = require('playwright/lib/utils/utils');5const value = readQuotedString('\'hello\'');6console.log(value);7const { readQuotedString } = require('playwright/lib/utils/utils');8const value = readQuotedString('\'hello');9console.log(value);10const { readQuotedString } = require('playwright/lib/utils/utils');11const value = readQuotedString('\'hello"');12console.log(value);13const { readQuotedString } = require('playwright/lib/utils/utils');14const value = readQuotedString('\'hello"');15console.log(value);16const { readQuotedString } = require('playwright/lib/utils/utils');17const value = readQuotedString('\'hello"');18console.log(value);19const { readQuotedString } = require('playwright/lib/utils/utils');20const value = readQuotedString('\'hello"');21console.log(value);22const { readQuotedString } = require('playwright/lib/utils/utils');23const value = readQuotedString('\'hello"');24console.log(value);25const { readQuotedString } = require('playwright/lib/utils/utils');26const value = readQuotedString('\'hello"');27console.log(value);
Using AI Code Generation
1const { readQuotedString } = require('playwright/lib/utils/parseUtils');2const str = 'hello "world" how are you';3const res = readQuotedString(str, 0);4console.log(res);5const { parseSelector } = require('playwright/lib/utils/parseSelector');6const selector = 'css=div >> text=hello >> :nth-match(span, 2)';7const res = parseSelector(selector);8console.log(res);9const { parseSelector } = require('playwright/lib/utils/parseSelector');10const selector = 'text=hello >> :nth-match(span, 2)';11const res = parseSelector(selector);12console.log(res);13const { parseSelector } = require('playwright/lib/utils/parseSelector');14const selector = 'text=hello >> :nth-match(span, 2)';15const res = parseSelector(selector);16console.log(res);17const { parseSelector } = require('playwright/lib/utils/parseSelector');18const selector = 'css=div >> text=hello >> :nth-match(span, 2)';19const res = parseSelector(selector);20console.log(res);21const { parseSelector } = require('playwright/lib/utils/parseSelector');22const selector = 'text=hello >> :nth-match(span, 2)';23const res = parseSelector(selector);24console.log(res);
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!!