There's Uppercase and lowercase, but did you know about SCREAMING-KEBAB-CASE?
strcaseto
This post's topic is that of a set of naming conventions used in just about every
programming language. These are things like CamelCase or kebab-case. The actual
names may be different than those used here but they really just refer to the same
thing.
strcase
strcase is a Go package for performing text transformations of these sorts of things. This package is used throughout the Go-Enjin and other projects, however it's also useful to have these abilities on the command-line. There are lots of little things that do one case or another, but none that really cover the same set as strcase.
Thank you iancoleman and all the contributors to the package as it's made my development life quite wonderful when dealing with string-case-naming things.
strcaseto is a simple command-line program that uses strcase to convert text
from any supported case to any other supported case. For each command line
argument, or for each line of standard input, strcaseto prints one line of
transformed input text.
For example:
# default is --camel
## converting command-line arguments...
> strcaseto this-thing that-thing
ThisThing
ThatThing
## converting lines of standard input
> echo -e "this-thing\nthat-thing" | strcaseto
ThisThing
ThatThing
Installation
This is the same as the other Go-CoreUtils projects:
# note: requires Go v1.22.6
> go install github.com/go-coreutils/stracseto/cmd/strcaseto@latest
Usage
Here's the --help text:
> straseto --help
NAME:
strcaseto - convert strings to various cases
USAGE:
strcaseto [option] <string> [string...]
echo "one-or-more-lines" | strcaseto [option]
VERSION:
0.2.1 (trunk)
DESCRIPTION:
Convert command line arguments (or lines of os.Stdin) to a specific case.
Outputting one line of text per input given.
GLOBAL OPTIONS:
Cases
--camel, -c
--kebab, -k
--lower-camel, -C
--screaming-kebab, -K
--screaming-snake, -S
--snake, -s
General
--help, -h, --usage
--version, -V
Symlinking
(Note: this section is basically a copy/paste of strcaseto README content.)
strcaseto supports a symlink feature for simplifying the usage of any
supported strcase type.
For example: strcaseto --kebab CamelCasedInput would print camel-cased-input
when run. Using a symlink to kebab would reduce the number of characters typed
on the command line to: kebab CamcelCasedInput.
The following naming conventions are supported:
-
to-<strcase>-case -
to-<strcase> -
<strcase>
Here's a little shell scripting to make these symlinks in ${GOPATH}/bin using
the shortest naming convention supported:
for DST in camel kebab lower-camel screaming-kebab screaming-snake snake; \
do \
ln -sv "${GOPATH}/bin/strcaseto" "${GOPATH}/bin/${DST}"; \
done
Now you can use the individual cases without needing to include command-line flags.
> camel "this string"
ThisString
> (echo -e "this string\nthat string") | screaming-kebab
THIS-STRING
THAT-STRING
Conclusion
Nothing super fancy, just a simple utility for transforming text cases.
Enjoy!