Skip to content

Commit dc4bf73

Browse files
committed
update readme
1 parent c137b57 commit dc4bf73

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,29 @@
55
![Hex downloads](https://img.shields.io/hexpm/dt/atomic_map.svg "Hex downloads")
66

77

8-
A small utility to convert deep Elixir maps with mixed string/atom keys to atom-only keyed maps. Optionally with a safe option, to prevent [atom space exhaustion of the Erlang VM](https://erlangcentral.org/wiki/index.php?title=String_Conversion_To_Atom).
8+
A small utility to convert deep Elixir maps with mixed string/atom keys to atom-only keyed maps. Optionally with a safe option, to prevent [atom space exhaustion of the Erlang VM](https://erlangcentral.org/wiki/index.php?title=String_Conversion_To_Atom). Since v0.8 it also supports conversion of keys from `CamelCase` to `under_score` format.
99

1010
## Usage
1111

1212

1313
```elixir
14+
# works with nested maps
1415
iex> AtomicMap.convert(%{"a" => 2, "b" => %{"c" => 4}}, safe: true)
1516
%{a: 2, b: %{c: 4}}
1617

18+
# works with nested maps + lists + mixed key types (atoms + binaries)
1719
iex> AtomicMap.convert([ %{"c" => 1}, %{:c => 2}, %{"c" => %{:b => 4}}], safe: true]
1820
[%{c: 1}, %{c: 2}, %{c: %{b: 4}}]
1921

2022

21-
iex> AtomicMap.convert(%{ "a" => [ %{"c" => 1}, %{"c" => 2}] }, safe: true]
22-
%{a: [%{c: 1}, %{c: 2}] }
2323

24+
# converts CamelCase to under_score by default (notice that you might have to turn 'safe' flag off)
25+
iex> AtomicMap.convert(%{ "CamelCase" => [ %{"c" => 1}, %{"c" => 2}] }, safe: false)
26+
%{camel_case: [%{c: 1}, %{c: 2}]}
27+
28+
# underscoring can be turned off by passing `underscore: false` to opts
29+
iex> AtomicMap.convert(%{ "CamelCase" => [ %{"c" => 1}, %{"c" => 2}] }, safe: false, underscore: false )
30+
%{CamelCase: [%{c: 1}, %{c: 2}]}
2431
```
2532

2633

0 commit comments

Comments
 (0)