Skip to content

Latest commit

 

History

History
57 lines (41 loc) · 1.47 KB

README.md

File metadata and controls

57 lines (41 loc) · 1.47 KB

Caramelize

Gooey chewy library to camelize keys in a map

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

Works when any child is a list, struct, or any other primitive type. Gracefully ignores DateTime structs.

Installation

Add caramelize to your list of dependencies in mix.exs:

def deps do
  [{:caramelize, "~> 0.1.0"}]
end

Ensure caramelize is started before your application:

def application do
  [applications: [:caramelize]]
end

Usage

Simply pass any map into the Caramelize.camelize() function, and it will return a map with all keys converted to camelCase.

Example

awesome_map = %{test_foo: "foo",
                test_bar: %CoolStruct{cool_key: "Cool Value"},
                test_baz: ["baz", "boz", "box"],
                test_boz: %{awesome_lib: "Thanks man!"}
              }

awesomer_map = Caramelize.camelize(awesome_map)

Output:

awesomer_map = %{"testFoo" => "foo",
                "testBar" => %CoolStruct{"coolKey" => "Cool Value"},
                "testBaz" => ["baz", "boz", "box"],
                "testBoz" => %{"awesomeLib" => "Thanks man!"}
              }

Contributing

Pull requests welcome! Add tests to the caramelize_test.exs and ensure all tests are passing before PR submission.