Helper Functions
Blokkio adds these functions to every expression, next to standard JavaScript:
| Helper | Signature | Returns |
|---|---|---|
$dt | $dt(value, zone?) | DateTime |
$jmespath | $jmespath(obj, expression) | any |
$if | $if(condition, whenTrue, whenFalse?) | any |
$ifEmpty | $ifEmpty(value, fallback) | any |
$min | $min(...values) or $min(list) | number or null |
$max | $max(...values) or $max(list) | number or null |
$sum | $sum(list, key?) | number |
$uniq | $uniq(list, key?) | array |
$groupBy | $groupBy(list, key) | object of arrays |
The examples below use this output of a node called Orders:
{
"items": [
{ "id": 1, "status": "paid", "total": 120, "customer": { "email": "ana@example.com", "country": "DE" } },
{ "id": 2, "status": "pending", "total": 35, "customer": { "email": "ben@example.com", "country": "FR" } },
{ "id": 3, "status": "paid", "total": 80, "customer": { "email": "ana@example.com", "country": "DE" } }
]
}
$dt
$dt(value: string | number | Date | DateTime, zone?: string): DateTime
Turns a value into a DateTime, the same type as $now and $today:
- an ISO 8601 string, such as
'2026-11-11T09:30:00Z'or'2026-11-11'. Strings without an offset are read as UTC. - a number of milliseconds since 1970 (multiply Unix seconds by 1000).
- a JavaScript
Dateor another DateTime.
zone is an IANA time zone such as 'Europe/Berlin'. The DateTime then shows the same instant in that zone.
Without it, the zone is UTC. A value that can't be read fails with
TypeError: Cannot convert '…' to a DateTime.
{{ $dt($trigger.body.createdAt).plus({ hours: 1 }).toISO() }}
{{ $dt(1762853400000).toISODate() }}
{{ $dt($trigger.body.timestamp * 1000).toFormat('yyyy-LL-dd HH:mm') }}
{{ $dt($trigger.scheduledAt, 'America/New_York').toFormat('cccc, HH:mm') }}
DateTime methods
DateTime values are immutable: methods return a new value.
| Method | Description | Example |
|---|---|---|
plus(duration) / plus(amount, unit) | Add a duration | $now.plus({ days: 1, hours: 2 }), $now.plus(30, 'minutes') |
minus(duration) / minus(amount, unit) | Subtract a duration | $today.minus({ weeks: 1 }) |
set(values) | Change parts (year, month, day, hour, minute, second, millisecond) | $now.set({ hour: 9, minute: 0 }) |
startOf(unit) | Start of the year, quarter, month, week (Monday), day, hour, minute or second | $now.startOf('month') |
endOf(unit) | Last millisecond of the unit | $now.endOf('day') |
setZone(zone) | Same instant in another IANA time zone | $now.setZone('Asia/Tokyo') |
toUTC() | Same instant in UTC | $dt(x, 'Europe/Paris').toUTC() |
diff(other, unit?) | this − other in the unit (default milliseconds). Fractional; wrap in Math.floor for whole units. | $now.diff($dt($trigger.body.createdAt), 'days') |
isBefore(other), isAfter(other) | Compare with a DateTime, string, number or Date | $dt(x.dueDate).isBefore($now) |
equals(other) | Same instant as another DateTime | $dt(a).equals($dt(b)) |
toFormat(format), format(format) | Format with tokens (below) | $now.toFormat('dd.LL.yyyy') |
toISO() | ISO timestamp, e.g. 2026-11-11T09:30:00.000Z | |
toISODate() | 2026-11-11 | |
toISOTime() | 09:30:00.000 | |
toMillis(), toSeconds(), toUnixInteger() | Unix time in milliseconds, seconds (fractional), seconds (whole) |
Units can be singular or plural (day / days), and ms, sec, min, h, d and y also work.
Properties: year, month (1–12), day, hour, minute, second, millisecond, weekday (1 = Monday …
7 = Sunday), ordinal (day of year), daysInMonth, zoneName.
A DateTime inserted into text, or compared with < and >, behaves like its timestamp: text gets the ISO string,
comparisons use the milliseconds.
Format tokens
toFormat uses Luxon-style tokens. Put literal text in single quotes.
| Token | Output | Token | Output |
|---|---|---|---|
yyyy / yy | 2026 / 26 | HH / H | 09 / 9 (24-hour) |
LL or MM / L or M | 03 / 3 (month) | hh / h | 09 / 9 (12-hour) |
LLL or MMM | Mar | a | AM / PM |
LLLL or MMMM | March | mm / m | minutes |
dd / d | 05 / 5 (day) | ss / s | seconds |
EEE or ccc | Thu | SSS | milliseconds |
EEEE or cccc | Thursday | ZZ / ZZZ / Z | +01:00 / +0100 / +1 |
o / ooo | day of year / zero-padded | z | zone name |
X / x | Unix seconds / milliseconds |
{{ $now.toFormat("yyyy-LL-dd'T'HH:mm") }}
{{ $now.setZone('Europe/London').toFormat("EEEE d LLLL 'at' HH:mm") }}
Names are in English.
$jmespath
$jmespath(obj: any, expression: string): any
Queries obj with a JMESPath expression. Handy for picking and reshaping data from
large API responses. Returns null when nothing matches.
{{ $jmespath($nodes['Orders'], 'items[].id') }}
→ [1, 2, 3]
{{ $jmespath($nodes['Orders'], "items[?status=='paid'].customer.email") }}
→ ["ana@example.com", "ana@example.com"]
{{ $jmespath($nodes['Orders'], 'items[?total > `50`] | length(@)') }}
→ 2
{{ $jmespath($nodes['Orders'], 'items[].{ id: id, country: customer.country }') }}
→ [{ "id": 1, "country": "DE" }, …]
Write the JMESPath expression as a JavaScript string. String literals inside it use single quotes
('paid'), so wrap the whole expression in double quotes. Number literals use backticks (`50`).
$if
$if(condition: any, whenTrue: any, whenFalse?: any): any
Returns whenTrue if condition is truthy, else whenFalse, or null when whenFalse is omitted.
{{ $if($vars.vip, 'priority', 'normal') }}
{{ $if($trigger.body.amount > 1000, 'manual review') }}
Both values are evaluated before $if runs. When one branch could fail (for example reading a property of
something that may be missing), use the ? : operator instead, which only evaluates the branch it picks.
$ifEmpty
$ifEmpty(value: any, fallback: any): any
Returns fallback when value is empty, otherwise value. Empty means null, undefined, '', [] or {}.
0 and false are not empty.
{{ $ifEmpty($trigger.body.name, 'Anonymous') }}
{{ $ifEmpty($nodes['Search'].body.results, [{ id: 'placeholder' }]) }}
$min and $max
$min(...values: number[]): number | null
$min(list: number[]): number | null
Smallest ($min) or largest ($max) number. Pass the numbers as arguments or as one array. Numeric strings
count ('12' is 12); null, '' and values that aren't numbers are ignored. Returns null if no numbers are
left.
{{ $max(1, 5, 3) }}
→ 5
{{ $min($nodes['Orders'].items.map(o => o.total)) }}
→ 35
{{ $max([]) }}
→ null
$sum
$sum(list: any[], key?: string | ((item) => number)): number
Adds up a list of numbers, or a property of a list of objects. key is a property path (dots for nested
properties) or a function. Values that aren't numbers are ignored, and an empty list gives 0. $sum(1, 2, 3)
also works.
{{ $sum([10, 20, 12.5]) }}
→ 42.5
{{ $sum($nodes['Orders'].items, 'total') }}
→ 235
{{ $sum($nodes['Orders'].items, o => o.status === 'paid' ? o.total : 0) }}
→ 200
$uniq
$uniq(list: any[], key?: string | ((item) => any)): any[]
Removes duplicates and keeps the first occurrence. Without key, items are compared by value (objects with the
same content count as duplicates). With key, items are compared by that property path or function result.
{{ $uniq([3, 1, 3, 2, 1]) }}
→ [3, 1, 2]
{{ $uniq($nodes['Orders'].items, 'customer.email').length }}
→ 2
{{ $uniq($nodes['Orders'].items.map(o => o.customer.country)) }}
→ ["DE", "FR"]
$groupBy
$groupBy(list: any[], key: string | ((item) => any)): { [key: string]: any[] }
Groups a list into an object whose keys are the key values and whose values are arrays of items. key is a
property path or a function. Keys become strings; items without a value are grouped under 'null'.
{{ $groupBy($nodes['Orders'].items, 'status') }}
→ { "paid": [ {id: 1, …}, {id: 3, …} ], "pending": [ {id: 2, …} ] }
{{ Object.keys($groupBy($nodes['Orders'].items, 'customer.country')) }}
→ ["DE", "FR"]
{{ $groupBy($nodes['Orders'].items, o => o.total >= 100 ? 'large' : 'small').large.length }}
→ 1
Combine helpers for quick summaries, for example revenue per country:
{{ Object.fromEntries(
Object.entries($groupBy($nodes['Orders'].items, 'customer.country'))
.map(([country, orders]) => [country, $sum(orders, 'total')])
) }}
→ { "DE": 200, "FR": 35 }