This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index at /llms.txt, or add .md to any page's URL.

Recipe: the standard functions

Every function an expression may call; bun exact.mjs contract vocab <name> has one's rules, or what to write for a name Contract lacks.
Every function an expression may call; bun exact.mjs contract vocab <name> has one's rules, or what to write for a name Contract lacks. The web's methods are called on their value (s.trim(), xs.length), the rest as functions (first(xs)).
Fix a function Contract does not have
Paste this into Claude, Cursor, Codex, or another agent.
•
Text: s.trim() · s.toLowerCase() · s.toUpperCase() · s.includes(t) · s.startsWith(t) · s.endsWith(t) · s.indexOf(t) · s.slice(start, end?) · s.split(sep) · s.replaceAll(find, with) · x.toString() · parseNumber(s) -> option<number> · encodeURIComponent(s).
•
Lists: x.length and x.isEmpty() (text too) · xs.map((x, i) => y) · xs.filter(x => bool) · first(xs) -> option<T> · xs.at(i) -> option<T> · xs.slice(start, end?) · xs.concat(ys) · xs.flat() · xs.includes(x) · xs.indexOf(x) -> number · xs.join(sep) · sum(xs) · sortBy(xs, x => key), stable · range(n).
•
Numbers: floor(n) · ceil(n) · round(n) · min(a, b) · max(a, b) · sin(rad) · cos(rad) · + - * / %.
•
Formatting: formatNumber(n, "decimal"|"percent"|"compact"), (n, "decimal", 1), (n, "currency", "USD") · n.toFixed(d) · formatDecimal(cents, 2) · formatDate(msOrDayKey, offset, "medium"|"month-year"|"month-day"|"iso") · formatTime(ms, offset, "short"|"2-digit"|"iso") · formatDay(then, now, offset, "day"|"list"|…) · calendarDiff(from, to, "years"|"months") · t("key", name=value).
•
Time: performanceNow(), ms since launch; the date is time.epochAtZero + performanceNow() (dates and days).
•
Routes: push(nav, location) · replace(nav, location) · back(nav) · go(nav, location) · open(nav, location) · select(nav, tab) · stack(nav) -> Entry[] · top(nav) -> Entry · depth(nav) · params(nav, name) -> string[] · searchParam(entry, name) · path("route", args…) · encodeRouteSegment(s).
•
Requests: pending(x) · failed(resource) · failure(resource) -> option<Failure>.
•
Values: some(x), none · Shape(field=value, …) · Shape(base, field=value) · empty(field=value) (a resource placeholder).
Host commands are statements: focus(id), blur(), showModal(id), close(id), copyText(s), openURL(url), share(…), haptic(…), scrollIntoView(id) (grammar); in actions, frame(id), measure("id") too.
What Contract omits is a composition or the data module's:
•
With p a predicate x => …: find is first(xs.filter(p)), some is xs.map(p).includes(true), every is not xs.map(p).includes(false), findIndex is xs.map(p).indexOf(true).
•
A count's noun follows the number: ${n} ${n == 1 ? "book" : "books"}, never "1 books" (lower-count-plural).
•
Grouping, folds and other maths (reduce, pow, abs) are the data module's. On screen, upper case is text-transform="uppercase"; s.toUpperCase() is for a string sent elsewhere (share, data).
Is this helpful
Last updated November 29, 2026
Exact Docs