1
- import { s_stripWhitespace } from '../strip-whitespace' ;
2
1
import { n_humanizeTime } from '../../number/humanize-time' ;
3
2
import { s_countWords } from '../count-words/count-words' ;
4
3
@@ -11,16 +10,16 @@ const IMAGE_READ_TIME = 12; // in seconds
11
10
* @param {number } [imageCounter=0] - The number of images in the text.
12
11
* @returns {string } - The estimated time it takes to read the text, in the format "Xm" where X is the number of minutes.
13
12
*/
14
- export const s_readTime = ( text : string , imageCounter = 0 ) : string =>
15
- n_humanizeTime ( imageReadTime ( imageCounter ) + calculateWordsReadTime ( s_stripWhitespace ( text ) ) ) ;
13
+ export const s_readTime = ( text : string , imageCounter : number = 0 ) : string =>
14
+ n_humanizeTime ( imageReadTime ( imageCounter ) + calculateWordsReadTime ( text . trim ( ) ) ) ;
16
15
17
16
/**
18
17
* Calculates the estimated time it takes to read text based on the number of words and a given words per minute rate.
19
18
* @param {string } text - The text to be read.
20
19
* @param {number } [wordsPerMin=WORDS_PER_MIN] - The words per minute rate to use for calculating read time.
21
20
* @returns {number } - The estimated time it takes to read the text in minutes.
22
21
*/
23
- export const calculateWordsReadTime = ( text : string , wordsPerMin = WORDS_PER_MIN ) : number =>
22
+ export const calculateWordsReadTime = ( text : string , wordsPerMin : number = WORDS_PER_MIN ) : number =>
24
23
s_countWords ( removeOtherLanguageCharacters ( text ) ) / wordsPerMin ;
25
24
26
25
/**
@@ -37,5 +36,5 @@ export const removeOtherLanguageCharacters = (text: string): string =>
37
36
* @param {number } [customImageTime=IMAGE_READ_TIME] - The time per image to use for calculating read time.
38
37
* @returns {number } - The estimated time it takes to read the images in minutes.
39
38
*/
40
- export const imageReadTime = ( count : number , customImageTime = IMAGE_READ_TIME ) : number =>
39
+ export const imageReadTime = ( count : number , customImageTime : number = IMAGE_READ_TIME ) : number =>
41
40
count > 10 ? ( ( count / 2 ) * ( customImageTime + 3 ) + ( count - 10 ) * 3 ) / 60 : ( ( count / 2 ) * ( 2 * customImageTime + ( 1 - count ) ) ) / 60 ;
0 commit comments