View Source Valicon.Conversions (valicon v1.7.1)
Data transformation functions. Pretty generic but used mostly before calling the validations.
Summary
Functions
Casts the string values inside the attrs map to the given types.
Functions
@spec atomize_value(map(), Valicon.key(), [atom()]) :: map()
Casts the string values inside the attrs map to the given types.
## Examples
iex> cast(%{name: "Butterfree", number: "012"}, [name: :string, number: :integer])
{:ok, %{name: "Butterfree", number: 12}}
@spec parse(String.t(), :date) :: {:ok, Date.t()} | {:error, atom()}
@spec parse(String.t(), :datetime) :: {:ok, DateTime.t()} | {:error, atom()}
@spec parse(String.t(), :integer) :: {:ok, integer()} | {:error, :bad_integer}
@spec parse(String.t(), :boolean) :: {:ok, boolean()} | {:error, :bad_boolean}
@spec parse(String.t() | [String.t()], :list) :: {:ok, [String.t()]}
@spec parse(String.t(), :string) :: {:ok, String.t()}
@spec parse_datetime(term()) :: {:ok, DateTime.t()} | {:error, atom()}
@spec rename_key(map(), Valicon.key(), Valicon.key()) :: map()