Global Functions Documentation

Lua Functions Documentation

This document provides a reference for all available Lua functions that can be used in playbooks. Each function is documented with its description, input types, example usage, and expected output. Click on any function name to expand its details.


BASE64_DECODE

Description

BASE64_DECODE(input) returns decoded string.

Input Types

string, number, boolean, object, array

Example Usage

return BASE64_DECODE("Rk9P")

Output

FOO

BASE64_ENCODE

Description

BASE64_ENCODE(input) returns encoded string.

Input Types

string, number, boolean, object, array

Example Usage

return BASE64_ENCODE("FOO")

Output

Rk9P

DECODE_URL_QUERY

Description

DECODE_URL_QUERY(input) returns object with query params.

Input Types

string

Example Usage

return DECODE_URL_QUERY("http://example.com/path?q=value#fragment")

Output

{"q":"value"}

FLATTEN

Description

FLATTEN(input, prefix, separator, depth, option) returns flattened object.

Input Types

object

Example Usage

return FLATTEN(input, "prefix", "_", 5, { array_start_index = 1 })

Sample Input

{
	"products": [
		{
		  "name": "Monopoly"
		},
		{
		  "name": "Uno"
		}
	]
}

Output

{"prefix_products_1_name":"Monopoly","prefix_products_2_name":"Uno"}

JOIN

Description

JOIN(input, separator) returns the string representation of an array using an optional delimiter.
Without separator, it returns concatenated value

Input Types

array

Example Usage

return JOIN(input, ", ")

Sample Input

["foo", "bar"]

Output

foo, bar

LOWER

Description

LOWER(input) returns lowercase string.

Input Types

string

Example Usage

return LOWER("HI")

Output

hi

MAP

Description

MAP(input, function) returns an array with the results of running func once for every element in values.

Input Types

array

Example Usage

return MAP(input.properties.products, function (product)
		    local price = product.price or 0
		    local quantity = product.quantity or 0
		    return price * quantity
		  end)

Sample Input

{
	"properties" : {
		"products" : [
			{"price": 500, "quantity": 1},
			{ "price" : 300, "quantity" :  2 },
			{              "quantity" : 10 },
			{ "price" : 10                 }
		]
	}
}

Output

[500,600,0,0]

MILLISECONDS_SINCE_EPOCH

Description

MILLISECONDS_SINCE_EPOCH() returns current time with the defined format.

Example Usage

return MILLISECONDS_SINCE_EPOCH()

MILLISECONDS_SINCE_EPOCH_FROM_RFC3999

Description

MILLISECONDS_SINCE_EPOCH_FROM_RFC3999(input) returns time with the defined format.

Input Types

string

Example Usage

return MILLISECONDS_SINCE_EPOCH_FROM_RFC3999("2006-01-02T15:04:05+07:00")

Output

1136189045000

OMIT

Description

OMIT(input, property) returns object without the specified property.

Input Types

object

Example Usage

return OMIT(input, 'foo')

Sample Input

{
	"foo": 1,
	"bar": 2,
	"bin": 3
}

Output

{"bar":2,"bin":3}

PATH_ESCAPE

Description

PATH_ESCAPE(input) returns escaped string.

Input Types

string, number.

Example Usage

return PATH_ESCAPE("Hello, playground")

Output

Hello%2C%20playground

PATH_UNESCAPE

Description

PATH_UNESCAPE(input) returns unescaped string.

Input Types

string, number

Example Usage

return PATH_UNESCAPE("Hello%2C%20playground")

Output

Hello, playground

PLUCK

Description

PLUCK(input, property) returns an array by selecting a single property from an collection of values.

Input Types

array

Example Usage

return PLUCK(input.properties.products, 'quantity')

Sample Input

{
	"properties": {
		"products": [
			{
			  "quantity": 1
			},
			{
			  "quantity": 2
			}
		]
	}
}

Output

[1,2]

QUERY_ESCAPE

Description

QUERY_ESCAPE(input) returns escaped string.

Input Types

string, number

Example Usage

return QUERY_ESCAPE("/hello/world?a=b&c=d")

Output

%2Fhello%2Fworld%3Fa%3Db%26c%3Dd

QUERY_UNESCAPE

Description

QUERY_UNESCAPE(input) returns unescaped string.

Input Types

string

Example Usage

return QUERY_UNESCAPE("%2Fhello%2Fworld%3Fa%3Db%26c%3Dd")

Output

/hello/world?a=b&c=d

REDUCE

Description

