Methods reference
Every built-in chainable method, grouped by the value type it applies to. A method is matched to the runtime type of the value on its left. Argument defaults are shown in the signatures.
You can add your own with
registerMethod().
String methods
Case and formatting
| Method | Result |
|---|---|
upper() | Uppercase |
lower() | Lowercase |
camel() | camelCase |
snake() | snake_case |
kebab() | kebab-case |
studly() | StudlyCase |
title() | Title Case |
slug(separator = "-") | URL slug |
reverse() | Characters reversed |
Trimming and padding
| Method | Result |
|---|---|
trim(chars = whitespace) | Trim both ends |
ltrim(chars = whitespace) | Trim start |
rtrim(chars = whitespace) | Trim end |
pad(length = 0, pad = " ") | Pad to length |
start(prefix = "") | Ensure it begins with prefix (added once) |
finish(suffix = "") | Ensure it ends with suffix (added once) |
wrap(before = "", after = before) | Wrap with before / after |
Slicing and searching
| Method | Result |
|---|---|
length() / count() | Byte length |
words() | Word count |
limit(limit = 100, end = "...") | Truncate, appending end |
substr(start = 0, length = null) | Substring |
before(search) | Everything before the first search |
after(search) | Everything after the first search |
indexOf(search) | Position of search, or false |
contains(search) | true if search occurs |
startsWith(search) | Boolean |
endsWith(search) | Boolean |
Transforming
| Method | Result |
|---|---|
replace(search, replace) | Replace all occurrences |
repeat(times = 1) | Repeat the string |
concat(append = "") | Append append |
split(delimiter = ",") | Split into an array |
To turn a string into a date, use the date()
function — date(trigger.dueDate) — not a
string method. See Working with
dates.
Array methods
Reading
| Method | Result |
|---|---|
count() / length() | Number of elements |
first() | First value, or null |
last() | Last value, or null |
nth(index = 0) | Element at index, or null |
keys() | The array's keys |
values() | The array's values, re-indexed |
pluck(key) | Column key from a list of records |
Aggregating
| Method | Result |
|---|---|
sum() | Sum of elements |
min() | Smallest element |
max() | Largest element |
avg() | Mean, or null if empty |
contains(needle = null) | true if needle is present |
join(glue = ", ") | Join into a string |
groupBy(key) | Bucket a list of records into { value: [records] } |
Reshaping (all re-index the result)
| Method | Result |
|---|---|
reverse() | Reversed order |
unique() | Duplicates removed |
flatten() | Fully flattened (all levels) |
skip(n = 0) | Drop the first n |
take(n = 0) | Keep the first n |
chunk(n = 1) | Split into groups of n |
diff(other = []) | Elements not in other |
intersect(other = []) | Elements also in other |
diff() / intersect() accept an array or a single scalar as other.
Per-item operations
| Method | Result |
|---|---|
filter(predicate) | Items where predicate is truthy |
map(transform) | Each item replaced by transform |
sort(by = null) | Sorted; by is a per-item sort key |
any(predicate) | true if predicate holds for any item |
every(predicate) / all(predicate) | true if it holds for every item |
These use the current keyword — see List operations.
Number methods
Available on integers and floats.
| Method | Result |
|---|---|
abs() | Absolute value |
ceil() | Round up to an integer |
floor() | Round down to an integer |
round(places = 0) | Round to places decimals |
clamp(min, max) | Constrain to the range [min, max] |
format(decimals = 2, decimalPoint = ".", thousands = ",") | Formatted string |
add(n = 0) | value + n |
sub(n = 0) | value - n |
mul(n = 1) | value * n |
div(n) | value / n — throws on n = 0 |
mod(n) | value % n (float-safe) — throws on n = 0 |
pow(n = 1) | value ** n |
div() and mod() by zero throw a native DivisionByZeroError (the
/ and % operators throw EvaluatorException
instead).
Date methods
Available on the chainable date object produced by the date(), now(),
or today() functions. Every method returns
a new date (dates are immutable).
Arithmetic
addSeconds(n = 1), addMinutes, addHours, addDays, addWeeks,
addMonths, addYears — and the matching subSeconds(n = 1) …
subYears.
Boundaries
startOfDay(), startOfWeek(), startOfMonth(), startOfYear() — and
the matching endOfDay() … endOfYear().
Comparison
| Method | Result |
|---|---|
isBefore(other) | Boolean |
isAfter(other) | Boolean |
isSame(other, unit = "day") | Boolean, compared at unit granularity |
diffInSeconds(other) | Absolute whole-number difference |
diffInMinutes / diffInHours / diffInDays / diffInWeeks / diffInMonths / diffInYears | As above, in that unit |
other may be another date object or a date string (parsed
automatically). diffIn* results are always positive magnitudes.
Output and components
| Method | Result |
|---|---|
format(format = "Y-m-d H:i:s") | Formatted string |
timestamp() | Unix timestamp |
day() / month() / year() | Integer components |
hour() / minute() / second() | Integer components |
dayOfWeek() | Integer (0–6) |
dayName() | e.g. "Monday" |
Any-value methods
Registered for any, so they work on every value regardless of type. A
type-specific method of the same name takes precedence.
| Method | Result |
|---|---|
default(fallback = null) | The value, or fallback if it is null |
in(...candidates) | true if the value equals one of candidates |
Type casts and guards — string(), int(), float(), bool(),
json(), decode(), isset(), empty(), not(), if() — are
functions, not methods. Call them as
isset(trigger.name), not trigger.name.isset().
in() accepts either a list of arguments or a single array:
trigger.status.in("open", "pending")
trigger.status.in(trigger.allowedStatuses)