View Source SmartCity.Helpers (smart_city v6.0.0)

Functions used across SmartCity modules.

Link to this section Summary

Functions

Merges two maps into one, including sub maps. Matching keys from the right map will override their corresponding key in the left map.

Standardize file type definitions by deferring to the official media type of the file based on a supplied extension.

Convert a map with string keys to one with atom keys. Will convert keys nested in a sub-map or a map that is part of a list. Ignores existing atom keys.

Convert a map with atom keys to one with string keys. Will convert keys nested in a sub-map or a map that is part of a list. Ignores existing string keys.

Link to this section Types

@type file_type() :: String.t()
@type mime_type() :: String.t()

Link to this section Functions

@spec deep_merge(map(), map()) :: map()

Merges two maps into one, including sub maps. Matching keys from the right map will override their corresponding key in the left map.

@spec mime_type(file_type()) :: mime_type()

Standardize file type definitions by deferring to the official media type of the file based on a supplied extension.

Link to this function

safe_atom_to_string(atom)

View Source
Link to this function

safe_string_to_atom(string)

View Source
@spec to_atom_keys(map()) :: map()

Convert a map with string keys to one with atom keys. Will convert keys nested in a sub-map or a map that is part of a list. Ignores existing atom keys.

examples

Examples

iex> SmartCity.Helpers.to_atom_keys(%{"abc" => 123})
%{abc: 123}

iex> SmartCity.Helpers.to_atom_keys(%{"a" => %{"b" => "c"}})
%{a: %{b: "c"}}

iex> SmartCity.Helpers.to_atom_keys(%{"a" => [%{"b" => "c"}]})
%{a: [%{b: "c"}]}
@spec to_string_keys(map()) :: map()

Convert a map with atom keys to one with string keys. Will convert keys nested in a sub-map or a map that is part of a list. Ignores existing string keys.

examples

Examples

iex> SmartCity.Helpers.to_string_keys(%{abc: 123})
%{"abc" => 123}

iex> SmartCity.Helpers.to_string_keys(%{a: %{b: "c"}})
%{"a" => %{"b" => "c"}}

iex> SmartCity.Helpers.to_string_keys(%{a: [%{b: "c"}]})
%{"a" => [%{"b" => "c"}]}