Skip to content

Cookie preferences

We use cookies for our own analytics, to see how our campaigns perform and, if you allow it, to load content from other services such as the Google site search. We never sell your data. Necessary cookies keep the site working and cannot be switched off. See our Cookie Policy for details and our Privacy Policy for how we handle personal data.

Security, load balancing and remembering your cookie choice.

Show us which pages people read, how they find the site and where they get stuck, so we can improve it (Google Analytics, Microsoft Clarity).

Show us which of our ad campaigns bring visitors to the site and remember the campaign or partner link you arrived from (Google Ads, LinkedIn, Meta, partner program). We do not use these cookies to build advertising profiles.

Load the site search from Google when you use it. Google sets its own cookies and shows ads in the search results.

© 2026 The ThingsBoard Authors

TBEL Helper Functions

TBEL provides a rich set of built-in helper functions for encoding, byte manipulation, hex conversion, date/time, and geofencing. For language syntax and data types, see the Language Guide.

Creates a Base64-encoded ASCII string from a binary string.

btoa(input)
Parameter Type Description
input String The binary string to encode

Returns: String — Base64-encoded string.

Example:

btoa("Hello, world"); // "SGVsbG8sIHdvcmxk"

Decodes a Base64-encoded string back to a binary string.

atob(input)
Parameter Type Description
input String Base64-encoded string

Returns: String — decoded binary string.

Example:

atob("SGVsbG8sIHdvcmxk"); // "Hello, world"

Rounds a double value towards the nearest neighbor with the given precision.

toFixed(value, precision)
Parameter Type Description
value double The value to round
precision int Number of decimal places

Returns: double — rounded value.

Examples:

toFixed(0.345, 1); // 0.3
toFixed(0.345, 2); // 0.35

Rounds a double value to the nearest integer. Halves are rounded away from zero.

toInt(value)
Parameter Type Description
value double The value to round

Returns: int — rounded integer.

Examples:

toInt(0.3); // 0
toInt(0.5); // 1
toInt(2.7); // 3
toInt(-2.5); // -3

Converts a string to a list of bytes.

stringToBytes(input[, charsetName])
Parameter Type Description
input String The string to convert
charsetName String Optional charset (default: UTF-8)

Returns: List — list of byte values.

Examples:

var str = "hello world";
stringToBytes(str); // [104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]
stringToBytes(str, "UTF8"); // [104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]

To get the bytes of a Base64-encoded payload, decode it with atob first:

var bytesStr = atob("eyJoZWxsbyI6ICJ3b3JsZCJ9");
stringToBytes(bytesStr);
// [123, 34, 104, 101, 108, 108, 111, 34, 58, 32, 34, 119, 111, 114, 108, 100, 34, 125]

Creates a string from a list of bytes.

bytesToString(bytesList[, charsetName])
Parameter Type Description
bytesList List A list of byte values
charsetName String Optional charset (default: UTF-8)

Returns: String — decoded string.

Example:

var bytes = [0x48, 0x45, 0x4C, 0x4C, 0x4F];
bytesToString(bytes); // "HELLO"

Same as bytesToString, including the optional charsetName parameter.

decodeToString(bytesList[, charsetName])

Decodes a JSON string, or a list of bytes that contains one, to a JSON document.

decodeToJson(data)
Parameter Type Description
data String or List A JSON string or a list of byte values

Returns: JSON object or primitive.

Example:

decodeToJson('{"hello": "world"}'); // {"hello": "world"}

To decode a JSON payload that arrives as bytes, pass the list of bytes:

var bytes = stringToBytes(atob("eyJoZWxsbyI6ICJ3b3JsZCJ9"));
decodeToJson(bytes); // {"hello": "world"}

Checks whether a string represents a binary (base-2) value.

isBinary(str)
Parameter Type Description
str String The string to check

Returns: int — 2 if binary, -1 otherwise.

Examples:

isBinary("1100110"); // 2
isBinary("2100110"); // -1

Checks whether a string represents an octal (base-8) value.

isOctal(str)
Parameter Type Description
str String The string to check

Returns: int — 8 if octal, -1 otherwise.

Examples:

