export const formatNumber = (val: number) => { return new Intl.NumberFormat("vi-VN").format(val); }; export const formatCarriers = (text) => { if (!text) return ""; return text.replace(/,\s*/g, ", "); }; export const setWithExpiry = ( key: string, value: string, ttlMs?: number | null ) => { const now = Date.now(); const item = { value, expiry: ttlMs ? now + ttlMs : now + 10 * 60 * 1000, // Default 10 minutes }; localStorage.setItem(key, JSON.stringify(item)); }; export const getWithExpiry = (key: string): T | null => { const itemStr = localStorage.getItem(key); if (!itemStr) return null; try { const item = JSON.parse(itemStr); if (!item.expiry || Date.now() > item.expiry) { localStorage.removeItem(key); return null; } return item.value as T; } catch { localStorage.removeItem(key); return null; } };