-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: [PE-737] CGN capitalize text apostrophe case #6293
chore: [PE-737] CGN capitalize text apostrophe case #6293
Conversation
test suite to ensure that capitalize function correctly handles words with apostrophes
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6293 +/- ##
==========================================
- Coverage 48.42% 46.98% -1.45%
==========================================
Files 1488 1802 +314
Lines 31617 36527 +4910
Branches 7669 8759 +1090
==========================================
+ Hits 15311 17161 +1850
- Misses 16238 19301 +3063
+ Partials 68 65 -3
... and 1414 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job on this PR! I've left a couple of minor suggestions
would you consider a simpler algorithm like function capitalizePersonName(text: string) {
// find all indices of characters that are preceded by a space or apostrophe
const indices = Array.from(text.matchAll(/(?<=\s|')\w/g)).map(match => match.index);
// uppercase each character at the found indices, lowercase others
return text.split('').map((char, index) => indices.includes(index) || index === 0 ? char.toLocaleUpperCase() : char.toLocaleLowerCase()).join('');
}
console.log(capitalizePersonName("frederik"))
console.log(capitalizePersonName("FREDERIK"))
console.log(capitalizePersonName("frederik van der linde"))
console.log(capitalizePersonName("FREDERIK van der LINDE"))
console.log(capitalizePersonName("o'connor"))
console.log(capitalizePersonName("O'CONNOR")) |
Thank you for your feedback! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🚀
From what I understood from other conversations, the user name and surname are provided by external systems and we are meant to disregard any capitalization coming from there and apply ours.
I do not remember the collegue who said this tough, and that if he actually meant this, should we verify? (@Hantex9 can you think about someone who could said this?) |
I'm not entirely sure about this, as not all surnames have a capital letter following an apostrophe. Maybe @michaeldisaro could provide us with more details on this. |
How these examples should be capitalized? D'AMICO |
|
For us, the important part is ensuring that the initials are uppercase. Beyond that, the capitalization that follows can't be something we can reliably predict. On our end, how can we be certain that if we're provided with D'AMICO, it should be capitalized as D'Amico and not D'amico? @thisisjp what are your thoughts from a product & design perspective? |
So, do you think we should first convert the entire string to lowercase and then capitalize the first character, as well as the first character after an apostrophe? |
The function now capitalize only the initials (as before), including the letter after the apostrophe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Short description
This PR updates the
capitalize
function to correctly handle words with apostrophes, ensuring that words like Dall'Ara remain Dall'Ara and not Dall'ara.List of changes proposed in this pull request
capitalize
function to correctly handle words with apostrophes.How to test
Or
##Preview