-
Notifications
You must be signed in to change notification settings - Fork 17
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
fix: words should drop apostrophes #123
fix: words should drop apostrophes #123
Conversation
export type WeirdTextUnion = typeof WEIRD_TEXT | 'dont.distribute unions' | ||
export type WeirdTextUnion = | ||
| typeof WEIRD_TEXT | ||
| "where's the leak ma'am" |
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.
@@ -6,6 +6,7 @@ import type { IsDigit } from './characters/numbers.js' | |||
import type { IsSpecial } from './characters/special.js' | |||
import type { IsStringLiteral } from '../internal/literals.js' | |||
|
|||
// prettier-ignore |
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.
Didn't want the type to turn into indentation hell, open to suggestions for a better solution
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.
Very good! Appreciate you jumping on it with a good strategy.
I would like to challenge this. Lodash approach is more complex than just "removing apostrophes before splitting words" because lodash behaviour will be different for So with the test sentence "Where's the leak ma'am?", we have:
I think I would be in favour of removing all special characters, but still count them as a word separator - i.e. go for: also - do we agree this is a breaking change that should wait for a v2? |
_.camelCase("Where's the leak ma'am")
// "wheresTheLeakMaam"
_.snakeCase("Where's the leak ma'am")
// "wheres_the_leak_maam" I guess they do the apostrophe removal at the casing level, before it is passed into words. We could move the removal of apostrophes to the casing function like they do here. This might be nice for a couple of reasons:
Can you think of scenarios where words should be separated based on an apostrophe?
Either way, |
Yes, I agree with @p9f that we should think carefully about (any) change in the words method. If we just "fixed" machine readable casing functions, would that be a major version? I'm also a little afraid of going down the "perfect grammar" route bc it can lead to a much more complex code. |
Based on this issue, it might be worth:
|
It does makes sense. I tend to adopt the same positioning of J Dalton there: limiting the scope to avoid creating a lil monster, but with that said if no one can come up with a con for that we can add that behavior. |
fwiw in french I think I don't see any downside in your latest solution right now, even though I think we should take our time to consider all the implications. It seems the best of both world. What do you think of, in the same release, changing the logic for special character so that they don't create artificial word? i.e. converting |
I'm not too sure what to do with the different special characters scenarios. Scenarios:
I've been thinking of a future solution, maybe something like:
I could put this in a github discussion |
|
: IsSeparator<T> extends true | ||
? false | ||
: true | ||
? false |
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.
We should probably disable prettier here too... but for other PR
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.
@gustavoguichard I'm okay either way. I think a majority of people would expect the updated behavior (eg: |
@jly36963 I'd do a major change ;) |
Words and Apostophes
Words
and related casing utilities have weird behavior for words containing'
.I updated the logic to be more like lodash's (removing apostrophes before splitting words)
Relates to, but is not a fix for: #122
Words
Casing