Helper.String (helper v1.0.1) View Source
Utility functions for operating with strings
Link to this section Summary
Functions
Convert a string to atom in a safe manner.
Link to this section Functions
Specs
Convert a string to atom in a safe manner.
The function will try String.to_existing_atom/1
and if it raises an
ArgumentError, the function will convert the binary to atom using
String.to_atom/1
## Example
iex> to_atom("nil")
:nil
iex> to_atom("random_atom") |> Atom.to_string()
"random_atom"
iex> to_atom([1, 2, 3])
** (ArgumentError) [1, 2, 3]: Expected a string