UNPKG

lyric-karaoke-cli

Version:

A CLI application for displaying song lyrics in a karaoke-style format

92 lines (81 loc) 2.18 kB
const chalk = require('chalk'); /** * Logger utility for consistent logging throughout the application */ const logger = { /** * Log information messages * @param {string} message - The message to log */ info: (message) => { console.log(chalk.blue('ℹ INFO: ') + message); }, /** * Log success messages * @param {string} message - The message to log */ success: (message) => { console.log(chalk.green('✓ SUCCESS: ') + message); }, /** * Log error messages * @param {string} message - The message to log * @param {Error} [error] - Optional error object */ error: (message, error) => { console.error(chalk.red('✗ ERROR: ') + message); if (error) { console.error(chalk.red(error.stack || error)); } }, /** * Log warning messages * @param {string} message - The message to log */ warn: (message) => { console.warn(chalk.yellow('⚠ WARNING: ') + message); } }; /** * Format lyrics for display * @param {string} lyrics - The raw lyrics to format * @returns {Array} An array of formatted lyrics lines */ const formatLyrics = (lyrics) => { if (!lyrics) { return []; } // Split by newlines and filter out empty lines const lines = lyrics.split('\n').filter(line => line.trim() !== ''); // Process and format each line return lines.map(line => { // Handle timestamps if present (e.g., [00:24]) const timestampMatch = line.match(/\[\d{2}:\d{2}\]/); if (timestampMatch) { const timestamp = timestampMatch[0]; const text = line.replace(timestamp, '').trim(); return { timestamp, text, formatted: chalk.dim(timestamp) + ' ' + text }; } // Handle section headers (e.g., [Chorus], [Verse]) if (line.match(/^\[.*\]$/)) { return { isSection: true, text: line, formatted: chalk.bold.yellow(line) }; } // Regular lyrics line return { text: line, formatted: line }; }); }; module.exports = { logger, formatLyrics };