From e5ad71505c310bd55919ec37bb11b7030e46a82c Mon Sep 17 00:00:00 2001 From: Jose Olarte III Date: Mon, 18 Aug 2025 17:47:33 +0800 Subject: [PATCH] Chore: move function to serverUtil - capitalizeAndInsertSpacesBeforeCapsWithAPrefix() defined in two places, unified and moved to endorserServer.ts - Use capitalizeAndInsertSpacesBeforeCaps() that's already defined in endorserServer.ts --- src/libs/endorserServer.ts | 22 ++++++++++++++++++++++ src/views/ClaimView.vue | 34 ++++------------------------------ src/views/ConfirmGiftView.vue | 29 +---------------------------- 3 files changed, 27 insertions(+), 58 deletions(-) diff --git a/src/libs/endorserServer.ts b/src/libs/endorserServer.ts index 735252f7..cdc516b1 100644 --- a/src/libs/endorserServer.ts +++ b/src/libs/endorserServer.ts @@ -1140,6 +1140,28 @@ export const capitalizeAndInsertSpacesBeforeCaps = (text: string) => { : text[0].toUpperCase() + text.substr(1).replace(/([A-Z])/g, " $1"); }; +/** + * Formats type string for display by adding spaces before capitals + * and optionally adds an appropriate article prefix (a/an) + * + * @param text - Text to format + * @returns Formatted string with article prefix + */ +export const capitalizeAndInsertSpacesBeforeCapsWithAPrefix = ( + text: string, +): string => { + const word = capitalizeAndInsertSpacesBeforeCaps(text); + if (word) { + // if the word starts with a vowel, use "an" instead of "a" + const firstLetter = word[0].toLowerCase(); + const vowels = ["a", "e", "i", "o", "u"]; + const particle = vowels.includes(firstLetter) ? "an" : "a"; + return particle + " " + word; + } else { + return ""; + } +}; + /** return readable summary of claim, or something generic diff --git a/src/views/ClaimView.vue b/src/views/ClaimView.vue index 55ca6744..3653861d 100644 --- a/src/views/ClaimView.vue +++ b/src/views/ClaimView.vue @@ -24,7 +24,9 @@

{{ - capitalizeAndInsertSpacesBeforeCaps(veriClaim.claimType || "") + serverUtil.capitalizeAndInsertSpacesBeforeCaps( + veriClaim.claimType || "", + ) }}