Skip to main content
Version: 2.4

JEXL Functions: Numbers And Validations

Function Reference

This section lists the non-entity JEXL helper functions currently available in tSM configuration. Entity calls such as crm.customer.find(...) are covered separately in the Public API section.

Numbers And Arithmetic

sum(...numbers)

Sums all arguments.

sum(1, 2, 3)
// 6

If no argument is provided, it returns 0 according to tests.

sumMany(array, field, fractionDigits = null)

Sums values of one field in an array of objects. Values are parsed with parseFloat; non-numeric values are ignored as 0.

sumMany([{ price: 10 }, { price: 20 }], 'price')
// 30

Rounding:

sumMany([{ price: 10.126 }, { price: 20.785 }], 'price', 2)
// 30.91

If the array is missing, it returns 0.

ceil(value)

Rounds a number up. If the input is not a number, it returns the original value.

ceil(1.2)
// 2

floor(value)

Rounds a number down. If the input is not a number, it returns the original value.

floor(1.9)
// 1

round(value)

Rounds a number to the nearest integer.

round(1.5)
// 2

If the helper is not available in a specific runtime, use floor, ceil, or a backend-provided value depending on the use case.

toFixed(value, decimals)

Returns a number as a string with a fixed number of decimal places.

toFixed(1.2345, 2)
// '1.23'

If the input is not a number or is null, it returns the original value.

transformNumber(value, fractionDigits?)

Formats a number using Czech locale cs.

transformNumber(1234.56)
// for example '1 234,56' depending on runtime locale formatting

With fixed fraction digits:

transformNumber(12.3, 2)
// '12,30'

If the input is null or NaN, it returns the original value.

percentToValue(value)

Converts a percentage to a decimal value using parseFloat(value) / 100.

percentToValue('50%')
// 0.5
percentToValue('12.5')
// 0.125

safePlus(value1, value2)

Adds two numbers using Decimal.js when both inputs are of type number. This avoids common floating-point precision issues.

safePlus(0.1, 0.2)
// 0.3

If either input is not a number, regular JavaScript + is used, which can concatenate strings:

safePlus('1', 2)
// '12'

safeMinus(value1, value2)

Subtracts two numbers using Decimal.js when both inputs are of type number.

safeMinus(0.3, 0.1)
// 0.2

If either input is not a number, regular JavaScript - is used.

safeMinus('5', 2)
// 3

Validations

isNullOrEmpty(value)

Returns true when the value is null, undefined, an empty string, or an array with no truthy items.

isNullOrEmpty(null)
// true
isNullOrEmpty('')
// true
isNullOrEmpty([null, '', false])
// true
isNullOrEmpty(['x'])
// false

Required-field validation:

isNullOrEmpty($value)

isValidEmail(email)

Validates an email using the regex from platform validation utilities. If the input is not a string, it returns the original value.

isValidEmail('test@example.com')
// true
isValidEmail('test@example')
// false

Optional email validation:

$value && !isValidEmail($value)

nidValid(nid)

Also described in Date & Time because it is related to national IDs and birth dates.

nidValid($context.form.birthNumber)

banValid(accountNumber)

Validates a bank account number.

banValid($context.form.bankAccount)

Verify the expected bank account format in the JEXL console or current application documentation.

isNaN(value)

Checks whether the value is not a number.

isNaN($context.form.amount)

In JavaScript/JEXL environments, be careful with coercion. A string such as '123' can often be treated as numeric input.

isUuid(value)

Validates a UUID string.

isUuid($context.entity.id)

Use it when a field must contain an identifier in UUID format.