Skip to content

Commit e1b0613

Browse files
committed
feat: Add detailed JSDoc comments to startLoader and stopLoader functions for improved documentation
1 parent 2656323 commit e1b0613

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed
Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,44 @@
1-
import readline from 'readline';
1+
import readline from 'readline'
22

3+
/**
4+
* Démarre un indicateur de chargement animé dans le terminal
5+
*
6+
* @param {string} message - Le message à afficher à côté de l'indicateur de chargement
7+
* @returns {NodeJS.Timeout} L'identifiant de l'interval pour pouvoir l'arrêter plus tard
8+
*
9+
* @example
10+
* const loader = startLoader('Chargement en cours...');
11+
* // ... opération longue ...
12+
* stopLoader(loader);
13+
*/
314
export function startLoader(message) {
4-
let currentFrame = 0;
5-
const spinnerFrames = ['-', '\\', '|', '/'];
15+
let currentFrame = 0
16+
const spinnerFrames = ['-', '\\', '|', '/']
617

718
const loaderInterval = setInterval(() => {
819
readline.cursorTo(process.stdout, 0);
920
process.stdout.write(`${spinnerFrames[currentFrame]} ${message} `);
1021
currentFrame = (currentFrame + 1) % spinnerFrames.length;
11-
}, 100);
22+
}, 100)
1223

13-
return loaderInterval;
24+
return loaderInterval
1425
}
1526

27+
/**
28+
* Arrête un indicateur de chargement précédemment démarré
29+
*
30+
* @param {NodeJS.Timeout} loaderInterval - L'identifiant de l'interval retourné par startLoader
31+
*
32+
* @example
33+
* const loader = startLoader('Chargement en cours...');
34+
* // ... opération longue ...
35+
* stopLoader(loader);
36+
*/
1637
export function stopLoader(loaderInterval) {
17-
clearInterval(loaderInterval);
18-
readline.cursorTo(process.stdout, 0);
38+
clearInterval(loaderInterval)
39+
readline.cursorTo(process.stdout, 0)
40+
1941
if (process.stdout.isTTY) {
20-
process.stdout.clearLine(0);
42+
process.stdout.clearLine(0)
2143
}
2244
}

0 commit comments

Comments
 (0)