Skip to content

Commit

Permalink
📝 (string.ts): add a new utility function ensurePeriod to ensure th…
Browse files Browse the repository at this point in the history
…at a sentence ends with a period

🐛 (
  • Loading branch information
romantech committed Aug 23, 2024
1 parent a7f959a commit cfe9459
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/base/utils/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}.`;
};
3 changes: 2 additions & 1 deletion src/features/syntax-analyzer/hooks/use-analysis-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useForm } from 'react-hook-form';
import { useNavigate } from 'react-router-dom';

import {
ensurePeriod,
expandAbbreviations,
removeThousandSeparator,
tokenizer,
Expand Down Expand Up @@ -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);
};

Expand Down

0 comments on commit cfe9459

Please sign in to comment.