Skip to main content

Built-in Functions

The expression language includes a large set of built-in functions organized by category.

String Functions

FunctionSignatureDescription
lengthlength(str)Returns the length of a string (also works on arrays)
containscontains(str, substring)Returns true if str contains substring
startsWithstartsWith(str, prefix)Returns true if str starts with prefix
endsWithendsWith(str, suffix)Returns true if str ends with suffix
toLowerCasetoLowerCase(str)Converts to lowercase
toUpperCasetoUpperCase(str)Converts to uppercase
substringsubstring(str, start, end)Extracts characters between start and end indices
trimtrim(str)Removes leading and trailing whitespace
trimStarttrimStart(str)Removes leading whitespace
trimEndtrimEnd(str)Removes trailing whitespace
replacereplace(str, search, replacement)Replaces all occurrences of search with replacement
splitsplit(str, separator)Splits a string into an array by separator
indexOfindexOf(str, search)Returns the index of search in str, or -1 if not found
lastIndexOflastIndexOf(str, search)Returns the last index of search in str, or -1 if not found
capitalizecapitalize(str, allWords?)Capitalizes the first letter and lowercases the rest. Pass true to capitalize every word
padLeftpadLeft(value, len, pad?)Pads the start of the string to len with pad (default: space)
padRightpadRight(value, len, pad?)Pads the end of the string to len with pad (default: space)
repeatrepeat(str, n)Repeats a string n times. Returns empty string for invalid n.
charAtcharAt(str, index)Returns the character at index, or empty string if out of bounds
includesincludes(strOrArray, search)Returns true if the string or array includes search
concatconcat(...values)Concatenates all arguments into a string. Null/undefined values become empty strings.
toUpperCase("hello")              // "HELLO"
contains("foobar", "bar") // true
substring("hello world", 0, 5) // "hello"
length("test") // 4
trim(" hello ") // "hello"
trimStart(" hello ") // "hello "
trimEnd(" hello ") // " hello"
replace("foo bar foo", "foo", "baz") // "baz bar baz"
split("a,b,c", ",") // ["a", "b", "c"]
indexOf("hello world", "world") // 6
lastIndexOf("abcabc", "c") // 5
capitalize("hello world") // "Hello world"
capitalize("hello world", true) // "Hello World"
padLeft("42", 5, "0") // "00042"
padRight("hi", 5, ".") // "hi..."
repeat("ab", 3) // "ababab"
charAt("hello", 1) // "e"
includes("hello", "ell") // true
includes([1, 2, 3], 2) // true
concat("a", null, "b", 42) // "ab42"

Math Functions

FunctionSignatureDescription
minmin(a, b, ...)Returns the smallest of the given numbers (variadic)
maxmax(a, b, ...)Returns the largest of the given numbers (variadic)
roundround(num, decimals?)Rounds to decimals decimal places (default: 0)
floorfloor(num)Rounds down
ceilceil(num)Rounds up
absabs(num)Returns the absolute value
powpow(base, exp)Returns base raised to the power of exp
sqrtsqrt(num)Returns the square root
loglog(num)Returns the natural logarithm (base e)
log10log10(num)Returns the base-10 logarithm
log2log2(num)Returns the base-2 logarithm
signsign(num)Returns -1, 0, or 1 indicating the sign
trunctrunc(num)Truncates the decimal part (toward zero)
modmod(a, b)Returns the remainder of a / b
clampclamp(value, min, max)Constrains value to the range [min, max]
lerplerp(a, b, t)Linear interpolation between a and b by factor t (0..1)
pipi()Returns the constant Pi (~3.14159)
ee()Returns Euler's number (~2.71828)
min(3, 7)        // 3
min(5, 2, 8, 1) // 1
max(3, 7) // 7
round(3.14, 1) // 3.1
floor(3.9) // 3
ceil(3.1) // 4
abs(-5) // 5
pow(2, 10) // 1024
sqrt(144) // 12
log(1) // 0
log10(1000) // 3
log2(8) // 3
sign(-42) // -1
sign(0) // 0
trunc(4.9) // 4
trunc(-4.9) // -4
mod(10, 3) // 1
clamp(150, 0, 100) // 100
clamp(-5, 0, 100) // 0
lerp(0, 10, 0.5) // 5
pi() // 3.14159...
e() // 2.71828...