isOctal("4567734"); // 8
isOctal("8100110"); // -1

Checks whether a string represents a decimal (base-10) value.

isDecimal(str)
Parameter Type Description
str String The string to check

Returns: int — 10 if decimal, -1 otherwise.

Examples:

isDecimal("4567039"); // 10
isDecimal("C100110"); // -1

Checks whether a string represents a hexadecimal (base-16) value.

isHexadecimal(str)
Parameter Type Description
str String The string to check

Returns: int — 16 if hexadecimal, -1 otherwise.

Examples:

isHexadecimal("F5D7039"); // 16
isHexadecimal("K100110"); // -1

Checks whether a double value is Not-a-Number.

isNaN(value)
Parameter Type Description
value double The value to check

Returns: boolean — true if NaN.

Examples:

isNaN(0.0 / 0.0); // true
isNaN(1.0); // false

Encodes a URI string, preserving reserved characters: A–Z a–z 0–9 - _ . ! ~ * ' ( ) ; / ? : @ & = + $ , #

encodeURI(uri)
Parameter Type Description
uri String The URI to encode

Returns: String — encoded URI.

Example:

var uri = "-_.!~*'();/?:@&=+$,#ht://example.ж д a/path with spaces/?param1=Київ 1&param2=Україна2";
encodeURI(uri);
// "-_.!~*'();/?:@&=+$,#ht://example.%D0%B6%20%D0%B4%20a/path%20with%20spaces/?param1=%D0%9A%D0%B8%D1%97%D0%B2%201&param2=%D0%A3%D0%BA%D1%80%D0%B0%D1%97%D0%BD%D0%B02"

Decodes a URI previously encoded with encodeURI.

decodeURI(uri)
Parameter Type Description
uri String The encoded URI

Returns: String — decoded URI.

Example:

var encoded = "-_.!~*'();/?:@&=+$,#ht://example.%D0%B6%20%D0%B4%20a/path%20with%20spaces/?param1=%D0%9A%D0%B8%D1%97%D0%B2%201&param2=%D0%A3%D0%BA%D1%80%D0%B0%D1%97%D0%BD%D0%B02";
decodeURI(encoded);
// "-_.!~*'();/?:@&=+$,#ht://example.ж д a/path with spaces/?param1=Київ 1&param2=Україна2"

Throws a RuntimeException with the given message.

raiseError(message)
Parameter Type Description
message String Exception message

Example:

var value = 4;
if (value > 2) {
raiseError("frequency_weighting_type must be 0, 1 or 2. A value of " + value + " is invalid.");
}
// throws RuntimeException: "frequency_weighting_type must be 0, 1 or 2. A value of 4 is invalid."

Converts a list of signed bytes to their unsigned integer representation.

printUnsignedBytes(byteArray)
Parameter Type Description
byteArray List List of signed byte values

Returns: List — unsigned byte values (0–255).

Examples:

var list = hexToBytes("D8FF");
printUnsignedBytes(list); // [216, 255]
var list2 = hexToBytes("FFD8");
printUnsignedBytes(list2); // [255, 216]

Pads a string from the start until the target length is reached.

padStart(str, targetLength, padString)
Parameter Type Description
str String The string to pad
targetLength int Desired result length
padString char Character to pad with

Returns: String — padded string. If the string is already at or beyond the target length, it is returned unchanged.

Examples:

padStart("010011", 8, '0'); // "00010011"
padStart("1001010011", 8, '0'); // "1001010011" (already >= 8)
padStart("1001010011", 16, '*'); // "******1001010011"

To mask a value and keep only its last characters:

var fullNumber = "203439900FFCD5581";
var last6 = fullNumber.substring(11);
padStart(last6, fullNumber.length(), '*'); // "***********CD5581"

Pads a string from the end until the target length is reached.

padEnd(str, targetLength, padString)
Parameter Type Description
str String The string to pad
targetLength int Desired result length
padString char Character to pad with

Returns: String — padded string. If the string is already at or beyond the target length, it is returned unchanged.

Examples:

padEnd("010011", 8, '0'); // "01001100"
padEnd("1001010011", 8, '0'); // "1001010011" (already >= 8)
padEnd("1001010011", 16, '*'); // "1001010011******"

