is ​
Type predicates for Lua values and filesystem path types.
Usage ​
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 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") --> trueFunctions ​
Type 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 |
|---|---|
path(v) | Returns true when v is a valid filesystem path. |
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. |
Type Checks ​
Core Lua type checks (type(v) family).
boolean(v) ​
Returns true when v is a boolean.
Parameters:
v(any): Value to validate.
Return:
isBoolean(boolean): Whether the check succeeds.
Example:
is.boolean(true)function(v) ​
Returns true when v is a function.
Parameters:
v(any): Value to validate.
Return:
isFunction(boolean): Whether the check succeeds.
Example:
is.Function(function() end)nil(v) ​
Returns true when v is nil.
Parameters:
v(any): Value to validate.
Return:
isNil(boolean): Whether the check succeeds.
Example:
is.Nil(nil)number(v) ​
Returns true when v is a number.
Parameters:
v(any): Value to validate.
Return:
isNumber(boolean): Whether the check succeeds.
Example:
is.number(3.14)string(v) ​
Returns true when v is a string.
Parameters:
v(any): Value to validate.
Return:
isString(boolean): Whether the check succeeds.
Example:
is.string("hello")table(v) ​
Returns true when v is a table.
Parameters:
v(any): Value to validate.
Return:
isTable(boolean): Whether the check succeeds.
Example:
is.table({})thread(v) ​
Returns true when v is a thread.
Parameters:
v(any): Value to validate.
Return:
isThread(boolean): Whether the check succeeds.
Example:
is.thread(coroutine.create(function() end))userdata(v) ​
Returns true when v is userdata.
Parameters:
v(any): Value to validate.
Return:
isUserdata(boolean): Whether the check succeeds.
Example:
is.userdata(io.stdout)Value Checks ​
Truthiness, exact-value, and callable checks.
false(v) ​
Returns true when v is exactly false.
Parameters:
v(any): Value to validate.
Return:
isFalse(boolean): Whether the check succeeds.
Example:
is.False(false)true(v) ​
Returns true when v is exactly true.
Parameters:
v(any): Value to validate.
Return:
isTrue(boolean): Whether the check succeeds.
Example:
is.True(true)falsy(v) ​
Returns true when v is falsy.
Parameters:
v(any): Value to validate.
Return:
isFalsy(boolean): Whether the check succeeds.
Example:
is.falsy(false)callable(v) ​
Returns true when v is callable.
Parameters:
v(any): Value to validate.
Return:
isCallable(boolean): Whether the check succeeds.
Example:
is.callable(function() end)integer(v) ​
Returns true when v is an integer.
Parameters:
v(any): Value to validate.
Return:
isInteger(boolean): Whether the check succeeds.
Example:
is.integer(42)truthy(v) ​
Returns true when v is truthy.
Parameters:
v(any): Value to validate.
Return:
isTruthy(boolean): Whether the check succeeds.
Example:
is.truthy("non-empty")Path Checks ​
Filesystem path type checks.
IMPORTANT
Path checks require LuaFileSystem (lfs) and raise an error if it is not installed.
path(v) ​
Returns true when v is a valid filesystem path.
Parameters:
v(any): Value to validate.
Return:
isPath(boolean): Whether the check succeeds.
Example:
is.path("README.md")Returns `true` for broken symlinks.
block(v) ​
Returns true when v is a block device path.
Parameters:
v(any): Value to validate.
Return:
isBlock(boolean): Whether the check succeeds.
Example:
is.block("/dev/sda")char(v) ​
Returns true when v is a character device path.
Parameters:
v(any): Value to validate.
Return:
isChar(boolean): Whether the check succeeds.
Example:
is.char("/dev/null")device(v) ​
Returns true when v is a block or character device path.
Parameters:
v(any): Value to validate.
Return:
isDevice(boolean): Whether the check succeeds.
Example:
is.device("/dev/null")dir(v) ​
Returns true when v is a directory path.
Parameters:
v(any): Value to validate.
Return:
isDir(boolean): Whether the check succeeds.
Example:
is.dir("/tmp")fifo(v) ​
Returns true when v is a FIFO path.
Parameters:
v(any): Value to validate.
Return:
isFifo(boolean): Whether the check succeeds.
Example:
is.fifo("/path/to/fifo")file(v) ​
Returns true when v is a file path.
Parameters:
v(any): Value to validate.
Return:
isFile(boolean): Whether the check succeeds.
Example:
is.file("README.md")link(v) ​
Returns true when v is a symlink path.
Parameters:
v(any): Value to validate.
Return:
isLink(boolean): Whether the check succeeds.
Example:
is.link("/path/to/link")socket(v) ​
Returns true when v is a socket path.
Parameters:
v(any): Value to validate.
Return:
isSocket(boolean): Whether the check succeeds.
Example:
is.socket("/path/to/socket")