Best JavaScript code snippet using fast-check-monorepo
jquery.zySlide.js
Source:jquery.zySlide.js
1//-------------------------------------------------------------------------//2(function ($) {3 // å建æé å½æ°4 function Slide(ele, options) {5 this.$ele = $(ele)//this. æé å½æ°çå®ä¾å¯¹è±¡6 let g = d3.select(ele)7 let width = g.node().clientWidth8 let height = g.node().clientHeight9 // image size 1280*62210 // let ratio_large = 0.511 let ratio_large = 0.512 let w = width * ratio_large13 let h = w * 622 / 128014 let len_li = g.selectAll('li').nodes().length15 this.len_li = len_li16 this.indexCurrent = 017 let states = null18 let back = {'&zIndex': 0, 'width': 0, 'height': 0, 'top': height * 0.5, 'left': width * 0.5, '$opacity': 0 }19 if (len_li < 3 ) {20 console.warn('image less than 3!')21 states = [{ '&zIndex': 4, 'width': w, 'height': h, 'top': height * 0.5 - h * 0.5, 'left': width * 0.5 - w * 0.5, '$opacity': 1 }]22 for (let i = 1; i< len_li; i++) {23 states.push(back)24 }25 this.indexCurrent = 026 } else if (len_li < 5) {27 console.warn('image less than 5!')28 let points = [0.325, 0.5, 0.675]29 let indeces = [3, 4, 3]30 let ratios = [0.65, 1, 0.65]31 let opacities = [0.5, 1, 0.5]32 33 points[0] = ratio_large * ratios[0] * 0.534 points[2] = 1 - points[0]35 states = points.map((p, i)=>{36 let tmp = {}37 tmp['&zIndex'] = indeces[i]38 tmp['width'] = w * ratios[i]39 tmp['height'] = h * ratios[i]40 tmp['left'] = width * points[i] - tmp['width'] * 0.541 tmp['top'] = height * 0.5 - tmp['height'] * 0.542 tmp['$opacity'] = opacities[i]43 return tmp44 })45 46 for (let i = 3; i< len_li; i++) {47 states.push(back)48 }49 this.indexCurrent = 150 } else {51 let points = [0.175, 0.325, 0.5, 0.675, 0.825]52 let indeces = [2, 3, 4, 3, 2]53 let ratios = [0.35, 0.65, 1, 0.65, 0.35]54 let opacities = [0.5, 0.75, 1, 0.75, 0.5]55 56 points[0] = ratio_large * ratios[0] * 0.557 points[4] = 1 - points[0]58 let ratio_overlap = ratios[0] + ratios[1] + 0.5 - 1 / ratio_large * 0.559 points[1] = (ratios[0]* (1-ratio_overlap) + ratios[1]* 0.5) * ratio_large60 points[3] = 1 - points[1]61 states = points.map((p, i)=>{62 let tmp = {}63 tmp['&zIndex'] = indeces[i]64 tmp['width'] = w * ratios[i]65 tmp['height'] = h * ratios[i]66 tmp['left'] = width * points[i] - tmp['width'] * 0.567 tmp['top'] = height * 0.5 - tmp['height'] * 0.568 tmp['$opacity'] = opacities[i]69 return tmp70 })71 for (let i = 5; i< len_li; i++) {72 states.push(back)73 }74 this.indexCurrent = 275 }76 77 console.log(states)78 console.log(g)79 this.options = $.extend({80 speed: 1000,81 delay: 300082 }, options)//æå±83 // this.states = [84 // { '&zIndex': 1, width: 120, height: 150, top: 71, left: 134, $opacity: 0.5 },85 // { '&zIndex': 2, width: 130, height: 170, top: 61, left: 0, $opacity: 0.6 },86 // { '&zIndex': 3, width: 170, height: 218, top: 37, left: 110, $opacity: 0.7 },87 // { '&zIndex': 4, width: 224, height: 288, top: 0, left: 262, $opacity: 1 },88 // { '&zIndex': 3, width: 170, height: 218, top: 37, left: 468, $opacity: 0.7 },89 // { '&zIndex': 2, width: 130, height: 170, top: 61, left: 620, $opacity: 0.6 },90 // { '&zIndex': 1, width: 120, height: 150, top: 71, left: 496, $opacity: 0.5 }91 // ]92 this.states = states93 // this.states = [{ '&zIndex': 4, width: w, height: h, top: height * 0.5 - h * 0.5, left: width * 0.5 - w * 0.5, $opacity: 1 },]94 this.lis = this.$ele.find('li')95 this.interval96 // ç¹å»åæ¢å°ä¸ä¸å¼ 97 this.$ele.find('section.next').on('click', function () {98 this.stop()99 this.next()100 this.play()101 }.bind(this))102 // ç¹å»åæ¢å°ä¸ä¸å¼ 103 this.$ele.find('section.previous').on('click', function () {104 this.stop()105 this.prev()106 this.play()107 }.bind(this))108 this.move()109 // 让轮æå¾å¼å§èªå¨ææ¾110 this.play()111 }112 Slide.prototype = {113 // ååæ¯ä¸ä¸ªå¯¹è±¡ï¼æ以åæä¸ä¸ªè±æ¬å·114 // move()æ¹æ³è®©è½®æå¾å°è¾¾statesæå®çç¶æ115 // <1>å½é¡µé¢æå¼æ¶å°è½®æå¾ä»ä¸å¿ç¹å±å¼116 // <2>å½è½®æå¾å·²ç»å±å¼æ¶ï¼ä¼æ»å¨è½®æå¾(éè¦ç¿»è½¬statesæ°ç»ä¸çæ°æ®)117 move: function () {118 let indexCurrent = this.indexCurrent119 d3.selectAll('.text-zySlide').style('opacity', (d, i)=> (i == indexCurrent)?1:0)120 this.lis.each(function (i, el) {121 $(el)122 .css('z-index', this.states[i]['&zIndex'])123 .finish().animate(this.states[i], this.options.speed)124 // .stop(true,true).animate(states[i], 1000)125 .find('img').css('opacity', this.states[i].$opacity)126 }.bind(this))127 },128 // 让轮æå¾åæ¢å°ä¸ä¸å¼ 129 next: function () {130 let indexCurrent = this.indexCurrent131 this.indexCurrent = (indexCurrent +ãthis.len_li + 1) % this.len_li132 this.states.unshift(this.states.pop())133 this.move()134 135 },136 // 让轮æå¾æ»å¨å°ä¸ä¸å¼ 137 prev: function () {138 let indexCurrent = this.indexCurrent139 this.indexCurrent = (indexCurrent +ãthis.len_li - 1) % this.len_li140 this.states.push(this.states.shift())141 this.move()142 },143 play: function () {144 this.interval = setInterval(function () {//è¿ä¸ªthisæwindow145 // setIntervalãsetTimeOut ä¸çthisæåwindow146 // states.unshift(states.pop()) //ä»åå¾åèµ°147 // states.push(states.shift()) //ä»åå¾åèµ°148 this.next()149 }.bind(this), this.options.delay)150 },151 // åæ¢èªå¨ææ¾152 stop: function () {153 // var _this = this154 clearInterval(this.interval)155 }156 }157 $.fn.zySlide = function (options) {158 this.each(function (i, ele) {159 new Slide(ele, options)160 })161 return this162 }...
main.js
Source:main.js
1const totalDrinkPercentBox = document.querySelector('.total-drink')2const totalRemainingNum = document.querySelector('.total-remained span')3const totalRemainingBox = document.querySelector('.total-remained')4const goalInput = document.querySelector('.goal-num')5const totalSmallCup = document.querySelector('.total-cups')6//Nháºp sá» lÃt target7goalInput.oninput = function () {8 //Chuyá»n Äá»i giá trá» sang mililit9 const goalNum = +document.querySelector('.goal-num').value * 100010 //render cup nhá» theo sá» lượng target11 renderingCupsmall(goalNum)12 const smallCups = document.querySelectorAll('.cup-small')13 //Äiá»u chá»nh width theo sá» lượng cup Äá» 50% target nằm trên 1 hà ng14 totalSmallCup.style.width = (250 * (goalNum / 2000)) + 'px';15 //Khá»i tạo giá trá» hiá»n tại16 var indexCurrent;17 smallCups.forEach(function (cup, index) {18 //Gán event cho cup con19 cup.onclick = function (e) {20 //Nếu cup Äã Äá» Äầy và không phải là giá trá» hiá»n tại21 if (cup.matches('.fill-cup') && indexCurrent != index) {22 // Äá» hết tất cả các nÆ°á»c á» vá» trà trÆ°á»c nó23 for (var i = index + 1; i <= smallCups.length - 1; ++i) {24 smallCups[i].classList.remove('fill-cup')25 }26 // Nếu là cup trùng vá»i giá trá» hiá»n tại27 } else if (indexCurrent == index) {28 // Äá» hết tất cả các nÆ°á»c29 for (var i = 0; i <= index; i++) {30 smallCups[i].classList.remove('fill-cup')31 }32 }33 else {34 for (var i = 0; i <= index; i++) {35 smallCups[i].classList.add('fill-cup')36 }37 for (var i = index + 1; i <= (smallCups.length - 1); ++i) {38 smallCups[i].classList.remove('fill-cup')39 }40 }41 //Äiá»u chá»nh bình nÆ°á»c lá»n42 indexCurrent = document.querySelectorAll('.fill-cup').length - 143 var totalDrink = 250 * (+indexCurrent + 1)44 var totalRemaining = ((goalNum - totalDrink) / 1000).toFixed(2)45 var totalDrinkPercent = (totalDrink / goalNum * 100).toFixed(1)46 totalDrinkPercentBox.innerText = totalDrinkPercent + '%';47 totalRemainingNum.innerText = totalRemaining48 totalRemainingBox.style.height = (100 - totalDrinkPercent) + '%';49 totalDrinkPercentBox.style.height = totalDrinkPercent + '%';50 if (indexCurrent == -1) {51 totalDrinkPercentBox.innerText = '';52 } else if (indexCurrent >= smallCups.length - 1) {53 totalRemainingNum.innerText = '';54 } else {55 }56 }57 })58}59function renderingCupsmall(num) {60 //Tạo mảng chứa sá» lượng cup61 var allCupsIndex = [];62 //Dùng vòng lặp Äá» push từng cup63 for (var i = 0; i < num / 250; ++i) {64 allCupsIndex.push(i)65 }66 //Tạo html cho từng cup67 var totalCupsInBox = allCupsIndex.map(function (cup, index) {68 return `<div class="cup cup-small" data-index="${index}">250 ml</div>`69 }).join('')70 //render và o box chứa cup nhá»71 totalSmallCup.innerHTML = totalCupsInBox72}73// let indexCurrent;74// goalInput.oninput = function (e) {75// const goalNum = +e.target.value * 1000;76// renderingCupSmalls(goalNum)77// const allSmallCups = document.querySelectorAll('.cup-small')78// allSmallCups.forEach((smallCup, index) => {79// smallCup.addEventListener('click', function (e) {80// // Thao tác cup81// const totalcups = allSmallCups.length;82// if (smallCup.classList.contains('fill-cup') && indexCurrent != index) {83// for (let i = index + 1; i < totalcups; ++i) {84// allSmallCups[i].classList.remove('fill-cup')85// }86// } else if (indexCurrent == index) {87// for (let i = 0; i <= index; ++i) {88// allSmallCups[i].classList.remove('fill-cup')89// }90// } else {91// for (let i = 0; i <= index; i++) {92// allSmallCups[i].classList.add('fill-cup')93// }94// for (let i = index + 1; i < totalcups; i++) {95// allSmallCups[i].classList.remove('fill-cup')96// }97// }98// indexCurrent = +document.querySelectorAll('.fill-cup').length - 199// // Thao tác BIG CUP100// let totalDrink = (indexCurrent + 1) * 250101// let totalRemaining = (goalNum - totalDrink)102// let totalRemainingToLits = (totalRemaining / 1000).toFixed(2)103// let totalDrinkPercent = ((totalDrink / goalNum) * 100).toFixed(1)104// let totalRemainingPercent = ((totalRemaining / goalNum) * 100).toFixed(1)105// totalDrinkPercentBox.innerText = `${totalDrinkPercent}%`106// totalRemainingNum.innerText = `${totalRemainingToLits}`107// totalDrinkPercentBox.style.height = `${totalDrinkPercent}%`108// totalRemainingBox.style.height = `${totalRemainingPercent}%`109// if (indexCurrent < 0) {110// totalDrinkPercentBox.innerText = ''111// } else if (indexCurrent > totalcups - 1) {112// totalRemainingNum.innerText = ''113// }114// })115// })116// }117// function renderingCupSmalls(num) {118// const cups = []119// for (let i = 0; i < num / 250; ++i) {120// cups.push(i)121// }122// const cupsHTML = cups.map((cup, index) => `<div class="cup cup-small" data-index="${index}">250 ml</div>`).join('')123// totalSmallCup.innerHTML = cupsHTML...
nav-days.js
Source:nav-days.js
1var lastDay = new Date(dt.getYear(), dt.getMonth() + 1, 0);2var nbMaxDays = lastDay.getDate();3console.log(nbMaxDays);4daysMonth = new Array(nbMaxDays);5for (var i = 0; i < nbMaxDays; i++) {6 daysMonth[i] = i + 1;7}8console.log(daysMonth);9var checkIndex = false;10var indexCurrent = null;11var posCenter = null;12if (checkIndex == false) {13 indexCurrent = daysMonth.indexOf(dayCur);14 posCenter = indexCurrent;15 checkIndex = true;16}17function changeDayNext() {18 if (posCenter != indexCurrent) {19 indexCurrent = posCenter;20 }21 document.getElementById("dayPrev").innerHTML = daysMonth[indexCurrent];22 indexCurrent++;23 posCenter = indexCurrent;24 document.getElementById("dayCurrent").innerHTML = daysMonth[posCenter];25 var x = document.getElementById("dayPrev");26 var y = document.getElementById("butDayBack");27 if (x.style.visibility === "hidden" && y.style.visibility === "hidden") {28 document.getElementById("dayPrev").style.visibility = "visible";29 document.getElementById("butDayBack").style.visibility = "visible";30 }31 if (posCenter === nbMaxDays - 1) {32 document.getElementById("dayNext").style.visibility = "hidden";33 document.getElementById("butDayNext").style.visibility = "hidden";34 } else if (posCenter < nbMaxDays) {35 indexCurrent++;36 document.getElementById("dayNext").innerHTML = daysMonth[indexCurrent];37 }38}39function changeDayPrevious() {40 if (posCenter != indexCurrent) {41 indexCurrent = posCenter;42 }43 document.getElementById("dayNext").innerHTML = daysMonth[indexCurrent];44 indexCurrent--;45 posCenter = indexCurrent;46 document.getElementById("dayCurrent").innerHTML = daysMonth[posCenter];47 var x = document.getElementById("dayNext");48 var y = document.getElementById("butDayNext");49 if (x.style.visibility === "hidden" && y.style.visibility === "hidden") {50 document.getElementById("dayNext").style.visibility = "visible";51 document.getElementById("butDayNext").style.visibility = "visible";52 }53 if (posCenter === 0) {54 document.getElementById("dayPrev").style.visibility = "hidden";55 document.getElementById("butDayBack").style.visibility = "hidden";56 } else if (posCenter > 0) {57 indexCurrent--;58 document.getElementById("dayPrev").innerHTML = daysMonth[indexCurrent];59 }...
Using AI Code Generation
1const fc = require('fast-check');2const { indexCurrent } = require('fast-check-monorepo');3const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];4const index = indexCurrent(array, 3);5const fc = require('fast-check');6const { indexCurrent } = require('fast-check-monorepo');7const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];8const index = indexCurrent(array, 3);9const fc = require('fast-check');10const { indexCurrent } = require('fast-check-monorepo');11const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];12const index = indexCurrent(array, 3);13const fc = require('fast-check');14const { indexCurrent } = require('fast-check-monorepo');15const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];16const index = indexCurrent(array, 3);17const fc = require('fast-check');18const { indexCurrent } = require('fast-check-monorepo');19const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];20const index = indexCurrent(array, 3);21const fc = require('fast-check');22const { indexCurrent } = require('fast-check-monorepo');
Using AI Code Generation
1const { indexCurrent } = require('fast-check-monorepo')2const { indexCurrent } = require('fast-check')3const { indexCurrent } = require('fast-check')4const { indexCurrent } = require('fast-check')5const { indexCurrent } = require('fast-check')6const { indexCurrent } = require('fast-check')7const { indexCurrent } = require('fast-check')8const { indexCurrent } = require('fast-check')9const { indexCurrent } = require('fast-check')10const { indexCurrent } = require('fast-check')11const { indexCurrent } = require('fast-check')12const { indexCurrent } = require('fast-check')13const { indexCurrent } = require('fast-check')14const { indexCurrent } = require('fast-check')15const { indexCurrent } = require('fast-check')16const { indexCurrent } = require('fast-check')17const { indexCurrent } = require('fast-check')18const { indexCurrent } = require('fast-check')19const { indexCurrent } = require('fast-check')20const { indexCurrent } = require('fast-check')21const { indexCurrent } = require('fast-check')22const { indexCurrent } = require('fast-check')23const { indexCurrent } = require('fast-check')
Using AI Code Generation
1import * as fc from 'fast-check';2import { indexCurrent } from 'fast-check-monorepo';3console.log(fc);4console.log(indexCurrent);5{6 "compilerOptions": {7 },8}9{10 "scripts": {11 },12 "dependencies": {13 }14}15{16 "dependencies": {17 "fast-check": {
Using AI Code Generation
1const fc = require('fast-check');2const { indexCurrent } = require('fast-check/src/check/arbitrary/IntegerArbitrary');3const { indexNext } = require('fast-check/src/check/arbitrary/IntegerArbitrary');4const { indexPrevious } = require('fast-check/src/check/arbitrary/IntegerArbitrary');5const index = indexCurrent(0, 10);6const index1 = indexNext(0, 10);7const index2 = indexPrevious(0, 10);8const index3 = indexNext(9, 10);9const index4 = indexPrevious(9, 10);10const index5 = indexNext(10, 10);11const index6 = indexPrevious(10, 10);12const index7 = indexNext(11, 10);13const index8 = indexPrevious(11, 10);14const index9 = indexNext(100, 10);15const index10 = indexPrevious(100, 10);16const index11 = indexNext(101, 10);17const index12 = indexPrevious(101, 10);18const index13 = indexNext(1000, 10);19const index14 = indexPrevious(1000, 10);20const index15 = indexNext(1001, 10);21const index16 = indexPrevious(1001, 10);22const index17 = indexNext(10000, 10);23const index18 = indexPrevious(10000, 10);24const index19 = indexNext(10001, 10);
Using AI Code Generation
1const { indexCurrent } = require('fast-check-monorepo');2const { indexCurrent } = require('fast-check-monorepo');3const fc = require('fast-check');4const { indexCurrent } = require('fast-check-monorepo');5const fc = require('fast-check');6const { indexCurrent } = require('fast-check-monorepo');7const fc = require('fast-check');8const { indexCurrent } = require('fast-check-monorepo');9const fc = require('fast-check');10const { indexCurrent } = require('fast-check-monorepo');11const fc = require('fast-check');12const { indexCurrent } = require('fast-check-monorepo');13const fc = require('fast-check');14const { indexCurrent } = require('fast-check-monorepo');15const fc = require('fast-check');16const { indexCurrent } = require('fast-check-monorepo');17const fc = require('fast-check');18const { indexCurrent } = require('fast-check-monorepo');19const fc = require('fast-check');20const { indexCurrent } = require('fast-check-monorepo');21const fc = require('fast-check');22const { indexCurrent } = require('fast-check-monorepo');23const fc = require('fast-check');24const { indexCurrent } = require('fast-check-monorepo');25const fc = require('fast-check');26const { indexCurrent } = require('fast-check-monorepo');27const fc = require('fast-check');28const { indexCurrent } = require('fast-check-monorepo');29const fc = require('fast-check');30const { indexCurrent } = require('fast-check-monorepo');31const fc = require('fast-check');32const { indexCurrent } = require('fast-check-monorepo');33const fc = require('fast-check');34const { indexCurrent } = require('fast-check-monorepo');35const fc = require('fast-check');36const { indexCurrent } = require('fast-check-monorepo');37const fc = require('fast-check');38const { indexCurrent } = require('fast-check-monorepo');39const fc = require('fast-check');40const { indexCurrent } = require('fast-check-monorepo');41const fc = require('fast-check');42const { indexCurrent } = require('fast-check-monorepo');43const fc = require('fast-check');44const { indexCurrent } = require('fast-check-monorepo');45const fc = require('fast-check');
Using AI Code Generation
1const fc = require('fast-check');2const { indexCurrent } = require('fast-check-monorepo');3const index = indexCurrent();4const fc = require('fast-check');5const { indexCurrent } = require('fast-check-monorepo');6const index = indexCurrent();7MIT - see [LICENSE](LICENSE)
Using AI Code Generation
1const { indexCurrent, indexTotal, indexTotal } = require('fast-check-monorepo');2const currentTestIndex = indexCurrent();3const totalTests = indexTotal();4const totalTests = indexTotal();5console.log(`Current test index is: ${currentTestIndex}`);6console.log(`Total tests are: ${totalTests}`);7console.log(`Total tests are: ${totalTests}`);
Using AI Code Generation
1const indexCurrent = require('../index.js')2const index = indexCurrent({})3console.log(index)4const indexCurrent = require('../index.js')5const index = indexCurrent({})6console.log(index)7const indexCurrent = require('../index.js')8const index = indexCurrent({})9console.log(index)10const indexCurrent = require('../index.js')11const index = indexCurrent({})12console.log(index)13const indexCurrent = require('../index.js')14const index = indexCurrent({})15console.log(index)16const indexCurrent = require('../index.js')17const index = indexCurrent({})18console.log(index)19const indexCurrent = require('../index.js')20const index = indexCurrent({})21console.log(index)22const indexCurrent = require('../index.js')23const index = indexCurrent({})24console.log(index)
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!!