View Source Vx (Vx v0.4.0)

Vx is a schema validation library.

Summary

Types

A Vx schema is anything that implements the Vx.Validatable protocol.

Functions

Checks if a value is valid against a given schema.

Validates a value against a given schema.

Validates a value against a given schema. Raises on error.

Types

@type schema() :: Vx.Validatable.t()

A Vx schema is anything that implements the Vx.Validatable protocol.

Functions

Link to this function

valid?(schema, value)

View Source (since 0.4.0)
@spec valid?(schema(), any()) :: boolean()

Checks if a value is valid against a given schema.

Examples

iex> Vx.valid?(Vx.String.t(), "foo")
true

iex> Vx.valid?(Vx.String.t(), 123)
false
@spec validate(schema(), any()) :: :ok | {:error, Vx.Error.t()}

Validates a value against a given schema.

Examples

iex> Vx.validate(Vx.String.t(), "foo")
:ok

iex> Vx.validate(Vx.String.t(), 123)
{:error, %Vx.Error{message: "must be a string", schema: Vx.String.t(), value: 123}}
Link to this function

validate!(schema, value)

View Source
@spec validate!(schema(), any()) :: :ok | no_return()

Validates a value against a given schema. Raises on error.

Examples

iex> Vx.validate!(Vx.String.t(), "foo")
:ok

iex> Vx.validate!(Vx.String.t(), 123)
** (Vx.Error) must be a string