From 9d3201841ccc3eb52f8d2cb2dae0ae328ded273e Mon Sep 17 00:00:00 2001 From: Federico Grandi Date: Tue, 13 Feb 2024 01:46:23 +0100 Subject: [PATCH] fix: fix tags formatting (#113) --- src/components/Util/Question.tsx | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/components/Util/Question.tsx b/src/components/Util/Question.tsx index 82d1a7b..0670353 100644 --- a/src/components/Util/Question.tsx +++ b/src/components/Util/Question.tsx @@ -103,14 +103,12 @@ export default function Question({ ) } +/** + * Creates a ready-to-print list of tags, including semicolons as delimiters and a final period. + * @param tagsArr The raw array of tags + * @example contatTags(['foo baR', 'baz']) // 'Foo BaR; baz.' + */ function concatTags(tagsArr: string[]): string { - return tagsArr - .map((tag, i) => { - const isFirstTag = i === 0 - const isLastTag = i === tagsArr.length - 1 - if (isFirstTag) return `${tag[0].toUpperCase()}${tag.slice(1)}; ` - if (isLastTag) return `${tag}.` - return `${tag}; ` - }) - .join('') + const res = tagsArr.join('; ').trim() + return res ? `${res[0].toUpperCase()}${res.slice(1)}.` : '' }