Best JavaScript code snippet using playwright-internal
parc-parser_step3.js
Source:parc-parser_step3.js  
...564							if (!(collect(match("\n"), result))) {565								return false;566							}567						568					return [{type: "lb", value: joinTokens(result)}];569					570					571				}572			573				function parse_openbracket() {574					let result = [];575					576							if (!(collect(matchChars(/[{(]/), result))) {577								return false;578							}579						580					return result;581					582					583				}584			585				function parse_closebracket() {586					let result = [];587					588							if (!(collect(matchChars(/[})]/), result))) {589								return false;590							}591						592					return result;593					594					595				}596			597				function parse_token() {598					let result = [];599					600							if (!(collect(parse_specialsyntax(), result))) {601								602							if (!(collect(parse_string(), result))) {603								604							if (!(collect(parse_chars(), result))) {605								606							if (!(collect(parse_name(), result))) {607								return false;608							}609						610							}611						612							}613						614							}615						616					return result;617					618					619				}620			621				function parse_specialsyntax() {622					let result = [];623					624							if (!(collect(parse_arrow(), result))) {625								626							if (!(collect(parse_equals(), result))) {627								628							if (!(collect(parse_star(), result))) {629								630							if (!(collect(parse_plus(), result))) {631								632							if (!(collect(parse_question(), result))) {633								634							if (!(collect(parse_dot(), result))) {635								636							if (!(collect(matchChars(/[\/>!]/), result))) {637								return false;638							}639						640							}641						642							}643						644							}645						646							}647						648							}649						650							}651						652					return result;653					654					655				}656			657				function parse_arrow() {658					let result = [];659					660							if (!(collect(match("=>"), result))) {661								return false;662							}663						664					return [{type: "arrow", value: joinTokens(result)}];665					666					667				}668			669				function parse_equals() {670					let result = [];671					672							673						if (collect(match("="), result)) {674							while(collect(match("="), result)) {};675							676							677						} else678					 {679								return false;680							}681						682					return [{type: "equals", value: joinTokens(result)}];683					684					685				}686			687				function parse_star() {688					let result = [];689					690							if (!(collect(match("*"), result))) {691								return false;692							}693						694					return [{type: "star", value: joinTokens(result)}];695					696					697				}698			699				function parse_plus() {700					let result = [];701					702							if (!(collect(match("+"), result))) {703								return false;704							}705						706					return [{type: "plus", value: joinTokens(result)}];707					708					709				}710			711				function parse_question() {712					let result = [];713					714							if (!(collect(match("?"), result))) {715								return false;716							}717						718					return [{type: "question", value: joinTokens(result)}];719					720					721				}722			723				function parse_dot() {724					let result = [];725					726							if (!(collect(match("."), result))) {727								return false;728							}729						730					return [{type: "dot", value: joinTokens(result)}];731					732					733				}734			735				function parse_name() {736					let result = [];737					738							739						if (collect(matchChars(/[a-zA-Z_]/), result)) {740							741							742							collect(parse_nametail(), result)743						} else744					 {745								return false;746							}747						748					return [{type: "name", value: joinTokens(result)}];749					750					751				}752			753				function parse_nametail() {754					let result = [];755					756							757						if (collect(matchChars(/[a-zA-Z0-9_]/), result)) {758							while(collect(matchChars(/[a-zA-Z0-9_]/), result)) {};759							760							761						} else762					 {763								return false;764							}765						766					return [{type: "nametail", value: joinTokens(result)}];767					768					769				}770			771				function parse_string() {772					let result = [];773					774							775						if (collect(match("\""), result)) {776							777							778							while (collect(parse_stritem(), result)) {};779							if (!(collect(match("\""), result))) {780								badSyntax();781							}782						783						} else784					 {785								return false;786							}787						788					return [{type: "string", value: joinTokens(result)}];789					790					791				}792			793				function parse_stritem() {794					let result = [];795					796							797						if (collect(match("\\"), result)) {798							799							800							801							if (!(collect(matchAny(), result))) {802								badSyntax();803							}804						805						} else806					 {807								808							if (!(collect(matchChars(/[^"]/), result))) {809								return false;810							}811						812							}813						814					return [{type: "stritem", value: joinTokens(result)}];815					816					817				}818			819				function parse_chars() {820					let result = [];821					822							823						if (collect(match("["), result)) {824							825							826							while (collect(parse_charsitem(), result)) {};827							if (!(collect(match("]"), result))) {828								badSyntax();829							}830						831						} else832					 {833								return false;834							}835						836					return [{type: "chars", value: joinTokens(result)}];837					838					839				}840			841				function parse_charsitem() {842					let result = [];843					844							845						if (collect(match("\\"), result)) {846							847							848							849							if (!(collect(matchAny(), result))) {850								badSyntax();851							}852						853						} else854					 {855								856							if (!(collect(matchChars(/[^\]]/), result))) {857								return false;858							}859						860							}861						862					return [{type: "charsitem", value: joinTokens(result)}];863					864					865				}866			867				868				869				function joinTokens(tokens) {870					return tokens.map(t => t.value).join("");871				}872				873				function match(str) {874					if (text.substring(i, i + str.length) === str) {875						i += str.length;876						return {type: str, value: str};877					}878					return false;879				}880				881				function matchChars(re) {882					if (i < text.length && re.test(text[i])) {883						return {type: text[i], value: text[i++]};...parc-parser_step4.js
Source:parc-parser_step4.js  
...543							if (!(collect(match("\n"), result))) {544								return false;545							}546						547					return [{type: "lb", value: joinTokens(result)}];548					549					550				}551			552				function parse_openbracket() {553					let result = [];554					555							if (!(collect(matchChars(/[{(]/), result))) {556								return false;557							}558						559					return result;560					561					562				}563			564				function parse_closebracket() {565					let result = [];566					567							if (!(collect(matchChars(/[})]/), result))) {568								return false;569							}570						571					return result;572					573					574				}575			576				function parse_token() {577					let result = [];578					579							if (!(collect(parse_specialsyntax(), result))) {580								581							if (!(collect(parse_string(), result))) {582								583							if (!(collect(parse_chars(), result))) {584								585							if (!(collect(parse_name(), result))) {586								return false;587							}588						589							}590						591							}592						593							}594						595					return result;596					597					598				}599			600				function parse_specialsyntax() {601					let result = [];602					603							if (!(collect(parse_arrow(), result))) {604								605							if (!(collect(parse_equals(), result))) {606								607							if (!(collect(parse_star(), result))) {608								609							if (!(collect(parse_plus(), result))) {610								611							if (!(collect(parse_question(), result))) {612								613							if (!(collect(parse_dot(), result))) {614								615							if (!(collect(matchChars(/[\/>!]/), result))) {616								return false;617							}618						619							}620						621							}622						623							}624						625							}626						627							}628						629							}630						631					return result;632					633					634				}635			636				function parse_arrow() {637					let result = [];638					639							if (!(collect(match("=>"), result))) {640								return false;641							}642						643					return [{type: "arrow", value: joinTokens(result)}];644					645					646				}647			648				function parse_equals() {649					let result = [];650					651							652						if (collect(match("="), result)) {653							while(collect(match("="), result)) {};654							655						} else656					 {657								return false;658							}659						660					return [{type: "equals", value: joinTokens(result)}];661					662					663				}664			665				function parse_star() {666					let result = [];667					668							if (!(collect(match("*"), result))) {669								return false;670							}671						672					return [{type: "star", value: joinTokens(result)}];673					674					675				}676			677				function parse_plus() {678					let result = [];679					680							if (!(collect(match("+"), result))) {681								return false;682							}683						684					return [{type: "plus", value: joinTokens(result)}];685					686					687				}688			689				function parse_question() {690					let result = [];691					692							if (!(collect(match("?"), result))) {693								return false;694							}695						696					return [{type: "question", value: joinTokens(result)}];697					698					699				}700			701				function parse_dot() {702					let result = [];703					704							if (!(collect(match("."), result))) {705								return false;706							}707						708					return [{type: "dot", value: joinTokens(result)}];709					710					711				}712			713				function parse_name() {714					let result = [];715					716							717						if (collect(matchChars(/[a-zA-Z_]/), result)) {718							719							collect(parse_nametail(), result)720						} else721					 {722								return false;723							}724						725					return [{type: "name", value: joinTokens(result)}];726					727					728				}729			730				function parse_nametail() {731					let result = [];732					733							734						if (collect(matchChars(/[a-zA-Z0-9_]/), result)) {735							while(collect(matchChars(/[a-zA-Z0-9_]/), result)) {};736							737						} else738					 {739								return false;740							}741						742					return [{type: "nametail", value: joinTokens(result)}];743					744					745				}746			747				function parse_string() {748					let result = [];749					750							751						if (collect(match("\""), result)) {752							753							while (collect(parse_stritem(), result)) {};754							if (!(collect(match("\""), result))) {755								badSyntax();756							}757						758						} else759					 {760								return false;761							}762						763					return [{type: "string", value: joinTokens(result)}];764					765					766				}767			768				function parse_stritem() {769					let result = [];770					771							772						if (collect(match("\\"), result)) {773							774							775							if (!(collect(matchAny(), result))) {776								badSyntax();777							}778						779						} else780					 {781								782							if (!(collect(matchChars(/[^"]/), result))) {783								return false;784							}785						786							}787						788					return [{type: "stritem", value: joinTokens(result)}];789					790					791				}792			793				function parse_chars() {794					let result = [];795					796							797						if (collect(match("["), result)) {798							799							while (collect(parse_charsitem(), result)) {};800							if (!(collect(match("]"), result))) {801								badSyntax();802							}803						804						} else805					 {806								return false;807							}808						809					return [{type: "chars", value: joinTokens(result)}];810					811					812				}813			814				function parse_charsitem() {815					let result = [];816					817							818						if (collect(match("\\"), result)) {819							820							821							if (!(collect(matchAny(), result))) {822								badSyntax();823							}824						825						} else826					 {827								828							if (!(collect(matchChars(/[^\]]/), result))) {829								return false;830							}831						832							}833						834					return [{type: "charsitem", value: joinTokens(result)}];835					836					837				}838			839				840				841				function joinTokens(tokens) {842					return tokens.map(t => t.value).join("");843				}844				845				function match(str) {846					if (text.substring(i, i + str.length) === str) {847						i += str.length;848						return {type: str, value: str};849					}850					return false;851				}852				853				function matchChars(re) {854					if (i < text.length && re.test(text[i])) {855						return {type: text[i], value: text[i++]};...parc-parser_step2.js
Source:parc-parser_step2.js  
...482							if (!(collect(match("\n"), result))) {483								return false;484							}485						486					return [{type: "lb", value: joinTokens(result)}];487					488					489				}490			491				function parse_openbracket() {492					let result = [];493					494							if (!(collect(matchChars(/[{(]/), result))) {495								return false;496							}497						498					return result;499					500					501				}502			503				function parse_closebracket() {504					let result = [];505					506							if (!(collect(matchChars(/[})]/), result))) {507								return false;508							}509						510					return result;511					512					513				}514			515				function parse_token() {516					let result = [];517					518							if (!(collect(parse_specialsyntax(), result))) {519								520							if (!(collect(parse_string(), result))) {521								522							if (!(collect(parse_chars(), result))) {523								524							if (!(collect(parse_name(), result))) {525								return false;526							}527						528							}529						530							}531						532							}533						534					return result;535					536					537				}538			539				function parse_specialsyntax() {540					let result = [];541					542							if (!(collect(parse_arrow(), result))) {543								544							if (!(collect(parse_equals(), result))) {545								546							if (!(collect(parse_star(), result))) {547								548							if (!(collect(parse_plus(), result))) {549								550							if (!(collect(parse_question(), result))) {551								552							if (!(collect(parse_dot(), result))) {553								554							if (!(collect(matchChars(/[\/>]/), result))) {555								return false;556							}557						558							}559						560							}561						562							}563						564							}565						566							}567						568							}569						570					return result;571					572					573				}574			575				function parse_arrow() {576					let result = [];577					578							if (!(collect(match("=>"), result))) {579								return false;580							}581						582					return [{type: "arrow", value: joinTokens(result)}];583					584					585				}586			587				function parse_equals() {588					let result = [];589					590							591						if (collect(match("="), result)) {592							while(collect(match("="), result)) {};593							594							595						} else596					 {597								return false;598							}599						600					return [{type: "equals", value: joinTokens(result)}];601					602					603				}604			605				function parse_star() {606					let result = [];607					608							if (!(collect(match("*"), result))) {609								return false;610							}611						612					return [{type: "star", value: joinTokens(result)}];613					614					615				}616			617				function parse_plus() {618					let result = [];619					620							if (!(collect(match("+"), result))) {621								return false;622							}623						624					return [{type: "plus", value: joinTokens(result)}];625					626					627				}628			629				function parse_question() {630					let result = [];631					632							if (!(collect(match("?"), result))) {633								return false;634							}635						636					return [{type: "question", value: joinTokens(result)}];637					638					639				}640			641				function parse_dot() {642					let result = [];643					644							if (!(collect(match("."), result))) {645								return false;646							}647						648					return [{type: "dot", value: joinTokens(result)}];649					650					651				}652			653				function parse_name() {654					let result = [];655					656							657						if (collect(matchChars(/[a-zA-Z_]/), result)) {658							659							collect(parse_nametail(), result)660							661						} else662					 {663								return false;664							}665						666					return [{type: "name", value: joinTokens(result)}];667					668					669				}670			671				function parse_nametail() {672					let result = [];673					674							675						if (collect(matchChars(/[a-zA-Z0-9_]/), result)) {676							while(collect(matchChars(/[a-zA-Z0-9_]/), result)) {};677							678							679						} else680					 {681								return false;682							}683						684					return [{type: "nametail", value: joinTokens(result)}];685					686					687				}688			689				function parse_string() {690					let result = [];691					692							693						if (collect(match("\""), result)) {694							695							696							while (collect(parse_stritem(), result)) {};697							if (!(collect(match("\""), result))) {698								badSyntax();699							}700						701						} else702					 {703								return false;704							}705						706					return [{type: "string", value: joinTokens(result)}];707					708					709				}710			711				function parse_stritem() {712					let result = [];713					714							715						if (collect(match("\\"), result)) {716							717							718							719							if (!(collect(matchAny(), result))) {720								badSyntax();721							}722						723						} else724					 {725								726							if (!(collect(matchChars(/[^"]/), result))) {727								return false;728							}729						730							}731						732					return [{type: "stritem", value: joinTokens(result)}];733					734					735				}736			737				function parse_chars() {738					let result = [];739					740							741						if (collect(match("["), result)) {742							743							744							while (collect(parse_charsitem(), result)) {};745							if (!(collect(match("]"), result))) {746								badSyntax();747							}748						749						} else750					 {751								return false;752							}753						754					return [{type: "chars", value: joinTokens(result)}];755					756					757				}758			759				function parse_charsitem() {760					let result = [];761					762							763						if (collect(match("\\"), result)) {764							765							766							767							if (!(collect(matchAny(), result))) {768								badSyntax();769							}770						771						} else772					 {773								774							if (!(collect(matchChars(/[^\]]/), result))) {775								return false;776							}777						778							}779						780					return [{type: "charsitem", value: joinTokens(result)}];781					782					783				}784			785				786				787				function joinTokens(tokens) {788					return tokens.map(t => t.value).join("");789				}790				791				function match(str) {792					if (text.substring(i, i + str.length) === str) {793						i += str.length;794						return {type: str, value: str};795					}796					return false;797				}798				799				function matchChars(re) {800					if (i < text.length && re.test(text[i])) {801						return {type: text[i], value: text[i++]};...parc-parser_step1.js
Source:parc-parser_step1.js  
...410							if (!(collect(match("=>"), result))) {411								return false;412							}413						414					return [{type: "arrow", value: joinTokens(result)}];415					416					417				}418			419				function parse_equals() {420					let result = [];421					422							423						if (collect(match("="), result)) {424							while(collect(match("="), result)) {};425							426							427						} else428					 {429								return false;430							}431						432					return [{type: "equals", value: joinTokens(result)}];433					434					435				}436			437				function parse_star() {438					let result = [];439					440							if (!(collect(match("*"), result))) {441								return false;442							}443						444					return [{type: "star", value: joinTokens(result)}];445					446					447				}448			449				function parse_plus() {450					let result = [];451					452							if (!(collect(match("+"), result))) {453								return false;454							}455						456					return [{type: "plus", value: joinTokens(result)}];457					458					459				}460			461				function parse_question() {462					let result = [];463					464							if (!(collect(match("?"), result))) {465								return false;466							}467						468					return [{type: "question", value: joinTokens(result)}];469					470					471				}472			473				function parse_dot() {474					let result = [];475					476							if (!(collect(match("."), result))) {477								return false;478							}479						480					return [{type: "dot", value: joinTokens(result)}];481					482					483				}484			485				function parse_name() {486					let result = [];487					488							489						if (collect(matchChars(/[a-zA-Z_]/), result)) {490							491							collect(parse_nametail(), result)492							493						} else494					 {495								return false;496							}497						498					return [{type: "name", value: joinTokens(result)}];499					500					501				}502			503				function parse_nametail() {504					let result = [];505					506							507						if (collect(matchChars(/[a-zA-Z0-9_]/), result)) {508							while(collect(matchChars(/[a-zA-Z0-9_]/), result)) {};509							510							511						} else512					 {513								return false;514							}515						516					return [{type: "nametail", value: joinTokens(result)}];517					518					519				}520			521				function parse_string() {522					let result = [];523					524							525						if (collect(match("\""), result)) {526							527							528							while (collect(parse_stritem(), result)) {};529							if (!(collect(match("\""), result))) {530								badSyntax();531							}532						533						} else534					 {535								return false;536							}537						538					return [{type: "string", value: joinTokens(result)}];539					540					541				}542			543				function parse_stritem() {544					let result = [];545					546							547						if (collect(match("\\"), result)) {548							549							550							551							if (!(collect(matchAny(), result))) {552								badSyntax();553							}554						555						} else556					 {557								558							if (!(collect(matchChars(/[^"]/), result))) {559								return false;560							}561						562							}563						564					return [{type: "stritem", value: joinTokens(result)}];565					566					567				}568			569				function parse_chars() {570					let result = [];571					572							573						if (collect(match("["), result)) {574							575							576							while (collect(parse_charsitem(), result)) {};577							if (!(collect(match("]"), result))) {578								badSyntax();579							}580						581						} else582					 {583								return false;584							}585						586					return [{type: "chars", value: joinTokens(result)}];587					588					589				}590			591				function parse_charsitem() {592					let result = [];593					594							595						if (collect(match("\\"), result)) {596							597							598							599							if (!(collect(matchAny(), result))) {600								badSyntax();601							}602						603						} else604					 {605								606							if (!(collect(matchChars(/[^\]]/), result))) {607								return false;608							}609						610							}611						612					return [{type: "charsitem", value: joinTokens(result)}];613					614					615				}616			617				618				619				function joinTokens(tokens) {620					return tokens.map(t => t.value).join("");621				}622				623				function match(str) {624					if (text.substring(i, i + str.length) === str) {625						i += str.length;626						return {type: str, value: str};627					}628					return false;629				}630				631				function matchChars(re) {632					if (i < text.length && re.test(text[i])) {633						return {type: text[i], value: text[i++]};...Swarm.js
Source:Swarm.js  
1/*2 * Docker Engine API3 * The Engine API is an HTTP API served by Docker Engine. It is the API the Docker client uses to communicate with the Engine, so everything the Docker client can do can be done with the API.  Most of the client's commands map directly to API endpoints (e.g. `docker ps` is `GET /containers/json`). The notable exception is running containers, which consists of several API calls.  # Errors  The API uses standard HTTP status codes to indicate the success or failure of the API call. The body of the response will be JSON in the following format:  ``` {   \"message\": \"page not found\" } ```  # Versioning  The API is usually changed in each release, so API calls are versioned to ensure that clients don't break. To lock to a specific version of the API, you prefix the URL with its version, for example, call `/v1.30/info` to use the v1.30 version of the `/info` endpoint. If the API version specified in the URL is not supported by the daemon, a HTTP `400 Bad Request` error message is returned.  If you omit the version-prefix, the current version of the API (v1.41) is used. For example, calling `/info` is the same as calling `/v1.41/info`. Using the API without a version-prefix is deprecated and will be removed in a future release.  Engine releases in the near future should support this version of the API, so your client will continue to work even if it is talking to a newer Engine.  The API uses an open schema model, which means server may add extra properties to responses. Likewise, the server will ignore any extra query parameters and request body properties. When you write clients, you need to ignore additional properties in responses to ensure they do not break when talking to newer daemons.   # Authentication  Authentication for registries is handled client side. The client has to send authentication details to various endpoints that need to communicate with registries, such as `POST /images/(name)/push`. These are sent as `X-Registry-Auth` header as a [base64url encoded](https://tools.ietf.org/html/rfc4648#section-5) (JSON) string with the following structure:  ``` {   \"username\": \"string\",   \"password\": \"string\",   \"email\": \"string\",   \"serveraddress\": \"string\" } ```  The `serveraddress` is a domain/IP without a protocol. Throughout this structure, double quotes are required.  If you have already got an identity token from the [`/auth` endpoint](#operation/SystemAuth), you can just pass this instead of credentials:  ``` {   \"identitytoken\": \"9cbaf023786cd7...\" } ``` 4 *5 * OpenAPI spec version: 1.416 *7 * NOTE: This class is auto generated by the swagger code generator program.8 * https://github.com/swagger-api/swagger-codegen.git9 *10 * Swagger Codegen version: 2.4.2111 *12 * Do not edit the class manually.13 *14 */15(function(root, factory) {16  if (typeof define === 'function' && define.amd) {17    // AMD. Register as an anonymous module.18    define(['ApiClient', 'model/ClusterInfo', 'model/JoinTokens', 'model/ObjectVersion', 'model/SwarmSpec', 'model/TLSInfo'], factory);19  } else if (typeof module === 'object' && module.exports) {20    // CommonJS-like environments that support module.exports, like Node.21    module.exports = factory(require('../ApiClient'), require('./ClusterInfo'), require('./JoinTokens'), require('./ObjectVersion'), require('./SwarmSpec'), require('./TLSInfo'));22  } else {23    // Browser globals (root is window)24    if (!root.DockerEngineApi) {25      root.DockerEngineApi = {};26    }27    root.DockerEngineApi.Swarm = factory(root.DockerEngineApi.ApiClient, root.DockerEngineApi.ClusterInfo, root.DockerEngineApi.JoinTokens, root.DockerEngineApi.ObjectVersion, root.DockerEngineApi.SwarmSpec, root.DockerEngineApi.TLSInfo);28  }29}(this, function(ApiClient, ClusterInfo, JoinTokens, ObjectVersion, SwarmSpec, TLSInfo) {30  'use strict';31  /**32   * The Swarm model module.33   * @module model/Swarm34   * @version 1.4135   */36  /**37   * Constructs a new <code>Swarm</code>.38   * @alias module:model/Swarm39   * @class40   * @extends module:model/ClusterInfo41   */42  var exports = function() {43    ClusterInfo.call(this);44  };45  /**46   * Constructs a <code>Swarm</code> from a plain JavaScript object, optionally creating a new instance.47   * Copies all relevant properties from <code>data</code> to <code>obj</code> if supplied or a new instance if not.48   * @param {Object} data The plain JavaScript object bearing properties of interest.49   * @param {module:model/Swarm} obj Optional instance to populate.50   * @return {module:model/Swarm} The populated <code>Swarm</code> instance.51   */52  exports.constructFromObject = function(data, obj) {53    if (data) {54      obj = obj || new exports();55      ClusterInfo.constructFromObject(data, obj);56      if (data.hasOwnProperty('JoinTokens'))57        obj.joinTokens = JoinTokens.constructFromObject(data['JoinTokens']);58    }59    return obj;60  }61  exports.prototype = Object.create(ClusterInfo.prototype);62  exports.prototype.constructor = exports;63  /**64   * @member {module:model/JoinTokens} joinTokens65   */66  exports.prototype.joinTokens = undefined;67  return exports;...agent.js
Source:agent.js  
1const os = require('os')2const { BOOTSTRAP_SWARM_RPC, GET_JOIN_ADDR_RPC, DOCKER_COMMAND_RPC, PING_EVENT } = require('../utils/schema')3const { dockerSwarmInit, dockerSwarmJoin, dockerCmd } = require('../utils/docker-cli')4const { getSwarmInfo, getNodeInfo } = require('../utils/docker-api')5const SWARM_PORT = 2377 // TODO: can it change?6module.exports = async function({logger, provideRpc, makeRpc, subscribe}) {7  subscribe(PING_EVENT, handlePing)8  // these RPC handlers will reject if not applicable to the current state9  provideRpcIf(inSwarm, GET_JOIN_ADDR_RPC, handleGetJoinAddr)10  provideRpcIf(inSwarm, DOCKER_COMMAND_RPC, handleDockerRpc)11  provideRpcIf(notInSwarm, BOOTSTRAP_SWARM_RPC, handleBootstrapSwarmRpc)12  // periodically will try to join some swarm13  setInterval(periodicActionHandler, 10000)14  // TODO: handle docker login in repositories15  logger.info("Swarm Queen Agent started")16  return;17  /************* internal functions **********/18  async function periodicActionHandler() {19    const iAmInSwarm = await inSwarm()20    if (!iAmInSwarm) {21      tryJoiningSomeSwarm()22    }23  }24  async function tryJoiningSomeSwarm() {25    logger.info("Looking for a SWARM to join - sending GET_JOIN_ADDR_RPC...")26    try {27      await joinExistingSwarm(await makeRpc(GET_JOIN_ADDR_RPC))28    }29    catch(error) {30      if (error === "NO_RPC_PROVIDER") {31        logger.info("--> No Managers available yet to join. Waiting...")32      } else {33        logger.error(`joinExistingSwarm or GET_JOIN_ADDR_RPC failed. ${error}`)34      }35    }36  }37  function handlePing() {38    logger.info("PING_EVENT received") // this log will be visible on the client side too39  }40  async function handleGetJoinAddr(_, response) {41    const joinInfo = await getJoinAddressAndTokens()42    response.send(joinInfo)43  }44  function handleDockerRpc({command, args, stdin}, response) {45    const handler = ({stdout, stderr}) => {46      response.send({stdout, stderr, hostname: os.hostname()})47    }48    logger.info(`RPC EXEC: docker ${command} ${args.join(' ')}`)49    dockerCmd({command, args, stdin}).then(handler).catch(handler)50  }51  async function handleBootstrapSwarmRpc(data, response)  {52    logger.info("Swarm Queen: bootstrapping a new swarm... ")53    await dockerSwarmInit()54    response.send("OK")55    logger.info("Swarm Queen: bootstrapped a new swarm successfully")56  }57  /************ utils *************/58  function provideRpcIf(predicate, name, handler) {59    provideRpc(name, async (data, response) => {60      response.autoAck = false // because capability check is async61      if (await predicate()) {62        response.ack()63        try {64          await handler(data, response)65        }66        catch(error) {67          logger.error(`${error.message}\n${error.stack}`)68          response.error(error.message)69        }70      } else {71        logger.info(`Rejecting ${name}`)72        response.reject()  // another node will try73      }74    })75  }76  async function inSwarm() {77    const self = await getNodeInfo()78    return !!self.Swarm.NodeID79  }80  async function notInSwarm() {81    return !(await inSwarm())82  }83  async function joinExistingSwarm({joinAddr, joinTokens}) {84    logger.info(`Joining existing swarm at ${joinAddr}...`)85    await dockerSwarmJoin(joinTokens.Manager, joinAddr)86    logger.info("Joined successfully")87  }88  async function getJoinAddressAndTokens() {89    const self = await getNodeInfo()90    const joinAddr = `${self.Swarm.NodeAddr}:${SWARM_PORT}`91    const joinTokens = (await getSwarmInfo()).JoinTokens92    return {joinAddr, joinTokens}93  }...play.js
Source:play.js  
...17   */18  async exec(ctx, args) {19    const player = await ctx.player();20    try {21      await player.prompt(ctx, joinTokens(args.many()));22    } catch (e) {23      if (e.code && e.code === 'ECONNREFUSED') ctx.send({ content: 'Lavalink connection refused...' });24      else ctx.send({ content: `Error: ${e.message}` });25    }26  }...name-utils.js
Source:name-utils.js  
...3}4function uppercaseFirst(s) {5    return s.charAt(0).toUpperCase() + s.substring(1);6}7function joinTokens(components) {8    var name = components.map(uppercaseFirst).join("");9    return lowercaseFirst(name);10}11function tokensForString(str) {12    var tokenizer = /\d+|[a-z]+|[A-Z]+(?![a-z])|[A-Z][a-z]+/g;13    var matchResult = str.match(tokenizer);14    if (!matchResult) {15        return ["invalid", "name"];16    }17    return matchResult.map(function (token) {18        return token.toLowerCase();19    });20}21export function generateName(name) {22    return joinTokens(tokensForString(name));...Using AI Code Generation
1const { joinTokens } = require('playwright/lib/utils/utils');2const { test } = require('@playwright/test');3test('test', async ({ page }) => {4    const url = await page.url();5    await page.goto(joinTokens(url, 'search?q=playwright'));6    await page.waitForSelector('text=Playwright');7});Using AI Code Generation
1const { joinTokens } = require('playwright/lib/utils/utils');2console.log(token);3const { joinTokens } = require('playwright/lib/utils/utils');4console.log(token);5const { joinTokens } = require('playwright/lib/utils/utils');6console.log(token);7const { joinTokens } = require('playwright/lib/utils/utils');8console.log(token);9const { joinTokens } = require('playwright/lib/utils/utils');10console.log(token);11const { joinTokens } = require('playwright/lib/utils/utils');12console.log(token);13const { joinTokens } = require('playwright/lib/utils/utils');14console.log(token);15const { joinTokens } = require('playwright/lib/utils/utils');16console.log(token);17const { joinTokens } = require('playwright/lib/utils/utils');18console.log(token);19const { joinTokens } = require('playwright/lib/utils/utils');20console.log(token);21const { joinTokens } = require('playwright/lib/utils/utils');Using AI Code Generation
1const { joinTokens } = require('playwright/lib/utils/utils');2const path = require('path');3const joinedPath = joinTokens(__dirname, 'path', 'to', 'file');4console.log(joinedPath);5const { joinTokens } = require('playwright/lib/utils/utils');6const path = require('path');7const joinedPath = joinTokens(__dirname, '..', 'path', 'to', 'file');8console.log(joinedPath);9const { joinTokens } = require('playwright/lib/utils/utils');10const path = require('path');11const joinedPath = joinTokens(__dirname, '..', '..', '..', '..', 'path', 'to', 'file');12console.log(joinedPath);13const { joinTokens } = require('playwright/lib/utils/utils');14const path = require('path');15const joinedPath = joinTokens(__dirname, 'path/to/file');16console.log(joinedPath);17const { joinTokens } = require('playwright/lib/utils/utils');18const path = require('path');19const joinedPath = joinTokens(__dirname, '..', 'path/to/file');20console.log(joinedPath);21const { joinTokens } = require('playwright/lib/utils/utils');22const path = require('path');23const joinedPath = joinTokens(__dirname, '..', '..', '..', '..', 'path/to/file');24console.log(joinedPath);25const { joinTokens } = require('playwright/lib/utils/utils');26const path = require('path');27const joinedPath = joinTokens(__dirname, 'path', 'to/file');28console.log(joinedPath);29const { joinTokensUsing AI Code Generation
1const { joinTokens } = require('playwright/lib/internal/protocol');2    { type: 'text', value: 'Hello' },3    { type: 'text', value: 'World' },4];5console.log(joinTokens(tokens));6const { joinTokens } = require('playwright/lib/internal/protocol');7    { type: 'text', value: 'Hello' },8    { type: 'text', value: 'World' },9];10console.log(joinTokens(tokens));11const { joinTokens } = require('playwright/lib/internal/protocol');12    { type: 'text', value: 'Hello' },13    { type: 'text', value: 'World' },14];15console.log(joinTokens(tokens));16const { joinTokens } = require('playwright/lib/internal/protocol');17    { type: 'text', value: 'Hello' },18    { type: 'text', value: 'World' },19];20console.log(joinTokens(tokens));21const { joinTokens } = require('playwright/lib/internal/protocol');22    { type: 'text', value: 'Hello' },23    { type: 'text', value: 'World' },24];25console.log(joinTokens(tokens));26const { joinTokens } = require('playwright/lib/internal/protocol');27    { type: 'text', value: 'Hello' },28    { type: 'text', value: 'World' },29];30console.log(joinTokens(tokens));31const { joinTokens } = require('playwright/lib/internal/protocol');32    { type: 'text', value: 'Hello' },33    { type: 'text', value: 'World' },34];35console.log(joinTokens(tokens));36const { joinTokens } = require('playwright/lib/internal/protocol');37    { type: 'text', value: 'Hello' },38    { type: 'text', value: 'World' },39];40console.log(joinTokens(tokens));41const {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!!
