Unify Applications
Logo
Built-in Utilities

Built-in Utilities

Logo

7 mins READ

Every expression can use a small set of helpers under the utils namespace — no setup required, available in any binding on any page. They cover the everyday jobs of turning raw data into something a user can read: dates, durations, numbers, JSON, and file downloads. Most helpers degrade quietly instead of throwing, so a formatting mistake doesn't crash your page.

built_in_utilities.png
built_in_utilities.png

Helpers at a Glance

HelperWhat it doesQuick example
utils.formatDateFormat a date with a custom date-fns pattern{{ utils.formatDate(order.createdAt, 'dd MMM yyyy') }} → 15 Jan 2024
utils.formatDateByFormatTypeFormat a date with a named preset, including relative forms like "2 hours ago"{{ utils.formatDateByFormatType(order.createdAt, 'Mdy') }} → January 05, 2024
utils.formatTimeTurn a millisecond duration into readable units like 1d 1h 1m{{ utils.formatTime(90061000, 'seconds') }} → 1d 1h 1m 1s
utils.formatNumberFormat a number — locale grouping, compact notation, units{{ utils.formatNumber({ value: 1234567, notation: 'compact' }) }} → 1.2M
utils.parseJsonParse a JSON string safely — never throws{{ utils.parseJson(orders_query.data.objects?.[0]?.payloadJson).total }} → 250
utils.stringifyJsonSerialize a value to JSON safely — never throws{{ utils.stringifyJson(filters.value) }} → {"status":"open"}
utils.downloadFileDownload a file in the current browser tab (side effect — use in actions, not rendered bindings){{ utils.downloadFile(invoice.fileUrl, 'invoice.pdf') }}
utils.dateTime.values.todayDateToday's date as dd-MM-yyyy (snapshot, not a live clock){{ utils.dateTime.values.todayDate }} → 06-07-2026
utils.dateTime.values.startOfTodayTimestampLocal midnight timestamp — use for "today only" filters{{ order.createdAt >= utils.dateTime.values.startOfTodayTimestamp }}
utils.getAuthTokenMobile apps only. Returns the signed-in session's auth token, or empty string.{{ utils.getAuthToken() }}

utils.formatDate

