D
D
Developers
Search…
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:
1
{[ let tokens = @ds.allTokens() /]}
Copied!
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:
1
{[ let token = @ds.tokenById(tokenId) /]}
Copied!
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:
1
{[ let result = @multiArgumentFunction(arg1, arg2)
Copied!

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:
1
{[ let isPartialSuccess @boolean.and(result1, result2) /]}
2
{[ let isSuccess @boolean.and(result1, result2, result3, result4) /]}
Copied!
@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.
Last modified 6mo ago