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.


base64decode

Description

BASE64_DECODE(input) returns decoded string.

Input Types

Available input type : string, number, boolean, object, array

Example Usage

return BASE64_DECODE("Rk9P")

Output

FOO

base64encode

Description

BASE64_ENCODE(input) returns encoded string.

Input Types

Available input type : string, number, boolean, object, array

Example Usage

return BASE64_ENCODE("FOO")

Output

Rk9P

decodeurlquery

Description

DECODE_URL_QUERY(input) returns object with query params.

Input Types

Available input type : 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

Available input type : object

Available prefix type : string

Available separator type : string

Available depth type : int

Available option type : 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

Available input type : array

Available separator type : string

Example Usage

return JOIN(input, ", ")

Sample Input

	const body = `return JOIN(input, ", ")`
	output, _ := luax.DoLuaWithInput(context.Background(), body, []byte(input))
	fmt.Println(output)
	// Output: foo, bar
}

lower

Description

LOWER(input) returns lowercas string.

Input Types

Available input type : string

Output

hi

millisecondssinceepoch

Description

MILLISECONDS_SINCE_EPOCH() returns current time with the defined format.

Example Usage

return MILLISECONDS_SINCE_EPOCH()

millisecondssinceepochfromstring

Description

MILLISECONDS_SINCE_EPOCH_FROM_RFC3999(input) returns time with the defined format.

Input Types

Available input type : string

Example Usage

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

Output

1136189045000

pathescape

Description

PATH_ESCAPE(input) returns escaped string.

Input Types

Available input type : string, number.

Example Usage

return PATH_ESCAPE("Hello, playground")

Output

Hello%2C%20playground

pathunescape

Description

PATH_UNESCAPE(input) returns unescaped string.

Input Types

Available input type : string, number

Example Usage

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

Output

Hello, playground

queryescape

Description

QUERY_ESCAPE(input) returns escaped string.

Input Types

Available input type : string, number

Example Usage

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

Output

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

queryunescape

Description

QUERY_UNESCAPE(input) returns unescaped string.

Input Types

Available input type : string

Example Usage

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

Output

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

replace

Description

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

Input Types

Available input type : string

Available existing_substring type : string

Available replacement_string type : string

Example Usage

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

Output

glue

secondssinceepoch

Description

SECONDS_SINCE_EPOCH() returns current time with the defined format.

Example Usage

return SECONDS_SINCE_EPOCH()

secondssinceepochfromstring

Description

SECONDS_SINCE_EPOCH_FROM_RFC3999(input) returns time with the defined format.

Input Types

Available input type : 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

Available input type : string

Available separator type : string

Available index type : int

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

Available input type : string

Available starting_position type : int

Available ending_position type : int

Example Usage

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

Output

my

tobool

Description

TO_BOOL(input) returns boolean.

Input Types

Available input type : string, boolean, number

Example Usage

return TO_BOOL("              TRUE            \n")

Output

true

todatetime

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

Available input type : 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

tofloat

Description

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

Input Types

Available input type : number, string, boolean

Example Usage

return TO_FLOAT("34.4")

Output

34.4

toisocountry

Description

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

Input Types

Available input type : string

Example Usage

return TO_ISO_COUNTRY("Germany")

Output

DE

tomd5hash

Description

TO_MD5_HASH(input) returns MD5 hashed string.

Input Types

Available input type : string

Example Usage

return TO_MD5_HASH("[email protected]")

Output

2e0d5407ce8609047b8255c50405d7b1

toroundedint

Description

TO_ROUNDED_INT(input) returns rounded int.

Input Types

Available input type : number, string

Example Usage

return TO_ROUNDED_INT("12.51")

Output

13

tosha256hash

Description

TO_SHA256_HASH(input) returns SHA256 hashed string.

Input Types

Available input type : string

Example Usage

return TO_SHA256_HASH("[email protected]")

Output

53e6cdc30765aade0129f85e5aeb50124b1d3f5bb9a70373be31e4eb328371e0

tostring

Description

TO_STRING(input) returns string.

Input Types

Available input type : number, boolean, object

Example Usage

return TO_STRING({1, 2})

Output

[1,2]

totruncatedfloat

Description

TO_TRUNCATED_FLOAT(input, precision) returns truncated int.

Input Types

Available input type : number, string, boolean

Available precision type : number

Example Usage

return TO_TRUNCATED_FLOAT(1.25, 1)

Output

1.2

totruncatedint

Description

TO_TRUNCATED_INT(input) returns truncated int.

Input Types

Available input type : number, string

Example Usage

return TO_TRUNCATED_INT("12.51")

Output

12

trim

Description

TRIM(input) returns trimmed string.

Input Types

Available input type : string

Example Usage

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

Output

hello there

upper

Description

UPPER(input) returns uppercase string.

Input Types

Available input type : string

Example Usage

return UPPER("hi")

Output

HI