Expressions

With expressions you can take interactions to a completely different level and make your prototype resemble a fully working product by form validation, computational components like shopping carts, or checking if a password meets certain criteria.

Since expressions are a part of interactions, you can use them for setting content of elements, creating conditions or performing operations on variables.

Writing Expressions

Below are the types of data that you can use in expressions with descriptions:

  • numbers — actual values, e.g. 5, 10, 15.
  • strings — text specified in double quotation marks, e.g. “Text”
  • variables — variables added to the prototype, e.g. $variable_name.
  • content of elements — content of an element specified in single quotation marks, e.g. ‘Box’.
  • function — any of the supported functions e.g. length(string).
  • boolean values — true or false value.

Choosing an expression as part of the interaction automatically displays the list with available variables, elements on canvas and all supported functions. To access the list while writing, type $ for variables, ‘ for elements and the first letters for functions.

Since you can mix different types of data in a single expression, it’s important to use the right syntax, depending on the type.

For each function, you will need to provide the specific type of arguments in the brackets. However, some arguments may be optional — they will be marked with a question mark in the description, e.g. time (format?). In some functions such as min (number, number, …) you’ll be able to add an unlimited number of arguments.

Compound Expressions

You can combine different types of data in a single expression. Let’s take simple math operations as an example — to perform them you can use exact numbers or the content of the given element or variable if they store numbers.

You can also take this step further and use several functions at once.

Consider creating a login from an email address provided by a user in the Input 1 element. To shorten the email and display only the characters before the @ sign, use these 2 functions:

indexOf(string, searchString)

Use it to determine the position of the @ character in the email.

left(string, number)

Use it to return the given number of the characters from the email, starting from the left side.

The expression will look like this:

left('Input 1', indexOf('Input 1', "@"))

Additionally, if you want the login to be displayed as lowercase only, you can add another function:

lowerCase(left('Input 1', indexOf('Input 1', "@")))

Common Functions

Expressions include a variety of functions which can be used in different scenarios. However, in the majority of cases, you need to use a combination of the most common functions to achieve the desired effects.

Numbers

To perform basic math operations, just use the arithmetic operators such as + for addition, for subtraction, / for division and * for multiplication.

Other common math functions include:

  • round(number) — It rounds the number to the nearest whole number. This is especially useful while working with monetary values.
  • random(min,max) — It gives you a random number from the specified range.

Text

Text functions can transform text strings. The most common functions include:

  • length(string)

It gives the number of characters in a string.

  • format (string|number,format) — It returns the string or number in the specified format.
  • replace(string, pattern, replace) — It replaces the string with another string. This function can be used, for example, to remove the space from the text.

Date

Date functions allow performing different types of operations on the specified time units.

  • now(format?)

It returns the current date in the specified format. If you don’t provide any format, the date will be displayed as yyyy-mm-dd by default.

See the supported formats for date and time.

  • dateAdd(date, amount, unit?, format?)

It adds a given amount of time in the specified unit (days, months, years) to the provided date. This can be used for displaying messages specifying periods of time, such as The promo offer ends in X days.

  • dateIsAfter(firstDate, secondDate, precision)

It checks if the first date is after the second date using the specified unit of time (year, month, week, day). This function is useful whenever you need to display a message based on the user’s date of birth.

Regex

The regex function uses regular expressions (regexp) to validate if the text matches the given expression. Regexps basically define search patterns for strings — they can be anything from a simple character, a fixed string or a complex expression containing special characters describing the pattern. Read more about regular expressions here.

Use the regex function whenever you need to check if the text provided in the prototype by users matches the specific patterns. This way you can create validation forms which check whether all the password requirements have been met. For example, a password has a specified minimum amount of characters or the characters used are alphanumeric. Similarly, you will be able to verify if the provided text is a correct email address or URL.

The regex function has the following syntax: regex(regexp, string). It returns the true or false boolean value depending on the result of the check.

The regex function has the following syntax: regex(regexp, string). It returns the true or false boolean value depending on the result of the check.

When using regex in the expressions, it’s always worth validating if the regular expression is written properly. You can do this by using one of the online regexp validators, such as regex101.com.

Supported functions

Below is a full list of supported functions and their syntax.

