Best JavaScript code snippet using wpt
EHB_test.js
Source:EHB_test.js
1const ByteBit = require("../src/EHB/ByteBit");2describe ('ByteBit', () => {3 it('should accept very large number', () => {4 const byteBit = new ByteBit('1334441894813007682332945638531320916');5 //console.log( byteBit.toByteArray() ); // [ 16, 16, 84, 204, 244, 21, 79, 57, 168, 254, 187, 216, 95, 168, 16, 1, 1, 1 ]6 //console.log( byteBit.coffecient ); // [ 84, 204, 244, 21, 79, 57, 168, 254, 187, 216, 95, 168, 16, 1, 1, 1 ]7 expect( byteBit.toExponentString() ).toEqual('1.334441894813007682332945638531320916e+36');8 expect( byteBit.toExponentString(5) ).toEqual('1.33444e+36');9 expect( byteBit.toString() ).toEqual('1334441894813007682332945638531320916');10 });11 it('should accept small number', () => {12 const byteBit = new ByteBit('137');13 expect( byteBit.toString() ).toEqual('137');14 expect( byteBit.toByteArray() ).toEqual( [1, 137]);15 });16 it('should caclculate negative exponent for decimal point', () => {17 let byteBit = new ByteBit('1677700.217');18 // expect( byteBit.exponent ).toEqual(-3);19 // expect( byteBit.exponentInBytes ).toEqual([ 128 +3 ]);20 //console.log( byteBit.headByte );21 //console.log( byteBit.coffecient );22 expect( byteBit.toString() ).toEqual('1677700.217');23 //expect( byteBit.toByteArray() ).toEqual([ 64+5, 128+3, 121,172,255,99]);24 expect( byteBit.toByteArray() ).toEqual([ 101, 3, 121,172,255,99]);25 });26 27 it('should ignore trailing zeros for decimal point', () => {28 let byteBit = new ByteBit('1677700.21700000');29 expect( byteBit.toString() ).toEqual('1677700.217');30 expect( byteBit.toByteArray() ).toEqual( [101, 3, 121,172,255,99]);31 32 byteBit = new ByteBit('1677700217.00000');33 expect( byteBit.toString() ).toEqual('1677700217');34 expect( byteBit.toByteArray() ).toEqual( [4, 121,172,255,99]);35 });36 it('should not calculate exponent when there is no decimal point and trailing zeros', () => {37 let byteBit = new ByteBit('1677700217');38 expect( byteBit.toString() ).toEqual('1677700217');39 expect( byteBit.toByteArray() ).toEqual([4, 121,172,255,99]);40 expect( byteBit.exponent ).toEqual( 0 );41 expect( byteBit.exponentInBytes ).toEqual( [] );42 expect( byteBit.headByte ).toEqual(4);43 });44 it('should not calculate exponent when \'forceExponent\' is set to \'false\'', () => {45 let byteBit = new ByteBit('70000', {46 forceExponent: false47 });48 expect( byteBit.toString() ).toEqual('70000');49 expect( byteBit.toByteArray() ).toEqual([3, 112, 17, 1]);50 expect( byteBit.exponent ).toEqual( 0 );51 expect( byteBit.exponentInBytes ).toEqual( []);52 expect( byteBit.headByte ).toEqual(3);53 });54 it('should calculate exponent when \'forceExponent\' is not set or \'true\' ', () => {55 const byteBit = new ByteBit('70000');56 expect( byteBit.toString() ).toEqual('70000');57 expect( byteBit.toByteArray() ).toEqual([64 + 2, 4, 7]);58 expect( byteBit.exponent ).toEqual( 4 );59 expect( byteBit.exponentInBytes ).toEqual( [ 4 ] );60 expect( byteBit.headByte ).toEqual( 64+2);61 });62 it('should not calculate exponent when value is smaller than 65535 ', () => {63 const byteBit = new ByteBit('60000');64 expect( byteBit.toString() ).toEqual('60000');65 expect( byteBit.toByteArray() ).toEqual([2, 96, 234]);66 expect( byteBit.exponent ).toEqual( 0 );67 expect( byteBit.exponentInBytes ).toEqual( [] );68 expect( byteBit.headByte ).toEqual( 2 );69 });70 71 it('should calculate exponent for trialing zeros but should ignore zeros after decimal point', () => {72 let byteBit = new ByteBit('167770021700.00');73 expect( byteBit.toString() ).toEqual('167770021700');74 expect( byteBit.toByteArray() ).toEqual([64+5, 2, 121,172,255,99]);75 expect( byteBit.exponent ).toEqual( 2 );76 expect( byteBit.exponentInBytes ).toEqual( [2] );77 expect( byteBit.headByte ).toEqual(64 + 5);78 byteBit = new ByteBit('100.00');79 expect( byteBit.toString() ).toEqual('100');80 expect( byteBit.toByteArray() ).toEqual([1, 100]);81 });82 it('should accept negative numbers', () => {83 const byteBit = new ByteBit('-37');84 expect( byteBit.toString() ).toEqual('-37');85 expect( byteBit.toByteArray() ).toEqual( [128+1, 37]);86 expect( byteBit.headByte ).toEqual( 129 );87 });88 it('should accept negative decimal numbers', () => {89 const byteBit = new ByteBit('-3.7000');90 expect( byteBit.toString() ).toEqual('-3.7');91 expect( byteBit.toByteArray() ).toEqual( [128+64+32+2, 1, 37]);92 expect( byteBit.exponent ).toEqual( -1 );93 expect( byteBit.exponentInBytes ).toEqual( [ 1 ] );94 expect( byteBit.headByte ).toEqual( 128+64+32+2 );95 });96 it('should accept a number with long exponent value', () => {97 const byteBit = new ByteBit('3.141592653589791233455');98 99 //console.log( byteBit.toByteArray() ); // [ 106, 21, 175, 213, 81, 148, 145, 49, 91, 78, 170 ]100 //console.log( byteBit.coffecient ); //[ 175, 213, 81, 148, 145, 49, 91, 78, 170 ]101 expect( byteBit.toString() ).toEqual('3.141592653589791233455');102 expect( byteBit.toByteArray() ).toEqual( [ 64 + 32 + 10 , 21, 175, 213, 81, 148, 145, 49, 91, 78, 170 ] );103 expect( ByteBit.decode( byteBit.toByteArray() ).toString() ).toEqual( '3.141592653589791233455');104 expect( byteBit.exponent ).toEqual( -21 );105 expect( byteBit.exponentInBytes ).toEqual( [ 21 ] );106 expect( byteBit.headByte ).toEqual( 64 + 32 + 10 );107 });108 it('should throw error when all the bytes are not present', () => {109 ///const byteBit = new ByteBit('-3.7'); // [128+64+2, 128+1, 37]110 expect( () =>{111 ByteBit.decode( [128+64+2, 128+1] );112 }).toThrowError('Invalid EHB bytes sequence.');113 });...
HB_test.js
Source:HB_test.js
...6 });7 8 it('should accept very large number', () => {9 const byteBit = new ByteBit('131337515616165120231511215188');10 //console.log( byteBit.toByteArray() ); // [ 13, 84, 204, 244, 21, 79, 57, 168, 254, 187, 216, 95, 168, 1 ]11 //console.log( byteBit.coffecient ); // [ 84, 204, 244, 21, 79, 57, 168, 254, 187, 216, 95, 168, 1 ]12 expect( byteBit.toExponentString() ).toEqual('1.31337515616165120231511215188e+29');13 expect( byteBit.toExponentString(5) ).toEqual('1.31338e+29');14 expect( byteBit.toString() ).toEqual('131337515616165120231511215188');15 });16 it('should accept small number', () => {17 const byteBit = new ByteBit('37');18 expect( byteBit.toString() ).toEqual('37');19 expect( byteBit.toByteArray() ).toEqual( [1, 37]);20 });21 it('should calculate positive exponent', () => {22 const byteBit = new ByteBit('9007199254740990');23 //console.log( byteBit.toByteArray() ); // 24 //console.log( byteBit.coffecient ); // 25 expect( byteBit.toString() ).toEqual('9007199254740990');26 });27 it('should caclculate negative exponent for decimal point', () => {28 let byteBit = new ByteBit('1677700.217');29 // expect( byteBit.exponent ).toEqual(-3);30 // expect( byteBit.exponentInBytes ).toEqual([ 128 +3 ]);31 // expect( byteBit.headByte ).toEqual(64 + 5);32 expect( byteBit.toString() ).toEqual('1677700.217');33 expect( byteBit.toByteArray() ).toEqual([ 64+5, 128+3, 121,172,255,99]);34 });35 36 it('should ignore trailing zeros for decimal point', () => {37 let byteBit = new ByteBit('1677700.21700000');38 expect( byteBit.toString() ).toEqual('1677700.217');39 expect( byteBit.toByteArray() ).toEqual([ 64+5, 128+3, 121,172,255,99]);40 41 byteBit = new ByteBit('1677700217.00000');42 expect( byteBit.toString() ).toEqual('1677700217');43 expect( byteBit.toByteArray() ).toEqual([4, 121,172,255,99]);44 });45 it('should not calculate exponent when there is no decimal point and trailing zeros', () => {46 let byteBit = new ByteBit('1677700217');47 expect( byteBit.toString() ).toEqual('1677700217');48 expect( byteBit.toByteArray() ).toEqual([4, 121,172,255,99]);49 expect( byteBit.exponent ).toEqual( 0 );50 expect( byteBit.exponentInBytes ).toEqual( undefined);51 expect( byteBit.headByte ).toEqual(4);52 });53 it('should not calculate exponent when \'forceExponent\' is set to \'false\'', () => {54 let byteBit = new ByteBit('70000', {55 forceExponent: false56 });57 expect( byteBit.toString() ).toEqual('70000');58 expect( byteBit.toByteArray() ).toEqual([3, 112, 17, 1]);59 expect( byteBit.exponent ).toEqual( 0 );60 expect( byteBit.exponentInBytes ).toEqual( undefined);61 expect( byteBit.headByte ).toEqual(3);62 });63 it('should calculate exponent when \'forceExponent\' is not set or \'true\' ', () => {64 const byteBit = new ByteBit('70000');65 expect( byteBit.toString() ).toEqual('70000');66 expect( byteBit.toByteArray() ).toEqual([64 + 2, 4, 7]);67 expect( byteBit.exponent ).toEqual( 4 );68 expect( byteBit.exponentInBytes ).toEqual( 4 );69 expect( byteBit.headByte ).toEqual( 64+2);70 });71 it('should not calculate exponent when value is smaller than 65535 ', () => {72 const byteBit = new ByteBit('60000');73 expect( byteBit.toString() ).toEqual('60000');74 expect( byteBit.toByteArray() ).toEqual([2, 96, 234]);75 expect( byteBit.exponent ).toEqual( 0 );76 expect( byteBit.exponentInBytes ).toEqual( undefined );77 expect( byteBit.headByte ).toEqual( 2 );78 });79 80 it('should calculate exponent for trialing zeros but should ignore zeros after decimal point', () => {81 let byteBit = new ByteBit('167770021700.00');82 expect( byteBit.toString() ).toEqual('167770021700');83 expect( byteBit.toByteArray() ).toEqual([64+5, 2, 121,172,255,99]);84 expect( byteBit.exponent ).toEqual( 2 );85 expect( byteBit.exponentInBytes ).toEqual( 2 );86 expect( byteBit.headByte ).toEqual(64 + 5);87 byteBit = new ByteBit('100.00');88 expect( byteBit.toString() ).toEqual('100');89 expect( byteBit.toByteArray() ).toEqual([1, 100]);90 });91 it('should accept negative numbers', () => {92 const byteBit = new ByteBit('-37');93 expect( byteBit.toString() ).toEqual('-37');94 expect( byteBit.toByteArray() ).toEqual( [128+1, 37]);95 expect( byteBit.headByte ).toEqual( 129 );96 });97 it('should accept negative decimal numbers', () => {98 const byteBit = new ByteBit('-3.7000');99 expect( byteBit.toString() ).toEqual('-3.7');100 expect( byteBit.toByteArray() ).toEqual( [128+64+2, 128+1, 37]);101 expect( ByteBit.decode( byteBit.toByteArray() ).toString() ).toEqual('-3.7');102 expect( byteBit.exponent ).toEqual( -1 );103 expect( byteBit.exponentInBytes ).toEqual( 128+1 );104 expect( byteBit.headByte ).toEqual( 128+64+2 );105 });106 it('should throw error when all the bytes are not present', () => {107 //const byteBit = new ByteBit('-3.7'); // [128+64+2, 128+1, 37]108 expect( () =>{109 ByteBit.decode( [128+64+2, 128+1] );110 }).toThrowError('Invalid HB Bytes sequence. All coffecient bytes are not present.');111 });...
forgeExample.ts
Source:forgeExample.ts
...38function forgeKeyToJwk(key: forge.pki.rsa.PrivateKey): JWKInterface {39 const { n, e, d, p, q, dP, dQ, qInv } = key;40 return {41 kty: "RSA",42 n: Buffer.from(n.toByteArray()).toString("base64"),43 e: Buffer.from(e.toByteArray()).toString("base64"),44 d: Buffer.from(d.toByteArray()).toString("base64"),45 p: Buffer.from(p.toByteArray()).toString("base64"),46 q: Buffer.from(q.toByteArray()).toString("base64"),47 dp: Buffer.from(dP.toByteArray()).toString("base64"),48 dq: Buffer.from(dQ.toByteArray()).toString("base64"),49 qi: Buffer.from(qInv.toByteArray()).toString("base64"),50 };51}52/**53 * Achieve the same result as the self executing function of `src/index.ts` but with node-forge54 */55export async function forgeExample() {56 console.log("generating the using forge key...");57 const time = Date.now();58 const key = await generateKey();59 console.log("generated the key in", (Date.now() - time) / 1000, "seconds");60 const jwk = forgeKeyToJwk(key.privateKey);61 const isKeyValid = await testJwk(jwk);62 if (isKeyValid) {63 console.log("the generated key is valid");...
Using AI Code Generation
1var wptools = require('wptools');2var wp = new wptools();3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var wptools = require('wptools');10var wp = new wptools();11 if (err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17var wptools = require('wptools');18var wp = new wptools();19 if (err) {20 console.log(err);21 } else {22 console.log(data);23 }24});25var wptools = require('wptools');26var wp = new wptools();27 if (err) {28 console.log(err);29 } else {30 console.log(data);31 }32});33var wptools = require('wptools');34var wp = new wptools();35 if (err) {36 console.log(err);37 } else {38 console.log(data);39 }40});41var wptools = require('wptools');42var wp = new wptools();43 if (err) {44 console.log(err);45 } else {46 console.log(data);47 }48});49var wptools = require('wptools');50var wp = new wptools();
Using AI Code Generation
1var enc = new TextEncoder();2var arr = enc.encode("Hello World");3console.log(arr);4var dec = new TextDecoder();5console.log(dec.decode(arr));6var buffer = new Buffer("Hello World");7console.log(buffer);
Using AI Code Generation
1var wptools = require('wptools');2var fs = require('fs');3var page = wptools.page('Barack Obama');4page.get(function(err, resp) {5 var image = resp.imageinfo[0];6 var data = new Buffer(image.thumburl, 'base64');7 fs.writeFileSync('image.png', data);8});9{10 "dependencies": {11 }12}
Using AI Code Generation
1var wptools = require('wptools');2pdf.toBuffer(function(err, buffer) {3 if (err) {4 console.log(err);5 return;6 }7 console.log(buffer.toString('base64'));8});9var wptools = require('wptools');10pdf.toPdf(function(err, buffer) {11 if (err) {12 console.log(err);13 return;14 }15 console.log(buffer.toString('base64'));16});17var wptools = require('wptools');18pdf.toImage(function(err, buffer) {19 if (err) {20 console.log(err);21 return;22 }23 console.log(buffer.toString('base64'));24});25var wptools = require('wptools');26pdf.toPdf(function(err, buffer) {27 if (err) {28 console.log(err);29 return;30 }31 console.log(buffer.toString('base64'));32});33var wptools = require('wpt
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!!