Caramelize v1.2.1 Snekize View Source
An Elixir library for converting the keys of camelCase maps to snake_case
Link to this section Summary
Functions
Snakeizes a variety of data structures
Link to this section Functions
Snakeizes a variety of data structures
- atom -> Snakeizes the atom
- string -> Snakeizes the string
- nested map -> Snakeizes the nested map keys
- list of maps -> Snakeizes the maps
- map -> Snakeizes the keys
- DateTime -> pass it straight through for easier serialization
Examples
iex(1)> Snekize.snake("coolString")
"cool_string"
iex(2)> Snekize.snake(:coolString)
"cool_string"
iex(3)> Snekize.snake(%{coolAtom: "foo"})
%{"cool_atom" => "foo"}
iex(4)> Snekize.snake(%{"coolString" => "bar"})
%{"cool_string" => "bar"}
iex(5)> Snekize.snake(%{coolAtom: %{anotherCoolAtom: "foo"}})
%{"cool_atom" => %{"another_cool_atom" => "foo"}}
iex(6)> Snekize.snake(%{"coolString" => %{
...> "anotherCoolString" => "bar"}
...> })
%{"cool_string" => %{"another_cool_string" => "bar"}}
iex(7)> Snekize.snake([%{coolKey: "foo"}])
[%{"cool_key" => "foo"}]
iex(8)> Snekize.snake(%{listKey: [%{foo: 12, bar: 13}]})
%{"list_key" => [%{"bar" => 13, "foo" => 12}]}
iex(9)> Snekize.snake(DateTime.from_unix!(1476219081))
%DateTime{calendar: Calendar.ISO, day: 11, hour: 20, microsecond: {0, 0},
minute: 51, month: 10, second: 21, std_offset: 0, time_zone: "Etc/UTC",
utc_offset: 0, year: 2016, zone_abbr: "UTC"}