Spaces:
Paused
Paused
File size: 1,273 Bytes
ee826ee | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | /**
* ============================================
* 🔧 utils.js — Utilidades compartidas
* ============================================
*/
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
export function readConfig() {
const raw = fs.readFileSync(path.join(__dirname, '../config.json'), 'utf-8');
return JSON.parse(raw);
}
export function sleep(ms) {
return new Promise(r => setTimeout(r, ms));
}
export function formatDuration(ms) {
const s = Math.floor(ms / 1000);
const m = Math.floor(s / 60);
const h = Math.floor(m / 60);
if (h > 0) return `${h}h ${m % 60}m ${s % 60}s`;
if (m > 0) return `${m}m ${s % 60}s`;
return `${s}s`;
}
export function truncate(str, max = 200) {
if (!str) return '';
return str.length > max ? str.substring(0, max) + '...' : str;
}
export function generateId() {
return `${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
}
// Formatear timestamp legible
export function formatDate(isoString) {
if (!isoString) return 'desconocido';
return new Date(isoString).toLocaleDateString('es-ES', {
day: '2-digit', month: '2-digit', year: 'numeric',
hour: '2-digit', minute: '2-digit',
});
}
|