Packages

An Elixir library that converts maps from `snake_case` to `camelCase`.

Current section

7 Versions

Jump to

Compare versions

4 files changed
+52 additions
-8 deletions
  @@ -13,7 +13,7 @@ Works when any child is a list, struct, or any other primitive type. Gracefully
13 13 Add caramelize to your list of dependencies in mix.exs:
14 14 ```elixir
15 15 def deps do
16 - [{:caramelize, "~> 0.1.0"}]
16 + [{:caramelize, "~> 0.1.1"}]
17 17 end
18 18 ```
19 19 Ensure caramelize is started before your application:
  @@ -14,5 +14,5 @@
14 14 [[{<<"app">>,<<"ecto">>},
15 15 {<<"name">>,<<"ecto">>},
16 16 {<<"optional">>,false},
17 - {<<"requirement">>,<<"~> 2.0.0">>}]]}.
18 - {<<"version">>,<<"0.1.1">>}.
17 + {<<"requirement">>,<<"~> 2.1.3">>}]]}.
18 + {<<"version">>,<<"0.1.2">>}.
  @@ -3,6 +3,50 @@ defmodule Caramelize do
3 3 An Elixir library for converting the keys of snake_case maps to camelCase
4 4 """
5 5
6 + @doc """
7 + Camelizes a variety of data structures
8 +
9 + * atom -> camelizes the atom
10 + * string -> camelizes the string
11 + * nested map -> camelize the nested map keys
12 + * list of maps -> camelize the maps
13 + * map -> camelize the keys
14 + * DateTime -> pass it straight through for easier serialization
15 +
16 + ## Examples
17 +
18 + iex(1)> Caramelize.camelize("cool_string")
19 + "coolString"
20 +
21 + iex(2)> Caramelize.camelize(:cool_string)
22 + "coolString"
23 +
24 + iex(3)> Caramelize.camelize(%{cool_atom: "foo"})
25 + %{"coolAtom" => "foo"}
26 +
27 + iex(4)> Caramelize.camelize(%{"cool_string" => "bar"})
28 + %{"coolString" => "bar"}
29 +
30 + iex(5)> Caramelize.camelize(%{cool_atom: %{another_cool_atom: "foo"}})
31 + %{"coolAtom" => %{"anotherCoolAtom" => "foo"}}
32 +
33 + iex(6)> Caramelize.camelize(%{"cool_string" => %{
34 + ...> "another_cool_string" => "bar"}
35 + ...> })
36 + %{"coolString" => %{"anotherCoolString" => "bar"}}
37 +
38 + iex(7)> Caramelize.camelize([%{cool_key: "foo"}])
39 + [%{"coolKey" => "foo"}]
40 +
41 + iex(8)> Caramelize.camelize(%{list_key: [%{foo: 12, bar: 13}]})
42 + %{"listKey" => [%{"bar" => 13, "foo" => 12}]}
43 +
44 + iex(9)> Caramelize.camelize(DateTime.from_unix!(1476219081))
45 + %DateTime{calendar: Calendar.ISO, day: 11, hour: 20, microsecond: {0, 0},
46 + minute: 51, month: 10, second: 21, std_offset: 0, time_zone: "Etc/UTC",
47 + utc_offset: 0, year: 2016, zone_abbr: "UTC"}
48 + """
49 +
6 50 # Camelize atoms in a map
7 51 def camelize(key) when is_atom(key) do
8 52 key |> Atom.to_string |> camelize
  @@ -3,13 +3,13 @@ defmodule Caramelize.Mixfile do
3 3
4 4 def project do
5 5 [app: :caramelize,
6 - version: "0.1.1",
6 + version: "0.1.2",
7 7 elixir: "~> 1.3",
8 - description: description,
9 - package: package,
8 + description: description(),
9 + package: package(),
10 10 build_embedded: Mix.env == :prod,
11 11 start_permanent: Mix.env == :prod,
12 - deps: deps,
12 + deps: deps(),
13 13 #Docs
14 14 name: "Caramelize",
15 15 source_url: "https://github.com/SRVentures/caramelize",
  @@ -33,7 +33,7 @@ defmodule Caramelize.Mixfile do
33 33 defp deps do
34 34 [{:ex_doc, ">= 0.0.0", only: :dev},
35 35 {:credo, "~> 0.4", only: [:dev, :test]},
36 - {:ecto, "~> 2.0.0"}]
36 + {:ecto, "~> 2.1.3"}]
37 37 end
38 38
39 39 defp package do