| |
| |
| |
| export const formatDate = (dateString) => { |
| const date = new Date(dateString) |
| return date.toLocaleDateString('en-US', { |
| year: 'numeric', |
| month: 'long', |
| day: 'numeric' |
| }) |
| } |
|
|
| |
| |
| |
| export const formatRelativeTime = (dateString) => { |
| const date = new Date(dateString) |
| const now = new Date() |
| const diffTime = Math.abs(now - date) |
| const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)) |
|
|
| if (diffDays === 0) return 'Today' |
| if (diffDays === 1) return 'Yesterday' |
| if (diffDays < 7) return `${diffDays} days ago` |
| if (diffDays < 30) return `${Math.floor(diffDays / 7)} weeks ago` |
| return `${Math.floor(diffDays / 30)} months ago` |
| } |
|
|
| |
| |
| |
| export const calculatePercentage = (value, total) => { |
| if (total === 0) return 0 |
| return Math.round((value / total) * 100) |
| } |
|
|
| |
| |
| |
| export const getDifficultyColor = (difficulty) => { |
| const colors = { |
| beginner: 'bg-green-100 text-green-700 border-green-200', |
| intermediate: 'bg-yellow-100 text-yellow-700 border-yellow-200', |
| advanced: 'bg-red-100 text-red-700 border-red-200' |
| } |
| return colors[difficulty] || colors.beginner |
| } |
|
|
| |
| |
| |
| export const getGrade = (percentage) => { |
| if (percentage >= 90) return { letter: 'A+', color: 'green', message: 'Outstanding!' } |
| if (percentage >= 80) return { letter: 'A', color: 'green', message: 'Excellent!' } |
| if (percentage >= 70) return { letter: 'B', color: 'blue', message: 'Good Job!' } |
| if (percentage >= 60) return { letter: 'C', color: 'yellow', message: 'Keep Practicing!' } |
| return { letter: 'F', color: 'red', message: 'Try Again!' } |
| } |
|
|
| |
| |
| |
| export const truncateText = (text, maxLength = 100) => { |
| if (text.length <= maxLength) return text |
| return text.substring(0, maxLength) + '...' |
| } |
|
|
| |
| |
| |
| export const debounce = (func, wait) => { |
| let timeout |
| return function executedFunction(...args) { |
| const later = () => { |
| clearTimeout(timeout) |
| func(...args) |
| } |
| clearTimeout(timeout) |
| timeout = setTimeout(later, wait) |
| } |
| } |
|
|
| |
| |
| |
| export const validateEmail = (email) => { |
| const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/ |
| return re.test(email) |
| } |
|
|
| |
| |
| |
| export const getKnowledgeLevelColor = (level) => { |
| if (level >= 0.8) return 'from-green-500 to-emerald-500' |
| if (level >= 0.6) return 'from-blue-500 to-cyan-500' |
| if (level >= 0.4) return 'from-yellow-500 to-orange-500' |
| return 'from-red-500 to-pink-500' |
| } |