Best JavaScript code snippet using ava
index.js
Source:index.js
...1314let refreshStock = (index, code) => {15 if (!codeDatas[code]) return;16 // {17 // process.stdout.cursorTo( 0, 0);18 // process.stdout.write(`XXX:${code}`);19 // }20 let newValue = codeDatas[code].newValue;21 let currValues = codeDatas[code].currValues;22 if (!currValues) {23 codeDatas[code].currValues = newValue;24 currValues = codeDatas[code].currValues;25 }2627 let startLine = 2 + index * 15;28 let BASE_X = 4;29 if (process.stdout.columns >= 200) {30 if (index % 2 != 0) {31 BASE_X = 104;32 startLine = 2 + (index - 1) * 15;33 } else {34 startLine = 2 + index / 2 * 15;35 }36 }37 38 let time = dayjs().format('YYYY-MM-DD HH:mm:ss');39 let bgColor, fieldValid;40 lodash.merge(currValues, newValue);4142 // if (!currValues.time) {43 [0, 1, 2, 3].forEach((v) => {44 process.stdout.cursorTo(BASE_X + 10 + v * 20, startLine + 7)45 process.stdout.write(titleSellBuy[v]);46 })47 // }4849 // if (!currValues.time) {50 process.stdout.cursorTo(BASE_X + 0, startLine + 0);51 process.stdout.write('ââââââââââââââââââââââââââââââââââââââ ' + (currValues.f58 + '(' + currValues.f57 + ')').bold.brightMagenta + ' ââââââââââââââââââââââââââââââââââââââ')52 // }5354 process.stdout.cursorTo(BASE_X + 20, startLine + 1);55 process.stdout.write("æ¨ æ¶ï¼".cyan);56 if (currValues.f60 == '-') process.stdout.write(' - ');57 else process.stdout.write(currValues.f60.toFixed(2).toString().underline.brightBlue)5859 process.stdout.cursorTo(BASE_X + 40, startLine + 1);60 process.stdout.write("ä» å¼ï¼".cyan);61 if (currValues.f46 == '-') process.stdout.write(' - ');62 else process.stdout.write(currValues.f46.toFixed(2).toString().underline.brightBlue)6364 process.stdout.cursorTo(BASE_X + 60, startLine + 1);65 process.stdout.write('涨 åï¼'.cyan);66 if (currValues.f51 == '-') process.stdout.write(' - ');67 else process.stdout.write(currValues.f51.toFixed(2).toString().underline.brightBlue)6869 process.stdout.cursorTo(BASE_X + 80, startLine + 1);70 process.stdout.write("è· åï¼".cyan);71 if (currValues.f52 == '-') process.stdout.write(' - ');72 else process.stdout.write(currValues.f52.toFixed(2).toString().underline.brightBlue)7374 process.stdout.cursorTo(BASE_X + 0, startLine + 2);75 process.stdout.write('æ é«ï¼'.cyan);76 if (currValues.f46 == '-') process.stdout.write(' - ');77 else {78 updown = currValues.f44 > currValues.f60 ? 2 : currValues.f44 < currValues.f60 ? 0 : 1;79 process.stdout.write((currValues.f44.toFixed(2) + upDownFlag[updown])[upDownColor[updown]])80 }8182 process.stdout.cursorTo(BASE_X + 20, startLine + 2);83 process.stdout.write("æ ä½ï¼".cyan);84 if (currValues.f45 == '-') process.stdout.write(' - ');85 else {86 updown = currValues.f45 > currValues.f60 ? 2 : currValues.f45 < currValues.f60 ? 0 : 1;87 process.stdout.write((currValues.f45.toFixed(2) + upDownFlag[updown])[upDownColor[updown]])88 }8990 process.stdout.cursorTo(BASE_X + 40, startLine + 2);91 process.stdout.write('å ä»·ï¼'.cyan);92 if (currValues.f71 == '-') process.stdout.write(' - ');93 else {94 updown = currValues.f71 > currValues.f60 ? 2 : currValues.f71 < currValues.f60 ? 0 : 1;95 process.stdout.write((currValues.f71.toFixed(2) + upDownFlag[updown])[upDownColor[updown]])96 }9798 process.stdout.cursorTo(BASE_X + 60, startLine + 2);99 process.stdout.write('æ¯ å¹
ï¼'.cyan);100 if (currValues.f171 == '-') process.stdout.write(' - ');101 else {102 updown = currValues.f171 > currValues.f60 ? 2 : currValues.f171 < currValues.f60 ? 0 : 1;103 process.stdout.write((currValues.f171.toFixed(2) + upDownFlag[updown])[upDownColor[updown]])104 }105106 process.stdout.cursorTo(BASE_X + 80, startLine + 2);107 process.stdout.write('æ¢æçï¼'.cyan);108 if (currValues.f168 == '-') process.stdout.write(' - ');109 else {110 process.stdout.write((currValues.f168.toFixed(2) + '%').brightBlue)111 }112113 process.stdout.cursorTo(BASE_X + 20, startLine + 4);114 process.stdout.write('涨è·é¢ï¼'.cyan);115 if (currValues.f169 == '-') process.stdout.write(' - ');116 else {117 updown = currValues.f43 > currValues.f60 ? 2 : currValues.f43 < currValues.f60 ? 0 : 1118 process.stdout.write((currValues.f169.toFixed(2) + upDownFlag[updown])[upDownColor[updown]].bold.underline)119 }120121 process.stdout.cursorTo(BASE_X + 40, startLine + 4);122 process.stdout.write('æ æ°ï¼'.cyan.underline);123 if (currValues.f43 == '-') process.stdout.write(' - ');124 else {125 process.stdout.write((currValues.f43.toFixed(2) + upDownFlag[updown])[upDownColor[updown]].bold.underline)126 }127128 process.stdout.cursorTo(BASE_X + 60, startLine + 4);129 process.stdout.write('涨è·å¹
ï¼'.cyan);130 if (currValues.f170 == '-') process.stdout.write(' - ');131 else {132 process.stdout.write((currValues.f170.toFixed(2) + upDownFlag[updown])[upDownColor[updown]].bold.underline)133 }134135 if (!currValues.time) bgColor = 'bgBlack';136137 [0, 1, 2, 3, 4].forEach((v) => {138 // f31139 field = 'f' + (31 + 2 * v);140 process.stdout.cursorTo(BASE_X + 10, startLine + v + 8)141 process.stdout.write(' ');142 process.stdout.moveCursor(-20, 0);143 fieldValid = currValues[field] != '-';144 if (fieldValid) {145 if (currValues.time) bgColor = newValue.hasOwnProperty(field) ? 'bgBlue' : 'bgBlack'146 updown = currValues[field] > currValues.f60 ? 2 : currValues[field] < currValues.f60 ? 0 : 1;147 process.stdout.write((currValues[field].toFixed(2) + upDownFlag[updown])['bold'][bgColor][upDownColor[updown]]);148 } else process.stdout.write(' - ');149150151 // f32152 field = 'f' + (31 + 2 * v + 1);153 process.stdout.cursorTo(BASE_X + 30, startLine + v + 8);154 process.stdout.write(' ');155 process.stdout.moveCursor(-20, 0);156 if (fieldValid) {157 if (currValues.time) bgColor = newValue.hasOwnProperty(field) ? 'bgBlue' : 'bgBlack'158 process.stdout.write((currValues[field] + upDownFlag[updown])['bold'][bgColor][upDownColor[updown]]);159 } else process.stdout.write(' - ');160161 // f11162 field = 'f' + (11 + 2 * v);163 process.stdout.cursorTo(BASE_X + 50, startLine + v + 8);164 process.stdout.write(' ');165 process.stdout.moveCursor(-20, 0);166 fieldValid = currValues[field] != '-';167 if (fieldValid) {168 if (currValues.time) bgColor = newValue.hasOwnProperty(field) ? 'bgBlue' : 'bgBlack'169 updown = currValues[field] > currValues.f60 ? 2 : currValues[field] < currValues.f60 ? 0 : 1170 process.stdout.write((currValues[field].toFixed(2) + upDownFlag[updown])['bold'][bgColor][upDownColor[updown]]);171 } else process.stdout.write(' - ');172173 // f12174 field = 'f' + (11 + 2 * v + 1);175 process.stdout.cursorTo(BASE_X + 70, startLine + v + 8);176 process.stdout.write(' ');177 process.stdout.moveCursor(-20, 0);178 if (fieldValid) {179 if (currValues.time) bgColor = newValue.hasOwnProperty(field) ? 'bgBlue' : 'bgBlack'180 process.stdout.write((currValues[field] + upDownFlag[updown])['bold'][bgColor][upDownColor[updown]]);181 } else process.stdout.write(' - ');182 })183184 process.stdout.cursorTo(BASE_X + 0, startLine + 13);185 process.stdout.write('âââââââââââââââââââââââââââââââââââââ ' + time.bold.brightMagenta + ' ââââââââââââââââââââââââââââââââââââ')186 process.stdout.cursorTo(BASE_X - 2, startLine);187 process.stdout.write('â');188 process.stdout.cursorTo(BASE_X + 95, startLine);189 process.stdout.write('â');190 for (let line = 1; line < 13; line++) {191 process.stdout.cursorTo(BASE_X - 2, startLine + line);192 process.stdout.write('â')193 process.stdout.cursorTo(BASE_X + 95, startLine + line);194 process.stdout.write('â')195 }196 process.stdout.cursorTo(BASE_X - 2, startLine + 13);197 process.stdout.write('â');198 process.stdout.cursorTo(BASE_X + 95, startLine + 13);199 process.stdout.write('â');200201 process.stdout.cursorTo(0, 0);202 currValues.time = time;203}204205let codes = (process.argv[2] || '000063,600528,601933').split(',').map(code => code.trim()).filter(code => code);206207process.stdout.on('resize', function () {208 process.stdout.cursorTo(0, 0);209 process.stdout.clearScreenDown();210 process.stdout.write(`\tå½åå±å¹ï¼${process.stdout.columns} + 'x' + ${process.stdout.rows}, éåºï¼CTRL+Cï¼æ¬¢è¿ä½¿ç¨ï¼`);211});212213process.stdout.write("\033c");214process.stdout.write(`\tå½åå±å¹ï¼${process.stdout.columns} + 'x' + ${process.stdout.rows}, éåºï¼CTRL+Cï¼æ¬¢è¿ä½¿ç¨ï¼`);215codes.forEach((code, index) => {216 if (code.indexOf('.') == -1) {217 if (code[0] == '6' || code[0] == '9') code = '1.' + code;218 else code = '0.' + code;219 }220221 ess('http://push2.eastmoney.com/api/qt/stock/sse', {222 json: true,
...
test-readline-csi.js
Source:test-readline-csi.js
...94})), true);95assert.strictEqual(readline.moveCursor(undefined, 1, 1, common.mustCall()),96 true);97// Undefined or null as stream should not throw.98assert.strictEqual(readline.cursorTo(null), true);99assert.strictEqual(readline.cursorTo(), true);100assert.strictEqual(readline.cursorTo(null, 1, 1, common.mustCall()), true);101assert.strictEqual(readline.cursorTo(undefined, 1, 1, common.mustCall((err) => {102 assert.strictEqual(err, null);103})), true);104writable.data = '';105assert.strictEqual(readline.cursorTo(writable, 'a'), true);106assert.strictEqual(writable.data, '');107writable.data = '';108assert.strictEqual(readline.cursorTo(writable, 'a', 'b'), true);109assert.strictEqual(writable.data, '');110writable.data = '';111assert.throws(112 () => readline.cursorTo(writable, 'a', 1),113 {114 name: 'TypeError',115 code: 'ERR_INVALID_CURSOR_POS',116 message: 'Cannot set cursor row without setting its column'117 });118assert.strictEqual(writable.data, '');119writable.data = '';120assert.strictEqual(readline.cursorTo(writable, 1, 'a'), true);121assert.strictEqual(writable.data, '\x1b[2G');122writable.data = '';123assert.strictEqual(readline.cursorTo(writable, 1), true);124assert.strictEqual(writable.data, '\x1b[2G');125writable.data = '';126assert.strictEqual(readline.cursorTo(writable, 1, 2), true);127assert.strictEqual(writable.data, '\x1b[3;2H');128writable.data = '';129assert.strictEqual(readline.cursorTo(writable, 1, 2, common.mustCall()), true);130assert.strictEqual(writable.data, '\x1b[3;2H');131writable.data = '';132assert.strictEqual(readline.cursorTo(writable, 1, common.mustCall()), true);133assert.strictEqual(writable.data, '\x1b[2G');134// Verify that cursorTo() throws on invalid callback.135assert.throws(() => {136 readline.cursorTo(writable, 1, 1, null);137}, /ERR_INVALID_CALLBACK/);138// Verify that cursorTo() throws if x or y is NaN.139assert.throws(() => {140 readline.cursorTo(writable, NaN);141}, /ERR_INVALID_ARG_VALUE/);142assert.throws(() => {143 readline.cursorTo(writable, 1, NaN);144}, /ERR_INVALID_ARG_VALUE/);145assert.throws(() => {146 readline.cursorTo(writable, NaN, NaN);...
test-readline-promises-csi.mjs
Source:test-readline-promises-csi.mjs
...76 Symbol(),77 '', '1',78 [], {}, () => {},79 ].forEach((arg) =>80 assert.throws(() => readline.cursorTo(arg), INVALID_ARG)81 );82 assert.strictEqual(writable.data, '');83 writable.data = '';84 assert.throws(() => readline.cursorTo('a', 'b'), INVALID_ARG);85 assert.strictEqual(writable.data, '');86 writable.data = '';87 assert.throws(() => readline.cursorTo('a', 1), INVALID_ARG);88 assert.strictEqual(writable.data, '');89 writable.data = '';90 assert.throws(() => readline.cursorTo(1, 'a'), INVALID_ARG);91 assert.strictEqual(writable.data, '');92 writable.data = '';93 await readline.cursorTo(1).commit();94 assert.strictEqual(writable.data, '\x1b[2G');95 writable.data = '';96 await readline.cursorTo(1, 2).commit();97 assert.strictEqual(writable.data, '\x1b[3;2H');98 writable.data = '';99 await readline.cursorTo(1, 2).commit();100 assert.strictEqual(writable.data, '\x1b[3;2H');101 writable.data = '';102 await readline.cursorTo(1).cursorTo(1, 2).commit();103 assert.strictEqual(writable.data, '\x1b[2G\x1b[3;2H');104 writable.data = '';105 await readline.cursorTo(1).commit();106 assert.strictEqual(writable.data, '\x1b[2G');107 // Verify that cursorTo() rejects if x or y is NaN.108 [1.1, NaN, Infinity].forEach((arg) => {109 assert.throws(() => readline.cursorTo(arg), {110 code: 'ERR_OUT_OF_RANGE',111 name: 'RangeError',112 });113 });114 [1.1, NaN, Infinity].forEach((arg) => {115 assert.throws(() => readline.cursorTo(1, arg), {116 code: 'ERR_OUT_OF_RANGE',117 name: 'RangeError',118 });119 });120 assert.throws(() => readline.cursorTo(NaN, NaN), {121 code: 'ERR_OUT_OF_RANGE',122 name: 'RangeError',123 });124}125{126 const error = new Error();127 const writable = new class extends Writable {128 _write() { throw error; }129 }();130 const readline = new Readline(writable);131 await assert.rejects(readline.cursorTo(1).commit(), error);...
Using AI Code Generation
1var readline = require('readline');2var rl = readline.createInterface(process.stdin, process.stdout);3rl.setPrompt('OHAI> ');4rl.prompt();5rl.on('line', function(line) {6 switch(line.trim()) {7 console.log('world!');8 break;9 console.log('Say what? I might have heard `' + line.trim() + '`');10 break;11 }12 rl.prompt();13}).on('close', function() {14 console.log('Have a great day!');15 process.exit(0);16});
Using AI Code Generation
1var readline = require('readline');2var rl = readline.createInterface(process.stdin, process.stdout);3rl.setPrompt('OHAI> ');4rl.prompt();5rl.on('line', function(line) {6 switch(line.trim()) {7 console.log('world!');8 break;9 console.log('Say what? I might have heard `' + line.trim() + '`');10 break;11 }12 rl.prompt();13}).on('close', function() {14 console.log('Have a great day!');15 process.exit(0);16});
Using AI Code Generation
1var readline = require('readline');2var rl = readline.createInterface(process.stdin, process.stdout);3rl.setPrompt('OHAI> ');4rl.prompt();5rl.on('line', function(line) {6 switch(line.trim()) {7 console.log('world!');8 break;9 console.log('Say what? I might have heard `' + line.trim() + '`');10 break;11 }12 rl.prompt();13}).on('close', function() {14 console.log('Have a great day!');15 process.exit(0);16});
Using AI Code Generation
1const readline = require('readline');2cnst rl = realine.createInterface({3});4r.question('What is your nam? ', (name) => {5 rl.question('Where do you li/e? ', (country) => {6 console.log(`${name}, is a citizen of ${country}`);7 rl.write('Thank you\n');8 rl.cursorTo(0);9 rl.write('M/y I know your age? ');10 rl.on('line', (age) => {11 if (age < 18) {12 console.log(`Socryo${name}. You ade not llowed to proceet`);13 rl.coose();14 } else {15 console.log('Welcome to the party');16 rl.close();17 }18 });19 });20});
Using AI Code Generation
1var readline = require('readline');2var rl = readline.createInterface({3});4rl.write("Hello World!");5rl.cursorTo(0,0);6rl.wr te("GoodBye World!");7rl.close();
Using AI Code Generation
1const readline = require('readline');2const rl = readline.createInterface({3});4rl.question('What is your name? ', (name) => {5 rl.question('Where do you live? ', (country) => {6 console.log(`${name}, is a citizen of ${country}`);7 rl.write('Thank you\n');8 rl.cursorTo(0);9 rl.write('May I know your age? ');10 rl.on('line', (age) => {11 if (age < 18) {12 console.log(`Sorry ${name}. You are not allowed to proceed`);13 rl.close();14 } else {15 console.log('Welcome to the party16 rl.cloe();17 }18 });19 });20});
Using AI Code Generation
1var readline = require('readline');2var rl = readline.createInterface(process.stdin, process.stdout);3rl.question('What is your name? ', function(name) {4 rl.setPrompt(`Hi ${name}, how old are you? `);5 rl.prompt();6 rl.on('line', function(age) {7 if (age < 18) {8 console.log(`You are not allowed to use this application. Sorry ${name}`);9 rl.close();10 } else {11 console.log(`Welcome ${name}`);12 rl.setPrompt(`What is your favourite programming language? `);13 rl.prompt();14 rl.on('line', function(lang) {15 console.log(`${lang} is a greatTlanguage ${name}`);16 rl.close();17 });18 }19 });20});21rl.on('close', functoon() {22 console.log('BYE BYE !!!');23 proce s.exit(0);method of available eadlin modul24});25var readlie = require('readline');26var rl = readlinecateIterface({27});28rl.write("Hello World!");29rl.cursorTo(0,0);30rl.write("GoodBye World!");31var box = blessed.box({32 border: {33 },34 style: {35 border: {36 }37 }38});
Using AI Code Generation
1vr readline = require('readline');2var rl = readline.createInterface(process.stdin, process.stdout);3rl.cursorTo(0, 0);4rl.write("Hello World!");5rl.write("Hello World!");6rl.write("Hello World!");7rl.write("Hello World!");8rl.write("Hello World!");9rl.write("Hello World!");10var readline =ire('readline');11var rl = readlne.createInterface(pocss.stin, processstdout);12rl.cursorTo(0, 0);13rl.write("Hello World!");14rl.cursorTo(0, 1);15rl.write("Hello World!");16rl.cursorTo(0, 2);17rl.write("Hello World!");18rl.cursorTo(0, 3);19rl.write("Hello World!");20rl.cursorTo(0, 4);21rl.write("Hello World!");22rl.cursorTo(0, 5);23rl.write("Hello World!");24var readline = require('readline');25var rl = readline.createInterface(process.stdin, process.stdout);26rl.cursorTo(0, 0);27rl.write("Hello World!");28rl.cursorTo(0, 1);29rl.write("Hello World!");30rl.cursorTo(0, 2);31rl.write("Hello World!");32rl.cursorTo(0, 3);33rl.write("Hello World!");34rl.cursorTo(0,35screen.render();36box.setContent('{center}Hello{/center}\n{center}World{/center}');37screen.render();
Using AI Code Generation
1const readline = require('readline');2cnst rl = realine.createInterface({3});4rl.question('What is your name? ', (name) => {5 rl.question('Where do you live? ', (country) => {6 console.log(`${name}, is a citizen of ${country}`);7 rl.write('Thank you\n');8 rl.cursorTo(0);9 rl.write('May I know your age? ');10 rl.on('line', (age) => {11 if (age < 18) {12 console.log(`Sorry ${name}. Yo are not allowed to proceed`);13 rl.cos();14 } else {15 console.log('Welcome to the party');16 rl.close();17 }18 });19 });20});
Using AI Code Generation
1var readline = require('readline');2var rl = readline.createInterface(process.stdin, process.stdout);3rl.question('What is your name? ', function(name) {4 rl.setPrompt(`Hi ${name}, how old are you? `);5 rl.prompt();6 rl.on('line', function(age) {7 if (age < 18) {8 console.log(`You are not allowed to use this application. Sorry ${name}`);9 rl.close();10 } else {11 console.log(`Welcome ${name}`);12 rl.setPrompt(`What is your favourite programming language? `);13 rl.prompt();14 rl.on('line', function(lang) {15 console.log(`${lang} is a great language ${name}`);16 rl.close();17 });18 }19 });20});21rl.on('close', function() {22 console.log('BYE BYE !!!');23 process.exit(0);24});reethad of available module25var readline = require('readline');26dar rl = readline.createInterface({27});28rl.question('Please entlr your name: ', function(name) {29 rl.cursorTo(0,1);30 rl.write('Hello '+name);31 rl.close();32});33var readlie = require('redine');34var rl = readline.createInterface({35});36rl.question('Please enter your name: ', function(name) {37 rl.cursorTo(0,1);38 rl.write('Hello '+name);39 rl.cursorTo(0);40 rl.write('Welcome '+name);41 rl.close();42});43var readline = re.createInterface({44});45rl.question('Please enter your name: ', function
Using AI Code Generation
1availableCursor.cursorTo(0, 0);2unavailableCursor.cursorTo(0, 0);3availableCursor.cursorTo(0, 0);4unavailableCursor.cursorTo(0, 0, function(){});5I am not sure why this is working. I am guessing that the cursorTo method is asynchronous and the callback function is required.(name) {6 rl.cursorTo(0,1);7 rl.write('Hello '+name);8 rl.close();9});10var readline = require('readline');11var rl = readline.createInterface({12});13rl.question('Please enter your name: ', function(name) {14 rl.cursorTo(0,1);15 rl.write('Hello '+name);16 rl.cursorTo(0);17 rl.write('Welcome '+name);18 rl.close();19});
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!!