16 lines
414 B
TypeScript
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`;
|
|
};
|