Giter Site home page Giter Site logo

ethanml / key_tools_ex Goto Github PK

View Code? Open in Web Editor NEW
7.0 1.0 2.0 17 KB

Simple functions for coercing Elixir Maps: atomizing, snake_casing, etc.

License: MIT License

Elixir 100.00%
elixir stringify atoms maps utils utilities snake-casing camel-case

key_tools_ex's Introduction

Code Climate

KeyTools

Simple functions for coercing Elixir Maps (or Lists of Maps).

Usage

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 KeyTools
iex(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

Current functions include:

  • atomize_keys/1
  • stringify_keys/1
  • underscore_keys/1
  • camelize_keys/1 / camelize_keys/2

Check out the docs for full details.

Installation

How to install from Hex:

  1. Add key_tools to your list of dependencies in mix.exs:
```elixir
def deps do
  [{:key_tools, "~> 0.4"}]
end
```
  1. Ensure key_tools is started before your application:
```elixir
def application do
  [applications: [:key_tools]]
end
```

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.

key_tools_ex's People

Contributors

benfalk avatar ethanml avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

benfalk boxxxie

key_tools_ex's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.