code-docs/plugins/operators/js.md
Core JavaScript operators for Lowdefy. The primary operator package included by default.
This package provides:
_state, _request, _user)_if, _and, _or)_sum, _multiply, _math)_string, _regex)_array, _object, _get)_type, _number, _json)Access page state:
# Get value
name:
_state: userName
# With default
name:
_state:
key: userName
default: Anonymous
Access request responses:
users:
_request: getUsers # Entire response
userName:
_request: getUsers.data.name # Nested path
Access URL query parameters:
# URL: /page?tab=settings
currentTab:
_url_query: tab
Access navigation input:
# Passed via Link action
itemId:
_input: id
Access global state:
theme:
_global: userTheme
Access user session (requires auth):
userId:
_user: id
userName:
_user: name
userRoles:
_user: roles
Access secrets (server-side only):
# In connection config
apiKey:
_secret: EXTERNAL_API_KEY
Access function arguments:
# In custom functions
value:
_args: 0 # First argument
Access event payload:
events:
onClick:
- id: log
type: SetState
params:
clickedItem:
_event: value
Conditional logic:
message:
_if:
test:
_state: isAdmin
then: Admin Panel
else: User Dashboard
Boolean logic:
visible:
_and:
- _state: isLoggedIn
- _state: hasPermission
# OR
showButton:
_or:
- _state: isAdmin
- _state: isOwner
# NOT
disabled:
_not:
_state: isEnabled
# Equality
_eq: [a, b] # a == b
_ne: [a, b] # a != b
# Numeric
_gt: [a, b] # a > b
_gte: [a, b] # a >= b
_lt: [a, b] # a < b
_lte: [a, b] # a <= b
Multiple conditions:
color:
_switch:
branches:
- if:
_eq:
- _state: status
- error
then: red
- if:
_eq:
- _state: status
- warning
then: orange
default: green
Default for null/undefined:
name:
_if_none:
- _state: userName
- Anonymous
total:
_sum:
- _state: price
- _state: tax
difference:
_subtract:
- _state: total
- _state: discount
product:
_multiply:
- _state: quantity
- _state: price
average:
_divide:
- _state: total
- _state: count
Advanced math operations:
rounded:
_math:
method: round
args:
- _state: value
absolute:
_math:
method: abs
args:
- _state: number
Supported methods: abs, ceil, floor, mod, round, max, min, pow, sqrt, etc.
Random number:
randomId:
_random: {} # 0-1
diceRoll:
_random:
min: 1
max: 6
integer: true
Concatenate strings:
fullName:
_string:
- _state: firstName
- ' '
- _state: lastName
Regular expression:
isEmail:
_regex:
pattern: '^[\\w-]+@[\\w-]+\\.[a-z]{2,}$'
value:
_state: email
flags: i
Create array:
items:
_array:
- item1
- _state: dynamicItem
- item3
Create object:
user:
_object:
- - name
- _state: userName
- - email
- _state: userEmail
Get nested value:
city:
_get:
from:
_request: getUser
key: address.city
default: Unknown
Check type:
isArray:
_type:
type: array
value:
_state: items
Parse number:
count:
_number:
_state: countString
JSON parse/stringify:
# Parse
data:
_json:
parse:
_state: jsonString
# Stringify
jsonStr:
_json:
stringify:
_state: data
Debug logging (outputs to console):
debug:
_log:
_state: debugValue
Internationalization:
price:
_intl:
type: NumberFormat
locale: en-US
options:
style: currency
currency: USD
value:
_state: price
URI encoding:
encoded:
_uri:
encode:
_state: searchQuery
Current date/time:
now:
_date: now
timestamp:
_date:
- now
- format: YYYY-MM-DD