UNPKG

@taizo-pro/github-discussions-cli

Version:

A powerful command-line tool for interacting with GitHub Discussions without opening a browser

39 lines 1.18 kB
export function formatDate(date) { const now = new Date(); const diffInMs = now.getTime() - date.getTime(); const diffInMinutes = Math.floor(diffInMs / (1000 * 60)); const diffInHours = Math.floor(diffInMinutes / 60); const diffInDays = Math.floor(diffInHours / 24); if (diffInMinutes < 1) { return 'just now'; } else if (diffInMinutes < 60) { return `${diffInMinutes}m ago`; } else if (diffInHours < 24) { return `${diffInHours}h ago`; } else if (diffInDays < 7) { return `${diffInDays}d ago`; } else { return date.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: date.getFullYear() !== now.getFullYear() ? 'numeric' : undefined, }); } } export function truncateText(text, maxLength) { if (text.length <= maxLength) { return text; } return text.substring(0, maxLength - 3) + '...'; } export function pluralize(count, singular, plural) { if (count === 1) { return `${count} ${singular}`; } return `${count} ${plural || singular + 's'}`; } //# sourceMappingURL=formatters.js.map