fix(Text Statistics): word counts for only spaces

Fix #1687
This commit is contained in:
ShareVB committed 2025-12-07 22:34:21 +01:00
1 parent ac08813407
commit e6cbe0884d
1 file changed
+2 -2
@@ -3,7 +3,7 @@ export function getStringSizeInBytes(text: string) {
}
export function textStatistics(text: string) {
const words_no_puncts = text.replace(/\p{P}/ug, '').trim().split(/\s+/);
const words_no_puncts = text.replace(/\p{P}/ug, '').trim().split(/\s+/).filter(Boolean);
const read_word_per_minutes = 200;
return {
chars: text.length,
@@ -13,7 +13,7 @@ export function textStatistics(text: string) {
chars_digits: text.replace(/\D+/ug, '').length,
chars_puncts: text.replace(/[^\p{P}]/ug, '').length,
chars_spaces: text.replace(/\S/ug, '').length,
words: text.trim().split(/\s+/).length,
words: text.trim().split(/\s+/).filter(Boolean).length,
read_time: words_no_puncts.length / read_word_per_minutes * 60,
words_no_puncs: words_no_puncts.length,
words_uniques: (new Set(words_no_puncts)).size,