Best JavaScript code snippet using wpt
base64decode.js
Source:base64decode.js
1/*2 * JavaScript base64 / base64url encoder and decoder3 */45var b64c = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" // base64 dictionary6var b64u = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_" // base64url dictionary7var b64pad = '='89/* base64_encode_data10 * Internal helper to encode data to base64 using specified dictionary.11 */12function base64_encode_data(data, len, b64x) {13 var dst = ""14 var i1516 for (i = 0; i <= len - 3; i += 3)17 {18 dst += b64x.charAt(data.charCodeAt(i) >>> 2)19 dst += b64x.charAt(((data.charCodeAt(i) & 3) << 4) | (data.charCodeAt(i+1) >>> 4))20 dst += b64x.charAt(((data.charCodeAt(i+1) & 15) << 2) | (data.charCodeAt(i+2) >>> 6))21 dst += b64x.charAt(data.charCodeAt(i+2) & 63)22 }2324 if (len % 3 == 2)25 {26 dst += b64x.charAt(data.charCodeAt(i) >>> 2)27 dst += b64x.charAt(((data.charCodeAt(i) & 3) << 4) | (data.charCodeAt(i+1) >>> 4))28 dst += b64x.charAt(((data.charCodeAt(i+1) & 15) << 2))29 dst += b64pad30 }31 else if (len % 3 == 1)32 {33 dst += b64x.charAt(data.charCodeAt(i) >>> 2)34 dst += b64x.charAt(((data.charCodeAt(i) & 3) << 4))35 dst += b64pad36 dst += b64pad37 }3839 return dst40}4142/* base64_encode43 * Encode a JavaScript string to base64.44 * Specified string is first converted from JavaScript UCS-2 to UTF-8.45 */46function base64_encode(str) {47 var utf8str = unescape(encodeURIComponent(str))48 return base64_encode_data(utf8str, utf8str.length, b64c)49}5051/* base64url_encode52 * Encode a JavaScript string to base64url.53 * Specified string is first converted from JavaScript UCS-2 to UTF-8.54 */55function base64url_encode(str) {56 var utf8str = unescape(encodeURIComponent(str))57 return base64_encode_data(utf8str, utf8str.length, b64u)58}5960/* base64_charIndex61 * Internal helper to translate a base64 character to its integer index.62 */63function base64_charIndex(c) {64 if (c == "+") return 6265 if (c == "/") return 6366 return b64u.indexOf(c)67}6869/* base64_decode70 * Decode a base64 or base64url string to a JavaScript string.71 * Input is assumed to be a base64/base64url encoded UTF-8 string.72 * Returned result is a JavaScript (UCS-2) string.73 */74function base64_decode(data) {75 var dst = ""76 var i, a, b, c, d, z77 78 for (i = 0; i < data.length - 3; i += 4) {79 a = base64_charIndex(data.charAt(i+0))80 b = base64_charIndex(data.charAt(i+1))81 c = base64_charIndex(data.charAt(i+2))82 d = base64_charIndex(data.charAt(i+3))8384 dst += String.fromCharCode((a << 2) | (b >>> 4))85 if (data.charAt(i+2) != b64pad)86 dst += String.fromCharCode(((b << 4) & 0xF0) | ((c >>> 2) & 0x0F))87 if (data.charAt(i+3) != b64pad)88 dst += String.fromCharCode(((c << 6) & 0xC0) | d)89 }9091 dst = decodeURIComponent(escape(dst))92 return dst93}9495/* base64url_sniff96 * Check whether specified base64 string contains base64url specific characters.97 * Return true if specified string is base64url encoded, false otherwise.98 */99function base64url_sniff(base64) {100 if (base64.indexOf("-") >= 0) return true101 if (base64.indexOf("_") >= 0) return true102 return false
...
base64.js
Source:base64.js
1/*! (c) Tom Wu | http://www-cs-students.stanford.edu/~tjw/jsbn/2 */3var b64map="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";4var b64pad="=";5function hex2b64(h) {6 var i;7 var c;8 var ret = "";9 for(i = 0; i+3 <= h.length; i+=3) {10 c = parseInt(h.substring(i,i+3),16);11 ret += b64map.charAt(c >> 6) + b64map.charAt(c & 63);12 }13 if(i+1 == h.length) {14 c = parseInt(h.substring(i,i+1),16);15 ret += b64map.charAt(c << 2);16 }17 else if(i+2 == h.length) {18 c = parseInt(h.substring(i,i+2),16);19 ret += b64map.charAt(c >> 2) + b64map.charAt((c & 3) << 4);20 }21 if (b64pad) while((ret.length & 3) > 0) ret += b64pad;22 return ret;23}24// convert a base64 string to hex25function b64tohex(s) {26 var ret = ""27 var i;28 var k = 0; // b64 state, 0-329 var slop;30 var v;31 for(i = 0; i < s.length; ++i) {32 if(s.charAt(i) == b64pad) break;33 v = b64map.indexOf(s.charAt(i));34 if(v < 0) continue;35 if(k == 0) {36 ret += int2char(v >> 2);37 slop = v & 3;38 k = 1;39 }40 else if(k == 1) {41 ret += int2char((slop << 2) | (v >> 4));42 slop = v & 0xf;43 k = 2;44 }45 else if(k == 2) {46 ret += int2char(slop);47 ret += int2char(v >> 2);48 slop = v & 3;49 k = 3;50 }51 else {52 ret += int2char((slop << 2) | (v >> 4));53 ret += int2char(v & 0xf);54 k = 0;55 }56 }57 if(k == 1)58 ret += int2char(slop << 2);59 return ret;60}61// convert a base64 string to a byte/number array62function b64toBA(s) {63 //piggyback on b64tohex for now, optimize later64 var h = b64tohex(s);65 var i;66 var a = new Array();67 for(i = 0; 2*i < h.length; ++i) {68 a[i] = parseInt(h.substring(2*i,2*i+2),16);69 }70 return a;...
Using AI Code Generation
1var wptools = require('wptools');2var base64 = wptools.b64pad('test');3var wptools = require('wptools');4var base64 = wptools.b64pad('test');5var wptools = require('wptools');6var base64 = wptools.b64pad('test');7var wptools = require('wptools');8var base64 = wptools.b64pad('test');9var wptools = require('wptools');10var base64 = wptools.b64pad('test');11var wptools = require('wptools');12var base64 = wptools.b64pad('test');13var wptools = require('wptools');14var base64 = wptools.b64pad('test');15var wptools = require('wptools');16var base64 = wptools.b64pad('test');17var wptools = require('wptools');18var base64 = wptools.b64pad('test');19var wptools = require('wptools');20var base64 = wptools.b64pad('test');21var wptools = require('wptools');22var base64 = wptools.b64pad('test');23var wptools = require('wptools');24var base64 = wptools.b64pad('test');25var wptools = require('wptools');26var base64 = wptools.b64pad('test');27var wptools = require('wptools');
Using AI Code Generation
1var wptools = require('wptools');2var b64pad = wptools.b64pad;3var b64 = b64pad('hello world');4console.log(b64);5var wptools = require('wptools');6var b64unpad = wptools.b64unpad;7var b64 = b64unpad('aGVsbG8gd29ybGQ=');8console.log(b64);9var wptools = require('wptools');10var b64decode = wptools.b64decode;11var b64 = b64decode('aGVsbG8gd29ybGQ=');12console.log(b64);13var wptools = require('wptools');14var b64encode = wptools.b64encode;15var b64 = b64encode('hello world');16console.log(b64);17var wptools = require('wptools');18var b64decode = wptools.b64decode;19var b64 = b64decode('aGVsbG8gd29ybGQ=');20console.log(b64);21var wptools = require('wptools');22var b64encode = wptools.b64encode;23var b64 = b64encode('hello world');24console.log(b64);25var wptools = require('wptools');26var b64decode = wptools.b64decode;27var b64 = b64decode('aGVsbG8gd29ybGQ=');28console.log(b64);
Using AI Code Generation
1var wptools = require('wptools');2var b64 = wptools.b64pad('test');3console.log(b64);4var wptools = require('wptools');5var b64 = wptools.b64pad('test');6console.log(b64);
Using AI Code Generation
1var base64 = require('wptools').base64;2var b64 = base64.b64pad('Hello World');3console.log(b64);4var base64 = require('wptools').base64;5var b64 = base64.b64pad('Hello World');6console.log(b64);7var base64 = require('wptools').base64;8var b64 = base64.b64pad('Hello World');9console.log(b64);10var base64 = require('wptools').base64;11var b64 = base64.b64pad('Hello World');12console.log(b64);13var base64 = require('wptools').base64;14var b64 = base64.b64pad('Hello World');15console.log(b64);16var base64 = require('wptools').base64;17var b64 = base64.b64pad('Hello World');18console.log(b64);19var base64 = require('wptools').base64;20var b64 = base64.b64pad('Hello World');21console.log(b64);22var base64 = require('wptools').base64;23var b64 = base64.b64pad('Hello World');24console.log(b64);25var base64 = require('wptools').base64;26var b64 = base64.b64pad('Hello World');27console.log(b64);28var base64 = require('wptools').base64;29var b64 = base64.b64pad('Hello World');30console.log(b64);31var base64 = require('wptools').base64;32var b64 = base64.b64pad('Hello World');
Using AI Code Generation
1var wptools = require('wptools');2var str = 'This is a test string';3var b64 = wptools.b64pad(str);4console.log(b64);5var str2 = wptools.b64unpad(b64);6console.log(str2);7var str = 'This is a test string';8var b64 = wptools.b64pad(str);9console.log(b64);10var str2 = wptools.b64unpad(b64);11console.log(str2);12include('wptools.php');13$str = 'This is a test string';14$b64 = wptools::b64pad($str);15echo $b64;16$str2 = wptools::b64unpad($b64);17echo $str2;18include('wptools.php');19$str = 'This is a test string';20$b64 = wptools::b64pad($str);21echo $b64;22$str2 = wptools::b64unpad($b64);23echo $str2;
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!!