blakeembrey / change-case

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

How to capitalize text starting with ampersand in 4.x, eg: #tag #343

Open Nantris opened 3 months ago

Nantris commented 3 months ago

3.x used to handle this seamlessly. I tried a few configuration options to restore this behavior but I can't seem to make it work.

It's not the end of the world if we have to substring and reconstruct the string, but I'd rather not if I'm just overlooking something.

blakeembrey commented 3 months ago

Just to clarify, you mean starting with # right? An ampersand is &. And this was intentional in https://github.com/blakeembrey/change-case/commit/2e0c64c9c1a1edd17e649b9e72a077ccb1ea6297. It could be added back as an option, but I'd love to hear about why you need to capitalize tags specifically?

If the goal is just capitalizing words, this is an expensive library for that and it's simpler to just do something like x.replace(/\p{L}+/ug, x => x[0].toUpperCase() + x.slice(1)) or something along these lines.

Nantris commented 3 months ago

First, thanks for the great work and for your reply! Thanks also for the correction!

We use title-case to title-case a variety of user-generated titles on the local page, with hashtags being a subset of titles more broadly. While it's a bit heavy for hashtags, it takes a cognitive load off to keep the processing uniform and idiomatic.

blakeembrey commented 3 months ago

Sounds good. If we can get a rough idea of how you think it should work it shouldn’t be an issue to add an option for you. Is it just the same behavior in v3? I don’t have time to test right now, but I think it wouldn’t have capitalized anything that had a capital (same behavior as words today). E.g. it’d stay as #soGreat. Is that the right behavior? And on URL-like things, such as www.example.com, you’d want that to stay as-is right? So only affect #?

Nantris commented 3 months ago

Yes I think all of your thoughts on how it should work align with mine (which I believe is how v3 worked as well - which indeed would preserve the existing capitalization of #soGreat)

Thank you again for your great work and your attention on this!

Nantris commented 2 months ago

@blakeembrey sorry to be a bother with this. Is our best bet for the short-term downgrading? Might this be resolved in the next few weeks?

I'm trying to square away some final tasks before a new release and I'm wondering if downgrading should be one of them.