To mask a value and keep only its first characters:

var fullNumber = "203439900FFCD5581";
var first11 = fullNumber.substring(0, 11);
padEnd(first11, fullNumber.length(), '*'); // "203439900FF******"

Converts an integer to a hexadecimal string.

intToHex(i[, bigEndian[, pref[, len]]])
Parameter Type Description
i Integer The integer to convert
bigEndian boolean Optional. Big-endian byte order (default: true)
pref boolean Optional. Include 0x prefix (default: false)
len int Optional. Number of hex digits to keep, counted from the end. Must not be greater than the length of the hex string, otherwise the call fails.

Returns: String — hex string.

Examples:

intToHex(0x7FFFFFFF, true, true); // "0x7FFFFFFF"
intToHex(171, true, false); // "AB"
intToHex(0xABCDEF, false, true, 4); // "0xCDAB"
intToHex(0xABCD, false, false, 2); // "AB"

Converts a long to a hexadecimal string.

longToHex(l[, bigEndian[, pref[, len]]])
Parameter Type Description
l Long The long to convert
bigEndian boolean Optional. Big-endian byte order (default: true)
pref boolean Optional. Include 0x prefix (default: false)
len int Optional. Number of hex digits to keep, counted from the end. Must not be greater than the length of the hex string, otherwise the call fails.

Returns: String — hex string.

Examples:

longToHex(9223372036854775807, true, true); // "0x7FFFFFFFFFFFFFFF"
longToHex(0x7A12BCD3, true, true, 4); // "0xBCD3"
longToHex(0x7A12BCD3, false, false, 4); // "127A"

Converts a float to a hexadecimal string using IEEE 754 representation.

floatToHex(f[, bigEndian])
Parameter Type Description
f Float The float to convert
bigEndian boolean Optional. Big-endian byte order (default: true)

Returns: String — hex string with 0x prefix.

Examples:

floatToHex(123456789.00); // "0x4CEB79A3"
floatToHex(123456789.00, false); // "0xA379EB4C"

Converts a double to a hexadecimal string using IEEE 754 representation.

doubleToHex(d[, bigEndian])
Parameter Type Description
d Double The double to convert
bigEndian boolean Optional. Big-endian byte order (default: true)

Returns: String — hex string with 0x prefix.

Examples:

doubleToHex(1729.1729d); // "0x409B04B10CB295EA"
doubleToHex(1729.1729d, false); // "0xEA95B20CB1049B40"

Converts a number to a string in the specified radix (binary, octal, decimal, or hex).

intLongToRadixString(number[, radix[, bigEndian[, pref]]])
Parameter Type Description
number Long The number to convert
radix int Optional. Base: 2, 8, 10, 16, or from 25 to 36 (default: 10)
bigEndian boolean Optional. Big-endian byte order (default: true)
pref boolean Optional. Include 0x prefix for hex (default: false)

Returns: String — the number in the specified radix.

Examples:

intLongToRadixString(58, 2); // "00111010"
intLongToRadixString(9223372036854775807, 2); // "0111...1" (64 digits: 0 followed by 63 ones)
intLongToRadixString(13158, 8); // "31546"
intLongToRadixString(-13158, 8); // "1777777777777777746232"
intLongToRadixString(-13158, 10); // "-13158"
intLongToRadixString(13158, 16); // "3366"
intLongToRadixString(-13158, 16); // "FFCC9A"
intLongToRadixString(9223372036854775807, 16); // "7FFFFFFFFFFFFFFF"
intLongToRadixString(-13158, 16, true, true); // "0xFFCC9A"
intLongToRadixString(255, 36); // "73"

Parses a hexadecimal string to an integer.

parseHexToInt(hex[, bigEndian])
Parameter Type Description
hex String Hexadecimal string
bigEndian boolean Optional. Big-endian byte order (default: true)

Returns: int — parsed integer.

Examples:

parseHexToInt("BBAA"); // 48042
parseHexToInt("BBAA", true); // 48042
parseHexToInt("AABB", false); // 48042
parseHexToInt("BBAA", false); // 43707

