All documentation

Function Reference

Complete reference of all built-in Trill functions — string, number, list, date, and utility functions.

String Functions

upper(text) → string

Convert all characters to uppercase.

upper("hello")    // "HELLO"

lower(text) → string

Convert all characters to lowercase.

lower("HELLO")    // "hello"

trim(text) → string

Remove leading and trailing whitespace.

trim("  hello  ")    // "hello"

trim_start(text) → string

Remove leading whitespace only.

trim_start("  hello  ")    // "hello  "

trim_end(text) → string

Remove trailing whitespace only.

trim_end("  hello  ")    // "  hello"

len(value) / length(value) → number

Return the length of a string or number of elements in a list.

len("hello")      // 5
len([1, 2, 3])    // 3

repeat(text, count) → string

Repeat a string count times.

repeat("ha", 3)    // "hahaha"

replace(text, from, to) → string

Replace all occurrences of from with to.

replace("hi there", "hi", "hello")    // "hello there"

slice(text, start, end) → string

Extract characters from index start (inclusive) to end (exclusive). Supports negative indices .

slice("hello", 1, 4)    // "ell"
slice("hello", -3, -1)  // "ll"

substr(text, start, length) → string

Extract length characters starting at start.

substr("hello", 1, 3)    // "ell"

split(text, delimiter) → list

Split a string into a list of substrings.

split("a,b,c", ",")    // ["a", "b", "c"]

contains(text, substring) → boolean

Check if text contains substring.

contains("hello world", "world")    // true

starts_with(text, prefix) → boolean

Check if text starts with prefix.

starts_with("hello", "he")    // true

ends_with(text, suffix) → boolean

Check if text ends with suffix.

ends_with("hello", "lo")    // true

reverse(value) → string or list

Reverse a string or list in place.

reverse("hello")           // "olleh"
reverse([1, 2, 3])         // [3, 2, 1]

pad_start(text, target_len, pad_char?) → string

Left-pad the string until it reaches target_len. Pads with pad_char (space by default).

pad_start("42", 5, "0")    // "00042"
pad_start("hi", 5)         // "   hi"

pad_end(text, target_len, pad_char?) → string

Right-pad the string until it reaches target_len.

pad_end("42", 5, "0")    // "42000"

concat(a, b, ...) → string

Concatenate all arguments as strings.

concat("hello", " ", "world")    // "hello world"

title(text) → string

Convert to title case — uppercase the first letter after any whitespace, -, or _.

title("hello world")    // "Hello World"

join(list, separator?) / join_list(list, separator?) → string

Join list elements into a string with optional separator.

join(["a", "b", "c"], ", ")    // "a, b, c"
join(["a", "b", "c"])          // "abc"

Number Functions

to_num(text) / number(text) → number

Parse a string into a number.

to_num("42")      // 42
to_num("3.14")    // 3.14

to_str(value) / string(value) → string

Convert any value to its string representation.

to_str(42)        // "42"
to_str(true)      // "true"
to_str(nil)       // ""

floor(n) → number

Round down to the nearest integer.

floor(3.7)    // 3
floor(-1.3)   // -2

ceil(n) / ceiling(n) → number

Round up to the nearest integer.

ceil(3.2)     // 4
ceil(-1.3)    // -1

round(n) → number

Round to the nearest integer.

round(3.7)    // 4
round(3.2)    // 3

abs(n) → number

Absolute value.

abs(-5)    // 5

min(a, b, ...) → number

Return the minimum of two or more values.

min(3, 7, 1, 9)    // 1

max(a, b, ...) → number

Return the maximum of two or more values.

max(3, 7, 1, 9)    // 9

clamp(value, lo, hi) → number

Clamp a value between lo and hi.

clamp(15, 0, 10)    // 10
clamp(-5, 0, 10)    // 0
clamp(7, 0, 10)     // 7

rand() → number

Random float between 0 and 1.

rand()    // e.g., 0.472839

rand(lo, hi) → number

Random integer between lo and hi (inclusive).

rand(1, 100)    // e.g., 73

List Functions

list(a, b, ...) → list

Create a list from individual arguments.

