RatMinimal web framework

Strings

The string builtins cover the basics every web app needs: case folding, whitespace trimming, splitting and joining, substring search and replace, prefix and suffix checks, padding for column alignment, and a positional format for templated output. Every call behaves the same on the server (during > server evaluation) and in the browser (inside handlers). Same name, same result.

upper / lower

Case folding, ASCII + Unicode aware

upper(s) and lower(s) return a new string with the case folded. They handle Unicode, so accented characters and non-Latin scripts round-trip correctly.

<p> [upper('hello')]
<p> [lower('WORLD')]
Result

HELLO

world

trim: strip leading and trailing whitespace

Inner spaces are preserved

trim(s) removes whitespace (spaces, tabs, newlines) from both ends of the string. Use it to clean up form input before validation. Inner whitespace is left alone, so reach for regex.replace when you need to collapse runs.

<p> ([trim('  hi  ')])
Result

(hi)

split / join

Two halves of the same conversion

split(s, sep) cuts a string on a delimiter into an array. join(arr, sep) is the inverse: it turns an array of strings into a delimited string. Together they let you reshape "list-as-string" data without writing a loop.

<p> [split('a,b,c', ',')]
<p> [join(items, ' / ')]
Result

split: [a, b, c]

join: apples / pears / figs

replace: all occurrences

No regex, no special chars

replace(s, from, to) swaps every occurrence of a literal substring. There are no escape rules: every character is matched literally. For pattern-based replacement, use regex.replace from the regex namespace.

<p> [replace('foo bar foo', 'foo', 'baz')]
Result

baz bar baz

starts_with / ends_with / contains

Three substring predicates, return booleans

Each takes the haystack first and the needle second, returning true or false. contains also works on arrays (element membership) and objects (key membership), handy when the data shape changes between two call sites.

<p> [starts_with('hello world', 'hello')]
<p> [ends_with('hello world', 'world')]
<p> [contains('hello world', 'lo wo')]
<p> [contains(items, 'pears')]
Result

starts: true

ends: true

contains string: true

contains array: true

pad_left / pad_right

Fixed-width alignment for tables and IDs

pad_left(s, width, char) prepends the pad character until the result is the requested width; pad_right appends instead. If the input is already at or over the width, it's returned unchanged. A common use is zero-padding numeric IDs for sortable filenames.

<p> ([pad_left('7', 3, '0')])
<p> ([pad_right('7', 3, '.')])
Result

pad_left: (007)

pad_right: (7..)

repeat: join N copies

Separators, ASCII art, progress bars

repeat(s, n) joins n copies of s into one string. Useful for rules in plain-text output, leader dots, or progress bars.

<p> [repeat('ab', 3)]
<p> [repeat('-', 20)]
Result

ababab

--------------------

format: positional placeholders

{} consumes args in order; no named slots

format(template, args...) substitutes each {} with the next argument. There are no named or indexed slots: order is the contract. The format spec mirrors the simplest subset of Python f-strings on purpose, so reach for string concatenation when you need anything richer.

<p> [format('hi {}', 'world')]
<p> [format('{} + {} = {}', 1, 2, 3)]
Result

hi world

1 + 2 = 3

See also Conversion · Encoding · Regex