Raxol.Utils.MapUtils (Raxol v2.0.1)
View SourceCommon utility functions for map operations.
This module consolidates frequently used map transformation functions to avoid code duplication across the codebase.
Summary
Functions
Recursively converts all map keys to atoms.
Safely atomizes keys, only converting strings that already exist as atoms. This prevents atom exhaustion attacks.
Recursively converts all map keys to strings.
Functions
Recursively converts all map keys to atoms.
Examples
iex> Raxol.Utils.MapUtils.atomize_keys(%{"foo" => "bar", "nested" => %{"key" => "value"}})
%{foo: "bar", nested: %{key: "value"}}
iex> Raxol.Utils.MapUtils.atomize_keys(%{"atom" => [%{"inner" => "value"}]})
%{atom: [%{inner: "value"}]}
Safely atomizes keys, only converting strings that already exist as atoms. This prevents atom exhaustion attacks.
Examples
iex> Raxol.Utils.MapUtils.safe_atomize_keys(%{"foo" => "bar"})
%{"foo" => "bar"} # "foo" atom doesn't exist
iex> _ = :existing_atom
iex> Raxol.Utils.MapUtils.safe_atomize_keys(%{"existing_atom" => "value"})
%{existing_atom: "value"}
Recursively converts all map keys to strings.
Examples
iex> Raxol.Utils.MapUtils.stringify_keys(%{foo: "bar", nested: %{key: "value"}})
%{"foo" => "bar", "nested" => %{"key" => "value"}}
iex> Raxol.Utils.MapUtils.stringify_keys(%{:atom => [%{inner: "value"}]})
%{"atom" => [%{"inner" => "value"}]}