Here are all the functions usable on the mappings section to transform expressions
Split
split a string into a list of items
split(string, separator)
examples
split("This is a sentence", " ") => ["This", "is", "a" "sentence"]
split("This is a sentence", " ")[1] => "is"
Replace
replace all occurrences of a text by another
replace(string, old, new)
example
replace("This is a sentence", "sentence", "paragraph") => "This is a paragraph"
Substring
extract a substring from a string
substring(string, start, length)
example
substring("This is a sentence", 2, 10) => "is is a "
Contains
check if a string contains a substring
contains(string, substring)
example
substring("This is a sentence", "sentence") => true
Concat
concatenate multiple string
concat(strings ...string)
example
concat("This", " ", "is", " ", "a", " ", "sentence") => "This is a sentence"
concatenate multiple string arrays
concat(slices ...[]string)
example
concat(["This", " ", "is", " ", "a", " ", "sentence"]) => "This is a sentence"
Join
merge strings arrays into a single string
join(slice []string, sep string)
example
join(["This is", "a sentence"], " ") => "This is a sentence"
Remove
removes all occurrences of a value from a string array
remove(slice []string, string)
example
join(["good","day","bad","day"], "day") => "["good","bad"]"
Feed
retrieve data from a source feed
feed(feedId, fieldName)
example
feed(12345678, "targetCountry")
Feed percentile
returns the value of a percentile for a field
feed_percentile(feedId, fieldName, statname)
example
feed(12345678, "price.value", 95.0) => 101.31
Feed stat
returns the value of a stat for a field
feed_stat(feedId, fieldName, percentile)
example
feed(12345678, "price.value", "sum") => 4383.17
Les statistiques disponibles pour la fonction feed_stat sont:
Les statistiques de base : sum, avg, max, min
Les percentiles : percentile10, percentile20, percentile30, percentile40, percentile50, percentile60, percentile70, percentile80, percentile90
Regexp replace
replace all regexp matches by another value. use $1, $2 in replacement to get capture groups
regexp_replace(value, regexp, replacement)
example
regexp_replace("Smith, John David", "^(\w+),(\s\w+)(\s\w+)?(\s\w+)?","$2$3$4 $1") => "John David Smith"
Regexp extract
returns the first substring that matches the expression
regexp_extract(value, regexp)
example
regexp_extract("https://www.thisisalink.com/page1/page2?parameter=test","https://(.*).com")
=> https://www.thisisalink.com
Regexp match
check if an expression matches the statement
regexp_match(value, regexp)
example
regexp_match("Hello World","[a-zA-Z]{5}") => true
Safe index
returns element at specified index from string array
safe_index(array, index)
example
safe_index(["This","is","a","sentence"], 2) => "a"
returns an empty string if the index is out of bound
negatives indexes count from the end of the array
Upper
convert a string to uppercase
upper(string)
example
upper("This is a sentence") => "THIS IS A SENTENCE"
Lower
convert a string to lowercase
lower(string)
example
lower("This is a sentence") => "this is a sentence"
Trim
remove leading and trailing whitespace
trim(string)
example
trim(" This is a sentence ") => "This is a sentence"
Mapping
returns the value of a another mapping
mapping(string)
example
mapping("targetCountry") => "EN"
If
if expression is not empty returns true_result, else returns else_result
if(expression, true result, false result)
example
if("expression", "this result exists", "this result is empty") => "this result exists"
Contains
check if a string contains a substring
contains(string, substring)
example
contains("This is a sentence", "sentence") => true
Length
returns the length of a string
len(string)
example
len("sentence") => "8"
returns the length of an array
len(array)
example
len(["431", "649", "233", "865", "903", "129", "451"]) => "7"
String
convert an integer to string
str(integer)
example
str(56) => "56"
convert a decimal to string
str(decimal)
example
str(34.74) => "34.74"
convert a boolean to string
str(boolean)
example
str(3 > 4) => "false"
Int
convert a string to an integer
int(string)
example
int("56") => 56
convert a decimal to an integer
int(decimal)
example
int(34.74) => 34
convert a boolean to an integer
int(boolean)
example
int(3 > 4) => 0
Float
convert an integer to a decimal
float(integer)
example
float(56) => 56.0
convert a string to a decimal
float(string)
example
float("34.74") => 34.74
convert a boolean to decimal
float(boolean)
example
float(3 > 4) => 0.0
Query params
extract a parameter from a URL
query_param(url, param)
example
query_param("https://www.test.com/?utm_campaign=christmas", "utm_campaign") => "christmas"
The next functions will be Math functions. All results using them will be fixed at 2 decimals
Round
round a decimal to a given precision
round(decimal, precision)
example
round("10.67") => "11.00"
round("8.23") => "8.00"
round a decimal with zero precision
round(decimal)
example
round("10.67") => "11.00"
round("8.23") => "8.00"
Ceil
returns the least integer value greater than or equal to the given number
ceil(float(string))
example
ceil("10.67") => "11.00"
Floor
returns the least integer value less than or equal to the given number
floor(float(string))
example
floor("10.67") => "10.00"
Min
returns the smaller of two given numbers
min(float(string), float(string))
example
min("24.48", "98.11") => "24.48"
Max
returns the larger of two given numbers
max(float(string), float(string))
example
max("24.48", "98.11") => "98.11"
Random
returns a random number between 0 and 1
random()
example
round(random()*100) => 47
If Else
returns a value if the condition is true or false
if (condition) {
expression
} else {
expression
}
example
if (feed(1,"category") == "cap" || feed(1,"category") == "beanie") {
"Tops"
}
else {
"Others"
}
Switch
returns a value according to the result equals to the condition
switch (result)
{
case condition: display
case condition: display
...
default: display
}
example
switch (true)
{
case feed(1,"price") >= feed_percentile(1,"price",500.0): "High"
case feed(1,"price") >= feed_percentile(1,"price",250.0): "Medium"
default: "Low"
}
JSON Create
convert a text to a JSON object or array
json_create(string)
example
json_create("{\"name\":\"list\",\"data\":[{\"element\":\"water\",\"color\":\"blue\"},{\"element\":\"fire\",\"color\":\"red\"}]}")
=>
{
"name": "list",
"data": [
{
"element": "water",
"color": "blue"
},
{
"element": "fire",
"color": "red"
}
]
}
JSON Stringify
convert a JSON object or array to a string
json_stringify(object/array)
example
json_stringify(
{
"name": "list",
"data": [
{
"element": "water",
"color": "blue"
},
{
"element": "fire",
"color": "red"
}
]
}
)
=> "{"name":"list","data":[{"element":"water","color":"blue"},{"element":"fire","color":"red"}]}"
JSON Path
extract a value using JSON Path language
json_path(string, expression)
example
json_path({"A":{"B":"b"}}, "$.A.B")
=> "b"
Exec_js
executes a javascript script and returns the last expression
exec_js(script)
example
exec_js("var i = Math.floor(Math.random() * 100);if(i<=49){var j=\"ori1\"}else{var j=\"ori2\"};j") => ori2