Masterminds / sprig

Useful template functions for Go templates.
http://masterminds.github.io/sprig/
MIT License
4.28k stars 441 forks source link

camelcase inconsistent documentation #154

Open badeadan opened 5 years ago

badeadan commented 5 years ago

"snakecase" documentation refers to camelCase to suggest the transformation of someString to _somestring but then "camelcase" documentation refers to CamelCase suggesting _somestring is converted to SomeString

I tested this with a helm chart and:

      - {{"some_string" | camelcase}}
      - {{"some_string" | camelcase | snakecase}}
      - {{"someString" | snakecase | camelcase }}

is rendered as:

    - SomeString
    - some_string
    - SomeString

where the 1st character is transformed by "camelcase" to upper.

Wikipedia definition states:

Camel case (stylized as camelCase; also known as camel caps or more formally as medial capitals) is the practice of writing phrases such that each word or abbreviation in the middle of the phrase begins with a capital letter, with no intervening spaces or punctuation. which means _somestring transformed to Camel case should be someString.

Fixing this is breaking compatibility with older versions so I suggest an update to the documentation page to point to huandu/xstrings definition of Camel case:

// ToCamelCase can convert all lower case characters behind underscores
// to upper case character.
// Underscore character will be removed in result except following cases.
//     * More than 1 underscore.
//           "a__b" => "A_B"
//     * At the beginning of string.
//           "_a" => "_A"
//     * At the end of string.
//           "ab_" => "Ab_"
ghostsquad commented 2 years ago

This is actually an issue that camelcase should mean that the first letter is lowercase. Pascalcase (function does not exist) is where the first letter is uppercase.

https://docs.microsoft.com/en-us/archive/blogs/brada/history-around-pascal-casing-and-camel-casing

https://www.theserverside.com/answer/Pascal-case-vs-camel-case-Whats-the-difference https://khalilstemmler.com/blogs/camel-case-snake-case-pascal-case/ https://betterprogramming.pub/string-case-styles-camel-pascal-snake-and-kebab-case-981407998841 https://stackoverflow.com/questions/41768733/camel-case-and-pascal-case-mistake

So the problem is that sprig has a bug. It would be nice if a new version was published that fixed this.