UNPKG

@lanonasis/cli

Version:

Professional CLI for LanOnasis Memory as a Service (MaaS) with MCP support, seamless inline editing, and enterprise-grade security

53 lines (52 loc) 1.6 kB
export function formatOutput(data, format = 'table') { switch (format) { case 'json': console.log(JSON.stringify(data, null, 2)); break; case 'yaml': // Would need to import yaml library console.log('YAML output not implemented yet'); break; default: // Table format is handled by calling code break; } } export function formatBytes(bytes) { if (bytes === 0) return '0 Bytes'; const k = 1024; const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']; const i = Math.floor(Math.log(bytes) / Math.log(k)); return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]; } export function truncateText(text, maxLength) { const normalized = typeof text === 'string' ? text : text == null ? '' : String(text); if (normalized.length <= maxLength) return normalized; return normalized.substring(0, maxLength - 3) + '...'; } export function formatDuration(ms) { if (ms < 1000) return `${ms}ms`; if (ms < 60000) return `${(ms / 1000).toFixed(1)}s`; return `${(ms / 60000).toFixed(1)}m`; } export function formatDate(date) { const d = new Date(date); return d.toLocaleString(); } export function formatTableData(data) { return data.map(item => { if (Array.isArray(item)) return item.map(String); if (typeof item === 'object' && item !== null) return Object.values(item).map(String); return [String(item)]; }); }