Skip to content

Commit fc4dc68

Browse files
Added the local readTime function to calculate the reading time
1 parent 26bac28 commit fc4dc68

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/lib/utils/reading-time.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export const readingTime = (text: string): { time: string; words: number } => {
2+
const wordsPerMinute = 200;
3+
const words = text.split(/\s+/g).length;
4+
const minutes = Math.ceil(words / wordsPerMinute);
5+
return {
6+
time: `${minutes} min read`,
7+
words,
8+
};
9+
};

0 commit comments

Comments
 (0)