[Go to site: main page, start]

Skip to content

Utilities ​

Timing, logging, metadata, variables, date helpers and pattern matching.

Timing ​

$sleep(ms) ​

Pause the run for the given number of milliseconds.

js
await $sleep(2000); // wait 2 seconds

$stopwatchStart(name?) ​

Start or resume a named stopwatch and return its current elapsed time in milliseconds. The default name is default.

js
$stopwatchStart('checkout');
await $sleep(500);

$stopwatchCheck(name?) ​

Read a stopwatch without stopping it.

js
const elapsed = $stopwatchCheck('checkout');

Throws when the named stopwatch has not been started.

$stopwatchStop(name?, options?) ​

Stop a stopwatch and return its elapsed time. The elapsed time is retained, so calling $stopwatchStart() again resumes it.

js
const elapsed = $stopwatchStop('checkout');
const finalElapsed = $stopwatchStop('checkout', { reset: true });

Set reset to true to reset the stored elapsed time after reading it.

Values and numbers ​

$if(condition, valueIfTrue, valueIfFalse) ​

Return one of two values. This helper is available in code flows and Code nodes.

js
const status = $if(total > 0, 'ready', 'empty');

$ifEmpty(value, fallback) ​

Return the fallback when value is undefined, null, an empty string, an empty array, or an empty object.

js
const label = $ifEmpty($input.label, 'Untitled');

$max(...numbers) ​

Return the highest supplied number.

js
const highest = $max(12, 38, 7); // 38

$min(...numbers) ​

Return the lowest supplied number.

js
const lowest = $min(12, 38, 7);  // 7

Logging & metadata ​

$log(...messages) ​

Log messages to the run's console output and append them to the output trace.

js
$log('Processing invoice', invoiceId);
$log('Found', items.length, 'items');

$legend(value) ​

Set a short caption for the run. Displayed in the runs list and anywhere the run appears in the UI.

js
$legend('3 invoices processed');
$legend(`${company} - ${period}`);

$meta(key, value) ​

Attach filterable metadata to the run. Accepts a key/value pair or an object for bulk updates. Supports markdown in values.

js
$meta('invoiceCount', 42);
$meta('status', 'processed');

// Bulk update
$meta({ status: 'processed', region: 'EU', total: '€1,234' });

Variables ​

$vars(variableId) ​

Resolve a variable at runtime. Variables are configured in the flow's settings.

js
const email = $vars('variable-id-for-email');
const password = $vars('variable-id-for-password');
const city = $vars('variable-id-for-json.address.city');

Use dotted paths to read nested keys from JSON variables.

For OTP/TOTP variables, a fresh code is computed on every call:

js
const otpCode = $vars('variable-id-for-otp'); // fresh 6-digit TOTP code
await $fillInput('#otp', otpCode);

Throws if the variable ID is not found, with a message listing available variables.

$totp(variableId) ​

Compute a fresh TOTP code from a TOTP variable ID. A literal 4-to-10-digit code is returned unchanged, which allows manual or API input to override a variable reference.

js
const otpCode = $totp($input.otpVariableId);

Pattern matching ​

$matchSequence(items, patterns) ​

Find the first consecutive sequence in an array where each element matches the corresponding regex pattern.

  • With 1 pattern: returns the matching string.
  • With N patterns: returns an array of N consecutive matches.
  • Returns null if no match is found.
js
const lines = ['Total', '€1,234.00', 'Tax', '€234.00'];

const total = $matchSequence(lines, [/^Total$/, /€[\d.,]+/]);
// ['Total', '€1,234.00']

const taxLine = $matchSequence(lines, [/€234/]);
// '€234.00'

Patterns can be RegExp objects or strings. Always pass them as an array, even when using a single pattern.

Date helpers ​

$parseDates(format, ...dateStrings) ​

Parse date strings according to a format pattern. Returns an array of Date objects.

Supported tokens: dd, mm, yyyy, yy.

js
const [start, end] = $parseDates('dd/mm/yyyy', '15/03/2026', '31/12/2026');
const [d] = $parseDates('mm-dd-yy', '03-15-26');

Throws on invalid dates or format mismatches.

$sortDates(format, dates, order?) ​

Sort an array of date strings by chronological order using the same format tokens as $parseDates(). order defaults to 'asc'; pass 'desc' for newest first.

js
const dates = ['31/12/2026', '15/03/2026', '01/01/2026'];

const asc = $sortDates('dd/mm/yyyy', dates);
// ['01/01/2026', '15/03/2026', '31/12/2026']

const desc = $sortDates('dd/mm/yyyy', dates, 'desc');
// ['31/12/2026', '15/03/2026', '01/01/2026']

$currentDate(ts?) ​

Get date components from a timestamp. Defaults to Date.now().

js
const d = $currentDate();
// { day: '18', month: '03', year: 2026 }

const d2 = $currentDate(1711234567890);

Returns: { day: string, month: string, year: number } - day and month are zero-padded.

$currentDateMinusOneMonth(ts?) ​

Same as $currentDate but shifted one month back.

js
const prev = $currentDateMinusOneMonth();
// In March 2026 → { day: '18', month: '02', year: 2026 }

$currentDatePlusOneMonth(ts?) ​

Same as $currentDate but shifted one month forward.

js
const next = $currentDatePlusOneMonth();
// In March 2026 → { day: '18', month: '04', year: 2026 }