Best JavaScript code snippet using wpt
GameState.js
Source:GameState.js
...23 this.x = x24 this.y = y25 this.z = z26 }27 convertToFlat(builder) {28 if(this.x == null && this.y == null && this.z == null) return null29 return flat.Vector3.createVector3(builder, this.x, this.y, this.z)30 } 31 convertToFlatPartial(builder) {32 if(this.x == null && this.y == null && this.z == null) return null33 Vector3Partial.startVector3Partial(builder)34 if(this.x != null) Vector3Partial.addX(builder, Float.createFloat(builder, this.x))35 if(this.y != null) Vector3Partial.addY(builder, Float.createFloat(builder, this.y))36 if(this.z != null) Vector3Partial.addZ(builder, Float.createFloat(builder, this.z))37 return Vector3Partial.endVector3Partial(builder)38 } 39}40class Rotator {41 /**42 * 43 * @param {Number} pitch 44 * @param {Number} yaw 45 * @param {Number} roll 46 */47 constructor(pitch, yaw, roll) {48 this.pitch = pitch49 this.yaw = yaw50 this.roll = roll51 }52 convertToFlat(builder) {53 if(this.pitch == null && this.yaw == null && this.roll == null) return null54 RotatorPartial.startRotatorPartial(builder)55 if(this.pitch != null) RotatorPartial.addPitch(builder, Float.createFloat(builder, this.pitch))56 if(this.yaw != null) RotatorPartial.addYaw(builder, Float.createFloat(builder, this.yaw))57 if(this.roll != null) RotatorPartial.addRoll(builder, Float.createFloat(builder, this.roll))58 return RotatorPartial.endRotatorPartial(builder)59 }60}61class Physics {62 /**63 * 64 * @param {Vector3} location 65 * @param {Rotator} rotation 66 * @param {Vector3} velocity 67 * @param {Vector3} angularVelocity68 */69 constructor(location, rotation, velocity, angularVelocity) {70 this.location = location71 this.rotation = rotation72 this.velocity = velocity73 this.angularVelocity = angularVelocity74 }75 convertToFlat(builder) {76 let locationFlat = this.location ? this.location.convertToFlatPartial(builder) : null77 let rotationFlat = this.rotation ? this.rotation.convertToFlat(builder) : null78 let velocityFlat = this.velocity ? this.velocity.convertToFlatPartial(builder) : null79 let angularVelocityFlat = this.angularVelocity ? this.angularVelocity.convertToFlatPartial(builder) : null80 if(locationFlat == null && rotationFlat == null && velocityFlat == null && angularVelocity == null) return null81 DesiredPhysics.startDesiredPhysics(builder)82 if(locationFlat != null) DesiredPhysics.addLocation(builder, locationFlat)83 if(rotationFlat != null) DesiredPhysics.addRotation(builder, rotationFlat)84 if(velocityFlat != null) DesiredPhysics.addVelocity(builder, velocityFlat)85 if(angularVelocityFlat != null) DesiredPhysics.addAngularVelocity(builder, angularVelocityFlat)86 return DesiredPhysics.endDesiredPhysics(builder)87 }88}89class BallState {90 /**91 * 92 * @param {Physics} physics 93 */94 constructor(physics) {95 this.physics = physics96 }97 convertToFlat(builder) {98 let physicsFlat = this.physics ? this.physics.convertToFlat(builder) : null99 if(physicsFlat == null) return null100 else {101 DesiredBallState.startDesiredBallState(builder)102 DesiredBallState.addPhysics(builder, physicsFlat)103 return DesiredBallState.endDesiredBallState(builder)104 }105 }106}107class CarState {108 /**109 * 110 * @param {Physics} physics 111 * @param {Number} boostAmount 112 * @param {Boolean} jumped 113 * @param {Boolean} doubleJumped 114 */115 constructor(physics, boostAmount, jumped, doubleJumped) {116 this.physics = physics117 this.boostAmount = boostAmount118 this.jumped = jumped119 this.doubleJumped = doubleJumped120 }121 convertToFlat(builder) {122 let physicsFlat = this.physics ? this.physics.convertToFlat(builder) : null123 DesiredCarState.startDesiredCarState(builder)124 if(physicsFlat != null) DesiredCarState.addPhysics(builder, physicsFlat)125 if(this.boostAmount != null) DesiredBallState.addBoostAmount(builder, this.boostAmount)126 if(this.jumped != null) DesiredBallState.addJumped(builder, this.jumped)127 if(this.doubleJumped != null) DesiredBallState.addDoubleJumped(builder, this.doubleJumped)128 return DesiredCarState.endDesiredCarState(builder)129 }130}131class BoostState {132 /**133 * 134 * @param {Number} respawnTime 135 */136 constructor(respawnTime) {137 this.respawnTime = respawnTime138 }139 convertToFlat(builder) {140 DesiredBoostState.startDesiredBoostState(builder)141 if(this.respawnTime != null) DesiredBoostState.addRespawnTime(builder, this.respawnTime)142 return DesiredBoostState.endDesiredBoostState(builder)143 }144}145class GameInfoState {146 /**147 * 148 * @param {Number} worldGravityZ 149 * @param {Number} gameSpeed 150 */151 constructor(worldGravityZ, gameSpeed) {152 this.worldGravityZ = worldGravityZ153 this.gameSpeed = gameSpeed 154 }155 convertToFlat(builder) {156 DesiredGameInfoState.startDesiredGameInfoState(builder)157 if(this.worldGravityZ != null) DesiredGameInfoState.addDesiredGameInfoState(builder, this.worldGravityZ)158 if(this.gameSpeed != null) DesiredGameInfoState.addDesiredGameInfoState(builder, this.gameSpeed)159 return DesiredGameInfoState.endDEsiredGameInfoState(builder)160 }161}162class GameState {163 /**164 * 165 * @param {BallState} ballState 166 * @param {Array<CarState>} carStates 167 * @param {Array<BoostState>} boostStates 168 * @param {GameInfoState} gameInfoState 169 */170 constructor(ballState, carStates, boostStates, gameInfoState) {171 this.ballState = ballState172 this.carStates = carStates173 this.boostStates = boostStates174 this.gameInfoState = gameInfoState175 }176 convertToFlat(builder) {177 if(builder == null) builder = new flatbuffers.Builder(0)178 let ballStateFlat = this.ballState ? this.ballState.convertToFlat(builder) : null179 let carStates = this.carStates ? [] : null180 if(carStates != null) {181 for(let carState of this.carStates) {182 carStates.push(carState ? carState.convertToFlat(builder) : null)183 }184 }185 let carStatesFlat = carStates ? DesiredGameState.createCarStatesVector(builder, carStates): null186 let boostStates = this.boostStates ? [] : null187 if(boostStates != null) {188 for(let boostState of this.boostStates) {189 boostStates.push(boostState ? boostState.convertToFlat(builder) : null)190 }191 }192 let boostStatesFlat = boostStates ? DesiredGameState.createBoostStatesVector(builder, boostStates) : null193 let gameInfoStateFlat = this.gameInfoState ? this.gameInfoState.convertToFlat(builder) : null194 DesiredGameState.startDesiredGameState(builder)195 if(ballStateFlat != null) DesiredGameState.addBallState(builder, ballStateFlat)196 if(carStatesFlat != null) DesiredGameState.addCarStates(builder, carStatesFlat)197 if(boostStatesFlat != null) DesiredGameState.addBoostStates(builder, boostStatesFlat)198 if(gameInfoStateFlat != null) DesiredGameState.addGameInfoState(builder, gameInfoStateFlat)199 return DesiredGameState.endDesiredGameState(builder)200 }201}202module.exports = {203 Vector3: Vector3,204 Rotator: Rotator,205 Physics: Physics,206 BallState: BallState,207 BoostState: BoostState,...
RenderManager.js
Source:RenderManager.js
...20 this.red = red21 this.green = green22 this.blue = blue23 }24 convertToFlat(builder) {25 flat.Color.startColor(builder)26 flat.Color.addA(builder, this.alpha)27 flat.Color.addR(builder, this.red)28 flat.Color.addG(builder, this.green)29 flat.Color.addB(builder, this.blue)30 return flat.Color.endColor(builder)31 }32}33class RenderManager {34 constructor(botManager, index) {35 this.manager = botManager36 this.builder = null37 this.index = index38 this.Color = Color39 this.renderList = []40 this.groupID = ''41 }42 /**43 *44 * @param {String} [groupID]45 */46 beginRendering(groupID) {47 this.builder = new flatbuffers.Builder(0)48 this.renderList = []49 if(groupID) this.groupID = groupID50 }51 endRendering() {52 if(this.groupID == undefined) this.groupID = 'default'53 const hash = crypto.createHash('sha256')54 hash.update(this.groupID + this.index)55 let groupIDHashed = parseInt(hash.digest('hex'), 16)%maxInt56 let messages = RenderGroup.createRenderMessagesVector(this.builder, this.renderList)57 RenderGroup.startRenderGroup(this.builder)58 RenderGroup.addId(this.builder, groupIDHashed)59 RenderGroup.addRenderMessages(this.builder, messages)60 let result = RenderGroup.endRenderGroup(this.builder)61 this.builder.finish(result)62 let buffer = Buffer.from(this.builder.asUint8Array())63 this.manager.interface.RenderGroup(ref.address(buffer), buffer.length)64 }65 /**66 *67 * @param {Number} x68 * @param {Number} y69 * @param {Number} scaleX70 * @param {Number} scaleY71 * @param {String} text72 * @param {Color} color73 */74 drawString2D(x, y, scaleX, scaleY, text, color) {75 let textFlat = this.builder.createString(text)76 let colorFlat = color.convertToFlat(this.builder)77 RenderMessage.startRenderMessage(this.builder)78 RenderMessage.addRenderType(this.builder, RenderType.DrawString2D)79 RenderMessage.addColor(this.builder, colorFlat)80 RenderMessage.addStart(this.builder, flat.Vector3.createVector3(this.builder, x, y))81 RenderMessage.addScaleX(this.builder, scaleX)82 RenderMessage.addScaleY(this.builder, scaleY)83 RenderMessage.addText(this.builder, textFlat)84 this.renderList.push(RenderMessage.endRenderMessage(this.builder))85 }86 /**87 *88 * @param {Vector3} vector89 * @param {Number} scaleX90 * @param {Number} scaleY91 * @param {String} text92 * @param {Color} color93 */94 drawString3D(vector, scaleX, scaleY, text, color) {95 let textFlat = this.builder.createString(text)96 let colorFlat = color.convertToFlat(this.builder)97 RenderMessage.startRenderMessage(this.builder)98 RenderMessage.addRenderType(this.builder, RenderType.DrawString3D)99 RenderMessage.addColor(this.builder, colorFlat)100 RenderMessage.addStart(this.builder, vector.convertToFlat(this.builder))101 RenderMessage.addScaleX(this.builder, scaleX)102 RenderMessage.addScaleY(this.builder, scaleY)103 RenderMessage.addText(this.builder, textFlat)104 this.renderList.push(RenderMessage.endRenderMessage(this.builder))105 }106 /**107 *108 * @param {Number} x109 * @param {Number} y110 * @param {Vector3} end111 * @param {Color} color112 */113 drawLine2D_3D(x, y, end, color) {114 let colorFlat = color.convertToFlat(this.builder)115 RenderMessage.startRenderMessage(this.builder)116 RenderMessage.addRenderType(this.builder, RenderType.DrawLine2D_3D)117 RenderMessage.addStart(this.builder, flat.Vector3.createVector3(this.builder, x, y))118 RenderMessage.addEnd(this.builder, end.convertToFlat(this.builder))119 RenderMessage.addColor(this.builder, colorFlat)120 this.renderList.push(RenderMessage.endRenderMessage(this.builder))121 }122 /**123 *124 * @param {Vector3} start125 * @param {Vector3} end126 * @param {Color} color127 */128 drawLine3D(start, end, color) {129 let colorFlat = color.convertToFlat(this.builder)130 RenderMessage.startRenderMessage(this.builder)131 RenderMessage.addRenderType(this.builder, RenderType.DrawLine3D)132 RenderMessage.addStart(this.builder, start.convertToFlat(this.builder))133 RenderMessage.addEnd(this.builder, end.convertToFlat(this.builder))134 RenderMessage.addColor(this.builder, colorFlat)135 this.renderList.push(RenderMessage.endRenderMessage(this.builder))136 }137 /**138 *139 * @param {Number} x140 * @param {Number} y141 * @param {Number} width142 * @param {Number} height143 * @param {Boolean} filled144 * @param {Color} color145 */146 drawRect2D(x, y, width, height, filled, color) {147 let colorFlat = color.convertToFlat(this.builder)148 RenderMessage.startRenderMessage(this.builder)149 RenderMessage.addRenderType(this.builder, RenderType.DrawRect2D)150 RenderMessage.addStart(this.builder, flat.Vector3.createVector3(this.builder, this.x, this.y))151 RenderMessage.addScaleX(this.builder, width)152 RenderMessage.addScaleY(this.builder, height)153 RenderMessage.addIsFilled(this.builder, filled)154 RenderMessage.addColor(this.builder, colorFlat)155 this.renderList.push(RenderMessage.endRenderMessage(this.builder))156 }157 /**158 *159 * @param {Vector3} vector160 * @param {Number} width161 * @param {Number} height162 * @param {Boolean} filled163 * @param {Color} color164 * @param {Boolean} [centered]165 */166 drawRect3D(vector, width, height, filled, color, centered) {167 let colorFlat = color.convertToFlat(this.builder)168 RenderMessage.startRenderMessage(this.builder)169 RenderMessage.addRenderType(this.builder, centered ? RenderType.DrawCenteredRect3D : RenderType.DrawRect3D)170 RenderMessage.addStart(this.builder, vector.convertToFlat(this.builder))171 RenderMessage.addScaleX(this.builder, width)172 RenderMessage.addScaleY(this.builder, height)173 RenderMessage.addIsFilled(this.builder, filled)174 RenderMessage.addColor(this.builder, colorFlat)175 this.renderList.push(RenderMessage.endRenderMessage(this.builder))176 }177 black() {178 return new this.Color(255, 0, 0, 0);179 }180 white() {181 return new this.Color(255, 255, 255, 255);182 }183 gray() {184 return new this.Color(255, 128, 128, 128);...
GroupUtils.test.ts
Source:GroupUtils.test.ts
...20 country: 'France',21 name: 'Simba',22 type: 'Cat',23 }]]]);24 const result = convertToFlat(mappedData);25 expect(result).toMatchSnapshot();26 });27 it('inner group', () => {28 const mappedData = new Map([['France',29 new Map([['Cat', [{30 country: 'France',31 name: 'Simba',32 type: 'Cat',33 }]]]),34 ]]);35 const result = convertToFlat(mappedData);36 expect(result).toMatchSnapshot();37 });38 it('complex structure', () => {39 const mappedData = new Map([['France',40 new Map([41 ['Cat', [{42 country: 'France',43 name: 'Simba',44 type: 'Cat',45 }, {46 country: 'France',47 name: 'Kas',48 type: 'Cat',49 }]],50 ['Dog', [{51 country: 'France',52 name: 'Slimu',53 type: 'Dog',54 }, {55 country: 'France',56 name: 'Rex',57 type: 'Dog',58 }]],59 ]),60 ],61 ['Brazil',62 new Map([63 ['Cat', [{64 country: 'Brazil',65 name: 'Simba',66 type: 'Cat',67 }, {68 country: 'Brazil',69 name: 'Kas',70 type: 'Cat',71 }]],72 ['Dog', [{73 country: 'Brazil',74 name: 'Slimu',75 type: 'Dog',76 }, {77 country: 'Brazil',78 name: 'Rex',79 type: 'Dog',80 }]],81 ]),82 ]]);83 const result = convertToFlat(mappedData);84 expect(result).toMatchSnapshot();85 });86 });87 it('getExpandedGroups', () => {88 const groupRowData: GroupRowData = { key: ['dog'], value: 'Rex', groupMark: getGroupMark() };89 const groupedData: any[] = [{}, groupRowData, {}];90 const result = getExpandedGroups(groupedData);91 expect(result).toEqual([['dog']]);92 });93 it('updateExpandedGroups add', () => {94 const groupsExpanded: any[][] = [['cat']];95 const updated = updateExpandedGroups(groupsExpanded, ['dog']);96 expect(updated).toEqual([['cat'], ['dog']]);97 });...
Using AI Code Generation
1var wpt = require('wpt.js');2var testObj = {3 "b": {4 "d": {5 }6 }7};8var flatObj = wpt.convertToFlat(testObj);9console.log(flatObj);10var wpt = require('wpt.js');11var testObj = {12};13var deepObj = wpt.convertToDeep(testObj);14console.log(deepObj);15var wpt = require('wpt.js');16var testObj = {17 "b": {18 "d": {19 }20 }21};22var flatObj = wpt.convertToFlat(testObj);23console.log(flatObj);24var wpt = require('wpt.js');25var testObj = {26};27var deepObj = wpt.convertToDeep(testObj);28console.log(deepObj);29var wpt = require('wpt.js');30var testObj = {31 "b": {32 "d": {33 }34 }35};36var flatObj = wpt.convertToFlat(testObj);37console.log(flat
Using AI Code Generation
1var wptools = require('wptools');2wptools.convertToFlat('test.json', 'testFlat.json', function (err, result) {3 if (err) {4 console.log(err);5 }6 else {7 console.log("result: " + result);8 }9});10{11 "address": {12 },13}14{15}
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2var flat = wptoolkit.convertToFlat({3 "a": {4 },5});6console.log(flat);7var wptoolkit = require('wptoolkit');8var nested = wptoolkit.convertToNested({9});10console.log(nested);11var wptoolkit = require('wptoolkit');12var flat = wptoolkit.convertToFlat({13 "a": {14 },15});16console.log(flat);17var wptoolkit = require('wptoolkit');18var nested = wptoolkit.convertToNested({19});20console.log(nested);21var wptoolkit = require('wptoolkit');22var flat = wptoolkit.convertToFlat({23 "a": {24 },25});26console.log(flat);
Using AI Code Generation
1const wptools = require('wptools');2wptools.convertToFlat('test.html', 'test_flat.html', function(err, res) {3 if (err) {4 console.log(err);5 } else {6 console.log(res);7 }8});9const wptools = require('wptools');10const res = wptools.convertToFlatSync('test.html');11console.log(res);12const wptools = require('wptools');13wptools.convertToFlatFromText('test text', 'test_flat.html', function(err, res) {14 if (err) {15 console.log(err);16 } else {17 console.log(res);18 }19});20const wptools = require('wptools');21const res = wptools.convertToFlatFromTextSync('test text');22console.log(res);23const wptools = require('wptools');24 if (err) {25 console.log(err);26 } else {27 console.log(res);28 }29});30const wptools = require('wptools');31console.log(res);
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2var wp = new wptoolkit();3var flat = wp.convertToFlat(json);4console.log(flat);5{6 "cars": {7 }8}9var wptoolkit = require('wptoolkit');10var wp = new wptoolkit();11var nested = wp.convertToNested(json);12console.log(nested);13{14}15var wptoolkit = require('wptoolkit');16var wp = new wptoolkit();17var flat = wp.convertToFlat(json, {separator: '.'});18console.log(flat);19{20}21var wptoolkit = require('wptoolkit');22var wp = new wptoolkit();23var nested = wp.convertToNested(json, {separator: '.'});24console.log(nested);25{26 "cars": {27 }28}29var wptoolkit = require('wptoolkit');30var wp = new wptoolkit();31var flat = wp.convertToFlat(json, {separator: '.'});32console.log(flat);33{
Using AI Code Generation
1const wptools = require('wptools')2wptools.convertToFlat('D:/test.docx', 'D:/test.pdf', (err, result) => {3 if (err) {4 console.log(err)5 }6 console.log(result)7})8const wptools = require('wptools')9wptools.convertToFlat('D:/test.docx', 'D:/test.pdf', (err, result) => {10 if (err) {11 console.log(err)12 }13 console.log(result)14})15const wptools = require('wptools')16wptools.convertToFlat('D:/test.docx', 'D:/test.pdf', (err, result) => {17 if (err) {18 console.log(err)19 }20 console.log(result)21})22const wptools = require('wptools')23wptools.convertToFlat('D:/test.docx', 'D:/test.pdf', (err, result) => {24 if (err) {25 console.log(err)26 }27 console.log(result)28})29const wptools = require('wptools')30wptools.convertToFlat('D:/test.docx', 'D:/test.pdf', (err, result) => {31 if (err) {32 console.log(err)33 }34 console.log(result)35})36const wptools = require('wptools')37wptools.convertToFlat('D:/test.docx', 'D:/test.pdf', (err, result) => {38 if (err) {39 console.log(err)40 }41 console.log(result)42})43const wptools = require('wptools')44wptools.convertToFlat('D:/test.docx', 'D:/test.pdf
Using AI Code Generation
1var wpt = require('webpagetest');2var test = new wpt('API_KEY');3var nestedJSON = {4 "address": {5 },6 {7 },8 {9 }10};11var flatJSON = test.convertToFlat(nestedJSON);12console.log(flatJSON);13var wpt = require('webpagetest');14var test = new wpt('API_KEY');15var flatJSON = {16};17var nestedJSON = test.convertToNested(flatJSON);18console.log(nestedJSON);
Using AI Code Generation
1var flatElements = wptbTable( 'table' ).convertToFlat();2var flatElements = wptbTable( 'table' ).convertToFlat();3var flatElements = wptbTable( 'table' ).convertToFlat();4var flatElements = wptbTable( 'table' ).convertToFlat();5var flatElements = wptbTable( 'table' ).convertToFlat();6var flatElements = wptbTable( 'table' ).convertToFlat();7var flatElements = wptbTable( 'table' ).convertToFlat();8var flatElements = wptbTable( 'table' ).convertToFlat();9var flatElements = wptbTable( 'table' ).convertToFlat();
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!