Skip to content

Commit 1b2eb30

Browse files
committed
fix(dfts-helper): read time use trim instead of strip whitespace
1 parent 4249b3e commit 1b2eb30

File tree

1 file changed

+4
-5
lines changed
  • libs/dfts-helper/src/lib/helper/string/read-time

1 file changed

+4
-5
lines changed

libs/dfts-helper/src/lib/helper/string/read-time/read-time.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { s_stripWhitespace } from '../strip-whitespace';
21
import { n_humanizeTime } from '../../number/humanize-time';
32
import { s_countWords } from '../count-words/count-words';
43

@@ -11,16 +10,16 @@ const IMAGE_READ_TIME = 12; // in seconds
1110
* @param {number} [imageCounter=0] - The number of images in the text.
1211
* @returns {string} - The estimated time it takes to read the text, in the format "Xm" where X is the number of minutes.
1312
*/
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()));
1615

1716
/**
1817
* Calculates the estimated time it takes to read text based on the number of words and a given words per minute rate.
1918
* @param {string} text - The text to be read.
2019
* @param {number} [wordsPerMin=WORDS_PER_MIN] - The words per minute rate to use for calculating read time.
2120
* @returns {number} - The estimated time it takes to read the text in minutes.
2221
*/
23-
export const calculateWordsReadTime = (text: string, wordsPerMin = WORDS_PER_MIN): number =>
22+
export const calculateWordsReadTime = (text: string, wordsPerMin: number = WORDS_PER_MIN): number =>
2423
s_countWords(removeOtherLanguageCharacters(text)) / wordsPerMin;
2524

2625
/**
@@ -37,5 +36,5 @@ export const removeOtherLanguageCharacters = (text: string): string =>
3736
* @param {number} [customImageTime=IMAGE_READ_TIME] - The time per image to use for calculating read time.
3837
* @returns {number} - The estimated time it takes to read the images in minutes.
3938
*/
40-
export const imageReadTime = (count: number, customImageTime = IMAGE_READ_TIME): number =>
39+
export const imageReadTime = (count: number, customImageTime: number = IMAGE_READ_TIME): number =>
4140
count > 10 ? ((count / 2) * (customImageTime + 3) + (count - 10) * 3) / 60 : ((count / 2) * (2 * customImageTime + (1 - count))) / 60;

0 commit comments

Comments
 (0)