View Source Transmogrify.Snakecase (transmogrify v2.0.2)

Convert strings to snake_case

Summary

Functions

Convert a string to snake_case, usually when originally PascalCase or CamelCase, using the following rules

Functions

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

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"