From cfe9459cdf5fd9cb1f1cea9fb9b0fa538a729a9c Mon Sep 17 00:00:00 2001 From: ColorFilter Date: Fri, 23 Aug 2024 13:37:16 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20(string.ts):=20add=20a=20new=20u?= =?UTF-8?q?tility=20function=20`ensurePeriod`=20to=20ensure=20that=20a=20s?= =?UTF-8?q?entence=20ends=20with=20a=20period=20=F0=9F=90=9B=20(?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/base/utils/string.ts | 10 ++++++++++ .../syntax-analyzer/hooks/use-analysis-form.ts | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/base/utils/string.ts b/src/base/utils/string.ts index b26f46e..d254394 100644 --- a/src/base/utils/string.ts +++ b/src/base/utils/string.ts @@ -75,3 +75,13 @@ export const removeThousandSeparator = (sentence: string): string => { match.replace(/,/g, ''), ); }; + +/** + * Ensures that a sentence ends with a period. + * + * @param {string} sentence - The sentence to check. + * @return {string} The sentence with a period at the end. + */ +export const ensurePeriod = (sentence: string): string => { + return sentence.endsWith('.') ? sentence : `${sentence}.`; +}; diff --git a/src/features/syntax-analyzer/hooks/use-analysis-form.ts b/src/features/syntax-analyzer/hooks/use-analysis-form.ts index 00d85f6..f38b267 100644 --- a/src/features/syntax-analyzer/hooks/use-analysis-form.ts +++ b/src/features/syntax-analyzer/hooks/use-analysis-form.ts @@ -4,6 +4,7 @@ import { useForm } from 'react-hook-form'; import { useNavigate } from 'react-router-dom'; import { + ensurePeriod, expandAbbreviations, removeThousandSeparator, tokenizer, @@ -34,7 +35,7 @@ const toastOptions: UseToastOptions = { * @return {string} The processed sentence. */ export const processSentence = (sentence: string): string => { - const expanded = expandAbbreviations(sentence); + const expanded = expandAbbreviations(ensurePeriod(sentence)); return removeThousandSeparator(expanded); };