helpers.js 750 B

12345678910111213141516171819202122232425262728
  1. // Utilidades compartidas para formateo y helpers de UI
  2. export function getComputedTailwindColor(className) {
  3. const colorMap = {
  4. "text-blue-500": "#3B82F6",
  5. "text-green-500": "#22C55E",
  6. "text-yellow-500": "#EAB308",
  7. "text-red-500": "#EF4444",
  8. "text-orange-400": "#FB923C",
  9. "text-gray-500": "#6B7280",
  10. };
  11. return colorMap[className] || "#6B7280";
  12. }
  13. export function truncate(str, n) {
  14. return str.length > n ? str.slice(0, n - 1) + "..." : str;
  15. }
  16. export function formatBytes(bytes) {
  17. const units = ["B", "KB", "MB", "GB"];
  18. let value = bytes;
  19. let unitIndex = 0;
  20. while (value >= 1024 && unitIndex < units.length - 1) {
  21. value /= 1024;
  22. unitIndex++;
  23. }
  24. return `${value.toFixed(2)} ${units[unitIndex]}`;
  25. }