๐ Standard Library
Complete reference for built-in modules and functions
Built-in Functions
| Function | Description | Example |
|---|---|---|
echo(value) | Print to stdout | echo("Hello") |
to_string(value) | Convert to string | to_string(42) |
to_int(value) | Convert to integer | to_int("123") |
to_float(value) | Convert to float | to_float("3.14") |
Module: net
Networking and HTTP functionality.
Functions
http_server(host, port)- Create HTTP serverroute(server, path, handler)- Register routestatic(server, prefix, dir)- Serve static filesserve(server)- Start serverhttp_get(url)- HTTP GET requesthttp_post(url, body)- HTTP POST requestjson_response(json)- Create JSON response
Module: io
File I/O and stream processing.
Functions
read_file(path)- Read entire filewrite_file(path, content)- Write to fileopen(path, mode)- Open file streamclose(stream)- Close streamread_line(stream)- Read line from stream
Module: media
Audio and image processing.
Functions
load_audio(path)- Load audio fileload_image(path)- Load image fileconvert(output, format, bitrate)- Convert audioresize(width, height)- Resize imageapply_filter(name)- Apply image filter
Module: datetime ๐
Date and time handling for real-world applications.
Functions
| Function | Description | Example |
|---|---|---|
datetime.now() | Current timestamp as struct | datetime.now().year |
datetime.format(ts, fmt) | Format timestamp to string | datetime.format(now, "YYYY-MM-DD") |
datetime.parse(str, fmt) | Parse string to timestamp | datetime.parse("2025-03-01", "YYYY-MM-DD") |
datetime.unix(ts) | Get Unix timestamp | datetime.unix(now) |
datetime.from_unix(unix) | Create from Unix timestamp | datetime.from_unix(1772373508) |
datetime.add(ts, days, hrs, min, sec) | Add time to timestamp | datetime.add(now, 1) |
datetime.diff(ts1, ts2) | Time difference in seconds | datetime.diff(tomorrow, now) |
datetime.weekday(ts) | Day of week (0=Sunday) | datetime.weekday(now) |
Timestamp Struct Fields
.year- Year (2025).month- Month (1-12).day- Day (1-31).hour- Hour (0-23).minute- Minute (0-59).second- Second (0-59).unix- Unix timestamp
Module: regex ๐
Pattern matching and text manipulation using POSIX regex.
Functions
| Function | Description | Example |
|---|---|---|
regex.compile(pattern) | Compile regex pattern (cached) | regex.compile("\\d+") |
regex.match(regex, str) | Boolean match check | regex.match(p, "123") |
regex.findall(regex, str) | Find all matches | regex.findall(p, "a1b2") |
regex.search(regex, str) | First match with position | regex.search(p, "price: 99") |
regex.replace(regex, str, repl) | Replace matches | regex.replace(p, "a1", "X") |
regex.split(regex, str) | Split by pattern | regex.split(p, "a,b;c") |
regex.groups(regex, str) | Extract capture groups | regex.groups("(\\d+)", "abc123") |
Module: test ๐งช
Built-in testing framework with familiar assertions.
Test Structure
import test;
test.describe("My tests", blast() {
test.it("should work", blast() {
test.expect(1 + 1).toBe(2);
});
});
test.run();
Assertion Functions
| Function | Description |
|---|---|
test.describe(name, fn) | Define test suite |
test.it(name, fn) | Define test case |
test.expect(val).toBe(expected) | Strict equality |
test.expect(val).toEqual(expected) | Deep equality |
test.expect(val).toBeTruthy() | Truthy check |
test.expect(val).toBeFalsy() | Falsy check |
test.expect(val).toBeNull() | Null check |
test.expect(val).toBeGreaterThan(n) | Greater than |
test.expect(val).toBeLessThan(n) | Less than |
test.beforeEach(fn) | Setup before each test |
test.afterEach(fn) | Cleanup after each test |
test.run() | Execute all tests |
test.skip(name, fn) | Skip a test |
Module: env ๐
Environment variable access and system information.
Functions
| Function | Description | Example |
|---|---|---|
env.get(name) | Get environment variable | env.get("HOME") |
env.set(name, value) | Set environment variable | env.set("DEBUG", "1") |
env.has(name) | Check if variable exists | env.has("PATH") |
env.unset(name) | Remove environment variable | env.unset("DEBUG") |
env.list() | Get all variables as struct | env.list() |
env.paths() | Parse PATH into array | env.paths() |
env.home() | Get HOME directory | env.home() |
env.cwd() | Get current working directory | env.cwd() |
env.user() | Get current username | env.user() |
env.shell() | Get current shell | env.shell() |
Module: cli ๐ฅ๏ธ
Command-line argument parsing for CLI tools.
Functions
| Function | Description | Example |
|---|---|---|
cli.args() | Get raw argument array | cli.args() |
cli.program() | Get program name | cli.program() |
cli.count() | Get argument count | cli.count() |
cli.has_flag(name) | Check if flag present | cli.has_flag("--verbose") |
cli.flag(name) | Get flag value | cli.flag("--output") |
cli.flags() | Get all flags as struct | cli.flags() |
cli.args_after_flag(name) | Get args after flag | cli.args_after_flag("--") |
cli.parse(spec) | Parse with specification | cli.parse(spec) |
Module: csv ๐
CSV file parsing and generation for data processing.
Functions
| Function | Description | Example |
|---|---|---|
csv.parse(str) | Parse CSV string to array | csv.parse(data) |
csv.stringify(data) | Convert array to CSV string | csv.stringify(rows) |
csv.read(path) | Read CSV file | csv.read("data.csv") |
csv.write(path, data) | Write CSV file | csv.write("out.csv", rows) |
Module: base64 ๐
Base64 encoding and decoding for data encoding.
Functions
| Function | Description | Example |
|---|---|---|
base64.encode(str) | Encode string to base64 | base64.encode("hello") |
base64.decode(str) | Decode base64 to string | base64.decode("aGVsbG8=") |
base64.encode_bytes(arr) | Encode byte array | base64.encode_bytes(bytes) |
base64.decode_bytes(str) | Decode to byte array | base64.decode_bytes(enc) |
Other Built-ins
web_init()js_eval(code)js_evalFile(path)html_parse(html)html_querySelector(doc, selector)css_parse(css)pkg_load(name)pkg_list()