EthanML/key_tools_ex
{ "createdAt": "2016-08-30T19:21:04Z", "defaultBranch": "master", "description": "Simple functions for coercing Elixir Maps: atomizing, snake_casing, etc.", "fullName": "EthanML/key_tools_ex", "homepage": "", "language": "Elixir", "name": "key_tools_ex", "pushedAt": "2017-02-08T01:23:13Z", "stargazersCount": 7, "topics": [ "atoms", "camel-case", "elixir", "maps", "snake-casing", "stringify", "utilities", "utils" ], "updatedAt": "2023-09-01T12:14:45Z", "url": "https://github.com/EthanML/key_tools_ex"}KeyTools
Section titled “KeyTools”Simple functions for coercing Elixir Maps (or Lists of Maps).
Say your API provides you with camelCased string keys…
iex(1)> payload = %{...(1)> "data" => [...(1)> %{...(1)> "userName" => "EthanML"...(1)> }...(1)> ]...(1)> }…and you want them to conform to Elixir standards, i.e. have atoms for keys and use snake_casing:
iex(2)> import KeyToolsiex(3)> payload...(3)> |> atomize_keys...(3)> |> underscore_keys%{data: [%{user_name: "EthanML"}]}And that’s about it.
Note that this library uses and thus is bound by the same limitations detailed in the docs for Macro.underscore/1:
This function was designed to underscore language identifiers/tokens, that’s why it belongs to the Macro module. Do not use it as a general mechanism for underscoring strings as it does not support Unicode or characters that are not valid in Elixir identifiers.
…so be careful if you’re likely to have to deal with any unusual characters in your keys.
Current Functions
Section titled “Current Functions”Current functions include:
atomize_keys/1stringify_keys/1underscore_keys/1camelize_keys/1/camelize_keys/2
Check out the docs for full details.
Installation
Section titled “Installation”How to install from Hex:
- Add
key_toolsto your list of dependencies inmix.exs:
```elixirdef deps do [{:key_tools, "~> 0.4"}]end```2. Ensure key_tools is started before your application:
```elixirdef application do [applications: [:key_tools]]end```How to Contribute
Section titled “How to Contribute”If you’d like to contribute to the project (thanks in advance!) please pull the dev branch, then create another branch off of dev with your changes. Then, just push your branch and create a Pull Request against dev for review.
Alternatively, feel free to write up an Issue.