Aliases:

  • parseLittleEndianHexToInt(hex) — equivalent to parseHexToInt(hex, false)
  • parseBigEndianHexToInt(hex) — equivalent to parseHexToInt(hex, true)

Parses a hexadecimal string to a long.

parseHexToLong(hex[, bigEndian])
Parameter Type Description
hex String Hexadecimal string
bigEndian boolean Optional. Big-endian byte order (default: true)

Returns: long — parsed long.

Examples:

parseHexToLong("BBAA"); // 48042
parseHexToLong("AABB", false); // 48042

Aliases:

  • parseLittleEndianHexToLong(hex) — equivalent to parseHexToLong(hex, false)
  • parseBigEndianHexToLong(hex) — equivalent to parseHexToLong(hex, true)

Parses a hexadecimal string to a float (IEEE 754).

parseHexToFloat(hex[, bigEndian])
Parameter Type Description
hex String Hexadecimal string
bigEndian boolean Optional. Big-endian byte order (default: true)

Returns: float — parsed float.

Examples:

parseHexToFloat("41EA62CC"); // 29.29824
parseHexToFloat("41EA62CC", true); // 29.29824
parseHexToFloat("41EA62CC", false); // -5.948442E7
parseHexToFloat("CC62EA41", false); // 29.29824

Aliases:

  • parseLittleEndianHexToFloat(hex) — equivalent to parseHexToFloat(hex, false)
  • parseBigEndianHexToFloat(hex) — equivalent to parseHexToFloat(hex, true)

Interprets a hex string as a plain integer value and returns it as a float. Unlike parseHexToFloat, this does not use IEEE 754 bit interpretation.

parseHexIntLongToFloat(hex, bigEndian)
Parameter Type Description
hex String Hexadecimal string (may include 0x prefix)
bigEndian boolean Big-endian byte order

Returns: float — the integer value as a float.

Examples:

parseHexIntLongToFloat("0x0A", true); // 10.0
parseHexIntLongToFloat("0x0A", false); // 10.0
parseHexIntLongToFloat("0x00000A", true); // 10.0
parseHexIntLongToFloat("0x0A0000", false); // 10.0
parseHexIntLongToFloat("0x000A0A", true); // 2570.0
parseHexIntLongToFloat("0x0A0A00", false); // 2570.0

Parses a hexadecimal string to a double (IEEE 754).

parseHexToDouble(hex[, bigEndian])
Parameter Type Description
hex String Hexadecimal string
bigEndian boolean Optional. Big-endian byte order (default: true)

Returns: double — parsed double.

Examples:

parseHexToDouble("409B04B10CB295EA"); // 1729.1729
parseHexToDouble("409B04B10CB295EA", true); // 1729.1729
parseHexToDouble("409B04B10CB295EA", false); // -2.7208640774822924E205
parseHexToDouble("EA95B20CB1049B40", false); // 1729.1729

Aliases:

  • parseLittleEndianHexToDouble(hex) — equivalent to parseHexToDouble(hex, false)
  • parseBigEndianHexToDouble(hex) — equivalent to parseHexToDouble(hex, true)

Converts a hexadecimal string to a list of byte values.

hexToBytes(hex)
Parameter Type Description
hex String Hexadecimal string

Returns: List — list of signed byte values (-128 to 127).

Example:

hexToBytes("D8FF"); // [-40, -1]

Converts a hexadecimal string to a byte array.

hexToBytesArray(hex)
Parameter Type Description
hex String Hexadecimal string

Returns: byte[] — byte array.

Example:

hexToBytesArray("D8FF"); // [-40, -1]

Converts a list of bytes to a hexadecimal string.

bytesToHex(bytesList)
Parameter Type Description
bytesList List or byte[] List or array of byte values

Returns: String — hexadecimal string.

Example:

bytesToHex([0xD8, 0xFF]); // "D8FF"

The functions below, from parseBytesToInt to parseBytesLongToDouble, take the same parameters. Pass only data to parse all bytes, or set the range and byte order:

Parameter Type Description
data List or byte[] Bytes to parse
offset int Optional. Index of the first byte to parse (default: 0)
length int Optional. Number of bytes to parse (default: all bytes from offset, up to the maximum of the function)
bigEndian boolean Optional. Big-endian byte order (default: true). To set it, also pass offset and length.

