View Source Transmogrify.Modulename (transmogrify v2.0.1)

Convert file/paths to Elixir ModuleName

Summary

Functions

Convert a path/module_name/string to Elixir's Path.ModuleName.String, using the following rules similar to PascalCase

Functions

@spec convert(String.t()) :: String.t()

Convert a path/module_name/string to Elixir's Path.ModuleName.String, using the following rules similar to PascalCase:

  • first letter is always capitalized
  • ascii alphabetic letters immediately following an underscore are capitalized
  • underscores are removed
  • slashes are converted to dots
  • existing case and other characters are preserved in all other cases
iex> convert("MODULENAME")
"MODULENAME"
iex> convert("_module___name__")
"ModuleName"
iex> convert("module_name")
"ModuleName"
iex> convert("module_name")
"ModuleName"
iex> convert("module_name")
"ModuleName"
iex> convert("ModuleNAME")
"ModuleNAME"
iex> convert("Module_NAME")
"ModuleNAME"
iex> convert("ModuleName")
"ModuleName"
iex> convert("Module Name")
"Module Name"
iex> convert("module/name/here")
"Module.Name.Here"
iex> convert("module_9name.here")
"Module9name.Here"
iex> convert(Module.Name)
"Module.Name"

note: Original code from Macro.camelize/1 with minor changes:

  • underscore followed by capital letter is treated the same as lowercase letter (the underscore is removed and the letter is capitalized)
  • existing dots are treated the same as slashes (following letter is capitalized)