Trigonometric Functions

FunctionSignatureDescription
sinsin(rad)Returns the sine of a value in radians
coscos(rad)Returns the cosine of a value in radians
tantan(rad)Returns the tangent of a value in radians
asinasin(num)Returns the arc sine (in radians) of a number
acosacos(num)Returns the arc cosine (in radians) of a number
atanatan(num)Returns the arc tangent (in radians) of a number
atan2atan2(y, x)Returns the angle (in radians) from the X axis to the point (x, y)
sin(0)           // 0
cos(0) // 1
tan(0) // 0
asin(1) // 1.5707... (pi/2)
acos(1) // 0
atan(1) // 0.7853... (pi/4)
atan2(1, 1) // 0.7853... (pi/4)

Array Functions

FunctionSignatureDescription
lengthlength(array)Returns the number of elements
sumsum(array)Sums all numeric elements
avgavg(array)Returns the average of numeric elements
countcount(array)Returns the number of elements (alias for length)
arrayContainsarrayContains(array, value)Returns true if the array includes value
firstfirst(array)Returns the first element, or null if empty
lastlast(array)Returns the last element, or null if empty
joinjoin(array, separator)Joins elements into a string
sortsort(array)Returns a sorted copy
reversereverse(array)Returns a reversed copy
sliceslice(array, start, end?)Returns a shallow copy from start to end (exclusive)
uniqueunique(array)Returns a new array with duplicates removed
compactcompact(array)Removes null, undefined, and empty string values
flatflat(array, depth?)Flattens nested arrays by depth levels (default: 1)
rangerange(start, end, step?)Generates a number sequence from start to end (exclusive)
chunkchunk(array, size)Splits an array into chunks of size
zipzip(arr1, arr2)Pairs elements from two arrays
sum([10, 20, 30])                // 60
avg([10, 20, 30]) // 20
count([1, 2, 3, 4]) // 4
first([10, 20, 30]) // 10
last([10, 20, 30]) // 30
arrayContains([1, 2, 3], 2) // true
join(["a", "b", "c"], ", ") // "a, b, c"
sort([3, 1, 2]) // [1, 2, 3]
reverse([1, 2, 3]) // [3, 2, 1]
slice([1, 2, 3, 4, 5], 1, 3) // [2, 3]
unique([1, 2, 2, 3, 3, 3]) // [1, 2, 3]
compact([1, null, 2, "", 3]) // [1, 2, 3]
flat([[1, 2], [3, 4]]) // [1, 2, 3, 4]
flat([1, [2, [3, [4]]]], 2) // [1, 2, 3, [4]]
range(0, 5) // [0, 1, 2, 3, 4]
range(0, 10, 2) // [0, 2, 4, 6, 8]
range(5, 0) // [5, 4, 3, 2, 1]
chunk([1, 2, 3, 4, 5], 2) // [[1, 2], [3, 4], [5]]
zip([1, 2, 3], ["a", "b", "c"]) // [[1, "a"], [2, "b"], [3, "c"]]

Statistical Functions

FunctionSignatureDescription
medianmedian(array)Returns the middle value of a numeric array
stddevstddev(array)Returns the standard deviation (population)
variancevariance(array)Returns the variance (population)
percentilepercentile(array, p)Returns the value at the pth percentile (0-100)
median([3, 1, 2])                // 2
median([1, 2, 3, 4]) // 2.5
stddev([2, 4, 4, 4, 5, 5, 7, 9]) // 2.0
variance([2, 4, 4, 4, 5, 5, 7, 9]) // 4.0
percentile([1, 2, 3, 4, 5], 50) // 3
percentile([1, 2, 3, 4, 5], 90) // 4.6