parseBytesToInt(data, true) does not set the byte order: true is read as offset 1.

Bytes are not sign-extended: fewer than 4 bytes (8 for parseBytesToLong) always give a non-negative value. For example, parseBytesToInt([0xFF, 0xFF]) returns 65535, and parseBytesToInt([0xFF, 0xFF, 0xFF, 0xFF]) returns -1.

Parses up to 4 bytes to an integer.

parseBytesToInt(data[, offset[, length[, bigEndian]]])

Returns: int — parsed integer.

Examples:

parseBytesToInt([0xBB, 0xAA]); // 48042
parseBytesToInt([0xAA, 0xBB], 0, 2, false); // 48042
parseBytesToInt([0x01, 0xBB, 0xAA], 1, 2); // 48042

Parses up to 8 bytes to a long.

parseBytesToLong(data[, offset[, length[, bigEndian]]])

Returns: long — parsed long.

Examples:

parseBytesToLong([0x00, 0x00, 0xBB, 0xAA]); // 48042
parseBytesToLong([0xAA, 0xBB, 0x00, 0x00], 0, 4, false); // 48042

Parses up to 4 bytes to a float (IEEE 754).

parseBytesToFloat(data[, offset[, length[, bigEndian]]])

Returns: float — parsed float.

Examples:

parseBytesToFloat([0x41, 0xEA, 0x62, 0xCC]); // 29.29824
parseBytesToFloat([0xCC, 0x62, 0xEA, 0x41], 0, 4, false); // 29.29824

Parses up to 8 bytes to a double (IEEE 754).

parseBytesToDouble(data[, offset[, length[, bigEndian]]])

Returns: double — parsed double.

Examples:

parseBytesToDouble([0x40, 0x9B, 0x04, 0xB1, 0x0C, 0xB2, 0x95, 0xEA]); // 1729.1729
parseBytesToDouble([0xEA, 0x95, 0xB2, 0x0C, 0xB1, 0x04, 0x9B, 0x40], 0, 8, false); // 1729.1729

Interprets up to 4 bytes as an unsigned integer and returns it as a float. Unlike parseBytesToFloat, this does not use IEEE 754 bit interpretation.

parseBytesIntToFloat(data[, offset[, length[, bigEndian]]])

Returns: float — the integer value as a float.

Examples:

parseBytesIntToFloat([0x0A, 0x0A]); // 2570.0
parseBytesIntToFloat([0x0A, 0x0A], 0, 1, false); // 10.0

Interprets up to 8 bytes as an unsigned long and returns it as a double. Unlike parseBytesToDouble, this does not use IEEE 754 bit interpretation.

parseBytesLongToDouble(data[, offset[, length[, bigEndian]]])

Returns: double — the long value as a double.

Example:

parseBytesLongToDouble([0x00, 0x0A, 0x0A]); // 2570.0

Converts a byte array, for example from hexToBytesArray or base64ToBytes, to a list (ExecutionArrayList, TBEL’s internal list type).

bytesToExecutionArrayList(data)
Parameter Type Description
data byte[] Byte array

Returns: List — execution array list.

Converts a single byte to a binary array.

parseByteToBinaryArray(b[, binLength[, bigEndian]])
Parameter Type Description
b byte A single byte value
binLength int Optional. Number of bits to return, counted from the lowest bit (default: 8)
bigEndian boolean Optional. true to start with the highest bit, false to start with the lowest bit (default: true)

Returns: byte[] — array of binary digits (0 or 1).

Examples:

parseByteToBinaryArray(0xFF); // [1, 1, 1, 1, 1, 1, 1, 1]
parseByteToBinaryArray(0x00); // [0, 0, 0, 0, 0, 0, 0, 0]
parseByteToBinaryArray(0x0A, 4); // [1, 0, 1, 0]
parseByteToBinaryArray(0x0A, 8, false); // [0, 1, 0, 1, 0, 0, 0, 0]

Converts a list of bytes to a binary array.

