mayo v0.1.0 Mayo.Any

Summary

Functions

Checks if the value is a boolean or true, false, yes, no, on, off, 1, 0, 1, 0

Sets to the default value if the value is nil

Checks if the value is a number

Checks if the value is nil

Checks if the value is a string

Functions

boolean(value)

Checks if the value is a boolean or true, false, yes, no, on, off, 1, 0, 1, 0.

iex> Mayo.Any.boolean(true)
true

iex> Mayo.Any.boolean("yes")
true

iex> Mayo.Any.boolean("foo")
{:error, %Mayo.Error{type: "any.boolean"}}
default(value, default)

Sets to the default value if the value is nil.

iex> Mayo.Any.default("test", "default")
"test"

iex> Mayo.Any.default(nil, "default")
"default"
number(value)

Checks if the value is a number.

iex> Mayo.Any.number(23)
23

iex> Mayo.Any.number("test")
{:error, %Mayo.Error{type: "any.number"}}
required(value)

Checks if the value is nil.

iex> Mayo.Any.required("test")
"test"

iex> Mayo.Any.required(nil)
{:error, %Mayo.Error{type: "any.required"}}
string(value)

Checks if the value is a string.

iex> Mayo.Any.string("test")
"test"

iex> Mayo.Any.string(23)
{:error, %Mayo.Error{type: "any.string"}}