Files
testingcodeantrepo/.gitea/workflows/src/utils/getReadingTime.ts
2026-03-30 02:48:26 +05:30

16 lines
414 B
TypeScript

export const getReadingTime = (text: string): string => {
if (!text) return "0 min read";
// Remove HTML tags if present
const cleanText = text.replace(/<[^>]+>/g, "");
if (!cleanText.trim()) return "0 min read";
// Count words
const words = cleanText.trim().split(/\s+/).length;
const wordsPerMinute = 200;
const minutes = Math.ceil(words / wordsPerMinute);
return `${minutes} min read`;
};