UNPKG

todofordevs

Version:

CLI for TodoForDevs - A simple task management tool for developers

109 lines (108 loc) 2.77 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.success = success; exports.error = error; exports.warning = warning; exports.info = info; exports.heading = heading; exports.createTable = createTable; exports.formatDate = formatDate; exports.truncate = truncate; exports.formatKeyValue = formatKeyValue; exports.divider = divider; const chalk_1 = __importDefault(require("chalk")); const cli_table3_1 = __importDefault(require("cli-table3")); /** * Print a success message */ function success(message) { console.log(chalk_1.default.green('✓ ') + message); } /** * Print an error message */ function error(message) { console.error(chalk_1.default.red('✗ ') + message); } /** * Print a warning message */ function warning(message) { console.warn(chalk_1.default.yellow('⚠ ') + message); } /** * Print an info message */ function info(message) { console.info(chalk_1.default.blue('ℹ ') + message); } /** * Print a heading */ function heading(message) { console.log('\n' + chalk_1.default.bold(message)); } /** * Create a table with the specified headers */ function createTable(headers) { return new cli_table3_1.default({ head: headers.map((header) => chalk_1.default.bold(header)), chars: { top: '─', 'top-mid': '┬', 'top-left': '┌', 'top-right': '┐', bottom: '─', 'bottom-mid': '┴', 'bottom-left': '└', 'bottom-right': '┘', left: '│', 'left-mid': '├', mid: '─', 'mid-mid': '┼', right: '│', 'right-mid': '┤', middle: '│', }, }); } /** * Format a date string for display */ function formatDate(dateString) { if (!dateString) return ''; try { const date = new Date(dateString); return date.toLocaleDateString(); } catch (e) { return dateString; } } /** * Truncate a string if it's too long */ function truncate(str, maxLength = 30) { if (str.length <= maxLength) return str; return str.substring(0, maxLength - 3) + '...'; } /** * Format a key-value pair for display */ function formatKeyValue(key, value) { const keyStr = chalk_1.default.bold(`${key}:`); const valueStr = value === undefined || value === null ? '' : value.toString(); console.log(`${keyStr.padEnd(20)} ${valueStr}`); } /** * Print a divider line */ function divider() { console.log(chalk_1.default.gray('─'.repeat(process.stdout.columns || 80))); }