Skip to content
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

toTitleCase is removing full stops . #35

Closed
dan-scrumsdotcom opened this issue Oct 5, 2023 · 7 comments · Fixed by #40
Closed

toTitleCase is removing full stops . #35

dan-scrumsdotcom opened this issue Oct 5, 2023 · 7 comments · Fixed by #40
Labels
bug Something isn't working documentation Improvements or additions to documentation good first issue Good for newcomers

Comments

@dan-scrumsdotcom
Copy link

console.log(toTitleCase('hello there old friend...'))

Screenshot 2023-10-05 at 10 39 15

Maybe intentional? Not sure :)

@dan-scrumsdotcom
Copy link
Author

Same log with console.log(toTitleCase('hello. there. old. friend...'))

@gustavoguichard
Copy link
Owner

gustavoguichard commented Oct 5, 2023

Hi @danharten-sovtech , thanks for reporting.

This is actually how lodash works as well:
Screenshot 2023-10-05 at 07 33 30

The goal of this library is not to be equivalent to lodash but in this case it is.
The casing functions all have the same foundation which is the words function that detects words and joins them with a different casing. If you think about toTitleCase as being from the same family as toCamelCase it becomes clearer:

toCamelCase('hello there old friend...')
// expected to be:
'helloThereOldFriend'

// this would be weird
'helloThereOldFriend...'

But as I think about it I realized we should probably have a different naming convention for toLowerCase and toUpperCase that have a different foundation therefore will keep the dots.

@jly36963 , @p9f , what do you guys think about it?

@gustavoguichard gustavoguichard added the invalid This doesn't seem right label Oct 5, 2023
@jly36963
Copy link
Contributor

jly36963 commented Oct 5, 2023

I would expect all punctuation to be removed
Eg:

toTitleCase('my-kebab-case') // 'My Kebab Case'
toTitleCase('my_snake_case') // 'My Snake Case'
toTitleCase('my.path.case') // 'My Path Case'

However, I definitely think we could include specific examples in the documentation to make this clear. As a user, I could see myself being surprised by this behavior as well.

@jly36963
Copy link
Contributor

jly36963 commented Oct 5, 2023

After trying a few different inputs, I do see this though:

toTitleCase('my.path.case[0]');  // "My Path Case [ 0 ]"

/*
// lodash example
_.startCase('my.path.case[0]') // "My Path Case 0"
*/

In this case, I would also expect [ and ] to be removed (as lodash does).

@gustavoguichard
Copy link
Owner

/*
// lodash example
_.startCase('my.path.case[0]') // "My Path Case 0"
*/

Even though the goal is not to have the same behavior as lodash I agree we should fix this... could you create another issue for it?

As for this issue, let's make it clearer in the docs. Let's check out what lodash does since we are talking about it:

## lowerCase
Converts string, as space separated words, to lower case.

## toLower
Converts string, as a whole, to lower case just like [String#toLowerCase](https://mdn.io/toLowerCase).

I thing we should name the methods differently for v2, and implement lowerCase and upperCase, like they do... for now we can have a different section in the README

@gustavoguichard
Copy link
Owner

gustavoguichard commented Oct 5, 2023

@jly36963 maybe we should add '\' | '|' | '(' | ')' | '[' | ']' | '{' | '}' to separators and also here.

That should make our library a lil more similar to what people are used to.

@gustavoguichard gustavoguichard added bug Something isn't working documentation Improvements or additions to documentation good first issue Good for newcomers and removed invalid This doesn't seem right labels Oct 5, 2023
@dan-scrumsdotcom
Copy link
Author

Wow, clocked off for the day to come back to a totally explained and resolved issue. Thank you @gustavoguichard @jly36963!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants