Calculations & Functions
Zolt features a robust expression engine for performing calculations and manipulating data.
Calculations
Basic Math
zolt
+ $10 + 5 = {{ 10 + 5 }}$
+ $20 - 8 = {{ 20 - 8 }}$
+ $3 * 4 = {{ 3 * 4 }}$
+ $15 / 3 = {{ 15 / 3 }}$
+ $10 \% 3 = {{ 10 % 3 }}$
+ $2 ^ 8 = {{ 2 ^ 8 }}$
Result
Operator Precedence
zolt
+ $3 + 2 * 5 = {{ 3 + 2 * 5 }}$
+ $(3 + 2) * 5 = {{ (3 + 2) * 5 }}$
+ $2 ^ {3 ^ 2} = {{ 2 ^ 3 ^ 2 }}$
Result
Namespace Functions
Math Namespace
The Math namespace provides common mathematical constants and functions.
| Function | Arguments | Return | Description |
|---|---|---|---|
Math.floor(n) | n: number | number | Returns the largest integer less than or equal to n. |
Math.ceil(n) | n: number | number | Returns the smallest integer greater than or equal to n. |
Math.round(n) | n: number | number | Returns the value of n rounded to the nearest integer. |
Math.abs(n) | n: number | number | Returns the absolute value of n. |
Math.pow(b, e) | b: number, e: number | number | Returns the base b to the exponent e power. |
Math.sqrt(n) | n: number | number | Returns the square root of n. |
Math.min(...n) | ...n: number | number | Returns the smallest of zero or more numbers. |
Math.max(...n) | ...n: number | number | Returns the largest of zero or more numbers. |
Examples
zolt
+ Math.floor(3.7) = {{ Math.floor(3.7) }}
+ Math.ceil(3.2) = {{ Math.ceil(3.2) }}
+ Math.round(3.5) = {{ Math.round(3.5) }}
+ Math.abs(-5) = {{ Math.abs(-5) }}
+ Math.min(10, 5) = {{ Math.min(10, 5) }}
+ Math.max(10, 5) = {{ Math.max(10, 5) }}
+ Math.pow(2, 8) = {{ Math.pow(2, 8) }}
+ Math.sqrt(16) = {{ Math.sqrt(16) }}
Result
- Math.floor(3.7) = 3
- Math.ceil(3.2) = 4
- Math.round(3.5) = 4
- Math.abs(-5) = 5
- Math.min(10, 5) = 5
- Math.max(10, 5) = 10
- Math.pow(2, 8) = 256
- Math.sqrt(16) = 4
List Namespace
The List namespace provides functions for manipulating arrays.
| Function | Arguments | Return | Description |
|---|---|---|---|
List.length(l) | l: array | number | Returns the number of elements in the list. |
List.count(l) | l: array | number | Alias of List.length. |
List.first(l) | l: array | any | Returns the first element of the list. |
List.last(l) | l: array | any | Returns the last element of the list. |
List.sum(l) | l: array | number | Returns the sum of all numeric elements in the list. |
List.avg(l) | l: array | number | Returns the average value of numeric elements in the list. |
List.min(l) | l: array | number | Returns the smallest numeric value in the list. |
List.max(l) | l: array | number | Returns the largest numeric value in the list. |
Examples
zolt
$numbers = [10, 20, 30, 40, 50]
+ Length: {{ List.length($numbers) }}
+ First: {{ List.first($numbers) }}
+ Last: {{ List.last($numbers) }}
+ Sum: {{ List.sum($numbers) }}
+ Average: {{ List.avg($numbers) }}
Result
- Length: 5
- First: 10
- Last: 50
- Sum: 150
- Average: 30
String Namespace
The String namespace provides functions for string manipulation.
| Function | Arguments | Return | Description |
|---|---|---|---|
String.upper(s) | s: string | string | Returns the string converted to uppercase. |
String.lower(s) | s: string | string | Returns the string converted to lowercase. |
String.length(s) | s: string | number | Returns the number of characters in the string. |
String.trim(s) | s: string | string | Returns the string with whitespace removed from both ends. |
String.replace(s, f, r) | s: string, f: string, r: string | string | Replaces all occurrences of f with r in s. |
String.split(s, sep) | s: string, sep: string | array | Splits the string into an array of strings by separator. |
String.join(l, sep) | l: array, sep: string | string | Joins all elements of an array into a string using the separator. |
Examples
zolt
{{ String.upper("hello") }}
{{ String.lower("HELLO") }}
{{ String.length("text") }}
{{ String.trim(" text ") }}
{{ String.replace("hello", "l", "r") }}
Result
- String.upper("hello") = HELLO
- String.lower("HELLO") = hello
- String.length("text") = 4
- String.trim(" text ") = text
- String.replace("hello", "l", "r") = herro
Date Namespace
The Date namespace provides functions for date and time operations.
| Function | Arguments | Return | Description |
|---|---|---|---|
Date.buildTime() | None | number | Returns the generation timestamp in milliseconds. |
Date.format(d, f) | d: timestamp/date/str, f: string | string | Formats a date according to the provided format string. |
Date.parse(s, f?) | s: string, f: string? | date | Parses a string into a Date object (optionally using a format). |
Date.calc(d, dur) | d: date, dur: object | date | Adds/subtracts time from a date (e.g., {days: 1}). |
Date.diff(d1, d2, u?) | d1: date, d2: date, u: string? | number | Returns the difference between two dates in the specified unit. |
Date.timestamp(d?) | d: date? | number | Returns the Unix timestamp (seconds) for a date or now. |
Date.msTimestamp(d?) | d: date? | number | Returns the timestamp (milliseconds) for a date or now. |
Format Tokens
Available format tokens:
| Token | Description | Example |
|---|---|---|
D | Day (1-2 digits) | 3 |
DD | Day (2 digits) | 03 |
ddd | Day name (short) | tue |
Ddd | Day name (short, Capital) | Tue |
DDD | Day name (short, Uppercase) | TUE |
dddd | Day name (full) | tuesday |
Dddd | Day name (full, Capital) | Tuesday |
DDDD | Day name (full, Uppercase) | TUESDAY |
M | Month (1-2 digits) | 3 |
MM | Month (2 digits) | 03 |
mmm | Month name (short) | mar |
Mmm | Month name (short, Capital) | Mar |
MMM | Month name (short, Upper) | MAR |
mmmm | Month name (full) | march |
Mmmm | Month name (full, Capital) | March |
MMMM | Month name (full, Upper) | MARCH |
YY | Year (2 digits) | 26 |
YYYY | Year (4 digits) | 2026 |
h | Hour (12h, 1-12) | 1 |
H | Hour (24h, 0-23) | 13 |
hh | Hour (12h, 01-12) | 01 |
HH | Hour (24h, 00-23) | 13 |
a | am/pm (lowercase) | pm |
A | AM/PM (uppercase) | PM |
m | Minutes (0-59) | 12 |
mm | Minutes (00-59) | 12 |
s | Seconds (0-59) | 59 |
ss | Seconds (00-59) | 59 |
sss | Milliseconds (000-999) | 750 |
Examples
zolt
$created = "2024-01-01"
+ Date.buildTime() = {{ Date.buildTime() }}
+ Date.format($created, "DD/MM/YYYY") = {{ Date.format($created, "DD/MM/YYYY") }}
+ Date.timestamp($created) = {{ Date.timestamp($created) }}
+ Date.msTimestamp($created) = {{ Date.msTimestamp($created) }}
Result
- Date.buildTime() = 1772543579751
- Date.format($created, "DD/MM/YYYY") = 01/01/2024
- Date.timestamp($created) = 1704067200
- Date.msTimestamp($created) = 1704067200000
Best Practices
- Test complex calculations separately to ensure accuracy
- Use parentheses to make operator precedence explicit and readable
- Handle null/undefined variables before performing math
- Use namespace functions for formatting and common transformations
© 2026 Marmotz