parseBytesToBinaryArray(bytesList[, binLength])
Parameter Type Description
bytesList List or byte[] List or array of byte values
binLength int Optional. Number of bits to return, counted from the lowest bit (default: 8 bits per byte)

Returns: byte[] — binary array.

Examples:

parseBytesToBinaryArray([0xFF, 0x00]);
// [1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0]
parseBytesToBinaryArray([0xFF, 0x00], 4); // [0, 0, 0, 0]

Converts a long to a binary array.

parseLongToBinaryArray(value[, binLength])
Parameter Type Description
value long The long value
binLength int Optional. Number of bits to return, counted from the lowest bit (default: 64)

Returns: byte[] — array of binary digits.

Examples:

parseLongToBinaryArray(255L);
// [0,0,...,0, 1,1,1,1,1,1,1,1] (56 zeros followed by 8 ones)
parseLongToBinaryArray(255, 10); // [0, 0, 1, 1, 1, 1, 1, 1, 1, 1]

Converts a binary array to an integer.

parseBinaryArrayToInt(binaryArray[, offset[, length]])
Parameter Type Description
binaryArray List or byte[] Array of binary digits (0s and 1s)
offset int Optional. Index of the first bit to parse (default: 0)
length int Optional. Number of bits to parse (default: all bits from offset)

Returns: int — parsed integer.

An array of exactly 8 bits that starts with 1 is read as a signed byte whenever offset is 0, even with length set: parseBinaryArrayToInt([1, 1, 1, 1, 0, 0, 0, 0], 0, 4) returns -1. To read all 8 bits as unsigned, put a 0 in front: parseBinaryArrayToInt([0, 1, 1, 1, 1, 1, 1, 1, 1]) returns 255.

Examples:

parseBinaryArrayToInt([0, 0, 1, 1, 1, 0, 1, 0]); // 58
parseBinaryArrayToInt([1, 1, 1, 1, 1, 1, 1, 1]); // -1
parseBinaryArrayToInt([1, 0, 0, 0, 0, 0, 0, 0]); // -128
parseBinaryArrayToInt([1, 1, 1, 1, 1, 1, 1, 1], 1, 7); // 127

Parses a string to an integer.

parseInt(str[, radix])
Parameter Type Description
str String The string to parse
radix int Optional. Base, for example 2, 8, 10, or 16. By default, it is detected from the string: a string with hex letters is read as hex. A hex string must have an even number of digits: parseInt("FFF") fails, parseInt("0FFF") returns 4095.

Returns: int — parsed integer.

Examples:

parseInt("123"); // 123
parseInt("FF"); // 255
parseInt("1010", 2); // 10

Parses a string to a long.

parseLong(str[, radix])
Parameter Type Description
str String The string to parse
radix int Optional. Base, as in parseInt

Returns: long — parsed long.

Examples:

parseLong("9223372036854775807"); // 9223372036854775807
parseLong("FF", 16); // 255

Parses a string to a float.

parseFloat(str[, radix])
Parameter Type Description
str String The string to parse
radix int Optional. 16 reads the string as IEEE 754 bits. Any other base only checks the digits: the string is still read as a decimal number.

Returns: float — parsed float.

Examples:

parseFloat("3.14"); // 3.14
parseFloat("41200000", 16); // 10.0

Parses a string to a double.

parseDouble(str)
Parameter Type Description
str String The string to parse

Returns: double — parsed double.

Example:

parseDouble("3.141592653589793"); // 3.141592653589793

TBEL supports standard bitwise operators inherited from Java:

Operator Description Example
& AND 0xFF & 0x0F → 0x0F
| OR 0xF0 | 0x0F → 0xFF
^ XOR 0xFF ^ 0x0F → 0xF0
~ NOT (complement) ~0x00 → -1
<< Left shift 1 << 8 → 256
>> Signed right shift -256 >> 4 → -16
>>> Unsigned right shift -1 >>> 28 → 15
var a = 0xFF;
var b = 0x0F;
var andResult = a & b; // 15 (0x0F)
var orResult = a | b; // 255 (0xFF)
var xorResult = a ^ b; // 240 (0xF0)
var shifted = 1 << 8; // 256

Converts a Base64-encoded string to a hexadecimal string.

