Learn Lua · Numbers and text · Lesson 3 of 4
Reshaping text
The text library reshapes strings. text.slug makes text safe for a web address or a
file name, text.title capitalises each word, and text.truncate shortens long text:
text.slug("Spring Flyers 2026!") --> "spring-flyers-2026"
text.title("spring flyers") --> "Spring Flyers"
text.truncate("Spring flyers", 6) --> "Spring…"text.truncate keeps the first characters and adds "…" when it cuts something off.
Text that's already short enough comes back unchanged.
What your code receives
Your code gets its data as input. The type Input line at the top of the code lists every field, and the editor uses it to suggest field names and spot typos. Here is an example. Each check sends different values, so work from the fields rather than these exact values.
input = { name = "spring flyers 2026!", description = "A5 flyers on silk paper, printed both sides" }Steps
- Return
slug:input.nameas a slug. - Add
heading:input.namewith each word capitalised. - Add
preview: the first 20 characters ofinput.description, followed by "…" when it was longer.
Show a hint
Each field is one call to a text function. Try your code with a description shorter
than 20 characters too.