strcase icon indicating copy to clipboard operation
strcase copied to clipboard

Preserve initialism

Open liyanchang opened this issue 2 years ago • 1 comments

What does this fix or improve?

Here we preserve existing initialisms without them needing to be defined ahead of time.

For instance,

caser := NewCaser(false, nil, nil) // No Go or custom initialisms

// Since we lower case everything, this is `nasa-rocket`
caser.ToCase("NASARocket", LowerCase, '-'))

// If we preserve the initialism, then the result will depend on the input
caser.ToCase("NASARocket", LowerCase|PreserveInitialism, '-')) // NASA-rocket
caser.ToCase("NasaRocket", LowerCase|PreserveInitialism, '-')) // nasa-rocket

This is a possible solution to #8

Is this a breaking change API change or change in behavior?

This will not break or change any existing behavior.*

This does increase the API surface area so I'll let this one sit for a bit before committing to it.

  • The only exception would be if someone specified an int that wasn't a valid WordCase that is now being implemented and that seems both unlikely and previously useless behavior.

Checklist:

  • [x] I have updated the documentation accordingly, if needed.
  • [x] I have added appropriate tests, if needed.

I will likely not merge this for a bit to allow for feedback and also to get more comfortable with the API changes.

liyanchang avatar Jan 14 '23 18:01 liyanchang

Hi @liyanchang, thank you for your work on this project.

I am trying to use this PR for one of the project that i am working on, and it seems to be working fine as expected. 🎉

one thing that I think might be useful for future is to be able to configure the PreserveInitialism with list of initialism instead of preserving all uppercase letters, but that is not a blocker (atleast for me) at the moment.

do you think we can merge this PR anytime soon?

thanks

rajatjindal avatar Aug 13 '24 02:08 rajatjindal