Packages

A collection of helpers to operate on nested maps. See README for the complete list of helpers. The test suite is also helpful.

Current section

Files

Jump to
digger lib impl camel_caser string.ex
Raw

lib/impl/camel_caser/string.ex

defimpl Digger.CamelCaser, for: BitString do
def camel_case(string, first_letter) do
string
|> String.split(~r/[-_\/]+/, include_captures: false)
|> Enum.map_join(&(uppercase_first(&1, :upper)))
|> uppercase_first(first_letter)
end
defp uppercase_first(string, :upper) do
remainder = String.slice(string, 1..-1)
string
|> String.first
|> String.capitalize
|> Kernel.<>(remainder)
end
defp uppercase_first(string, _first_letter) do
remainder = String.slice(string, 1..-1)
string
|> String.first
|> String.downcase
|> Kernel.<>(remainder)
end
end