Skip to content

Commit

Permalink
Prevent Duplication of Trailing Punctuation in Hyphenated Words Proce…
Browse files Browse the repository at this point in the history
…ssing
  • Loading branch information
danielhaim1 committed Dec 11, 2023
1 parent 721ea18 commit 4bd4e18
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 9 additions & 0 deletions __tests__/TitleCaser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ const createTest = (description, input, expected) => {
});
};


describe(`
Testing Combined Words that End with Symbol`, () => {
createTest('Capitalizes country code "US" correctly in a geopolitical context',
'Championing Self-Acceptance: Landmark Initiative',
'Championing Self-Acceptance: Landmark Initiative');
});


describe(`
Testing Acronym/Pronoun of Alpha2/3 Country Codes`, () => {
createTest('Capitalizes country code "US" correctly in a geopolitical context',
Expand Down
6 changes: 2 additions & 4 deletions src/TitleCaser.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,8 @@ export class TitleCaser {
const isReplaced = !replacedParts.every((part, index) => part === parts[index]);

// Reassemble the word with the hyphen, reattach trailing punctuation, and return
return (
(isReplaced ? replacedParts.join("-") : TitleCaserUtils.correctTermHyphenated(word, style)) +
trailingPunctuation
);
const processedWord = isReplaced ? replacedParts.join("-") : TitleCaserUtils.correctTermHyphenated(word, style);
return processedWord.endsWith(trailingPunctuation) ? processedWord : processedWord + trailingPunctuation;
case TitleCaserUtils.hasSuffix(word, style):
// If the word has a suffix, return the correct casing.
return TitleCaserUtils.correctSuffix(word, correctTitleCasingList);
Expand Down

0 comments on commit 4bd4e18

Please sign in to comment.