ettle / strcase

Go package to convert strings to snake_case, camelCase, kebab-case and more! Supports Go initialisms
MIT License
41 stars 4 forks source link

Retain Acronyms when casing #8

Open TristanSpeakEasy opened 1 year ago

TristanSpeakEasy commented 1 year ago

Hi, great library btw it has been very helpful with code gen work we are doing!

What did you do?

strcase.ToCamel("nativeOrgURL")

What did you expect to see?

output == "nativeOrgURL"

What did you see instead?

output == "nativeOrgUrl"

I was looking through the options of creating a custom caser and thought omitting the SplitAcronym option may have produced the output I would have expected.

But basically I would like to be able to pass a string and be able to retain any acronyms that are contained within without needing to understand the input and try and populate the initialisms map with any acronyms I want to retain (as the input comes from end-users so we could receive any acronym), I can't really use strcase.ToGoCamel as it initializes acronyms that weren't initially upper case ie nativeOrgUrl as we are generating code for languages other than Go.

Basically if

input = "nativeOrgURL" then output = "nativeOrgURL" input = "nativeOrgUrl" then output = "nativeOrgUrl"

I don't see a way to achieve this at the moment with the library, any help figuring out if this is possible would be appreciated.

while it looks like I am just trying to have a noop in the case of the examples above we could receive inputs that are of any case for example native_org_url or NativeOrgURL and want to format to nativeOrgUrl or nativeOrlURL to produce properties names suitable for a typescript class for example

liyanchang commented 1 year ago

This is interesting and something worth considering. Trying to think through some of the performance and API implications before I rush something out. Thanks for the suggestion.

liyanchang commented 1 year ago

You can try #13 by doing go get github.com/ettle/strcase@liyanchang-preserve-initialism and let me know how that goes!

You will need to use a custom caser.