Text manipulation
replace
replace(text, match, substitution)
Replaces the matching text with the given substitution.
replace("The lazy cat","cat", "dog")
returns“The lazy dog”
text_join
text_join(delimiter, ignoreEmpty, text1, [text2...])
Joins text or lists of text with a separator.
text_join(" ", "a", "b")
returns"a b"
text_join(",", false, "a", "" , "b")
returns"a,,b"
text_join(",", true, "a", "" , "b")
returns"a,b"
text_split
text_split(text, delimiter, [ignore_empty])
Splits text into a list on a separating character (delimiter). By default empty text between delimiters is not included in the result.
text_split("a b", " ")
returns a list of["a", "b"]
text_split("a,,b", ",", false)
returns a list of["a", "", "b"]
substring
substring(input_text, start_index, [end_index, length: length])
Returns the segment of input_text that runs from start_index
, inclusive, to end_index
, exclusive.
An optional end_index
or length
may be specified. Specifying both is an error.
If neither end_index
nor length
is specified, the segment runs to the end of input_text
.
The first character in the text has index 0. Negative indexes count from the end of input_text.
substring("Hello World", 0, 5)
returns"Hello"
substring("Hello World", 6, length: 100)
returns"World"
substring("Hello World", 3, length: 2)
returns"lo"
substring("Hello World", -5)
returns"World"
substring("Hello World", -5, -3)
returns"Wo"
substring("Hello World", 6, -3)
returns"Wo"
concat()
concat("x", “y”)
Join text together without a delimiter. You can also use &
as shorthand.
Formatting text
lower
lower(text)
Converts the given text (or list of texts) to lower case.
lower("Pole ABC")
returns“pole abc”
lower(list("A", "B", "c"))
returns["a", "b", "c"]
upper
upper(text)
Converts the given text (or list of texts) to upper case.
upper("Pole abc")
returns“POLE ABC”
lower(list("a", "b", "C"))
returns["A", "B", "C"]
Text matching
match
match(pattern, text, [is_case_sensitive])
Checks if text contains a pattern and returns true if it does, otherwise returns false. By default it is not case sensitive. It splits a phrase up and matches each separate word (see contains for exact match).
match("Lazy", "The lazy cat")
returnstrue
match("Lazy", "The lazy cat", true)
returnsfalse
match("dog", "The lazy cat")
returnsfalse
match("The cat", "The lazy cat")
returnstrue
contains
contains(pattern, text, [is_case_sensitive])
Checks if text contains a pattern and returns true if it does, otherwise returns false. By default it is not case sensitive. It checks if the entire pattern is contained in the text.
contains("Lazy", "The lazy cat")
returnstrue
contains("Lazy", "The lazy cat", true)
returnsfalse
contains("dog", "The lazy cat")
returnsfalse
contains("The cat", "The lazy cat")
returnsfalse
regex_match
regex_match(regex pattern, text, [is_case_sensitive])
Matches a regular expression.
Returns a list of text values representing the matched groups.
Formatting units as text
text_unit
text_unit(number, unit_code, [dp, mode])
Converts a number to a textual representation in the given unit, with the unit suffixed.
Valid unit render modes are: compact
(default), textual
, none
text_unit(10 * unit("m"), "m")
returns10.00m
text_unit(10 * unit("m"), "m", 1, "textual")
returns10.0 metres
text_unit(10 * unit("m"), "m", 3, "none")
returns10.000
Parsing text
parse_timestamp
parse_timestamp(format, time_text)
Parses time text into a timestamp object using the given format string.
The implementation should largely follow the ICU formatting codes.
If the time is invalid then the unix epoch is returned (1/1/1970), and this value should be checked for as a difference between two invalid times would be zero.
parse_timestamp("yyyy-MM-ddTHH:mm:ssZ", "2020-05-23T23:57:59Z+1100")
See also: epoch_timestamp()
parse_num
parse_num(num_string, [default_number])
Parses strings like "1", "2.3", "-3.1" etc and returns a dimensionless number. If the string doesn't parse return the default number.
parse_num("1")
returns1.00
parse_num("a", 0)
returns0.00
parse_voltage
parse_voltage(voltage_string)
Parses strings like "LV", "415V", "22kV", etc and returns a number in Volts
(not kV
).
parse_voltage("LV")
returns415.00
parse_voltage("415V")
returns415.00
parse_voltage("22kV")
returns22000.00
Styling
colored_text
colored_text(color, text)
Creates colored text. color
may be either a color object, a hex value, or a color name.
colored_text("green", "sample text")
returns sample textcolored_text("ff0000", "sample text")
returns sample text
Valid color names (visual color reference):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
color_to_hex
color_to_hex(color)
Returns the hexadecimal representation of the color.
URLs
hyperlink
hyperlink(safe_url, [title]) hyperlink(href, [title])
Creates a clickable link with the given title.
hyperlink("https://www.neara.com", "Neara Homepage")
make_url
make_url(templated_url: templated_url, substitution: map())
Inserts the URL-encoded substitution
into the provided templated_url
.
Substitutable parts of the templated_url
are wrapped in percentage symbols (%
) and are in CAPS.
The templated_url can be created using authorize_service()
.
Example:
If a templated_url looks like this: https://example.com/%PATH%
then
make_url(templated_url: templated_url, substitution: map("PATH", "myPath"))
returns a safe_url that looks like this: https://example.com/myPath
authorize_service
authorize_service(service_name)
Returns a TemplatedUrl
if the service authentication is successful. The TemplatedUrl
can then be passed to the make_url()
function for user substitution.
Authentication is on a per-organization basis, so individual login credentials are not required.