Functions & Macros
Macros and functions supported by the design automation engine
We have a bank of predefined functions and you can find the functions in the doc below.
A simple example exercise before we begin-
{{variable_to_assign_to}} = UPPER({{variable_to_apply_to}})
//you can also chain functions like -
{{variable_to_assign_to}} = LOWER(STRIP("HELLO "))
//you can have multiple inputs in functions, that may or may not be variables -
{{variable_to_assign_to}} = MIN(3,4,2,8,9)
//You can also have multiple returned values from a function call (depends on what the function returns) -
{{first name}}, {{last name}} = SPLIT("Adolf Lincoln", " ", 2)
The parameters for a function that you want to use goes inside () i.e parenthesis.
If you are doing nested function calls, then the () or parenthesis needs to be balanced otherwise while compiling, it will throw an error.
Functions might return more than one outputs (eg: SPLIT)
How to use this guide-
We made it super easy for you, below are the examples, just copy the code snippet of your desired function & replace it with your intended values, in the mason code editor!
Note -
In order to use a function, you need to write the function name exactly as is in the below doc
The order of parameters passed to the function matters and should be in sync with the function definitionLayer ids can be acquired by clicking on the layer once in the code editor
denoted here below as <layer_id> where needed.
The <input_column_to_apply_to> is the column you want to apply this operation or function to (in your input sheet).
Available Functions
These functions are kept very similar to string/ text manipulations in most languages
Text manipulations
UPPER
upper Takes a string as input and changes into uppercase
{{<layer_id>.text}}=UPPER({{<input_column_to_apply_to>}})
LOWER
lower Takes a string as input and changes into lowercase
{{<layer_id>.text}}=LOWER({{<input_column_to_apply_to>}})
SUBSTITUTE
Substitute Takes a string, what to substitute from and to and substitutes in the string
{{<layer_id>.text}}=SUBSTITUTE({{<input_column_to_apply_to>}}, "<word_to_replace>", "<word_to_replace_it_to>")
STRIP
Strip Takes a string and what you want to strip of from the string as input and returns the updated string
{{<layer_id>.text}}=STRIP("{{<input_column_to_apply_to>}}", ",")
LEN
Len Takes a list/ string as input and returns the length
{{<layer_id>.text}}=LEN({{<input_column_to_apply_to>}})
MIN
Min Takes a list/ string, series of values as input and returns the minimum value
{{<layer_id>.text}}=MIN({{<comparator_1>, <comparator_2>, <comparator_3>}})
MAX
Max Takes a list/ string, series of values as input and returns the MAXIMUM value.
{{<layer_id>.text}}=MAX({{<comparator_1>, <comparator_2>, <comparator_3>}})
RIGHT_STRIP
What it does: takes a string and what you want to strip off from the string as input and strips that off from the right.
{{<layer_id>.text}}=RIGHT_STRIP({{<input_column_to_apply_to>}}," .")
LEFT_STRIP
What it does: takes a string and what you want to strip off from the string as input and strips that off from the left.
{{<layer_id>.text}}=LEFT_STRIP({{<input_column_to_apply_to>}}," .")
TRIM
What it does: Removes all extra spaces at the start and end of string and removes more than one adjacent occurrence of spaces
{{<layer_id>.text}}=TRIM({{<input_column_to_apply_to>}})
GET_TEXT_OUTSIDE_PARENTHESIS
What it does: Takes a string as input and returns text outside parenthesis
how to use: GET_TEXT_OUTSIDE_PARENTHESIS(text)
{<layer_id>{.text}}=GET_TEXT_OUTSIDE_PARENTHESIS({{<input_column_to_apply_to>}})
GET_TEXT_INSIDE_PARENTHESIS
What it does: Takes a string as input and returns text inside parenthesis
how to use: GET_TEXT_INSIDE_PARENTHESIS(text)
{<layer_id>{.text}}=GET_TEXT_INSIDE_PARENTHESIS({{<input_column_to_apply_to>}})
WRAP_TEXT
This method expects the following things : text, height, width, font_url, max_font_size
max_font_size is optional
{{<layer_id>.text}}, {{<layer_id>.fontSize}} = WRAP_TEXT({{<input_column_to_apply_to>}}, 100, 500,"<font_file.ttf>", 20)
STARTS_WITH
What it does: This method expects a string and a text and checks whether the string starts with the text
How to use: STARTS_WITH(String, text)
{{<layer_id>.text}}=STARTS_WITH({{<input_column_to_apply_to>}},"<comparator_text>")
ENDS_WITH
What it does: This method expects a string and a text and checks whether the string ends with the text
How to use: ENDS_WITH(String, text)
{{<layer_id>.text}}=ENDS_WITH({{<input_column_to_apply_to>}},"<comparator_text>")
Numeral manipulations
RANDOM
Takes in a series of values and returns a random value out of them, see the example below -
{{<layer_id>.text}}=RANDOM({{<comparator_1>, <comparator_2>, <comparator_3>}})
CHECK_ODD_EVEN
What it does: This method expects either a numeric string or integer and returns 0 if the input is even and 1 if the input is odd.
How to use: CHECK_ODD_EVEN(input)
{{<layer_id>.text}}=CHECK_ODD_EVEN({{<input_1>}})
GET_FK_DATA
What it does: This method expects fsm_id and returns the image URL
How to use: GET_FK_DATA("fsn_id")
More coming soon!
We are working on adding reusable examples for each function and exposing more such functions through the inference.
Updated about 3 years ago