Convert from and to different CaseStyles.
This library is different than the others, because you need to explicitly say from and to which case you want to convert. This is nice because you can keep some context and this makes it possible to convert between cases without losing data (check the tests for the edge cases).
input = "testing_testing"
# we convert from SnakeCase
{:ok, casing} = CaseStyle.from_string(input, CaseStyle.SnakeCase)
# casing is a struct with a list of tokens
converted = CaseStyle.to_string(casing, CaseStyle.CamelCase)
# converted is "testingTesting"
In the above example the modules can be dynamically passed. If you know what you want upfront you can use the convenience functions:
{:ok, "testingTesting"} = CaseStyle.snake_to_camel("testing_testing")
If available in Hex, the package can be installed
by adding case_style
to your list of dependencies in mix.exs
:
def deps do
[
{:case_style, "~> 0.2.1"}
]
end
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/case_style.