View Source Transmogrify.Snakecase (transmogrify v2.0.1)
Convert strings to snake_case
Summary
Functions
Convert a string to snake_case
, usually when originally PascalCase
or
CamelCase
, using the following rules
Convert pascal, dashed etc to a snake_case name as an atom.
Functions
Convert a string to snake_case
, usually when originally PascalCase
or
CamelCase
, using the following rules:
- dashes are treated the same as underscores
- uppercase ascii alphabetic letters are lowercased, and prefixed with an underscore, except when they are the first letter.
- duplicate underscores are removed
- ACRONYMS are preserved
- other characters are preserved in all other cases
Similar to Pathname, except .
is not converted to /
, and dashes are
coverted to underbars
iex> convert("value-dashed")
"value_dashed"
iex> convert("Value")
"value"
iex> convert("vaLue")
"va_lue"
iex> convert("VALUE")
"value"
iex> convert("vaLUE")
"va_lue"
iex> convert("-vaLUE")
"va_lue"
iex> convert("_va___LUE")
"va_lue"
iex> convert(:_va___LUE)
"va_lue"
Convert pascal, dashed etc to a snake_case name as an atom.
iex> snake_atom(:value)
iex> snake_atom(:Value)
iex> snake_atom("valueCamelToSnake")
iex> snake_atom(:"value-dashed")
iex> snake_atom("Value-Dashed")
iex> snake_atom!("Value-Dashed") :value_dashed iex> snake_existing_atom("Value-Dashed")
iex> snake_existing_atom!("Value-Dashed") :value_dashed