Caramelize v1.2.1 Caramelize View Source

An Elixir library for converting the keys of snake_case maps to camelCase

Link to this section Summary

Functions

Camelizes a variety of data structures

Link to this section Functions

Camelizes a variety of data structures

  • atom -> camelizes the atom
  • string -> camelizes the string
  • nested map -> camelize the nested map keys
  • list of maps -> camelize the maps
  • map -> camelize the keys
  • DateTime -> pass it straight through for easier serialization

Examples

iex(1)> Caramelize.camelize("cool_string")
"coolString"

iex(2)> Caramelize.camelize(:cool_string)
"coolString"

iex(3)> Caramelize.camelize(%{cool_atom: "foo"})
%{"coolAtom" => "foo"}

iex(4)> Caramelize.camelize(%{"cool_string" => "bar"})
%{"coolString" => "bar"}

iex(5)> Caramelize.camelize(%{cool_atom: %{another_cool_atom: "foo"}})
%{"coolAtom" => %{"anotherCoolAtom" => "foo"}}

iex(6)> Caramelize.camelize(%{"cool_string" => %{
...>      "another_cool_string" => "bar"}
...>    })
%{"coolString" => %{"anotherCoolString" => "bar"}}

iex(7)> Caramelize.camelize([%{cool_key: "foo"}])
[%{"coolKey" => "foo"}]

iex(8)> Caramelize.camelize(%{list_key: [%{foo: 12, bar: 13}]})
%{"listKey" => [%{"bar" => 13, "foo" => 12}]}

iex(9)> Caramelize.camelize(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"}