Built-in Functions Reference
Complete reference for built-in functions available in TinySystems expressions.
Time Functions
now()
Returns the current timestamp in nanoseconds since Unix epoch.
Syntax:
now()Returns: number (nanoseconds)
Examples:
{{now()}}
// Result: 1705312200000000000
timestamp: "{{now()}}"
// Result: "1705312200000000000"RFC3339()
Formats a timestamp as an RFC3339 string.
Syntax:
RFC3339(timestamp)Parameters:
| Name | Type | Description |
|---|---|---|
| timestamp | number | Unix timestamp in nanoseconds |
Returns: string (RFC3339 formatted)
Examples:
{{RFC3339(now())}}
// Result: "2024-01-15T10:30:00Z"
{{RFC3339($.createdAt)}}
// Result: "2024-01-10T14:22:35Z"Type Conversion Functions
string()
Converts a value to string.
Syntax:
string(value)Parameters:
| Name | Type | Description |
|---|---|---|
| value | any | Value to convert |
Returns: string
Conversion Rules:
| Input | Output |
|---|---|
42 | "42" |
3.14 | "3.14" |
true | "true" |
false | "false" |
null | "null" |
Examples:
{{string($.count)}}
// 42 → "42"
{{string($.active)}}
// true → "true"
{{'ID-' + string($.id)}}
// "ID-123"int()
Converts a value to integer.
Syntax:
int(value)Parameters:
| Name | Type | Description |
|---|---|---|
| value | any | Value to convert |
Returns: number (integer)
Conversion Rules:
| Input | Output |
|---|---|
"42" | 42 |
3.7 | 3 |
true | 1 |
false | 0 |
"abc" | 0 or NaN |
Examples:
{{int($.stringNumber)}}
// "42" → 42
{{int($.floatValue)}}
// 3.7 → 3String Functions
upper()
Converts string to uppercase.
Syntax:
upper(string)Parameters:
| Name | Type | Description |
|---|---|---|
| string | string | String to convert |
Returns: string
Examples:
{{upper($.name)}}
// "alice" → "ALICE"
{{upper('hello')}}
// "HELLO"lower()
Converts string to lowercase.
Syntax:
lower(string)Parameters:
| Name | Type | Description |
|---|---|---|
| string | string | String to convert |
Returns: string
Examples:
{{lower($.email)}}
// "USER@EXAMPLE.COM" → "user@example.com"
{{lower('HELLO')}}
// "hello"trim()
Removes whitespace from both ends of a string.
Syntax:
trim(string)Parameters:
| Name | Type | Description |
|---|---|---|
| string | string | String to trim |
Returns: string
Examples:
{{trim($.input)}}
// " hello " → "hello"
{{trim(' world ')}}
// "world"len()
Returns the length of a string or array.
Syntax:
len(value)Parameters:
| Name | Type | Description |
|---|---|---|
| value | string or array | Value to measure |
Returns: number
Examples:
// String length
{{len($.name)}}
// "Alice" → 5
// Array length
{{len($.items)}}
// [1, 2, 3] → 3
// Empty check
{{len($.text) > 0}}
// true if not emptyMath Functions
round()
Rounds to nearest integer.
Syntax:
round(number)Parameters:
| Name | Type | Description |
|---|---|---|
| number | number | Number to round |
Returns: number
Rounding Rules:
| Input | Output |
|---|---|
3.2 | 3 |
3.5 | 4 |
3.7 | 4 |
-2.5 | -2 |
Examples:
{{round($.price)}}
// 19.99 → 20
{{round($.average)}}
// 3.14159 → 3floor()
Rounds down to nearest integer.
Syntax:
floor(number)Parameters:
| Name | Type | Description |
|---|---|---|
| number | number | Number to floor |
Returns: number
Examples:
{{floor(3.9)}}
// 3
{{floor(-2.1)}}
// -3
{{floor($.value)}}ceil()
Rounds up to nearest integer.
Syntax:
ceil(number)Parameters:
| Name | Type | Description |
|---|---|---|
| number | number | Number to ceil |
Returns: number
Examples:
{{ceil(3.1)}}
// 4
{{ceil(-2.9)}}
// -2
{{ceil($.quantity)}}abs()
Returns absolute value.
Syntax:
abs(number)Parameters:
| Name | Type | Description |
|---|---|---|
| number | number | Number |
Returns: number
Examples:
{{abs(-5)}}
// 5
{{abs($.difference)}}
{{abs($.a - $.b)}}Function Quick Reference
| Function | Parameters | Returns | Description |
|---|---|---|---|
now() | none | number | Current timestamp (ns) |
RFC3339(ts) | timestamp | string | Format timestamp |
string(v) | any | string | Convert to string |
int(v) | any | number | Convert to integer |
upper(s) | string | string | Uppercase |
lower(s) | string | string | Lowercase |
trim(s) | string | string | Remove whitespace |
len(v) | string/array | number | Length |
round(n) | number | number | Round to nearest |
floor(n) | number | number | Round down |
ceil(n) | number | number | Round up |
abs(n) | number | number | Absolute value |
Usage Examples
Timestamp Formatting
created: "{{RFC3339(now())}}"
// "2024-01-15T10:30:00Z"Data Normalization
email: "{{lower(trim($.email))}}"
// " USER@EXAMPLE.COM " → "user@example.com"Calculations
discountedPrice: {{round($.price * 0.9 * 100) / 100}}
// Round to 2 decimal placesConditional with Functions
hasContent: {{len($.text) > 0}}
displayName: "{{len($.nickname) > 0 ? $.nickname : $.fullName}}"Combined Operations
summary: "{{upper($.name)}} - Items: {{len($.items)}} - Total: ${{round($.total)}}"
// "ALICE - Items: 5 - Total: $150"Error Handling
Invalid Arguments
| Scenario | Behavior |
|---|---|
| Wrong type | Type coercion attempted |
| null/undefined | Returns null or empty |
| Missing argument | Error or undefined |
Best Practices
# Provide defaults before function calls
name: "{{upper($.name || 'unknown')}}"
# Check for existence
length: "{{$.items != null ? len($.items) : 0}}"