base64ToHex(base64Str)
Parameter Type Description
base64Str String Base64-encoded string

Returns: String — hexadecimal string.

Example:

base64ToHex("SGVsbG8gV29ybGQ="); // "48656C6C6F20576F726C64"

Converts a hexadecimal string to a Base64 string.

hexToBase64(hex)
Parameter Type Description
hex String Hexadecimal string

Returns: String — Base64-encoded string.

Example:

hexToBase64("48656C6C6F"); // "SGVsbG8="

Converts a list of bytes to a Base64 string.

bytesToBase64(bytesList)
Parameter Type Description
bytesList List List of byte values

Returns: String — Base64-encoded string.

Example:

bytesToBase64([72, 101, 108, 108, 111]); // "SGVsbG8="

Converts a Base64 string to a byte array.

base64ToBytes(base64Str)
Parameter Type Description
base64Str String Base64-encoded string

Returns: byte[] — byte array.

Example:

base64ToBytes("SGVsbG8gV29ybGQ=");
// [72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]

Same as base64ToBytes, but returns a List of byte values.

base64ToBytesList(base64Str)

Flattens a nested JSON object into a single-level map where nested keys are joined with dots. The function takes an object, not a string: to flatten a JSON string, parse it first with decodeToJson.

toFlatMap(json)
toFlatMap(json, pathInKey)
toFlatMap(json, excludeList)
toFlatMap(json, excludeList, pathInKey)

Returns: Map — flattened map.

Overload 1 — basic flattening:

var json = {"temperature": 42, "nested": {"humidity": 73}};
toFlatMap(json);
// {"temperature": 42, "nested.humidity": 73}

Overload 2 — with pathInKey flag:

Parameter Type Description
json Map JSON object to flatten
pathInKey boolean true to include full path in keys, false to use only the leaf key
var json = {"temperature": 42, "nested": {"humidity": 73}};
toFlatMap(json, true); // {"temperature": 42, "nested.humidity": 73}
toFlatMap(json, false); // {"temperature": 42, "humidity": 73}

Overload 3 — with exclusion list:

Parameter Type Description
json Map JSON object to flatten
excludeList List Key names to leave out, matched at any depth (not dotted paths). An excluded object is left out with everything inside it.
var json = {"temperature": 42, "nested": {"humidity": 73, "pressure": 1013}};
toFlatMap(json, ["pressure"]);
// {"temperature": 42, "nested.humidity": 73}

Overload 4 — with exclusion list and pathInKey:

Parameter Type Description
json Map JSON object to flatten
excludeList List Key names to leave out, matched at any depth (not dotted paths). An excluded object is left out with everything inside it.
pathInKey boolean true to include full path in keys
var json = {"temperature": 42, "nested": {"humidity": 73, "pressure": 1013}};
toFlatMap(json, ["pressure"], false);
// {"temperature": 42, "humidity": 73}

The Date class provides date/time creation and arithmetic.

new Date(dateString[, pattern[, locale[, timeZone]]])
Parameter Type Description
dateString String The date string to parse. Without pattern, use ISO 8601 with time, for example 2024-01-15T14:30:00Z, or RFC 1123, for example Mon, 15 Jan 2024 14:30:00 GMT.
pattern String Optional. Date format pattern, for example dd/MM/yyyy HH:mm
locale String Optional. Locale as a language tag, for example en-US or fr-FR. Needed when the date has month or day names. Without it, the server’s locale is used.
timeZone String Optional. Time zone, for example UTC or America/New_York. To set it, also pass locale. It overrides any offset in the string. Without it, a date that has no offset is read in the server’s time zone.

Examples:

var date1 = new Date("2024-01-15T14:30:00Z"); // 2024-01-15T14:30:00Z
var date2 = new Date("Mon, 15 Jan 2024 14:30:00 GMT"); // 2024-01-15T14:30:00Z
var date3 = new Date("2024-01-15 14:30:00.000Z", "yyyy-MM-dd HH:mm:ss.SSSXXX"); // 2024-01-15T14:30:00Z
var date4 = new Date("02:15:30 PM, Sun 10/09/2022", "hh:mm:ss a, EEE M/d/uuuu", "en-US", "America/New_York");
// 2022-10-09T18:15:30Z
var date5 = new Date("15/01/2024 14:30", "dd/MM/yyyy HH:mm", "en-US", "UTC"); // 2024-01-15T14:30:00Z

