blakeembrey / change-case

Convert strings between camelCase, PascalCase, Capital Case, snake_case and more
MIT License
2.27k stars 97 forks source link

Title Case not working with a camelCase string #279

Closed btxtiger closed 2 years ago

btxtiger commented 2 years ago

Seems Title Case not working with a camelCase string. I needed to use titleCase(sentenceCase('userSessions')) to get User Sessions. Otherwise the output remains camelCase.

rinogo commented 2 years ago

This confused me, too. It's possible that this Issue is related.

Regardless, I wonder if you could add spaces before all capitalized letters first...

Maybe try something like this?

titleCase(sentenceCase('userSessions'.replace(/([A-Z])/, ' $1')))
blakeembrey commented 2 years ago

I'm not sure I follow this issue, but it works for me: https://runkit.com/blakeembrey/62105d3771ff5600088d0b2d.

In that example of capitalCase and titleCase are working.

blakeembrey commented 2 years ago

Oh, I think the complaint is that titleCase doesn't automatically turn camel case into something else. That's expected behavior, you want capitalCase (title case is for just turning text into a "title" according to basic English rules). That's why it's not included in change-case at all.