Best JavaScript code snippet using wpt
unicode_converter.js
Source:unicode_converter.js
1/*2 Copyright (C) 2007 Richard Ishida ishida@w3.org3 This program is free software; you can redistribute it and/or modify it under the terms4 of the GNU General Public License as published by the Free Software Foundation; either5 version 2 of the License, or (at your option) any later version as long as you point to6 http://rishida.net/ in your code.7 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;8 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.9 See the GNU General Public License for more details. http://www.gnu.org/licenses/gpl.html10 21 jun, added remaining entities to entities.js, and corrected emspace, rlm, etc.11 */12module.exports = convertAllEscapes;13function hex2char(hex) {14 // converts a single hex number to a character15 // note that no checking is performed to ensure that this is just a hex number, eg. no spaces etc16 // hex: string, the hex codepoint to be converted17 var result = '';18 var n = parseInt(hex, 16);19 if (n <= 0xFFFF) {20 result += String.fromCharCode(n);21 } else if (n <= 0x10FFFF) {22 n -= 0x1000023 result += String.fromCharCode(0xD800 | (n >> 10)) + String.fromCharCode(0xDC00 | (n & 0x3FF));24 } else {25 result += 'hex2Char error: Code point out of range: ' + dec2hex(n);26 }27 return result;28}29function dec2char(n) {30 // converts a single string representing a decimal number to a character31 // note that no checking is performed to ensure that this is just a hex number, eg. no spaces etc32 // dec: string, the dec codepoint to be converted33 var result = '';34 if (n <= 0xFFFF) {35 result += String.fromCharCode(n);36 } else if (n <= 0x10FFFF) {37 n -= 0x1000038 result += String.fromCharCode(0xD800 | (n >> 10)) + String.fromCharCode(0xDC00 | (n & 0x3FF));39 } else {40 result += 'dec2char error: Code point out of range: ' + dec2hex(n);41 }42 return result;43}44function dec2hex(textString) {45 return (textString + 0).toString(16).toUpperCase();46}47function dec2hex2(textString) {48 var hexequiv = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F");49 return hexequiv[(textString >> 4) & 0xF] + hexequiv[textString & 0xF];50}51function dec2hex4(textString) {52 var hexequiv = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F");53 return hexequiv[(textString >> 12) & 0xF] + hexequiv[(textString >> 8) & 0xF] +54 hexequiv[(textString >> 4) & 0xF] + hexequiv[textString & 0xF];55}56function convertChar2CP(textString) {57 var haut = 0;58 var n = 0;59 var CPstring = '';60 for (var i = 0; i < textString.length; i++) {61 var b = textString.charCodeAt(i);62 if (b < 0 || b > 0xFFFF) {63 CPstring += 'Error in convertChar2CP: byte out of range ' + dec2hex(b) + '!';64 }65 if (haut != 0) {66 if (0xDC00 <= b && b <= 0xDFFF) {67 CPstring += dec2hex(0x10000 + ((haut - 0xD800) << 10) + (b - 0xDC00)) + ' ';68 haut = 0;69 continue;70 } else {71 CPstring += 'Error in convertChar2CP: surrogate out of range ' + dec2hex(haut) + '!';72 haut = 0;73 }74 }75 if (0xD800 <= b && b <= 0xDBFF) {76 haut = b;77 } else {78 CPstring += dec2hex(b) + ' ';79 }80 }81 return CPstring.substring(0, CPstring.length - 1);82}83// ========================== Converting to characters ==============================================84function convertAllEscapes(str, numbers) {85 // converts all escapes in the text str to characters, and can interpret numbers as escapes too86 // str: string, the text to be converted87 // numbers: string enum [none, hex, dec, utf8, utf16], what to treat numbers as88 str = convertUnicode2Char(str); //alert(str);89 str = convertZeroX2Char(str); //alert(str);90 str = convertHexNCR2Char(str); //alert(str);91 str = convertDecNCR2Char(str); //alert(str);92 str = convertjEsc2Char(str, true);93 str = convertpEnc2Char(str); //alert(str);94 str = convertEntities2Char(str); //alert(str);95 str = convertNumbers2Char(str, numbers); //alert(str);96 return str;97}98function convertUnicode2Char(str) {99 // converts a string containing U+... escapes to a string of characters100 // str: string, the input101 // first convert the 6 digit escapes to characters102 str = str.replace(/[Uu]\+10([A-Fa-f0-9]{4})/g,103 function(matchstr, parens) {104 return hex2char('10' + parens);105 }106 );107 // next convert up to 5 digit escapes to characters108 str = str.replace(/[Uu]\+([A-Fa-f0-9]{1,5})/g,109 function(matchstr, parens) {110 return hex2char(parens);111 }112 );113 return str;114}115function oldconvertUnicode2Char(str) {116 // converts a string containing U+... escapes to a string of characters117 // str: string, the input118 // first convert the 6 digit escapes to characters119 str = str.replace(/U\+10([A-Fa-f0-9]{4})/g,120 function(matchstr, parens) {121 return hex2char('10' + parens);122 }123 );124 // next convert up to 5 digit escapes to characters125 str = str.replace(/U\+([A-Fa-f0-9]{1,5})/g,126 function(matchstr, parens) {127 return hex2char(parens);128 }129 );130 return str;131}132function convertHexNCR2Char(str) {133 // converts a string containing &#x...; escapes to a string of characters134 // str: string, the input135 // convert up to 6 digit escapes to characters136 str = str.replace(/&#x([A-Fa-f0-9]{1,6});/g,137 function(matchstr, parens) {138 return hex2char(parens);139 }140 );141 return str;142}143function convertDecNCR2Char(str) {144 // converts a string containing &#...; escapes to a string of characters145 // str: string, the input146 // convert up to 6 digit escapes to characters147 str = str.replace(/&#([0-9]{1,7});/g,148 function(matchstr, parens) {149 return dec2char(parens);150 }151 );152 return str;153}154function convertZeroX2Char(str) {155 // converts a string containing 0x... escapes to a string of characters156 // str: string, the input157 // convert up to 6 digit escapes to characters158 str = str.replace(/0x([A-Fa-f0-9]{1,6})/g,159 function(matchstr, parens) {160 return hex2char(parens);161 }162 );163 return str;164}165function convertCSS2Char(str, convertbackslash) {166 // converts a string containing CSS escapes to a string of characters167 // str: string, the input168 // convertbackslash: boolean, true if you want \x etc to become x or \a to be treated as 0xA169 // convert up to 6 digit escapes to characters & throw away any following whitespace170 if (convertbackslash) {171 str = str.replace(/\\([A-Fa-f0-9]{1,6})(\s)?/g,172 function(matchstr, parens) {173 return hex2char(parens);174 }175 );176 str = str.replace(/\\/g, '');177 } else {178 str = str.replace(/\\([A-Fa-f0-9]{2,6})(\s)?/g,179 function(matchstr, parens) {180 return hex2char(parens);181 }182 );183 }184 return str;185}186function convertjEsc2Char(str, shortEscapes) {187 // converts a string containing JavaScript or Java escapes to a string of characters188 // str: string, the input189 // shortEscapes: boolean, if true the function will convert \b etc to characters190 // convert \U and 6 digit escapes to characters191 str = str.replace(/\\U([A-Fa-f0-9]{8})/g,192 function(matchstr, parens) {193 return hex2char(parens);194 }195 );196 // convert \u and 6 digit escapes to characters197 str = str.replace(/\\u([A-Fa-f0-9]{4})/g,198 function(matchstr, parens) {199 return hex2char(parens);200 }201 );202 // convert \b etc to characters, if flag set203 if (shortEscapes) {204 //str = str.replace(/\\0/g, '\0');205 str = str.replace(/\\b/g, '\b');206 str = str.replace(/\\t/g, '\t');207 str = str.replace(/\\n/g, '\n');208 str = str.replace(/\\v/g, '\v');209 str = str.replace(/\\f/g, '\f');210 str = str.replace(/\\r/g, '\r');211 str = str.replace(/\\\'/g, '\'');212 str = str.replace(/\\\"/g, '\"');213 str = str.replace(/\\\\/g, '\\');214 }215 return str;216}217function convertpEnc2Char(str) {218 // converts a string containing precent encoded escapes to a string of characters219 // str: string, the input220 // find runs of hex numbers separated by % and send them for conversion221 str = str.replace(/((%[A-Fa-f0-9]{2})+)/g,222 function(matchstr, parens) {223 //return convertpEsc2Char(parens.replace(/%/g,' '));224 return convertpEsc2Char(parens);225 }226 );227 return str;228}229function convertEntities2Char(str) {230 // converts a string containing HTML/XML character entities to a string of characters231 // str: string, the input232 str = str.replace(/&([A-Za-z0-9]+);/g,233 function(matchstr, parens) { //alert(parens);234 if (parens in entities) { //alert(entities[parens]);235 return entities[parens];236 } else {237 return matchstr;238 }239 }240 );241 return str;242}243function convertNumbers2Char(str, type) {244 // converts a string containing HTML/XML character entities to a string of characters245 // str: string, the input246 // type: string enum [none, hex, dec, utf8, utf16], what to treat numbers as247 if (type == 'hex') {248 str = str.replace(/(\b[A-Fa-f0-9]{1,6}\b)/g,249 function(matchstr, parens) {250 return hex2char(parens);251 }252 );253 } else if (type == 'dec') {254 str = str.replace(/(\b[0-9]+\b)/g,255 function(matchstr, parens) {256 return dec2char(parens);257 }258 );259 } else if (type == 'utf8') {260 str = str.replace(/(( [A-Fa-f0-9]{2})+)/g,261 //str = str.replace(/((\b[A-Fa-f0-9]{2}\b)+)/g,262 function(matchstr, parens) {263 return convertUTF82Char(parens);264 }265 );266 } else if (type == 'utf16') {267 str = str.replace(/(( [A-Fa-f0-9]{1,6})+)/g,268 function(matchstr, parens) {269 return convertUTF162Char(parens);270 }271 );272 }273 return str;274}275function convertUTF82Char(str) {276 // converts to characters a sequence of space-separated hex numbers representing bytes in utf8277 // str: string, the sequence to be converted278 var outputString = "";279 var counter = 0;280 var n = 0;281 // remove leading and trailing spaces282 str = str.replace(/^\s+/, '');283 str = str.replace(/\s+$/, '');284 if (str.length == 0) {285 return "";286 }287 str = str.replace(/\s+/g, ' ');288 var listArray = str.split(' ');289 for (var i = 0; i < listArray.length; i++) {290 var b = parseInt(listArray[i], 16); // alert('b:'+dec2hex(b));291 switch (counter) {292 case 0:293 if (0 <= b && b <= 0x7F) { // 0xxxxxxx294 outputString += dec2char(b);295 } else if (0xC0 <= b && b <= 0xDF) { // 110xxxxx296 counter = 1;297 n = b & 0x1F;298 } else if (0xE0 <= b && b <= 0xEF) { // 1110xxxx299 counter = 2;300 n = b & 0xF;301 } else if (0xF0 <= b && b <= 0xF7) { // 11110xxx302 counter = 3;303 n = b & 0x7;304 } else {305 outputString += 'convertUTF82Char: error1 ' + dec2hex(b) + '! ';306 }307 break;308 case 1:309 if (b < 0x80 || b > 0xBF) {310 outputString += 'convertUTF82Char: error2 ' + dec2hex(b) + '! ';311 }312 counter--;313 outputString += dec2char((n << 6) | (b - 0x80));314 n = 0;315 break;316 case 2:317 case 3:318 if (b < 0x80 || b > 0xBF) {319 outputString += 'convertUTF82Char: error3 ' + dec2hex(b) + '! ';320 }321 n = (n << 6) | (b - 0x80);322 counter--;323 break;324 }325 }326 return outputString.replace(/ $/, '');327}328function convertUTF162Char(str) {329 // Converts a string of UTF-16 code units to characters330 // str: sequence of UTF16 code units, separated by spaces331 var highsurrogate = 0;332 var suppCP;333 var n = 0;334 var outputString = '';335 // remove leading and multiple spaces336 str = str.replace(/^\s+/, '');337 str = str.replace(/\s+$/, '');338 if (str.length == 0) {339 return;340 }341 str = str.replace(/\s+/g, ' ');342 var listArray = str.split(' ');343 for (var i = 0; i < listArray.length; i++) {344 var b = parseInt(listArray[i], 16); //alert(listArray[i]+'='+b);345 if (b < 0 || b > 0xFFFF) {346 outputString += '!Error in convertUTF162Char: unexpected value, b=' + dec2hex(b) + '!';347 }348 if (highsurrogate != 0) {349 if (0xDC00 <= b && b <= 0xDFFF) {350 outputString += dec2char(0x10000 + ((highsurrogate - 0xD800) << 10) + (b - 0xDC00));351 highsurrogate = 0;352 continue;353 } else {354 outputString += 'Error in convertUTF162Char: low surrogate expected, b=' + dec2hex(b) + '!';355 highsurrogate = 0;356 }357 }358 if (0xD800 <= b && b <= 0xDBFF) { // start of supplementary character359 highsurrogate = b;360 } else {361 outputString += dec2char(b);362 }363 }364 return outputString;365}366function convertpEsc2Char(str) {367 // converts to characters a sequence of %-separated hex numbers representing bytes in utf8368 // str: string, the sequence to be converted369 var outputString = "";370 var counter = 0;371 var n = 0;372 var listArray = str.split('%');373 for (var i = 1; i < listArray.length; i++) {374 var b = parseInt(listArray[i], 16); // alert('b:'+dec2hex(b));375 switch (counter) {376 case 0:377 if (0 <= b && b <= 0x7F) { // 0xxxxxxx378 outputString += dec2char(b);379 } else if (0xC0 <= b && b <= 0xDF) { // 110xxxxx380 counter = 1;381 n = b & 0x1F;382 } else if (0xE0 <= b && b <= 0xEF) { // 1110xxxx383 counter = 2;384 n = b & 0xF;385 } else if (0xF0 <= b && b <= 0xF7) { // 11110xxx386 counter = 3;387 n = b & 0x7;388 } else {389 outputString += 'convertpEsc2Char: error ' + dec2hex(b) + '! ';390 }391 break;392 case 1:393 if (b < 0x80 || b > 0xBF) {394 outputString += 'convertpEsc2Char: error ' + dec2hex(b) + '! ';395 }396 counter--;397 outputString += dec2char((n << 6) | (b - 0x80));398 n = 0;399 break;400 case 2:401 case 3:402 if (b < 0x80 || b > 0xBF) {403 outputString += 'convertpEsc2Char: error ' + dec2hex(b) + '! ';404 }405 n = (n << 6) | (b - 0x80);406 counter--;407 break;408 }409 }410 return outputString;411}412function convertXML2Char(str) {413 // converts XML or HTML text to characters by removing all character entities and ncrs414 // str: string, the sequence to be converted415 // remove various escaped forms416 str = convertHexNCR2Char(str);417 str = convertDecNCR2Char(str);418 str = convertEntities2Char(str);419 return str;420}421// ============================== Convert to escapes ===============================================422function convertCharStr2XML(str, convertinvisibles, bidimarkup) {423 // replaces xml/html syntax-sensitive characters in a string with entities424 // also replaces invisible and ambiguous characters with escapes (list to be extended)425 // str: string, the input string426 // convertinvisibles: boolean, if true, invisible characters are converted to NCRs427 // bidimarkup: boolean, if true, bidi rle/lre/pdf characters are converted to markup428 str = str.replace(/&/g, '&');429 str = str.replace(/"/g, '"');430 str = str.replace(/</g, '<');431 str = str.replace(/>/g, '>');432 // replace invisible and ambiguous characters433 if (convertinvisibles) {434 str = str.replace(/\u202A/g, '‪');435 str = str.replace(/\u202B/g, '‫');436 str = str.replace(/\u202D/g, '‭');437 str = str.replace(/\u202E/g, '‮');438 str = str.replace(/\u202C/g, '‬');439 str = str.replace(/\u200E/g, '‎');440 str = str.replace(/\u200F/g, '‏');441 str = str.replace(/\uAO/g, '
O;');442 //str = str.replace(/\u/g, '&#x;');443 }444 // convert lre/rle/pdf to markup445 if (bidimarkup) {446 str = str.replace(/\u202A/g, '<span dir="ltr">');447 str = str.replace(/\u202B/g, '<span dir="rtl">');448 str = str.replace(/\u202C/g, '</span>');449 str = str.replace(/‪/g, '<span dir="ltr">');450 str = str.replace(/‫/g, '<span dir="rtl">');451 //str = str.replace(/\u202D/g, '<bdo dir="ltr">');452 //str = str.replace(/\u202E/g, '<bdo dir="rtl">');453 str = str.replace(/‬/g, '</span>');454 }455 return str;456}457function convertCharStr2SelectiveCPs(str, preserve, pad, before, after, base) {458 // converts a string of characters to code points or code point based escapes459 // str: string, the string to convert460 // preserve: string enum [ascii, latin1], a set of characters to not convert461 // pad: boolean, if true, hex numbers lower than 1000 are padded with zeros462 // before: string, any characters to include before a code point (eg. &#x for NCRs)463 // after: string, any characters to include after (eg. ; for NCRs)464 // base: string enum [hex, dec], hex or decimal output465 var haut = 0;466 var n = 0;467 var cp;468 var CPstring = '';469 for (var i = 0; i < str.length; i++) {470 var b = str.charCodeAt(i);471 if (b < 0 || b > 0xFFFF) {472 CPstring += 'Error in convertCharStr2SelectiveCPs: byte out of range ' + dec2hex(b) + '!';473 }474 if (haut != 0) {475 if (0xDC00 <= b && b <= 0xDFFF) {476 if (base == 'hex') {477 CPstring += before + dec2hex(0x10000 + ((haut - 0xD800) << 10) + (b - 0xDC00)) + after;478 } else {479 cp = 0x10000 + ((haut - 0xD800) << 10) + (b - 0xDC00);480 CPstring += before + cp + after;481 }482 haut = 0;483 continue;484 } else {485 CPstring += 'Error in convertCharStr2SelectiveCPs: surrogate out of range ' + dec2hex(haut) + '!';486 haut = 0;487 }488 }489 if (0xD800 <= b && b <= 0xDBFF) {490 haut = b;491 } else {492 if (preserve == 'ascii' && b <= 127) { // && b != 0x3E && b != 0x3C && b != 0x26) {493 CPstring += str.charAt(i);494 } else if (b <= 255 && preserve == 'latin1') { // && b != 0x3E && b != 0x3C && b != 0x26) {495 CPstring += str.charAt(i);496 } else {497 if (base == 'hex') {498 cp = dec2hex(b);499 if (pad) {500 while (cp.length < 4) {501 cp = '0' + cp;502 }503 }504 } else {505 cp = b;506 }507 CPstring += before + cp + after;508 }509 }510 }511 return CPstring;512}513function convertCharStr2Unicode(textString, preserve, pad) {514 // converts a string of characters to U+... notation, separated by space515 // textString: string, the string to convert516 // preserve: string enum [ascii, latin1], a set of characters to not convert517 // pad: boolean, if true, hex numbers lower than 1000 are padded with zeros518 var haut = 0;519 var n = 0;520 var CPstring = '';521 pad = false;522 for (var i = 0; i < textString.length; i++) {523 var b = textString.charCodeAt(i);524 if (b < 0 || b > 0xFFFF) {525 CPstring += 'Error in convertChar2CP: byte out of range ' + dec2hex(b) + '!';526 }527 if (haut != 0) {528 if (0xDC00 <= b && b <= 0xDFFF) {529 CPstring += dec2hex(0x10000 + ((haut - 0xD800) << 10) + (b - 0xDC00)) + ' ';530 haut = 0;531 continue;532 } else {533 CPstring += 'Error in convertChar2CP: surrogate out of range ' + dec2hex(haut) + '!';534 haut = 0;535 }536 }537 if (0xD800 <= b && b <= 0xDBFF) {538 haut = b;539 } else {540 if (b <= 127 && preserve == 'ascii') {541 CPstring += textString.charAt(i) + ' ';542 } else if (b <= 255 && preserve == 'latin1') {543 CPstring += textString.charAt(i) + ' ';544 } else {545 cp = dec2hex(b);546 if (pad) {547 while (cp.length < 4) {548 cp = '0' + cp;549 }550 }551 CPstring += 'U+' + cp + ' ';552 }553 }554 }555 return CPstring.substring(0, CPstring.length - 1);556}557function convertCharStr2HexNCR(textString) {558 var outputString = "";559 textString = textString.replace(/^\s+/, '');560 if (textString.length == 0) {561 return "";562 }563 textString = textString.replace(/\s+/g, ' ');564 var listArray = textString.split(' ');565 for (var i = 0; i < listArray.length; i++) {566 var n = parseInt(listArray[i], 16);567 outputString += '&#x' + dec2hex(n) + ';';568 }569 return (outputString);570}571function convertCharStr2pEsc(str) {572 // str: sequence of Unicode characters573 var outputString = "";574 var CPstring = convertChar2CP(str);575 if (str.length == 0) {576 return "";577 }578 // process each codepoint579 var listArray = CPstring.split(' ');580 for (var i = 0; i < listArray.length; i++) {581 var n = parseInt(listArray[i], 16);582 //if (i > 0) { outputString += ' ';}583 if (n == 0x20) {584 outputString += '%20';585 } else if (n >= 0x41 && n <= 0x5A) {586 outputString += String.fromCharCode(n);587 } // alpha588 else if (n >= 0x61 && n <= 0x7A) {589 outputString += String.fromCharCode(n);590 } // alpha591 else if (n >= 0x30 && n <= 0x39) {592 outputString += String.fromCharCode(n);593 } // digits594 else if (n == 0x2D || n == 0x2E || n == 0x5F || n == 0x7E) {595 outputString += String.fromCharCode(n);596 } // - . _ ~597 else if (n <= 0x7F) {598 outputString += '%' + dec2hex2(n);599 } else if (n <= 0x7FF) {600 outputString += '%' + dec2hex2(0xC0 | ((n >> 6) & 0x1F)) + '%' + dec2hex2(0x80 | (n & 0x3F));601 } else if (n <= 0xFFFF) {602 outputString += '%' + dec2hex2(0xE0 | ((n >> 12) & 0x0F)) + '%' + dec2hex2(0x80 | ((n >> 6) & 0x3F)) + '%' + dec2hex2(0x80 | (n & 0x3F));603 } else if (n <= 0x10FFFF) {604 outputString += '%' + dec2hex2(0xF0 | ((n >> 18) & 0x07)) + '%' + dec2hex2(0x80 | ((n >> 12) & 0x3F)) + '%' + dec2hex2(0x80 | ((n >> 6) & 0x3F)) + '%' + dec2hex2(0x80 | (n & 0x3F));605 } else {606 outputString += '!Error ' + dec2hex(n) + '!';607 }608 }609 return (outputString);610}611function convertCharStr2UTF8(str) {612 // Converts a string of characters to UTF-8 byte codes, separated by spaces613 // str: sequence of Unicode characters614 var highsurrogate = 0;615 var suppCP; // decimal code point value for a supp char616 var n = 0;617 var outputString = '';618 for (var i = 0; i < str.length; i++) {619 var cc = str.charCodeAt(i);620 if (cc < 0 || cc > 0xFFFF) {621 outputString += '!Error in convertCharStr2UTF16: unexpected charCodeAt result, cc=' + cc + '!';622 }623 if (highsurrogate != 0) {624 if (0xDC00 <= cc && cc <= 0xDFFF) {625 suppCP = 0x10000 + ((highsurrogate - 0xD800) << 10) + (cc - 0xDC00);626 outputString += ' ' + dec2hex2(0xF0 | ((suppCP >> 18) & 0x07)) + ' ' + dec2hex2(0x80 | ((suppCP >> 12) & 0x3F)) + ' ' + dec2hex2(0x80 | ((suppCP >> 6) & 0x3F)) + ' ' + dec2hex2(0x80 | (suppCP & 0x3F));627 highsurrogate = 0;628 continue;629 } else {630 outputString += 'Error in convertCharStr2UTF16: low surrogate expected, cc=' + cc + '!';631 highsurrogate = 0;632 }633 }634 if (0xD800 <= cc && cc <= 0xDBFF) { // high surrogate635 highsurrogate = cc;636 } else {637 if (cc <= 0x7F) {638 outputString += ' ' + dec2hex2(cc);639 } else if (cc <= 0x7FF) {640 outputString += ' ' + dec2hex2(0xC0 | ((cc >> 6) & 0x1F)) + ' ' + dec2hex2(0x80 | (cc & 0x3F));641 } else if (cc <= 0xFFFF) {642 outputString += ' ' + dec2hex2(0xE0 | ((cc >> 12) & 0x0F)) + ' ' + dec2hex2(0x80 | ((cc >> 6) & 0x3F)) + ' ' + dec2hex2(0x80 | (cc & 0x3F));643 }644 }645 }646 return outputString.substring(1);647}648function convertCharStr2UTF16(str) {649 // Converts a string of characters to UTF-16 code units, separated by spaces650 // str: sequence of Unicode characters651 var highsurrogate = 0;652 var suppCP;653 var n = 0;654 var outputString = '';655 for (var i = 0; i < str.length; i++) {656 var cc = str.charCodeAt(i);657 if (cc < 0 || cc > 0xFFFF) {658 outputString += '!Error in convertCharStr2UTF16: unexpected charCodeAt result, cc=' + cc + '!';659 }660 if (highsurrogate != 0) {661 if (0xDC00 <= cc && cc <= 0xDFFF) {662 suppCP = 0x10000 + ((highsurrogate - 0xD800) << 10) + (cc - 0xDC00);663 suppCP -= 0x10000;664 outputString += dec2hex4(0xD800 | (suppCP >> 10)) + ' ' + dec2hex4(0xDC00 | (suppCP & 0x3FF)) + ' ';665 highsurrogate = 0;666 continue;667 } else {668 outputString += 'Error in convertCharStr2UTF16: low surrogate expected, cc=' + cc + '!';669 highsurrogate = 0;670 }671 }672 if (0xD800 <= cc && cc <= 0xDBFF) { // start of supplementary character673 highsurrogate = cc;674 } else {675 outputString += dec2hex(cc) + ' ';676 }677 }678 return outputString.substring(0, outputString.length - 1);679}680function convertCharStr2jEsc(str, cstyle) {681 // Converts a string of characters to JavaScript escapes682 // str: sequence of Unicode characters683 var highsurrogate = 0;684 var suppCP;685 var pad;686 var n = 0;687 var outputString = '';688 for (var i = 0; i < str.length; i++) {689 var cc = str.charCodeAt(i);690 if (cc < 0 || cc > 0xFFFF) {691 outputString += '!Error in convertCharStr2UTF16: unexpected charCodeAt result, cc=' + cc + '!';692 }693 if (highsurrogate != 0) { // this is a supp char, and cc contains the low surrogate694 if (0xDC00 <= cc && cc <= 0xDFFF) {695 suppCP = 0x10000 + ((highsurrogate - 0xD800) << 10) + (cc - 0xDC00);696 if (cstyle) {697 pad = suppCP.toString(16);698 while (pad.length < 8) {699 pad = '0' + pad;700 }701 outputString += '\\U' + pad;702 } else {703 suppCP -= 0x10000;704 outputString += '\\u' + dec2hex4(0xD800 | (suppCP >> 10)) + '\\u' + dec2hex4(0xDC00 | (suppCP & 0x3FF));705 }706 highsurrogate = 0;707 continue;708 } else {709 outputString += 'Error in convertCharStr2UTF16: low surrogate expected, cc=' + cc + '!';710 highsurrogate = 0;711 }712 }713 if (0xD800 <= cc && cc <= 0xDBFF) { // start of supplementary character714 highsurrogate = cc;715 } else { // this is a BMP character716 //outputString += dec2hex(cc) + ' ';717 switch (cc) {718 case 0:719 outputString += '\\0';720 break;721 case 8:722 outputString += '\\b';723 break;724 case 9:725 outputString += '\\t';726 break;727 case 10:728 outputString += '\\n';729 break;730 case 13:731 outputString += '\\r';732 break;733 case 11:734 outputString += '\\v';735 break;736 case 12:737 outputString += '\\f';738 break;739 case 34:740 outputString += '\\\"';741 break;742 case 39:743 outputString += '\\\'';744 break;745 case 92:746 outputString += '\\\\';747 break;748 default:749 if (cc > 0x1f && cc < 0x7F) {750 outputString += String.fromCharCode(cc);751 } else {752 pad = cc.toString(16).toUpperCase();753 while (pad.length < 4) {754 pad = '0' + pad;755 }756 outputString += '\\u' + pad;757 }758 }759 }760 }761 return outputString;762}763function convertCharStr2CSS(str) {764 // Converts a string of characters to CSS escapes765 // str: sequence of Unicode characters766 var highsurrogate = 0;767 var suppCP;768 var pad;769 var outputString = '';770 for (var i = 0; i < str.length; i++) {771 var cc = str.charCodeAt(i);772 if (cc < 0 || cc > 0xFFFF) {773 outputString += '!Error in convertCharStr2CSS: unexpected charCodeAt result, cc=' + cc + '!';774 }775 if (highsurrogate != 0) { // this is a supp char, and cc contains the low surrogate776 if (0xDC00 <= cc && cc <= 0xDFFF) {777 suppCP = 0x10000 + ((highsurrogate - 0xD800) << 10) + (cc - 0xDC00);778 pad = suppCP.toString(16).toUpperCase();779 if (suppCP < 0x10000) {780 while (pad.length < 4) {781 pad = '0' + pad;782 }783 } else {784 while (pad.length < 6) {785 pad = '0' + pad;786 }787 }788 outputString += '\\' + pad + ' ';789 highsurrogate = 0;790 continue;791 } else {792 outputString += 'Error in convertCharStr2CSS: low surrogate expected, cc=' + cc + '!';793 highsurrogate = 0;794 }795 }796 if (0xD800 <= cc && cc <= 0xDBFF) { // start of supplementary character797 highsurrogate = cc;798 } else { // this is a BMP character799 if (cc == 0x5C) {800 outputString += '\\\\';801 } else if (cc > 0x1f && cc < 0x7F) {802 outputString += String.fromCharCode(cc);803 } else if (cc == 0x9 || cc == 0xA || cc == 0xD) {804 outputString += String.fromCharCode(cc);805 } else /* if (cc > 0x7E) */ {806 pad = cc.toString(16).toUpperCase();807 while (pad.length < 4) {808 pad = '0' + pad;809 }810 outputString += '\\' + pad + ' ';811 }812 }813 }814 return outputString;815}816function convertCharStr2CP(textString, preserve, pad, type) {817 // converts a string of characters to code points, separated by space818 // textString: string, the string to convert819 // preserve: string enum [ascii, latin1], a set of characters to not convert820 // pad: boolean, if true, hex numbers lower than 1000 are padded with zeros821 // type: string enum[hex, dec, unicode, zerox], whether output should be in hex or dec or unicode U+ form822 var haut = 0;823 var n = 0;824 var CPstring = '';825 var afterEscape = false;826 for (var i = 0; i < textString.length; i++) {827 var b = textString.charCodeAt(i);828 if (b < 0 || b > 0xFFFF) {829 CPstring += 'Error in convertChar2CP: byte out of range ' + dec2hex(b) + '!';830 }831 if (haut != 0) {832 if (0xDC00 <= b && b <= 0xDFFF) { //alert('12345'.slice(-1).match(/[A-Fa-f0-9]/)+'<');833 //if (CPstring.slice(-1).match(/[A-Za-z0-9]/) != null) { CPstring += ' '; }834 if (afterEscape) {835 CPstring += ' ';836 }837 if (type == 'hex') {838 CPstring += dec2hex(0x10000 + ((haut - 0xD800) << 10) + (b - 0xDC00));839 } else if (type == 'unicode') {840 CPstring += 'U+' + dec2hex(0x10000 + ((haut - 0xD800) << 10) + (b - 0xDC00));841 } else if (type == 'zerox') {842 CPstring += '0x' + dec2hex(0x10000 + ((haut - 0xD800) << 10) + (b - 0xDC00));843 } else {844 CPstring += 0x10000 + ((haut - 0xD800) << 10) + (b - 0xDC00);845 }846 haut = 0;847 continue;848 afterEscape = true;849 } else {850 CPstring += 'Error in convertChar2CP: surrogate out of range ' + dec2hex(haut) + '!';851 haut = 0;852 }853 }854 if (0xD800 <= b && b <= 0xDBFF) {855 haut = b;856 } else {857 if (b <= 127 && preserve == 'ascii') {858 CPstring += textString.charAt(i);859 afterEscape = false;860 } else if (b <= 255 && preserve == 'latin1') {861 CPstring += textString.charAt(i);862 afterEscape = false;863 } else {864 //if (CPstring.slice(-1).match(/[A-Za-z0-9]/) != null) { CPstring += ' '; }865 if (afterEscape) {866 CPstring += ' ';867 }868 if (type == 'hex') {869 cp = dec2hex(b);870 if (pad) {871 while (cp.length < 4) {872 cp = '0' + cp;873 }874 }875 } else if (type == 'unicode') {876 cp = dec2hex(b);877 if (pad) {878 while (cp.length < 4) {879 cp = '0' + cp;880 }881 }882 CPstring += 'U+';883 } else if (type == 'zerox') {884 cp = dec2hex(b);885 if (pad) {886 while (cp.length < 4) {887 cp = '0' + cp;888 }889 }890 CPstring += '0x';891 } else {892 cp = b;893 }894 CPstring += cp;895 afterEscape = true;896 }897 }898 }899 //return CPstring.substring(0, CPstring.length-1);900 return CPstring;901}902function convertCharStr2Unicode(textString, preserve, pad) {903 alert('here');904 // converts a string of characters to U+... notation, separated by space905 // textString: string, the string to convert906 // preserve: string enum [ascii, latin1], a set of characters to not convert907 // pad: boolean, if true, hex numbers lower than 1000 are padded with zeros908 var haut = 0;909 var n = 0;910 var CPstring = '';911 pad = false;912 for (var i = 0; i < textString.length; i++) {913 var b = textString.charCodeAt(i);914 if (b < 0 || b > 0xFFFF) {915 CPstring += 'Error in convertChar2CP: byte out of range ' + dec2hex(b) + '!';916 }917 if (haut != 0) {918 if (0xDC00 <= b && b <= 0xDFFF) {919 CPstring += 'U+' + dec2hex(0x10000 + ((haut - 0xD800) << 10) + (b - 0xDC00)) + ' ';920 haut = 0;921 continue;922 } else {923 CPstring += 'Error in convertChar2CP: surrogate out of range ' + dec2hex(haut) + '!';924 haut = 0;925 }926 }927 if (0xD800 <= b && b <= 0xDBFF) {928 haut = b;929 } else {930 if (b <= 127 && preserve == 'ascii') {931 CPstring += textString.charAt(i) + ' ';932 } else if (b <= 255 && preserve == 'latin1') {933 CPstring += textString.charAt(i) + ' ';934 } else {935 cp = dec2hex(b);936 if (pad) {937 while (cp.length < 4) {938 cp = '0' + cp;939 }940 }941 CPstring += 'U+' + cp + ' ';942 }943 }944 }945 return CPstring.substring(0, CPstring.length - 1);...
url-setters-stripping.any.js
Source:url-setters-stripping.any.js
1function urlString({ scheme = "https",2 username = "username",3 password = "password",4 host = "host",5 port = "8000",6 pathname = "path",7 search = "query",8 hash = "fragment" }) {9 return `${scheme}://${username}:${password}@${host}:${port}/${pathname}?${search}#${hash}`;10}11function urlRecord(scheme) {12 return new URL(urlString({ scheme }));13}14for(const scheme of ["https", "wpt++"]) {15 for(let i = 0; i < 0x20; i++) {16 const stripped = i === 0x09 || i === 0x0A || i === 0x0D;17 // It turns out that user agents are surprisingly similar for these ranges so generate fewer18 // tests. If this is changed also change the logic for host below.19 if (i !== 0 && i !== 0x1F && !stripped) {20 continue;21 }22 const cpString = String.fromCodePoint(i);23 const cpReference = "U+" + i.toString(16).toUpperCase().padStart(4, "0");24 test(() => {25 const expected = scheme === "https" ? (stripped ? "http" : "https") : (stripped ? "wpt--" : "wpt++");26 const url = urlRecord(scheme);27 url.protocol = String.fromCodePoint(i) + (scheme === "https" ? "http" : "wpt--");28 assert_equals(url.protocol, expected + ":", "property");29 assert_equals(url.href, urlString({ scheme: expected }), "href");30 }, `Setting protocol with leading ${cpReference} (${scheme}:)`);31 test(() => {32 const expected = scheme === "https" ? (stripped ? "http" : "https") : (stripped ? "wpt--" : "wpt++");33 const url = urlRecord(scheme);34 url.protocol = (scheme === "https" ? "http" : "wpt--") + String.fromCodePoint(i);35 assert_equals(url.protocol, expected + ":", "property");36 assert_equals(url.href, urlString({ scheme: expected }), "href");37 }, `Setting protocol with ${cpReference} before inserted colon (${scheme}:)`);38 // Cannot test protocol with trailing as the algorithm inserts a colon before proceeding39 // These do no stripping40 for (const property of ["username", "password"]) {41 for (const [type, expected, input] of [42 ["leading", encodeURIComponent(cpString) + "test", String.fromCodePoint(i) + "test"],43 ["middle", "te" + encodeURIComponent(cpString) + "st", "te" + String.fromCodePoint(i) + "st"],44 ["trailing", "test" + encodeURIComponent(cpString), "test" + String.fromCodePoint(i)]45 ]) {46 test(() => {47 const url = urlRecord(scheme);48 url[property] = input;49 assert_equals(url[property], expected, "property");50 assert_equals(url.href, urlString({ scheme, [property]: expected }), "href");51 }, `Setting ${property} with ${type} ${cpReference} (${scheme}:)`);52 }53 }54 for (const [type, expectedPart, input] of [55 ["leading", (scheme === "https" ? cpString : encodeURIComponent(cpString)) + "test", String.fromCodePoint(i) + "test"],56 ["middle", "te" + (scheme === "https" ? cpString : encodeURIComponent(cpString)) + "st", "te" + String.fromCodePoint(i) + "st"],57 ["trailing", "test" + (scheme === "https" ? cpString : encodeURIComponent(cpString)), "test" + String.fromCodePoint(i)]58 ]) {59 test(() => {60 const expected = i === 0x00 ? "host" : stripped ? "test" : expectedPart;61 const url = urlRecord(scheme);62 url.host = input;63 assert_equals(url.host, expected + ":8000", "property");64 assert_equals(url.href, urlString({ scheme, host: expected }), "href");65 }, `Setting host with ${type} ${cpReference} (${scheme}:)`);66 test(() => {67 const expected = i === 0x00 ? "host" : stripped ? "test" : expectedPart;68 const url = urlRecord(scheme);69 url.hostname = input;70 assert_equals(url.hostname, expected, "property");71 assert_equals(url.href, urlString({ scheme, host: expected }), "href");72 }, `Setting hostname with ${type} ${cpReference} (${scheme}:)`);73 }74 test(() => {75 const expected = stripped ? "9000" : "8000";76 const url = urlRecord(scheme);77 url.port = String.fromCodePoint(i) + "9000";78 assert_equals(url.port, expected, "property");79 assert_equals(url.href, urlString({ scheme, port: expected }), "href");80 }, `Setting port with leading ${cpReference} (${scheme}:)`);81 test(() => {82 const expected = stripped ? "9000" : "90";83 const url = urlRecord(scheme);84 url.port = "90" + String.fromCodePoint(i) + "00";85 assert_equals(url.port, expected, "property");86 assert_equals(url.href, urlString({ scheme, port: expected }), "href");87 }, `Setting port with middle ${cpReference} (${scheme}:)`);88 test(() => {89 const expected = "9000";90 const url = urlRecord(scheme);91 url.port = "9000" + String.fromCodePoint(i);92 assert_equals(url.port, expected, "property");93 assert_equals(url.href, urlString({ scheme, port: expected }), "href");94 }, `Setting port with trailing ${cpReference} (${scheme}:)`);95 for (const [property, separator] of [["pathname", "/"], ["search", "?"], ["hash", "#"]]) {96 for (const [type, expectedPart, input] of [97 ["leading", encodeURIComponent(cpString) + "test", String.fromCodePoint(i) + "test"],98 ["middle", "te" + encodeURIComponent(cpString) + "st", "te" + String.fromCodePoint(i) + "st"],99 ["trailing", "test" + encodeURIComponent(cpString), "test" + String.fromCodePoint(i)]100 ]) {101 test(() => {102 const expected = stripped ? "test" : expectedPart;103 const url = urlRecord(scheme);104 url[property] = input;105 assert_equals(url[property], separator + expected, "property");106 assert_equals(url.href, urlString({ scheme, [property]: expected }), "href");107 }, `Setting ${property} with ${type} ${cpReference} (${scheme}:)`);108 }109 }110 }...
Using AI Code Generation
1const wptools = require('wptools');2wptools.page('Barack Obama').then(function(page) {3 return page.cpString('birth_date');4}).then(function(cpString) {5 console.log(cpString);6});7const wptools = require('wptools');8wptools.page('Barack Obama').then(function(page) {9 return page.cpString('birth_date');10}).then(function(cpString) {11 console.log(cpString);12});13const wptools = require('wptools');14wptools.page('Barack Obama').then(function(page) {15 return page.cpString('birth_date');16}).then(function(cpString) {17 console.log(cpString);18});
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new wpt('API_KEY');3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var wpt = require('wpt');10var wpt = new wpt('API_KEY');11 if (err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17var wpt = require('wpt');18var wpt = new wpt('API_KEY');19 if (err) {20 console.log(err);21 } else {22 console.log(data);23 }24});25var wpt = require('wpt');26var wpt = new wpt('API_KEY');27 if (err) {28 console.log(err);29 } else {30 console.log(data);31 }32});33var wpt = require('wpt');34var wpt = new wpt('API_KEY');35 if (err) {36 console.log(err);37 } else {38 console.log(data);39 }40});41var wpt = require('wpt');42var wpt = new wpt('API_KEY');43 if (err) {44 console.log(err);45 } else {46 console.log(data);47 }48});49var wpt = require('wpt');50var wpt = new wpt('
Using AI Code Generation
1var wptext = require('wptext');2var text = wptext.cpString('hello world');3console.log(text);4var wptext = require('wptext');5var text = wptext.cpString('hello world', 'en');6console.log(text);7var wptext = require('wptext');8var text = wptext.cpString('hello world', 'en', 'fr');9console.log(text);10var wptext = require('wptext');11var text = wptext.cpString('hello world', 'en', 'fr', 'text');12console.log(text);13var wptext = require('wptext');14var text = wptext.cpString('hello world', 'en', 'fr', 'text', 'html');15console.log(text);16var wptext = require('wptext');17var text = wptext.cpString('hello world', 'en', 'fr', 'text', 'html', '1');18console.log(text);19var wptext = require('wptext');20var text = wptext.cpString('hello world', 'en', 'fr', 'text', 'html', '1', '1');21console.log(text);22var wptext = require('wptext');23var text = wptext.cpString('hello world', 'en', 'fr', 'text', 'html', '1', '1', '1');24console.log(text);25var wptext = require('wptext');26var text = wptext.cpString('hello world', 'en', 'fr', 'text', 'html', '1', '1', '1', '1');27console.log(text);
Using AI Code Generation
1var wptext = require('wptext');2var text = "Hello World";3var result = wptext.cpString(text);4console.log(result);5var wptext = require('wptext');6var text = "Hello World";7var result = wptext.cpString(text);8console.log(result);9var wptext = require('wptext');10var text = "Hello World";11var result = wptext.cpString(text);12console.log(result);13var wptext = require('wptext');14var text = "Hello World";15var result = wptext.cpString(text);16console.log(result);17var wptext = require('wptext');18var text = "Hello World";19var result = wptext.cpString(text);20console.log(result);21var wptext = require('wptext');22var text = "Hello World";23var result = wptext.cpString(text);24console.log(result);25var wptext = require('wptext');26var text = "Hello World";27var result = wptext.cpString(text);28console.log(result);29var wptext = require('wptext');30var text = "Hello World";31var result = wptext.cpString(text);32console.log(result);33var wptext = require('wptext');34var text = "Hello World";35var result = wptext.cpString(text);36console.log(result);37var wptext = require('wptext');38var text = "Hello World";39var result = wptext.cpString(text);40console.log(result);
Using AI Code Generation
1var cpString = require('./wptext').cpString;2console.log(cpString('Hello World!'));3exports.cpString = function (str) {4 return str;5};6function cpString(str) {7 return str;8}9module.exports = cpString;10var cpString = require('./wptext');11console.log(cpString('Hello World!'));12module.exports = function (str) {13 return str;14};15var cpString = require('./wptext');16console.log(cpString('Hello World!'));17module.exports.cpString = function (str) {18 return str;19};20var wptext = require('./wptext');21console.log(wptext.cpString('Hello World!'));22module.exports = {23 cpString: function (str) {24 return str;25 }26};27var wptext = require('./wptext');28console.log(wptext.cpString('Hello World!'));29module.exports = {30 cpString: function (str) {31 return str;32 },33 cpString2: function (str) {34 return str;35 }36};37var wptext = require('./wptext');38console.log(wptext.cpString('Hello World!'));39module.exports = {40 cpString: function (str) {41 return str;42 },43 cpString2: function (str) {44 return str;45 }46};
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2var string = "Hello World";3var newString = wptoolkit.cpString(string);4console.log(newString);5var wptoolkit = require('wptoolkit');6var string = "Hello World";7var newString = wptoolkit.cpString(string);8console.log(newString);9var wptoolkit = require('wptoolkit');10var string = "Hello World";11var newString = wptoolkit.cpString(string);12console.log(newString);13var wptoolkit = require('wptoolkit');14var string = "Hello World";15var newString = wptoolkit.cpString(string);16console.log(newString);17var wptoolkit = require('wptoolkit');18var string = "Hello World";19var newString = wptoolkit.cpString(string);20console.log(newString);21var wptoolkit = require('wptoolkit');22var string = "Hello World";23var newString = wptoolkit.cpString(string);24console.log(newString);25var wptoolkit = require('wptoolkit');26var string = "Hello World";27var newString = wptoolkit.cpString(string);28console.log(newString);29var wptoolkit = require('wptoolkit');30var string = "Hello World";31var newString = wptoolkit.cpString(string);32console.log(newString);33var wptoolkit = require('
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2var cpString = wptoolkit.cpString;3var cpString = cpString('test string');4console.log(cpString);5var wptoolkit = require('wptoolkit');6var cpString = wptoolkit.cpString;7var cpString = cpString('test string');8console.log(cpString);9var wptoolkit = require('wptoolkit');10var cpString = wptoolkit.cpString;11var cpString = cpString('test string');12console.log(cpString);13var wptoolkit = require('wptoolkit');14var cpString = wptoolkit.cpString;15var cpString = cpString('test string');16console.log(cpString);17var wptoolkit = require('wptoolkit');18var cpString = wptoolkit.cpString;19var cpString = cpString('test string');20console.log(cpString);21var wptoolkit = require('wptoolkit');22var cpString = wptoolkit.cpString;23var cpString = cpString('test string');24console.log(cpString);25var wptoolkit = require('wptoolkit');26var cpString = wptoolkit.cpString;27var cpString = cpString('test string');28console.log(cpString);29var wptoolkit = require('wptoolkit');30var cpString = wptoolkit.cpString;31var cpString = cpString('test string');32console.log(cpString);
Using AI Code Generation
1var cpString = require('./wptextpattern.js');2var str = 'hello';3var result = cpString(str);4console.log(result);5module.exports = function cpString(str){6 str = str + str;7 return str;8}9var express = require('express');10var app = express();11app.get('/', function(req, res){12 res.send('Hello World');13});14app.listen(3000, function(){15 console.log('Server started on port 3000');16});17var fs = require('fs');18fs.readFile('test.txt', 'utf8', function(err, data){19 if(err){20 return console.log(err);21 }22 console.log(data);23});24vrwptoolkath= r quite('wptoolkit's;js25varvcpStringa=rcpString('ttotkstring');t = require('wptoolkit');26ring = wptoocpSiring.cpString;27sole.log(cpString);28var cpStringooltptoolkit.cpString;29var c Srring = cpStringeqtest stringptoolkit');30console log(cpString);31ol Prth: g;js32vr wptoolkct =Srrquine('wptoolkit'g; cpString('test string');33varocpStringu=pcpString('tu:ttstring');st string34var wptoolkit = require('wptoolkit');35var cpString = wptoolkit.cpString;36var cpString = cpString('test stringoo;kit37consoltoolkie.log(cpString)toolki;38var cpSuringt: cpStritg('testtstring');39console.log(cpString);40var wptoolkit = require('wptoolkit');41var cpString = wptoolkit.cpString;42var cpString = cpString('test string');43console.log(cpString);44var wptoolkit = require('wptoolkit');45var cpString = wptoolkit.cpString;46var cpString = cpString('test string');47console.log(cpString);48var wptoolkit = require('wptoolkit');49var cpString = wptoolkit.cpString;50var cpString = cpString('test string');51console.log(cpString);52var wptoolkit = require('wptoolkit');53var cpString = wptoolkit.cpString;54var cpString = cpString('test string');55console.log(cpString);
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2var cpString = wptoolkit.cpString;3var cpString = cpString('test string');4console.log(cpString);5var wptoolkit = require('wptoolkit' ;6var cpString = wptoolkit.cpString console.log(err);7var cpString = cpString('test string'); } else {8console.log(cpString);9 }toolkit10var wptoolkit = require('wptoolkit');11var cpString = wptoolkit.cpString;12var cpString = cpString('test string');13console.log(cpString);14var wptoolkit = require('wptoolkit');15var cpString = wptoolkit.cpString;16var cpString = cpString('test string');17console.log(cpString);18var wptoolkit = require('wptoolkit');19var cpString = wptoolkit.cpString;20var cpString = cpString('test string');21console.log(cpString);22var wptoolkit = require('wptoolkit');23var cpString = wptoolkit.cpString;24var cpString = cpString('test string');25console.log(cpString);26var wptoolkit = require('wptoolkit');27var cpString = wptoolkit.cpString;28var cpString = cpString('tesstring');29onsoe.log(cpString);30});toolkitoolki31r cpString = wptoolkit.cpString;32var cpString = cpString('test string');33console.log(cpString);
Using AI Code Generation
1var cpString = require('./wptextpattern.js');2var str = 'hello';3var result = cpString(str);4console.log(result);5module.exports = function cpString(str){6 st = str + str;7 return str;8}9var express require('express');10var app = express();11app.get('/', function(req, res){12 res.sed('Hello World');13});14app.listn(3000, function(){15 console.log('Server started on port 3000');16});17var fs = requirefs');18fs.readFile('test.txt', 'utf8', function(err, data){19 if(err){20 return console.log(err);21 }22 console.log(data);23});24var wpt = require('wpt');25var wpt = new wpt('API_KEY');26 if (err) {27 console.log(err);28 } else {29 console.log(data);30 }31});32var wpt = require('wpt');33var wpt = new wpt('API_KEY');34 if (err) {35 console.log(err);36 } else {37 console.log(data);38 }39});40var wpt = require('wpt');41var wpt = new wpt('API_KEY');42 if (err) {43 console.log(err);44 } else {45 console.log(data);46 }47});48var wpt = require('wpt');49var wpt = new wpt('
Using AI Code Generation
1var cpString = require('./wptextpattern.js');2var str = 'hello';3var result = cpString(str);4console.log(result);5module.exports = function cpString(str){6 str = str + str;7 return str;8}9var express = require('express');10var app = express();11app.get('/', function(req, res){12 res.send('Hello World');13});14app.listen(3000, function(){15 console.log('Server started on port 3000');16});17var fs = require('fs');18fs.readFile('test.txt', 'utf8', function(err, data){19 if(err){20 return console.log(err);21 }22 console.log(data);23});
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!!