The string must contain the time: a date alone, such as 2024-01-15 or 15/01/2024 with the pattern dd/MM/yyyy, fails with an error. To parse a date without time, add the time to the string and to the pattern, for example new Date("15/01/2024 00:00", "dd/MM/yyyy HH:mm", "en-US", "UTC").

Months are numbered from 1 (January). Without a time zone, the server’s time zone is used. Two-digit years are converted: 0–69 become 2000–2069, and 70–99 become 1970–1999.

var date1 = new Date(2024, 1, 15);
var date2 = new Date(2024, 1, 15, 14, 30);
var date3 = new Date(2024, 1, 15, 14, 30, 45);
var date4 = new Date(2024, 1, 15, 14, 30, 45, 500);
var date5 = new Date(2024, 1, 15, "UTC");
var date6 = new Date(2024, 1, 15, 14, 30, 45, "UTC");

Each form with time components also accepts a time zone as the last argument.

var now = new Date(); // current time
var date = new Date(1705329000000); // timestamp in milliseconds
date.toISOString(); // "2024-01-15T14:30:00Z"

Parses an ISO 8601 date and time with Z or an offset to a timestamp in milliseconds. Returns the current time if the string cannot be parsed, including a string without a time zone, such as 2024-01-15T14:30:00.

parseDateToTimestampOrNow(dateString)
Parameter Type Description
dateString String Date and time in ISO 8601 format with Z or an offset, for example 2024-01-15T14:30:00Z or 2024-01-15T16:30:00+02:00

Returns: long — timestamp in milliseconds.

Examples:

parseDateToTimestampOrNow("2024-01-15T14:30:00Z"); // 1705329000000
parseDateToTimestampOrNow("not a date"); // current time

Each method changes the date in place and returns nothing. The calculation is done in UTC.

var date = new Date(2024, 1, 15, "UTC");
date.addYears(1); // 2025-01-15T00:00:00Z
date.addMonths(2); // 2025-03-15T00:00:00Z
date.addWeeks(1); // 2025-03-22T00:00:00Z
date.addDays(5); // 2025-03-27T00:00:00Z
date.addHours(3); // 2025-03-27T03:00:00Z
date.addMinutes(30); // 2025-03-27T03:30:00Z
date.addSeconds(45); // 2025-03-27T03:30:45Z
date.addNanos(500000000); // 2025-03-27T03:30:45.500Z
date.toISOString(); // "2025-03-27T03:30:45.500Z"

There is no addMilliseconds method: to add milliseconds, multiply them by 1,000,000 and use addNanos. Negative values subtract time.

Checks whether a geographic point lies inside a polygon.

isInsidePolygon(latitude, longitude, perimeter)
Parameter Type Description
latitude double Point latitude
longitude double Point longitude
perimeter String or List Polygon vertices as [[latitude, longitude], …]: a list, or a JSON string such as the value of a perimeter attribute. Two points define a rectangle by its opposite corners. A list of polygons defines several areas; a polygon that lies inside another one is a hole.

Returns: boolean — true if the point is inside the polygon.

Example:

var polygon = [
[50.45, 30.50],
[50.45, 30.55],
[50.40, 30.55],
[50.40, 30.50]
];
isInsidePolygon(50.43, 30.52, polygon); // true

Checks whether a geographic point lies inside a circle.

isInsideCircle(latitude, longitude, perimeter)
Parameter Type Description
latitude double Point latitude
longitude double Point longitude
perimeter String Circle as a JSON string with latitude and longitude of the center, radius, and an optional radiusUnit: METER (default), KILOMETER, FOOT, MILE, or NAUTICAL_MILE. For example, the value of a perimeter attribute.

Returns: boolean — true if the point is inside the circle.

Example:

var circle = '{"latitude": 50.45, "longitude": 30.52, "radius": 1.5, "radiusUnit": "KILOMETER"}';
isInsideCircle(50.455, 30.525, circle); // true