Formats a date or timestamp using a date-fns pattern (https://date-fns.org/docs/format).

utils.formatDate(date, formatStr)

ParameterTypeRequiredDescription
dateDate | string | numberRequiredA Date object, ISO string, or numeric timestamp. A numeric string (e.g. '1704067200000') is treated as an epoch timestamp — see gotchas.
formatStrstringRequiredAny date-fns pattern. Common tokens: dd day, MMM short month, yyyy year, H 24-hour, h 12-hour, mm minutes, a AM/PM.

Examples

{{ utils.formatDate(order.createdAt, 'dd MMM yyyy') }} // → 15 Jan 2024 {{ utils.formatDate(order.createdAt, 'MMM dd, yyyy h:mm a') }} // → Jan 15, 2024 10:30 AM {{ utils.formatDate('not-a-date', 'dd MMM yyyy') }} // → not-a-date (echoes invalid input)

utils.formatDateByFormatType

Formats a date using a named preset instead of a raw pattern — including relative forms like "2 hours ago".

utils.formatDateByFormatType(date, formatType, options)

ParameterTypeRequiredDefaultDescription
dateDate | string | numberRequired—The date to format.
formatTypestringOptionalmdyhmA preset name from the table below, or any raw date-fns pattern. Unknown strings are treated as raw patterns.
optionsobjectOptional—Only used by relative-time presets.

Date Format Presets

Preset

Pattern

Output (example: Jan 05, 2024, 09:07:03)

dmyhms

dd MMM yyyy, H:mm:ss

05 Jan 2024, 9:07:03

dmhms

dd MMM, H:mm:ss

05 Jan, 9:07:03

dmyhma

dd MMM yyyy, H:mm a

05 Jan 2024, 9:07 AM

dmyhm

dd MMM yyyy, H:mm

05 Jan 2024, 9:07

mdyhm (default)

MM/dd/yyyy H:mm

01/05/2024 9:07

mdyhma

MMM dd, yyyy h:mm a

Jan 05, 2024 9:07 AM

mdhma

MMM dd, h:mma

Jan 05, 9:07AM

Mdy

MMMM dd, yyyy

January 05, 2024

dMy

d MMM yyyy

5 Jan 2024

yyyyMMdd

yyyy-MM-dd

2024-01-05

ddMMyyyy

dd-MM-yyyy

05-01-2024

ddMMyyyyhma

dd-MM-yyyy h:mm a

05-01-2024 9:07 AM

ddMMM

dd MMM

05 Jan

dMMM

d MMM

5 Jan

DayMMddyyyy

EEEE, MM-dd-yyyy

Friday, 01-05-2024

hhmm

HH:mm

09:07

hma

h:mm a

9:07 AM

iso

yyyy-MM-dd'T'HH:mm:ssxxx

2024-01-05T09:07:03+05:30

relative-time-ago

Relative with "ago"

2 hours ago

relative-time-to-now

Relative with "about"

about 2 hours

Presets that combine H (24-hour) with a keep the 24-hour number. For an afternoon time such as Mar 20, 2024, 16:05, dmyhma gives 20 Mar 2024, 16:05 PM, while mdyhma (12-hour h) gives Mar 20, 2024 4:05 PM.

utils.formatTime

Turns a duration in milliseconds into readable units. This is elapsed time, not a clock time.

utils.formatTime(ms, precision, notation, maxSignificantUnits)

ParameterTypeDefaultDescription
msnumber—Duration in milliseconds.
precisionstring'milliseconds'Smallest unit to show: 'years', 'months', 'days', 'hours', 'minutes', 'seconds', 'milliseconds'.
notationstring'compact''compact' → 1d 1h; 'comfortable' → 1 day 1 hour.
maxSignificantUnitsnumber7Show at most this many units. Values are clamped to 1–6, so the default of 7 shows up to 6 units.

Examples

{{ utils.formatTime(90061000, 'seconds') }} // → 1d 1h 1m 1s {{ utils.formatTime(90061000, 'seconds', 'comfortable') }} // → 1 day 1 hour 1 minute 1 second {{ utils.formatTime(90061000, 'seconds', 'compact', 2) }} // → 1d 1h

utils.formatNumber

Formats a number with locale grouping, compact notation, or units. Takes a single options object — not a plain number.

utils.formatNumber({ value, locale, notation, compactDisplay, maximumFractionDigits, padDecimalPlaces, unit, unitDisplay })

PropertyTypeRequiredDefaultDescription
valuenumberRequired—The number to format.
localestringOptionalRuntime localee.g. 'en-US', 'de-DE'
notationstringOptional'standard''standard', 'compact', 'scientific', 'engineering', or 'text' (disables grouping).
compactDisplaystringOptional—With compact notation: 'short' (1.2M) or 'long' (1.2 million).
maximumFractionDigitsnumberOptional—Maximum digits after the decimal.
padDecimalPlacesbooleanOptional—Pad decimals with zeros to maximumFractionDigits. Has no effect without maximumFractionDigits.
unitstringOptional—e.g. 'percent', 'kilometer-per-hour', 'megabyte'.
unitDisplaystringOptional—'short', 'narrow', or 'long'.

Examples

{{ utils.formatNumber({ value: 1234567.891, maximumFractionDigits: 2 }) }} // → 1,234,567.89 {{ utils.formatNumber({ value: 1234567, notation: 'compact', compactDisplay: 'short', maximumFractionDigits: 1 }) }} // → 1.2M {{ utils.formatNumber({ value: 5, maximumFractionDigits: 2, padDecimalPlaces: true }) }} // → 5.00 {{ utils.formatNumber({ value: 20, unit: 'percent' }) }} // → 20% {{ utils.formatNumber({ value: 20, unit: 'kilometer-per-hour', unitDisplay: 'long' }) }} // → 20 kilometers per hour

Warning: utils.formatNumber does not support currency formatting. To show monetary values, format the number and add the currency symbol yourself in your expression: {{ '$' + utils.formatNumber({ value: total, maximumFractionDigits: 2 }) }}

utils.parseJson

Parses a JSON string safely. Invalid JSON never throws — you get the fallback value instead.

utils.parseJson(str, fallback, retriever)

ParameterTypeDefaultDescription
strstring—The JSON text to parse.
fallbackany{}Returned on a parse error and when the parsed value is null.
retrieverfunction—A JSON reviver — advanced, usually omitted.

Examples

{{ utils.parseJson(orders_query.data.objects?.[0]?.payloadJson).total }} // → 250 {{ utils.parseJson('oops', []) }} // → [] (fallback) {{ utils.parseJson('null') }} // → {} (null result → fallback)

utils.stringifyJson

Serializes a value to a JSON string. On failure (e.g. circular reference) returns the fallback instead of throwing.

utils.stringifyJson(obj, fallback, space, replacer)

ParameterTypeDefaultDescription
objany—The value to serialize.
fallbackstring—Returned on failure. If absent, failure returns null.
spacenumber0Indentation for pretty-printing.
replacerfunction—JSON replacer function — advanced, usually omitted.

Examples

  • {{ utils.stringifyJson({ orderId: 'ORD-1042', total: 250 }) }} → {"orderId":"ORD-1042","total":250}

  • {{ utils.stringifyJson({ a: 1 }, undefined, 2) }} → the same JSON indented by 2 spaces per level. Pass undefined for fallback to reach space.

  • {{ utils.stringifyJson(circularObject) }} → null (failed, no fallback given)

utils.downloadFile

Starts a file download in the current browser tab. This is a side effect — put it in an action (button's On Click), not in a text/label binding that recomputes on every render.

utils.downloadFile(fileOrUrl, filename)

ParameterTypeDescription
fileOrUrlstring | BlobA file URL/path, or in-memory file content. Platform file URLs are resolved automatically.
filenamestringThe name to save the file as.

Usage — in a button's On Click action

Run Script takes plain JavaScript, not a {{ }} binding, so write the call without braces:

utils.downloadFile(invoice_query.data.fileUrl, 'invoice-2024.pdf');

Don't put it in a text binding.

Gotchas

Gotcha

Details

Helpers rarely throw

Most helpers return a safe fallback instead of throwing. A formatting mistake shows as unformatted output, not an error screen. The relative-time presets are the exception: they throw on an invalid date, which leaves the binding empty.

Numeric string = timestamp in formatDate

A string of digits (e.g. '1704067200000') is treated as an epoch timestamp by formatDate, not as text.

formatNumber takes an object, not a number

Write {{ utils.formatNumber({ value: total }) }} — not {{ utils.formatNumber(total) }}. Passing a plain number renders NaN.

downloadFile is a side effect

A binding re-evaluates on every render. Placing utils.downloadFile in a text/label binding downloads on every re-render. Place it in button actions only.

formatTime = elapsed time, not clock time

Takes a duration in milliseconds, not a time of day. If precision is coarser than the whole span (e.g. hours on a 90-second duration), the result is an empty string — not "0h".

Relative presets and invalid dates

The relative-time-ago and relative-time-to-now presets both accept a Date, a timestamp or an ISO string. Text that cannot be parsed as a date, or an empty string, gives an empty binding or 1 Jan 1970.

dateTime values are snapshots

todayDate and startOfTodayTimestamp are computed when the page context is built — they reflect the time of last rebuild, not a live clock.

getAuthToken is mobile-only

utils.getAuthToken() does not exist on web apps — it is only available in mobile apps.