Repository navigation
standard library
Made by warp help --markdown from lib/*.wasp: each module with its words, a word with the comment line above it. A module comes with use <module>; the prelude needs none.
The prelude (notes/stdlib.md §8): words every program has without use; only those it calls come along. Each is name(parameters) := body (modules::prelude_word_arity reads the parameters); library_words maps other spellings and method forms onto them (isdigit(c), xs.first(), round(x, 2) → round_to)
first(xs)last(xs)-
round_to(x, places): x rounded to that many digits after the point replace(t, old, new)-
is_digit(c): ASCII character tests; a character compares by its code point is_alpha(c)is_alphanumeric(c)
Linear memory by its bytes (samples/wasm_interop.wasp): memory.slice(ptr, end) reads the bytes ptr…end-1, memory.copy(bytes, ptr) writes them from ptr on; addresses are 0-based byte offsets
The standard library module net (notes/stdlib.md section 7): use net; fetch (GET) is a prelude word. post sends a text through the adapter std_io and gives the answer's text (ureq natively, a synchronous request in the browser)
post(url:any, body:any)
The standard library module collections (notes/stdlib.md): use collections, classes over a list field
class Stackclass Queueclass Dequeclass Setclass Counter-
OrderedMap(): wasp maps keep insertion order: an ordered map is a map
The standard library module hash (notes/stdlib.md section 7): use hash, through the adapter std_pure, of a text's UTF-8 bytes: sha256 as lowercase hex, crc32 as a number
sha256(subject:any)crc32(subject:any)
The standard library module regex (notes/stdlib.md section 7): use regex, through the adapter std_pure: Rust's regex natively, JS RegExp in the browser, held to what both do alike (no look-around, no backreferences)
matches(subject:any, pattern:any)first_match(subject:any, pattern:any)find_all(subject:any, pattern:any)replace_all(subject:any, pattern:any, replacement:any)
The standard library module file (notes/stdlib.md section 7): use file, or a file URL in the program (P183). read, write and exists are prelude words (P171), the rest needs the module; append is written file.append(path, text). They call the adapter std_io: the file system natively, the page's in-memory files in the browser
write(path:any, text:any)append_file(path:any, text:any)exists(path:any)list_files(folder:any)lines(path)
The standard library module json (notes/stdlib.md section 7): use json. Wasp data is a superset of JSON; the adapter std_pure parses and writes it (serde_json natively, JSON.parse / JSON.stringify in the browser)
parse_json(text:any)to_json(value:any)-
to_json_of_classes(value:any, classes:any): to_json in a program with classes (class_methods lower_json_classes): an instance is its fields
The standard library module os (notes/stdlib.md section 7): use os, through the adapter std_io; the browser has no environment (env gives ø)
env(name:any)
The standard library module list (notes/stdlib.md): use list
unique(xs)zip(a, b)enumerate(xs)product(xs)mean(xs)take(xs, n)drop(xs, n)flatten(xs)chunk(xs, n)window(xs, n)median(xs)flat_map(xs, f)-
partition(xs, f): [kept, rest]: the elements f holds for, and the others max_by(xs, f)min_by(xs, f)-
group_by(xs, f): {key: [elements]}: the elements by the text of f's value -
tally(xs): {element: how often} zip_with(a, b, f)sum_by(xs, f)count_by(xs, f)-
rotate(xs, n): the elements moved n places to the left interleave(a, b)-
dedupe(xs): without runs of equal neighbours -
scan(xs, start, f): the running results of f: scan([1, 2, 3], 0, (a, b) => a + b) is [1 3 6] take_while(xs, f)drop_while(xs, f)-
argmax(xs): the index (from 0, like xs[i]) of the greatest element, the first of equal ones argmin(xs)-
pairwise(xs): the neighbours: pairwise([1, 2, 3]) is 1 2] [2 3 -
split_at(xs, n): [the first n, the rest] -
cartesian(a, b): every pair of an element of a and one of b -
mode(xs): the most frequent element, the first of equally frequent ones -
variance(xs): the population variance and standard deviation stdev(xs)-
index_where(xs, f): the position (from 1, like index_of) of the first element f holds for, 0 when none does last_n(xs, n)-
fill(n, value): n copies of value: fill(3, 0) is [0 0 0] -
minmax(xs): [smallest, greatest]
The standard library module math (notes/stdlib.md): use math, together with the C library libm
gcd(a, b)lcm(a, b)clamp(x, low, high)sign(x)-
round_to(x, digits): x rounded to the given number of decimal places: round_to(3.14159, 2) is 3.14 factorial(n)is_prime(n)-
lerp(a, b, t): the value a fraction t of the way from a to b is_even(n)is_odd(n)-
digits(n): the decimal digits of a whole number: digits(1234) is [1 2 3 4] -
choose(n, k): the number of ways to choose k of n (the binomial coefficient) -
mod_pow(base, exponent, modulus): base^exponent % modulus without the huge power -
percent(part, whole): part as a percentage of whole: percent(1, 4) is 25 to_radians(degrees)to_degrees(radians)-
isqrt(n): the whole square root, rounded down is_square(n)divisors(n)prime_factors(n)-
to_base(n, base): the digits of n in a base up to 36: to_base(255, 16) is "ff" from_base(t, base)-
square(x): P169/P191: descriptive names; they forward to the C library (use cmath) until wasp has its own implementations. square_root(x)cube_root(x)power(base, exponent)exponential(x)natural_log(x)binary_log(x)decimal_log(x)-
logarithm(x, base): the logarithm of x to any base: logarithm(8, 2) is 3 sine(x)cosine(x)tangent(x)arc_sine(x)arc_cosine(x)arc_tangent(x)-
angle(x, y): the angle of the point (x, y) from the x axis, in radians: C's atan2(y, x) hyperbolic_sine(x)hyperbolic_cosine(x)hyperbolic_tangent(x)-
hypotenuse(a, b): the length of the long side of a right triangle with sides a and b ceiling(x)-
whole_part(x): x without its fraction, toward zero: whole_part(-2.5) is -2 -
remainder(a, b): what remains of a after taking out b as often as it fits, with the sign of a (C's fmod)
The standard library module text (notes/stdlib.md): use text
repeat(t, n)pad_left(t, width)pad_right(t, width)-
format(template, values): format("{} has {} items", ["cart", 3]): each {} takes the next value -
words(t): the words between runs of spaces lines(t)capitalize(t)center(t, width)title(t)-
slug(t): lower case letters and digits, the rest as single dashes: "Hello, World!" → "hello-world" truncate(t, width)-
is_blank(t): only spaces, tabs and line breaks, or nothing -
is_upper(t): has letters, all upper (or lower) case is_lower(t)remove_prefix(t, prefix)remove_suffix(t, suffix)-
count_of(t, part): how often part occurs, not overlapping: count_of("banana", "an") is 2 is_palindrome(t)word_count(t)-
snake_case(t): "helloWorld", "Hello World", "hello-world" → "hello_world" kebab_case(t)-
camel_case(t): "hello_world" → "helloWorld" -
indent(t, n): each line indented by n spaces -
is_numeric(t): a whole or decimal number, optionally signed: "12.5", "-3" -
between(t, opening, closing): the text between the first opening and the next closing after it, "" when either is missing -
wrap(t, width): the words in lines of at most width characters
The standard library module random (notes/stdlib.md): use random, over the host words random and random_below
choice(xs)shuffle(xs)sample(xs, k)-
seed(n): the same numbers after the same seed: seed(42); [random_below(100), random()]
The standard library module map (notes/stdlib.md): use map
merge(a, b)map_values(m, f)-
invert(m): {a:1 b:2} → {1:"a" 2:"b"}: the values become the keys -
pick(m, wanted): only the entries of the given keys that m has -
from_pairs(pairs): "a", 1] ["b", 2 → {a:1 b:2} -
omit(m, unwanted): the entries of m without the given keys -
filter_values(m, f): the entries whose value f holds for -
entries(m): {a:1 b:2} → "a", 1] ["b", 2, the opposite of from_pairs -
get_or(m, key, fallback): the value of key, or fallback when m has none -
find_key(m, f): the first key whose value f holds for, ø when none
The standard library module time (notes/stdlib.md): use time, the calendar over clock() (milliseconds since 1970, UTC)
day_number(ms)-
date_of(ms): Howard Hinnant's civil_from_days: the proleptic Gregorian date of a day number -
weekday(ms): ISO weekday: Monday 1 … Sunday 7 today()add_days(ms, n)days_between(from, to)two_digits(n)-
format_date(ms): ISO 8601: 2026-10-07 -
format_time(ms): the time of day, UTC: 13:05:09 -
days_from_date(year, month, day): Howard Hinnant's days_from_civil: the day number of a proleptic Gregorian date -
parse_date(t): "2026-10-07" → milliseconds since 1970 at midnight UTC -
format_duration(ms): milliseconds as the largest units: 5430000 → "1h 30m 30s", 250 → "250ms" is_leap_year(year)days_in_month(year, month)
The standard library matrix module (notes/stdlib.md): use matrix. A matrix is a list of rows: m[i][j] (m#i#j) reads and writes an element, printing and equality are those of lists. Locals are var: a program's own m or row stays apart from them
matrix(r, c, f)filled_matrix(r, c, v)zeros(r, c)ones(r, c)random_matrix(r, c)identity(n)rows(m)cols(m)shape(m)transpose(m)matrix_add(a, b)scale(m, k)map_matrix(m, f)dot(u, v)matmul(a, b)
The standard library module draw (notes/stdlib.md, card drawing-words): use draw, a canvas of colored pixels shown by paint (the playground's canvas, natively a PNG). A color is a number 0xAARRGGBB: rgb, hsv, the named colors, with_alpha
-
paper: paper: the canvas before anything is drawn, as paint shows 0 (src/paint.rs PAPER) blackwhitegrayredgreenblueyelloworangepurple-
cell(v): the pixel a coordinate falls in -
rgb(r, g, b): r, g, b from 0 to 255 -
with_alpha(color, alpha): alpha from 0 (invisible) to 1 (opaque) alpha_of(color)-
channel_mix(color, under, a, place): one channel (its place 65536, 256 or 1) of color over under, by alpha a from 0 to 255
The standard library module markup (card web-ssr, notes/web_framework.md "Built sites"): use markup (not html, which samples/html.wasp would shadow). to_html(value) is the HTML of a markup value, div{ class:"box" h1{"Hi"} } →
style: { fontSize: 12 } inline CSS), anything else a child in order.
html_elements-
html_void_elements: elements without content or closing tag html_attributes-
html_boolean_attributes: attributes that are present or absent:checked: done -
html_unitless_properties: CSS properties whose number has no unit; any other number is pixels to_html(value:any)-
html_render(value:any, scope:any):scope: the component whose elements a style sheet styles (data-wasp-scope, card web-scoped) html_is_element(value:any)html_element(tag:any, content:any, scope:any)-
html_items(content:any): the items of an element's block, or its one item -
html_is_attribute(item:any, tag:any):class:"box"inside an element: an attribute when its name is one and its value plain (or inline CSS for style) -
html_holds_pairs(value:any):class:["btn" "btn-info"]is an attribute,style{ ".card": {…} }an element: its items are rules html_attribute(item:any)-
html_attribute_name(name:any):li{ key: todo.id … }names a list item: the attribute data-wasp-key, by which the page moves its element -
html_is_declarations(value:any):{ color: theme padding: 8 }: a block of CSS properties with plain values -
html_css(value:any):color: red; padding: 8px: camelCase names in kebab-case, numbers in pixels unless the property has no unit -
html_css_value(property:any, value:any): a number in pixels unless the property has no unit -
html_style_rule(rule:any, scope:any):style{ ".card": { padding: 8 } }: a ruleselector { declarations }; a text is CSS as written -
html_scoped(selectors:any, scope:any):h2, pin the component Card:[data-wasp-scope="Card"] h2, [data-wasp-scope="Card"] p html_kebab(name:any)-
html_attribute_value(value:any):class:['btn' 'btn-info']is the attributebtn btn-info -
html_plain(value:any): a value as the text it shows: a text without quotes, anything else as wasp writes it html_is_true(value:any)html_escaped(text:any)
The standard library module router (card web-router, notes/web_framework.md "Routes"): a route pattern "/users/:id" matches the path "/users/7" with the parameter id = 7; "" matches any path (the not-found page). A parameter may declare its type (card route-typed): ":id:int" matches digits only, ":price:float" a decimal number, ":name:text" any part, given as text even when it is digits. The browser's URLPattern syntax too (card route-urlpattern): the last part may be optional (":tab?", ø when absent) or take the rest of the path (":path" zero or more parts, ":path+" one or more, joined by "/"; "*" unnamed); lowering/routes.rs checks a parameter's regular expression (":id(\d+)"), which matches any part here. lowering/routes.rs makes each route "…" {…} of a page a function and picks the first one matching page_path().
route_segments(path:any)route_matches(pattern:any, path:any)-
route_segment(pattern:any, path:any, name:any): the part of the path the parameter:nameof the pattern stands for, as text; ø when the pattern has none -
route_parameter(pattern:any, path:any, name:any): the parameter:namewithout a declared type: a number when it is digits ("/users/7" gives id 7), else its text -
route_part_name(part:any): the name of the parameter a pattern part declares (":id:int", ":id(\d+)", ":id?" → "id"), "" for a fixed part -
route_part_type(part:any): the type a parameter declares (":id:int" → "int"), "" when it declares none (nor with a URLPattern mark or group) -
route_part_mark(part:any): how often the last part of a pattern may come (URLPattern): "?" at most once, "*" any number, "+" at least once, -
route_number(segment:any, dots:any): whether a path part is all digits, with at mostdotsdecimal points among them -
route_fits(kind:any, segment:any): whether a path part fits the declared type of its parameter
The standard library module i18n (card web-i18n, notes/i18n.md): use i18n. Translations are data, one map per language; a message is a text with {name} holes, or a map of plural categories (Unicode CLDR: zero one two few many other) chosen by the value count: messages = { en: { cart: { one: "{count} item", other: "{count} items" } }, de: { cart: { one: "{count} Artikel", other: "{count} Artikel" } } } translate(messages, "de", "cart", { count: 3 }) → "3 Artikel" A language the messages lack, or a message one language lacks, comes from the first language (de-AT reads de first).
translate(messages:any, language:text, key:text, values:any)-
i18n_message(messages:any, language:text, key:text): The message of a key: in the language, its base language (de for de-AT), else the first language -
i18n_plural_form(forms:any, category:text): A plural message's form for the category, else its form other -
i18n_filled(message:text, values:any): The text with each {name} replaced by the value named name -
plural_category(language:text, n:int): The CLDR plural category of a whole number in a language: "one", "few", "other", …