UNPKG

mcp-hacker-news

Version:
32 lines 1.14 kB
// ***************************************************** // *********** Hacker News MCP Helpers *********** // ***************************************************** const cache = new Map(); const CACHE_DURATION = 2 * 60 * 1000; // 2 minutes // Function to get cached data export function getCached(key) { const cached = cache.get(key); if (cached && Date.now() - cached.timestamp < CACHE_DURATION) { return cached.data; } return null; } // Function to set cached data export function setCache(key, data) { cache.set(key, { data, timestamp: Date.now() }); } // Function to format timestamp to a readable format export function formatTime(timestamp) { const date = new Date(timestamp * 1000); const now = new Date(); const diff = now.getTime() - date.getTime(); const minutes = Math.floor(diff / (1000 * 60)); const hours = Math.floor(diff / (1000 * 60 * 60)); const days = Math.floor(diff / (1000 * 60 * 60 * 24)); if (minutes < 60) return `${minutes}m ago`; if (hours < 24) return `${hours}h ago`; return `${days}d ago`; } //# sourceMappingURL=helpers.js.map