Last active
June 3, 2017 22:18
-
-
Save ponty96/0a50733c99f53df90fc4089a5b681205 to your computer and use it in GitHub Desktop.
Camelize
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Ponty96.ToolTips.Camelize do | |
@moduledoc false | |
def camelize(word), do: camelize(word, []) | |
def camelize(word, opts \\ []) | |
def camelize("_" <> word, opts) do | |
"_" <> camelize(word, opts) | |
end | |
def camelize(word, opts) do | |
case opts |> Enum.into(%{}) do | |
%{lower: true} -> | |
{first, rest} = String.split_at(Macro.camelize(word), 1) | |
String.downcase(first) <> rest | |
_ -> | |
Macro.camelize(word) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment