Best JavaScript code snippet using wpt
helpers.js
Source:helpers.js
...24// Treats an array as a set, and generates an array of all non-empty25// subsets (which are themselves arrays).26//27// The order of members of the "subsets" is not guaranteed.28function allNonemptySubsetsOf(arr) {29 var results = [];30 var firstElement;31 var remainingElements;32 for(var i=0; i<arr.length; i++) {33 firstElement = arr[i];34 remainingElements = arr.slice(i+1);35 results.push([firstElement]);36 if (remainingElements.length > 0) {37 allNonemptySubsetsOf(remainingElements).forEach(function(combination) {38 combination.push(firstElement);39 results.push(combination);40 });41 }42 }43 return results;44}45// Create a string representation of keyGeneration parameters for46// test names and labels.47function objectToString(obj) {48 var keyValuePairs = [];49 if (Array.isArray(obj)) {50 return "[" + obj.map(function(elem){return objectToString(elem);}).join(", ") + "]";51 } else if (typeof obj === "object") {52 Object.keys(obj).sort().forEach(function(keyName) {53 keyValuePairs.push(keyName + ": " + objectToString(obj[keyName]));54 });55 return "{" + keyValuePairs.join(", ") + "}";56 } else if (typeof obj === "undefined") {57 return "undefined";58 } else {59 return obj.toString();60 }61 var keyValuePairs = [];62 Object.keys(obj).sort().forEach(function(keyName) {63 var value = obj[keyName];64 if (typeof value === "object") {65 value = objectToString(value);66 } else if (typeof value === "array") {67 value = "[" + value.map(function(elem){return objectToString(elem);}).join(", ") + "]";68 } else {69 value = value.toString();70 }71 keyValuePairs.push(keyName + ": " + value);72 });73 return "{" + keyValuePairs.join(", ") + "}";74}75// Is key a CryptoKey object with correct algorithm, extractable, and usages?76// Is it a secret, private, or public kind of key?77function assert_goodCryptoKey(key, algorithm, extractable, usages, kind) {78 var correctUsages = [];79 var registeredAlgorithmName;80 registeredAlgorithmNames.forEach(function(name) {81 if (name.toUpperCase() === algorithm.name.toUpperCase()) {82 registeredAlgorithmName = name;83 }84 });85 assert_equals(key.constructor, CryptoKey, "Is a CryptoKey");86 assert_equals(key.type, kind, "Is a " + kind + " key");87 if (key.type === "public") {88 extractable = true; // public keys are always extractable89 }90 assert_equals(key.extractable, extractable, "Extractability is correct");91 assert_equals(key.algorithm.name, registeredAlgorithmName, "Correct algorithm name");92 assert_equals(key.algorithm.length, algorithm.length, "Correct length");93 if (["HMAC", "RSASSA-PKCS1-v1_5", "RSA-PSS"].includes(registeredAlgorithmName)) {94 assert_equals(key.algorithm.hash.name.toUpperCase(), algorithm.hash.toUpperCase(), "Correct hash function");95 }96 // usages is expected to be provided for a key pair, but we are checking97 // only a single key. The publicKey and privateKey portions of a key pair98 // recognize only some of the usages appropriate for a key pair.99 if (key.type === "public") {100 ["encrypt", "verify", "wrapKey"].forEach(function(usage) {101 if (usages.includes(usage)) {102 correctUsages.push(usage);103 }104 });105 } else if (key.type === "private") {106 ["decrypt", "sign", "unwrapKey", "deriveKey", "deriveBits"].forEach(function(usage) {107 if (usages.includes(usage)) {108 correctUsages.push(usage);109 }110 });111 } else {112 correctUsages = usages;113 }114 assert_equals((typeof key.usages), "object", key.type + " key.usages is an object");115 assert_not_equals(key.usages, null, key.type + " key.usages isn't null");116 // The usages parameter could have repeats, but the usages117 // property of the result should not.118 var usageCount = 0;119 key.usages.forEach(function(usage) {120 usageCount += 1;121 assert_in_array(usage, correctUsages, "Has " + usage + " usage");122 });123 assert_equals(key.usages.length, usageCount, "usages property is correct");124}125// The algorithm parameter is an object with a name and other126// properties. Given the name, generate all valid parameters.127function allAlgorithmSpecifiersFor(algorithmName) {128 var results = [];129 // RSA key generation is slow. Test a minimal set of parameters130 var hashes = ["SHA-1", "SHA-256"];131 // EC key generation is a lot faster. Check all curves in the spec132 var curves = ["P-256", "P-384", "P-521"];133 if (algorithmName.toUpperCase().substring(0, 3) === "AES") {134 // Specifier properties are name and length135 [128, 192, 256].forEach(function(length) {136 results.push({name: algorithmName, length: length});137 });138 } else if (algorithmName.toUpperCase() === "HMAC") {139 [140 {name: "SHA-1", length: 160},141 {name: "SHA-256", length: 256},142 {name: "SHA-384", length: 384},143 {name: "SHA-512", length: 512}144 ].forEach(function(hashAlgorithm) {145 results.push({name: algorithmName, hash: hashAlgorithm.name, length: hashAlgorithm.length});146 });147 } else if (algorithmName.toUpperCase().substring(0, 3) === "RSA") {148 hashes.forEach(function(hashName) {149 results.push({name: algorithmName, hash: hashName, modulusLength: 2048, publicExponent: new Uint8Array([1,0,1])});150 });151 } else if (algorithmName.toUpperCase().substring(0, 2) === "EC") {152 curves.forEach(function(curveName) {153 results.push({name: algorithmName, namedCurve: curveName});154 });155 }156 return results;157}158// Create every possible valid usages parameter, given legal159// usages. Note that an empty usages parameter is not always valid.160//161// There is an optional parameter - mandatoryUsages. If provided,162// it should be an array containing those usages of which one must be163// included.164function allValidUsages(validUsages, emptyIsValid, mandatoryUsages) {165 if (typeof mandatoryUsages === "undefined") {166 mandatoryUsages = [];167 }168 okaySubsets = [];169 allNonemptySubsetsOf(validUsages).forEach(function(subset) {170 if (mandatoryUsages.length === 0) {171 okaySubsets.push(subset);172 } else {173 for (var i=0; i<mandatoryUsages.length; i++) {174 if (subset.includes(mandatoryUsages[i])) {175 okaySubsets.push(subset);176 return;177 }178 }179 }180 });181 if (emptyIsValid) {182 okaySubsets.push([]);183 }...
Using AI Code Generation
1var wptools = require('wptools');2var allNonemptySubsetsOf = wptools.allNonemptySubsetsOf;3var allSubsetsOf = wptools.allSubsetsOf;4var allCombinationsOf = wptools.allCombinationsOf;5var array = [1, 2, 3, 4, 5];6var subsets = allNonemptySubsetsOf(array);7console.log(subsets);8var subsets = allSubsetsOf(array);9console.log(subsets);10var subsets = allCombinationsOf(array);11console.log(subsets);12var subsets = allCombinationsOf(array, 3);13console.log(subsets);14var subsets = allCombinationsOf(array, [3, 4]);15console.log(subsets);16var subsets = allCombinationsOf(array, [3, 4, 5]);17console.log(subsets);18var subsets = allCombinationsOf(array, [3, 4, 5, 6]);19console.log(subsets);20var subsets = allCombinationsOf(array, [3, 4, 5, 6, 7]);21console.log(subsets);22var subsets = allCombinationsOf(array, [3, 4, 5, 6, 7, 8]);23console.log(subsets);24var subsets = allCombinationsOf(array, [3, 4, 5, 6, 7, 8, 9]);25console.log(subsets);
Using AI Code Generation
1var wptools = require('wptools');2var allNonemptySubsetsOf = wptools.allNonemptySubsetsOf;3var a = [1,2,3,4,5];4var b = allNonemptySubsetsOf(a);5console.log(b);6var wptools = require('wptools');7var allNonemptySubsetsOf = wptools.allNonemptySubsetsOf;8var a = [1,2,3,4,5];9var b = allNonemptySubsetsOf(a);10console.log(b);
Using AI Code Generation
1var wptools = require('wptools');2var array = ['a', 'b', 'c'];3var subsets = wptools.allNonemptySubsetsOf(array);4console.log(subsets);5var wptools = require('wptools');6var array = ['a', 'b', 'c'];7var subsets = wptools.allNonemptySubsetsOf(array, 2);8console.log(subsets);9var wptools = require('wptools');10var array = ['a', 'b', 'c'];11var subsets = wptools.allNonemptySubsetsOf(array, 2, 3);12console.log(subsets);13var wptools = require('wptools');14var array = ['a', 'b', 'c'];15var subsets = wptools.allNonemptySubsetsOf(array, 2, 3, 1);16console.log(subsets);17var wptools = require('wptools');18var array = ['a', 'b', 'c'];19var subsets = wptools.allNonemptySubsetsOf(array, 2, 3, 1, 0);20console.log(subsets);21var wptools = require('wptools');22var array = ['a', 'b', 'c'];23var subsets = wptools.allNonemptySubsetsOf(array, 2, 3, 1, 0, 4);24console.log(subsets);25var wptools = require('wptools');26var array = ['a', 'b', 'c'];27var subsets = wptools.allNonemptySubsetsOf(array, 2, 3, 1, 0, 4, 5);28console.log(subsets);
Using AI Code Generation
1var wptools = require('wptools');2var test = wptools.allNonemptySubsetsOf([1,2,3,4,5]);3console.log(test);4var wptools = require('wptools');5var test = wptools.allNonemptySubsetsOf([1,2,3,4,5], 2);6console.log(test);7var wptools = require('wptools');8var test = wptools.allNonemptySubsetsOf([1,2,3,4,5], 2, 3);9console.log(test);10var wptools = require('wptools');11var test = wptools.allNonemptySubsetsOf([1,2,3,4,5], 2, 3, 10);12console.log(test);13var wptools = require('wptools');14var test = wptools.allNonemptySubsetsOf([1,2,3,4,5], 2, 3, 10, 1);15console.log(test);16var wptools = require('wptools');17var test = wptools.allNonemptySubsetsOf([1,2,3,4,5], 2, 3, 10, 1, 2);18console.log(test);19var wptools = require('wptools');20var test = wptools.allNonemptySubsetsOf([1,2,3,4,5], 2, 3, 10, 1, 2, 3);21console.log(test);22var wptools = require('
Using AI Code Generation
1var wptools = require("wptools");2var a = wptools.allNonemptySubsetsOf([1,2,3,4]);3var wptools = require("wptools");4var a = wptools.allNonemptySubsetsOf([1,2,3,4]);5var wptools = require("wptools");6var a = wptools.allNonemptySubsetsOf([1,2,3,4]);7var wptools = require("wptools");8var a = wptools.allNonemptySubsetsOf([1,2,3,4]);
Using AI Code Generation
1var wpt = require('wpt');2var a = [1,2,3,4,5];3var b = wpt.allNonemptySubsetsOf(a);4console.log(b);5var wpt = require('wpt');6var a = [1,2,3,4,5];7var b = wpt.allNonemptySubsetsOf(a);8console.log(b);9var wpt = require('wpt');10var a = [1,2,3,4,5];11var b = wpt.allNonemptySubsetsOf(a);12console.log(b);13var wpt = require('wpt');14var a = [1,2,3,4,5];15var b = wpt.allNonemptySubsetsOf(a);16console.log(b);17var wpt = require('wpt');18var a = [1,2,3,4,5];19var b = wpt.allNonemptySubsetsOf(a);20console.log(b);21var wpt = require('wpt');22var a = [1,2,3,4,5];23var b = wpt.allNonemptySubsetsOf(a);24console.log(b);25var wpt = require('wpt');26var a = [1,2,3,4,5];27var b = wpt.allNonemptySubsetsOf(a);28console.log(b);29var wpt = require('wpt');30var a = [1,2,3,4,5];31var b = wpt.allNonemptySubsetsOf(a);32console.log(b);
Using AI Code Generation
1var wpt = require('wpt.js');2var arr = ['a','b','c'];3var subsets = wpt.allNonemptySubsetsOf(arr);4console.log(subsets);5var wpt = require('wpt.js');6var arr = ['a','b','c'];7var pairs = wpt.allOrderedPairsOf(arr);8console.log(pairs);9var wpt = require('wpt.js');10var arr = ['a','b','c'];11var subsets = wpt.allSubsetsOf(arr);12console.log(subsets);13var wpt = require('wpt.js');14var arr = ['a','b','c'];15var subsets = wpt.allUniqueSubsetsOf(arr);16console.log(subsets);17var wpt = require('wpt.js');18var arr = ['a','b','c'];19var pairs = wpt.allUniqueOrderedPairsOf(arr);20console.log(pairs);
Using AI Code Generation
1var wpt = require('./wpt.js');2var allSubsets = wpt.allNonemptySubsetsOf([1,2,3,4]);3console.log(allSubsets);4var wpt = require('./wpt.js');5var allSubsets = wpt.allNonemptySubsetsOf([1,2,3,4]);6console.log(allSubsets);7var wpt = require('./wpt.js');8var allSubsets = wpt.allNonemptySubsetsOf([1,2,3,4]);9console.log(allSubsets);
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!!