UNPKG

@stoar/cli

Version:

CLI tool for STOAR - decentralized file storage on Arweave

78 lines 2.03 kB
import chalk from 'chalk'; import Table from 'cli-table3'; import ora from 'ora'; export function output(data, options = {}) { if (options.quiet) { // In quiet mode, only output essential data if (typeof data === 'string') { console.log(data); } else if (data.id || data.transactionId) { console.log(data.id || data.transactionId); } return; } if (options.json) { console.log(JSON.stringify(data, null, 2)); return; } // Default output console.log(data); } export function success(message, options = {}) { if (!options.quiet) { console.log(chalk.green('✓'), message); } } export function error(message, options = {}) { console.error(chalk.red('✗'), message); } export function info(message, options = {}) { if (!options.quiet) { console.log(chalk.blue('ℹ'), message); } } export function warn(message, options = {}) { if (!options.quiet) { console.log(chalk.yellow('⚠'), message); } } export function createTable(headers) { return new Table({ head: headers.map(h => chalk.bold(h)), style: { head: ['cyan'] } }); } export function createSpinner(text) { return ora({ text, spinner: 'dots' }); } export function formatBytes(bytes) { const units = ['B', 'KB', 'MB', 'GB', 'TB']; let size = bytes; let unitIndex = 0; while (size >= 1024 && unitIndex < units.length - 1) { size /= 1024; unitIndex++; } return `${size.toFixed(2)} ${units[unitIndex]}`; } export function formatDuration(ms) { const seconds = Math.floor(ms / 1000); const minutes = Math.floor(seconds / 60); const hours = Math.floor(minutes / 60); if (hours > 0) { return `${hours}h ${minutes % 60}m`; } else if (minutes > 0) { return `${minutes}m ${seconds % 60}s`; } else { return `${seconds}s`; } } //# sourceMappingURL=output.js.map