How to use hex method in wpt

Best JavaScript code snippet using wpt

15.1.2.2-1.js

Source:15.1.2.2-1.js Github

copy

Full Screen

1/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */2/* This Source Code Form is subject to the terms of the Mozilla Public3 * License, v. 2.0. If a copy of the MPL was not distributed with this4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */5gTestfile = '15.1.2.2-1.js';6/**7 File Name: 15.1.2.2-1.js8 ECMA Section: 15.1.2.2 Function properties of the global object9 parseInt( string, radix )10 Description:11 The parseInt function produces an integer value dictated by intepretation12 of the contents of the string argument according to the specified radix.13 When the parseInt function is called, the following steps are taken:14 1. Call ToString(string).15 2. Compute a substring of Result(1) consisting of the leftmost character16 that is not a StrWhiteSpaceChar and all characters to the right of17 that character. (In other words, remove leading whitespace.)18 3. Let sign be 1.19 4. If Result(2) is not empty and the first character of Result(2) is a20 minus sign -, let sign be -1.21 5. If Result(2) is not empty and the first character of Result(2) is a22 plus sign + or a minus sign -, then Result(5) is the substring of23 Result(2) produced by removing the first character; otherwise, Result(5)24 is Result(2).25 6. If the radix argument is not supplied, go to step 12.26 7. Call ToInt32(radix).27 8. If Result(7) is zero, go to step 12; otherwise, if Result(7) < 2 or28 Result(7) > 36, return NaN.29 9. Let R be Result(7).30 10. If R = 16 and the length of Result(5) is at least 2 and the first two31 characters of Result(5) are either "0x" or "0X", let S be the substring32 of Result(5) consisting of all but the first two characters; otherwise,33 let S be Result(5).34 11. Go to step 22.35 12. If Result(5) is empty or the first character of Result(5) is not 0,36 go to step 20.37 13. If the length of Result(5) is at least 2 and the second character of38 Result(5) is x or X, go to step 17.39 14. Let R be 8.40 15. Let S be Result(5).41 16. Go to step 22.42 17. Let R be 16.43 18. Let S be the substring of Result(5) consisting of all but the first44 two characters.45 19. Go to step 22.46 20. Let R be 10.47 21. Let S be Result(5).48 22. If S contains any character that is not a radix-R digit, then let Z be49 the substring of S consisting of all characters to the left of the50 leftmost such character; otherwise, let Z be S.51 23. If Z is empty, return NaN.52 24. Compute the mathematical integer value that is represented by Z in53 radix-R notation. (But if R is 10 and Z contains more than 2054 significant digits, every digit after the 20th may be replaced by a 055 digit, at the option of the implementation; and if R is not 2, 4, 8,56 10, 16, or 32, then Result(24) may be an implementation-dependent57 approximation to the mathematical integer value that is represented58 by Z in radix-R notation.)59 25. Compute the number value for Result(24).60 26. Return sign Result(25).61 Note that parseInt may interpret only a leading portion of the string as62 an integer value; it ignores any characters that cannot be interpreted as63 part of the notation of an integer, and no indication is given that any64 such characters were ignored.65 Author: christine@netscape.com66 Date: 28 october 199767*/68var SECTION = "15.1.2.2-1";69var VERSION = "ECMA_1";70var TITLE = "parseInt(string, radix)";71var BUGNUMBER = "none";72startTest();73writeHeaderToLog( SECTION + " "+ TITLE);74var HEX_STRING = "0x0";75var HEX_VALUE = 0;76new TestCase( SECTION, 77 "parseInt.length", 78 2, 79 parseInt.length );80new TestCase( SECTION, 81 "parseInt.length = 0; parseInt.length", 82 2, 83 eval("parseInt.length = 0; parseInt.length") );84new TestCase( SECTION, 85 "var PROPS=''; for ( var p in parseInt ) { PROPS += p; }; PROPS", "prototype",86 eval("var PROPS=''; for ( var p in parseInt ) { PROPS += p; }; PROPS") );87new TestCase( SECTION, 88 "delete parseInt.length", 89 false, 90 delete parseInt.length );91new TestCase( SECTION, 92 "delete parseInt.length; parseInt.length", 93 2, 94 eval("delete parseInt.length; parseInt.length") );95new TestCase( SECTION, 96 "parseInt.length = null; parseInt.length", 97 2, 98 eval("parseInt.length = null; parseInt.length") );99new TestCase( SECTION, 100 "parseInt()", 101 NaN, 102 parseInt() );103new TestCase( SECTION, 104 "parseInt('')", 105 NaN, 106 parseInt("") );107new TestCase( SECTION, 108 "parseInt('','')", 109 NaN, 110 parseInt("","") );111new TestCase( SECTION,112 "parseInt(\" 0xabcdef ",113 11259375,114 parseInt( " 0xabcdef " ));115new TestCase( SECTION,116 "parseInt(\" 0XABCDEF ",117 11259375,118 parseInt( " 0XABCDEF " ) );119new TestCase( SECTION,120 "parseInt( 0xabcdef )",121 11259375,122 parseInt( "0xabcdef") );123new TestCase( SECTION,124 "parseInt( 0XABCDEF )",125 11259375,126 parseInt( "0XABCDEF") );127for ( HEX_STRING = "0x0", HEX_VALUE = 0, POWER = 0; POWER < 15; POWER++, HEX_STRING = HEX_STRING +"f" ) {128 new TestCase( SECTION, "parseInt("+HEX_STRING+")", HEX_VALUE, parseInt(HEX_STRING) );129 HEX_VALUE += Math.pow(16,POWER)*15;130}131for ( HEX_STRING = "0X0", HEX_VALUE = 0, POWER = 0; POWER < 15; POWER++, HEX_STRING = HEX_STRING +"f" ) {132 new TestCase( SECTION, "parseInt("+HEX_STRING+")", HEX_VALUE, parseInt(HEX_STRING) );133 HEX_VALUE += Math.pow(16,POWER)*15;134}135for ( HEX_STRING = "0x0", HEX_VALUE = 0, POWER = 0; POWER < 15; POWER++, HEX_STRING = HEX_STRING +"f" ) {136 new TestCase( SECTION, "parseInt("+HEX_STRING+",16)", HEX_VALUE, parseInt(HEX_STRING,16) );137 HEX_VALUE += Math.pow(16,POWER)*15;138}139for ( HEX_STRING = "0x0", HEX_VALUE = 0, POWER = 0; POWER < 15; POWER++, HEX_STRING = HEX_STRING +"f" ) {140 new TestCase( SECTION, "parseInt("+HEX_STRING+",16)", HEX_VALUE, parseInt(HEX_STRING,16) );141 HEX_VALUE += Math.pow(16,POWER)*15;142}143for ( HEX_STRING = "0x0", HEX_VALUE = 0, POWER = 0; POWER < 15; POWER++, HEX_STRING = HEX_STRING +"f" ) {144 new TestCase( SECTION, "parseInt("+HEX_STRING+",null)", HEX_VALUE, parseInt(HEX_STRING,null) );145 HEX_VALUE += Math.pow(16,POWER)*15;146}147for ( HEX_STRING = "0x0", HEX_VALUE = 0, POWER = 0; POWER < 15; POWER++, HEX_STRING = HEX_STRING +"f" ) {148 new TestCase( SECTION, "parseInt("+HEX_STRING+", void 0)", HEX_VALUE, parseInt(HEX_STRING, void 0) );149 HEX_VALUE += Math.pow(16,POWER)*15;150}151// a few tests with spaces152for ( var space = " ", HEX_STRING = "0x0", HEX_VALUE = 0, POWER = 0;153 POWER < 15;154 POWER++, HEX_STRING = HEX_STRING +"f", space += " ")155{156 new TestCase( SECTION, "parseInt("+space+HEX_STRING+space+", void 0)", HEX_VALUE, parseInt(space+HEX_STRING+space, void 0) );157 HEX_VALUE += Math.pow(16,POWER)*15;158}159// a few tests with negative numbers160for ( HEX_STRING = "-0x0", HEX_VALUE = 0, POWER = 0; POWER < 15; POWER++, HEX_STRING = HEX_STRING +"f" ) {161 new TestCase( SECTION, "parseInt("+HEX_STRING+")", HEX_VALUE, parseInt(HEX_STRING) );162 HEX_VALUE -= Math.pow(16,POWER)*15;163}164// we should stop parsing when we get to a value that is not a numeric literal for the type we expect165for ( HEX_STRING = "0x0", HEX_VALUE = 0, POWER = 0; POWER < 15; POWER++, HEX_STRING = HEX_STRING +"f" ) {166 new TestCase( SECTION, "parseInt("+HEX_STRING+"g,16)", HEX_VALUE, parseInt(HEX_STRING+"g",16) );167 HEX_VALUE += Math.pow(16,POWER)*15;168}169for ( HEX_STRING = "0x0", HEX_VALUE = 0, POWER = 0; POWER < 15; POWER++, HEX_STRING = HEX_STRING +"f" ) {170 new TestCase( SECTION, "parseInt("+HEX_STRING+"g,16)", HEX_VALUE, parseInt(HEX_STRING+"G",16) );171 HEX_VALUE += Math.pow(16,POWER)*15;172}173for ( HEX_STRING = "-0x0", HEX_VALUE = 0, POWER = 0; POWER < 15; POWER++, HEX_STRING = HEX_STRING +"f" ) {174 new TestCase( SECTION, "parseInt("+HEX_STRING+")", HEX_VALUE, parseInt(HEX_STRING) );175 HEX_VALUE -= Math.pow(16,POWER)*15;176}177for ( HEX_STRING = "-0X0", HEX_VALUE = 0, POWER = 0; POWER < 15; POWER++, HEX_STRING = HEX_STRING +"f" ) {178 new TestCase( SECTION, "parseInt("+HEX_STRING+")", HEX_VALUE, parseInt(HEX_STRING) );179 HEX_VALUE -= Math.pow(16,POWER)*15;180}181for ( HEX_STRING = "-0x0", HEX_VALUE = 0, POWER = 0; POWER < 15; POWER++, HEX_STRING = HEX_STRING +"f" ) {182 new TestCase( SECTION, "parseInt("+HEX_STRING+",16)", HEX_VALUE, parseInt(HEX_STRING,16) );183 HEX_VALUE -= Math.pow(16,POWER)*15;184}185for ( HEX_STRING = "-0x0", HEX_VALUE = 0, POWER = 0; POWER < 15; POWER++, HEX_STRING = HEX_STRING +"f" ) {186 new TestCase( SECTION, "parseInt("+HEX_STRING+",16)", HEX_VALUE, parseInt(HEX_STRING,16) );187 HEX_VALUE -= Math.pow(16,POWER)*15;188}189// let us do some octal tests. numbers that start with 0 and do not provid a radix should190// default to using "0" as a radix.191var OCT_STRING = "0";192var OCT_VALUE = 0;193for ( OCT_STRING = "0", OCT_VALUE = 0, POWER = 0; POWER < 15; POWER++, OCT_STRING = OCT_STRING +"7" ) {194 new TestCase( SECTION, "parseInt("+OCT_STRING+")", OCT_VALUE, parseInt(OCT_STRING) );195 OCT_VALUE += Math.pow(8,POWER)*7;196}197for ( OCT_STRING = "-0", OCT_VALUE = 0, POWER = 0; POWER < 15; POWER++, OCT_STRING = OCT_STRING +"7" ) {198 new TestCase( SECTION, "parseInt("+OCT_STRING+")", OCT_VALUE, parseInt(OCT_STRING) );199 OCT_VALUE -= Math.pow(8,POWER)*7;200}201// should get the same results as above if we provid the radix of 8 (or 010)202for ( OCT_STRING = "0", OCT_VALUE = 0, POWER = 0; POWER < 15; POWER++, OCT_STRING = OCT_STRING +"7" ) {203 new TestCase( SECTION, "parseInt("+OCT_STRING+",8)", OCT_VALUE, parseInt(OCT_STRING,8) );204 OCT_VALUE += Math.pow(8,POWER)*7;205}206for ( OCT_STRING = "-0", OCT_VALUE = 0, POWER = 0; POWER < 15; POWER++, OCT_STRING = OCT_STRING +"7" ) {207 new TestCase( SECTION, "parseInt("+OCT_STRING+",010)", OCT_VALUE, parseInt(OCT_STRING,010) );208 OCT_VALUE -= Math.pow(8,POWER)*7;209}210// we shall stop parsing digits when we get one that isn't a numeric literal of the type we think211// it should be.212for ( OCT_STRING = "0", OCT_VALUE = 0, POWER = 0; POWER < 15; POWER++, OCT_STRING = OCT_STRING +"7" ) {213 new TestCase( SECTION, "parseInt("+OCT_STRING+"8,8)", OCT_VALUE, parseInt(OCT_STRING+"8",8) );214 OCT_VALUE += Math.pow(8,POWER)*7;215}216for ( OCT_STRING = "-0", OCT_VALUE = 0, POWER = 0; POWER < 15; POWER++, OCT_STRING = OCT_STRING +"7" ) {217 new TestCase( SECTION, "parseInt("+OCT_STRING+"8,010)", OCT_VALUE, parseInt(OCT_STRING+"8",010) );218 OCT_VALUE -= Math.pow(8,POWER)*7;219}220new TestCase( SECTION,221 "parseInt( '0x' )", 222 NaN, 223 parseInt("0x") );224new TestCase( SECTION,225 "parseInt( '0X' )", 226 NaN, 227 parseInt("0X") );228new TestCase( SECTION,229 "parseInt( '11111111112222222222' )", 230 11111111112222222222, 231 parseInt("11111111112222222222") );232new TestCase( SECTION,233 "parseInt( '111111111122222222223' )", 234 111111111122222222220, 235 parseInt("111111111122222222223") );236new TestCase( SECTION,237 "parseInt( '11111111112222222222',10 )", 238 11111111112222222222, 239 parseInt("11111111112222222222",10) );240new TestCase( SECTION,241 "parseInt( '111111111122222222223',10 )", 242 111111111122222222220, 243 parseInt("111111111122222222223",10) );244new TestCase( SECTION,245 "parseInt( '01234567890', -1 )", 246 Number.NaN, 247 parseInt("01234567890",-1) );248new TestCase( SECTION,249 "parseInt( '01234567890', 0 )", 250 Number.NaN, 251 parseInt("01234567890",1) );252new TestCase( SECTION,253 "parseInt( '01234567890', 1 )", 254 Number.NaN, 255 parseInt("01234567890",1) );256new TestCase( SECTION,257 "parseInt( '01234567890', 2 )", 258 1, 259 parseInt("01234567890",2) );260new TestCase( SECTION,261 "parseInt( '01234567890', 3 )", 262 5, 263 parseInt("01234567890",3) );264new TestCase( SECTION,265 "parseInt( '01234567890', 4 )", 266 27, 267 parseInt("01234567890",4) );268new TestCase( SECTION,269 "parseInt( '01234567890', 5 )", 270 194, 271 parseInt("01234567890",5) );272new TestCase( SECTION,273 "parseInt( '01234567890', 6 )", 274 1865, 275 parseInt("01234567890",6) );276new TestCase( SECTION,277 "parseInt( '01234567890', 7 )", 278 22875, 279 parseInt("01234567890",7) );280new TestCase( SECTION,281 "parseInt( '01234567890', 8 )", 282 342391, 283 parseInt("01234567890",8) );284new TestCase( SECTION,285 "parseInt( '01234567890', 9 )", 286 6053444, 287 parseInt("01234567890",9) );288new TestCase( SECTION,289 "parseInt( '01234567890', 10 )",290 1234567890, 291 parseInt("01234567890",10) );292// need more test cases with hex radix293new TestCase( SECTION,294 "parseInt( '1234567890', '0xa')",295 1234567890,296 parseInt("1234567890","0xa") );297new TestCase( SECTION,298 "parseInt( '012345', 11 )", 299 17715, 300 parseInt("012345",11) );301new TestCase( SECTION,302 "parseInt( '012345', 35 )", 303 1590195, 304 parseInt("012345",35) );305new TestCase( SECTION,306 "parseInt( '012345', 36 )", 307 1776965, 308 parseInt("012345",36) );309new TestCase( SECTION,310 "parseInt( '012345', 37 )", 311 Number.NaN, 312 parseInt("012345",37) );...

