Skip to content

Built-in Functions

TinySystems expressions support JavaScript built-in functions plus custom helpers. This reference covers all available functions.

String Functions

toUpperCase()

Convert string to uppercase:

yaml
data:
  upper: "{{$.name.toUpperCase()}}"
# "john" → "JOHN"

toLowerCase()

Convert string to lowercase:

yaml
data:
  lower: "{{$.name.toLowerCase()}}"
# "JOHN" → "john"

trim()

Remove whitespace from both ends:

yaml
data:
  trimmed: "{{$.input.trim()}}"
# "  hello  " → "hello"

trimStart() / trimEnd()

Remove whitespace from one end:

yaml
data:
  leftTrimmed: "{{$.input.trimStart()}}"
  rightTrimmed: "{{$.input.trimEnd()}}"

substring()

Extract part of a string:

yaml
data:
  sub: "{{$.text.substring(0, 5)}}"    # First 5 characters
  rest: "{{$.text.substring(5)}}"       # Everything after position 5

slice()

Similar to substring with negative index support:

yaml
data:
  first5: "{{$.text.slice(0, 5)}}"
  last3: "{{$.text.slice(-3)}}"

split()

Split string into array:

yaml
data:
  parts: "{{$.csv.split(',')}}"
  lines: "{{$.text.split('\\n')}}"

replace()

Replace occurrences:

yaml
data:
  replaced: "{{$.text.replace('old', 'new')}}"
  allReplaced: "{{$.text.replace(/old/g, 'new')}}"

includes()

Check if string contains substring:

yaml
data:
  hasWord: "{{$.text.includes('search')}}"

startsWith() / endsWith()

Check string boundaries:

yaml
data:
  startsWithHttp: "{{$.url.startsWith('http')}}"
  endsWithJson: "{{$.filename.endsWith('.json')}}"

padStart() / padEnd()

Pad string to length:

yaml
data:
  padded: "{{$.num.toString().padStart(5, '0')}}"
# "42" → "00042"

repeat()

Repeat string:

yaml
data:
  repeated: "{{$.char.repeat(3)}}"
# "x" → "xxx"

charAt()

Get character at position:

yaml
data:
  firstChar: "{{$.text.charAt(0)}}"

length

Get string length:

yaml
data:
  len: "{{$.text.length}}"

Number Functions

parseInt()

Parse string to integer:

yaml
data:
  num: "{{parseInt($.stringNum)}}"
  hex: "{{parseInt($.hexString, 16)}}"

parseFloat()

Parse string to float:

yaml
data:
  decimal: "{{parseFloat($.stringFloat)}}"

toFixed()

Format to fixed decimal places:

yaml
data:
  price: "{{$.amount.toFixed(2)}}"
# 19.5 → "19.50"

toString()

Convert to string:

yaml
data:
  str: "{{$.number.toString()}}"
  hex: "{{$.number.toString(16)}}"

isNaN()

Check if not a number:

yaml
data:
  valid: "{{!isNaN($.value)}}"

isFinite()

Check if finite number:

yaml
data:
  finite: "{{isFinite($.value)}}"

Math Functions

Math.round()

Round to nearest integer:

yaml
data:
  rounded: "{{Math.round($.value)}}"

Math.floor()

Round down:

yaml
data:
  floored: "{{Math.floor($.value)}}"

Math.ceil()

Round up:

yaml
data:
  ceiled: "{{Math.ceil($.value)}}"

Math.abs()

Absolute value:

yaml
data:
  absolute: "{{Math.abs($.value)}}"

Math.min() / Math.max()

Find minimum/maximum:

yaml
data:
  min: "{{Math.min($.a, $.b, $.c)}}"
  max: "{{Math.max(...$.values)}}"

Math.pow()

Exponentiation:

yaml
data:
  squared: "{{Math.pow($.value, 2)}}"
  # Or: "{{$.value ** 2}}"

Math.sqrt()

Square root:

yaml
data:
  sqrt: "{{Math.sqrt($.value)}}"

Math.random()

Random number (0-1):

yaml
data:
  random: "{{Math.random()}}"
  randomInt: "{{Math.floor(Math.random() * 100)}}"

Math.trunc()

Remove decimal part:

yaml
data:
  integer: "{{Math.trunc($.value)}}"

Math.sign()

Get sign (-1, 0, or 1):

yaml
data:
  sign: "{{Math.sign($.value)}}"

Array Functions

length

Get array length:

yaml
data:
  count: "{{$.items.length}}"

map()

Transform each element:

yaml
data:
  ids: "{{$.users.map(u => u.id)}}"
  doubled: "{{$.numbers.map(n => n * 2)}}"

filter()

Select matching elements:

yaml
data:
  active: "{{$.items.filter(i => i.active)}}"
  positive: "{{$.numbers.filter(n => n > 0)}}"

find()

Find first match:

yaml
data:
  admin: "{{$.users.find(u => u.role === 'admin')}}"

findIndex()

Find index of first match:

yaml
data:
  adminIndex: "{{$.users.findIndex(u => u.role === 'admin')}}"

some()

Check if any match:

yaml
data:
  hasAdmin: "{{$.users.some(u => u.role === 'admin')}}"

every()

Check if all match:

yaml
data:
  allActive: "{{$.users.every(u => u.active)}}"

reduce()

Aggregate values:

yaml
data:
  sum: "{{$.numbers.reduce((a, b) => a + b, 0)}}"
  grouped: "{{$.items.reduce((acc, item) => ({...acc, [item.type]: [...(acc[item.type] || []), item]}), {})}}"

sort()

Sort array:

