| description | Type predicates for Lua values and filesystem path types. |
|---|
Type predicates for Lua values and filesystem path types.
is = require "mods.is"
ok = is.number(3.14) --> true
ok = is("hello", "string") --> true
ok = is.table({}) --> trueNote
Function names are case-insensitive.
is.table({}) --> true
is.Table({}) --> true
is.tAbLe({}) --> trueis is also callable as is(value, type) to check if a value is of a given
type.
is("hello", "string") --> true
is("hello", "String") --> true
is("hello", "STRING") --> trueType Checks:
| Function | Description |
|---|---|
boolean(v) |
Returns true when v is a boolean. |
function(v) |
Returns true when v is a function. |
nil(v) |
Returns true when v is nil. |
number(v) |
Returns true when v is a number. |
string(v) |
Returns true when v is a string. |
table(v) |
Returns true when v is a table. |
thread(v) |
Returns true when v is a thread. |
userdata(v) |
Returns true when v is userdata. |
Value Checks:
| Function | Description |
|---|---|
false(v) |
Returns true when v is exactly false. |
true(v) |
Returns true when v is exactly true. |
falsy(v) |
Returns true when v is falsy. |
callable(v) |
Returns true when v is callable. |
integer(v) |
Returns true when v is an integer. |
truthy(v) |
Returns true when v is truthy. |
Path Checks:
| Function | Description |
|---|---|
block(v) |
Returns true when v is a block device path. |
char(v) |
Returns true when v is a character device path. |
device(v) |
Returns true when v is a block or character device path. |
dir(v) |
Returns true when v is a directory path. |
fifo(v) |
Returns true when v is a FIFO path. |
file(v) |
Returns true when v is a file path. |
link(v) |
Returns true when v is a symlink path. |
socket(v) |
Returns true when v is a socket path. |
Core Lua type checks (type(v) family).
Returns true when v is a boolean.
Parameters:
v(any): Value to validate.
Return:
ok(boolean): Whether the check succeeds.
Example:
is.boolean(true)Returns true when v is a function.
Parameters:
v(any): Value to validate.
Return:
ok(boolean): Whether the check succeeds.
Example:
is.Function(function() end)Returns true when v is nil.
Parameters:
v(any): Value to validate.
Return:
ok(boolean): Whether the check succeeds.
Example:
is.Nil(nil)Returns true when v is a number.
Parameters:
v(any): Value to validate.
Return:
ok(boolean): Whether the check succeeds.
Example:
is.number(3.14)Returns true when v is a string.
Parameters:
v(any): Value to validate.
Return:
ok(boolean): Whether the check succeeds.
Example:
is.string("hello")Returns true when v is a table.
Parameters:
v(any): Value to validate.
Return:
ok(boolean): Whether the check succeeds.
Example:
is.table({})Returns true when v is a thread.
Parameters:
v(any): Value to validate.
Return:
ok(boolean): Whether the check succeeds.
Example:
is.thread(coroutine.create(function() end))Returns true when v is userdata.
Parameters:
v(any): Value to validate.
Return:
ok(boolean): Whether the check succeeds.
Example:
is.userdata(io.stdout)Truthiness, exact-value, and callable checks.
Returns true when v is exactly false.
Parameters:
v(any): Value to validate.
Return:
ok(boolean): Whether the check succeeds.
Example:
is.False(false)Returns true when v is exactly true.
Parameters:
v(any): Value to validate.
Return:
ok(boolean): Whether the check succeeds.
Example:
is.True(true)Returns true when v is falsy.
Parameters:
v(any): Value to validate.
Return:
ok(boolean): Whether the check succeeds.
Example:
is.falsy(false)Returns true when v is callable.
Parameters:
v(any): Value to validate.
Return:
ok(boolean): Whether the check succeeds.
Example:
is.callable(function() end)Returns true when v is an integer.
Parameters:
v(any): Value to validate.
Return:
ok(boolean): Whether the check succeeds.
Example:
is.integer(42)Returns true when v is truthy.
Parameters:
v(any): Value to validate.
Return:
ok(boolean): Whether the check succeeds.
Example:
is.truthy("non-empty")Filesystem path type checks.
Important
Path checks require LuaFileSystem
(lfs) and raise an error if
it is not installed.
Returns true when v is a block device path.
Parameters:
v(any): Value to validate.
Return:
ok(boolean): Whether the check succeeds.
Example:
is.block("/dev/sda")Returns true when v is a character device path.
Parameters:
v(any): Value to validate.
Return:
ok(boolean): Whether the check succeeds.
Example:
is.char("/dev/null")Returns true when v is a block or character device path.
Parameters:
v(any): Value to validate.
Return:
ok(boolean): Whether the check succeeds.
Example:
is.device("/dev/null")Returns true when v is a directory path.
Parameters:
v(any): Value to validate.
Return:
ok(boolean): Whether the check succeeds.
Example:
is.dir("/tmp")Returns true when v is a FIFO path.
Parameters:
v(any): Value to validate.
Return:
ok(boolean): Whether the check succeeds.
Example:
is.fifo("/path/to/fifo")Returns true when v is a file path.
Parameters:
v(any): Value to validate.
Return:
ok(boolean): Whether the check succeeds.
Example:
is.file("README.md")Returns true when v is a symlink path.
Parameters:
v(any): Value to validate.
Return:
ok(boolean): Whether the check succeeds.
Example:
is.link("/path/to/link")Returns true when v is a socket path.
Parameters:
v(any): Value to validate.
Return:
ok(boolean): Whether the check succeeds.
Example:
is.socket("/path/to/socket")