Skip to content

Expression Functions Reference

This page lists every function available in SuperPlane expressions. For an introduction to how expressions work, see Expressions.


FunctionDescriptionExample
root()Root payload that started the runroot().data.ref
previous()Immediate upstream node’s payloadprevious().data.status
previous(n)Walk n levels upstreamprevious(2).data.version

FunctionDescriptionExample
trim(str)Remove whitespace from both endstrim(" hello ") == "hello"
trim(str, chars)Remove specific characterstrim("xxhelloxx", "x") == "hello"
trimPrefix(str, prefix)Remove prefix if presenttrimPrefix("HelloWorld", "Hello") == "World"
trimSuffix(str, suffix)Remove suffix if presenttrimSuffix("HelloWorld", "World") == "Hello"
upper(str)Convert to uppercaseupper("hello") == "HELLO"
lower(str)Convert to lowercaselower("HELLO") == "hello"
split(str, delim)Split into arraysplit("a,b,c", ",") == ["a", "b", "c"]
split(str, delim, n)Split with limitsplit("a,b,c", ",", 2) == ["a", "b,c"]
splitAfter(str, delim)Split keeping delimiterssplitAfter("a,b,c", ",") == ["a,", "b,", "c"]
replace(str, old, new)Replace all occurrencesreplace("hello world", "world", "there")
repeat(str, n)Repeat n timesrepeat("ab", 3) == "ababab"
indexOf(str, sub)First occurrence index (-1 if missing)indexOf("apple pie", "pie") == 6
lastIndexOf(str, sub)Last occurrence index (-1 if missing)lastIndexOf("abab", "ab") == 2
hasPrefix(str, prefix)Starts with prefix?hasPrefix("hello", "he") == true
hasSuffix(str, suffix)Ends with suffix?hasSuffix("hello", "lo") == true

FunctionDescriptionExample
max(a, b)Larger of two numbersmax(5, 7) == 7
min(a, b)Smaller of two numbersmin(5, 7) == 5
abs(n)Absolute valueabs(-5) == 5
ceil(n)Round upceil(1.2) == 2.0
floor(n)Round downfloor(1.8) == 1.0
round(n)Round to nearest integerround(1.5) == 2.0

Array functions that accept a predicate use # for the current element. See Closures.

