Skip to content

Latest commit

 

History

History
529 lines (311 loc) · 8.53 KB

File metadata and controls

529 lines (311 loc) · 8.53 KB
description Type predicates for Lua values and filesystem path types.

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({})          --> true

Note

Function names are case-insensitive.

is.table({})  --> true
is.Table({})  --> true
is.tAbLe({})  --> true

is()

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") --> true

Functions

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
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:

  • ok (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:

  • ok (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:

  • ok (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:

  • ok (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:

  • ok (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:

  • ok (boolean): Whether the check succeeds.

Example:

is.table({})

thread(v)

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))

userdata(v)

Returns true when v is userdata.

Parameters:

  • v (any): Value to validate.

Return:

  • ok (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:

  • ok (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:

  • ok (boolean): Whether the check succeeds.

Example:

is.True(true)

falsy(v)

Returns true when v is falsy.

Parameters:

  • v (any): Value to validate.

Return:

  • ok (boolean): Whether the check succeeds.

Example:

is.falsy(false)

callable(v)

Returns true when v is callable.

Parameters:

  • v (any): Value to validate.

Return:

  • ok (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:

  • ok (boolean): Whether the check succeeds.

Example:

is.integer(42)

truthy(v)

Returns true when v is truthy.

Parameters:

  • v (any): Value to validate.

Return:

  • ok (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.

block(v)

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")

char(v)

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")

device(v)

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")

dir(v)

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")

fifo(v)

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")

file(v)

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")

link(v)

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")

socket(v)

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")