Text

  • contains(string, searchString) — checks whether the string contains the search string.
  • startsWith(string, searchString) — checks whether the string starts from the specified characters; it returns true or false value.
  • endsWith(string, searchString) — checks whether the string ends with the specified characters; it returns true or false value.
  • replace(string, pattern, replace) — replaces string with another string.
  • concat(string, string, …) – combines the texts of provided strings and returns a new string.
  • trim(string) — trims the whitespaces from the beginning and the end of the string.
  • lowerCase(string) — returns the text in all lowercase.
  • upperCase(string) — returns the text in all uppercase.
  • capitalize(string) — returns the text with the first letter capitalized.
  • indexOf(string, searchString) — returns the position of the search string in the primary string.
  • left(string, number) — returns a number of letters in a text, starting from the left side.
  • right(string, number) — returns a number of letters in a text, starting from the right side.
  • length(string) — returns the number of the characters in a string.
  • substring(string, start, length) — returns the part of the string, starting at the specified index and extending for a given number of characters afterward.
  • execute(string) — executes the expression provided in a string.
  • toString(value) — returns the element as a string.
  • regex(regexp, string) — checks whether string matches the regular expression.

Numbers

  • min(number, number, …) — returns the minimum number from the selected numbers.
  • max(number, number, …) — returns the maximum number from the selected numbers.
  • round(number, precision?) — rounds the number to the nearest whole number.
  • floor(number) — returns the largest integer less than or equal to a given number.
  • ceil(number) — returns the smallest integer greater than or equal to a given number.
  • trunc(number) — returns the integer part of a number by removing any fractional digits.
  • pow(base, exponent) — returns the power of the specified exponent.
  • sqrt(number) — returns the square root of a number.
  • log(number) — returns the natural logarithm of a number.
  • abs(number) — returns the absolute value of a number.
  • sin(number) — returns the sine of a number.
  • cos(number) — returns the cosine of a number.
  • tan(number) — returns the tangent of a number.
  • asin(number) — returns the arcsine of a number.
  • acos(number) — returns the arccosine of a number.
  • atan(number) — returns the arctangent of a number.
  • avg(number, number,…) — returns the average value of the selected numbers.
  • median(number, number,…) — returns the median of the selected numbers.
  • random(min, max) — gives you a random number from the specified range.
  • isBetween(number, start, end) — checks whether the number is a part of the specified range.
  • isNotBetween(number, start, end) — checks whether the number is not a part of the specified range.
  • toNumber(value) — returns the element as a number.
  • toFixed (string|number,digits) — returns the string representing the given number with the provided number of digits after a decimal point.

Date

  • now(format?) — returns the current date in the specified format; the default format is yyyy-mm-dd.
  • time(format?) — returns current time in the specified format; the default format is hh:mm:ss.
  • date(format?) — returns date in the specified format; the default format is yyyy-mm-dd.
  • dateAdd(date, amount, unit?, format?) — adds the given amount of time in the specified unit (days, months, years) to date.
  • dateSubtract(date, amount, unit?, format?) — subtracts the given amount of time in the specified unit (days, months, years) from date.
  • dateDiff(date, date, unit?) — returns difference between dates in the specified unit of time.
  • dateIsAfter(firstDate, secondDate, unit?) — checks if the first date is after the second date using the specified unit of time (year, month, week, day).
  • dateIsBefore(firstDate, secondDate, unit?) — checks if the first date is before the second date using the specified unit of time (year, month, week, day).
  • dateIsBetween(date, startDate, endDate, unit?) — checks if the date is part of the specified time between the start and end dates using the specified unit of time (year, month, week, day).

Browser

  • windowWidth() — returns the width of the browser window viewport including, if rendered, the vertical scrollbar.
  • windowHeight() — returns the height of the browser window viewport including, if rendered, the horizontal scrollbar.
  • windowScrollX() — gives the position on x-axis (in pixels) that the document is currently scrolled to.
  • windowScrollY() —gives the position on y-axis (in pixels) that the document is currently scrolled to.
  • deviceOS()— returns the operating system type.

Prototype

  • prototypeName() — returns the name of the prototype.
  • pageName() — returns the name of the current page.
  • pageNumber() — returns the numeric order of the current page in the sitemap.
  • pagePath() — returns the path of the current page, where path reflects the position of the page in the sitemap hierarchy.
  • canvasWidth() — returns the width of the canvas.
  • canvasHeight() — returns the height of the canvas.