Higher-Order Array Functions

These functions accept a callback. When using arrow function syntax, enable enableArrowFunctions.

Iteration

FunctionSignatureDescription
mapmap(array, fn)Transforms each element
filterfilter(array, fn)Keeps elements where fn returns true
findfind(array, fn)Returns the first element where fn returns true
findIndexfindIndex(array, fn)Returns the index of the first element where fn returns true, or -1
reducereduce(array, fn, initial?)Reduces the array to a single value
everyevery(array, fn)Returns true if fn returns true for all elements
somesome(array, fn)Returns true if fn returns true for at least one element
map(numbers, x => x * 2)                    // [2, 4, 6, 8, 10]
filter(numbers, x => x % 2 == 0) // [2, 4]
find(users, u => u.name == "Alice") // {name: "Alice", ...}
findIndex([10, 20, 30], x => x > 15) // 1
reduce(numbers, (acc, x) => acc + x, 0) // 15
every([2, 4, 6], x => x % 2 == 0) // true
some([1, 2, 3], x => x > 2) // true

Sorting and Grouping

FunctionSignatureDescription
sortBysortBy(array, fn)Returns a sorted copy, ordered by fn return values
groupBygroupBy(array, fn)Groups elements into an object keyed by fn return values
distinctBydistinctBy(array, fn)Returns unique elements, using fn to determine equality
sortBy(users, u => u.age)
// [{name: "Bob", age: 17}, {name: "Alice", age: 25}, {name: "Carol", age: 30}]

groupBy(items, x => x.category)
// { "fruit": [...], "vegetable": [...] }

distinctBy(users, u => u.department)
// one user per department

Aggregation

FunctionSignatureDescription
minByminBy(array, fn)Returns the element with the minimum fn return value
maxBymaxBy(array, fn)Returns the element with the maximum fn return value
sumBysumBy(array, fn)Sums the fn return values across all elements
countBycountBy(array, fn)Counts elements where fn returns a truthy value
minBy(products, p => p.price)                // cheapest product
maxBy(products, p => p.price) // most expensive product
sumBy(orders, o => o.total) // total revenue
countBy(users, u => u.active) // number of active users

See Arrow Functions for details on lambda syntax.

Object Functions

FunctionSignatureDescription
keyskeys(obj)Returns an array of property names
valuesvalues(obj)Returns an array of property values
entriesentries(obj)Returns an array of [key, value] pairs
hasKeyhasKey(obj, key)Returns true if the object has the specified own property
mergemerge(obj1, obj2)Shallow merges two objects (obj2 overrides obj1)
pickpick(obj, ...keys)Returns a new object with only the specified keys
omitomit(obj, ...keys)Returns a new object without the specified keys
fromEntriesfromEntries(entries)Creates an object from an array of [key, value] pairs
keys(user)                       // ["name", "age"]
values(user) // ["Alice", 25]
entries(user) // [["name", "Alice"], ["age", 25]]
hasKey(user, "name") // true
hasKey(user, "email") // false
merge({a: 1}, {b: 2}) // {a: 1, b: 2}
merge({a: 1}, {a: 2}) // {a: 2}
pick(user, "name", "age") // {name: "Alice", age: 25}
omit(user, "password") // user without password field
fromEntries([["a", 1], ["b", 2]]) // {a: 1, b: 2}

Type Checking Functions