REDUCE(input, function) returns value with the results of running func once for every element in values.

Input Types

array

Example Usage

return REDUCE(input, 0, function (memo, o) return memo + (o.id * 2) end)

Sample Input

[
	{
	  "id": 1
	},
	{
	  "id": 2
	},
	{
	  "id": 3
	}
]

Output

12

REPLACE

Description

REPLACE(input, existing_substring, replacement_string) returns replaced string.

Input Types

string

Example Usage

return REPLACE(true, "tr", "gl")

Output

glue

SECONDS_SINCE_EPOCH

Description

SECONDS_SINCE_EPOCH() returns current time with the defined format.

Example Usage

return SECONDS_SINCE_EPOCH()

SECONDS_SINCE_EPOCH_FROM_RFC3999

Description

SECONDS_SINCE_EPOCH_FROM_RFC3999(input) returns time with the defined format.

Input Types

string

Example Usage

return MILLISECONDS_SINCE_EPOCH_FROM_RFC3999("2006-01-02T15:04:05+07:00")

Output

1136189045000

SPLIT

Description

SPLIT(input, separator, index) returns array with the defined index.

Input Types

string

Example Usage

return SPLIT("1,2,3,4,5", ",", 3)

Output

["1","2","3"]

SUBSTRING

Description

SUBSTRING(input, starting_position, ending_position) returns extracted part of a string.

Input Types

string

Example Usage

return SUBSTRING("my string", 0, 2)

Output

my

SUM

Description

SUM(input) calculates the sum of elements in a given array.

Input Types

array

Example Usage

return SUM(input)

Sample Input

[1, 2, 3]

Output

6

TO_BOOL

Description

TO_BOOL(input) returns boolean.

Input Types

string, boolean, number

Example Usage

return TO_BOOL("              TRUE            \n")

Output

true

TO_DATE_TIME

Description

TO_DATE_TIME(input, { inputFormat = example-based layouts, outputFormat = example-based layouts }) returns string.
You can refer valid inputFormat and outputFormat from https://pkg.go.dev/time#pkg-constants
Without outputFormat, it follows RFC3339 format

Input Types

string

Example Usage

return TO_DATE_TIME("2020-10-26T18:10:38Z", { inputFormat = "2006-01-02T15:04:05Z07:00", outputFormat = "Mon Jan _2 15:04:05 MST 2006" })

Output

Mon Oct 26 18:10:38 UTC 2020

TO_FLOAT

Description

TO_FLOAT(input) returns number.
true returns 1 and false returns 0

Input Types

number, string, boolean

Example Usage

return TO_FLOAT("34.4")

Output

34.4

TO_ISO_COUNTRY

Description

TO_ISO_COUNTRY(input) returns the ISO country code.
If the country is not found, it returns the original input string.

Input Types

string

Example Usage

return TO_ISO_COUNTRY("Germany")

Output

DE

TO_MD5_HASH

Description

TO_MD5_HASH(input) returns MD5 hashed string.

Input Types

string

Example Usage

return TO_MD5_HASH("[email protected]")

Output

2e0d5407ce8609047b8255c50405d7b1

TO_ROUNDED_INT

Description

TO_ROUNDED_INT(input) returns rounded int.

Input Types

number, string

Example Usage

return TO_ROUNDED_INT("12.51")

Output

13

TO_SHA256_HASH

Description

TO_SHA256_HASH(input) returns SHA256 hashed string.

Input Types

string

Example Usage

return TO_SHA256_HASH("[email protected]")

Output

53e6cdc30765aade0129f85e5aeb50124b1d3f5bb9a70373be31e4eb328371e0

TO_STRING

Description

TO_STRING(input) returns string.

Input Types

number, boolean, object

Example Usage

return TO_STRING({1, 2})

Output

[1,2]

TO_TRUNCATED_FLOAT

Description

TO_TRUNCATED_FLOAT(input, precision) returns truncated int.

Input Types

number, string, boolean

Example Usage

return TO_TRUNCATED_FLOAT(1.25, 1)

Output

1.2

TO_TRUNCATED_INT

Description

TO_TRUNCATED_INT(input) returns truncated int.

Input Types

number, string

Example Usage

return TO_TRUNCATED_INT("12.51")

Output

12

TRIM

Description

TRIM(input) returns trimmed string.

Input Types

string

Example Usage

return TRIM("   \n hello there   \n")

Output

hello there

UPPER

Description

UPPER(input) returns uppercase string.

Input Types

string

Example Usage

return UPPER("hi")

Output

HI