Skip to Content
DocumentationExpressionsBuilt-in Functions

Built-in Functions

The expression engine provides whitelisted functions for math, dates, and data utilities. Only these functions are available β€” arbitrary JavaScript functions cannot be called.

Math functions

All functions are accessed via the Math object.

FunctionDescriptionExampleResult
Math.abs(n)Absolute value{{Math.abs(-5)}}5
Math.ceil(n)Round up{{Math.ceil(4.2)}}5
Math.floor(n)Round down{{Math.floor(4.8)}}4
Math.round(n)Round to nearest integer{{Math.round(4.5)}}5
Math.max(a, b)Larger of two values{{Math.max(price, minPrice)}}whichever is larger
Math.min(a, b)Smaller of two values{{Math.min(score, 100)}}caps at 100
Math.sqrt(n)Square root{{Math.sqrt(16)}}4
Math.pow(a, b)Power{{Math.pow(2, 3)}}8
Math.trunc(n)Truncate decimal{{Math.trunc(4.9)}}4

Practical examples

// Cap a value between 0 and 100 {{Math.min(Math.max(score, 0), 100)}} // Round a price to avoid floating point issues {{Math.round(price * 100) / 100}} // Calculate distance {{Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2))}}

Date functions

All functions are accessed via the Date object.

FunctionDescriptionExampleResult
Date.now()Current timestamp (ms){{Date.now()}}1708876800000
Date.parse(value)Parse date string to timestamp{{Date.parse(createdAt)}}timestamp in ms
Date.format(value, fmt)Format a date{{Date.format(createdAt, "YYYY-MM-DD")}}"2024-02-25"

Date.format only supports two format strings:

  • "YYYY-MM-DD" β€” returns "2024-02-25"
  • Any other value β€” returns full ISO string "2024-02-25T12:00:00.000Z"

There is no support for custom format patterns like "MM/DD/YYYY" or "HH:mm:ss".

Practical examples

// Format a timestamp to date {{Date.format(updatedAt, "YYYY-MM-DD")}} // Check if a date is in the past {{Date.parse(expiresAt) < Date.now()}}

Utility functions

These are available as top-level functions (no object prefix).

FunctionDescriptionExampleResult
stringify(value)Convert to JSON string{{stringify(address)}}'{"city":"NYC"}'
toString(value)Convert to string{{toString(count)}}"42"
keys(value)Get object keys{{keys(user)}}["name","age"]
values(value)Get object values{{values(user)}}["Alice",25]

stringify(value)

Converts any value to its JSON string representation using JSON.stringify. Useful for serializing nested objects into a flat string.

// Input: { "meta": { "version": 2, "draft": true } } {{stringify(meta)}} β†’ '{"version":2,"draft":true}'

toString(value)

Converts a value to a string. Handles special cases:

  • null / undefined β†’ "" (empty string)
  • Date objects β†’ ISO string
  • Objects β†’ JSON string (same as stringify)
  • Everything else β†’ String(value)
{{toString(42)}} β†’ "42" {{toString(null)}} β†’ "" {{toString(true)}} β†’ "true"

keys(value) and values(value)

Return the keys or values of an object as arrays. Returns an empty array for non-objects.

// Input: { "user": { "name": "Alice", "age": 25, "role": "admin" } } {{keys(user)}} β†’ ["name", "age", "role"] {{values(user)}} β†’ ["Alice", 25, "admin"]

Since single expressions preserve types, {{"{{"}}keys(user){{"}}"}} returns an actual array, not a string. This is useful when the result feeds into another operation.

Last updated on