list(1, 2, 3)    // [1, 2, 3]

len(value) / length(value) → number

Return the number of elements in a list (or length of a string).

len([10, 20, 30])    // 3

first(list) / first(string) → any

Return the first element of a list or character of a string.

first([10, 20, 30])    // 10
first("hello")         // "h"

last(list) / last(string) → any

Return the last element of a list or character of a string.

last([10, 20, 30])    // 30
last("hello")         // "o"

reverse(list) / reverse(string) → list or string

Reverse the order of a list or characters of a string.

reverse([1, 2, 3])    // [3, 2, 1]

sort(list) → list

Sort a list by the string representation of its elements.

sort([3, 1, 2])    // [1, 2, 3]

choice(list) → any

Pick a random element from the list.

choice(["rock", "paper", "scissors"])    // e.g., "paper"

map(list, builtin_name) → list

Transform each element of a list by calling a built-in function on each item. The function is referenced by name as a string.

map(["hello", "world"], "upper")    // ["HELLO", "WORLD"]

filter(list, condition_name) → list

Keep only elements where a built-in condition function returns true. The function is referenced by name as a string.

filter([1, 2, 3, 4], "is_even")    // calls is_even on each

join(list, separator?) / join_list(list, separator?) → string

Join list elements into a string with an optional separator.

join(["a", "b", "c"], ", ")    // "a, b, c"

Date / Time Functions

now(format?) → string

Return the current date and time. Uses strftime format — defaults to %Y-%m-%d %H:%M:%S.

now()                       // "2026-05-13 14:30:00"
now("%Y-%m-%d")             // "2026-05-13"
now("%B %d, %Y at %I:%M %p")  // "May 13, 2026 at 02:30 PM"

today(format?) → string

Return the current date. Defaults to %Y-%m-%d.

today()                    // "2026-05-13"
today("%A, %B %d, %Y")    // "Tuesday, May 13, 2026"

date_add(date_string, days) → string

Add or subtract days from a date string.

date_add("2026-05-13", 7)    // "2026-05-20"
date_add("2026-05-13", -3)   // "2026-05-10"

date_format(date_string, format) → string

Reformat a date string using a strftime format.

date_format("2026-05-13", "%A")    // "Tuesday"

strftime Format Specifiers

SpecifierMeaningExample
%Y4-digit year 2026
%y2-digit year26
%mZero-padded month05
%BFull month nameMay
%bAbbreviated month name May
%dZero-padded day of month13
%AFull weekday nameTuesday
%aAbbreviated weekday nameTue
%H24-hour, zero-padded14
%I12-hour, zero-padded 02
%MMinutes, zero-padded30
%SSeconds, zero-padded00
%pAM or PM PM

Utility Functions

if_then_else(condition, then_value, else_value) → any

Ternary conditional — returns then_value if the condition is truthy, otherwise else_value.

if_then_else(5 > 3, "yes", "no")    // "yes"

This is equivalent to the if then else expression but available as a callable function.


Template Variables

These built-in variables are always available in trigger replacements:

VariableDescriptionExample
{{date}}Current date2026-05-13
{{time}}Current time14:30:00
{{datetime}}Date and time2026-05-13 14:30:00
{{year}}Current year2026
{{month}}Current month (zero-padded)05
{{day}}Current day (zero-padded)13
{{hour}}Current hour14
{{minute}}Current minute30
{{second}}Current second00
{{weekday}}Weekday nameWednesday
{{shortdate}}Short date format05/13/2026

Trigger Arguments

When a trigger has argument mode enabled, these variables are available:

VariableDescriptionExample
argsList of all argumentsargs[0], args[-1]
_arg_0, _arg_1, ...Individual arguments_arg_0
_args_lenNumber of arguments3

Map and Filter Notes

map(list, name) and filter(list, name) accept a built-in function name as a string, not a lambda expression. The named function is called once per element with the current item.

For example, to convert all strings in a list to uppercase:

map(["hello", "world"], "upper")
// → ["HELLO", "WORLD"]

To check if a condition holds for any element, you'd need a built-in that returns a boolean. Custom conditions as lambdas are not yet supported.