Skip to content

Gooey chewy library to camelize keys in a map

Notifications You must be signed in to change notification settings

sgtpepper43/caramelize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Gooey chewy library to camelize keys in a map

Resources

Stars

Watchers

Forks

Packages

No packages published