Full Screen

Full Screen

ColorUtil.js

Source:ColorUtil.js Github

copy

Full Screen

...109 var sB = (endB - startB) / step;110 var colorArr = [];111 for (var i = 0; i < step; i++) {112 //计算每一步的hex值113 var hex = this.rgb2hex([parseInt((sR * i + startR)), parseInt((sG * i + startG)), parseInt((sB * i + startB))]);114 colorArr.push(hex);115 }116 return colorArr;117}...

Full Screen

Full Screen

util.js

Source:util.js Github

copy

Full Screen

1export function expandHex(hex) {2 if (hex.indexOf('#') === 0) {3 hex = hex.substr(1);4 }5 if (!hex) {6 return null;7 }8 if (hex.length === 3) {9 hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];10 }11 return hex.length === 6 ? `#${hex}` : null;12}1314export function shrinkHex(hex) {15 if (hex.indexOf('#') === 0) {16 hex = hex.substr(1);17 }18 if (hex.length === 6 && hex[0] === hex[1] && hex[2] === hex[3] && hex[4] === hex[5]) {19 hex = hex[0] + hex[2] + hex[4];20 }21 return `#${hex}`;22}2324export function parseIntFromHex(val) {25 return parseInt(val, 16);26}2728export function isPercentage(n) {29 return typeof n === 'string' && n.indexOf('%') === n.length - 1;30}3132export function conventPercentageToRgb(n) {33 return parseInt(Math.round(n.slice(0, -1) * 2.55), 10);34}3536export function convertPercentageToFloat(n) {37 return parseFloat(n.slice(0, -1) / 100, 10);38}3940export function flip(o) {41 const flipped = {};42 for (const i in o) {43 if (o.hasOwnProperty(i)) {44 flipped[o[i]] = i;45 }46 }47 return flipped; ...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require('fs');3var request = require('request');4var cheerio = require('cheerio');5var async = require('async');6var url = require('url');7var path = require('path');8var Promise = require('bluebird');9var _ = require('lodash');10var data = fs.readFileSync('test.json');11var json = JSON.parse(data);12var urls = [];13var images = [];14var imageUrls = [];15var imageUrls2 = [];16var imageUrls3 = [];17var imageUrls4 = [];18var imageUrls5 = [];19var imageUrls6 = [];20var imageUrls7 = [];21var imageUrls8 = [];22var imageUrls9 = [];23var imageUrls10 = [];24var imageUrls11 = [];25var imageUrls12 = [];26var imageUrls13 = [];27var imageUrls14 = [];28var imageUrls15 = [];29var imageUrls16 = [];30var imageUrls17 = [];31var imageUrls18 = [];32var imageUrls19 = [];33var imageUrls20 = [];34var imageUrls21 = [];35var imageUrls22 = [];36var imageUrls23 = [];37var imageUrls24 = [];38var imageUrls25 = [];39var imageUrls26 = [];40var imageUrls27 = [];41var imageUrls28 = [];42var imageUrls29 = [];43var imageUrls30 = [];44var imageUrls31 = [];45var imageUrls32 = [];46var imageUrls33 = [];47var imageUrls34 = [];48var imageUrls35 = [];49var imageUrls36 = [];50var imageUrls37 = [];51var imageUrls38 = [];52var imageUrls39 = [];53var imageUrls40 = [];54var imageUrls41 = [];55var imageUrls42 = [];56var imageUrls43 = [];57var imageUrls44 = [];58var imageUrls45 = [];59var imageUrls46 = [];60var imageUrls47 = [];61var imageUrls48 = [];62var imageUrls49 = [];63var imageUrls50 = [];64var imageUrls51 = [];65var imageUrls52 = [];66var imageUrls53 = [];67var imageUrls54 = [];68var imageUrls55 = [];69var imageUrls56 = [];70var imageUrls57 = [];71var imageUrls58 = [];72var imageUrls59 = [];73var imageUrls60 = [];74var imageUrls61 = [];75var imageUrls62 = [];76var imageUrls63 = [];77var imageUrls64 = [];78var imageUrls65 = [];79var imageUrls66 = [];80var imageUrls67 = [];

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var page = wptools.page('Barack Obama');3page.get(function(err, resp) {4 console.log(resp);5});6var wptools = require('wptools');7var page = wptools.page('Barack Obama');8page.get(function(err, resp) {9 console.log(resp);10});11var wptools = require('wptools');12var page = wptools.page('Barack Obama');13page.get(function(err, resp) {14 console.log(resp);15});16var wptools = require('wptools');17var page = wptools.page('Barack Obama');18page.get(function(err, resp) {19 console.log(resp);20});21var wptools = require('wptools');22var page = wptools.page('Barack Obama');23page.get(function(err, resp) {24 console.log(resp);25});26var wptools = require('wptools');27var page = wptools.page('Barack Obama');28page.get(function(err, resp) {29 console.log(resp);30});31var wptools = require('wptools');32var page = wptools.page('Barack Obama');33page.get(function(err, resp) {34 console.log(resp);35});36var wptools = require('wptools');37var page = wptools.page('Barack Obama');38page.get(function(err, resp) {39 console.log(resp);40});41var wptools = require('wptools');42var page = wptools.page('Barack Obama');43page.get(function(err, resp) {44 console.log(resp);45});46var wptools = require('wptools');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require("wptools");2wptools.page("Barack_Obama").then(function(page) {3 page.html().then(function(html){4 console.log(html);5 });6});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2var hex = wptoolkit.hex;3var test = new hex('test');4test.on('error', function(err) {5 console.log(err);6});7test.on('data', function(data) {8 console.log(data);9});10test.on('end', function() {11 console.log('end');12});13test.start();

Full Screen

Using AI Code Generation

copy

Full Screen

1var mongoose = require('mongoose');2var Article = require('../models/article');3var User = require('../models/user');4var request = require('request');5var cheerio = require('cheerio');6var path = require('path');7var async = require('async');8var _ = require('lodash');9var fs = require('fs');10var getArticleImage = function (articleTitle, callback) {11 request(url, function (error, response, html) {12 if (!error) {13 var $ = cheerio.load(html);14 var image = $('.infobox img').attr('src');15 if (image) {16 image = 'https:' + image;17 }18 callback(null, image);19 } else {20 callback(null, null);21 }22 } else {23 callback(error);24 }25 });26};27var getArticleImage2 = function (articleTitle, callback) {28 request(url, function (error, response, html) {29 if (!error) {30 var $ = cheerio.load(html);31 var image = $('.infobox img').attr('src');32 if (image) {33 image = 'https:' + image;34 }35 callback(null, image);36 } else {37 callback(null, null);38 }39 } else {40 callback(error);41 }42 });43};44var getArticleImage3 = function (articleTitle, callback) {45 request(url, function (error, response, html) {46 if (!error) {47 var $ = cheerio.load(html);48 var image = $('.infobox img').attr('src');

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful