Initial commit

This commit is contained in:
decolua
2026-01-05 09:58:59 +07:00
commit 3857598de4
159 changed files with 14537 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
// Shared Utils - Export all
export { cn } from "./cn";
export * as api from "./api";
/**
* Extract error code from error message (401, 429, 503...)
* @param {string} lastError - Error message
* @returns {string|null} Error code or null
*/
export function getErrorCode(lastError) {
if (!lastError) return null;
const match = lastError.match(/\b([45]\d{2})\b/);
return match ? match[1] : "ERR";
}
/**
* Get relative time string (e.g. "5 min ago")
* @param {string} isoDate - ISO date string
* @returns {string} Relative time
*/
export function getRelativeTime(isoDate) {
if (!isoDate) return "";
const diff = Date.now() - new Date(isoDate).getTime();
const mins = Math.floor(diff / 60000);
if (mins < 1) return "just now";
if (mins < 60) return `${mins}m ago`;
const hours = Math.floor(mins / 60);
if (hours < 24) return `${hours}h ago`;
const days = Math.floor(hours / 24);
return `${days}d ago`;
}