Skip to content

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:

NameTypeDescription
timestampnumberUnix 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:

NameTypeDescription
valueanyValue to convert

Returns: string

Conversion Rules:

InputOutput
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:

NameTypeDescription
valueanyValue to convert

Returns: number (integer)

Conversion Rules:

InputOutput
"42"42
3.73
true1
false0
"abc"0 or NaN

Examples:

{{int($.stringNumber)}}
// "42" → 42

{{int($.floatValue)}}
// 3.7 → 3

String Functions

upper()

Converts string to uppercase.

Syntax:

upper(string)

Parameters:

NameTypeDescription
stringstringString to convert

Returns: string

Examples:

{{upper($.name)}}
// "alice" → "ALICE"

{{upper('hello')}}
// "HELLO"

lower()

Converts string to lowercase.

Syntax:

lower(string)

Parameters:

NameTypeDescription
stringstringString 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:

NameTypeDescription
stringstringString 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:

NameTypeDescription
valuestring or arrayValue 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 empty

Math Functions

round()

Rounds to nearest integer.

Syntax:

round(number)

Parameters:

NameTypeDescription
numbernumberNumber to round

Returns: number

Rounding Rules:

InputOutput
3.23
3.54
3.74
-2.5-2

Examples:

{{round($.price)}}
// 19.99 → 20

{{round($.average)}}
// 3.14159 → 3

floor()

Rounds down to nearest integer.

Syntax:

floor(number)

Parameters:

NameTypeDescription
numbernumberNumber 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:

NameTypeDescription
numbernumberNumber to ceil

Returns: number

Examples:

{{ceil(3.1)}}
// 4

{{ceil(-2.9)}}
// -2

{{ceil($.quantity)}}

abs()

Returns absolute value.

Syntax:

abs(number)

Parameters:

NameTypeDescription
numbernumberNumber

Returns: number

Examples:

{{abs(-5)}}
// 5

{{abs($.difference)}}

{{abs($.a - $.b)}}

Function Quick Reference

FunctionParametersReturnsDescription
now()nonenumberCurrent timestamp (ns)
RFC3339(ts)timestampstringFormat timestamp
string(v)anystringConvert to string
int(v)anynumberConvert to integer
upper(s)stringstringUppercase
lower(s)stringstringLowercase
trim(s)stringstringRemove whitespace
len(v)string/arraynumberLength
round(n)numbernumberRound to nearest
floor(n)numbernumberRound down
ceil(n)numbernumberRound up
abs(n)numbernumberAbsolute value

Usage Examples

Timestamp Formatting

yaml
created: "{{RFC3339(now())}}"
// "2024-01-15T10:30:00Z"

Data Normalization

yaml
email: "{{lower(trim($.email))}}"
// " USER@EXAMPLE.COM " → "user@example.com"

Calculations

yaml
discountedPrice: {{round($.price * 0.9 * 100) / 100}}
// Round to 2 decimal places

Conditional with Functions

yaml
hasContent: {{len($.text) > 0}}
displayName: "{{len($.nickname) > 0 ? $.nickname : $.fullName}}"

Combined Operations

yaml
summary: "{{upper($.name)}} - Items: {{len($.items)}} - Total: ${{round($.total)}}"
// "ALICE - Items: 5 - Total: $150"

Error Handling

Invalid Arguments

ScenarioBehavior
Wrong typeType coercion attempted
null/undefinedReturns null or empty
Missing argumentError or undefined

Best Practices

yaml
# Provide defaults before function calls
name: "{{upper($.name || 'unknown')}}"

# Check for existence
length: "{{$.items != null ? len($.items) : 0}}"

Build flow-based applications on Kubernetes