Stream: show and tell

Topic: To heck with it


view this post on Zulip Ian McLerran (Feb 18 2025 at 20:54):

Quick port of the rust heck crate to roc - convert any string to various casings:

  1. UpperCamelCase / PascalCase
  2. lowerCamelCase
  3. snake_case / snek_case
  4. kebab-case
  5. SHOUTY_SNAKE_CASE / SHOUTY_SNEK_CASE
  6. Title Case
  7. SHOUTY-KEBAB-CASE
  8. Train-Case

view this post on Zulip Luke Boswell (Feb 18 2025 at 21:21):

Neat, I remember implementing something similar for roc-json with plans to roll it into the ascii package someday. It was definitely non-trivial, so will be nice to have a real package to do it.

view this post on Zulip Luke Boswell (Feb 18 2025 at 21:22):

Here's my version in case you're interested https://github.com/lukewilliamboswell/roc-json/blob/main/package/StringFormat.roc

view this post on Zulip Ian McLerran (Feb 18 2025 at 22:08):

Oh yeah… Of course you would have had to implement this for roc-json. I can't take credit for the implementation here, as I just ported from rust, but it’s a pretty minimal algorithm. All boils down to about a 40 line transform algorithm which accepts a function to transform a word, and a function to insert a divider.

view this post on Zulip Ian McLerran (Feb 18 2025 at 22:09):

I can probably clean up the roc implementation a little, but I kept it close to the rust code to begin with.


Last updated: Jul 26 2025 at 12:14 UTC