snakecase
snakecase is a pre-alpha library that offers compile time validation of snake_case
strings.
For the purposes of this library, a valid snake_case
string:
- must start with a lowercase letter;
[a-z]
- may only contain lowercase letters, digits, and underscores;
[a-z0-9_]+
Usage
This library is currently available for Scala binary versions 2.13 and 3.
To use the latest version, include the following in your build.sbt
:
libraryDependencies ++= Seq(
"pink.cozydev" %% "snakecase" % "0.0.4"
)
A typical example of library use:
import pink.cozydev.snakecase._
val snakeString: SnakeCase = snake"western_coachwhip"
// snakeString: SnakeCase = SnakeCase(toString = "western_coachwhip")
println(s"This is a snake case string: $snakeString")
// This is a snake case string: western_coachwhip
If an invalid string is passed, a compiler error will be raised:
val badString: SnakeCase = snake"CAPYBARA"
// error: Invalid SnakeCase -- string may only contain a-z, 0-9, _, and must start with a letter
// val badString: SnakeCase = snake"CAPYBARA"
// ^^^^^^^^^^^^^^^