From e6cbe0884da8230ccfece5a607e5f9f1050a89dd Mon Sep 17 00:00:00 2001 From: ShareVB Date: Sun, 7 Dec 2025 21:53:59 +0100 Subject: [PATCH] fix(Text Statistics): word counts for only spaces Fix #1687 --- src/tools/text-statistics/text-statistics.service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tools/text-statistics/text-statistics.service.ts b/src/tools/text-statistics/text-statistics.service.ts index c53a2be9..1ed3025e 100644 --- a/src/tools/text-statistics/text-statistics.service.ts +++ b/src/tools/text-statistics/text-statistics.service.ts @@ -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,