View Source Vx.String (Vx v0.4.0)
The String type.
Summary
Functions
Requires a string to match the given regex.
Requires a string to be at most length
characters long.
Requires a string to be at least length
characters long.
Requires a string to be non-empty.
Requires a string to be non-empty after stripping leading and trailing whitespace.
Builds a new String type.
Types
@opaque t()
The string type.
Functions
Requires a string to match the given regex.
Examples
iex> Vx.String.t() |> Vx.String.format(~r/\d+/) |> Vx.validate!("123")
:ok
iex> Vx.String.t() |> Vx.String.format(~r/\d+/) |> Vx.validate!("foo")
** (Vx.Error) must match expected format
@spec max_length(t(), non_neg_integer()) :: t()
Requires a string to be at most length
characters long.
Examples
iex> Vx.String.t() |> Vx.String.max_length(3) |> Vx.validate!("foo")
:ok
iex> Vx.String.t() |> Vx.String.max_length(3) |> Vx.validate!("fo")
:ok
iex> Vx.String.t() |> Vx.String.max_length(3) |> Vx.validate!("fooo")
** (Vx.Error) must be at most 3 characters
@spec min_length(t(), non_neg_integer()) :: t()
Requires a string to be at least length
characters long.
Examples
iex> Vx.String.t() |> Vx.String.min_length(3) |> Vx.validate!("foo")
:ok
iex> Vx.String.t() |> Vx.String.min_length(3) |> Vx.validate!("foob")
:ok
iex> Vx.String.t() |> Vx.String.min_length(3) |> Vx.validate!("fo")
** (Vx.Error) must be at least 3 characters
Requires a string to be non-empty.
Examples
iex> Vx.String.t() |> Vx.String.non_empty() |> Vx.validate!("foo")
:ok
iex> Vx.String.t() |> Vx.String.non_empty() |> Vx.validate!(" ")
:ok
iex> Vx.String.t() |> Vx.String.non_empty() |> Vx.validate!("")
** (Vx.Error) must not be empty
Requires a string to be non-empty after stripping leading and trailing whitespace.
Examples
iex> Vx.String.t() |> Vx.String.present() |> Vx.validate!("foo")
:ok
iex> Vx.String.t() |> Vx.String.present() |> Vx.validate!("")
** (Vx.Error) must be present
iex> Vx.String.t() |> Vx.String.present() |> Vx.validate!(" ")
** (Vx.Error) must be present
@spec t() :: t()
Builds a new String type.
Examples
iex> Vx.String.t() |> Vx.validate!("foo")
:ok
iex> Vx.String.t() |> Vx.validate!(123)
** (Vx.Error) must be a string