FunctionSignatureDescription
typetype(value)Returns the type as a string: "number", "string", "boolean", "array", "object", "date", "null"
isNullisNull(value)Returns true if the value is null
isUndefinedisUndefined(value)Returns true if the value is undefined
isDefinedisDefined(value)Returns true if the value is not null and not undefined
isNumberisNumber(value)Returns true if the value is a number
isStringisString(value)Returns true if the value is a string
isBooleanisBoolean(value)Returns true if the value is a boolean
isObjectisObject(value)Returns true if the value is a plain object (not array, not null, not Date)
isArrayisArray(value)Returns true if the value is an array
isDateisDate(value)Returns true if the value is a valid Date instance
isEmptyisEmpty(value)Returns true if the value is null, undefined, or an empty string ""
type(42)           // "number"
type("hello") // "string"
type([1, 2]) // "array"
type(null) // "null"
isDefined(user) // true if user is in the context
isArray(items) // true if items is an array

Conversion Functions

FunctionSignatureDescription
toStringtoString(value)Converts a value to its string representation. Returns "" for null/undefined.
toNumbertoNumber(value)Parses a value as a number. Returns null for invalid input.
toBooleantoBoolean(value)Converts a value to boolean using JavaScript truthiness.
toIntegertoInteger(value)Converts to an integer (truncates decimals). Returns null for invalid input.
toDatetoDate(value)Converts a Date, number (timestamp), or string to a Date. Returns null on invalid input.
toFixedtoFixed(num, digits)Formats a number to digits decimal places. Returns a string.
parseIntparseInt(str, radix?)Parses an integer from a string with optional radix (default: 10). Returns null on invalid input.
parseFloatparseFloat(str)Parses a floating-point number from a string. Returns null on invalid input.
toString(42)         // "42"
toString(true) // "true"
toString(null) // ""
toNumber("42") // 42
toNumber("3.14") // 3.14
toNumber("abc") // null
toBoolean(1) // true
toBoolean(0) // false
toBoolean("") // false
toInteger(3.9) // 3
toInteger(-3.9) // -3
toDate("2024-01-15") // Date object
toFixed(3.14159, 2) // "3.14"
parseInt("ff", 16) // 255
parseInt("42") // 42
parseFloat("3.14") // 3.14

Utility Functions

FunctionSignatureDescription
coalescecoalesce(a, b, ...)Returns the first argument that is not null or undefined
ifElseifElse(cond, then, else)Returns then if cond is truthy, otherwise else
defaultTodefaultTo(value, fallback)Returns fallback if value is null, undefined, or NaN
jsonStringifyjsonStringify(value)Serializes a value to a JSON string
jsonParsejsonParse(str)Parses a JSON string into a value. Returns null on invalid input.
coalesce(null, null, 42)        // 42
coalesce(user.name, "Guest") // user.name if defined, otherwise "Guest"
ifElse(score > 90, "A", "B") // "A" if score > 90
defaultTo(value, 0) // value, or 0 if null/undefined/NaN
jsonStringify({a: 1}) // '{"a":1}'
jsonParse('{"a":1}') // {a: 1}

Random Functions

FunctionSignatureDescription
randomrandom()Returns a random floating-point number between 0 (inclusive) and 1 (exclusive)
randomIntrandomInt(min, max)Returns a random integer between min and max (inclusive)
random()           // 0.7392... (varies)
randomInt(1, 10) // 7 (varies, always 1-10)
randomInt(0, 1) // 0 or 1

Regex Functions

FunctionSignatureDescription
regexTestregexTest(str, pattern)Returns true if pattern matches anywhere in str
regexMatchregexMatch(str, pattern)Returns the first match of pattern in str, or null
regexReplaceregexReplace(str, pattern, replacement)Replaces all matches of pattern with replacement

Patterns are standard regex strings. Invalid patterns return false/null instead of throwing.

regexTest("hello123", "\\d+")                     // true
regexTest("hello", "\\d+") // false
regexMatch("order-42-confirmed", "\\d+") // "42"
regexReplace("hello 123 world 456", "\\d+", "NUM") // "hello NUM world NUM"

Date Functions

Date objects can flow through the evaluation context. These functions create, inspect, format, and perform arithmetic on dates. All component functions use local time. Months are 1-based (1 = January, 12 = December).

