mayo v0.2.0 Mayo.Any

Summary

Functions

Checks if the value is an atom

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

Sets to the default value if the value is nil

Forbids any value except nil

Checks if the value is a list

Checks if the value is a map

Checks if the value is a number

Checks if the value is nil

Checks if the value is a string

Sets the value to nil. Used to sanitize output

Functions

atom(value)

Checks if the value is an atom.

iex> Mayo.Any.atom(:test)
:test

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

Checks if the value is a boolean or true, false, yes, no, on, off, 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"
forbidden(value)

Forbids any value except nil.

iex> Mayo.Any.forbidden(nil)
nil

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

Checks if the value is a list.

iex> Mayo.Any.list([1, 2, 3])
[1, 2, 3]

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

Checks if the value is a map.

iex> Mayo.Any.map(%{username: "test"})
%{username: "test"}

iex> Mayo.Any.map("test")
{:error, %Mayo.Error{type: "any.map"}}
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"}}
strip()

Sets the value to nil. Used to sanitize output.

iex> Mayo.Any.strip("test")
nil

iex> Mayo.Any.strip(nil)
nil