FunctionDescriptionExample
all(arr, pred)True if all elements matchall([1, 2, 3], # > 0) == true
any(arr, pred)True if any element matchesany([1, 2, 3], # > 2) == true
one(arr, pred)True if exactly one matchesone([1, 2, 3], # == 2) == true
none(arr, pred)True if no elements matchnone([1, 2, 3], # > 5) == true
map(arr, pred)Transform each elementmap([1, 2, 3], # * 2) == [2, 4, 6]
filter(arr, pred)Keep matching elementsfilter([1, 2, 3], # > 1) == [2, 3]
find(arr, pred)First matching elementfind([1, 2, 3], # > 1) == 2
findIndex(arr, pred)Index of first matchfindIndex([1, 2, 3], # > 1) == 1
findLast(arr, pred)Last matching elementfindLast([1, 2, 3], # > 1) == 3
findLastIndex(arr, pred)Index of last matchfindLastIndex([1, 2, 3], # > 1) == 2
groupBy(arr, pred)Group elements by keygroupBy(users, #.role)
count(arr, pred)Count matching elementscount([1, 2, 3], # > 1) == 2
reduce(arr, pred, init)Reduce to single value (#acc + #)reduce([1, 2, 3], #acc + #, 0) == 6
sum(arr)Sum of numberssum([1, 2, 3]) == 6
mean(arr)Averagemean([1, 2, 3]) == 2.0
median(arr)Median valuemedian([1, 2, 3]) == 2.0
first(arr)First element (nil if empty)first([1, 2, 3]) == 1
last(arr)Last element (nil if empty)last([1, 2, 3]) == 3
take(arr, n)First n elementstake([1, 2, 3, 4], 2) == [1, 2]
reverse(arr)Reverse orderreverse([1, 2, 3]) == [3, 2, 1]
sort(arr)Sort ascendingsort([3, 1, 2]) == [1, 2, 3]
sort(arr, "desc")Sort descendingsort([1, 2, 3], "desc") == [3, 2, 1]
sortBy(arr, pred)Sort by predicatesortBy(users, #.age, "desc")
concat(arr1, arr2, ...)Concatenate arraysconcat([1, 2], [3, 4]) == [1, 2, 3, 4]
flatten(arr)Flatten nested arraysflatten([[1, 2], [3]]) == [1, 2, 3]
uniq(arr)Remove duplicatesuniq([1, 2, 2, 3]) == [1, 2, 3]
join(arr, delim)Join into stringjoin(["a", "b"], ",") == "a,b"

FunctionDescriptionExample
keys(map)Array of keyskeys({a: 1, b: 2}) == ["a", "b"]
values(map)Array of valuesvalues({a: 1, b: 2}) == [1, 2]
toPairs(map)Map to key-value pairstoPairs({a: 1}) == [["a", 1]]
fromPairs(arr)Key-value pairs to mapfromPairs([["a", 1]]) == {a: 1}

FunctionDescriptionExample
now()Current time (UTC)now().Year()
date(str)Parse a date stringdate("2024-08-14")
date(str, tz)Parse with timezonedate("2024-08-14", "America/New_York")
date(unix)Parse a Unix timestampdate(1700000000)
duration(str)Parse a duration stringduration("1h30m")
timezone(str)Get a timezone by nametimezone("Europe/Zurich")

Duration units: ns, us, ms, s, m, h. Date strings are parsed as RFC 3339 or YYYY-MM-DD. Numeric timestamps are auto-detected as seconds, milliseconds, microseconds, or nanoseconds.

now() and date() return a time value with these chainable methods:

MethodReturnsExample
.Year()Year (e.g. 2024)now().Year()
.Month()Month (1-12)now().Month()
.Day()Day of month (1-31)now().Day()
.Hour()Hour (0-23)now().Hour()
.Minute()Minute (0-59)now().Minute()
.Second()Second (0-59)now().Second()
.Weekday()Day of week (0 = Sunday)now().Weekday()
.YearDay()Day of year (1-366)now().YearDay()
.Unix()Unix timestamp (seconds)now().Unix()
.UnixMilli()Unix timestamp (ms)now().UnixMilli()
.Format(layout)Format using Go layoutnow().Format("2006-01-02")
.Add(dur)Add a durationnow().Add(duration("1h"))
.Sub(time)Duration between two timesnow().Sub(date("2024-01-01"))
.Before(time)True if beforedate("2024-01-01").Before(now())
.After(time)True if afternow().After(date("2024-01-01"))
.In(tz)Convert to timezonenow().In(timezone("US/Eastern"))
.UTC()Convert to UTCdate("...").UTC()
.Round(dur)Round to nearest durationnow().Round(duration("1h"))
.Truncate(dur)Truncate to durationnow().Truncate(duration("24h"))
.IsZero()True if zero valuedate("...").IsZero()
MethodReturnsExample
.Hours()Float hoursduration("90m").Hours() == 1.5
.Minutes()Float minutesduration("1h").Minutes() == 60.0
.Seconds()Float secondsduration("1m30s").Seconds() == 90.0
.Milliseconds()Integer msduration("1s").Milliseconds() == 1000
.Microseconds()Integer usduration("1ms").Microseconds() == 1000
.Nanoseconds()Integer nsduration("1us").Nanoseconds() == 1000

FunctionDescriptionExample
type(v)Type name as stringtype(42) == "int"
int(v)Convert to integerint("123") == 123
float(v)Convert to floatfloat("1.5") == 1.5
string(v)Convert to stringstring(123) == "123"
toJSON(v)Serialize to JSON stringtoJSON({a: 1})
fromJSON(str)Parse JSON stringfromJSON("{\"a\":1}")
toBase64(str)Base64 encodetoBase64("hello")
fromBase64(str)Base64 decodefromBase64("aGVsbG8=") == "hello"
len(v)Length of string, array, or maplen("hello") == 5
get(v, key)Safe index/key access (nil if missing)get([1, 2], 5) == nil

For the Expr language specification, see the Expr documentation.