-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
getInitials: handle more cases to reduce cross-platform inconsistencies #5029
Conversation
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.
Thanks for doing this!
I've made a couple of comments. When in doubt, making this match Android's codebase is ideal.
Thanks for making the updates. I might not get to it this week, but I'll take another look at your changes. |
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.
A few more comments. Thanks for doing this!
[ | ||
['山田 太郎', '山太'], | ||
['王五', '王五'], | ||
['Иван Иванов', 'ИИ'], | ||
].forEach(([name, initials]) => { | ||
it('returns initials for languages with non-Latin alphabets', () => { | ||
assert.strictEqual(getInitials(name), initials); | ||
}); | ||
}); |
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.
This forEach
(and the one below) causes multiple it
blocks with the same title. I think it might be clearer to do everything inline:
it('returns initials for languages with non-Latin alphabets', () => {
assert.strictEqual(getInitials('山田 太郎'), '山太');
// ...
});
Same comment applies to the RTL test below.
}); | ||
|
||
it('returns the first letter of a name that is one ASCII word', () => { | ||
assert.strictEqual(getInitials('Foo'), 'F'); |
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.
Could you add a test for a two-letter name (like "Bo")? (I think that should be "B", not "BO".)
|
||
[ | ||
['山田 太郎', '山太'], | ||
['王五', '王五'], |
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.
Is this correct? Are "王五" initials? Or should it be "王"?
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.
I think it's correct. Those two signs are both uppercase letters.
@EvanHahn-Signal I'm sorry it's taken so long. I completely missed the notifications for these newer comments. I'll work on them this week. |
No worries at all. Take your time! |
I just saw that you pushed some more commits. Let me know if I should take another look. |
Yes, please do. I made some changes to the test file based on your comments. |
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.
Looks good! We'll plan to merge this soon.
First time contributor checklist:
Contributor checklist:
development
branchyarn ready
run passes successfully (more about tests here)Description
#4172
I made changes to the
getInitials
method to handle more cases. The first letter of the first and the last word in a passed string will form the initials. Any non-letters, suffixes such as "Jr", "Sr" or Roman numerals will be omitted.I added tests and tried to cover multiple edge cases.
OS X 10.15.6.