Skip to content

Text

The text data type in Filtrera is used to represent string values. This reference guide provides a detailed specification of the text data type, its syntax, and usage for users already familiar with the concept.

Syntax

Literal text values are wrapped in single quotes.

Basic Syntax

let greeting = 'Hello, World!'

Single-quotes can be escaped:

from 'Hello, ''World!'''

Templates

Template texts can be used by prepending a $-sign to the text:

let name = 'Alice'
let greeting = $'Hello, {name}!'
from greeting

In this example, greeting will be 'Hello, Alice!'.

Escaping Curly Braces

To insert actual curly braces into a template, simply put two brackets:

let example = $'This is an example of double curly braces: {{example}}'
from example

In this example, example will be 'This is an example of double curly braces: {example}'.

Constraints

Literal

Primitive types in Filtrera can be further constrained. The most common constraint is a literal constraint. This means that a text type can define a specific text value. When combined with a Union, this allows you to specify a type of one of multiple literal text values.

Example

param status: 'active' | 'inactive' | 'pending'
let message = 'The current status is {status}.'
from message

In this example, status can only be 'active', 'inactive', or 'pending'.

Regular Expression Pattern

Regular Expression patterns can be used to create a more dynamic constraint. This is especially useful when combined with match.

Example

from input match
/hot dog/ |> 'It''s a 🌭'
/hot/ |> 'It''s something hot'
/dog/ |> 'It''s something dog-ish'

Summary

The text data type in Filtrera allows you to work with string values effectively. By understanding its syntax and usage, including variable insertion and escaping curly braces, you can create dynamic and flexible text outputs. Additionally, leveraging literal text types allows for more precise and controlled parameter definitions, enhancing the robustness of your Filtrera programs.