Best JavaScript code snippet using wpt
index.js
Source:index.js
...7})8app.get("/", (req, res) => {9 const a = [10 {11 "b": atob("QmFib3kga28gc2EgcHVsbywgYmFsYWhpYm8neSBwYWtvLg=="),12 "s": [13 atob("bGFuZ2th")14 ] // 115 },16 {17 "b": atob("QnV0byd0IGJhbGF0LCBsdW1pbGlwYWQ="),18 "s": [19 atob("c2FyYW5nZ29sYQ==")20 ] // 221 },22 {23 "b": atob("QXlhbiBuYSwgYXlhbiBuYSwgaGluZGkgbW8gcGEgbWFraXRhLg=="),24 "s": [25 atob("aGFuZ2lu")26 ] // 327 },28 {29 "b": atob("SGluZGkgaGFyaSwgaGluZGkgcGFyaSwgbmd1bml0IGFuZyBzdW90IGF5IHNhcmktc2FyaS4="),30 "s": [31 atob("c2FtcGF5YW4="),32 atob("dW5hbg==")33 ] // 434 },35 {36 "b": atob("RGluaWxhYW4gbXVuYSwgYmFnbyBwYXNvay4="),37 "s": [38 atob("c2ludWxpZA==")39 ] // 540 },41 {42 "b": atob("TWF0YW5na2FkIGthcGFnIG5ha2F1cG8sIG1hYmFiYSBrYXBhZyBuYWthdGF5bw=="),43 "s": [44 atob("YXNv")45 ] // 646 },47 {48 "b": atob("SXNkYSBrbyBzYSBNYXJpdmVsZXMsIG5hc2EgbG9vYiBhbmcga2FsaXNraXMu"),49 "s": [50 atob("c2lsaQ==")51 ] // 752 },53 {54 "b": atob("U2EgdW1hZ2EneSBhcGF0IGFuZyBwYWEsIHNhIHRhbmdoYWxpJ3kgZGFsYXdhLCBhdCBzYSBwYWdzYXBpdCBuZyBnYWJpJ3kgYW5nIHBhYSBheSB0YXRsbyBuYS4="),55 "s": [56 atob("dGFv")57 ] // 858 },59 {60 "b": atob("SXNhbmcgYmFsb25nIG1hbGFsaW0sIHB1bm9uZyBwdW5vIG5nIHBhdGFsaW0u"),61 "s": [62 atob("YmliaWc="),63 atob("YnVuZ2FuZ2E=")64 ] // 965 },66 {67 "b": atob("QXJhdy1hcmF3IG5hbWFtYXRheSwgdGFvbi10YW9uZyBuYWJ1YnVoYXku"),68 "s": [69 atob("a2FsZW5kYXJ5bw==")70 ] // 1071 },72 {73 "b": atob("QWJvdCBuZyB0aW5naW4sIGhpbmRpIG5hbWFuIG1hcmF0aW5nLg=="),74 "s": [75 atob("bGFuZ2l0"),76 atob("a2FsYW5naXRhbg==")77 ] // 1178 },79 {80 "b": atob("TmFyaXlhbiBuYSBzaSBLYXRvdG8sIGJpdGJpdCBhbmcga2FueWFuZyBrdWJvLg=="),81 "s": [82 atob("cGFnb25n")83 ] // 1284 },85 {86 "b": atob("RGFsYXdhbmcga2F0YXdhbiwgdGFndXNhbiBhbmcgdGFkeWFuZy4="),87 "s": [88 atob("aGFnZGFu")89 ] // 1390 },91 {92 "b": atob("SGluaWxhIGtvIGFuZyBiYWdpbmcsIG5hZ2thZ3VsbyBhbmcgbWdhIG1hdHNpbmc="),93 "s": [94 atob("a2FtcGFuYQ==")95 ] // 1496 },97 {98 "b": atob("TGltYW5nIHB1bm8gbmcgbml5b2csIGlpc2EgYW5nIG1hdGF5b2cu"),99 "s": [100 atob("ZGFsaXJp")101 ] // 15102 },103 {104 "b": atob("UGl0b25nIGJpbnRhbmEsIHRhdGxvIGFuZyBuYWlzYXNhcmEu"),105 "s": [106 atob("bXVraGE=")107 ] // 16108 },109 {110 "b": atob("THVtdWx1aGEgd2FsYW5nIG1hdGEsIGx1bWFsYWthZCB3YWxhbmcgcGFhLg=="),111 "s": [112 atob("cGFudWxhdA=="),113 atob("YmFsbHBlbg=="),114 atob("bGFwaXM="),115 atob("cGx1bWE=")116 ] // 17117 },118 {119 "b": atob("S3VuZyBrYWlsYW4gcGluYXRheSwgc2FrYSBodW1hYmEgYW5nIGJ1aGF5Lg=="),120 "s": [121 atob("a2FuZGlsYQ==")122 ] // 18123 },124 {125 "b": atob("SXNhIGtvbmcga2FpYmlnYW4sIGthc2FtYSBrbyBrYWhpdCBzYWFuLg=="),126 "s": [127 atob("YW5pbm8=")128 ] // 19129 },130 {131 "b": atob("U2EgdW1hZ2EneSBidW1ib25nLCBzYSBnYWJpIGF5IGRhaG9uLg=="),132 "s": [133 atob("YmFuaWc=")134 ] // 20135 },136 {137 "b": atob("U2EgZ2FiaSd5IGhpbm9nLCBzYSB1bWFnYSd5IGhpbGF3Lg=="),138 "s": [139 atob("YnVtYmlseWE="),140 atob("aWxhdw==")141 ] // 21142 },143 {144 "b": atob("QXBhdCBuYSBrYXRhbywgaWlzYSBhbmcgc3VtYnJlcm8="),145 "s": [146 atob("YmFoYXk=")147 ] // 22148 },149 {150 "b": atob("SXNhbmcgYml5YXMgbmEga2F3YXlhbiwgcHVubyBuZyBrYXlhbWFuYW4u"),151 "s": [152 atob("YWxrYW5zeWE="),153 atob("YWxrYW5zaXlh")154 ] // 23155 },156 {157 "b": atob("S2FwaXJhc29uZyB0ZWxhbmcgdGFncGktdGFncGksIGlnaW5hZ2FsYW5nIG5nIGF0aW5nIGxhaGku"),158 "s": [159 atob("d2F0YXdhdA=="),160 atob("YmFuZGlsYQ==")161 ] // 24162 },163 {164 "b": atob("S2FwaXJhc29uZyBwYXRwYXQsIHR1bWF3aWQgbmcgZGFnYXQsIHVtYWt5YXQgbmcgYnVuZG9rLCBuYWd0YWJveSBuZyBoYXlvcC4="),165 "s": [166 atob("c3V5b2Q=")167 ] // 25168 },169 {170 "b": atob("TXVudGluZyBwcmluc2VzYSwgbmFrYXVwbyBzYSB0YXNh"),171 "s": [172 atob("a2FzdXk=")173 ] // 26174 },175 {176 "b": atob("QmluaWxpIGtvJ3kgaXRpbSwgZ2luYW1pdCBrbyd5IHB1bGEsIHRpbmFwaW4ga28neSBwdXRpLg=="),177 "s": [178 atob("dWxpbmc=")179 ] // 27180 },181 {182 "b": atob("QmF0YSBwYSBsYW5nIHNpIE5lbmEsIG1hYWxhbSBuYW5nIG1hbmFoaS4="),183 "s": [184 atob("Z2FnYW1iYQ==")185 ] // 28186 }187 ]188 res.send(JSON.stringify(a[Math.floor(Math.random() * a.length)]))189})190app.listen(port, () => {191 console.log("Active")192})...
worker-atob-btoa.js
Source:worker-atob-btoa.js
1importScripts('../../../resources/js-test-pre.js');2var global = this;3global.jsTestIsAsync = true;4description("tests that atob() / btoa() work in workers.");5shouldBe('self.atob("YQ==")', '"a"');6shouldBe('self.atob("YWI=")', '"ab"');7shouldBe('self.atob("YWJj")', '"abc"');8shouldBe('self.atob("YWJjZA==")', '"abcd"');9shouldBe('self.atob("YWJjZGU=")', '"abcde"');10shouldBe('self.atob("YWJjZGVm")', '"abcdef"');11shouldBe('self.btoa("a")', '"YQ=="');12shouldBe('self.btoa("ab")', '"YWI="');13shouldBe('self.btoa("abc")', '"YWJj"');14shouldBe('self.btoa("abcd")', '"YWJjZA=="');15shouldBe('self.btoa("abcde")', '"YWJjZGU="');16shouldBe('self.btoa("abcdef")', '"YWJjZGVm"');17shouldBe('typeof self.btoa', '"function"');18shouldThrow('self.btoa()', '"TypeError: Not enough arguments"');19shouldBe('self.btoa("")', '""');20shouldBe('self.btoa(null)', '"bnVsbA=="'); // Gets converted to "null" string.21shouldBe('self.btoa(undefined)', '"dW5kZWZpbmVk"');22shouldBe('self.btoa(self)', '"W29iamVjdCBEZWRpY2F0ZWRXb3JrZXJHbG9iYWxTY29wZV0="'); // "[object DedicatedWorkerGlobalScope]"23shouldBe('self.btoa("éé")', '"6ek="');24shouldBe('self.btoa("\\u0080\\u0081")', '"gIE="');25shouldThrow('self.btoa("ÑеÑÑ")');26self.btoa = 0;27shouldBe('self.btoa', '0');28shouldBe('typeof self.btoa', '"number"');29shouldBe('typeof self.atob', '"function"');30shouldThrow('self.atob()', '"TypeError: Not enough arguments"');31shouldBe('self.atob("")', '""');32shouldBe('self.atob(null)', '"\x9Eée"'); // Gets converted to "null" string.33shouldThrow('self.atob(undefined)');34shouldBe('self.atob(" YQ==")', '"a"');35shouldBe('self.atob("YQ==\\u000a")', '"a"');36shouldBe('self.atob("ab\\tcd")', '"i·\x1d"');37shouldBe('self.atob("ab\\ncd")', '"i·\x1d"');38shouldBe('self.atob("ab\\fcd")', '"i·\x1d"');39shouldBe('self.atob("ab cd")', '"i·\x1d"');40shouldBe('self.atob("ab\\t\\n\\f\\r cd")', '"i·\x1d"');41shouldBe('self.atob(" \\t\\n\\f\\r ab\\t\\n\\f\\r cd\\t\\n\\f\\r ")', '"i·\x1d"');42shouldBe('self.atob("ab\\t\\n\\f\\r =\\t\\n\\f\\r =\\t\\n\\f\\r ")', '"i"');43shouldBe('self.atob(" ")', '""');44shouldThrow('self.atob(" abcd===")');45shouldThrow('self.atob("abcd=== ")');46shouldThrow('self.atob("abcd ===")');47shouldBe('self.atob("6ek=")', '"éé"');48shouldBe('self.atob("6ek")', '"éé"');49shouldBe('self.atob("gIE=")', '"\u0080\u0081"');50shouldThrow('self.atob("ÑеÑÑ")');51shouldThrow('self.atob("z")');52shouldBe('self.atob("zz")', '"Ã"');53shouldBe('self.atob("zzz")', '"Ã\u003C"');54shouldBe('self.atob("zzz=")', '"Ã\u003C"');55shouldThrow('self.atob("zzz==")'); // excess pad characters.56shouldThrow('self.atob("zzz===")'); // excess pad characters.57shouldThrow('self.atob("zzz====")'); // excess pad characters.58shouldThrow('self.atob("zzz=====")'); // excess pad characters.59shouldBe('self.atob("zzzz")', '"Ã\u003Có"');60shouldThrow('self.atob("zzzzz")');61shouldThrow('self.atob("z=zz")');62shouldThrow('self.atob("=")');63shouldThrow('self.atob("==")');64shouldThrow('self.atob("===")');65shouldThrow('self.atob("====")');66shouldThrow('self.atob("=====")');67self.atob = 0;68shouldBe('self.atob', '0');69shouldBe('typeof self.atob', '"number"');...
Using AI Code Generation
1function atob(input) {2 var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';3 var str = String(input).replace(/=+$/, '');4 var output = '';5 if (str.length % 4 == 1) {6 throw new InvalidCharacterError("'atob' failed: The string to be decoded is not correctly encoded.");7 }8 for (9 var bc = 0, bs, buffer, idx = 0;10 buffer = str.charAt(idx++);11 ~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer,12 bc++ % 4) ? output += String.fromCharCode(255 & bs >> (-2 * bc & 6)) : 013 ) {14 buffer = chars.indexOf(buffer);15 }16 return output;17 }18 function btoa(input) {19 var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';20 var str = String(input);21 for (22 var block, charCode, idx = 0, map = chars, output = '';23 str.charAt(idx | 0) || (map = '=', idx % 1);24 output += map.charAt(63 & block >> 8 - idx % 1 * 8)25 ) {26 charCode = str.charCodeAt(idx += 3 / 4);27 if (charCode > 0xFF) {28 throw new InvalidCharacterError("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");29 }30 block = block << 8 | charCode;31 }32 return output;33 }
Using AI Code Generation
1var atob = require('atob');2var btoa = require('btoa');3var atob = require('atob');4var btoa = require('btoa');5var atob = require('atob');6var btoa = require('btoa');7var atob = require('atob');8var btoa = require('btoa');9var atob = require('atob');10var btoa = require('btoa');11var atob = require('atob');12var btoa = require('btoa');13var atob = require('atob');14var btoa = require('btoa');
Using AI Code Generation
1var atob = require('atob');2var btoa = require('btoa');3var base64String = "SGVsbG8gV29ybGQh";4var decodedString = atob(base64String);5console.log(decodedString);6var atob = require('atob');7var btoa = require('btoa');8var base64String = "SGVsbG8gV29ybGQh";9var decodedString = atob(base64String);10console.log(decodedString);
Using AI Code Generation
1var b64 = 'SGVsbG8sIFdvcmxkIQ==';2var str = atob(b64);3console.log(str);4var str = 'Hello, World!';5var b64 = btoa(str);6console.log(b64);7function myFunction() {8 console.log('Hello');9}10setTimeout(myFunction, 3000);11function myFunction() {12 console.log('Hello');13}14setInterval(myFunction, 3000);15var myVar = setInterval(myFunction, 3000);16function myFunction() {17 console.log('Hello');18}19clearInterval(myVar);20var myVar = setTimeout(myFunction, 3000);21function myFunction() {22 console.log('Hello');23}24clearTimeout(myVar);25setImmediate(function() {26 console.log('Hello');27});28var myVar = setImmediate(function() {29 console.log('Hello');30});31clearImmediate(myVar);32var myVar = setInterval(function() {33 console.log('Hello');34}, 3000);35var myVar = setTimeout(function() {36 console.log('Hello');37}, 3000);38var myVar = setInterval(function() {39 console.log('Hello');40}, 3000);41clearInterval(myVar);
Using AI Code Generation
1var encoded = "dGVzdA==";2var decoded = atob(encoded);3console.log(decoded);4var decoded = "test";5var encoded = btoa(decoded);6console.log(encoded);7var decoded = "test";8var encoded = btoa(decoded);9console.log(encoded);10var decoded = "test";11var encoded = btoa(decoded);12console.log(encoded);13var decoded = "test";14var encoded = btoa(decoded);15console.log(encoded);16var decoded = "test";17var encoded = btoa(decoded);18console.log(encoded);19var decoded = "test";20var encoded = btoa(decoded);21console.log(encoded);22var decoded = "test";23var encoded = btoa(decoded);24console.log(encoded);25var decoded = "test";26var encoded = btoa(decoded);27console.log(encoded);28var decoded = "test";29var encoded = btoa(decoded);30console.log(encoded);31var decoded = "test";32var encoded = btoa(decoded);33console.log(encoded);34var decoded = "test";35var encoded = btoa(decoded);36console.log(encoded);37var decoded = "test";38var encoded = btoa(decoded);39console.log(encoded);40var decoded = "test";41var encoded = btoa(decoded);42console.log(encoded);
Using AI Code Generation
1var input = "SGVsbG8gV29ybGQh";2var output = atob(input);3console.log(output);4 var input = "SGVsbG8gV29ybGQh";5 var output = atob(input);6 console.log(output);7 var input = "SGVsbG8gV29ybGQh";8 var output = atob(input);9 console.log(output);10var input = "SGVsbG8gV29ybGQh";11var output = atob(input);12console.log(output);13 var input = "SGVsbG8gV29ybGQh";14 var output = atob(input);15 console.log(output);16var input = "SGVsbG8gV29ybGQh";17var output = atob(input);18console.log(output);19 var input = "SGVsbG8gV29ybGQh";20 var output = atob(input);21 console.log(output);22var input = "SGVsbG8gV29ybGQh";23var output = atob(input);24console.log(output);25 var input = "SGVsbG8gV29ybGQh";26 var output = atob(input);27 console.log(output);28var input = "SGVsbG8gV29ybGQh";29var output = atob(input);30console.log(output);
Using AI Code Generation
1var str = "test";2var encoded = btoa(str);3var decoded = atob(encoded);4console.log(encoded);5console.log(decoded);6encodeURI() and decodeURI() method7var encoded = encodeURI(str);8var decoded = decodeURI(encoded);9console.log(encoded);10console.log(decoded);11encodeURIComponent() and decodeURIComponent()12var encoded = encodeURIComponent(str);13var decoded = decodeURIComponent(encoded);14console.log(encoded);15console.log(decoded);
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!!