Best JavaScript code snippet using puppeteer
Mybatis_Camel_Service.js
Source:Mybatis_Camel_Service.js
1//DESC : ì»¬ë¼ ë°°ì´, 길ì´ì ë°ë¥¸ 공백 ê° ë§ë¤ê¸°2//param 3// colArr : íì±í´ì¼íë colArr4//return : 5// 6fcolArrMake = async function (colArr) {7 let resultColArr = []; // 8 let spaceLength = 0; // 공백 ê° íì¸9 let colflag = true; // flag ì ì¸10 let maxLength = 0; // 공백 ìµë 길ì´11 let rdoSelVal = common.getRdoValue('rdo_compireType', 'value');12 for (var col of colArr) { // 13 col.replaceAll(" ", ""); // 공백 ì ê±°14 if (col == "") {15 continue; // 공백ì´ë¼ë©´ í¬í¨ X16 }17 let fromCompireType = common.getSbxValue('sbx_fromCompireType', 'value');18 let toCompireType = common.getSbxValue('sbx_toCompireType', 'value');19 let fromCompireTypeObj = {};20 fromCompireTypeObj = await fFromCompireType(col, fromCompireType); // ì»´íì¼ íì
ì ì문ì íì± return , Caseindexëí 리í´21 col = await fToCompireType(fromCompireTypeObj, toCompireType); // ì»´íì¼ ííì ë§ì¶° 문ìì´ return;22 resultColArr.push(col); // ì»´íì¼ ë°ì´í° ë°°ì´ push23 ///////////////////// ê¸ì 길ì´ë¡ ìµë ê³µë°±ê° êµ¬í기///////////////////// 24 if (col.length > maxLength) {25 maxLength = col.length;26 spaceLength = (parseInt(maxLength / 4) + 1);27 }28 }29 return { resultColArr: resultColArr, spaceLength: spaceLength }; // íì±ë ë°ì´í°, 공백 길ì´30};31//DESC : ë
¸ì¶ ë°ì´í° ìì± íì
32 //param 33 // 34 //return :35 fMakeParsingData = async function(colArr, colCmArr, resultColArr, resultColCmArr,spaceLength, tableName){ 36 let resultText = ''; // ë¦¬í´ ê° 37 let spaceString = '';38 let parsingType = common.getRdoValue('rdo_parsingType','value'); //íì± ì¢
ë¥39 40 41 42 43 if(parsingType == 'basic'){//Basic44 /////////////// col + space + colCmt + \n; ìì
ìì45 for(var i = 0; i < resultColArr.length; i++ ){ // col, colcoment 리í´ê° ìì±46 spaceString = ''; // 공백 ì´ê¸°í47 let resultObj = await fGetSpaceLengthAndCmNullCheck(resultColArr[i], resultColCmArr[i], spaceLength);48 spaceString = resultObj.spaceString;49 resultColCmArr[i] = resultObj.resultColCmArrValue;50 ///////////////////// SettingEnd ParsingStart51 52 resultText += (resultColArr[i] + spaceString + resultColCmArr[i] + '\n'); // col + space + colCmt + \n;53 }54 /////////////////col + space + colCmt + \n; ìì
ë 55 }else if(parsingType == 'select'){ // select56 let selectParsingText = '';57 let fromParsingText = 'FROM\n\t\t' + 'TABLE_NAME';58 let sSelect1 = 'SELECT\n';59 let sSelect2 = '';60 let sFrom = 'FROM\t';61 let sWhere1 = 'WHERE\t1 = 1\n';62 let sWhere2 = '';63 64 for(var i = 0; i < resultColArr.length; i++ ){ // col, colcoment 리í´ê° ìì±65 spaceString = ''; // 공백 ì´ê¸°í66 let resultObj = await fGetSpaceLengthAndCmNullCheck(resultColArr[i], resultColCmArr[i], spaceLength);67 spaceString = resultObj.spaceString;68 resultColCmArr[i] = resultObj.resultColCmArrValue;69 ///////////////////// SettingEnd ParsingStart70 71 sSelect2 += ( (i == 0 ? '\t\t ' : '\t\t,')72 + colArr[i] 73 + spaceString 74 + 'AS ' 75 + resultColArr[i] 76 + spaceString 77 + '/*' + resultColCmArr[i] + '*/' 78 + '\n'79 ); // col + space + colCmt + \n;80 sWhere2 += ( 'AND'81 + '\t\t'82 + colArr[i]83 + spaceString84 + '= '85 + '#{'86 + resultColArr[i]87 + '}'88 + spaceString89 + '/*' + resultColCmArr[i] + '*/' 90 + '\n'91 );92 93 }94 95 resultText = sSelect1 96 + sSelect2 97 + sFrom 98 + tableName + '\n' 99 + sWhere1100 + sWhere2;101 }else if(parsingType == 'insert'){ // insert102 let sInsertInto = 'INSERT INTO ' + tableName + '\n(\n'103 let sInto = '';104 let sValue = '';105 106 for(var i = 0; i < resultColArr.length; i++ ){ // col, colcoment 리í´ê° ìì±107 spaceString = ''; // 공백 ì´ê¸°í108 let resultObj = await fGetSpaceLengthAndCmNullCheck(resultColArr[i], resultColCmArr[i], spaceLength); // 공백, ëì²´í¬109 spaceString = resultObj.spaceString;110 resultColCmArr[i] = resultObj.resultColCmArrValue;111 ///////////////////// SettingEnd ParsingStart112 sInto += (i == 0 ? ' ' : ' ,')113 + colArr[i] 114 + spaceString 115 + '/*' 116 + resultColCmArr[i] 117 + '*/\n';118 119 sValue += (i == 0 ? ' ' : ' ,')120 + '#{' + resultColArr[i] + '}'121 + spaceString122 + '/*' 123 + resultColCmArr[i] 124 + '*/\n';125 }126 resultText = sInsertInto + sInto + ')\nVALUES\n(\n' + sValue + ')';127 }else if(parsingType == 'update'){ 128 let sUpdate = 'UPDATE ' + tableName + '\n' + 'SET\n'; 129 let sSet = '';130 let sWhere = 'WHERE 1 = 1\n';131 132 for(var i = 0; i < resultColArr.length; i++ ){ // col, colcoment 리í´ê° ìì±133 spaceString = ''; // 공백 ì´ê¸°í134 let resultObj = await fGetSpaceLengthAndCmNullCheck(resultColArr[i], resultColCmArr[i], spaceLength); // 공백, ëì²´í¬135 spaceString = resultObj.spaceString;136 resultColCmArr[i] = resultObj.resultColCmArrValue;137 ///////////////////// SettingEnd ParsingStart138 139 sSet += (i == 0 ? ' ' : ' ,')140 + colArr[i] 141 + spaceString142 + '= #{' + resultColArr[i] + '}'143 + spaceString 144 + '/*' + resultColCmArr[i] + '*/\n';145 146 sWhere += (i == 0 ? ' ' : ' ,')147 + resultColArr[i]148 + spaceString149 + '= #{' + resultColArr[i] + '}'150 + spaceString 151 + '/*' + resultColCmArr[i] + '*/\n';152 153 }154 resultText = sUpdate + sSet + sWhere;155 }else if(parsingType = 'delete'){ 156 let sdelete = 'DELETE FROM ' + tableName + '\n';157 let swhere = 'WHERE 1 = 1\n'158 for(var i = 0; i < resultColArr.length; i++ ){ // col, colcoment 리í´ê° ìì±159 spaceString = ''; // 공백 ì´ê¸°í160 let resultObj = await fGetSpaceLengthAndCmNullCheck(resultColArr[i], resultColCmArr[i], spaceLength); // 공백, ëì²´í¬161 spaceString = resultObj.spaceString;162 resultColCmArr[i] = resultObj.resultColCmArrValue;163 ///////////////////// SettingEnd ParsingStart164 165 swhere += colArr[i]166 + spaceString167 + '= #{' + resultColArr[i] + '}'168 + spaceString169 + '/*' + resultColCmArr[i] + '*/\n';170 171 172 }173 resultText = sdelete + swhere;174 }175 176 177 178 179 return resultText;180 } 181 182////////////////////////////// 컬ë¼ì ìµë 길ì´ë¥¼ íµí 공백 구í기 ë° ì½ë©í¸ 공백ì¼ë¡ ë§ë¤ê¸°183fGetSpaceLengthAndCmNullCheck = async function(resultColArrValue, resultColCmArrValue, spaceLength){184 let spaceString = '';185 186 for(var j = 0; j <= spaceLength - parseInt(resultColArrValue.length / 4); j++){ // ìµë 공백 길ì´ìì colì 길ì´ë§í¼ 빼주기187 spaceString += '\t';188 }189 if(resultColCmArrValue == null || resultColCmArrValue == 'undefined'){ // ê°ì´ ìë¤ë©´ 공백ì¼ë¡190 resultColCmArrValue = '';191 }192 return {spaceString : spaceString, resultColCmArrValue, resultColCmArrValue};193};194fFromCompireType = async function(col, fromCompireType){195 let charArr = [];196 let gubunCaseNum = []197 let j = 0;198 199 200 for(let i = 0 ; i < col.length ; i++){201 if(fromCompireType == 'snakeCase'){ //snakeCase SNAKE_CASE_TEST -> snakecase,[5,9];202 if(col[i] == "_"){203 j++204 gubunCaseNum.push(i-j+1);205 continue;206 }207 charArr[i-j] = col[i].toLowerCase();208 }else if(fromCompireType == 'camelCase' || fromCompireType == 'pascalCase'){ //camelCase camelCaseTest -> camelcasetest,[5,9];209 if(col[i].charCodeAt() > 64 && col[i].charCodeAt() < 91){210 if(!(fromCompireType == 'pascalCase' && i == 0)){211 gubunCaseNum.push(i);212 }213 }214 charArr[i] = col[i].toLowerCase();215 }else if(fromCompireType == 'kebabCase'){216 if(col[i] == "-"){217 j++218 gubunCaseNum.push(i-j+1);219 continue;220 }221 charArr[i-j] = col[i].toLowerCase();222 }223 }224 return {gubunCaseNum : gubunCaseNum, charArr : charArr};225}226////////////////////////////////////////227fToCompireType = async function(fromCompireTypeObj, toCompireType){228 let charArr = fromCompireTypeObj.charArr;229 let colGubunIndex = fromCompireTypeObj.gubunCaseNum;230 let colText = '';231 let j = 0;232 233 234 for(let i = 0 ; i < charArr.length; i++){235 236 if(toCompireType == 'snakeCase' || toCompireType == 'kebabCase' ){237 charArr[i] = charArr[i].toUpperCase();238 }else if(toCompireType == 'pascalCase' && i == 0){239 charArr[i] = charArr[i].toUpperCase();240 }241 242 if(i == colGubunIndex[j]){243 j++;244 if(toCompireType == 'camelCase' || toCompireType == 'pascalCase'){ //camelCase : camelcasetest,[5,9] -> camelCaseTest245 charArr[i] = charArr[i].toUpperCase();246 }else if(toCompireType == 'snakeCase'){ //snakeCase : snakecasetest,[5,9] -> SNAKE_CASE_TEST247 charArr[i] = '_' + charArr[i];248 }else if(toCompireType == 'kebabCase'){ //snakeCase : snakecasetest,[5,9] -> SNAKE_CASE_TEST249 charArr[i] = '-' + charArr[i];250 }251 }252 253 254 255 colText += charArr[i];256 }257 if(j != colGubunIndex.length){258 console.error('íì±ìì
ì´ ì ììë íì§ ìììµëë¤.' + 'ERR.001');259 }else{260 console.log('íì±ìì
ì´ ì ì ìë íììµëë¤. => ' + colText);261 }262 return colText;263 264 265 ...
monthGen.js
Source:monthGen.js
1#!/usr/bin/env node2//actual methods3'use strict';4//set month strings object equal to empty object5const monthStrings = {};6let space = " ";7//Returns a string with spaces, the year, and the month, with january = 1, and then returns a new line with the days of the week8monthStrings.calHeaderOutput = (month, year) => {9 const monthArray = [ , 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];10 const fullTopString = `${monthArray[month]} ${year}`;11 const initalSpaces = ((20 - (monthArray[month].length + 5))/2)-1;12 const spaceString = " ";13 return `${spaceString.repeat(initalSpaces+1)}${fullTopString}\nSu Mo Tu We Th Fr Sa`;14};15//Returns a string with spaces, the year, and the month, with january = 1, and then returns a new line with the days of the week16monthStrings.calHeaderOutputLinux = (month, year) => {17 const monthArray = [ , 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];18 const fullTopString = `${monthArray[month]} ${year}`;19 const initalSpaces = ((20 - (monthArray[month].length + 5))/2)-1;20 const spaceString = " ";21 return `${spaceString.repeat(initalSpaces+1)}${fullTopString}${spaceString.repeat(initalSpaces+4)}\nSu Mo Tu We Th Fr Sa `;22};23//Returns a string with spaces, the year, and the month, with january = 1, and then returns a new line with the days of the week24monthStrings.monthNameOnly = (month) => {25 const monthArray = [ , 'January ', 'February', 'March', 'April ', ' May', 'June', 'July', 'August', 'September', 'October ', 'November', 'December'];26 const fullTopString = `${monthArray[month]}`;27 const initalSpaces = ((20 - (monthArray[month].length))/2);28 const spaceString = " ";29 if(monthArray[month] === 'March' || monthArray[month] === 'June' || monthArray[month] === 'September' || monthArray[month] === 'December'){30 return `${spaceString.repeat(initalSpaces)}${fullTopString}`;31 }else{32 return `${spaceString.repeat(initalSpaces)}${fullTopString}${spaceString.repeat(initalSpaces)}`;33 }34};35//returns the days of the month from 1 - 31 with spaces for formatting36monthStrings.calBodyOutput = (month, year) => {37 const zellars = require("./zellars.js");38 const totalDays = new Date(year, month, 0).getDate();39 let daysNums = [];40 for(let i = 1; i <= totalDays; i++){41 if(i <= 9 ){42 let spacedI = " "+i;43 daysNums.push(spacedI);44 } else {45 daysNums.push(i);46 }47 }48 const getDay = zellars.getDay;49 const prependedSpaces = getDay(year, month, 1) * 3;50 const initialSpace = " ";51 const finalString = `${initialSpace.repeat(prependedSpaces)}${daysNums.join(" ")}`;52 const spacedFinal = finalString.match(new RegExp('.{1,'+21+'}', 'g'));53 let fixedArray = [];54 for(let i = 0; i < spacedFinal.length; i++){55 if(i === spacedFinal.length-1){56 let newLine = spacedFinal[i];57 fixedArray.push(newLine);58 }else {59 let newLine = spacedFinal[i].split("").splice(0,spacedFinal[i].split("").length-1).join("");60 fixedArray.push(newLine);61 }62 }63 return fixedArray.join("\n");64};65//returns the days of the month from 1 - 31 with spaces for formatting66monthStrings.calBodyOutputLinux = (month, year) => {67 const zellars = require("./zellars.js");68 const totalDays = new Date(year, month, 0).getDate();69 let daysNums = [];70 for(let i = 1; i <= totalDays; i++){71 if(i <= 9 ){72 let spacedI = " "+i;73 daysNums.push(spacedI);74 } else {75 daysNums.push(i);76 }77 }78 const getDay = zellars.getDay;79 const prependedSpaces = getDay(year, month, 1) * 3;80 const initialSpace = " ";81 const finalString = `${initialSpace.repeat(prependedSpaces)}${daysNums.join(" ")}`;82 const spacedFinal = finalString.match(new RegExp('.{1,'+21+'}', 'g'));83 let fixedArray = [];84 for(let i = 0; i < spacedFinal.length; i++){85 if(i === spacedFinal.length-1){86 let newLine = `${spacedFinal[i]}`;87 fixedArray.push(newLine);88 }else {89 let newLine = spacedFinal[i].split("").splice(0,spacedFinal[i].split("").length-1).join("");90 fixedArray.push(newLine);91 }92 }93 return fixedArray.join(" \n");94};95//output day lines96monthStrings.dayLinesOutput = (month, year) => {97 return monthStrings.calBodyOutput(month,year).split("\n");98};99//outputs full calendar100monthStrings.outputCal = (month, year) => {101 if(monthStrings.getWeeks(month,year) === 4 || monthStrings.getWeeks(month,year) === 5){102 return `${monthStrings.calHeaderOutput(month,year)}\n${monthStrings.calBodyOutput(month, year)}\n`103 } else {104 return `${monthStrings.calHeaderOutput(month,year)}\n${monthStrings.calBodyOutput(month, year)}`105 }106};107monthStrings.outputCalLinux = (month, year) => {108 if(monthStrings.getWeeks(month,year) === 4 || monthStrings.getWeeks(month,year) === 5){109 return `${monthStrings.calHeaderOutputLinux(month,year)}\n${monthStrings.calBodyOutputLinux(month, year)}\n${space.repeat(22)}`110 } else {111 return `${monthStrings.calHeaderOutputLinux(month,year)}\n${monthStrings.calBodyOutputLinux(month, year)}`112 }113};114//get weeks of a certain month of a year115monthStrings.getWeeks = (month, year) => {116 if(monthStrings.calBodyOutput(month, year).lastIndexOf("\n") === 62){117 return 4;118 } else if (monthStrings.calBodyOutput(month, year).lastIndexOf("\n") === 83){119 return 5120 } else if (monthStrings.calBodyOutput(month, year).lastIndexOf("\n") === 104){121 return 6122 }123};124//get total number of days125monthStrings.getTotalDays = (month, year) => {126 const totalDays = new Date(year, month, 0).getDate();127 return totalDays;128}...
index.js
Source:index.js
1function onlyNumberKey(evt) {2 var ASCIICode = (evt.which) ? evt.which : evt.keyCode3 if (ASCIICode > 31 && (ASCIICode < 48 || ASCIICode > 57))4 return false;5 return true;6}7function validateInputNumber(value) {8 if (value >= 10 && value <= 40) {9 return true;10 }11 alert('Insira um valor entre 10 e 40')12 return false;13}14function renderLine(n) {15 var array = new Array(n).fill('#')16 var string = ''17 array.map(e => string = string + e)18 console.log(string)19}20function renderString(n, caracter) {21 var string = ''22 if (n < 0) {23 n = 024 }25 var array = new Array(n).fill(caracter)26 array.map(e => string = string + e)27 return string28}29//HELPERS30function renderTimeLine(n, column, seg) {31 if (column >= (n / 2)) {32 return33 }34 var string = ''35 var hashString = renderString((n - (column * 2) - 4), '#')36 var spaceString = renderString(column, ' ')37 var spaceCenterString = renderString((n - (column * 2) - 4), ' ')38 if (column >= ((n - 1) / 2) - 1) {39 console.log("#" + spaceString + '#' + spaceString + '#')40 return41 }42 if (column < seg) {43 console.log("#" + spaceString + '#' + spaceCenterString + '#' + spaceString + '#')44 return45 }46 string = "#" + spaceString + '#' + hashString + '#' + spaceString + '#'47 console.log(string)48}49function renderDecTimeLine(n, column, seg) {50 if (column >= (n / 2)) {51 return52 }53 var spaceCenterString = renderString((n - (column * 2) - 2), ' ')54 var spaceString = renderString(column - 1, ' ')55 var hashString = renderString(((n - (column * 2) - 2)), '#')56 if ((n / 2) - 2 == column) {57 if (n % 2 == 0) {58 console.log("#" + spaceString + ' ## ' + spaceString + '#\n')59 }60 else {61 }62 }63 if (column < seg) {64 console.log("#" + spaceString + '#' + hashString + '#' + spaceString + '#')65 return66 }67 console.log("#" + spaceString + '#' + spaceCenterString + '#' + spaceString + '#')68}69function showHourglass(n, seg) {70 let column = 0;71 renderLine(n)72 while (column <= (n / 2) - 1) {73 if (column != (n / 2) - 1) {74 renderTimeLine(n, column, seg)75 }76 column = column + 177 }78 column = 0;79 while (column < (n / 2) - 1) {80 if (((n / 2) - 1) - column != (n / 2) - 1) {81 var valueColumn = 0;82 if (n % 2 != 0) {83 valueColumn = (((n / 2) - 1) - column) + 0.5;84 }85 else {86 valueColumn = (((n / 2) - 1) - column);87 }88 renderDecTimeLine(n, valueColumn, seg)89 }90 column = column + 1;91 }92 renderLine(n)93}94function setTime(n) {95 var count = 0;96 var interval = setInterval(() => {97 if (count < n / 2) {98 console.clear();99 showHourglass(n, count);100 count = count + 1;101 }102 else {103 clearInterval(interval);104 }105 }, 1000)106}107function onClickButton() {108 var inputValue = document.querySelector("#input").value;109 if (validateInputNumber(inputValue)) {110 setTime(parseInt(inputValue))111 }112}113// ####################114// ####################115// # ################ #116// # ############## #117// # ############ #118// # ########## #119// # ######## #120// # ###### #121// # #### #122// # ## #123// # ## #124// # # # #125// # # # #126// # # # #127// # # # #128// # # # #129// # # # #130// # # # #131// ## ##...
week1_challenge.js
Source:week1_challenge.js
1/*2PROBLEM - 13Create a function that takes height as a param and prints tree like shape with given height as illustrated below4 EXAMPLES ::5 6 height = 67 A8 ABC9 ABCDE10 ABCDEFG11 ABCDEFGHI12 ABCDEFGHIJK13 14 height = 315 A16 ABC17 ABCDE18 height = 419 A20 ABC21 ABCDE22 ABCDEFG23 24*/25function drawTree(height) {26 let spaceString = ''27 let alpha = [28 'A',29 'B',30 'C',31 'D',32 'E',33 'F',34 'G',35 'H',36 'I',37 'J',38 'K',39 'L',40 'M',41 'N',42 'O',43 'P',44 'Q',45 'R',46 'S',47 'T',48 'U',49 'V',50 'W',51 'X',52 'Y',53 'Z',54 ]55 for (let i = 1; i <= height; i++) {56 // console.log(i)57 for (let j = height - i; j > 0; j--) {58 spaceString += ' '59 }60 let charString = ''61 for (let k = 0; k < i * 2 - 1; k++) {62 charString += alpha[k]63 }64 spaceString += charString65 spaceString += '\n'66 }67 console.log(spaceString)68}69drawTree(4)70/*71PROBLEM - 272Create a function that returns an array that expands by 1 from 1 to the value of the input, and then reduces back to 1. Items in the arrays will be the same as the length of the arrays.73EXAMPLES ::74diamondArrays(1) â [[1]]75diamondArrays(2) â [[1], [2, 2], [1]]76diamondArrays(5) â [[1], [2, 2], [3, 3, 3], [4, 4, 4, 4], [5, 5, 5, 5, 5], [4, 4, 4, 4], [3, 3, 3], [2, 2], [1]]77*/78function diamondArrays(num) {79 // ... your code here80 let arr = []81 for (let i = 0; i < num; i++) {82 let firstArr = []83 for (let j = 0; j <= i; j++) {84 firstArr.push(i + 1)85 }86 arr.push(firstArr)87 }88 for (let i = num - 1; i > 0; i--) {89 let secArr = []90 for (let j = i; j > 0; j--) {91 secArr.push(i)92 }93 arr.push(secArr)94 }95 console.log(arr)96}97diamondArrays(4)98/*99PROBLEM - 3100find positive Cumulative Sum of Array.101The cumulative sum of an array at index i is defined as the sum of all elements of the array from index 0 to index i.102NOTE: if possible try to use map and reduce103EXAMPLES ::104Initial Array: [1, 3, 5, 7] => Cumulative Sum: [1, 4, 9, 16] => Positive Cumulative Sum: [1, 4, 9, 16]105Initial Array: [1, -2, 3, 4, -6] => Cumulative Sum: [1, -1, 2, 6, 0] => Positive Cumulative Sum: [1, 2, 6]106Initial Array: [1, -1, -1, -1, 1] => Cumulative Sum: [1, 0, -1, -2, -1] => Positive Cumulative Sum: [1]107*/108function getPositiveCumulativeSum(arr) {109 const newArr = arr.map((item, index, array) => {110 array[index + 1] = item + array[index + 1]111 return item112 })113 const finalArr = newArr.filter((item) => {114 return item > 0115 })116 return { CumulativeSum: newArr, PositiveCumulativeSum: finalArr }117}...
Default.js
Source:Default.js
1import React from 'react';2import {3 Avatar,4 List,5 ListItemMeeting,6} from '@momentum-ui/react';7export default class ListItemDefault extends React.PureComponent {8 render() {9 return (10 <List>11 <ListItemMeeting12 isAllDay13 header="ListItemMeeting (isAllDay)"14 anchorLabel="SpaceString"15 anchorOnClick={() => alert('anchor clicked')}16 childrenRight={<Avatar title="NA" />}17 popoverContent={'test'}18 />19 <ListItemMeeting20 time={{ start: '5:00PM', end: '10:00PM' }}21 header="ListItemMeeting (time object)"22 isRecurring23 anchorLabel="SpaceString"24 anchorOnClick={() => alert('anchor clicked')}25 childrenRight={<Avatar title="NA" />}26 popoverContent={'test'}27 />28 <ListItemMeeting29 time={{ start: '5:00PM', end: '10:00PM' }}30 inProgress31 header="ListItemMeeting (inProgress)"32 anchorLabel="SpaceString"33 anchorOnClick={() => alert('anchor clicked')}34 childrenRight={<Avatar title="NA" />}35 popoverContent={'test'}36 />37 <ListItemMeeting38 includeDate={true}39 date="January 24, 2018"40 time={{ start: '10:00 AM', end: '11:00 AM' }}41 header="Finish presentation on focus areas"42 />43 <ListItemMeeting44 inProgress45 type="chip"46 includeDate={true}47 date="January 25, 2018"48 time={{ start: '3:00PM', end: '4:00PM' }}49 header="I'm a flagged meeting"50 />51 <ListItemMeeting52 includeDate={true}53 date="March 2, 2019"54 isRecurring55 isCompleted56 header="ListItemMeeting (isCompleted)"57 anchorLabel="SpaceString"58 anchorOnClick={() => alert('anchor clicked')}59 childrenRight={<Avatar title="NA" />}60 popoverContent={'test'}61 />62 </List>63 );64 }...
json-transform.js
Source:json-transform.js
1const defaultIndentation = 2;2const addSpace = (spaceCount) => {3 let spaceString = '';4 for (let i = spaceCount; i; i -= 1) {5 spaceString = `${spaceString} `;6 }7 return spaceString;8};9const applyEslintRules = (jsonSelected, indentationCount = defaultIndentation) => {10 let formatedResult = '';11 for (let key in jsonSelected) {12 let newKey = key;13 let newValue = jsonSelected[key];14 if (key.includes('-')) {15 newKey = `'${key}'`;16 }17 if (typeof jsonSelected[key] !== 'number'18 && typeof jsonSelected[key] !== 'object'19 ) {20 newValue = `'${jsonSelected[key]}'`;21 } else if (typeof jsonSelected[key] === 'object') {22 const spaceCount = indentationCount + defaultIndentation;23 let newObjectHowString = '{';24 newObjectHowString = `${newObjectHowString}${applyEslintRules(jsonSelected[key], spaceCount)}`;25 newValue = `${newObjectHowString} \n${addSpace(indentationCount)}}`;26 }27 formatedResult = `${formatedResult}\n${addSpace(indentationCount)}${newKey}: ${newValue},`;28 }29 return formatedResult;30};31const jsonTransform = (textSelected) => {32 const jsonSelected = JSON.parse(textSelected);33 let newObjectHowString = `{${applyEslintRules(jsonSelected)}`;34 return `${newObjectHowString}\n}`;35};...
stairCase.js
Source:stairCase.js
1/**2 * Reference : https://www.hackerrank.com/challenges/staircase/problem3 */4function staircase(n) {5 // Space Character6 const space = " ";7 // initial pattern string8 let hash = "#";9 // Initialize the space10 let spaceString = space.repeat(n-1);11 12 13 while(n--){14 // print space and character15 console.log(`${spaceString}${hash}`);16 // increase the pattern size17 hash+="#";18 // decrease the space string by 119 spaceString = spaceString.substr(0,spaceString.length - 1);20 }...
helpers.js
Source:helpers.js
1// This file contains helper methods and enumerations2// to be used by the application.3export const WeatherEnum = Object.freeze({4 thunderstorm: "Thunderstorm",5 clear: "Clear",6 snow: "Snow",7 rain: "Rain",8 drizzle: "Drizzle",9 clouds: "Clouds"10});11/**12 * Removes any dashes in strings, replaces them with13 * spaces and caplitalizes the first character.14 */15String.prototype.prep = function() {16 let spaceString = this.replace("-", " ");17 return spaceString.charAt(0).toUpperCase() + spaceString.slice(1);...
Using AI Code Generation
1const puppeteer = require('puppeteer');2const fs = require('fs');3const path = require('path');4(async () => {5 const browser = await puppeteer.launch();6 const page = await browser.newPage();7 await page.screenshot({path: 'google.png'});8 const text = await page.evaluate(() => {9 return document.querySelector('body').innerText;10 });11 const text2 = text.replace(/(\r\n|\n|\r)/gm," ");12 fs.writeFile(path.join(__dirname, 'test.txt'), text2, err => {13 if(err) throw err;14 console.log('File written to...');15 });16 await browser.close();17})();18const puppeteer = require('puppeteer');19const fs = require('fs');20const path = require('path');21(async () => {22 const browser = await puppeteer.launch();23 const page = await browser.newPage();24 await page.screenshot({path: 'google.png'});25 const text = await page.evaluate(() => {26 return document.querySelector('body').innerText;27 });28 const text2 = text.replace(/(\r\n|\n|\r)/gm," ");29 fs.writeFile(path.join(__dirname, 'test.txt'), text2, err => {30 if(err) throw err;31 console.log('File written to...');32 });33 await browser.close();34})();
Using AI Code Generation
1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 await page.pdf({path: 'hn.pdf', format: 'A4'});6 await browser.close();7})();8const puppeteer = require('puppeteer');9(async () => {10 const browser = await puppeteer.launch();11 const page = await browser.newPage();12 await page.pdf({path: 'hn.pdf', format: 'A4'});13 await browser.close();14})();15const puppeteer = require('puppeteer');16(async () => {17 const browser = await puppeteer.launch();18 const page = await browser.newPage();19 await page.pdf({path: 'hn.pdf', format: 'A4'});20 await browser.close();21})();22const puppeteer = require('puppeteer');23(async () => {24 const browser = await puppeteer.launch();25 const page = await browser.newPage();26 await page.pdf({path: 'hn.pdf', format: 'A4'});27 await browser.close();28})();29const puppeteer = require('puppeteer');30(async () => {31 const browser = await puppeteer.launch();32 const page = await browser.newPage();33 await page.pdf({path: 'hn.pdf', format: 'A4'});34 await browser.close();35})();36const puppeteer = require('puppeteer');37(async () => {38 const browser = await puppeteer.launch();39 const page = await browser.newPage();40 await page.pdf({path: 'hn.pdf', format: 'A4'});41 await browser.close();42})();
Using AI Code Generation
1const puppeteer = require('puppeteer');2const fs = require('fs');3(async () => {4 const browser = await puppeteer.launch();5 const page = await browser.newPage();6 const text = await page.evaluate(() => document.body.textContent);7 await fs.writeFileSync('test.txt', text);8 await browser.close();9})();
Using AI Code Generation
1const puppeteer = require('puppeteer');2const fs = require('fs');3(async () => {4 const browser = await puppeteer.launch({headless: false});5 const page = await browser.newPage();6 let searchInput = await page.$('input[name="q"]');7 await searchInput.type('puppeteer', {delay: 100});8 await searchInput.press('Enter');9 await page.waitForNavigation();10 await page.screenshot({path: 'google.png'});11 await browser.close();12})();
Using AI Code Generation
1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 await page.screenshot({path: 'example.png'});6 await browser.close();7})();8 at CDPSession.send (C:\Users\user\Desktop\test\node_modules\puppeteer\lib\Connection.js:200:56)9 at ExecutionContext.evaluateHandle (C:\Users\user\Desktop\test\node_modules\puppeteer\lib\ExecutionContext.js:71:75)10 at ExecutionContext.evaluate (C:\Users\user\Desktop\test\node_modules\puppeteer\lib\ExecutionContext.js:46:31)11 at Page.evaluate (C:\Users\user\Desktop\test\node_modules\puppeteer\lib\Page.js:1094:43)12 at Page.<anonymous> (C:\Users\user\Desktop\test\test.js:8:15)13 at Generator.next (<anonymous>)14 at new Promise (<anonymous>)15 at __awaiter (C:\Users\user\Desktop\test\test.js:4:12)16I have tried to use the `page.on()` event listener, but it gives me the
Using AI Code Generation
1const puppeteer = require('puppeteer');2const fs = require('fs');3const spaceString = require('space-string');4(async () => {5 const browser = await puppeteer.launch();6 const page = await browser.newPage();7 await page.screenshot({path: 'example.png'});8 await browser.close();9})();10'use strict';11module.exports = function (str, count) {12 if (typeof str !== 'string') {13 throw new TypeError('Expected a string');14 }15 if (typeof count !== 'number') {16 throw new TypeError('Expected a number');17 }18 return str + ' '.repeat(count);19};20### spaceString(str, count)21MIT © [Abhishek Gupta](
Using AI Code Generation
1const puppeteer = require('puppeteer');2const fs = require('fs');3(async () => {4 const browser = await puppeteer.launch();5 const page = await browser.newPage();6 await page.waitForSelector('#main');7 const text = await page.$eval('#main', el => el.textContent);8 const spaceString = text.replace(/\s/g, '');9 fs.writeFile('test.txt', spaceString, (err) => {10 if (err) throw err;11 console.log('The file has been saved!');12 });13 await browser.close();14})();15Replace()16Replace()17Replace()18Replace()19Replace()20Replace()21Replace()
Using AI Code Generation
1await page.keyboard.spaceString()2await page.keyboard.press('Space');3await page.keyboard.press('Space');4await page.keyboard.press('Space');5await page.keyboard.downArrow()6await page.keyboard.press('ArrowDown');7await page.keyboard.press('ArrowDown');8await page.keyboard.press('ArrowDown');9await page.keyboard.upArrow()10await page.keyboard.press('ArrowUp');11await page.keyboard.press('ArrowUp');12await page.keyboard.press('ArrowUp');13await page.keyboard.leftArrow()14await page.keyboard.press('ArrowLeft');15await page.keyboard.press('ArrowLeft');16await page.keyboard.press('ArrowLeft');17await page.keyboard.rightArrow()18await page.keyboard.press('ArrowRight');19await page.keyboard.press('ArrowRight');20await page.keyboard.press('ArrowRight');
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!!