String case conversion utilities implemented as an mq module — camelCase, PascalCase, snake_case, kebab-case, CONSTANT_CASE, Title Case, and more.
- Converts between
camelCase,PascalCase,snake_case,kebab-case,CONSTANT_CASE,dot.case,path/case,Title Case, andSentence case. - Correctly splits acronyms (
XMLHttpRequest->xml,http,request) - Treats any run of non-alphanumeric characters as a word separator, so it accepts input in any of the above styles
is_*_casepredicates to check whether a string already matches a given convention
Copy case.mq to your mq module directory, or place it anywhere and reference it with -L.
cp case.mq ~/.local/mq/config/If mq was built with the http-import feature, you can import directly from GitHub without any local setup:
mq -I raw 'import "github.com/harehare/case.mq" | case::snake_case(.)' input.txtPin to a specific release with @vX.Y.Z:
mq -I raw 'import "github.com/harehare/case.mq@v0.1.0" | ...'mq -L /path/to/modules -I raw \
'import "case" | case::snake_case(.)' input.txtIf you copied it to the mq built-in module directory:
mq -I raw 'import "case" | case::snake_case(.)' input.txt| Function | Description |
|---|---|
camel_case(s) |
Converts s to camelCase |
pascal_case(s) |
Converts s to PascalCase |
snake_case(s) |
Converts s to snake_case |
kebab_case(s) |
Converts s to kebab-case |
constant_case(s) |
Converts s to CONSTANT_CASE |
dot_case(s) |
Converts s to dot.case |
path_case(s) |
Converts s to path/case |
title_case(s) |
Converts s to Title Case |
sentence_case(s) |
Converts s to Sentence case. |
is_snake_case(s) |
Returns true if s is already valid snake_case |
is_kebab_case(s) |
Returns true if s is already valid kebab-case |
is_camel_case(s) |
Returns true if s is already valid camelCase |
is_pascal_case(s) |
Returns true if s is already valid PascalCase |
All conversion functions accept input in any style (or a mix), since they first split the string into words on case boundaries, acronyms, and non-alphanumeric separators before rejoining.
mq -L . -I raw 'import "case" | case::camel_case(.)' <<< "my_http-Server Name"
# => "myHttpServerName"
mq -L . -I raw 'import "case" | case::snake_case(.)' <<< "XMLHttpRequest"
# => "xml_http_request"Rename a list of identifiers in bulk:
import "case"
| map(["userId", "user-name", "user_email"], case::snake_case)
# => ["user_id", "user_name", "user_email"]
Requires mq v0.6 or later (uses regex-based gsub/split).
MIT