View Source Vx.Number (Vx v0.4.0)

The Integer type provides validators for integers.

Summary

Types

t()

The number type.

Functions

Requires the number to be within the given range.

Requires the number to be greater than the given value.

Requires the number to be greater than or equal to the given value.

Requires the number to have no decimal places.

Requires the number to be less than the given value.

Requires the number to be less than or equal to the given value.

Requires the number to be negative.

Requires the number to be positive.

Requires the number to be in the given range.

t()

Builds a new Number type.

Types

@type numeric() :: t() | Vx.Float.t() | Vx.Integer.t()
@opaque t()

The number type.

Functions

Link to this function

between(schema \\ t(), first, last)

View Source
@spec between(schema, number(), number()) :: schema when schema: numeric()

Requires the number to be within the given range.

Link to this function

gt(schema \\ t(), value)

View Source
@spec gt(schema, number()) :: schema when schema: numeric()

Requires the number to be greater than the given value.

Link to this function

gteq(schema \\ t(), value)

View Source
@spec gteq(schema, number()) :: schema when schema: numeric()

Requires the number to be greater than or equal to the given value.

@spec integer(schema) :: schema when schema: numeric()

Requires the number to have no decimal places.

Examples

iex> Vx.Number.integer() |> Vx.validate!(123)
:ok

iex> Vx.Number.integer() |> Vx.validate!(123.0)
:ok

iex> Vx.Number.integer() |> Vx.validate!(123.4)
** (Vx.Error) must have no decimal places

iex> Vx.Number.integer() |> Vx.validate!("foo")
** (Vx.Error) must be a number
Link to this function

lt(schema \\ t(), value)

View Source
@spec lt(schema, number()) :: schema when schema: numeric()

Requires the number to be less than the given value.

Link to this function

lteq(schema \\ t(), value)

View Source
@spec lteq(schema, number()) :: schema when schema: numeric()

Requires the number to be less than or equal to the given value.

Link to this function

negative(schema \\ t())

View Source (since 0.3.0)
@spec negative(schema) :: schema when schema: numeric()

Requires the number to be negative.

Link to this function

positive(schema \\ t())

View Source (since 0.3.0)
@spec positive(schema) :: schema when schema: numeric()

Requires the number to be positive.

Link to this function

range(schema \\ t(), range)

View Source
@spec range(schema, Range.t()) :: schema when schema: numeric()

Requires the number to be in the given range.

Example

iex> Vx.Number.range(1..10) |> Vx.validate!(5)
:ok

iex> Vx.Number.range(1..10) |> Vx.validate!(11)
** (Vx.Error) must be in 1..10
@spec t() :: t()

Builds a new Number type.

Examples

iex> Vx.Number.t() |> Vx.validate!(123)
:ok

iex> Vx.Number.t() |> Vx.validate!(123.4)
:ok

iex> Vx.Number.t() |> Vx.validate!("foo")
** (Vx.Error) must be a number