Camel case to dashed case

I am playing around with the idea of having CSS variables in a TOML configuration. For that to work the config will be in camel case and needs to be translated into lower cases with dashes.

I couldn’t find a function that does that, something like camel case to urlize.

Currently I think it’s a sequence like this:

  • Do a replaceRE over the key (see this regexp test)
  • lower case it
  • trim extra dashes - the last item has a dash at the end because of the weird OR syntax

Is that the proper way or do I miss an easy way?

Sample:

config sample in TOML:

someCamelCase = "#123456"

is supposed to end up as

--some-camel-case: "#123456";

Why do the CSS variables need to be “dashed”?

Because the overridden system is out of my hands:

{{ $v := "someCamelCase" }}
{{ add "--" ($v | humanize | lower | replaceRE " " "-") }}
4 Likes

That did the trick. And I remember i saw humanize before, but always had it in mind for ordinals in my numbers. But it’s a secret weapon. Thanks @jmooring.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.