Skip to content

Instantly share code, notes, and snippets.

@ponty96
Last active June 3, 2017 22:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ponty96/0a50733c99f53df90fc4089a5b681205 to your computer and use it in GitHub Desktop.
Save ponty96/0a50733c99f53df90fc4089a5b681205 to your computer and use it in GitHub Desktop.
Camelize
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