Functions

Functions are self-contained blocks of code that can be invoked at any point to compute and retrieve specific data or results. Supernova comes with dozens of pre-defined functions that help you to obtain the data from the Design System Model and some that help with additional tasks such as comparing values to other values, generating random test data, and many more.

Syntax

Each function call starts with @ symbol and is invoked using () brackets. For example, this is how you obtain all the data about all the tokens inside targeted design system:

{[ let tokens = @ds.allTokens() /]}

This creates a new variable tokens that is filled with data about all the screens in the current project. Function allTokens doesn't take any input parameters, so its invoked only with ().

Input parameters

In some cases, functions require input parameters to be provided. For example, this is how you obtain data about a specific screen in the current project:

{[ let token = @ds.tokenById(tokenId) /]}

This again creates a new variable token that is filled with data about a specific token. We have specified which token by providing tokenId to the function call.

Multiple input arguments

Some functions also require more than just one input argument. In this case, you separate them with , . Note that spaces between arguments are ignored, so we recommend writing them after each separator, which helps readability a lot:

{[ let result = @multiArgumentFunction(arg1, arg2)

Variadic functions

Some functions you'll encounter are variadic. This means that they take any number of input parameters and they all contribute to the output of the function. A good example is @boolean.and function used for boolean operations:

{[ let isPartialSuccess @boolean.and(result1, result2) /]}
{[ let isSuccess @boolean.and(result1, result2, result3, result4) /]}

@boolean.and is a variadic function and you can use it to test whether all parameters are true - be it 2 in the first definition, or 4 in the second one.

Custom functionality

Missing some functionality Pulsar is not covering? You can extend the language capabilities by using javascript and provide your own functions, transformers, or even test and configuration data. We dedicate an entire chapter to this topic.

pageUsing Javascript

Last updated