-
-
Notifications
You must be signed in to change notification settings - Fork 176
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
Updated the restoreCase logic to check for upper and lower case pluralization #136
Updated the restoreCase logic to check for upper and lower case pluralization #136
Conversation
…s well added new testcases for checking them
pluralize.js
Outdated
@@ -49,6 +49,11 @@ | |||
// Tokens are an exact match. | |||
if (word === token) return token; | |||
|
|||
// Starts with the same letters | |||
if (token.toLowerCase().startsWith(word.toLowerCase())) { |
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 is a breaking change for supported environments of pluralize
. We should change startsWith
to something else. Can you also remove the token logic below? This probably overlaps in implementation.
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.
Updated the code with:
if ((token.toLowerCase().substring(0, word.length)) === word.toLowerCase()) {
return word + token.substring(word.length);
}
These parts only check for special cases where we have weird combinations when calling the "pluralize" method and if this check fails then it goes to the base case. Such as "sTaRTREK" and wanting the result to be "sTaRTREKS".
.gitignore
Outdated
@@ -3,3 +3,5 @@ node_modules | |||
components | |||
build | |||
coverage | |||
yarn.lock |
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.
Please don't change this.
…om using 'startsWith' to 'substring'
Hey Blake, I'd undid the changes to the ".gitignore" file and updated the "pluralize" file. As for my logic:
This parts only check for special cases where we have weird combination when calling "pluralize" method and if this checks fails then it goes to the base case. Such as "sTaRTREK" and wanting the result to be "sTaRTREKS". |
I’d like to see more tests and unnecessary changes reverted before I can merge it. Based on this PR, I’m pretty sure it’ll break anyone using upper cased words. At that point, it’s probably better to just always use lowercase and not have this logic at all. |
Actually, am I understanding this correctly that it'll only word if the entire token is matched? In that case, I think it'd be better that we find a more appropriate solution. It also doesn't solve #131 unless you intend to add manual overrides to every word, which seems redundant. |
If this is a real issue for people, I propose just removing the feature altogether and making the consumers of the library handle the casing they want. It'd make it slightly faster, make those overrides "expected", and making it to upper case is easier than doing all the other magic. |
Here's a test case to consider that fails with this change, if you're planning to add more tests:
|
I'd updated the logic for the restoreCase as it has missed some testcases as well and it shall pass for the new ones. And this is the solution for https://github.com/blakeembrey/pluralize/issues/131