A version of this article is available on Medium.
Heck is a Luau library that provides case conversion utilities for strings. It analyzes the input string to find the necessary word boundaries to properly rewrite it in one of the supported case formats. Thanks to the luau-character project, there’s Unicode support out of the box.
Supported case formats:
- lowerCamelCase
- UpperCamelCase (also called PascalCase)
- snake_case
- SHOUTY_SNAKE_CASE
- kebab-case
- SHOUTY-KEBAB-CASE
- Title Case
- Train-Case
Case Conversion Functions
All functions accept a string and return a new string that follows a specific case.
Note that the following examples assume you have imported the package into a heck variable.
local heck = require('@pkg/@seaofvoices/heck-luau')
| function | “hello world” | “RGBColor” | “var__name1!” |
|---|---|---|---|
toSnakeCase |
hello_world |
rgb_color |
var_name1 |
toPascalCase |
HelloWorld |
RgbColor |
VarName1 |
toLowerCamelCase |
helloWorld |
rgbColor |
varName1 |
toKebabCase |
hello-world |
rgb-color |
var-name1 |
toShoutySnakeCase |
HELLO_WORLD |
RGB_COLOR |
VAR_NAME1 |
toShoutyKebabCase |
HELLO-WORLD |
RGB-COLOR |
VAR-NAME1 |
toTitleCase |
Hello World |
Rgb Color |
Var Name1 |
toTrainCase |
Hello-World |
Rgb-Color |
Var-Name1 |
Word Boundaries
Heck recognizes word boundaries based on capitalization patterns, numbers and separators like spaces, underscores and hyphens. When multiple word boundary characters appear consecutively, they are folded into a single separator in the output.
heck.toSnakeCase("hello___world") -- "hello_world"
heck.toKebabCase("hello---world") -- "hello-world"
heck.toTitleCase("hello world") -- "Hello World"
Installation
The project is hosted on GitHub. You can grab a Roblox model file attached to the latest release:
- Navigate to the GitHub releases
- Scroll to the
Assetssection and download theheck.rbxm(Roblox model file) - Drag the file into Roblox Studio
The project is also published on the npm registry. You can add @seaofvoices/heck-luau to your project dependencies with:
npm install @seaofvoices/heck-luau
# or
yarn add @seaofvoices/heck-luau
End Notes
I work part-time to dedicate time to the Luau open-source ecosystem. If you find this library or my other projects helpful, please consider buying me a coffee on ko-fi ![]()
This project was carefully translated from the Rust heck project, along with its many unit tests (~130).
If you find any issues with the library or have suggestions for improvements, please open an issue on the GitHub repository.
Useful Links
- github.com/seaofvoices/heck-luau
- github.com/seaofvoices/luau-character
- All my projects and articles on seaofvoices.ca
- ko-fi.com/seaofvoices
- Sea of Voices Github
A few other articles I wrote: