chanced/caps

How to generate a Go parameter name?

MartyHub opened this issue · 5 comments

Hello,

I'm using caps to generate some Go code and I was wondering if there was a way to achieve the following behavior:

caps.ToLowerCamel("entity id") // entityID
caps.ToLowerCamel("id") // id

Actually, the second example generates "ID"
And if I use the caps.WithReplaceStyleLower() option, the first example is not right anymore

Thanks and regards

Hmm, that's definitely a bug. The second should have been "id"..

I'll fix it but in the meantime, this works:

caps.ToLowerCamel("entity id")                        // entityID
caps.ToLowerCamel("id", caps.WithReplaceStyleLower()) // id

https://go.dev/play/p/K5r_72rYHDx

Thank you for reporting it.

Oh wait, I see the problem. If you use WithReplaceStyleLower then the first wouldn't be correct.

I released version 1.0.1 which should fix this. Sorry about that.

It's working great, thank you!

Awesome, glad to hear it!