From 538cda754c0e98508a87f32b5a185808cf7d12b5 Mon Sep 17 00:00:00 2001 From: typicode Date: Sun, 7 Jan 2024 02:49:48 +0100 Subject: [PATCH] refactor: kaomoji selection logic in bin.ts --- src/bin.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/bin.ts b/src/bin.ts index f1bc3f7..cb8344a 100644 --- a/src/bin.ts +++ b/src/bin.ts @@ -101,7 +101,10 @@ function logRoutes(data: Data) { const kaomojis = ['♡⸜(˶˃ ᵕ ˂˶)⸝♡', '♡( ◡‿◡ )', '( ˶ˆ ᗜ ˆ˵ )', '(˶ᵔ ᵕ ᵔ˶)'] -// Get system current language +function randomItem(items: string[]): string { + const index = Math.floor(Math.random() * items.length) + return items.at(index) ?? '' +} app.listen(port, () => { console.log( @@ -110,7 +113,7 @@ app.listen(port, () => { chalk.gray('Press CTRL-C to stop'), chalk.gray(`Watching ${file}...`), '', - chalk.magenta(kaomojis[Math.floor(Math.random() * kaomojis.length)]), + chalk.magenta(randomItem(kaomojis)), '', chalk.bold('Index:'), chalk.gray(`http://localhost:${port}/`),