KeyConvert v0.1.0 KeyConvert View Source
KeyConvert allows transforming the keys of maps to another case.
Atom
keys will be converted to String
s as atoms are not
garbage-collected and are not meant for dynamically generated data.
It supports nested maps.
Link to this section Summary
Functions
Converts the keys to camel case
Converts the keys based on converter
function provided
Converts the keys to snake case
Link to this section Functions
Converts the keys to camel case.
Examples
iex> KeyConvert.camelize(%{total_amount: 500})
%{"totalAmount" => 500}
iex> KeyConvert.camelize(%{
...> contact_info: %{email_address: "email@example.com"}
...> })
%{"contactInfo" => %{"emailAddress" => "email@example.com"}}
Converts the keys based on converter
function provided.
Converter function should be able to take a key as an input and return a new
key which will be used for the converted Map
.
Examples
iex> append_change = fn key -> key <> ".changed" end
iex> KeyConvert.convert(%{"total_amount" => 500}, append_change)
%{"total_amount.changed" => 500}