Skip to main content

Built-In Functions

Label Functions

hasLabel

hasLabel(token: Token, label: String) -> Bool

Returns whether an given token has the specified label

Map Functions [TODO]

mapGet

mapGet(map: Map, key: String) -> Any

Given a map object, returns the specified key if found, otherwise returns NULL

mapSet

mapGet(map: Map, key: String, value: Any)

Given a object, set the provided key to specified value

JSON Functions

jsonExtract

jsonExtract(jval: JVal, jsonPath: String) -> Any

Given a JSON object, extract the value specified by jsonPath, returning NULL if the path does not exist.

Type Annotation

When assigning the return value of jsonExtract to a feature, the feature must be type annotated otherwise compilation will fail.

Ex. Given a JSON EventData with value {"score": 12.0}, we can write the following test (see testing for how to write test)

__test__.tw
LET Score: Number = jsonExtract(EventData, "$.score");
ASSERT Score = 12.0;
caution

jsonExtract does not return the resulting value in a wrapper array.

jsonStringify

jsonStringify(val: Any) -> String

jsonParse

jsonParse(jstr: String) - JVal

String Functions

concat

concat(a: String, b: String) -> String

len

len(str: String) -> Number

Returns the unicode character len of a given string

startsWith

startsWith(str: String, prefix: String) -> Boolean

Checks whether given input has given prefix

endsWith

endsWith(str: String, suffix: String) -> Boolean

Checks whether given input has given suffix

Array Functions

join

join(array: Array<String>, separator: String) -> String

Given an array of string, concat the items separated by separator.

IP Functions TODO

ipToCountry

ipToCountry(ip: String) -> String

Given an IP string (ip4 or ip6), return the geolocated two letter country code

Time Functions

now

now() -> Number

Returns the seconds since UNIX epoch

Regex Functions

match

match(patterns: Array<String>, text: String) -> Bool

Given the a list of regex patterns, return whether the provided text matches any of the provided patterns.

Key Value Database

A simple key value storage for storing data across events.

setKv

setKv(ns: String, key: String, val: String, expiry_duration: Duration)

getKv

getKv(ns: String, key: String, val: String, expiry_duration: Duration) - String | NULL

Set Database

A persistent storage for storing a unique set of events grouped under a particular key.

addToSet

addToSet(ns: String, key: Token, item: String)

isInSet

isInSet(ns: String, key: Token, item: String) -> Boolean

Counter Database

A simple counter implementation that provides second level granularity

incCount

incCount(ns: String, by: By, incr: Number)

getCount

getCount(ns: String, by: By, lookback_window: OptionDuration) -> Number

Token Functions

toToken

toToken(type: String, val: String) -> Token

Type Functions

toNum

toNum(input: Any) -> Number | null

Tries to convert the given input to a number, returning null if conversion fails

toString

toString(input: Any) -> String

Convert the given input to string

toBool

toBool(input: Any) -> Boolean

Convert the given input to boolean.

false, null, empty container ([], {}), empty string (""), and zero (0) convert to false everything else evaluates to true.

Misc Functions

random

random() -> Number

Returns a value uniformly sampled between (0, 1), exclusive of the bound.