22 lines
491 B
JavaScript
22 lines
491 B
JavaScript
'use strict';
|
|
|
|
function truncateText(text, maxLen) {
|
|
if (text.length <= maxLen) return text;
|
|
return text.slice(0, maxLen) + '...';
|
|
}
|
|
|
|
function sleep(ms) {
|
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
}
|
|
|
|
async function streamText(prefix, text, delayMs) {
|
|
if (prefix) process.stdout.write(prefix);
|
|
for (const ch of text) {
|
|
process.stdout.write(ch);
|
|
await sleep(delayMs);
|
|
}
|
|
process.stdout.write('\n');
|
|
}
|
|
|
|
module.exports = { truncateText, sleep, streamText };
|