View Source Valicon.Conversions (valicon v1.4.0)

Data transformation functions. Pretty generic but used mostly before calling the validations.

Summary

Functions

Link to this function

atomize_keys(attrs, keys)

View Source
@spec atomize_keys(map(), [atom()]) :: map()
Link to this function

atomize_value(attrs, key, possible_values)

View Source
@spec atomize_value(map(), Valicon.key(), [atom()]) :: map()
@spec cast(map(), Keyword.t()) ::
  {:ok, map()} | {:error, [Valicon.ConversionError.t()]}

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 downcase_in(map(), atom()) :: map()
@spec parse(String.t(), :date) :: {:ok, Date.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_boolean(term()) :: {:ok, boolean()} | {:error, :bad_boolean}
@spec parse_float(term()) :: {:ok, float()} | {:error, :bad_float}
@spec parse_integer(term()) :: {:ok, integer()} | {:error, :bad_integer}
@spec parse_list(String.t() | [String.t()]) ::
  {:ok, [String.t()]} | {:error, :bad_list}
@spec parse_string(term()) :: {:ok, String.t()} | {:error, :bad_string}
Link to this function

rename_key(map, from, to)

View Source
@spec rename_key(map(), Valicon.key(), Valicon.key()) :: map()
Link to this function

transform(attrs, fields)

View Source
@spec transform(map(), list()) :: map()
Link to this function

transform_in(attrs, key, transformation)

View Source
@spec transform_in(map(), atom(), (term() -> term())) :: map()
@spec trim_whitespaces(any()) :: any()
@spec upcase_in(map(), atom()) :: map()