yaml
data:
  sorted: "{{$.items.sort((a, b) => a.name.localeCompare(b.name))}}"
  byNum: "{{$.numbers.sort((a, b) => a - b)}}"

reverse()

Reverse array:

yaml
data:
  reversed: "{{$.items.reverse()}}"

slice()

Get subset:

yaml
data:
  first5: "{{$.items.slice(0, 5)}}"
  last3: "{{$.items.slice(-3)}}"

concat()

Combine arrays:

yaml
data:
  combined: "{{$.arr1.concat($.arr2)}}"

join()

Join to string:

yaml
data:
  csv: "{{$.items.join(',')}}"

includes()

Check if contains value:

yaml
data:
  hasValue: "{{$.items.includes('target')}}"

indexOf()

Find index of value:

yaml
data:
  index: "{{$.items.indexOf('target')}}"

flat()

Flatten nested arrays:

yaml
data:
  flattened: "{{$.nested.flat()}}"
  deepFlat: "{{$.deep.flat(Infinity)}}"

flatMap()

Map and flatten:

yaml
data:
  allTags: "{{$.items.flatMap(i => i.tags)}}"

Array.isArray()

Check if array:

yaml
data:
  isArr: "{{Array.isArray($.value)}}"

Array.from()

Create array from iterable:

yaml
data:
  arr: "{{Array.from($.set)}}"

Spread operator

yaml
data:
  unique: "{{[...new Set($.items)]}}"
  merged: "{{[...$.arr1, ...$.arr2]}}"

Object Functions

Object.keys()

Get object keys:

yaml
data:
  keys: "{{Object.keys($.obj)}}"

Object.values()

Get object values:

yaml
data:
  values: "{{Object.values($.obj)}}"

Object.entries()

Get key-value pairs:

yaml
data:
  entries: "{{Object.entries($.obj)}}"

Object.fromEntries()

Create object from pairs:

yaml
data:
  obj: "{{Object.fromEntries($.pairs)}}"

Object.assign()

Merge objects:

yaml
data:
  merged: "{{Object.assign({}, $.obj1, $.obj2)}}"

Spread operator

yaml
data:
  merged: "{{...$.defaults, ...$.overrides}}"
  extended: "{{...$.original, newField: 'value'}}"

hasOwnProperty()

Check property existence:

yaml
data:
  hasId: "{{$.obj.hasOwnProperty('id')}}"

Date Functions

Date.now()

Current timestamp (milliseconds):

yaml
data:
  timestamp: "{{Date.now()}}"

new Date()

Create date object:

yaml
data:
  date: "{{new Date()}}"
  fromTimestamp: "{{new Date($.timestamp)}}"
  fromString: "{{new Date($.dateString)}}"

toISOString()

ISO 8601 format:

yaml
data:
  iso: "{{new Date($.timestamp).toISOString()}}"

toLocaleDateString()

Locale date string:

yaml
data:
  local: "{{new Date($.timestamp).toLocaleDateString()}}"

getTime()

Get timestamp from date:

yaml
data:
  ms: "{{new Date($.dateString).getTime()}}"

Date.parse()

Parse date string to timestamp:

yaml
data:
  timestamp: "{{Date.parse($.dateString)}}"

JSON Functions

JSON.stringify()

Convert to JSON string:

yaml
data:
  json: "{{JSON.stringify($.obj)}}"
  pretty: "{{JSON.stringify($.obj, null, 2)}}"

JSON.parse()

Parse JSON string:

yaml
data:
  obj: "{{JSON.parse($.jsonString)}}"

Type Checking

typeof

Get type:

yaml
data:
  type: "{{typeof $.value}}"
  isString: "{{typeof $.value === 'string'}}"

instanceof

Check instance:

yaml
data:
  isDate: "{{$.value instanceof Date}}"
  isArray: "{{$.value instanceof Array}}"

Logical Operators

Ternary (?😃

yaml
data:
  result: "{{$.condition ? 'yes' : 'no'}}"

Nullish coalescing (??)

yaml
data:
  value: "{{$.value ?? 'default'}}"

Optional chaining (?.)

yaml
data:
  safe: "{{$.nested?.deeply?.value}}"

Logical OR (||)

yaml
data:
  fallback: "{{$.value || 'default'}}"

Logical AND (&&)

yaml
data:
  conditional: "{{$.enabled && $.value}}"

Comparison Operators

yaml
data:
  equal: "{{$.a === $.b}}"
  notEqual: "{{$.a !== $.b}}"
  greater: "{{$.a > $.b}}"
  greaterOrEqual: "{{$.a >= $.b}}"
  less: "{{$.a < $.b}}"
  lessOrEqual: "{{$.a <= $.b}}"

Function Reference Table

CategoryFunctionDescription
StringtoUpperCase()Convert to uppercase
toLowerCase()Convert to lowercase
trim()Remove whitespace
split()Split into array
replace()Replace text
includes()Check contains
startsWith()Check prefix
substring()Extract portion
NumberparseInt()Parse integer
parseFloat()Parse decimal
toFixed()Format decimals
MathMath.round()Round number
Math.floor()Round down
Math.ceil()Round up
Math.min()Find minimum
Math.max()Find maximum
Math.abs()Absolute value
Arraymap()Transform elements
filter()Select elements
reduce()Aggregate values
find()Find first match
sort()Order elements
slice()Get subset
join()Join to string
ObjectObject.keys()Get keys
Object.values()Get values
Object.entries()Get pairs
JSONJSON.stringify()To JSON string
JSON.parse()Parse JSON
DateDate.now()Current timestamp
toISOString()ISO format

Next Steps

Build flow-based applications on Kubernetes