Input coercion: most date functions accept a Date, a number (timestamp in ms), or a string (ISO/date format). Invalid input returns null.

Creation

FunctionSignatureDescription
nownow()Returns the current date/time
datedate(y, m, d, h?, min?, s?, ms?)Creates a date from components. Month is 1-12. Returns null on invalid input.
parseDateparseDate(str)Parses an ISO/date string. Returns null on invalid input.
toDatetoDate(value)Converts a Date, number, or string to a Date. Returns null on invalid input.
now()                           // current Date
date(2024, 3, 15) // March 15, 2024
date(2024, 3, 15, 10, 30, 0) // March 15, 2024 10:30:00
parseDate("2024-03-15") // March 15, 2024
toDate(1710500000000) // Date from timestamp

Component Extraction

FunctionSignatureDescription
yearyear(date)Full year (e.g. 2024)
monthmonth(date)Month 1-12
dayday(date)Day of month 1-31
hourhour(date)Hour 0-23
minuteminute(date)Minute 0-59
secondsecond(date)Second 0-59
dayOfWeekdayOfWeek(date)Day of week: 0 = Sunday, 6 = Saturday
timestamptimestamp(date)Milliseconds since Unix epoch
year("2024-03-15T00:00:00")    // 2024
month("2024-03-15T00:00:00") // 3
day("2024-03-15T00:00:00") // 15
dayOfWeek(date(2024, 3, 15)) // 5 (Friday)
timestamp(now()) // 1710500000000 (varies)

Formatting

FunctionSignatureDescription
formatDateformatDate(date, pattern?)Formats a date. Default pattern: yyyy-MM-dd. Tokens: yyyy, yy, MM, dd, HH, mm, ss, SSS.
toISOStringtoISOString(date)Returns an ISO 8601 string (UTC)
formatDate(date(2024, 3, 15))                        // "2024-03-15"
formatDate(date(2024, 3, 15, 10, 30), "HH:mm dd/MM") // "10:30 15/03"
toISOString(date(2024, 3, 15)) // "2024-03-15T00:00:00.000Z" (UTC)

Arithmetic

FunctionSignatureDescription
dateAdddateAdd(date, amount, unit)Adds an amount to a date. Negative values subtract. Clamps month/year overflow (Jan 31 + 1 month = Feb 28/29).
dateDiffdateDiff(d1, d2, unit)Difference between two dates. Positive if d1 > d2. Truncates partial units. Calendar-aware for months and years.

Valid units: years, months, weeks, days, hours, minutes, seconds, milliseconds (singular forms also accepted).

dateAdd(date(2024, 1, 31), 1, "months")  // Feb 29, 2024 (clamped, leap year)
dateAdd(date(2024, 3, 15), -5, "days") // March 10, 2024
dateAdd(date(2024, 3, 15), 2, "weeks") // March 29, 2024
dateDiff(date(2024, 3, 15), date(2024, 3, 10), "days") // 5
dateDiff(date(2024, 3, 10), date(2024, 3, 15), "days") // -5

Utilities

FunctionSignatureDescription
startOfDaystartOfDay(date)Truncates a date to midnight (00:00:00.000)
endOfDayendOfDay(date)Sets a date to end of day (23:59:59.999)
startOfMonthstartOfMonth(date)First day of month at midnight
endOfMonthendOfMonth(date)Last day of month at 23:59:59.999
dateBetweendateBetween(date, start, end)Returns true if date is between start and end (inclusive)
startOfDay(date(2024, 3, 15, 10, 30))    // March 15, 2024 00:00:00.000
endOfDay(date(2024, 3, 15)) // March 15, 2024 23:59:59.999
startOfMonth(date(2024, 3, 15)) // March 1, 2024 00:00:00.000
endOfMonth(date(2024, 3, 15)) // March 31, 2024 23:59:59.999
dateBetween(date(2024, 3, 15), date(2024, 3, 1), date(2024, 3, 31)) // true