Operators and Functions
TinySystems expressions support a variety of operators and built-in functions for data manipulation.
Arithmetic Operators
Basic Math
| Operator | Description | Example | Result |
|---|---|---|---|
+ | Addition | {{5 + 3}} | 8 |
- | Subtraction | {{10 - 4}} | 6 |
* | Multiplication | {{6 * 7}} | 42 |
/ | Division | {{15 / 3}} | 5 |
% | Modulo (remainder) | {{17 % 5}} | 2 |
With Variables
yaml
total: {{$.price * $.quantity}}
discount: {{$.total * 0.1}}
finalPrice: {{$.total - $.discount}}
average: {{$.sum / $.count}}Operator Precedence
Standard mathematical precedence applies:
- Parentheses
() - Multiplication, Division, Modulo
*,/,% - Addition, Subtraction
+,-
yaml
# Without parentheses: 2 + (3 * 4) = 14
result1: {{2 + 3 * 4}}
# With parentheses: (2 + 3) * 4 = 20
result2: {{(2 + 3) * 4}}Comparison Operators
| Operator | Description | Example |
|---|---|---|
== | Equal | {{$.a == $.b}} |
!= | Not equal | {{$.a != $.b}} |
> | Greater than | {{$.a > $.b}} |
< | Less than | {{$.a < $.b}} |
>= | Greater or equal | {{$.a >= $.b}} |
<= | Less or equal | {{$.a <= $.b}} |
Examples
yaml
isEqual: {{$.count == 10}}
isPositive: {{$.value > 0}}
inRange: {{$.age >= 18 && $.age <= 65}}
isEmpty: {{$.items.length == 0}}Type Comparison
yaml
# String comparison
isAdmin: {{$.role == 'admin'}}
# Number comparison
isExpensive: {{$.price > 100}}
# Boolean comparison
isActive: {{$.enabled == true}}Logical Operators
| Operator | Description | Example |
|---|---|---|
&& | Logical AND | {{$.a && $.b}} |
|| | Logical OR | {{$.a || $.b}} |
! | Logical NOT | {{!$.a}} |
Truth Tables
AND (&&)
| A | B | A && B |
|---|---|---|
| true | true | true |
| true | false | false |
| false | true | false |
| false | false | false |
OR (||)
| A | B | A || B |
|---|---|---|
| true | true | true |
| true | false | true |
| false | true | true |
| false | false | false |
Complex Conditions
yaml
# Multiple conditions
canAccess: {{$.isLoggedIn && $.hasPermission}}
# Either condition
notify: {{$.isUrgent || $.isHighPriority}}
# Negation
isDisabled: {{!$.enabled}}
# Combined
showWarning: {{($.count > 100 || $.force) && !$.silent}}Ternary Operator
The conditional (ternary) operator:
condition ? valueIfTrue : valueIfFalseBasic Usage
yaml
status: "{{$.active ? 'enabled' : 'disabled'}}"
message: "{{$.count > 0 ? 'Has items' : 'Empty'}}"Nested Ternary
yaml
# Multiple conditions (use sparingly for readability)
grade: "{{$.score >= 90 ? 'A' : ($.score >= 80 ? 'B' : ($.score >= 70 ? 'C' : 'F'))}}"Type-Preserving
yaml
# Return different types based on condition
result: {{$.hasData ? $.data : []}}
value: {{$.count > 0 ? $.count : 0}}String Operators
Concatenation
Use + to join strings:
yaml
fullName: "{{$.firstName + ' ' + $.lastName}}"
url: "{{$.baseUrl + '/api/' + $.endpoint}}"Template Strings
Embed expressions in strings:
yaml
greeting: "Hello, {{$.name}}!"
summary: "Order {{$.orderId}}: {{$.itemCount}} items totaling ${{$.total}}"Default Value Operator
The || operator provides fallback values:
yaml
# Use default if null/undefined/empty
name: "{{$.name || 'Anonymous'}}"
count: {{$.count || 0}}
items: {{$.list || []}}
# Chain multiple defaults
value: "{{$.primary || $.secondary || $.fallback || 'default'}}"Built-in Functions
Time Functions
now()
Returns the current timestamp as a Unix timestamp in nanoseconds:
yaml
timestamp: "{{now()}}"RFC3339()
Formats a timestamp as RFC3339 string:
yaml
formatted: "{{RFC3339(now())}}"
# Output: "2024-01-15T10:30:00Z"Type Conversion Functions
string()
Convert to string:
yaml
countStr: "{{string($.count)}}"
boolStr: "{{string($.active)}}"int()
Convert to integer:
yaml
num: {{int($.stringNumber)}}
rounded: {{int($.floatValue)}}String Functions
upper()
Convert to uppercase:
yaml
loud: "{{upper($.text)}}"
# "hello" → "HELLO"lower()
Convert to lowercase:
yaml
quiet: "{{lower($.text)}}"
# "HELLO" → "hello"trim()
Remove whitespace from ends:
yaml
clean: "{{trim($.input)}}"
# " hello " → "hello"len()
Get string length:
yaml
length: {{len($.text)}}Math Functions
round()
Round to nearest integer:
yaml
rounded: {{round($.value)}}
# 3.7 → 4
# 3.2 → 3floor()
Round down:
yaml
floored: {{floor($.value)}}
# 3.7 → 3
# 3.2 → 3ceil()
Round up:
yaml
ceiling: {{ceil($.value)}}
# 3.2 → 4
# 3.7 → 4abs()
Absolute value:
yaml
absolute: {{abs($.value)}}
# -5 → 5
# 5 → 5Array Functions
len() for Arrays
Get array length:
yaml
count: {{len($.items)}}Or use .length property:
yaml
count: {{$.items.length}}Operator Summary Table
| Category | Operators |
|---|---|
| Arithmetic | + - * / % |
| Comparison | == != > < >= <= |
| Logical | && || ! |
| Conditional | ? : |
| Default | || |
| Member Access | . [] |
Function Summary Table
| Function | Purpose | Example |
|---|---|---|
now() | Current timestamp | {{now()}} |
RFC3339() | Format timestamp | {{RFC3339(now())}} |
string() | Convert to string | {{string(42)}} |
int() | Convert to integer | {{int("42")}} |
upper() | Uppercase string | {{upper("hi")}} |
lower() | Lowercase string | {{lower("HI")}} |
trim() | Trim whitespace | {{trim(" hi ")}} |
len() | Length of string/array | {{len($.items)}} |
round() | Round number | {{round(3.5)}} |
floor() | Round down | {{floor(3.9)}} |
ceil() | Round up | {{ceil(3.1)}} |
abs() | Absolute value | {{abs(-5)}} |
Combining Operations
Complex Calculations
yaml
# Calculate discounted total
subtotal: {{$.price * $.quantity}}
discount: {{$.subtotal * ($.discountPercent / 100)}}
tax: {{($.subtotal - $.discount) * 0.08}}
total: {{$.subtotal - $.discount + $.tax}}Conditional Formatting
yaml
# Format based on value
display: "{{$.count > 0 ? string($.count) + ' items' : 'Empty'}}"
# Price formatting
priceDisplay: "${{round($.price * 100) / 100}}"Data Validation
yaml
# Check multiple conditions
isValid: {{$.email != '' && len($.email) > 5 && $.age >= 18}}
# Provide validated value or error
result: "{{$.isValid ? $.data : 'Invalid input'}}"Next Steps
- Expression Examples - Real-world examples
- Expression Syntax - Syntax reference
- Data Mapping - Using expressions in flows