Skip to content

Commit 3b22d62

Browse files
authored
[MC-1682] fix: capitalization after curly apostrophe (#1233)
* [MC-1682] fix: capitalization after curly apostrophe * fix lint errors
1 parent 1d4a195 commit 3b22d62

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

src/_shared/utils/applyApTitleCase.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,17 @@ describe('applyApTitleCase', () => {
137137
expect(applyApTitleCase(swc.result)).toEqual(swc.expected);
138138
});
139139
});
140+
it('should correctly format titles with curly apostrophes', () => {
141+
const testCases = [
142+
{
143+
result: 'every state\u2018S dream travel destination, mapped',
144+
expected: 'Every State\u2018s Dream Travel Destination, Mapped',
145+
},
146+
];
147+
testCases.forEach(({ result, expected }) => {
148+
expect(applyApTitleCase(result)).toEqual(expected);
149+
});
150+
});
140151
});
141152

142153
describe('lowercaseAfterApostrophe', () => {
@@ -150,4 +161,9 @@ describe('lowercaseAfterApostrophe', () => {
150161
);
151162
expect(result).toEqual("'Foo' foo's DaY's You'll 'foo Bar foo'ss'");
152163
});
164+
it('should lowercase the letter after a curly apostrophe', () => {
165+
const input = 'Every State\u2018S Dream Travel Destination, Mapped';
166+
const expected = 'Every State\u2018s Dream Travel Destination, Mapped';
167+
expect(lowercaseAfterApostrophe(input)).toEqual(expected);
168+
});
153169
});

src/_shared/utils/applyApTitleCase.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ export const stop = STOP_WORDS.split(' ');
1515
* @returns {string}
1616
*/
1717
export const lowercaseAfterApostrophe = (input: string): string => {
18-
// matches an apostrophe followed by a char
19-
// ensures only the first char after the apostrophe is converted to lowercase
20-
const regex = /(?<=\w)(')(\w)/g;
21-
22-
return input.replace(regex, (match, p1, char) => {
23-
return `'${char.toLowerCase()}`; // Lowercase the first char after the apostrophe
24-
});
18+
// Match either an ASCII or curly apostrophe followed by a letter, after a word character.
19+
const regex = /(?<=\w)(['\u2018\u2019])(\w)/g;
20+
return input.replace(
21+
regex,
22+
(_, apostrophe, letter) => `${apostrophe}${letter.toLowerCase()}`,
23+
);
2524
};
2625

2726
/**

src/curated-corpus/components/ProspectFilters/ProspectFilters.test.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
Prospect,
99
Topics,
1010
} from '../../../api/generatedTypes';
11-
import { StoriesSummary } from '../ScheduleSummaryCard/ScheduleSummaryCard';
1211
import { DateTime } from 'luxon';
1312

1413
describe('The ProspectFilters component', () => {

0 commit comments

Comments
 (0)