abs(number: number): number
function
Returns the absolute value of the given number.
abs(-10)
10
468 functions
abs(number: number): number
function
Returns the absolute value of the given number.
abs(-10)
10
add(value1: dynamic, value2: dynamic): dynamic
function
Adds two values.
add(1, 2)
3
all_symbols(): array
function
Returns an array of all interned symbols.
and(value1: bool, value2: bool): bool
function
Performs a logical AND operation on two boolean values.
and(true, false)
false
array(values: dynamic): array
function
Creates an array from the given values.
array(1, 2, 3)
[1, 2, 3]
ascii_downcase(input: string): string
function
Converts ASCII uppercase letters (A-Z) in the given string to lowercase, leaving all other characters unchanged.
ascii_downcase("ABC")
abc
ascii_upcase(input: string): string
function
Converts ASCII lowercase letters (a-z) in the given string to uppercase, leaving all other characters unchanged.
ascii_upcase("abc")
ABC
attr(markdown: markdown, attribute: string): dynamic
function
Retrieves the value of the specified attribute from a markdown node.
band(bytes1: bytes, bytes2: bytes): bytes
function
Computes the bitwise AND of two byte arrays of equal length.
base64(input: string): string
function
Encodes the given string to base64.
base64("hi")
aGk=
base64d(input: string): string
function
Decodes the given base64 string.
base64d("aGk=")
hi
base64url(input: string): string
function
Encodes the given string to URL-safe base64.
base64url("hi")
aGk
base64urld(input: string): string
function
Decodes the given URL-safe base64 string.
base64urld(base64url("hi"))
hi
basename(path: string): string
function
Returns the final component of a path string (e.g. "file.txt" from "/a/b/file.txt").
basename("/a/b/file.txt")
file.txt
bnot(bytes: bytes): bytes
function
Computes the bitwise NOT (complement) of a byte array.
bor(bytes1: bytes, bytes2: bytes): bytes
function
Computes the bitwise OR of two byte arrays of equal length.
breakpoint(): dynamic
function
Sets a breakpoint for debugging; execution will pause at this point if a debugger is attached.
capture(string: string, pattern: string): dict
function
Captures named groups from the given string based on the specified regular expression pattern and returns them as a dictionary keyed by group names.
capture("v1.2.3", "(?P<major>[0-9]+)")
{"major": "1"}
ceil(number: number): number
function
Rounds the given number up to the nearest integer.
ceil(3.2)
4
coalesce(value1: dynamic, value2: dynamic): dynamic
function
Returns the first non-None value from the two provided arguments.
coalesce(None, 5)
5
collection(dir: string, respect_gitignore?: boolean): array
functionrequires file-io
Recursively reads every Markdown file in the given directory (including subdirectories and symlinked files/directories) and returns an array of `{path, title, frontmatter, content}` dicts, sorted by path, so they can be filtered, sorted, or aggregated as a single dataset. `content` holds the file's Markdown nodes with frontmatter stripped. Symlink cycles are detected and only visited once. `respect_gitignore` is optional (default `false`); when `true`, dotfiles/dot-directories and any path matched by a `.gitignore` in `dir` or a subdirectory are skipped, with closer `.gitignore` files taking precedence, same as `git`. Requires the --allow-read CLI flag; otherwise returns a runtime error.
compact(array: array): array
function
Removes None values from the given array.
compact([1, None, 2])
[1, 2]
convert(input: dynamic, format: string): dynamic
function
Converts the input value to the specified format. Supported formats: base64, html, text, uri, heading (#, ##, etc.), blockquote (>), list item (-), or link (URL).
date_add(array: array, n: number, unit: string): array
function
Adds n units to a broken-down time array and returns a new array. Units: "seconds", "minutes", "hours", "days", "weeks", "months", "years". Month/year arithmetic is calendar-aware.
date_diff(array1: array, array2: array, unit: string): number
function
Returns the difference (array2 - array1) in the given unit. Units: "seconds", "minutes", "hours", "days", "weeks".
date_diff(gmtime(0), gmtime(86400), "days")
1
date_relative(base_timestamp: number, date_str: string): number
function
Parses a natural-language relative date expression (e.g. "3 days ago", "yesterday", "tomorrow", "next monday", "in 2 weeks") relative to a base Unix timestamp and returns the resulting Unix timestamp (seconds, UTC).
del(array_or_string: dynamic, index: number): dynamic
function
Deletes the element at the specified index in the array or string.
del([1, 2, 3], 1)
[1, 3]
dict(): dict
function
Creates a new, empty dict.
dict()
{}
dirname(path: string): string
function
Returns the parent directory of a path string (e.g. "/a/b" from "/a/b/file.txt"). Returns "." if the path has no parent.
dirname("/a/b/file.txt")
/a/b
div(value1: dynamic, value2: dynamic): dynamic
function
Divides the first value by the second value.
div(6, 2)
3
downcase(input: string): string
function
Converts the given string to lowercase.
downcase("ABC")
abc
embed_images(base_dir: string): markdown
functionrequires file-io
Inlines an `.image` node's local file into its `url` as a base64 `data:` URI, resolving the path relative to the given base directory (default ".") and inferring the MIME type from the file extension. URLs that are already `data:` URIs or contain a `://` scheme (e.g. `https://`), and non-image nodes, are left unchanged. Requires the --allow-read CLI flag; otherwise returns a runtime error.
ends_with(value: dynamic, suffix: dynamic): bool
function
Checks if the given string or byte array ends with the specified suffix.
ends_with("hello", "lo")
true
entries(dict: dict): array
function
Returns an array of key-value pairs from the dict as arrays.
eq(value1: dynamic, value2: dynamic): bool
function
Checks if two values are equal.
eq(1, 1)
true
error(message: string): dynamic
function
Raises a user-defined error with the specified message.
exp(number: number): number
function
Returns the exponential (e^x) of the given number.
exp(0)
1
explode(string: string): array
function
Splits the given string into an array of characters.
explode("ab")
[97, 98]
extname(path: string): string
function
Returns the extension of a file path including the leading dot (e.g. ".txt" from "file.txt"). Returns an empty string if there is no extension.
extname("file.txt")
.txt
extract_images(dir: string): markdown
functionrequires file-io
Decodes an `.image` node's base64 `data:` URI and writes the bytes to a file under the given directory, named by the content's MD5 hash with an extension inferred from the MIME type, then replaces `url` with that file's path. Nodes whose `url` is not a base64 `data:` URI, including non-image nodes, are left unchanged. Requires the --allow-write CLI flag; otherwise returns a runtime error.
file_exists(path: string): bool
functionrequires file-io
Checks if a file exists at the given path. Requires the --allow-read CLI flag; otherwise returns a runtime error.
file_size(path: string): number
functionrequires file-io
Returns the size, in bytes, of the file at the given path. Requires the --allow-read CLI flag; otherwise returns a runtime error.
flatten(array: array): array
function
Flattens a nested array into a single level array.
flatten([[1, 2], [3]])
[1, 2, 3]
floor(number: number): number
function
Rounds the given number down to the nearest integer.
floor(3.8)
3
from_date(date_str: string): number
function
Converts a date string to a timestamp.
from_date("1970-01-01T00:00:00Z")
0
from_hex(hex_string: string): bytes
function
Parses a hex string into raw bytes.
from_html(html: string): array
function
Converts the given HTML string to Markdown.
get(obj: dict, key: dynamic): dynamic
function
Retrieves a value from a dict by its key. Returns None if the key is not found.
get_location(node: markdown): dict
function
Returns the source position of a markdown node as a dict with start_line, start_column, end_line, and end_column, or None if the node has no position info.
get_title(node: markdown): string
function
Returns the title of a markdown node.
get_url(node: markdown): string
function
Returns the url of a markdown node.
get_url(to_link("https://example.com", "Example", ""))
https://example.com
get_variable(symbol_or_string: dynamic): dynamic
function
Retrieves the value of a symbol or variable from the current environment.
glob_match(pattern: string, path: string): bool
function
Checks whether the given path matches the glob pattern (e.g. "*.md", "docs/**/*.rs"), commonly used to filter file lists.
glob_match("*.md", "readme.md")
true
gmtime(timestamp: number): array
function
Converts Unix timestamp (seconds since epoch) to broken-down UTC time array [year, mon (0-11), mday, hour, min, sec, wday (0=Sun), yday (0-365)].
gmtime(0)
[1970, 0, 1, 0, 0, 0, 4, 0]
gsub(from: string, pattern: string, to: string): string
function
Replaces all occurrences matching a regular expression pattern with the replacement string.
gsub("a1b2", "[0-9]", "#")
a#b#
gt(value1: dynamic, value2: dynamic): bool
function
Checks if the first value is greater than the second value.
gt(2, 1)
true
gte(value1: dynamic, value2: dynamic): bool
function
Checks if the first value is greater than or equal to the second value.
gte(1, 1)
true
halt(exit_code: number): dynamic
function
Terminates the program with the given exit code.
html_escape(string: string): string
function
Escapes `&`, `<`, `>`, `"`, and `'` in the given string as HTML entities.
html_escape("<a>")
<a>
html_unescape(string: string): string
function
Decodes named and numeric HTML entities in the given string into their corresponding characters.
html_unescape("<a>")
<a>
http(method: string, url: string, body: string, headers: dict): string
functionrequires http
Performs an HTTPS request with the given method (a string or symbol, e.g. "post" or :post — get, post, put, delete, patch, head, ... are all supported) and returns the response body as a string. An optional body argument (string) sends a request body regardless of method, and an optional headers argument (a dict of string to string, e.g. {"Content-Type": "application/json"}) is applied to the request. Requires the --allow-net CLI flag; otherwise returns a runtime error. Only https:// URLs are allowed.
implode(array: array): string
function
Joins an array of characters into a string.
implode(explode("ab"))
ab
index(value: dynamic, needle: dynamic): number
function
Finds the first occurrence of a substring or byte subsequence. Returns -1 if not found.
index("hello", "ll")
2
infinite(): number
function
Returns an infinite number value.
input(): string
function
Reads a line from standard input and returns it as a string.
insert(target: dynamic, index_or_key: dynamic, value: dynamic): dynamic
function
Inserts a value into an array or string at the specified index, or into a dict with the specified key.
insert([1, 2, 3], 1, "x")
[1, "x", 2, 3]
intern(string: string): string
function
Interns the given string, returning a canonical reference for efficient comparison.
intern("hi")
hi
is_not_regex_match(string: string, pattern: string): bool
function
Checks if the given pattern does not match the string.
is_not_regex_match("abc", "x")
true
is_regex_match(string: string, pattern: string): bool
function
Checks if the given pattern matches the string.
is_regex_match("abc", "a.c")
true
join(array: array, separator: string): string
function
Joins the elements of an array into a string with the given separator.
join([1, 2, 3], ",")
1,2,3
keys(dict: dict): array
function
Returns an array of keys from the dict.
len(value: dynamic): number
function
Returns the length of the given string or array.
len("hello")
5
ln(number: number): number
function
Returns the natural logarithm (base e) of the given number.
ln(1)
0
localtime(timestamp: number): array
function
Converts Unix timestamp (seconds since epoch) to broken-down local time array [year, mon (0-11), mday, hour, min, sec, wday (0=Sun), yday (0-365)].
log10(number: number): number
function
Returns the base-10 logarithm of the given number.
log10(100)
2
lt(value1: dynamic, value2: dynamic): bool
function
Checks if the first value is less than the second value.
lt(1, 2)
true
lte(value1: dynamic, value2: dynamic): bool
function
Checks if the first value is less than or equal to the second value.
lte(1, 1)
true
ltrim(input: string): string
function
Trims whitespace from the left end of the given string.
ltrim(" hi ")
hi
max(value1: dynamic, value2: dynamic): dynamic
function
Returns the maximum of two values.
max(1, 2)
2
md5(input: dynamic): string
function
Computes the MD5 hash of a string or bytes and returns a lowercase hex string.
min(value1: dynamic, value2: dynamic): dynamic
function
Returns the minimum of two values.
min(1, 2)
1
mktime(time_array: array): number
function
Converts broken-down UTC time array [year, mon (0-11), mday, hour, min, sec, wday, yday] to Unix timestamp (seconds since epoch).
mktime(gmtime(0))
0
mod(value1: dynamic, value2: dynamic): dynamic
function
Calculates the remainder of the division of the first value by the second value.
mod(7, 3)
1
mul(value1: dynamic, value2: dynamic): dynamic
function
Multiplies two values.
mul(2, 3)
6
nan(): number
function
Returns a Not-a-Number (NaN) value.
ne(value1: dynamic, value2: dynamic): bool
function
Checks if two values are not equal.
ne(1, 2)
true
negate(number: number): number
function
Returns the negation of the given number.
negate(5)
-5
not(value: bool): bool
function
Performs a logical NOT operation on a boolean value.
not(true)
false
now(): number
function
Returns the current timestamp.
or(value1: bool, value2: bool): bool
function
Performs a logical OR operation on two boolean values.
or(true, false)
true
pack(format: string, value: number): bytes
function
Packs a number into bytes using the given format. Supported formats: u8, i8, u16be/le, i16be/le, u32be/le, i32be/le, u64be/le, i64be/le, f32be/le, f64be/le.
partial(function: function, arg1: dynamic, arg2: dynamic, ...: dynamic): function
function
Creates a new function by partially applying the given arguments to the specified function.
path_join(base: string, component: string): string
function
Joins a base path with a component path and returns the resulting path string (e.g. path_join("/a/b", "c.txt") → "/a/b/c.txt").
path_join("/a/b", "c.txt")
/a/b/c.txt
pow(base: number, exponent: number): number
function
Raises the base to the power of the exponent.
pow(2, 10)
1024
print(message: string): dynamic
function
Prints a message to standard output and returns the current value.
rand(): number
function
Generates a pseudo-random number in the range [0, 1). Not cryptographically secure.
rand_int(min: number, max: number): number
function
Generates a pseudo-random integer uniformly distributed in [min, max] (inclusive). Not cryptographically secure.
random_string(len: number, charset: string): string
function
Generates a random string of `len` characters, each independently chosen (with replacement) from `charset`. Not cryptographically secure.
range(start: number, end: number, step: number): array
function
Creates an array from start to end with an optional step.
range(0, 5, 1)
[0, 1, 2, 3, 4, 5]
read_file(path: string): string
functionrequires file-io
Reads the contents of a file at the given path and returns it as a string. Requires the --allow-read CLI flag; otherwise returns a runtime error.
read_file_bytes(path: string): bytes
functionrequires file-io
Reads the contents of a file at the given path and returns it as raw bytes. Requires the --allow-read CLI flag; otherwise returns a runtime error.
regex_match(string: string, pattern: string): array
function
Finds all matches of the given pattern in the string.
regex_match("abc123", "[0-9]+")
["123"]
repeat(string: string, count: number): string
function
Repeats the given string a specified number of times.
repeat("ab", 3)
ababab
replace(from: string, pattern: string, to: string): string
function
Replaces all occurrences of a substring with another substring.
replace("aXbXc", "X", "-")
a-b-c
reverse(value: dynamic): dynamic
function
Reverses the given string or array.
reverse("abc")
cba
rindex(value: dynamic, needle: dynamic): number
function
Finds the last occurrence of a substring or byte subsequence. Returns -1 if not found.
rindex("hello", "l")
3
round(number: number): number
function
Rounds the given number to the nearest integer.
round(3.5)
4
rtrim(input: string): string
function
Trims whitespace from the right end of the given string.
rtrim(" hi ")
hi
sample(array: array, n: number): array
function
Returns n elements sampled from the array without replacement, in random order. Errors if n exceeds the array length.
sanitize_html(html: string): string
function
Sanitizes the given HTML string using an allowlist of safe tags and attributes, removing scripts and other XSS vectors.
scan(string: string, pattern: string): array
function
Finds all matches of a regular expression pattern in the string. For each match, returns the captured groups as an array if the pattern has capture groups, otherwise returns the whole match as a string.
scan("a1b2", "[0-9]")
["1", "2"]
set(obj: dict, key: dynamic, value: dynamic): dict
function
Sets a key-value pair in a dict. If the key exists, its value is updated. Returns the modified map.
set_attr(markdown: markdown, attribute: string, value: dynamic): markdown
function
Sets the value of the specified attribute on a markdown node.
set_check(list: markdown, checked: bool): markdown
function
Creates a markdown list node with the given checked state.
set_check(to_md_list("Item", 0), true)
- [x] Item
set_children(markdown: markdown, children: array): markdown
function
Sets the children nodes of a markdown node. Nodes without children (e.g. text, code) are left unchanged.
set_code_block_lang(code_block: markdown, language: string): markdown
function
Sets the language of a markdown code block node.
set_code_block_lang(to_code("x", "python"), "rust")
```rust
x
```
set_list_ordered(list: markdown, ordered: bool): markdown
function
Sets the ordered property of a markdown list node.
set_list_ordered(to_md_list("Item", 0), true)
1. Item
set_ref(node: markdown, reference_id: string): markdown
function
Sets the reference identifier for markdown nodes that support references (e.g., Definition, LinkRef, ImageRef, Footnote, FootnoteRef).
set_variable(symbol_or_string: dynamic, value: dynamic): dynamic
function
Sets a symbol or variable in the current environment with the given value.
sha256(input: dynamic): string
function
Computes the SHA-256 hash of a string or bytes and returns a lowercase hex string.
sha512(input: dynamic): string
function
Computes the SHA-512 hash of a string or bytes and returns a lowercase hex string.
shift_left(value: dynamic, shift_amount: number): dynamic
function
Performs a left shift operation on the given value: for numbers, this is a bitwise left shift by the specified number of positions; for strings, this removes characters from the start; for Markdown headings, this increases the heading level accordingly.
shift_left(1, 2)
4
shift_right(value: dynamic, shift_amount: number): dynamic
function
Performs a bitwise right shift on numbers, slices characters from the end of strings, and adjusts Markdown heading levels when applied to headings, using the given shift amount.
shift_right(8, 2)
2
shuffle(array: array): array
function
Returns a new array containing the same elements as the input, in a uniformly random order.
slice(string: string, start: number, end: number): string
function
Extracts a substring from the given string.
slice("hello", 1, 3)
el
sort(array: array): array
function
Sorts the elements of the given array.
sort([3, 1, 2])
[1, 2, 3]
split(string: string, separator: string): array
function
Splits the given string by the specified separator.
split("a,b,c", ",")
["a", "b", "c"]
sqrt(number: number): number
function
Returns the square root of the given number.
sqrt(9)
3
starts_with(value: dynamic, prefix: dynamic): bool
function
Checks if the given string or byte array starts with the specified prefix.
starts_with("hello", "he")
true
stderr(message: string): dynamic
function
Prints a message to standard error and returns the current value.
stem(path: string): string
function
Returns the file name without the extension (e.g. "file" from "/a/b/file.txt").
stem("/a/b/file.txt")
file
strftime(timestamp: number, format: string): string
function
Formats a Unix timestamp (seconds) as a date string using the given strftime format (e.g. "%Y-%m-%d").
strftime(0, "%Y-%m-%d")
1970-01-01
strip_tags(string: string): string
function
Removes HTML tags from the given string, keeping the surrounding text content.
strip_tags("<b>hi</b>")
hi
strptime(date_str: string, format: string): number
function
Parses a date string using the given strptime format (e.g. "%Y-%m-%d") and returns a Unix timestamp (seconds, UTC).
strptime("1970-01-01", "%Y-%m-%d")
0
sub(value1: dynamic, value2: dynamic): dynamic
function
Subtracts the second value from the first value.
sub(5, 2)
3
to_array(value: dynamic): array
function
Converts the given value to an array.
to_array(1)
[1]
to_blockquote(value: dynamic): markdown
function
Creates a markdown blockquote node with the given value.
to_blockquote("Quote")
> Quote
to_boolean(value: dynamic): bool
function
Converts the given value to a boolean. Booleans are returned unchanged, the strings "true" and "false" are converted to their boolean equivalent, and all other input results in an error.
to_boolean("true")
true
to_break(): markdown
function
Creates a markdown hard line break node.
to_break()
\
to_bytes(value: dynamic): bytes
function
Converts a string (UTF-8), array of numbers, or bytes to raw bytes.
to_callout(value: dynamic, kind: string, title: string): markdown
function
Creates a markdown callout node with the given value, kind, and title.
to_callout("Note text", "note", "")
> [!NOTE]
> Note text
to_code(value: dynamic, language: string): markdown
function
Creates a markdown code block with the given value and language.
to_code("x = 1", "python")
```python
x = 1
```
to_code_inline(value: dynamic): markdown
function
Creates an inline markdown code node with the given value.
to_code_inline("x")
`x`
to_date(timestamp: number, format: string): string
function
Converts a timestamp to a date string with the given format.
to_date(0, "%Y-%m-%d")
1970-01-01
to_definition(url: string, ident: string, title: string): markdown
function
Creates a markdown link reference definition node with the given url, identifier, and title.
to_definition("https://example.com", "ex", "")
[ex]: https://example.com
to_delete(value: dynamic): markdown
function
Creates a markdown delete (strikethrough) node with the given value.
to_delete("Old")
~~Old~~
to_em(value: dynamic): markdown
function
Creates a markdown emphasis (italic) node with the given value.
to_em("Italic")
*Italic*
to_footnote(value: dynamic, ident: string): markdown
function
Creates a markdown footnote definition node with the given value and identifier.
to_footnote("Footnote text", "1")
[^1]: Footnote text
to_footnote_ref(ident: string): markdown
function
Creates a markdown footnote reference node with the given identifier.
to_footnote_ref("1")
[^1]
to_h(value: dynamic, depth: number): markdown
function
Creates a markdown heading node with the given value and depth.
to_h("Title", 1)
# Title
to_hex(bytes: bytes): string
function
Encodes raw bytes as a lowercase hex string.
to_hex(from_hex("6869"))
6869
to_hr(): markdown
function
Creates a markdown horizontal rule node.
to_hr()
***
to_html(markdown: string): string
function
Converts the given markdown string to HTML.
to_image(url: string, alt: string, title: string): markdown
function
Creates a markdown image node with the given URL, alt text, and title.
to_image("https://example.com/a.png", "Alt", "")

to_link(url: string, value: dynamic, title: string): markdown
function
Creates a markdown link node with the given url and title.
to_link("https://example.com", "Example", "")
[Example](https://example.com)
to_markdown(markdown_string: string): array
function
Parses a markdown string and returns an array of markdown nodes.
to_markdown("# Hi")
[# Hi]
to_markdown_string(value: dynamic): string
function
Converts the given value(s) to a markdown string representation.
to_math(value: dynamic): markdown
function
Creates a markdown math block with the given value.
to_math("x^2")
$$
x^2
$$
to_math_inline(value: dynamic): markdown
function
Creates an inline markdown math node with the given value.
to_math_inline("x^2")
$x^2$
to_md_fragment(values: array): markdown
function
Creates a markdown fragment node that groups an array of markdown nodes into a single value.
to_md_html(value: dynamic): markdown
function
Creates a raw markdown HTML node with the given value.
to_md_html("<br>")
<br>
to_md_list(value: dynamic, indent: number): markdown
function
Creates a markdown list node with the given value and indent level.
to_md_list("Item", 0)
- Item
to_md_name(markdown: markdown): string
function
Returns the name of the given markdown node.
to_md_name(to_h("t", 1))
h1
to_md_table_align(aligns: array): markdown
function
Creates a markdown table alignment row node from an array of alignments ("left", "right", "center", "none").
to_md_table_align(["left", "right"])
|:---|---:|
to_md_table_cell(value: dynamic, row: number, column: number): markdown
function
Creates a markdown table cell node with the given value at the specified row and column.
to_md_table_cell("A1", 0, 0)
A1
to_md_table_row(cells: array): markdown
function
Creates a markdown table row node with the given values.
to_md_text(value: dynamic): markdown
function
Creates a markdown text node with the given value.
to_md_text("hi")
hi
to_mdx(mdx_string: string): array
function
Parses an MDX string and returns an array of MDX nodes.
to_number(value: dynamic): number
function
Converts the given value to a number.
to_number("42")
42
to_string(value: dynamic): string
function
Converts the given value to a string.
to_string(1)
1
to_strong(value: dynamic): markdown
function
Creates a markdown strong (bold) node with the given value.
to_strong("Bold")
**Bold**
to_text(markdown: markdown): string
function
Converts the given markdown node to plain text.
to_text(to_strong("hi"))
hi
token_compress(nodes: array, budget: number, model?: string): array
function
Reduces an array of Markdown nodes to fit within `budget` LLM tokens, preserving structure as much as possible: paragraphs are cut to their first sentence, then lists/tables/code blocks are collapsed to a summary, and only as a last resort is the remaining text hard-truncated. Uses a lightweight chars-per-token heuristic by default; built with the `tiktoken` Cargo feature, counts exactly via tiktoken-rs instead when `model` (e.g. "gpt-5") is given. `model` is optional; without it, the heuristic estimate is always used.
token_count(text: string, model?: string): number
function
Estimates how many LLM tokens the given text would consume, for context-window budgeting. Uses a lightweight chars-per-token heuristic by default; built with the `tiktoken` Cargo feature, counts exactly via tiktoken-rs instead when `model` (e.g. "gpt-5") is given. `model` is optional; without it, the heuristic estimate is always used.
token_count("Hello, world!")
4
trim(input: string): string
function
Trims whitespace from both ends of the given string.
trim(" hi ")
hi
trunc(number: number): number
function
Truncates the given number to an integer by removing the fractional part.
trunc(3.9)
3
truncate(string: string, width: number, ellipsis: string): string
function
Truncates the given string to the specified display width, appending the ellipsis string when truncated (CJK and other wide characters count as two columns).
truncate("hello world", 5, "...")
he...
type(value: dynamic): string
function
Returns the type of the given value.
type(1)
number
uniq(array: array): array
function
Removes duplicate elements from the given array.
uniq([1, 1, 2])
[1, 2]
unpack(format: string, bytes: bytes): number
function
Unpacks a number from bytes using the given format. Supported formats: u8, i8, u16be/le, i16be/le, u32be/le, i32be/le, u64be/le, i64be/le, f32be/le, f64be/le.
upcase(input: string): string
function
Converts the given string to uppercase.
upcase("abc")
ABC
update(target_value: dynamic, source_value: dynamic): dynamic
function
Update the value with specified value.
url_decode(input: string): string
function
URL-decodes the given string.
url_decode("a%20b")
a b
url_encode(input: string): string
function
URL-encodes the given string.
url_encode("a b")
a%20b
utf8(bytes: bytes): string
function
Decodes bytes as a UTF-8 string, returning an error if the bytes are not valid UTF-8.
utf8(to_bytes("hi"))
hi
uuid(): string
function
Generates a random (version 4, RFC 4122) UUID string.
uuid_v4(): string
function
Generates a random (version 4, RFC 4122) UUID string. Alias of `uuid`.
uuid_v7(): string
function
Generates a time-ordered (version 7, RFC 9562) UUID string: a millisecond Unix timestamp followed by random bits, so values sort by creation time. The timestamp is plaintext, so prefer uuid/uuid_v4 for unguessable IDs.
values(dict: dict): array
function
Returns an array of values from the dict.
word_wrap(string: string, width: number): string
function
Wraps the given string into lines no wider than the specified display width, breaking on word boundaries (CJK and other wide characters count as two columns).
word_wrap("hello world", 5)
hello
world
write_file(path: string, content: dynamic): dynamic
functionrequires file-io
Writes content (string or bytes) to the file at the given path, creating or truncating it. Requires the --allow-write CLI flag; otherwise returns a runtime error.
xor(bytes1: bytes, bytes2: bytes): bytes
function
Computes the bitwise XOR of two byte arrays of equal length.
halt_error(): dynamic
function
Halts execution with error code 5
is_array(a: dynamic): bool
function
Checks if input is an array
is_array([1, 2])
true
is_markdown(m: dynamic): bool
function
Checks if input is markdown
is_markdown(to_h("t", 1))
true
is_bool(b: dynamic): bool
function
Checks if input is a boolean
is_bool(true)
true
is_number(n: dynamic): bool
function
Checks if input is a number
is_number(1)
true
is_string(s: dynamic): bool
function
Checks if input is a string
is_string("hi")
true
is_none(n: dynamic): bool
function
Checks if input is None
is_none(None)
true
is_dict(d: dynamic): bool
function
Checks if input is a dictionary
is_dict({"a": 1})
true
is_bytes(b: dynamic): bool
function
Checks if input is bytes
is_bytes(to_bytes("hi"))
true
contains(haystack: dynamic, needle: dynamic): bool
function
Checks if string contains a substring
contains("hello world", "world")
true
ltrimstr(s: dynamic, left: dynamic): string
function
Removes prefix string from input if it exists
ltrimstr("prefix_value", "prefix_")
value
rtrimstr(s: dynamic, right: dynamic): string
function
Removes suffix string from input if it exists
rtrimstr("value_suffix", "_suffix")
value
is_empty(s: dynamic): bool
function
Checks if string, array or dict is empty
is_empty([])
true
test(s: dynamic, pattern: dynamic): bool
function
Tests if string matches a pattern
test("abc", "a.c")
true
select(v: dynamic, f: dynamic): dynamic
function
Returns value if condition is true, None otherwise
select(5, true)
5
arrays(a: dynamic): dynamic
function
Returns array if input is array, None otherwise
arrays([1, 2])
[1, 2]
markdowns(m: dynamic): dynamic
function
Returns markdown if input is markdown, None otherwise
markdowns(to_h("t", 1))
# t
booleans(b: dynamic): dynamic
function
Returns boolean if input is boolean, None otherwise
booleans(true)
true
numbers(n: dynamic): dynamic
function
Returns number if input is number, None otherwise
numbers(1)
1
strings(s: dynamic): dynamic
function
Returns string if input is string, None otherwise
strings("hi")
hi
dicts(d: dynamic): dynamic
function
Returns dict if input is dict, None otherwise
dicts({"a": 1})
{"a": 1}
nones(n: dynamic): dynamic
function
Returns the value if it is None, None otherwise
nones(None)
bytes(b: dynamic): dynamic
function
Returns bytes if input is bytes, None otherwise
bytes(to_bytes("hi"))
6869
iterables(v: dynamic): dynamic
function
Returns the value if it is an array or dict (i.e. a container that can be iterated over), None otherwise
iterables([1, 2])
[1, 2]
scalars(v: dynamic): dynamic
function
Returns the value if it is not an array or dict (i.e. a leaf/scalar value), None otherwise
scalars(1)
1
to_date_iso8601(d: dynamic): string
function
Formats a date to ISO 8601 format (YYYY-MM-DDTHH:MM:SSZ)
to_date_iso8601(0)
1970-01-01T00:00:00Z
map(v: dynamic, f: dynamic): array
function
Applies a given function to each element of the provided array and returns a new array with the results.
map([1, 2, 3], fn(x): mul(x, 2);)
[2, 4, 6]
flat_map(v: dynamic, f: dynamic): array
function
Applies a function to each element and flattens the result into a single array
flat_map([1, 2], fn(x): [x, x];)
[1, 1, 2, 2]
filter(v: dynamic, f: dynamic): array
function
Filters the elements of an array based on a provided callback function.
filter([1, 2, 3, 4], fn(x): x > 2;)
[3, 4]
each(v: dynamic, f: dynamic): dynamic
function
Executes a provided function once for each element in an array or each key-value pair in a dictionary.
first(arr: dynamic): dynamic
function
Returns the first element of an array
first([1, 2, 3])
1
last(arr: dynamic): dynamic
function
Returns the last element of an array
last([1, 2, 3])
3
second(arr: dynamic): dynamic
function
Returns the second element of an array
second([1, 2, 3])
2
is_h1(md: dynamic): bool
function
Checks if markdown is h1 heading
is_h1(to_h("t", 1))
true
is_h2(md: dynamic): bool
function
Checks if markdown is h2 heading
is_h2(to_h("t", 2))
true
is_h3(md: dynamic): bool
function
Checks if markdown is h3 heading
is_h3(to_h("t", 3))
true
is_h4(md: dynamic): bool
function
Checks if markdown is h4 heading
is_h4(to_h("t", 4))
true
is_h5(md: dynamic): bool
function
Checks if markdown is h5 heading
is_h5(to_h("t", 5))
true
is_h6(md: dynamic): bool
function
Checks if markdown is h6 heading
is_h6(to_h("t", 6))
true
is_h(md: dynamic): bool
function
Checks if markdown is heading
is_h(to_h("t", 2))
true
is_h_level(md: dynamic, level: dynamic): bool
function
Checks if markdown is a heading of the specified level (1-6)
is_h_level(to_h("t", 2), 2)
true
is_table_align(md: dynamic): bool
function
Checks if markdown is table align
is_table_align(to_md_table_align(["left"]))
true
is_table_cell(md: dynamic): bool
function
Checks if markdown is table cell
is_table_cell(to_md_table_cell("A1", 0, 0))
true
is_em(md: dynamic): bool
function
Checks if markdown is emphasis
is_em(to_em("hi"))
true
is_html(md: dynamic): bool
function
Checks if markdown is html
is_yaml(md: dynamic): bool
function
Checks if markdown is yaml
is_toml(md: dynamic): bool
function
Checks if markdown is toml
is_code(md: dynamic): bool
function
Checks if markdown is code block
is_code(to_code("x", "python"))
true
is_text(text: dynamic): bool
function
Checks if markdown is text
is_text(to_md_text("hi"))
true
is_list(list: dynamic): bool
function
Checks if markdown is list
is_list(to_md_list("Item", 0))
true
matches_url(node: dynamic, url: dynamic): bool
functionDeprecated
Checks if markdown node's URL matches a specified URL deprecated: use select(.link.url == url) instead
matches_url(to_link("https://example.com", "x", ""), "https://example.com")
true
is_mdx_flow_expression(mdx: dynamic): bool
function
Checks if markdown is MDX Flow Expression
is_mdx_jsx_flow_element(mdx: dynamic): bool
function
Checks if markdown is MDX Jsx Flow Element
is_mdx_jsx_text_element(mdx: dynamic): bool
function
Checks if markdown is MDX Jsx Text Element
is_mdx_text_expression(mdx: dynamic): bool
function
Checks if markdown is MDX Text Expression
is_mdx_js_esm(mdx: dynamic): bool
function
Checks if markdown is MDX Js Esm
is_mdx(mdx: dynamic): bool
function
Checks if markdown is MDX
is_callout(md: dynamic): bool
function
Checks if markdown is a callout block
is_callout(to_callout("Note", "note", ""))
true
fill(value: dynamic, n: dynamic): array
function
Returns an array of length n filled with the given value.
fill("x", 3)
["x", "x", "x"]
sort_by(arr: dynamic, f: dynamic): array
function
Sorts an array using a key function that extracts a comparable value for each element.
sort_by([3, 1, 2], identity)
[1, 2, 3]
sort_natural(arr: dynamic): array
function
Sorts an array in natural order (numeric-aware), so runs of digits embedded in a string are compared as numbers rather than character-by-character, e.g. "file2" sorts before "file10" (unlike a plain lexicographic `sort`).
sort_natural(["file10", "file2"])
["file2", "file10"]
count_by(arr: dynamic, f: dynamic): number
function
Returns the count of elements in the array that satisfy the provided function.
count_by([1, 2, 3, 4], fn(x): x > 2;)
2
skip(arr: dynamic, n: dynamic): array
function
Skips the first n elements of an array and returns the rest
skip([1, 2, 3, 4], 2)
[3, 4]
take(arr: dynamic, n: dynamic): array
function
Takes the first n elements of an array
take([1, 2, 3, 4], 2)
[1, 2]
find_index(arr: dynamic, f: dynamic): number
function
Returns the index of the first element in an array that satisfies the provided function.
find_index([1, 2, 3], fn(x): x == 2;)
1
skip_while(arr: dynamic, f: dynamic): array
function
Skips elements from the beginning of an array while the provided function returns true
skip_while([1, 2, 3, 4], fn(x): x < 3;)
[3, 4]
take_while(arr: dynamic, f: dynamic): array
function
Takes elements from the beginning of an array while the provided function returns true
take_while([1, 2, 3, 4], fn(x): x < 3;)
[1, 2]
group_by(arr: dynamic, f: dynamic): dict
function
Groups elements of an array by the result of applying a function to each element
group_by([1, 2, 3, 4], fn(x): mod(x, 2);)
{"1": [1, 3], "0": [2, 4]}
frequencies_by(arr: dynamic, f: dynamic): dict
function
Counts occurrences of each key extracted from the elements of an array, returning a dict of `{key: count}`.
frequencies_by(["a", "b", "a"], identity)
{"a": 2, "b": 1}
tally(arr: dynamic): dict
function
Counts occurrences of each element in an array, returning a dict of `{value: count}`.
tally(["a", "b", "a"])
{"a": 2, "b": 1}
any(v: dynamic, f: dynamic): bool
function
Returns true if any element in the array satisfies the provided function.
any([1, 2, 3], fn(x): x > 2;)
true
all(v: dynamic, f: dynamic): bool
function
Returns true if all element in the array satisfies the provided function.
all([1, 2, 3], fn(x): x > 0;)
true
in(v: dynamic, elem: dynamic): bool
function
Returns true if the element is in the array.
in([1, 2, 3], 2)
true
fold(arr: dynamic, init: dynamic, f: dynamic): dynamic
function
Reduces an array to a single value by applying a function, starting from an initial value.
fold([1, 2, 3], 0, fn(acc, x): acc + x;)
6
unique_by(arr: dynamic, f: dynamic): array
function
Returns a new array with duplicate elements removed, comparing by the result of the provided function.
unique_by([1, 2, 1, 3], identity)
[1, 2, 3]
identity(x: dynamic): dynamic
function
Returns the input value unchanged.
identity(1)
1
transpose(matrix: dynamic): array
function
Transposes a 2D array (matrix), swapping rows and columns.
transpose([[1, 2], [3, 4]])
[[1, 3], [2, 4]]
tap(value: dynamic, expr: dynamic): dynamic
function
Applies a function to a value and returns the value (useful for debugging or side effects).
tap(1, 2)
1
pluck(pluck_obj: dynamic, selector: dynamic): dynamic
function
Extracts values from an array of objects based on a specified selector.
compact_map(arr: dynamic, f: dynamic): array
function
Maps over an array and removes None values from the result.
compact_map([1, 2, 3], fn(x): if (x > 1): x;)
[2, 3]
reject(arr: dynamic, f: dynamic): array
function
Filters out elements that match the condition (opposite of filter).
reject([1, 2, 3, 4], fn(x): x > 2;)
[1, 2]
partition(arr: dynamic, f: dynamic): array
function
Splits an array into two arrays: [matching, not_matching] based on a condition.
partition([1, 2, 3, 4], fn(x): x > 2;)
[[3, 4], [1, 2]]
get_or(dict: dynamic, key: dynamic, default: dynamic): dynamic
function
Safely gets a value from a dict with a default if the key doesn't exist.
get_or({"a": 1}, "b", 0)
0
times(n: dynamic, value: dynamic): array
functionDeprecated
Executes an expression n times and returns an array of results. Note: `value` is evaluated once (eagerly) and repeated, not re-evaluated per iteration. Deprecated: use `repeat` instead
times(3, 1)
[1, 1, 1]
between(value: dynamic, min: dynamic, max: dynamic): bool
function
Checks if a value is between min and max (inclusive).
between(5, 1, 10)
true
sum_by(arr: dynamic, f: dynamic): number
function
Sums elements of an array after applying a transformation function.
sum_by([1, 2, 3], fn(x): mul(x, 2);)
12
index_by(arr: dynamic, f: dynamic): dict
function
Creates a dictionary indexed by a key extracted from each element.
index_by([1, 2, 3], to_string)
{"1": 1, "2": 2, "3": 3}
join_by(left: dynamic, right: dynamic, left_key: dynamic, right_key: dynamic, kind: dynamic): array
function
Joins two arrays of dict records on `left_key`/`right_key`, similar to a SQL join. Matching records are merged with `+` (right's fields win on collision). `kind` is one of "inner" (default), "left", "right", or "full"; unmatched records in outer joins are filled with `None` for the other side's fields (inferred from that side's full key set). Records with a missing or `None` join key never match, and duplicate keys on either side expand as a cross product.
join_by([{"id": 2, "name": "bob"}], [{"uid": 2, "age": 30}], "id", "uid")
[{"id": 2, "name": "bob", "uid": 2, "age": 30}]
inspect(value: dynamic): dynamic
function
Inspects a value by printing its string representation and returning the value.
lpad(s: dynamic, length: dynamic, pad_str: dynamic): string
function
Left-pads a string to a specified length using a given padding string.
lpad("7", 3, "0")
007
rpad(s: dynamic, length: dynamic, pad_str: dynamic): string
function
Right-pads a string to a specified length using a given padding string.
rpad("7", 3, "0")
700
load_markdown(path: dynamic): array
function
Loads a markdown file from the specified path
http_get(url: dynamic, headers: dynamic): string
function
Performs an HTTPS GET request, optionally with the given headers (a dict of string to string), and returns the response body as a string
http_post(url: dynamic, body: dynamic, headers: dynamic): string
function
Performs an HTTPS POST request with the given body, optionally with the given headers (a dict of string to string), and returns the response body as a string
http_put(url: dynamic, body: dynamic, headers: dynamic): string
function
Performs an HTTPS PUT request with the given body, optionally with the given headers (a dict of string to string), and returns the response body as a string
http_patch(url: dynamic, body: dynamic, headers: dynamic): string
function
Performs an HTTPS PATCH request with the given body, optionally with the given headers (a dict of string to string), and returns the response body as a string
http_delete(url: dynamic, headers: dynamic): string
function
Performs an HTTPS DELETE request, optionally with the given headers (a dict of string to string), and returns the response body as a string
http_head(url: dynamic, headers: dynamic): string
function
Performs an HTTPS HEAD request, optionally with the given headers (a dict of string to string), and returns the response body as a string
http_get_json(url: dynamic, headers: dynamic): dynamic
function
Performs an HTTPS GET request, optionally with the given headers (a dict of string to string), and parses the response body as JSON, returning the resulting data structure
http_post_json(url: dynamic, body: dynamic, headers: dynamic): dynamic
function
Performs an HTTPS POST request with the given body, optionally with the given headers (a dict of string to string), and parses the response body as JSON, returning the resulting data structure
http_put_json(url: dynamic, body: dynamic, headers: dynamic): dynamic
function
Performs an HTTPS PUT request with the given body, optionally with the given headers (a dict of string to string), and parses the response body as JSON, returning the resulting data structure
http_patch_json(url: dynamic, body: dynamic, headers: dynamic): dynamic
function
Performs an HTTPS PATCH request with the given body, optionally with the given headers (a dict of string to string), and parses the response body as JSON, returning the resulting data structure
http_delete_json(url: dynamic, headers: dynamic): dynamic
function
Performs an HTTPS DELETE request, optionally with the given headers (a dict of string to string), and parses the response body as JSON, returning the resulting data structure
debug(args: dynamic): dynamic
function
Prints the debug information of the given value(s).
increase_header_depth(node: dynamic): markdown
function
Increases the depth (numeric level) of a markdown heading node by one, effectively demoting the heading (e.g. h1 -> h2), up to a maximum of 6.
increase_header_depth(to_h("t", 1))
## t
decrease_header_depth(node: dynamic): markdown
function
Decreases the depth (numeric level) of a markdown heading node by one, effectively promoting the heading (e.g. h2 -> h1), down to a minimum of 1.
decrease_header_depth(to_h("t", 2))
# t
demote_heading(node: dynamic): markdown
function
Demotes a markdown heading by increasing its depth (numeric level) by one. This is an alias for `increase_header_depth`.
demote_heading(to_h("t", 1))
## t
promote_heading(node: dynamic): markdown
function
Promotes a markdown heading by decreasing its depth (numeric level) by one. This is an alias for `decrease_header_depth`.
promote_heading(to_h("t", 2))
# t
increase_header_level(node: dynamic): markdown
functionDeprecated
Deprecated: use `increase_header_depth` or `demote_heading` instead. Kept for backward compatibility; behavior unchanged.
increase_header_level(to_h("t", 1))
## t
decrease_header_level(node: dynamic): markdown
functionDeprecated
Deprecated: use `decrease_header_depth` or `promote_heading` instead. Kept for backward compatibility; behavior unchanged.
decrease_header_level(to_h("t", 2))
# t
bsearch(arr: dynamic, target: dynamic): number
function
Performs a binary search on a sorted array to find the index of the target value.
bsearch([1, 3, 5, 7, 9], 5)
2
slugify(s: dynamic, separator: dynamic): string
function
Converts a string into a URL-friendly slug by lowercasing, replacing non-alphanumeric characters with hyphens, and trimming hyphens from the ends.
slugify("Hello, World!")
hello-world
percentile(arr: dynamic, p: dynamic): number
function
Calculates the p-th percentile of an array of numbers using linear interpolation between closest ranks.
percentile([1, 2, 3, 4, 5], 0.5)
3
chunks(v: dynamic, size: dynamic): array
function
Splits an array into chunks of a specified size, returning an array of arrays.
chunks([1, 2, 3, 4, 5], 2)
[[1, 2], [3, 4], [5]]
chunk_by(v: dynamic, f: dynamic): array
function
Splits an array into chunks based on the result of applying a function to each element, grouping consecutive elements with the same key together.
chunk_by([1, 1, 2, 2, 3], identity)
[[1, 1], [2, 2], [3]]
flip(f: dynamic, a: dynamic, b: dynamic): dynamic
function
Returns a new function that takes the same arguments as the original function but with the first two arguments flipped.
flip(sub, 2, 10)
8
complement(f: dynamic): bool
function
Returns a new predicate function that negates the result of the given function.
let f = complement(is_none) | f(1)
true
comp(fns: dynamic): dynamic
function
Composes functions into one function, applying them right-to-left. `comp(f, g, h)(x)` is equivalent to `f(g(h(x)))`.
let f = comp(fn(x): x + 1;, fn(x): x * 2;) | f(3)
7
juxt(fns: dynamic): array
function
Returns a function that applies each given function to its argument and collects the results into an array. `juxt(f, g, h)(x)` is equivalent to `[f(x), g(x), h(x)]`.
let f = juxt(first, last) | f([1, 2, 3])
[1, 3]
sum(arr: dynamic): number
function
Returns the sum of the elements in an array after applying a transformation function to each element.
sum([1, 2, 3])
6
mean(arr: dynamic): number
function
Returns the average (mean) of an array of numbers, or None if the array is empty.
mean([1, 2, 3])
2
geomean(arr: dynamic): number
function
Returns the geometric mean of an array of numbers, or None if the array is empty.
geomean([1, 4])
2
variance(arr: dynamic): number
function
Returns the population variance of an array of numbers, or None if the array is empty.
variance([2, 4, 4, 4, 5, 5, 7, 9])
4
stddev(arr: dynamic): number
function
Returns the population standard deviation of an array of numbers, or None if the array is empty.
stddev([2, 4, 4, 4, 5, 5, 7, 9])
2
mode(arr: dynamic): array
function
Returns the mode(s) of an array, i.e. the most frequently occurring value(s). Multiple values are returned if there is a tie for the highest frequency. Returns None if the array is empty.
mode([1, 2, 2, 3])
[2]
describe(arr: dynamic): dict
function
Returns a dict of summary statistics for an array of numbers: `{min, max, mean, median, stddev, variance, count}`. Returns None if the array is empty.
describe([1, 2, 3, 4, 5])
{"count": 5, "min": 1, "max": 5, "mean": 3, "variance": 2, "stddev": 1.414214, "median": 3}
ngram(s: dynamic, n: dynamic): array
function
Returns the n-grams of an array or string, which are overlapping contiguous subarrays (or substrings) of length n, sliding one element at a time.
ngram("abcd", 2)
["ab", "bc", "cd"]
zip(arr1: dynamic, arr2: dynamic): array
function
Combines two arrays into an array of pairs, where each pair contains elements from the same index in both arrays.
zip([1, 2], ["a", "b"])
[[1, "a"], [2, "b"]]
min_by(arr: dynamic, f: dynamic): dynamic
function
Returns the minimum element in an array based on a provided function that extracts a comparable value from each element.
min_by([3, 1, 2], identity)
1
max_by(arr: dynamic, f: dynamic): dynamic
function
Returns the maximum element in an array based on a provided function that extracts a comparable value from each element.
max_by([3, 1, 2], identity)
3
lines(s: dynamic): array
function
Returns the lines of a string as an array by splitting on newline characters.
lines("a\nb\nc")
["a", "b", "c"]
unlines(arr: dynamic): string
function
Joins an array of strings into a single string with newline characters between them.
unlines(["a", "b", "c"]) == "a\nb\nc"
true
pick(d: dynamic, keys: dynamic): dict
function
Returns a new dictionary containing only the specified keys from the original dictionary, if they exist.
pick({"a": 1, "b": 2}, ["a"])
{"a": 1}
omit(d: dynamic, keys: dynamic): dict
function
Returns a new dictionary excluding the specified keys from the original dictionary.
omit({"a": 1, "b": 2}, ["a"])
{"b": 2}
has(v: dynamic, key: dynamic): bool
function
Checks if a dict has the given key, or an array has an element at the given index.
has({"a": 1}, "a")
true
get_path(value: dynamic, path: dynamic): dynamic
function
Retrieves a nested value by following an array of keys/indices, e.g. `get_path(d, ["a", "b", 0])`. Returns None as soon as any intermediate step is missing.
get_path({"a": {"b": 1}}, ["a", "b"])
1
set_path(value: dynamic, path: dynamic, new_value: dynamic): dynamic
function
Sets a nested value by following an array of keys/indices, e.g. `set_path(d, ["a", "b", 0], 1)`. Missing intermediate dicts/arrays are created automatically, choosing an array when the corresponding path element is a number and a dict otherwise.
set_path({"a": {"b": 1}}, ["a", "b"], 2)
{"a": {"b": 2}}
del_path(value: dynamic, path: dynamic): dynamic
function
Deletes the value at a nested path, following an array of keys/indices, e.g. `del_path(d, ["a", "b", 0])`. An empty path deletes the whole value, mirroring jq's `delpaths([[]])`. A path through a missing intermediate container, or ending in a missing key/out-of-range index, leaves `value` unchanged.
del_path({"a": {"b": 1, "c": 2}}, ["a", "b"])
{"a": {"c": 2}}
del_paths(value: dynamic, paths: dynamic): dynamic
function
Deletes the values at multiple nested paths, e.g. `del_paths(d, [["a"], ["b", 0]])`. Paths are applied deepest-first (via `sort`/`reverse`) so that deleting one array element doesn't shift the indices used by the remaining paths, mirroring jq's `delpaths`.
del_paths({"a": 1, "b": 2, "c": 3}, [["a"], ["c"]])
{"b": 2}
paths(value: dynamic): array
function
Returns an array of leaf-path arrays for a value, e.g. `paths({"a": {"b": 1}})` returns `[["a", "b"]]`. Each returned path can be passed to `get_path`/`set_path`. Containers with no leaves (e.g. `{}`, `[]`) contribute no paths.
paths({"a": {"b": 1}})
[["a", "b"]]
from_entries(arr: dynamic): dict
function
Builds a dict from an array of [key, value] pairs, as produced by `entries`. If the same key appears more than once, the last occurrence wins.
from_entries([["a", 1], ["b", 2]])
{"a": 1, "b": 2}
with_entries(d: dynamic, f: dynamic): dict
function
Transforms each [key, value] pair of a dict by applying the given function, then rebuilds a dict from the resulting pairs.
with_entries({"a": 1}, fn(e): [e[0], e[1] + 1];)
{"a": 2}
merge_with(a: dynamic, b: dynamic, policy: dynamic): dynamic
function
Deep merges two values, recursing into dicts key by key. Neither input is mutated. When both sides provide a leaf/array value for the same key, the conflict is resolved according to `policy`, one of: - `"replace"`: the second value (`b`) wins. - `"append"`: arrays are concatenated; other conflicting values are collected into `[a, b]`. - `"error"`: raises an error describing the conflict.
merge_with({"a": 1, "b": {"x": 1}}, {"b": {"y": 2}, "c": 3}, "replace")
{"a": 1, "b": {"x": 1, "y": 2}, "c": 3}
merge_defaults(d: dynamic, defaults: dynamic): dynamic
function
Deep merges `d` over `defaults`, similar to Jsonnet's object inheritance: values present in `d` win (recursively for nested dicts), while keys missing from `d` fall back to the corresponding value in `defaults`. Arrays and scalar conflicts are resolved by letting `d` replace `defaults`. Neither input is mutated.
merge_defaults({"a": {"x": 1}}, {"a": {"x": 0, "y": 2}, "b": 3})
{"a": {"x": 1, "y": 2}, "b": 3}
frontmatter(v: dynamic): dynamic
function
Parses frontmatter from a markdown node, supporting both YAML and TOML formats.
walk(v: dynamic, f: dynamic): dynamic
function
Walks through a value (which can be a markdown node, array, or dict) and applies a function to each element, returning a new structure with the results.
walk([1, [2, 3]], fn(x): if (is_number(x)): x * 2 else: x;)
[2, [4, 6]]
human_bytes(n: dynamic): string
function
Formats a byte count as a human-readable decimal (SI, 1000-based) string, e.g. `human_bytes(1500)` => "1.5KB". Negative numbers keep their sign.
human_bytes(1500)
1.5KB
human_size(n: dynamic): string
function
Formats a byte count as a human-readable binary (IEC, 1024-based) string without the "i" suffix, matching `numfmt --to=iec`, e.g. `human_size(1536)` => "1.5K". Negative numbers keep their sign.
human_size(1536)
1.5K
cbor_parse(input: dynamic): dynamic
function
Parses a base64-encoded CBOR string (or raw bytes) and returns the corresponding data structure.
Module: import "cbor" | cbor::cbor_parse(...)
import "cbor" | cbor::cbor_parse(cbor::cbor_stringify({"a": 1}))
{"a": 1}
cbor_stringify(data: dynamic): bytes
function
Serializes a value to CBOR bytes.
Module: import "cbor" | cbor::cbor_stringify(...)
import "cbor" | cbor::cbor_stringify(1)
f93c00
csv_needs_quote(field: dynamic, delimiter: dynamic): bool
function
Checks whether a field's string form needs quoting for the given delimiter (RFC 4180): it contains a quote, newline, carriage return, the delimiter itself, or leading/trailing whitespace.
Module: import "csv" | csv::csv_needs_quote(...)
import "csv" | csv::csv_needs_quote("a,b", ",")
true
csv_parse_with_delimiter(input: dynamic, delimiter: dynamic, has_header: dynamic): array
function
Parses CSV content with a specified delimiter and optional header row.
Module: import "csv" | csv::csv_parse_with_delimiter(...)
import "csv" | csv::csv_parse_with_delimiter("a;b\n1;2", ";", true)
[{"a": "1", "b": "2"}]
csv_parse(input: dynamic, has_header: dynamic): array
function
Parses CSV content using a comma as the delimiter.
Module: import "csv" | csv::csv_parse(...)
import "csv" | csv::csv_parse("name,age\nAlice,30", true)
[{"name": "Alice", "age": "30"}]
tsv_parse(input: dynamic, has_header: dynamic): array
function
Parses TSV (Tab-Separated Values) content.
Module: import "csv" | csv::tsv_parse(...)
import "csv" | csv::tsv_parse("name\tage\nAlice\t30", true)
[{"name": "Alice", "age": "30"}]
psv_parse(input: dynamic, has_header: dynamic): array
function
Parses PSV (Pipe-Separated Values) content.
Module: import "csv" | csv::psv_parse(...)
import "csv" | csv::psv_parse("name|age\nAlice|30", true)
[{"name": "Alice", "age": "30"}]
csv_stringify(data: dynamic, delimiter: dynamic): string
function
Converts data to a CSV string with a specified delimiter.
Module: import "csv" | csv::csv_stringify(...)
import "csv" | csv::csv_stringify([{"name": "Alice", "age": 30}], ",")
name,age
Alice,30
csv_to_markdown_table(data: dynamic): string
function
Converts CSV data to a Markdown table format.
Module: import "csv" | csv::csv_to_markdown_table(...)
import "csv" | csv::csv_to_markdown_table([{"name": "Alice", "age": 30}])
| name | age |
| --- | --- |
| Alice | 30 |
csv_to_json(data: dynamic): string
function
Converts CSV data to a JSON string.
Module: import "csv" | csv::csv_to_json(...)
import "csv" | csv::csv_to_json([{"name": "Alice", "age": 30}])
[{"name":"Alice","age":30}]
levenshtein(s1: dynamic, s2: dynamic): number
function
Calculates the Levenshtein distance between two strings.
Module: import "fuzzy" | fuzzy::levenshtein(...)
import "fuzzy" | fuzzy::levenshtein("kitten", "sitting")
3
jaro(s1: dynamic, s2: dynamic): number
function
Calculates the Jaro distance between two strings (0.0 to 1.0, where 1.0 is exact match).
Module: import "fuzzy" | fuzzy::jaro(...)
import "fuzzy" | fuzzy::jaro("martha", "marhta")
0.944444
jaro_winkler(s1: dynamic, s2: dynamic): number
function
Calculates the Jaro-Winkler distance between two strings.
Module: import "fuzzy" | fuzzy::jaro_winkler(...)
import "fuzzy" | fuzzy::jaro_winkler("martha", "marhta")
0.961111
fuzzy_match(candidates: dynamic, query: dynamic): array
function
Performs fuzzy matching on an array of strings using Jaro-Winkler distance.
Module: import "fuzzy" | fuzzy::fuzzy_match(...)
import "fuzzy" | fuzzy::fuzzy_match(["apple", "aple", "banana"], "aple")
[{"text": "aple", "score": 1}, {"text": "apple", "score": 0.946667}, {"text": "banana", "score": 0.472222}]
fuzzy_match_levenshtein(candidates: dynamic, query: dynamic): array
function
Performs fuzzy matching using Levenshtein distance.
Module: import "fuzzy" | fuzzy::fuzzy_match_levenshtein(...)
import "fuzzy" | fuzzy::fuzzy_match_levenshtein(["apple", "aple", "banana"], "aple")
[{"text": "aple", "score": 0}, {"text": "apple", "score": 1}, {"text": "banana", "score": 5}]
fuzzy_match_jaro(candidates: dynamic, query: dynamic): array
function
Performs fuzzy matching using Jaro distance.
Module: import "fuzzy" | fuzzy::fuzzy_match_jaro(...)
import "fuzzy" | fuzzy::fuzzy_match_jaro(["apple", "aple", "banana"], "aple")
[{"text": "aple", "score": 1}, {"text": "apple", "score": 0.933333}, {"text": "banana", "score": 0.472222}]
fuzzy_filter(candidates: dynamic, query: dynamic, threshold: dynamic): array
function
Filters candidates by minimum fuzzy match score using Jaro-Winkler.
Module: import "fuzzy" | fuzzy::fuzzy_filter(...)
import "fuzzy" | fuzzy::fuzzy_filter(["apple", "aple", "banana"], "aple", 0.8)
[{"text": "aple", "score": 1}, {"text": "apple", "score": 0.946667}]
fuzzy_best_match(candidates: dynamic, query: dynamic): dict
function
Finds the best fuzzy match from candidates.
Module: import "fuzzy" | fuzzy::fuzzy_best_match(...)
import "fuzzy" | fuzzy::fuzzy_best_match(["apple", "aple", "banana"], "aple")
{"text": "aple", "score": 1}
gron_parse(input: dynamic): dynamic
function
Parses gron-style `path = value;` assignment statements (as produced by `mq -F gron`) and returns the corresponding data structure.
Module: import "gron" | gron::gron_parse(...)
import "gron" | gron::gron_parse("json.a = 1;\njson.b = 2;")
{"a": 1, "b": 2}
json_parse(input: dynamic): dynamic
function
Parses a JSON string and returns the corresponding data structure.
Module: import "json" | json::json_parse(...)
import "json" | json::json_parse("{\"a\": 1}")
{"a": 1}
json_stringify(data: dynamic): string
function
Serializes a value to a JSON string.
Module: import "json" | json::json_stringify(...)
import "json" | json::json_stringify({"a": 1})
{"a": 1}
json_to_markdown_table(data: dynamic): string
function
Converts a JSON data structure to a Markdown table.
Module: import "json" | json::json_to_markdown_table(...)
import "json" | json::json_to_markdown_table([{"a": 1, "b": 2}])
| a | b |
| --- | --- |
| 1 | 2 |
h(value: dynamic, depth: dynamic): markdown
function
Wraps `value` in a heading node at the given `depth` (1-6).
Module: import "md" | md::h(...)
import "md" | md::h("Title", 1)
# Title
code(value: dynamic, lang: dynamic): markdown
function
Wraps `value` in a fenced code block with the given `lang`.
Module: import "md" | md::code(...)
code_inline(value: dynamic): markdown
function
Wraps `value` in an inline code span.
Module: import "md" | md::code_inline(...)
import "md" | md::code_inline("x")
`x`
text(value: dynamic): markdown
function
Creates a plain text node from `value`.
Module: import "md" | md::text(...)
import "md" | md::text("hi")
hi
strong(value: dynamic): markdown
function
Wraps `value` in a strong (bold) node.
Module: import "md" | md::strong(...)
import "md" | md::strong("Bold")
**Bold**
em(value: dynamic): markdown
function
Wraps `value` in an emphasis (italic) node.
Module: import "md" | md::em(...)
import "md" | md::em("Italic")
*Italic*
delete(value: dynamic): markdown
function
Wraps `value` in a delete (strikethrough) node.
Module: import "md" | md::delete(...)
import "md" | md::delete("Old")
~~Old~~
blockquote(value: dynamic): markdown
function
Wraps `value` in a blockquote node.
Module: import "md" | md::blockquote(...)
import "md" | md::blockquote("Quote")
> Quote
callout(value: dynamic, kind: dynamic, title: dynamic): markdown
function
Wraps `value` in a callout node of the given `kind` (e.g. "note", "warning"), with an optional custom `title`.
Module: import "md" | md::callout(...)
import "md" | md::callout("Note text", "note", "")
> [!NOTE]
> Note text
hr(): markdown
function
Creates a horizontal rule node.
Module: import "md" | md::hr(...)
import "md" | md::hr()
***
br(): markdown
function
Creates a blank line between the surrounding elements in a `doc()`/`to_md_fragment()` call.
Module: import "md" | md::br(...)
math(value: dynamic): markdown
function
Wraps `value` in a math block node.
Module: import "md" | md::math(...)
import "md" | md::math("x^2")
$$
x^2
$$
math_inline(value: dynamic): markdown
function
Wraps `value` in an inline math node.
Module: import "md" | md::math_inline(...)
import "md" | md::math_inline("x^2")
$x^2$
link(url: dynamic, value: dynamic, title: dynamic): markdown
function
Creates a link node pointing to `url` with link text `value` and an optional `title`.
Module: import "md" | md::link(...)
import "md" | md::link("https://example.com", "Example", "")
[Example](https://example.com)
image(url: dynamic, alt: dynamic, title: dynamic): markdown
function
Creates an image node pointing to `url` with `alt` text and an optional `title`.
Module: import "md" | md::image(...)
import "md" | md::image("https://example.com/a.png", "Alt", "")

footnote(value: dynamic, ident: dynamic): markdown
function
Wraps `value` in a footnote definition node identified by `ident`.
Module: import "md" | md::footnote(...)
import "md" | md::footnote("Footnote text", "1")
[^1]: Footnote text
footnote_ref(ident: dynamic): markdown
function
Creates a footnote reference node pointing at `ident`.
Module: import "md" | md::footnote_ref(...)
import "md" | md::footnote_ref("1")
[^1]
definition(url: dynamic, ident: dynamic, title: dynamic): markdown
function
Creates a link reference definition node (`[ident]: url "title"`) for `ident`, with an optional `title`.
Module: import "md" | md::definition(...)
import "md" | md::definition("https://example.com", "ex", "")
[ex]: https://example.com
html(value: dynamic): markdown
function
Wraps `value` in a raw HTML node, emitted as-is.
Module: import "md" | md::html(...)
import "md" | md::html("<br>")
<br>
linebreak(): markdown
function
Creates a hard line break node.
Module: import "md" | md::linebreak(...)
list(value: dynamic, level: dynamic, ordered: dynamic, checked: dynamic): markdown
function
Wraps `value` in a list item node at the given `level` (0-indexed nesting), optionally `ordered` (numbered) and/or `checked` (checkbox); pass `checked = None` for a plain item.
Module: import "md" | md::list(...)
import "md" | md::list("Item", 0)
- Item
table_row(cells: dynamic): markdown
function
Creates a table row node from an array of cell values.
Module: import "md" | md::table_row(...)
import "md" | md::table_row(["a", "b"])
|a|b|
table_cell(value: dynamic, row: dynamic, column: dynamic): markdown
function
Creates a single table cell node at the given `row`/`column`.
Module: import "md" | md::table_cell(...)
import "md" | md::table_cell("A1", 0, 0)
A1
table_align(aligns: dynamic): markdown
function
Creates a table alignment (header separator) row node from an array of alignments (e.g. ["left", "right", "center"]).
Module: import "md" | md::table_align(...)
import "md" | md::table_align(["left", "right"])
|:---|---:|
table(header: dynamic, rows: dynamic, aligns: dynamic): array
function
Builds a full table from a `header` array of cell values and a `rows` array of row arrays. `aligns` is an array of alignment strings (e.g. ["left", "right", "center"]) matching `header`'s length; defaults to no alignment. Returns an array of row/align nodes ready to splice into `doc()`.
Module: import "md" | md::table(...)
import "md" | md::doc(md::table(["A", "B"], [["1", "2"], ["3", "4"]]))
|A|B|
|---|---|
|1|2|
|3|4|
doc(values: dynamic): markdown
function
Combines markdown nodes into a single markdown value. Accepts either a variable number of arguments (`doc(a, b, c)`) or a single array (`doc([a, b, c])`). Nested arrays (e.g. from `map()`) are flattened automatically, so components can return plain arrays of nodes and be spliced in as children.
Module: import "md" | md::doc(...)
import "md" | md::doc(md::h("T", 1), md::text("hi"))
# T
hi
section(md_nodes: dynamic, pattern: dynamic, depth: dynamic): array
function
Returns sections whose title contains the specified pattern. If depth is true, each section spans until the next header at the same or higher level (delegates to section::sections(md_nodes, depth), see its doc for details).
Module: import "section" | section::section(...)
import "section" | len(section::section(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B"), "A"))
2
sections(md_nodes: dynamic, depth: dynamic): array
function
Splits markdown nodes into sections based on headers. If depth is true, each section's body extends to the next heading at the same or higher level as that section's own heading, so nested subheadings' content is included in their parent's body. If depth is false (default), every heading of any level is a boundary, so a heading's body only extends to the very next heading regardless of level.
Module: import "section" | section::sections(...)
import "section" | len(section::sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B")))
3
import "section" | len(section::body(first(section::sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B"), true))))
3
filter_sections(md_nodes: dynamic, predicate: dynamic): array
function
Filters sections based on a given predicate function.
Module: import "section" | section::filter_sections(...)
import "section" | len(section::filter_sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B"), fn(s): true;))
3
map_sections(md_nodes: dynamic, mapper: dynamic): array
function
Maps sections using a given mapper function.
Module: import "section" | section::map_sections(...)
import "section" | section::map_sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B"), fn(header, children): to_text(header);)
["A", "A1", "B"]
split(md_nodes: dynamic, level: dynamic): array
function
Returns an array of sections, each section is an array of markdown nodes between the specified header and the next header of the same level.
Module: import "section" | section::split(...)
import "section" | len(section::split(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B"), 1))
2
title_contains(sections: dynamic, text: dynamic): array
function
Filters the given list of sections, returning only those whose title contains the specified text.
Module: import "section" | section::title_contains(...)
import "section" | len(section::title_contains(section::sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B")), "A"))
2
title_match(sections: dynamic, pattern: dynamic): array
function
Filters sections by a pattern match in the title text.
Module: import "section" | section::title_match(...)
import "section" | len(section::title_match(section::sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B")), "^A"))
2
title(section: dynamic): string
function
Returns the title text of a section (header text without the # symbols).
Module: import "section" | section::title(...)
import "section" | section::title(first(section::sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B"))))
A
content(section: dynamic): array
functionDeprecated
Returns the content of a section (all nodes except the header). Deprecated: Use body() instead, as content()
Module: import "section" | section::content(...)
import "section" | len(section::content(first(section::sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B")))))
1
body(section: dynamic): array
function
Returns the body of a section (all nodes except the header).
Module: import "section" | section::body(...)
import "section" | len(section::body(first(section::sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B")))))
1
all_nodes(section: dynamic): array
function
Returns all nodes of a section, including both the header and content.
Module: import "section" | section::all_nodes(...)
import "section" | len(section::all_nodes(first(section::sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B")))))
2
by_level(sections: dynamic, l: dynamic): array
function
Filters sections by heading level. l can be a number (exact level) or a range array (e.g. 1..2).
Module: import "section" | section::by_level(...)
import "section" | len(section::by_level(section::sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B")), 1))
2
level(section: dynamic): number
function
Returns the header level (1-6) of a section.
Module: import "section" | section::level(...)
import "section" | section::level(first(section::sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B"))))
1
nth(sections: dynamic, n: dynamic): dynamic
function
Returns the nth section from an array of sections (0-indexed).
Module: import "section" | section::nth(...)
import "section" | section::title(section::nth(section::sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B")), 0))
A
titles(sections: dynamic): array
function
Extracts titles from all sections.
Module: import "section" | section::titles(...)
import "section" | section::titles(section::sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B")))
["A", "A1", "B"]
bodies(sections: dynamic): array
function
Extracts body from all sections.
Module: import "section" | section::bodies(...)
import "section" | len(section::bodies(section::sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B"))))
3
toc(sections: dynamic): array
function
Generates a table of contents from sections.
Module: import "section" | section::toc(...)
import "section" | section::toc(section::sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B")))
[" - A", " - A1", " - B"]
has_content(section: dynamic): bool
function
Checks if a section has any content beyond the header.
Module: import "section" | section::has_content(...)
import "section" | section::has_content(first(section::sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B"))))
true
collect(sections: dynamic): array
function
Flattens sections back to markdown nodes for output. This converts section objects back to their original markdown node arrays.
Module: import "section" | section::collect(...)
import "section" | len(section::collect(section::sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B"))))
6
semver_parse(s: dynamic): dict
function
Parses a SemVer string into a dict with major, minor, patch, pre, and build fields.
Module: import "semver" | semver::semver_parse(...)
import "semver" | semver::semver_to_string(semver::semver_parse("1.2.3-beta.1"))
1.2.3-beta.1
semver_to_string(v: dynamic): string
function
Converts a parsed SemVer dict back to a version string.
Module: import "semver" | semver::semver_to_string(...)
import "semver" | semver::semver_to_string(semver::semver_parse("1.2.3-beta"))
1.2.3-beta
semver_compare(a: dynamic, b: dynamic): number
function
Compares two parsed SemVer dicts. Returns -1 if a < b, 0 if a == b, 1 if a > b.
Module: import "semver" | semver::semver_compare(...)
import "semver" | semver::semver_compare(semver::semver_parse("1.0.0"), semver::semver_parse("2.0.0"))
-1
semver_gt(a: dynamic, b: dynamic): bool
function
Returns true if version a is greater than version b.
Module: import "semver" | semver::semver_gt(...)
import "semver" | semver::semver_gt(semver::semver_parse("2.0.0"), semver::semver_parse("1.0.0"))
true
semver_lt(a: dynamic, b: dynamic): bool
function
Returns true if version a is less than version b.
Module: import "semver" | semver::semver_lt(...)
import "semver" | semver::semver_lt(semver::semver_parse("1.0.0"), semver::semver_parse("2.0.0"))
true
semver_eq(a: dynamic, b: dynamic): bool
function
Returns true if version a equals version b (ignoring build metadata).
Module: import "semver" | semver::semver_eq(...)
import "semver" | semver::semver_eq(semver::semver_parse("1.0.0"), semver::semver_parse("1.0.0"))
true
semver_gte(a: dynamic, b: dynamic): bool
function
Returns true if version a is greater than or equal to version b.
Module: import "semver" | semver::semver_gte(...)
import "semver" | semver::semver_gte(semver::semver_parse("1.0.0"), semver::semver_parse("1.0.0"))
true
semver_lte(a: dynamic, b: dynamic): bool
function
Returns true if version a is less than or equal to version b.
Module: import "semver" | semver::semver_lte(...)
import "semver" | semver::semver_lte(semver::semver_parse("1.0.0"), semver::semver_parse("1.0.0"))
true
semver_bump_major(v: dynamic): dict
function
Increments the major version and resets minor, patch, and pre-release.
Module: import "semver" | semver::semver_bump_major(...)
import "semver" | semver::semver_to_string(semver::semver_bump_major(semver::semver_parse("1.2.3")))
2.0.0
semver_bump_minor(v: dynamic): dict
function
Increments the minor version and resets patch and pre-release.
Module: import "semver" | semver::semver_bump_minor(...)
import "semver" | semver::semver_to_string(semver::semver_bump_minor(semver::semver_parse("1.2.3")))
1.3.0
semver_bump_patch(v: dynamic): dict
function
Increments the patch version and clears pre-release.
Module: import "semver" | semver::semver_bump_patch(...)
import "semver" | semver::semver_to_string(semver::semver_bump_patch(semver::semver_parse("1.2.3")))
1.2.4
semver_sort(versions: dynamic): array
function
Sorts an array of parsed SemVer dicts in ascending order.
Module: import "semver" | semver::semver_sort(...)
import "semver" | map(semver::semver_sort([semver::semver_parse("2.0.0"), semver::semver_parse("1.0.0")]), semver::semver_to_string)
["1.0.0", "2.0.0"]
semver_max(versions: dynamic): dict
function
Returns the maximum version from an array of parsed SemVer dicts.
Module: import "semver" | semver::semver_max(...)
import "semver" | semver::semver_to_string(semver::semver_max([semver::semver_parse("1.0.0"), semver::semver_parse("2.0.0")]))
2.0.0
semver_min(versions: dynamic): dict
function
Returns the minimum version from an array of parsed SemVer dicts.
Module: import "semver" | semver::semver_min(...)
import "semver" | semver::semver_to_string(semver::semver_min([semver::semver_parse("1.0.0"), semver::semver_parse("2.0.0")]))
1.0.0
semver_satisfies(version: dynamic, range: dynamic): bool
function
Returns true if the given version string satisfies every comma-separated comparator in `range`. Supported comparators: "=", "==", "!=", ">", ">=", "<", "<=". A bare version (no operator) requires an exact match. Example: semver_satisfies("1.5.0", ">=1.0.0,<2.0.0") == true
Module: import "semver" | semver::semver_satisfies(...)
import "semver" | semver::semver_satisfies("1.5.0", ">=1.0.0,<2.0.0")
true
tables(md_nodes: dynamic): array
function
Extract table structures from a list of markdown nodes.
Module: import "table" | table::tables(...)
import "table" | table::tables(to_markdown("| a | b |\n| --- | --- |\n| 1 | 2 |\n| 3 | 4 |")) | len(self)
1
set_align(table: dynamic, align: dynamic): dict
function
Set the alignment for a table.
Module: import "table" | table::set_align(...)
import "table" | table::tables(to_markdown("| a | b |\n| --- | --- |\n| 1 | 2 |\n| 3 | 4 |")) | first(self) | table::set_align(self, ["left", "right"]) | table::to_csv(self)
a,b
1,2
3,4
add_row(table: dynamic, row: dynamic): dict
function
Add a new row to a table.
Module: import "table" | table::add_row(...)
import "table" | table::tables(to_markdown("| a | b |\n| --- | --- |\n| 1 | 2 |\n| 3 | 4 |")) | first(self) | table::add_row(self, ["5", "6"]) | table::to_csv(self)
a,b
1,2
3,4
5,6
add_column(table: dynamic, col: dynamic): dict
function
Add a new column to a table.
Module: import "table" | table::add_column(...)
import "table" | table::tables(to_markdown("| a | b |\n| --- | --- |\n| 1 | 2 |\n| 3 | 4 |")) | first(self) | table::add_column(self, ["c", "9", "10"]) | table::to_csv(self)
a,b,c
1,2,9
3,4,10
remove_row(table: dynamic, row_index: dynamic): dict
function
Remove a row from a table at the specified index.
Module: import "table" | table::remove_row(...)
import "table" | table::tables(to_markdown("| a | b |\n| --- | --- |\n| 1 | 2 |\n| 3 | 4 |")) | first(self) | table::remove_row(self, 0) | table::to_csv(self)
a,b
3,4
remove_column(table: dynamic, col_index: dynamic): dict
function
Remove a column from a table at the specified index.
Module: import "table" | table::remove_column(...)
import "table" | table::tables(to_markdown("| a | b |\n| --- | --- |\n| 1 | 2 |\n| 3 | 4 |")) | first(self) | table::remove_column(self, 0) | len(self[:rows][0])
1
map_rows(table: dynamic, f: dynamic): dict
function
Map a function over each row in the table.
Module: import "table" | table::map_rows(...)
import "table" | table::tables(to_markdown("| a | b |\n| --- | --- |\n| 1 | 2 |\n| 3 | 4 |")) | first(self) | table::map_rows(self, fn(row): row;) | table::to_csv(self)
a,b
1,2
3,4
filter_tables(tables: dynamic, f: dynamic): array
function
Filter tables from markdown nodes based on a predicate function.
Module: import "table" | table::filter_tables(...)
import "table" | table::tables(to_markdown("| a | b |\n| --- | --- |\n| 1 | 2 |\n| 3 | 4 |")) | table::filter_tables(self, fn(h, r): true;) | len(self)
1
filter_rows(table: dynamic, f: dynamic): dict
function
Filter rows in the table based on a predicate function.
Module: import "table" | table::filter_rows(...)
import "table" | table::tables(to_markdown("| a | b |\n| --- | --- |\n| 1 | 2 |\n| 3 | 4 |")) | first(self) | table::filter_rows(self, fn(row): true;) | table::to_csv(self)
a,b
1,2
3,4
sort_rows(table: dynamic, column_index: dynamic): dict
function
Sort rows in the table by a specified column index or default sorting.
Module: import "table" | table::sort_rows(...)
import "table" | table::tables(to_markdown("| a | b |\n| --- | --- |\n| 1 | 2 |\n| 3 | 4 |")) | first(self) | table::sort_rows(self) | table::to_csv(self)
a,b
1,2
3,4
to_markdown(table: dynamic): array
function
Convert a table structure back into a list of markdown nodes.
Module: import "table" | table::to_markdown(...)
import "table" | table::tables(to_markdown("| a | b |\n| --- | --- |\n| 1 | 2 |\n| 3 | 4 |")) | first(self) | table::to_markdown(self) | len(self)
7
to_csv(table: dynamic, delimiter: dynamic): string
function
Convert a table structure into a CSV string with the specified delimiter.
Module: import "table" | table::to_csv(...)
import "table" | table::tables(to_markdown("| a | b |\n| --- | --- |\n| 1 | 2 |\n| 3 | 4 |")) | first(self) | table::to_csv(self)
a,b
1,2
3,4
to_array(table: dynamic): array
function
Convert a table structure into an array of dict records keyed by header text. The resulting shape matches `csv::csv_parse`'s output, so it composes with `join_by` and other record-array builtins.
Module: import "table" | table::to_array(...)
import "table" | table::tables(to_markdown("| a | b |\n| --- | --- |\n| 1 | 2 |\n| 3 | 4 |")) | first(self) | table::to_array(self)
[{"a": "1", "b": "2"}, {"a": "3", "b": "4"}]
pivot_longer(table: dynamic, value_columns: dynamic, names_to: dynamic, values_to: dynamic): dict
function
Reshape a table from wide format to long format (a.k.a. melt/unpivot). `value_columns` is an array of column indices to unpivot; each one becomes a row holding its header name (in the `names_to` column) and its cell value (in the `values_to` column). Columns not listed in `value_columns` are treated as identifier columns and repeated for every unpivoted value.
Module: import "table" | table::pivot_longer(...)
import "table" | table::tables(to_markdown("| a | b |\n| --- | --- |\n| 1 | 2 |\n| 3 | 4 |")) | first(self) | table::pivot_longer(self, [1]) | table::to_csv(self)
a,name,value
1,b,2
3,b,4
pivot_wider(table: dynamic, names_from: dynamic, values_from: dynamic): dict
function
Reshape a table from long format to wide format (a.k.a. pivot/cast). `names_from` is the column index whose distinct values become the headers of new columns; `values_from` is the column index supplying the values for those new columns. Columns other than `names_from` and `values_from` are treated as identifier columns and used to group rows together.
Module: import "table" | table::pivot_wider(...)
import "table" | table::tables(to_markdown("| id | name | value |\n| --- | --- | --- |\n| 1 | x | 10 |\n| 1 | y | 20 |")) | first(self) | table::pivot_wider(self, 1, 2) | table::to_csv(self)
id,x,y
1,10,20
assert(cond: dynamic): dynamic
function
Verifies that a condition is true and raises an error if it's false.
Module: import "test" | test::assert(...)
true | include "test" | assert(true)
true
assert_eq(actual: dynamic, expected: dynamic): dynamic
function
Verifies that two values are equal
Module: import "test" | test::assert_eq(...)
1 | include "test" | assert_eq(1, 1)
1
assert_ne(actual: dynamic, expected: dynamic): dynamic
function
Verifies that two values are not equal
Module: import "test" | test::assert_ne(...)
1 | include "test" | assert_ne(1, 2)
1
assert_true(value: dynamic): dynamic
function
Verifies that a value is true
Module: import "test" | test::assert_true(...)
true | include "test" | assert_true(true)
true
assert_false(value: dynamic): dynamic
function
Verifies that a value is false
Module: import "test" | test::assert_false(...)
false | include "test" | assert_false(false)
false
assert_none(value: dynamic): dynamic
function
Verifies that a value is None
Module: import "test" | test::assert_none(...)
None | include "test" | assert_none(None)
assert_not_none(value: dynamic): dynamic
function
Verifies that a value is not None
Module: import "test" | test::assert_not_none(...)
1 | include "test" | assert_not_none(1)
1
assert_contains(array: dynamic, value: dynamic): dynamic
function
Verifies that an array contains a specific value
Module: import "test" | test::assert_contains(...)
[1, 2] | include "test" | assert_contains([1, 2], 1)
[1, 2]
assert_len(array: dynamic, expected_length: dynamic): dynamic
function
Verifies that an array has a specific length
Module: import "test" | test::assert_len(...)
[1, 2] | include "test" | assert_len([1, 2], 2)
[1, 2]
assert_empty(array: dynamic): dynamic
function
Verifies that an array is empty
Module: import "test" | test::assert_empty(...)
[] | include "test" | assert_empty([])
[]
assert_not_empty(array: dynamic): dynamic
function
Verifies that an array is not empty
Module: import "test" | test::assert_not_empty(...)
[1] | include "test" | assert_not_empty([1])
[1]
assert_type(value: dynamic, expected_type: dynamic): dynamic
function
Verifies that a value has the given type. For markdown nodes this checks the node kind (e.g. "h1", "code", "list"), matching `to_md_name`. For every other value it checks the runtime type returned by `type`. On failure the source range of `value` is included so callers (e.g. content-lint rules) can point at the offending node.
Module: import "test" | test::assert_type(...)
1 | include "test" | assert_type(1, "number")
1
assert_field(value: dynamic, field: dynamic): dynamic
function
Verifies that a dict has the given field.
Module: import "test" | test::assert_field(...)
{"a": 1} | include "test" | assert_field({"a": 1}, "a")
{"a": 1}
assert_matches(value: dynamic, pattern: dynamic): dynamic
function
Verifies that a value's string representation matches the given regular expression pattern.
Module: import "test" | test::assert_matches(...)
"abc" | include "test" | assert_matches("abc", "a.c")
abc
run_tests(tests: dynamic): bool
function
Executes multiple test functions. The whole report is built as a single string and printed with one `print` call, so concurrently running test files (the Rust runner may evaluate several files in parallel) can never interleave their output mid-line. Returns `true` if every test passed, so the caller can aggregate pass/fail across files itself instead of this function terminating the process.
Module: import "test" | test::run_tests(...)
test_case(name: dynamic, func: dynamic): dict
function
Helper function to create a test case
Module: import "test" | test::test_case(...)
include "test" | test_case("my test", fn(): true;)["name"]
my test
toml_parse(input: dynamic): dynamic
function
Parses a TOML string and returns the parsed data structure.
Module: import "toml" | toml::toml_parse(...)
import "toml" | toml::toml_parse("key = 1")
{"key": 1}
toml_stringify(data: dynamic): string
function
Converts a data structure to a TOML string representation.
Module: import "toml" | toml::toml_stringify(...)
import "toml" | toml::toml_stringify({"key": 1})
key = 1
toml_to_json(data: dynamic): string
function
Converts a data structure to a JSON string representation.
Module: import "toml" | toml::toml_to_json(...)
import "toml" | toml::toml_to_json({"key": 1})
{"key":1}
toml_to_markdown_table(data: dynamic): string
function
Converts a TOML data structure to a Markdown table.
Module: import "toml" | toml::toml_to_markdown_table(...)
import "toml" | toml::toml_to_markdown_table([{"a": 1}])
| a |
| --- |
| 1 |
toon_stringify(data: dynamic): string
function
To convert a data structure into a TOON string
Module: import "toon" | toon::toon_stringify(...)
import "toon" | toon::toon_stringify({"a": 1})
a: 1
toon_parse(input: dynamic): dynamic
function
To parse a TOON string into a data structure
Module: import "toon" | toon::toon_parse(...)
import "toon" | toon::toon_parse(toon::toon_stringify({"a": 1}))
{"a": 1}
xml_parse(input: dynamic): dynamic
function
Parses an XML string and returns the corresponding data structure.
Module: import "xml" | xml::xml_parse(...)
import "xml" | xml::xml_parse("<a>hi</a>")["tag"]
a
xml_stringify(data: dynamic): string
function
Serializes a value to an XML string.
Module: import "xml" | xml::xml_stringify(...)
import "xml" | xml::xml_stringify({"tag": "a", "attributes": {}, "children": [], "text": "hi"})
<?xml version="1.0" encoding="UTF-8"?>
<a>hi</a>
xml_to_markdown_table(data: dynamic): string
function
Converts an XML data structure to a Markdown table.
Module: import "xml" | xml::xml_to_markdown_table(...)
import "xml" | xml::xml_to_markdown_table({"tag": "a", "attributes": {}, "children": [], "text": "hi"})
| Tag | Attributes | Text | Children |
| --- | --- | --- | --- |
| a | | hi | 0 |
yaml_parse(input: dynamic): dynamic
function
Parses a YAML string and returns the parsed data structure. A single `---`-separated document is returned as-is; if the input contains multiple `---`-separated documents, an array of the parsed documents is returned.
Module: import "yaml" | yaml::yaml_parse(...)
import "yaml" | yaml::yaml_parse("key: 1")
{"key": 1}
yaml_stringify(data: dynamic): string
function
Converts a data structure to a YAML string representation.
Module: import "yaml" | yaml::yaml_stringify(...)
import "yaml" | yaml::yaml_stringify({"key": 1})
key: 1
yaml_to_markdown_table(data: dynamic): string
function
Converts a YAML data structure to a Markdown table.
Module: import "yaml" | yaml::yaml_to_markdown_table(...)
import "yaml" | yaml::yaml_to_markdown_table([{"a": 1}])
| a |
| --- |
| 1 |
yaml_to_json(data: dynamic): string
function
Converts a data structure to a JSON string representation.
Module: import "yaml" | yaml::yaml_to_json(...)
import "yaml" | yaml::yaml_to_json({"key": 1})
{"key": 1}
to_front_matter(data: dynamic): string
functionDeprecated
Converts a data structure to a YAML front matter string. deprecated: use to_frontmatter instead
Module: import "yaml" | yaml::to_front_matter(...)
import "yaml" | yaml::to_front_matter({"key": 1})
---
key: 1
---
to_frontmatter(data: dynamic): string
function
Converts a data structure to a YAML front matter string.
Module: import "yaml" | yaml::to_frontmatter(...)
import "yaml" | yaml::to_frontmatter({"key": 1})
---
key: 1
---
340 functions
abs(number: number): number
function
Returns the absolute value of the given number.
abs(-10)
10
add(value1: dynamic, value2: dynamic): dynamic
function
Adds two values.
add(1, 2)
3
all_symbols(): array
function
Returns an array of all interned symbols.
and(value1: bool, value2: bool): bool
function
Performs a logical AND operation on two boolean values.
and(true, false)
false
array(values: dynamic): array
function
Creates an array from the given values.
array(1, 2, 3)
[1, 2, 3]
ascii_downcase(input: string): string
function
Converts ASCII uppercase letters (A-Z) in the given string to lowercase, leaving all other characters unchanged.
ascii_downcase("ABC")
abc
ascii_upcase(input: string): string
function
Converts ASCII lowercase letters (a-z) in the given string to uppercase, leaving all other characters unchanged.
ascii_upcase("abc")
ABC
attr(markdown: markdown, attribute: string): dynamic
function
Retrieves the value of the specified attribute from a markdown node.
band(bytes1: bytes, bytes2: bytes): bytes
function
Computes the bitwise AND of two byte arrays of equal length.
base64(input: string): string
function
Encodes the given string to base64.
base64("hi")
aGk=
base64d(input: string): string
function
Decodes the given base64 string.
base64d("aGk=")
hi
base64url(input: string): string
function
Encodes the given string to URL-safe base64.
base64url("hi")
aGk
base64urld(input: string): string
function
Decodes the given URL-safe base64 string.
base64urld(base64url("hi"))
hi
basename(path: string): string
function
Returns the final component of a path string (e.g. "file.txt" from "/a/b/file.txt").
basename("/a/b/file.txt")
file.txt
bnot(bytes: bytes): bytes
function
Computes the bitwise NOT (complement) of a byte array.
bor(bytes1: bytes, bytes2: bytes): bytes
function
Computes the bitwise OR of two byte arrays of equal length.
breakpoint(): dynamic
function
Sets a breakpoint for debugging; execution will pause at this point if a debugger is attached.
capture(string: string, pattern: string): dict
function
Captures named groups from the given string based on the specified regular expression pattern and returns them as a dictionary keyed by group names.
capture("v1.2.3", "(?P<major>[0-9]+)")
{"major": "1"}
ceil(number: number): number
function
Rounds the given number up to the nearest integer.
ceil(3.2)
4
coalesce(value1: dynamic, value2: dynamic): dynamic
function
Returns the first non-None value from the two provided arguments.
coalesce(None, 5)
5
collection(dir: string, respect_gitignore?: boolean): array
functionrequires file-io
Recursively reads every Markdown file in the given directory (including subdirectories and symlinked files/directories) and returns an array of `{path, title, frontmatter, content}` dicts, sorted by path, so they can be filtered, sorted, or aggregated as a single dataset. `content` holds the file's Markdown nodes with frontmatter stripped. Symlink cycles are detected and only visited once. `respect_gitignore` is optional (default `false`); when `true`, dotfiles/dot-directories and any path matched by a `.gitignore` in `dir` or a subdirectory are skipped, with closer `.gitignore` files taking precedence, same as `git`. Requires the --allow-read CLI flag; otherwise returns a runtime error.
compact(array: array): array
function
Removes None values from the given array.
compact([1, None, 2])
[1, 2]
convert(input: dynamic, format: string): dynamic
function
Converts the input value to the specified format. Supported formats: base64, html, text, uri, heading (#, ##, etc.), blockquote (>), list item (-), or link (URL).
date_add(array: array, n: number, unit: string): array
function
Adds n units to a broken-down time array and returns a new array. Units: "seconds", "minutes", "hours", "days", "weeks", "months", "years". Month/year arithmetic is calendar-aware.
date_diff(array1: array, array2: array, unit: string): number
function
Returns the difference (array2 - array1) in the given unit. Units: "seconds", "minutes", "hours", "days", "weeks".
date_diff(gmtime(0), gmtime(86400), "days")
1
date_relative(base_timestamp: number, date_str: string): number
function
Parses a natural-language relative date expression (e.g. "3 days ago", "yesterday", "tomorrow", "next monday", "in 2 weeks") relative to a base Unix timestamp and returns the resulting Unix timestamp (seconds, UTC).
del(array_or_string: dynamic, index: number): dynamic
function
Deletes the element at the specified index in the array or string.
del([1, 2, 3], 1)
[1, 3]
dict(): dict
function
Creates a new, empty dict.
dict()
{}
dirname(path: string): string
function
Returns the parent directory of a path string (e.g. "/a/b" from "/a/b/file.txt"). Returns "." if the path has no parent.
dirname("/a/b/file.txt")
/a/b
div(value1: dynamic, value2: dynamic): dynamic
function
Divides the first value by the second value.
div(6, 2)
3
downcase(input: string): string
function
Converts the given string to lowercase.
downcase("ABC")
abc
embed_images(base_dir: string): markdown
functionrequires file-io
Inlines an `.image` node's local file into its `url` as a base64 `data:` URI, resolving the path relative to the given base directory (default ".") and inferring the MIME type from the file extension. URLs that are already `data:` URIs or contain a `://` scheme (e.g. `https://`), and non-image nodes, are left unchanged. Requires the --allow-read CLI flag; otherwise returns a runtime error.
ends_with(value: dynamic, suffix: dynamic): bool
function
Checks if the given string or byte array ends with the specified suffix.
ends_with("hello", "lo")
true
entries(dict: dict): array
function
Returns an array of key-value pairs from the dict as arrays.
eq(value1: dynamic, value2: dynamic): bool
function
Checks if two values are equal.
eq(1, 1)
true
error(message: string): dynamic
function
Raises a user-defined error with the specified message.
exp(number: number): number
function
Returns the exponential (e^x) of the given number.
exp(0)
1
explode(string: string): array
function
Splits the given string into an array of characters.
explode("ab")
[97, 98]
extname(path: string): string
function
Returns the extension of a file path including the leading dot (e.g. ".txt" from "file.txt"). Returns an empty string if there is no extension.
extname("file.txt")
.txt
extract_images(dir: string): markdown
functionrequires file-io
Decodes an `.image` node's base64 `data:` URI and writes the bytes to a file under the given directory, named by the content's MD5 hash with an extension inferred from the MIME type, then replaces `url` with that file's path. Nodes whose `url` is not a base64 `data:` URI, including non-image nodes, are left unchanged. Requires the --allow-write CLI flag; otherwise returns a runtime error.
file_exists(path: string): bool
functionrequires file-io
Checks if a file exists at the given path. Requires the --allow-read CLI flag; otherwise returns a runtime error.
file_size(path: string): number
functionrequires file-io
Returns the size, in bytes, of the file at the given path. Requires the --allow-read CLI flag; otherwise returns a runtime error.
flatten(array: array): array
function
Flattens a nested array into a single level array.
flatten([[1, 2], [3]])
[1, 2, 3]
floor(number: number): number
function
Rounds the given number down to the nearest integer.
floor(3.8)
3
from_date(date_str: string): number
function
Converts a date string to a timestamp.
from_date("1970-01-01T00:00:00Z")
0
from_hex(hex_string: string): bytes
function
Parses a hex string into raw bytes.
from_html(html: string): array
function
Converts the given HTML string to Markdown.
get(obj: dict, key: dynamic): dynamic
function
Retrieves a value from a dict by its key. Returns None if the key is not found.
get_location(node: markdown): dict
function
Returns the source position of a markdown node as a dict with start_line, start_column, end_line, and end_column, or None if the node has no position info.
get_title(node: markdown): string
function
Returns the title of a markdown node.
get_url(node: markdown): string
function
Returns the url of a markdown node.
get_url(to_link("https://example.com", "Example", ""))
https://example.com
get_variable(symbol_or_string: dynamic): dynamic
function
Retrieves the value of a symbol or variable from the current environment.
glob_match(pattern: string, path: string): bool
function
Checks whether the given path matches the glob pattern (e.g. "*.md", "docs/**/*.rs"), commonly used to filter file lists.
glob_match("*.md", "readme.md")
true
gmtime(timestamp: number): array
function
Converts Unix timestamp (seconds since epoch) to broken-down UTC time array [year, mon (0-11), mday, hour, min, sec, wday (0=Sun), yday (0-365)].
gmtime(0)
[1970, 0, 1, 0, 0, 0, 4, 0]
gsub(from: string, pattern: string, to: string): string
function
Replaces all occurrences matching a regular expression pattern with the replacement string.
gsub("a1b2", "[0-9]", "#")
a#b#
gt(value1: dynamic, value2: dynamic): bool
function
Checks if the first value is greater than the second value.
gt(2, 1)
true
gte(value1: dynamic, value2: dynamic): bool
function
Checks if the first value is greater than or equal to the second value.
gte(1, 1)
true
halt(exit_code: number): dynamic
function
Terminates the program with the given exit code.
html_escape(string: string): string
function
Escapes `&`, `<`, `>`, `"`, and `'` in the given string as HTML entities.
html_escape("<a>")
<a>
html_unescape(string: string): string
function
Decodes named and numeric HTML entities in the given string into their corresponding characters.
html_unescape("<a>")
<a>
http(method: string, url: string, body: string, headers: dict): string
functionrequires http
Performs an HTTPS request with the given method (a string or symbol, e.g. "post" or :post — get, post, put, delete, patch, head, ... are all supported) and returns the response body as a string. An optional body argument (string) sends a request body regardless of method, and an optional headers argument (a dict of string to string, e.g. {"Content-Type": "application/json"}) is applied to the request. Requires the --allow-net CLI flag; otherwise returns a runtime error. Only https:// URLs are allowed.
implode(array: array): string
function
Joins an array of characters into a string.
implode(explode("ab"))
ab
index(value: dynamic, needle: dynamic): number
function
Finds the first occurrence of a substring or byte subsequence. Returns -1 if not found.
index("hello", "ll")
2
infinite(): number
function
Returns an infinite number value.
input(): string
function
Reads a line from standard input and returns it as a string.
insert(target: dynamic, index_or_key: dynamic, value: dynamic): dynamic
function
Inserts a value into an array or string at the specified index, or into a dict with the specified key.
insert([1, 2, 3], 1, "x")
[1, "x", 2, 3]
intern(string: string): string
function
Interns the given string, returning a canonical reference for efficient comparison.
intern("hi")
hi
is_not_regex_match(string: string, pattern: string): bool
function
Checks if the given pattern does not match the string.
is_not_regex_match("abc", "x")
true
is_regex_match(string: string, pattern: string): bool
function
Checks if the given pattern matches the string.
is_regex_match("abc", "a.c")
true
join(array: array, separator: string): string
function
Joins the elements of an array into a string with the given separator.
join([1, 2, 3], ",")
1,2,3
keys(dict: dict): array
function
Returns an array of keys from the dict.
len(value: dynamic): number
function
Returns the length of the given string or array.
len("hello")
5
ln(number: number): number
function
Returns the natural logarithm (base e) of the given number.
ln(1)
0
localtime(timestamp: number): array
function
Converts Unix timestamp (seconds since epoch) to broken-down local time array [year, mon (0-11), mday, hour, min, sec, wday (0=Sun), yday (0-365)].
log10(number: number): number
function
Returns the base-10 logarithm of the given number.
log10(100)
2
lt(value1: dynamic, value2: dynamic): bool
function
Checks if the first value is less than the second value.
lt(1, 2)
true
lte(value1: dynamic, value2: dynamic): bool
function
Checks if the first value is less than or equal to the second value.
lte(1, 1)
true
ltrim(input: string): string
function
Trims whitespace from the left end of the given string.
ltrim(" hi ")
hi
max(value1: dynamic, value2: dynamic): dynamic
function
Returns the maximum of two values.
max(1, 2)
2
md5(input: dynamic): string
function
Computes the MD5 hash of a string or bytes and returns a lowercase hex string.
min(value1: dynamic, value2: dynamic): dynamic
function
Returns the minimum of two values.
min(1, 2)
1
mktime(time_array: array): number
function
Converts broken-down UTC time array [year, mon (0-11), mday, hour, min, sec, wday, yday] to Unix timestamp (seconds since epoch).
mktime(gmtime(0))
0
mod(value1: dynamic, value2: dynamic): dynamic
function
Calculates the remainder of the division of the first value by the second value.
mod(7, 3)
1
mul(value1: dynamic, value2: dynamic): dynamic
function
Multiplies two values.
mul(2, 3)
6
nan(): number
function
Returns a Not-a-Number (NaN) value.
ne(value1: dynamic, value2: dynamic): bool
function
Checks if two values are not equal.
ne(1, 2)
true
negate(number: number): number
function
Returns the negation of the given number.
negate(5)
-5
not(value: bool): bool
function
Performs a logical NOT operation on a boolean value.
not(true)
false
now(): number
function
Returns the current timestamp.
or(value1: bool, value2: bool): bool
function
Performs a logical OR operation on two boolean values.
or(true, false)
true
pack(format: string, value: number): bytes
function
Packs a number into bytes using the given format. Supported formats: u8, i8, u16be/le, i16be/le, u32be/le, i32be/le, u64be/le, i64be/le, f32be/le, f64be/le.
partial(function: function, arg1: dynamic, arg2: dynamic, ...: dynamic): function
function
Creates a new function by partially applying the given arguments to the specified function.
path_join(base: string, component: string): string
function
Joins a base path with a component path and returns the resulting path string (e.g. path_join("/a/b", "c.txt") → "/a/b/c.txt").
path_join("/a/b", "c.txt")
/a/b/c.txt
pow(base: number, exponent: number): number
function
Raises the base to the power of the exponent.
pow(2, 10)
1024
print(message: string): dynamic
function
Prints a message to standard output and returns the current value.
rand(): number
function
Generates a pseudo-random number in the range [0, 1). Not cryptographically secure.
rand_int(min: number, max: number): number
function
Generates a pseudo-random integer uniformly distributed in [min, max] (inclusive). Not cryptographically secure.
random_string(len: number, charset: string): string
function
Generates a random string of `len` characters, each independently chosen (with replacement) from `charset`. Not cryptographically secure.
range(start: number, end: number, step: number): array
function
Creates an array from start to end with an optional step.
range(0, 5, 1)
[0, 1, 2, 3, 4, 5]
read_file(path: string): string
functionrequires file-io
Reads the contents of a file at the given path and returns it as a string. Requires the --allow-read CLI flag; otherwise returns a runtime error.
read_file_bytes(path: string): bytes
functionrequires file-io
Reads the contents of a file at the given path and returns it as raw bytes. Requires the --allow-read CLI flag; otherwise returns a runtime error.
regex_match(string: string, pattern: string): array
function
Finds all matches of the given pattern in the string.
regex_match("abc123", "[0-9]+")
["123"]
repeat(string: string, count: number): string
function
Repeats the given string a specified number of times.
repeat("ab", 3)
ababab
replace(from: string, pattern: string, to: string): string
function
Replaces all occurrences of a substring with another substring.
replace("aXbXc", "X", "-")
a-b-c
reverse(value: dynamic): dynamic
function
Reverses the given string or array.
reverse("abc")
cba
rindex(value: dynamic, needle: dynamic): number
function
Finds the last occurrence of a substring or byte subsequence. Returns -1 if not found.
rindex("hello", "l")
3
round(number: number): number
function
Rounds the given number to the nearest integer.
round(3.5)
4
rtrim(input: string): string
function
Trims whitespace from the right end of the given string.
rtrim(" hi ")
hi
sample(array: array, n: number): array
function
Returns n elements sampled from the array without replacement, in random order. Errors if n exceeds the array length.
sanitize_html(html: string): string
function
Sanitizes the given HTML string using an allowlist of safe tags and attributes, removing scripts and other XSS vectors.
scan(string: string, pattern: string): array
function
Finds all matches of a regular expression pattern in the string. For each match, returns the captured groups as an array if the pattern has capture groups, otherwise returns the whole match as a string.
scan("a1b2", "[0-9]")
["1", "2"]
set(obj: dict, key: dynamic, value: dynamic): dict
function
Sets a key-value pair in a dict. If the key exists, its value is updated. Returns the modified map.
set_attr(markdown: markdown, attribute: string, value: dynamic): markdown
function
Sets the value of the specified attribute on a markdown node.
set_check(list: markdown, checked: bool): markdown
function
Creates a markdown list node with the given checked state.
set_check(to_md_list("Item", 0), true)
- [x] Item
set_children(markdown: markdown, children: array): markdown
function
Sets the children nodes of a markdown node. Nodes without children (e.g. text, code) are left unchanged.
set_code_block_lang(code_block: markdown, language: string): markdown
function
Sets the language of a markdown code block node.
set_code_block_lang(to_code("x", "python"), "rust")
```rust
x
```
set_list_ordered(list: markdown, ordered: bool): markdown
function
Sets the ordered property of a markdown list node.
set_list_ordered(to_md_list("Item", 0), true)
1. Item
set_ref(node: markdown, reference_id: string): markdown
function
Sets the reference identifier for markdown nodes that support references (e.g., Definition, LinkRef, ImageRef, Footnote, FootnoteRef).
set_variable(symbol_or_string: dynamic, value: dynamic): dynamic
function
Sets a symbol or variable in the current environment with the given value.
sha256(input: dynamic): string
function
Computes the SHA-256 hash of a string or bytes and returns a lowercase hex string.
sha512(input: dynamic): string
function
Computes the SHA-512 hash of a string or bytes and returns a lowercase hex string.
shift_left(value: dynamic, shift_amount: number): dynamic
function
Performs a left shift operation on the given value: for numbers, this is a bitwise left shift by the specified number of positions; for strings, this removes characters from the start; for Markdown headings, this increases the heading level accordingly.
shift_left(1, 2)
4
shift_right(value: dynamic, shift_amount: number): dynamic
function
Performs a bitwise right shift on numbers, slices characters from the end of strings, and adjusts Markdown heading levels when applied to headings, using the given shift amount.
shift_right(8, 2)
2
shuffle(array: array): array
function
Returns a new array containing the same elements as the input, in a uniformly random order.
slice(string: string, start: number, end: number): string
function
Extracts a substring from the given string.
slice("hello", 1, 3)
el
sort(array: array): array
function
Sorts the elements of the given array.
sort([3, 1, 2])
[1, 2, 3]
split(string: string, separator: string): array
function
Splits the given string by the specified separator.
split("a,b,c", ",")
["a", "b", "c"]
sqrt(number: number): number
function
Returns the square root of the given number.
sqrt(9)
3
starts_with(value: dynamic, prefix: dynamic): bool
function
Checks if the given string or byte array starts with the specified prefix.
starts_with("hello", "he")
true
stderr(message: string): dynamic
function
Prints a message to standard error and returns the current value.
stem(path: string): string
function
Returns the file name without the extension (e.g. "file" from "/a/b/file.txt").
stem("/a/b/file.txt")
file
strftime(timestamp: number, format: string): string
function
Formats a Unix timestamp (seconds) as a date string using the given strftime format (e.g. "%Y-%m-%d").
strftime(0, "%Y-%m-%d")
1970-01-01
strip_tags(string: string): string
function
Removes HTML tags from the given string, keeping the surrounding text content.
strip_tags("<b>hi</b>")
hi
strptime(date_str: string, format: string): number
function
Parses a date string using the given strptime format (e.g. "%Y-%m-%d") and returns a Unix timestamp (seconds, UTC).
strptime("1970-01-01", "%Y-%m-%d")
0
sub(value1: dynamic, value2: dynamic): dynamic
function
Subtracts the second value from the first value.
sub(5, 2)
3
to_array(value: dynamic): array
function
Converts the given value to an array.
to_array(1)
[1]
to_blockquote(value: dynamic): markdown
function
Creates a markdown blockquote node with the given value.
to_blockquote("Quote")
> Quote
to_boolean(value: dynamic): bool
function
Converts the given value to a boolean. Booleans are returned unchanged, the strings "true" and "false" are converted to their boolean equivalent, and all other input results in an error.
to_boolean("true")
true
to_break(): markdown
function
Creates a markdown hard line break node.
to_break()
\
to_bytes(value: dynamic): bytes
function
Converts a string (UTF-8), array of numbers, or bytes to raw bytes.
to_callout(value: dynamic, kind: string, title: string): markdown
function
Creates a markdown callout node with the given value, kind, and title.
to_callout("Note text", "note", "")
> [!NOTE]
> Note text
to_code(value: dynamic, language: string): markdown
function
Creates a markdown code block with the given value and language.
to_code("x = 1", "python")
```python
x = 1
```
to_code_inline(value: dynamic): markdown
function
Creates an inline markdown code node with the given value.
to_code_inline("x")
`x`
to_date(timestamp: number, format: string): string
function
Converts a timestamp to a date string with the given format.
to_date(0, "%Y-%m-%d")
1970-01-01
to_definition(url: string, ident: string, title: string): markdown
function
Creates a markdown link reference definition node with the given url, identifier, and title.
to_definition("https://example.com", "ex", "")
[ex]: https://example.com
to_delete(value: dynamic): markdown
function
Creates a markdown delete (strikethrough) node with the given value.
to_delete("Old")
~~Old~~
to_em(value: dynamic): markdown
function
Creates a markdown emphasis (italic) node with the given value.
to_em("Italic")
*Italic*
to_footnote(value: dynamic, ident: string): markdown
function
Creates a markdown footnote definition node with the given value and identifier.
to_footnote("Footnote text", "1")
[^1]: Footnote text
to_footnote_ref(ident: string): markdown
function
Creates a markdown footnote reference node with the given identifier.
to_footnote_ref("1")
[^1]
to_h(value: dynamic, depth: number): markdown
function
Creates a markdown heading node with the given value and depth.
to_h("Title", 1)
# Title
to_hex(bytes: bytes): string
function
Encodes raw bytes as a lowercase hex string.
to_hex(from_hex("6869"))
6869
to_hr(): markdown
function
Creates a markdown horizontal rule node.
to_hr()
***
to_html(markdown: string): string
function
Converts the given markdown string to HTML.
to_image(url: string, alt: string, title: string): markdown
function
Creates a markdown image node with the given URL, alt text, and title.
to_image("https://example.com/a.png", "Alt", "")

to_link(url: string, value: dynamic, title: string): markdown
function
Creates a markdown link node with the given url and title.
to_link("https://example.com", "Example", "")
[Example](https://example.com)
to_markdown(markdown_string: string): array
function
Parses a markdown string and returns an array of markdown nodes.
to_markdown("# Hi")
[# Hi]
to_markdown_string(value: dynamic): string
function
Converts the given value(s) to a markdown string representation.
to_math(value: dynamic): markdown
function
Creates a markdown math block with the given value.
to_math("x^2")
$$
x^2
$$
to_math_inline(value: dynamic): markdown
function
Creates an inline markdown math node with the given value.
to_math_inline("x^2")
$x^2$
to_md_fragment(values: array): markdown
function
Creates a markdown fragment node that groups an array of markdown nodes into a single value.
to_md_html(value: dynamic): markdown
function
Creates a raw markdown HTML node with the given value.
to_md_html("<br>")
<br>
to_md_list(value: dynamic, indent: number): markdown
function
Creates a markdown list node with the given value and indent level.
to_md_list("Item", 0)
- Item
to_md_name(markdown: markdown): string
function
Returns the name of the given markdown node.
to_md_name(to_h("t", 1))
h1
to_md_table_align(aligns: array): markdown
function
Creates a markdown table alignment row node from an array of alignments ("left", "right", "center", "none").
to_md_table_align(["left", "right"])
|:---|---:|
to_md_table_cell(value: dynamic, row: number, column: number): markdown
function
Creates a markdown table cell node with the given value at the specified row and column.
to_md_table_cell("A1", 0, 0)
A1
to_md_table_row(cells: array): markdown
function
Creates a markdown table row node with the given values.
to_md_text(value: dynamic): markdown
function
Creates a markdown text node with the given value.
to_md_text("hi")
hi
to_mdx(mdx_string: string): array
function
Parses an MDX string and returns an array of MDX nodes.
to_number(value: dynamic): number
function
Converts the given value to a number.
to_number("42")
42
to_string(value: dynamic): string
function
Converts the given value to a string.
to_string(1)
1
to_strong(value: dynamic): markdown
function
Creates a markdown strong (bold) node with the given value.
to_strong("Bold")
**Bold**
to_text(markdown: markdown): string
function
Converts the given markdown node to plain text.
to_text(to_strong("hi"))
hi
token_compress(nodes: array, budget: number, model?: string): array
function
Reduces an array of Markdown nodes to fit within `budget` LLM tokens, preserving structure as much as possible: paragraphs are cut to their first sentence, then lists/tables/code blocks are collapsed to a summary, and only as a last resort is the remaining text hard-truncated. Uses a lightweight chars-per-token heuristic by default; built with the `tiktoken` Cargo feature, counts exactly via tiktoken-rs instead when `model` (e.g. "gpt-5") is given. `model` is optional; without it, the heuristic estimate is always used.
token_count(text: string, model?: string): number
function
Estimates how many LLM tokens the given text would consume, for context-window budgeting. Uses a lightweight chars-per-token heuristic by default; built with the `tiktoken` Cargo feature, counts exactly via tiktoken-rs instead when `model` (e.g. "gpt-5") is given. `model` is optional; without it, the heuristic estimate is always used.
token_count("Hello, world!")
4
trim(input: string): string
function
Trims whitespace from both ends of the given string.
trim(" hi ")
hi
trunc(number: number): number
function
Truncates the given number to an integer by removing the fractional part.
trunc(3.9)
3
truncate(string: string, width: number, ellipsis: string): string
function
Truncates the given string to the specified display width, appending the ellipsis string when truncated (CJK and other wide characters count as two columns).
truncate("hello world", 5, "...")
he...
type(value: dynamic): string
function
Returns the type of the given value.
type(1)
number
uniq(array: array): array
function
Removes duplicate elements from the given array.
uniq([1, 1, 2])
[1, 2]
unpack(format: string, bytes: bytes): number
function
Unpacks a number from bytes using the given format. Supported formats: u8, i8, u16be/le, i16be/le, u32be/le, i32be/le, u64be/le, i64be/le, f32be/le, f64be/le.
upcase(input: string): string
function
Converts the given string to uppercase.
upcase("abc")
ABC
update(target_value: dynamic, source_value: dynamic): dynamic
function
Update the value with specified value.
url_decode(input: string): string
function
URL-decodes the given string.
url_decode("a%20b")
a b
url_encode(input: string): string
function
URL-encodes the given string.
url_encode("a b")
a%20b
utf8(bytes: bytes): string
function
Decodes bytes as a UTF-8 string, returning an error if the bytes are not valid UTF-8.
utf8(to_bytes("hi"))
hi
uuid(): string
function
Generates a random (version 4, RFC 4122) UUID string.
uuid_v4(): string
function
Generates a random (version 4, RFC 4122) UUID string. Alias of `uuid`.
uuid_v7(): string
function
Generates a time-ordered (version 7, RFC 9562) UUID string: a millisecond Unix timestamp followed by random bits, so values sort by creation time. The timestamp is plaintext, so prefer uuid/uuid_v4 for unguessable IDs.
values(dict: dict): array
function
Returns an array of values from the dict.
word_wrap(string: string, width: number): string
function
Wraps the given string into lines no wider than the specified display width, breaking on word boundaries (CJK and other wide characters count as two columns).
word_wrap("hello world", 5)
hello
world
write_file(path: string, content: dynamic): dynamic
functionrequires file-io
Writes content (string or bytes) to the file at the given path, creating or truncating it. Requires the --allow-write CLI flag; otherwise returns a runtime error.
xor(bytes1: bytes, bytes2: bytes): bytes
function
Computes the bitwise XOR of two byte arrays of equal length.
halt_error(): dynamic
function
Halts execution with error code 5
is_array(a: dynamic): bool
function
Checks if input is an array
is_array([1, 2])
true
is_markdown(m: dynamic): bool
function
Checks if input is markdown
is_markdown(to_h("t", 1))
true
is_bool(b: dynamic): bool
function
Checks if input is a boolean
is_bool(true)
true
is_number(n: dynamic): bool
function
Checks if input is a number
is_number(1)
true
is_string(s: dynamic): bool
function
Checks if input is a string
is_string("hi")
true
is_none(n: dynamic): bool
function
Checks if input is None
is_none(None)
true
is_dict(d: dynamic): bool
function
Checks if input is a dictionary
is_dict({"a": 1})
true
is_bytes(b: dynamic): bool
function
Checks if input is bytes
is_bytes(to_bytes("hi"))
true
contains(haystack: dynamic, needle: dynamic): bool
function
Checks if string contains a substring
contains("hello world", "world")
true
ltrimstr(s: dynamic, left: dynamic): string
function
Removes prefix string from input if it exists
ltrimstr("prefix_value", "prefix_")
value
rtrimstr(s: dynamic, right: dynamic): string
function
Removes suffix string from input if it exists
rtrimstr("value_suffix", "_suffix")
value
is_empty(s: dynamic): bool
function
Checks if string, array or dict is empty
is_empty([])
true
test(s: dynamic, pattern: dynamic): bool
function
Tests if string matches a pattern
test("abc", "a.c")
true
select(v: dynamic, f: dynamic): dynamic
function
Returns value if condition is true, None otherwise
select(5, true)
5
arrays(a: dynamic): dynamic
function
Returns array if input is array, None otherwise
arrays([1, 2])
[1, 2]
markdowns(m: dynamic): dynamic
function
Returns markdown if input is markdown, None otherwise
markdowns(to_h("t", 1))
# t
booleans(b: dynamic): dynamic
function
Returns boolean if input is boolean, None otherwise
booleans(true)
true
numbers(n: dynamic): dynamic
function
Returns number if input is number, None otherwise
numbers(1)
1
strings(s: dynamic): dynamic
function
Returns string if input is string, None otherwise
strings("hi")
hi
dicts(d: dynamic): dynamic
function
Returns dict if input is dict, None otherwise
dicts({"a": 1})
{"a": 1}
nones(n: dynamic): dynamic
function
Returns the value if it is None, None otherwise
nones(None)
bytes(b: dynamic): dynamic
function
Returns bytes if input is bytes, None otherwise
bytes(to_bytes("hi"))
6869
iterables(v: dynamic): dynamic
function
Returns the value if it is an array or dict (i.e. a container that can be iterated over), None otherwise
iterables([1, 2])
[1, 2]
scalars(v: dynamic): dynamic
function
Returns the value if it is not an array or dict (i.e. a leaf/scalar value), None otherwise
scalars(1)
1
to_date_iso8601(d: dynamic): string
function
Formats a date to ISO 8601 format (YYYY-MM-DDTHH:MM:SSZ)
to_date_iso8601(0)
1970-01-01T00:00:00Z
map(v: dynamic, f: dynamic): array
function
Applies a given function to each element of the provided array and returns a new array with the results.
map([1, 2, 3], fn(x): mul(x, 2);)
[2, 4, 6]
flat_map(v: dynamic, f: dynamic): array
function
Applies a function to each element and flattens the result into a single array
flat_map([1, 2], fn(x): [x, x];)
[1, 1, 2, 2]
filter(v: dynamic, f: dynamic): array
function
Filters the elements of an array based on a provided callback function.
filter([1, 2, 3, 4], fn(x): x > 2;)
[3, 4]
each(v: dynamic, f: dynamic): dynamic
function
Executes a provided function once for each element in an array or each key-value pair in a dictionary.
first(arr: dynamic): dynamic
function
Returns the first element of an array
first([1, 2, 3])
1
last(arr: dynamic): dynamic
function
Returns the last element of an array
last([1, 2, 3])
3
second(arr: dynamic): dynamic
function
Returns the second element of an array
second([1, 2, 3])
2
is_h1(md: dynamic): bool
function
Checks if markdown is h1 heading
is_h1(to_h("t", 1))
true
is_h2(md: dynamic): bool
function
Checks if markdown is h2 heading
is_h2(to_h("t", 2))
true
is_h3(md: dynamic): bool
function
Checks if markdown is h3 heading
is_h3(to_h("t", 3))
true
is_h4(md: dynamic): bool
function
Checks if markdown is h4 heading
is_h4(to_h("t", 4))
true
is_h5(md: dynamic): bool
function
Checks if markdown is h5 heading
is_h5(to_h("t", 5))
true
is_h6(md: dynamic): bool
function
Checks if markdown is h6 heading
is_h6(to_h("t", 6))
true
is_h(md: dynamic): bool
function
Checks if markdown is heading
is_h(to_h("t", 2))
true
is_h_level(md: dynamic, level: dynamic): bool
function
Checks if markdown is a heading of the specified level (1-6)
is_h_level(to_h("t", 2), 2)
true
is_table_align(md: dynamic): bool
function
Checks if markdown is table align
is_table_align(to_md_table_align(["left"]))
true
is_table_cell(md: dynamic): bool
function
Checks if markdown is table cell
is_table_cell(to_md_table_cell("A1", 0, 0))
true
is_em(md: dynamic): bool
function
Checks if markdown is emphasis
is_em(to_em("hi"))
true
is_html(md: dynamic): bool
function
Checks if markdown is html
is_yaml(md: dynamic): bool
function
Checks if markdown is yaml
is_toml(md: dynamic): bool
function
Checks if markdown is toml
is_code(md: dynamic): bool
function
Checks if markdown is code block
is_code(to_code("x", "python"))
true
is_text(text: dynamic): bool
function
Checks if markdown is text
is_text(to_md_text("hi"))
true
is_list(list: dynamic): bool
function
Checks if markdown is list
is_list(to_md_list("Item", 0))
true
matches_url(node: dynamic, url: dynamic): bool
functionDeprecated
Checks if markdown node's URL matches a specified URL deprecated: use select(.link.url == url) instead
matches_url(to_link("https://example.com", "x", ""), "https://example.com")
true
is_mdx_flow_expression(mdx: dynamic): bool
function
Checks if markdown is MDX Flow Expression
is_mdx_jsx_flow_element(mdx: dynamic): bool
function
Checks if markdown is MDX Jsx Flow Element
is_mdx_jsx_text_element(mdx: dynamic): bool
function
Checks if markdown is MDX Jsx Text Element
is_mdx_text_expression(mdx: dynamic): bool
function
Checks if markdown is MDX Text Expression
is_mdx_js_esm(mdx: dynamic): bool
function
Checks if markdown is MDX Js Esm
is_mdx(mdx: dynamic): bool
function
Checks if markdown is MDX
is_callout(md: dynamic): bool
function
Checks if markdown is a callout block
is_callout(to_callout("Note", "note", ""))
true
fill(value: dynamic, n: dynamic): array
function
Returns an array of length n filled with the given value.
fill("x", 3)
["x", "x", "x"]
sort_by(arr: dynamic, f: dynamic): array
function
Sorts an array using a key function that extracts a comparable value for each element.
sort_by([3, 1, 2], identity)
[1, 2, 3]
sort_natural(arr: dynamic): array
function
Sorts an array in natural order (numeric-aware), so runs of digits embedded in a string are compared as numbers rather than character-by-character, e.g. "file2" sorts before "file10" (unlike a plain lexicographic `sort`).
sort_natural(["file10", "file2"])
["file2", "file10"]
count_by(arr: dynamic, f: dynamic): number
function
Returns the count of elements in the array that satisfy the provided function.
count_by([1, 2, 3, 4], fn(x): x > 2;)
2
skip(arr: dynamic, n: dynamic): array
function
Skips the first n elements of an array and returns the rest
skip([1, 2, 3, 4], 2)
[3, 4]
take(arr: dynamic, n: dynamic): array
function
Takes the first n elements of an array
take([1, 2, 3, 4], 2)
[1, 2]
find_index(arr: dynamic, f: dynamic): number
function
Returns the index of the first element in an array that satisfies the provided function.
find_index([1, 2, 3], fn(x): x == 2;)
1
skip_while(arr: dynamic, f: dynamic): array
function
Skips elements from the beginning of an array while the provided function returns true
skip_while([1, 2, 3, 4], fn(x): x < 3;)
[3, 4]
take_while(arr: dynamic, f: dynamic): array
function
Takes elements from the beginning of an array while the provided function returns true
take_while([1, 2, 3, 4], fn(x): x < 3;)
[1, 2]
group_by(arr: dynamic, f: dynamic): dict
function
Groups elements of an array by the result of applying a function to each element
group_by([1, 2, 3, 4], fn(x): mod(x, 2);)
{"1": [1, 3], "0": [2, 4]}
frequencies_by(arr: dynamic, f: dynamic): dict
function
Counts occurrences of each key extracted from the elements of an array, returning a dict of `{key: count}`.
frequencies_by(["a", "b", "a"], identity)
{"a": 2, "b": 1}
tally(arr: dynamic): dict
function
Counts occurrences of each element in an array, returning a dict of `{value: count}`.
tally(["a", "b", "a"])
{"a": 2, "b": 1}
any(v: dynamic, f: dynamic): bool
function
Returns true if any element in the array satisfies the provided function.
any([1, 2, 3], fn(x): x > 2;)
true
all(v: dynamic, f: dynamic): bool
function
Returns true if all element in the array satisfies the provided function.
all([1, 2, 3], fn(x): x > 0;)
true
in(v: dynamic, elem: dynamic): bool
function
Returns true if the element is in the array.
in([1, 2, 3], 2)
true
fold(arr: dynamic, init: dynamic, f: dynamic): dynamic
function
Reduces an array to a single value by applying a function, starting from an initial value.
fold([1, 2, 3], 0, fn(acc, x): acc + x;)
6
unique_by(arr: dynamic, f: dynamic): array
function
Returns a new array with duplicate elements removed, comparing by the result of the provided function.
unique_by([1, 2, 1, 3], identity)
[1, 2, 3]
identity(x: dynamic): dynamic
function
Returns the input value unchanged.
identity(1)
1
transpose(matrix: dynamic): array
function
Transposes a 2D array (matrix), swapping rows and columns.
transpose([[1, 2], [3, 4]])
[[1, 3], [2, 4]]
tap(value: dynamic, expr: dynamic): dynamic
function
Applies a function to a value and returns the value (useful for debugging or side effects).
tap(1, 2)
1
pluck(pluck_obj: dynamic, selector: dynamic): dynamic
function
Extracts values from an array of objects based on a specified selector.
compact_map(arr: dynamic, f: dynamic): array
function
Maps over an array and removes None values from the result.
compact_map([1, 2, 3], fn(x): if (x > 1): x;)
[2, 3]
reject(arr: dynamic, f: dynamic): array
function
Filters out elements that match the condition (opposite of filter).
reject([1, 2, 3, 4], fn(x): x > 2;)
[1, 2]
partition(arr: dynamic, f: dynamic): array
function
Splits an array into two arrays: [matching, not_matching] based on a condition.
partition([1, 2, 3, 4], fn(x): x > 2;)
[[3, 4], [1, 2]]
get_or(dict: dynamic, key: dynamic, default: dynamic): dynamic
function
Safely gets a value from a dict with a default if the key doesn't exist.
get_or({"a": 1}, "b", 0)
0
times(n: dynamic, value: dynamic): array
functionDeprecated
Executes an expression n times and returns an array of results. Note: `value` is evaluated once (eagerly) and repeated, not re-evaluated per iteration. Deprecated: use `repeat` instead
times(3, 1)
[1, 1, 1]
between(value: dynamic, min: dynamic, max: dynamic): bool
function
Checks if a value is between min and max (inclusive).
between(5, 1, 10)
true
sum_by(arr: dynamic, f: dynamic): number
function
Sums elements of an array after applying a transformation function.
sum_by([1, 2, 3], fn(x): mul(x, 2);)
12
index_by(arr: dynamic, f: dynamic): dict
function
Creates a dictionary indexed by a key extracted from each element.
index_by([1, 2, 3], to_string)
{"1": 1, "2": 2, "3": 3}
join_by(left: dynamic, right: dynamic, left_key: dynamic, right_key: dynamic, kind: dynamic): array
function
Joins two arrays of dict records on `left_key`/`right_key`, similar to a SQL join. Matching records are merged with `+` (right's fields win on collision). `kind` is one of "inner" (default), "left", "right", or "full"; unmatched records in outer joins are filled with `None` for the other side's fields (inferred from that side's full key set). Records with a missing or `None` join key never match, and duplicate keys on either side expand as a cross product.
join_by([{"id": 2, "name": "bob"}], [{"uid": 2, "age": 30}], "id", "uid")
[{"id": 2, "name": "bob", "uid": 2, "age": 30}]
inspect(value: dynamic): dynamic
function
Inspects a value by printing its string representation and returning the value.
lpad(s: dynamic, length: dynamic, pad_str: dynamic): string
function
Left-pads a string to a specified length using a given padding string.
lpad("7", 3, "0")
007
rpad(s: dynamic, length: dynamic, pad_str: dynamic): string
function
Right-pads a string to a specified length using a given padding string.
rpad("7", 3, "0")
700
load_markdown(path: dynamic): array
function
Loads a markdown file from the specified path
http_get(url: dynamic, headers: dynamic): string
function
Performs an HTTPS GET request, optionally with the given headers (a dict of string to string), and returns the response body as a string
http_post(url: dynamic, body: dynamic, headers: dynamic): string
function
Performs an HTTPS POST request with the given body, optionally with the given headers (a dict of string to string), and returns the response body as a string
http_put(url: dynamic, body: dynamic, headers: dynamic): string
function
Performs an HTTPS PUT request with the given body, optionally with the given headers (a dict of string to string), and returns the response body as a string
http_patch(url: dynamic, body: dynamic, headers: dynamic): string
function
Performs an HTTPS PATCH request with the given body, optionally with the given headers (a dict of string to string), and returns the response body as a string
http_delete(url: dynamic, headers: dynamic): string
function
Performs an HTTPS DELETE request, optionally with the given headers (a dict of string to string), and returns the response body as a string
http_head(url: dynamic, headers: dynamic): string
function
Performs an HTTPS HEAD request, optionally with the given headers (a dict of string to string), and returns the response body as a string
http_get_json(url: dynamic, headers: dynamic): dynamic
function
Performs an HTTPS GET request, optionally with the given headers (a dict of string to string), and parses the response body as JSON, returning the resulting data structure
http_post_json(url: dynamic, body: dynamic, headers: dynamic): dynamic
function
Performs an HTTPS POST request with the given body, optionally with the given headers (a dict of string to string), and parses the response body as JSON, returning the resulting data structure
http_put_json(url: dynamic, body: dynamic, headers: dynamic): dynamic
function
Performs an HTTPS PUT request with the given body, optionally with the given headers (a dict of string to string), and parses the response body as JSON, returning the resulting data structure
http_patch_json(url: dynamic, body: dynamic, headers: dynamic): dynamic
function
Performs an HTTPS PATCH request with the given body, optionally with the given headers (a dict of string to string), and parses the response body as JSON, returning the resulting data structure
http_delete_json(url: dynamic, headers: dynamic): dynamic
function
Performs an HTTPS DELETE request, optionally with the given headers (a dict of string to string), and parses the response body as JSON, returning the resulting data structure
debug(args: dynamic): dynamic
function
Prints the debug information of the given value(s).
increase_header_depth(node: dynamic): markdown
function
Increases the depth (numeric level) of a markdown heading node by one, effectively demoting the heading (e.g. h1 -> h2), up to a maximum of 6.
increase_header_depth(to_h("t", 1))
## t
decrease_header_depth(node: dynamic): markdown
function
Decreases the depth (numeric level) of a markdown heading node by one, effectively promoting the heading (e.g. h2 -> h1), down to a minimum of 1.
decrease_header_depth(to_h("t", 2))
# t
demote_heading(node: dynamic): markdown
function
Demotes a markdown heading by increasing its depth (numeric level) by one. This is an alias for `increase_header_depth`.
demote_heading(to_h("t", 1))
## t
promote_heading(node: dynamic): markdown
function
Promotes a markdown heading by decreasing its depth (numeric level) by one. This is an alias for `decrease_header_depth`.
promote_heading(to_h("t", 2))
# t
increase_header_level(node: dynamic): markdown
functionDeprecated
Deprecated: use `increase_header_depth` or `demote_heading` instead. Kept for backward compatibility; behavior unchanged.
increase_header_level(to_h("t", 1))
## t
decrease_header_level(node: dynamic): markdown
functionDeprecated
Deprecated: use `decrease_header_depth` or `promote_heading` instead. Kept for backward compatibility; behavior unchanged.
decrease_header_level(to_h("t", 2))
# t
bsearch(arr: dynamic, target: dynamic): number
function
Performs a binary search on a sorted array to find the index of the target value.
bsearch([1, 3, 5, 7, 9], 5)
2
slugify(s: dynamic, separator: dynamic): string
function
Converts a string into a URL-friendly slug by lowercasing, replacing non-alphanumeric characters with hyphens, and trimming hyphens from the ends.
slugify("Hello, World!")
hello-world
percentile(arr: dynamic, p: dynamic): number
function
Calculates the p-th percentile of an array of numbers using linear interpolation between closest ranks.
percentile([1, 2, 3, 4, 5], 0.5)
3
chunks(v: dynamic, size: dynamic): array
function
Splits an array into chunks of a specified size, returning an array of arrays.
chunks([1, 2, 3, 4, 5], 2)
[[1, 2], [3, 4], [5]]
chunk_by(v: dynamic, f: dynamic): array
function
Splits an array into chunks based on the result of applying a function to each element, grouping consecutive elements with the same key together.
chunk_by([1, 1, 2, 2, 3], identity)
[[1, 1], [2, 2], [3]]
flip(f: dynamic, a: dynamic, b: dynamic): dynamic
function
Returns a new function that takes the same arguments as the original function but with the first two arguments flipped.
flip(sub, 2, 10)
8
complement(f: dynamic): bool
function
Returns a new predicate function that negates the result of the given function.
let f = complement(is_none) | f(1)
true
comp(fns: dynamic): dynamic
function
Composes functions into one function, applying them right-to-left. `comp(f, g, h)(x)` is equivalent to `f(g(h(x)))`.
let f = comp(fn(x): x + 1;, fn(x): x * 2;) | f(3)
7
juxt(fns: dynamic): array
function
Returns a function that applies each given function to its argument and collects the results into an array. `juxt(f, g, h)(x)` is equivalent to `[f(x), g(x), h(x)]`.
let f = juxt(first, last) | f([1, 2, 3])
[1, 3]
sum(arr: dynamic): number
function
Returns the sum of the elements in an array after applying a transformation function to each element.
sum([1, 2, 3])
6
mean(arr: dynamic): number
function
Returns the average (mean) of an array of numbers, or None if the array is empty.
mean([1, 2, 3])
2
geomean(arr: dynamic): number
function
Returns the geometric mean of an array of numbers, or None if the array is empty.
geomean([1, 4])
2
variance(arr: dynamic): number
function
Returns the population variance of an array of numbers, or None if the array is empty.
variance([2, 4, 4, 4, 5, 5, 7, 9])
4
stddev(arr: dynamic): number
function
Returns the population standard deviation of an array of numbers, or None if the array is empty.
stddev([2, 4, 4, 4, 5, 5, 7, 9])
2
mode(arr: dynamic): array
function
Returns the mode(s) of an array, i.e. the most frequently occurring value(s). Multiple values are returned if there is a tie for the highest frequency. Returns None if the array is empty.
mode([1, 2, 2, 3])
[2]
describe(arr: dynamic): dict
function
Returns a dict of summary statistics for an array of numbers: `{min, max, mean, median, stddev, variance, count}`. Returns None if the array is empty.
describe([1, 2, 3, 4, 5])
{"count": 5, "min": 1, "max": 5, "mean": 3, "variance": 2, "stddev": 1.414214, "median": 3}
ngram(s: dynamic, n: dynamic): array
function
Returns the n-grams of an array or string, which are overlapping contiguous subarrays (or substrings) of length n, sliding one element at a time.
ngram("abcd", 2)
["ab", "bc", "cd"]
zip(arr1: dynamic, arr2: dynamic): array
function
Combines two arrays into an array of pairs, where each pair contains elements from the same index in both arrays.
zip([1, 2], ["a", "b"])
[[1, "a"], [2, "b"]]
min_by(arr: dynamic, f: dynamic): dynamic
function
Returns the minimum element in an array based on a provided function that extracts a comparable value from each element.
min_by([3, 1, 2], identity)
1
max_by(arr: dynamic, f: dynamic): dynamic
function
Returns the maximum element in an array based on a provided function that extracts a comparable value from each element.
max_by([3, 1, 2], identity)
3
lines(s: dynamic): array
function
Returns the lines of a string as an array by splitting on newline characters.
lines("a\nb\nc")
["a", "b", "c"]
unlines(arr: dynamic): string
function
Joins an array of strings into a single string with newline characters between them.
unlines(["a", "b", "c"]) == "a\nb\nc"
true
pick(d: dynamic, keys: dynamic): dict
function
Returns a new dictionary containing only the specified keys from the original dictionary, if they exist.
pick({"a": 1, "b": 2}, ["a"])
{"a": 1}
omit(d: dynamic, keys: dynamic): dict
function
Returns a new dictionary excluding the specified keys from the original dictionary.
omit({"a": 1, "b": 2}, ["a"])
{"b": 2}
has(v: dynamic, key: dynamic): bool
function
Checks if a dict has the given key, or an array has an element at the given index.
has({"a": 1}, "a")
true
get_path(value: dynamic, path: dynamic): dynamic
function
Retrieves a nested value by following an array of keys/indices, e.g. `get_path(d, ["a", "b", 0])`. Returns None as soon as any intermediate step is missing.
get_path({"a": {"b": 1}}, ["a", "b"])
1
set_path(value: dynamic, path: dynamic, new_value: dynamic): dynamic
function
Sets a nested value by following an array of keys/indices, e.g. `set_path(d, ["a", "b", 0], 1)`. Missing intermediate dicts/arrays are created automatically, choosing an array when the corresponding path element is a number and a dict otherwise.
set_path({"a": {"b": 1}}, ["a", "b"], 2)
{"a": {"b": 2}}
del_path(value: dynamic, path: dynamic): dynamic
function
Deletes the value at a nested path, following an array of keys/indices, e.g. `del_path(d, ["a", "b", 0])`. An empty path deletes the whole value, mirroring jq's `delpaths([[]])`. A path through a missing intermediate container, or ending in a missing key/out-of-range index, leaves `value` unchanged.
del_path({"a": {"b": 1, "c": 2}}, ["a", "b"])
{"a": {"c": 2}}
del_paths(value: dynamic, paths: dynamic): dynamic
function
Deletes the values at multiple nested paths, e.g. `del_paths(d, [["a"], ["b", 0]])`. Paths are applied deepest-first (via `sort`/`reverse`) so that deleting one array element doesn't shift the indices used by the remaining paths, mirroring jq's `delpaths`.
del_paths({"a": 1, "b": 2, "c": 3}, [["a"], ["c"]])
{"b": 2}
paths(value: dynamic): array
function
Returns an array of leaf-path arrays for a value, e.g. `paths({"a": {"b": 1}})` returns `[["a", "b"]]`. Each returned path can be passed to `get_path`/`set_path`. Containers with no leaves (e.g. `{}`, `[]`) contribute no paths.
paths({"a": {"b": 1}})
[["a", "b"]]
from_entries(arr: dynamic): dict
function
Builds a dict from an array of [key, value] pairs, as produced by `entries`. If the same key appears more than once, the last occurrence wins.
from_entries([["a", 1], ["b", 2]])
{"a": 1, "b": 2}
with_entries(d: dynamic, f: dynamic): dict
function
Transforms each [key, value] pair of a dict by applying the given function, then rebuilds a dict from the resulting pairs.
with_entries({"a": 1}, fn(e): [e[0], e[1] + 1];)
{"a": 2}
merge_with(a: dynamic, b: dynamic, policy: dynamic): dynamic
function
Deep merges two values, recursing into dicts key by key. Neither input is mutated. When both sides provide a leaf/array value for the same key, the conflict is resolved according to `policy`, one of: - `"replace"`: the second value (`b`) wins. - `"append"`: arrays are concatenated; other conflicting values are collected into `[a, b]`. - `"error"`: raises an error describing the conflict.
merge_with({"a": 1, "b": {"x": 1}}, {"b": {"y": 2}, "c": 3}, "replace")
{"a": 1, "b": {"x": 1, "y": 2}, "c": 3}
merge_defaults(d: dynamic, defaults: dynamic): dynamic
function
Deep merges `d` over `defaults`, similar to Jsonnet's object inheritance: values present in `d` win (recursively for nested dicts), while keys missing from `d` fall back to the corresponding value in `defaults`. Arrays and scalar conflicts are resolved by letting `d` replace `defaults`. Neither input is mutated.
merge_defaults({"a": {"x": 1}}, {"a": {"x": 0, "y": 2}, "b": 3})
{"a": {"x": 1, "y": 2}, "b": 3}
frontmatter(v: dynamic): dynamic
function
Parses frontmatter from a markdown node, supporting both YAML and TOML formats.
walk(v: dynamic, f: dynamic): dynamic
function
Walks through a value (which can be a markdown node, array, or dict) and applies a function to each element, returning a new structure with the results.
walk([1, [2, 3]], fn(x): if (is_number(x)): x * 2 else: x;)
[2, [4, 6]]
human_bytes(n: dynamic): string
function
Formats a byte count as a human-readable decimal (SI, 1000-based) string, e.g. `human_bytes(1500)` => "1.5KB". Negative numbers keep their sign.
human_bytes(1500)
1.5KB
human_size(n: dynamic): string
function
Formats a byte count as a human-readable binary (IEC, 1024-based) string without the "i" suffix, matching `numfmt --to=iec`, e.g. `human_size(1536)` => "1.5K". Negative numbers keep their sign.
human_size(1536)
1.5K
CBOR Implementation in mq.
2 functions
cbor_parse(input: dynamic): dynamic
function
Parses a base64-encoded CBOR string (or raw bytes) and returns the corresponding data structure.
Module: import "cbor" | cbor::cbor_parse(...)
import "cbor" | cbor::cbor_parse(cbor::cbor_stringify({"a": 1}))
{"a": 1}
cbor_stringify(data: dynamic): bytes
function
Serializes a value to CBOR bytes.
Module: import "cbor" | cbor::cbor_stringify(...)
import "cbor" | cbor::cbor_stringify(1)
f93c00
CSV/TSV Implementation in mq. Based on RFC 4180 for CSV format.
8 functions
csv_needs_quote(field: dynamic, delimiter: dynamic): bool
function
Checks whether a field's string form needs quoting for the given delimiter (RFC 4180): it contains a quote, newline, carriage return, the delimiter itself, or leading/trailing whitespace.
Module: import "csv" | csv::csv_needs_quote(...)
import "csv" | csv::csv_needs_quote("a,b", ",")
true
csv_parse_with_delimiter(input: dynamic, delimiter: dynamic, has_header: dynamic): array
function
Parses CSV content with a specified delimiter and optional header row.
Module: import "csv" | csv::csv_parse_with_delimiter(...)
import "csv" | csv::csv_parse_with_delimiter("a;b\n1;2", ";", true)
[{"a": "1", "b": "2"}]
csv_parse(input: dynamic, has_header: dynamic): array
function
Parses CSV content using a comma as the delimiter.
Module: import "csv" | csv::csv_parse(...)
import "csv" | csv::csv_parse("name,age\nAlice,30", true)
[{"name": "Alice", "age": "30"}]
tsv_parse(input: dynamic, has_header: dynamic): array
function
Parses TSV (Tab-Separated Values) content.
Module: import "csv" | csv::tsv_parse(...)
import "csv" | csv::tsv_parse("name\tage\nAlice\t30", true)
[{"name": "Alice", "age": "30"}]
psv_parse(input: dynamic, has_header: dynamic): array
function
Parses PSV (Pipe-Separated Values) content.
Module: import "csv" | csv::psv_parse(...)
import "csv" | csv::psv_parse("name|age\nAlice|30", true)
[{"name": "Alice", "age": "30"}]
csv_stringify(data: dynamic, delimiter: dynamic): string
function
Converts data to a CSV string with a specified delimiter.
Module: import "csv" | csv::csv_stringify(...)
import "csv" | csv::csv_stringify([{"name": "Alice", "age": 30}], ",")
name,age
Alice,30
csv_to_markdown_table(data: dynamic): string
function
Converts CSV data to a Markdown table format.
Module: import "csv" | csv::csv_to_markdown_table(...)
import "csv" | csv::csv_to_markdown_table([{"name": "Alice", "age": 30}])
| name | age |
| --- | --- |
| Alice | 30 |
csv_to_json(data: dynamic): string
function
Converts CSV data to a JSON string.
Module: import "csv" | csv::csv_to_json(...)
import "csv" | csv::csv_to_json([{"name": "Alice", "age": 30}])
[{"name":"Alice","age":30}]
Fuzzy Match Implementation in mq Distance calculations (Levenshtein, Jaro, Jaro-Winkler) are implemented natively in Rust for performance; this module wraps them with matching, filtering, and sorting utilities.
8 functions
levenshtein(s1: dynamic, s2: dynamic): number
function
Calculates the Levenshtein distance between two strings.
Module: import "fuzzy" | fuzzy::levenshtein(...)
import "fuzzy" | fuzzy::levenshtein("kitten", "sitting")
3
jaro(s1: dynamic, s2: dynamic): number
function
Calculates the Jaro distance between two strings (0.0 to 1.0, where 1.0 is exact match).
Module: import "fuzzy" | fuzzy::jaro(...)
import "fuzzy" | fuzzy::jaro("martha", "marhta")
0.944444
jaro_winkler(s1: dynamic, s2: dynamic): number
function
Calculates the Jaro-Winkler distance between two strings.
Module: import "fuzzy" | fuzzy::jaro_winkler(...)
import "fuzzy" | fuzzy::jaro_winkler("martha", "marhta")
0.961111
fuzzy_match(candidates: dynamic, query: dynamic): array
function
Performs fuzzy matching on an array of strings using Jaro-Winkler distance.
Module: import "fuzzy" | fuzzy::fuzzy_match(...)
import "fuzzy" | fuzzy::fuzzy_match(["apple", "aple", "banana"], "aple")
[{"text": "aple", "score": 1}, {"text": "apple", "score": 0.946667}, {"text": "banana", "score": 0.472222}]
fuzzy_match_levenshtein(candidates: dynamic, query: dynamic): array
function
Performs fuzzy matching using Levenshtein distance.
Module: import "fuzzy" | fuzzy::fuzzy_match_levenshtein(...)
import "fuzzy" | fuzzy::fuzzy_match_levenshtein(["apple", "aple", "banana"], "aple")
[{"text": "aple", "score": 0}, {"text": "apple", "score": 1}, {"text": "banana", "score": 5}]
fuzzy_match_jaro(candidates: dynamic, query: dynamic): array
function
Performs fuzzy matching using Jaro distance.
Module: import "fuzzy" | fuzzy::fuzzy_match_jaro(...)
import "fuzzy" | fuzzy::fuzzy_match_jaro(["apple", "aple", "banana"], "aple")
[{"text": "aple", "score": 1}, {"text": "apple", "score": 0.933333}, {"text": "banana", "score": 0.472222}]
fuzzy_filter(candidates: dynamic, query: dynamic, threshold: dynamic): array
function
Filters candidates by minimum fuzzy match score using Jaro-Winkler.
Module: import "fuzzy" | fuzzy::fuzzy_filter(...)
import "fuzzy" | fuzzy::fuzzy_filter(["apple", "aple", "banana"], "aple", 0.8)
[{"text": "aple", "score": 1}, {"text": "apple", "score": 0.946667}]
fuzzy_best_match(candidates: dynamic, query: dynamic): dict
function
Finds the best fuzzy match from candidates.
Module: import "fuzzy" | fuzzy::fuzzy_best_match(...)
import "fuzzy" | fuzzy::fuzzy_best_match(["apple", "aple", "banana"], "aple")
{"text": "aple", "score": 1}
gron Implementation in mq.
1 functions
gron_parse(input: dynamic): dynamic
function
Parses gron-style `path = value;` assignment statements (as produced by `mq -F gron`) and returns the corresponding data structure.
Module: import "gron" | gron::gron_parse(...)
import "gron" | gron::gron_parse("json.a = 1;\njson.b = 2;")
{"a": 1, "b": 2}
JSON Implementation in mq
3 functions
json_parse(input: dynamic): dynamic
function
Parses a JSON string and returns the corresponding data structure.
Module: import "json" | json::json_parse(...)
import "json" | json::json_parse("{\"a\": 1}")
{"a": 1}
json_stringify(data: dynamic): string
function
Serializes a value to a JSON string.
Module: import "json" | json::json_stringify(...)
import "json" | json::json_stringify({"a": 1})
{"a": 1}
json_to_markdown_table(data: dynamic): string
function
Converts a JSON data structure to a Markdown table.
Module: import "json" | json::json_to_markdown_table(...)
import "json" | json::json_to_markdown_table([{"a": 1, "b": 2}])
| a | b |
| --- | --- |
| 1 | 2 |
Builder functions for constructing markdown nodes from scratch. This module is under development. APIs and behavior may change without notice.
26 functions
h(value: dynamic, depth: dynamic): markdown
function
Wraps `value` in a heading node at the given `depth` (1-6).
Module: import "md" | md::h(...)
import "md" | md::h("Title", 1)
# Title
code(value: dynamic, lang: dynamic): markdown
function
Wraps `value` in a fenced code block with the given `lang`.
Module: import "md" | md::code(...)
code_inline(value: dynamic): markdown
function
Wraps `value` in an inline code span.
Module: import "md" | md::code_inline(...)
import "md" | md::code_inline("x")
`x`
text(value: dynamic): markdown
function
Creates a plain text node from `value`.
Module: import "md" | md::text(...)
import "md" | md::text("hi")
hi
strong(value: dynamic): markdown
function
Wraps `value` in a strong (bold) node.
Module: import "md" | md::strong(...)
import "md" | md::strong("Bold")
**Bold**
em(value: dynamic): markdown
function
Wraps `value` in an emphasis (italic) node.
Module: import "md" | md::em(...)
import "md" | md::em("Italic")
*Italic*
delete(value: dynamic): markdown
function
Wraps `value` in a delete (strikethrough) node.
Module: import "md" | md::delete(...)
import "md" | md::delete("Old")
~~Old~~
blockquote(value: dynamic): markdown
function
Wraps `value` in a blockquote node.
Module: import "md" | md::blockquote(...)
import "md" | md::blockquote("Quote")
> Quote
callout(value: dynamic, kind: dynamic, title: dynamic): markdown
function
Wraps `value` in a callout node of the given `kind` (e.g. "note", "warning"), with an optional custom `title`.
Module: import "md" | md::callout(...)
import "md" | md::callout("Note text", "note", "")
> [!NOTE]
> Note text
hr(): markdown
function
Creates a horizontal rule node.
Module: import "md" | md::hr(...)
import "md" | md::hr()
***
br(): markdown
function
Creates a blank line between the surrounding elements in a `doc()`/`to_md_fragment()` call.
Module: import "md" | md::br(...)
math(value: dynamic): markdown
function
Wraps `value` in a math block node.
Module: import "md" | md::math(...)
import "md" | md::math("x^2")
$$
x^2
$$
math_inline(value: dynamic): markdown
function
Wraps `value` in an inline math node.
Module: import "md" | md::math_inline(...)
import "md" | md::math_inline("x^2")
$x^2$
link(url: dynamic, value: dynamic, title: dynamic): markdown
function
Creates a link node pointing to `url` with link text `value` and an optional `title`.
Module: import "md" | md::link(...)
import "md" | md::link("https://example.com", "Example", "")
[Example](https://example.com)
image(url: dynamic, alt: dynamic, title: dynamic): markdown
function
Creates an image node pointing to `url` with `alt` text and an optional `title`.
Module: import "md" | md::image(...)
import "md" | md::image("https://example.com/a.png", "Alt", "")

footnote(value: dynamic, ident: dynamic): markdown
function
Wraps `value` in a footnote definition node identified by `ident`.
Module: import "md" | md::footnote(...)
import "md" | md::footnote("Footnote text", "1")
[^1]: Footnote text
footnote_ref(ident: dynamic): markdown
function
Creates a footnote reference node pointing at `ident`.
Module: import "md" | md::footnote_ref(...)
import "md" | md::footnote_ref("1")
[^1]
definition(url: dynamic, ident: dynamic, title: dynamic): markdown
function
Creates a link reference definition node (`[ident]: url "title"`) for `ident`, with an optional `title`.
Module: import "md" | md::definition(...)
import "md" | md::definition("https://example.com", "ex", "")
[ex]: https://example.com
html(value: dynamic): markdown
function
Wraps `value` in a raw HTML node, emitted as-is.
Module: import "md" | md::html(...)
import "md" | md::html("<br>")
<br>
linebreak(): markdown
function
Creates a hard line break node.
Module: import "md" | md::linebreak(...)
list(value: dynamic, level: dynamic, ordered: dynamic, checked: dynamic): markdown
function
Wraps `value` in a list item node at the given `level` (0-indexed nesting), optionally `ordered` (numbered) and/or `checked` (checkbox); pass `checked = None` for a plain item.
Module: import "md" | md::list(...)
import "md" | md::list("Item", 0)
- Item
table_row(cells: dynamic): markdown
function
Creates a table row node from an array of cell values.
Module: import "md" | md::table_row(...)
import "md" | md::table_row(["a", "b"])
|a|b|
table_cell(value: dynamic, row: dynamic, column: dynamic): markdown
function
Creates a single table cell node at the given `row`/`column`.
Module: import "md" | md::table_cell(...)
import "md" | md::table_cell("A1", 0, 0)
A1
table_align(aligns: dynamic): markdown
function
Creates a table alignment (header separator) row node from an array of alignments (e.g. ["left", "right", "center"]).
Module: import "md" | md::table_align(...)
import "md" | md::table_align(["left", "right"])
|:---|---:|
table(header: dynamic, rows: dynamic, aligns: dynamic): array
function
Builds a full table from a `header` array of cell values and a `rows` array of row arrays. `aligns` is an array of alignment strings (e.g. ["left", "right", "center"]) matching `header`'s length; defaults to no alignment. Returns an array of row/align nodes ready to splice into `doc()`.
Module: import "md" | md::table(...)
import "md" | md::doc(md::table(["A", "B"], [["1", "2"], ["3", "4"]]))
|A|B|
|---|---|
|1|2|
|3|4|
doc(values: dynamic): markdown
function
Combines markdown nodes into a single markdown value. Accepts either a variable number of arguments (`doc(a, b, c)`) or a single array (`doc([a, b, c])`). Nested arrays (e.g. from `map()`) are flattened automatically, so components can return plain arrays of nodes and be spliced in as children.
Module: import "md" | md::doc(...)
import "md" | md::doc(md::h("T", 1), md::text("hi"))
# T
hi
The section module splits and filters Markdown documents by heading section. Call it via `import "section"` then `section::fn()` (recommended, namespaced), `include "section"` then `fn()` (no namespace prefix), or `mq -A 'section::fn()'` on the command line. Section functions need every document node at once — pass `-A` on the CLI, or pipe through `nodes` in an inline query/script; a single node instead prints a stderr warning and is treated as a one-element array.
import "section" | len(section::section(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B"), "A"))
2
19 functions
section(md_nodes: dynamic, pattern: dynamic, depth: dynamic): array
function
Returns sections whose title contains the specified pattern. If depth is true, each section spans until the next header at the same or higher level (delegates to section::sections(md_nodes, depth), see its doc for details).
Module: import "section" | section::section(...)
import "section" | len(section::section(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B"), "A"))
2
sections(md_nodes: dynamic, depth: dynamic): array
function
Splits markdown nodes into sections based on headers. If depth is true, each section's body extends to the next heading at the same or higher level as that section's own heading, so nested subheadings' content is included in their parent's body. If depth is false (default), every heading of any level is a boundary, so a heading's body only extends to the very next heading regardless of level.
Module: import "section" | section::sections(...)
import "section" | len(section::sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B")))
3
import "section" | len(section::body(first(section::sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B"), true))))
3
filter_sections(md_nodes: dynamic, predicate: dynamic): array
function
Filters sections based on a given predicate function.
Module: import "section" | section::filter_sections(...)
import "section" | len(section::filter_sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B"), fn(s): true;))
3
map_sections(md_nodes: dynamic, mapper: dynamic): array
function
Maps sections using a given mapper function.
Module: import "section" | section::map_sections(...)
import "section" | section::map_sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B"), fn(header, children): to_text(header);)
["A", "A1", "B"]
split(md_nodes: dynamic, level: dynamic): array
function
Returns an array of sections, each section is an array of markdown nodes between the specified header and the next header of the same level.
Module: import "section" | section::split(...)
import "section" | len(section::split(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B"), 1))
2
title_contains(sections: dynamic, text: dynamic): array
function
Filters the given list of sections, returning only those whose title contains the specified text.
Module: import "section" | section::title_contains(...)
import "section" | len(section::title_contains(section::sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B")), "A"))
2
title_match(sections: dynamic, pattern: dynamic): array
function
Filters sections by a pattern match in the title text.
Module: import "section" | section::title_match(...)
import "section" | len(section::title_match(section::sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B")), "^A"))
2
title(section: dynamic): string
function
Returns the title text of a section (header text without the # symbols).
Module: import "section" | section::title(...)
import "section" | section::title(first(section::sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B"))))
A
content(section: dynamic): array
functionDeprecated
Returns the content of a section (all nodes except the header). Deprecated: Use body() instead, as content()
Module: import "section" | section::content(...)
import "section" | len(section::content(first(section::sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B")))))
1
body(section: dynamic): array
function
Returns the body of a section (all nodes except the header).
Module: import "section" | section::body(...)
import "section" | len(section::body(first(section::sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B")))))
1
all_nodes(section: dynamic): array
function
Returns all nodes of a section, including both the header and content.
Module: import "section" | section::all_nodes(...)
import "section" | len(section::all_nodes(first(section::sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B")))))
2
by_level(sections: dynamic, l: dynamic): array
function
Filters sections by heading level. l can be a number (exact level) or a range array (e.g. 1..2).
Module: import "section" | section::by_level(...)
import "section" | len(section::by_level(section::sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B")), 1))
2
level(section: dynamic): number
function
Returns the header level (1-6) of a section.
Module: import "section" | section::level(...)
import "section" | section::level(first(section::sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B"))))
1
nth(sections: dynamic, n: dynamic): dynamic
function
Returns the nth section from an array of sections (0-indexed).
Module: import "section" | section::nth(...)
import "section" | section::title(section::nth(section::sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B")), 0))
A
titles(sections: dynamic): array
function
Extracts titles from all sections.
Module: import "section" | section::titles(...)
import "section" | section::titles(section::sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B")))
["A", "A1", "B"]
bodies(sections: dynamic): array
function
Extracts body from all sections.
Module: import "section" | section::bodies(...)
import "section" | len(section::bodies(section::sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B"))))
3
toc(sections: dynamic): array
function
Generates a table of contents from sections.
Module: import "section" | section::toc(...)
import "section" | section::toc(section::sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B")))
[" - A", " - A1", " - B"]
has_content(section: dynamic): bool
function
Checks if a section has any content beyond the header.
Module: import "section" | section::has_content(...)
import "section" | section::has_content(first(section::sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B"))))
true
collect(sections: dynamic): array
function
Flattens sections back to markdown nodes for output. This converts section objects back to their original markdown node arrays.
Module: import "section" | section::collect(...)
import "section" | len(section::collect(section::sections(to_markdown("# A\n\nBody A\n\n## A1\n\nSub A\n\n# B\n\nBody B"))))
6
Semantic Versioning (SemVer) Implementation in mq Based on the Semantic Versioning 2.0.0 specification: https://semver.org/
15 functions
semver_parse(s: dynamic): dict
function
Parses a SemVer string into a dict with major, minor, patch, pre, and build fields.
Module: import "semver" | semver::semver_parse(...)
import "semver" | semver::semver_to_string(semver::semver_parse("1.2.3-beta.1"))
1.2.3-beta.1
semver_to_string(v: dynamic): string
function
Converts a parsed SemVer dict back to a version string.
Module: import "semver" | semver::semver_to_string(...)
import "semver" | semver::semver_to_string(semver::semver_parse("1.2.3-beta"))
1.2.3-beta
semver_compare(a: dynamic, b: dynamic): number
function
Compares two parsed SemVer dicts. Returns -1 if a < b, 0 if a == b, 1 if a > b.
Module: import "semver" | semver::semver_compare(...)
import "semver" | semver::semver_compare(semver::semver_parse("1.0.0"), semver::semver_parse("2.0.0"))
-1
semver_gt(a: dynamic, b: dynamic): bool
function
Returns true if version a is greater than version b.
Module: import "semver" | semver::semver_gt(...)
import "semver" | semver::semver_gt(semver::semver_parse("2.0.0"), semver::semver_parse("1.0.0"))
true
semver_lt(a: dynamic, b: dynamic): bool
function
Returns true if version a is less than version b.
Module: import "semver" | semver::semver_lt(...)
import "semver" | semver::semver_lt(semver::semver_parse("1.0.0"), semver::semver_parse("2.0.0"))
true
semver_eq(a: dynamic, b: dynamic): bool
function
Returns true if version a equals version b (ignoring build metadata).
Module: import "semver" | semver::semver_eq(...)
import "semver" | semver::semver_eq(semver::semver_parse("1.0.0"), semver::semver_parse("1.0.0"))
true
semver_gte(a: dynamic, b: dynamic): bool
function
Returns true if version a is greater than or equal to version b.
Module: import "semver" | semver::semver_gte(...)
import "semver" | semver::semver_gte(semver::semver_parse("1.0.0"), semver::semver_parse("1.0.0"))
true
semver_lte(a: dynamic, b: dynamic): bool
function
Returns true if version a is less than or equal to version b.
Module: import "semver" | semver::semver_lte(...)
import "semver" | semver::semver_lte(semver::semver_parse("1.0.0"), semver::semver_parse("1.0.0"))
true
semver_bump_major(v: dynamic): dict
function
Increments the major version and resets minor, patch, and pre-release.
Module: import "semver" | semver::semver_bump_major(...)
import "semver" | semver::semver_to_string(semver::semver_bump_major(semver::semver_parse("1.2.3")))
2.0.0
semver_bump_minor(v: dynamic): dict
function
Increments the minor version and resets patch and pre-release.
Module: import "semver" | semver::semver_bump_minor(...)
import "semver" | semver::semver_to_string(semver::semver_bump_minor(semver::semver_parse("1.2.3")))
1.3.0
semver_bump_patch(v: dynamic): dict
function
Increments the patch version and clears pre-release.
Module: import "semver" | semver::semver_bump_patch(...)
import "semver" | semver::semver_to_string(semver::semver_bump_patch(semver::semver_parse("1.2.3")))
1.2.4
semver_sort(versions: dynamic): array
function
Sorts an array of parsed SemVer dicts in ascending order.
Module: import "semver" | semver::semver_sort(...)
import "semver" | map(semver::semver_sort([semver::semver_parse("2.0.0"), semver::semver_parse("1.0.0")]), semver::semver_to_string)
["1.0.0", "2.0.0"]
semver_max(versions: dynamic): dict
function
Returns the maximum version from an array of parsed SemVer dicts.
Module: import "semver" | semver::semver_max(...)
import "semver" | semver::semver_to_string(semver::semver_max([semver::semver_parse("1.0.0"), semver::semver_parse("2.0.0")]))
2.0.0
semver_min(versions: dynamic): dict
function
Returns the minimum version from an array of parsed SemVer dicts.
Module: import "semver" | semver::semver_min(...)
import "semver" | semver::semver_to_string(semver::semver_min([semver::semver_parse("1.0.0"), semver::semver_parse("2.0.0")]))
1.0.0
semver_satisfies(version: dynamic, range: dynamic): bool
function
Returns true if the given version string satisfies every comma-separated comparator in `range`. Supported comparators: "=", "==", "!=", ">", ">=", "<", "<=". A bare version (no operator) requires an exact match. Example: semver_satisfies("1.5.0", ">=1.0.0,<2.0.0") == true
Module: import "semver" | semver::semver_satisfies(...)
import "semver" | semver::semver_satisfies("1.5.0", ">=1.0.0,<2.0.0")
true
The table module extracts and transforms Markdown tables. This module is under development; APIs and behavior may change without notice. Call it via `import "table"` then `table::fn()` — from an inline query, a script, or `mq -A 'import "table" | table::fn()'` on the command line. Unlike `section`, `import` must always be written explicitly (no `include` shortcut). Table functions need every document node at once: pass `-A` on the CLI, or pipe through `nodes` inline.
import "table" | len(table::tables(to_markdown("| a | b |\n| - | - |\n| 1 | 2 |")))
1
15 functions
tables(md_nodes: dynamic): array
function
Extract table structures from a list of markdown nodes.
Module: import "table" | table::tables(...)
import "table" | table::tables(to_markdown("| a | b |\n| --- | --- |\n| 1 | 2 |\n| 3 | 4 |")) | len(self)
1
set_align(table: dynamic, align: dynamic): dict
function
Set the alignment for a table.
Module: import "table" | table::set_align(...)
import "table" | table::tables(to_markdown("| a | b |\n| --- | --- |\n| 1 | 2 |\n| 3 | 4 |")) | first(self) | table::set_align(self, ["left", "right"]) | table::to_csv(self)
a,b
1,2
3,4
add_row(table: dynamic, row: dynamic): dict
function
Add a new row to a table.
Module: import "table" | table::add_row(...)
import "table" | table::tables(to_markdown("| a | b |\n| --- | --- |\n| 1 | 2 |\n| 3 | 4 |")) | first(self) | table::add_row(self, ["5", "6"]) | table::to_csv(self)
a,b
1,2
3,4
5,6
add_column(table: dynamic, col: dynamic): dict
function
Add a new column to a table.
Module: import "table" | table::add_column(...)
import "table" | table::tables(to_markdown("| a | b |\n| --- | --- |\n| 1 | 2 |\n| 3 | 4 |")) | first(self) | table::add_column(self, ["c", "9", "10"]) | table::to_csv(self)
a,b,c
1,2,9
3,4,10
remove_row(table: dynamic, row_index: dynamic): dict
function
Remove a row from a table at the specified index.
Module: import "table" | table::remove_row(...)
import "table" | table::tables(to_markdown("| a | b |\n| --- | --- |\n| 1 | 2 |\n| 3 | 4 |")) | first(self) | table::remove_row(self, 0) | table::to_csv(self)
a,b
3,4
remove_column(table: dynamic, col_index: dynamic): dict
function
Remove a column from a table at the specified index.
Module: import "table" | table::remove_column(...)
import "table" | table::tables(to_markdown("| a | b |\n| --- | --- |\n| 1 | 2 |\n| 3 | 4 |")) | first(self) | table::remove_column(self, 0) | len(self[:rows][0])
1
map_rows(table: dynamic, f: dynamic): dict
function
Map a function over each row in the table.
Module: import "table" | table::map_rows(...)
import "table" | table::tables(to_markdown("| a | b |\n| --- | --- |\n| 1 | 2 |\n| 3 | 4 |")) | first(self) | table::map_rows(self, fn(row): row;) | table::to_csv(self)
a,b
1,2
3,4
filter_tables(tables: dynamic, f: dynamic): array
function
Filter tables from markdown nodes based on a predicate function.
Module: import "table" | table::filter_tables(...)
import "table" | table::tables(to_markdown("| a | b |\n| --- | --- |\n| 1 | 2 |\n| 3 | 4 |")) | table::filter_tables(self, fn(h, r): true;) | len(self)
1
filter_rows(table: dynamic, f: dynamic): dict
function
Filter rows in the table based on a predicate function.
Module: import "table" | table::filter_rows(...)
import "table" | table::tables(to_markdown("| a | b |\n| --- | --- |\n| 1 | 2 |\n| 3 | 4 |")) | first(self) | table::filter_rows(self, fn(row): true;) | table::to_csv(self)
a,b
1,2
3,4
sort_rows(table: dynamic, column_index: dynamic): dict
function
Sort rows in the table by a specified column index or default sorting.
Module: import "table" | table::sort_rows(...)
import "table" | table::tables(to_markdown("| a | b |\n| --- | --- |\n| 1 | 2 |\n| 3 | 4 |")) | first(self) | table::sort_rows(self) | table::to_csv(self)
a,b
1,2
3,4
to_markdown(table: dynamic): array
function
Convert a table structure back into a list of markdown nodes.
Module: import "table" | table::to_markdown(...)
import "table" | table::tables(to_markdown("| a | b |\n| --- | --- |\n| 1 | 2 |\n| 3 | 4 |")) | first(self) | table::to_markdown(self) | len(self)
7
to_csv(table: dynamic, delimiter: dynamic): string
function
Convert a table structure into a CSV string with the specified delimiter.
Module: import "table" | table::to_csv(...)
import "table" | table::tables(to_markdown("| a | b |\n| --- | --- |\n| 1 | 2 |\n| 3 | 4 |")) | first(self) | table::to_csv(self)
a,b
1,2
3,4
to_array(table: dynamic): array
function
Convert a table structure into an array of dict records keyed by header text. The resulting shape matches `csv::csv_parse`'s output, so it composes with `join_by` and other record-array builtins.
Module: import "table" | table::to_array(...)
import "table" | table::tables(to_markdown("| a | b |\n| --- | --- |\n| 1 | 2 |\n| 3 | 4 |")) | first(self) | table::to_array(self)
[{"a": "1", "b": "2"}, {"a": "3", "b": "4"}]
pivot_longer(table: dynamic, value_columns: dynamic, names_to: dynamic, values_to: dynamic): dict
function
Reshape a table from wide format to long format (a.k.a. melt/unpivot). `value_columns` is an array of column indices to unpivot; each one becomes a row holding its header name (in the `names_to` column) and its cell value (in the `values_to` column). Columns not listed in `value_columns` are treated as identifier columns and repeated for every unpivoted value.
Module: import "table" | table::pivot_longer(...)
import "table" | table::tables(to_markdown("| a | b |\n| --- | --- |\n| 1 | 2 |\n| 3 | 4 |")) | first(self) | table::pivot_longer(self, [1]) | table::to_csv(self)
a,name,value
1,b,2
3,b,4
pivot_wider(table: dynamic, names_from: dynamic, values_from: dynamic): dict
function
Reshape a table from long format to wide format (a.k.a. pivot/cast). `names_from` is the column index whose distinct values become the headers of new columns; `values_from` is the column index supplying the values for those new columns. Columns other than `names_from` and `values_from` are treated as identifier columns and used to group rows together.
Module: import "table" | table::pivot_wider(...)
import "table" | table::tables(to_markdown("| id | name | value |\n| --- | --- | --- |\n| 1 | x | 10 |\n| 1 | y | 20 |")) | first(self) | table::pivot_wider(self, 1, 2) | table::to_csv(self)
id,x,y
1,10,20
Testing framework for mq A simple testing framework to execute test functions and output results
16 functions
assert(cond: dynamic): dynamic
function
Verifies that a condition is true and raises an error if it's false.
Module: import "test" | test::assert(...)
true | include "test" | assert(true)
true
assert_eq(actual: dynamic, expected: dynamic): dynamic
function
Verifies that two values are equal
Module: import "test" | test::assert_eq(...)
1 | include "test" | assert_eq(1, 1)
1
assert_ne(actual: dynamic, expected: dynamic): dynamic
function
Verifies that two values are not equal
Module: import "test" | test::assert_ne(...)
1 | include "test" | assert_ne(1, 2)
1
assert_true(value: dynamic): dynamic
function
Verifies that a value is true
Module: import "test" | test::assert_true(...)
true | include "test" | assert_true(true)
true
assert_false(value: dynamic): dynamic
function
Verifies that a value is false
Module: import "test" | test::assert_false(...)
false | include "test" | assert_false(false)
false
assert_none(value: dynamic): dynamic
function
Verifies that a value is None
Module: import "test" | test::assert_none(...)
None | include "test" | assert_none(None)
assert_not_none(value: dynamic): dynamic
function
Verifies that a value is not None
Module: import "test" | test::assert_not_none(...)
1 | include "test" | assert_not_none(1)
1
assert_contains(array: dynamic, value: dynamic): dynamic
function
Verifies that an array contains a specific value
Module: import "test" | test::assert_contains(...)
[1, 2] | include "test" | assert_contains([1, 2], 1)
[1, 2]
assert_len(array: dynamic, expected_length: dynamic): dynamic
function
Verifies that an array has a specific length
Module: import "test" | test::assert_len(...)
[1, 2] | include "test" | assert_len([1, 2], 2)
[1, 2]
assert_empty(array: dynamic): dynamic
function
Verifies that an array is empty
Module: import "test" | test::assert_empty(...)
[] | include "test" | assert_empty([])
[]
assert_not_empty(array: dynamic): dynamic
function
Verifies that an array is not empty
Module: import "test" | test::assert_not_empty(...)
[1] | include "test" | assert_not_empty([1])
[1]
assert_type(value: dynamic, expected_type: dynamic): dynamic
function
Verifies that a value has the given type. For markdown nodes this checks the node kind (e.g. "h1", "code", "list"), matching `to_md_name`. For every other value it checks the runtime type returned by `type`. On failure the source range of `value` is included so callers (e.g. content-lint rules) can point at the offending node.
Module: import "test" | test::assert_type(...)
1 | include "test" | assert_type(1, "number")
1
assert_field(value: dynamic, field: dynamic): dynamic
function
Verifies that a dict has the given field.
Module: import "test" | test::assert_field(...)
{"a": 1} | include "test" | assert_field({"a": 1}, "a")
{"a": 1}
assert_matches(value: dynamic, pattern: dynamic): dynamic
function
Verifies that a value's string representation matches the given regular expression pattern.
Module: import "test" | test::assert_matches(...)
"abc" | include "test" | assert_matches("abc", "a.c")
abc
run_tests(tests: dynamic): bool
function
Executes multiple test functions. The whole report is built as a single string and printed with one `print` call, so concurrently running test files (the Rust runner may evaluate several files in parallel) can never interleave their output mid-line. Returns `true` if every test passed, so the caller can aggregate pass/fail across files itself instead of this function terminating the process.
Module: import "test" | test::run_tests(...)
test_case(name: dynamic, func: dynamic): dict
function
Helper function to create a test case
Module: import "test" | test::test_case(...)
include "test" | test_case("my test", fn(): true;)["name"]
my test
TOML Implementation in mq Based on TOML v1.0.0 specification
4 functions
toml_parse(input: dynamic): dynamic
function
Parses a TOML string and returns the parsed data structure.
Module: import "toml" | toml::toml_parse(...)
import "toml" | toml::toml_parse("key = 1")
{"key": 1}
toml_stringify(data: dynamic): string
function
Converts a data structure to a TOML string representation.
Module: import "toml" | toml::toml_stringify(...)
import "toml" | toml::toml_stringify({"key": 1})
key = 1
toml_to_json(data: dynamic): string
function
Converts a data structure to a JSON string representation.
Module: import "toml" | toml::toml_to_json(...)
import "toml" | toml::toml_to_json({"key": 1})
{"key":1}
toml_to_markdown_table(data: dynamic): string
function
Converts a TOML data structure to a Markdown table.
Module: import "toml" | toml::toml_to_markdown_table(...)
import "toml" | toml::toml_to_markdown_table([{"a": 1}])
| a |
| --- |
| 1 |
TOON implementation in mq
2 functions
toon_stringify(data: dynamic): string
function
To convert a data structure into a TOON string
Module: import "toon" | toon::toon_stringify(...)
import "toon" | toon::toon_stringify({"a": 1})
a: 1
toon_parse(input: dynamic): dynamic
function
To parse a TOON string into a data structure
Module: import "toon" | toon::toon_parse(...)
import "toon" | toon::toon_parse(toon::toon_stringify({"a": 1}))
{"a": 1}
XML Implementation in mq
3 functions
xml_parse(input: dynamic): dynamic
function
Parses an XML string and returns the corresponding data structure.
Module: import "xml" | xml::xml_parse(...)
import "xml" | xml::xml_parse("<a>hi</a>")["tag"]
a
xml_stringify(data: dynamic): string
function
Serializes a value to an XML string.
Module: import "xml" | xml::xml_stringify(...)
import "xml" | xml::xml_stringify({"tag": "a", "attributes": {}, "children": [], "text": "hi"})
<?xml version="1.0" encoding="UTF-8"?>
<a>hi</a>
xml_to_markdown_table(data: dynamic): string
function
Converts an XML data structure to a Markdown table.
Module: import "xml" | xml::xml_to_markdown_table(...)
import "xml" | xml::xml_to_markdown_table({"tag": "a", "attributes": {}, "children": [], "text": "hi"})
| Tag | Attributes | Text | Children |
| --- | --- | --- | --- |
| a | | hi | 0 |
Based on YAML 1.2 specification
6 functions
yaml_parse(input: dynamic): dynamic
function
Parses a YAML string and returns the parsed data structure. A single `---`-separated document is returned as-is; if the input contains multiple `---`-separated documents, an array of the parsed documents is returned.
Module: import "yaml" | yaml::yaml_parse(...)
import "yaml" | yaml::yaml_parse("key: 1")
{"key": 1}
yaml_stringify(data: dynamic): string
function
Converts a data structure to a YAML string representation.
Module: import "yaml" | yaml::yaml_stringify(...)
import "yaml" | yaml::yaml_stringify({"key": 1})
key: 1
yaml_to_markdown_table(data: dynamic): string
function
Converts a YAML data structure to a Markdown table.
Module: import "yaml" | yaml::yaml_to_markdown_table(...)
import "yaml" | yaml::yaml_to_markdown_table([{"a": 1}])
| a |
| --- |
| 1 |
yaml_to_json(data: dynamic): string
function
Converts a data structure to a JSON string representation.
Module: import "yaml" | yaml::yaml_to_json(...)
import "yaml" | yaml::yaml_to_json({"key": 1})
{"key": 1}
to_front_matter(data: dynamic): string
functionDeprecated
Converts a data structure to a YAML front matter string. deprecated: use to_frontmatter instead
Module: import "yaml" | yaml::to_front_matter(...)
import "yaml" | yaml::to_front_matter({"key": 1})
---
key: 1
---
to_frontmatter(data: dynamic): string
function
Converts a data structure to a YAML front matter string.
Module: import "yaml" | yaml::to_frontmatter(...)
import "yaml" | yaml::to_frontmatter({"key": 1})
---
key: 1
---
48 selectors
..(): array
selector
Recursively selects every descendant node (depth-first), not the node itself. Combine with a following selector for a descendant chain, e.g. `.blockquote .code` (sugar for `.blockquote | .. | .code`).
to_markdown("> ## Nested")[0] | ..
[Nested, ## Nested]
.<>(): markdown
selector
Selects an HTML node.
.[](index: number, ...: dynamic): markdown
selector
Selects a list item node, optionally filtered by item index (e.g. `.[](0)`). To filter by checked state, use `.task`/`.todo`/`.done` instead.
to_md_list("Item", 0) | .[]
- Item
.[][](row: number, column: number): markdown
selector
Selects a table cell node with the specified row and column.
to_md_table_cell("A1", 0, 0) | .[][]
A1
.blockquote(): markdown
selector
Selects a blockquote node.
to_blockquote("Quote") | .blockquote
> Quote
.break(): markdown
selector
Selects a break node.
to_markdown("Line1 \nLine2")[1] | .break
\
.callout(kind: string, ...: dynamic): markdown
selector
Selects an Obsidian-style callout node, optionally filtered by kind (e.g. `.callout("note")`).
to_markdown("> [!NOTE]\n> body")[0] | .callout
> [!NOTE]
> body
.code(lang: string, ...: dynamic): markdown
selector
Selects a code block node with the specified language.
to_code("x = 1", "python") | .code
```python
x = 1
```
.code_inline(): markdown
selector
Selects an inline code node.
to_code_inline("x") | .code_inline
`x`
.definition(ident: string, ...: dynamic): markdown
selector
Selects a definition node, optionally filtered by identifier.
to_markdown("[ref]: https://example.com")[0] | .definition
[ref]: https://example.com
.delete(): markdown
selector
Selects a delete (strikethrough) node.
to_delete("Old") | .delete
~~Old~~
.done(): markdown
selector
Selects a done item in the task list node.
to_markdown("- [ ] Todo\n- [x] Done")[1] | .done
- [x] Done
.embed(target: string, ...: dynamic): markdown
selector
Selects an Obsidian-style embed node, optionally filtered by target.
to_markdown("![[image.png]]")[0] | .embed
![[image.png]]
.emphasis(): markdown
selector
Selects an emphasis (italic) node.
to_em("Italic") | .emphasis
*Italic*
.footnote(ident: string, ...: dynamic): markdown
selector
Selects a footnote node, optionally filtered by identifier.
to_markdown("Text[^1]\n\n[^1]: Note")[2] | .footnote
[^1]: Note
.footnote_ref(ident: string, ...: dynamic): markdown
selector
Selects a footnote reference node, optionally filtered by identifier.
to_markdown("Text[^1]\n\n[^1]: Note")[1] | .footnote_ref
[^1]
.h(depth: number, ...: dynamic): markdown
selector
Selects a heading node with the specified depth.
to_h("Title", 3) | .h
### Title
.h1(): markdown
selector
Selects a heading node with the 1 depth.
to_h("Title", 1) | .h1
# Title
.h2(): markdown
selector
Selects a heading node with the 2 depth.
to_h("Title", 2) | .h2
## Title
.h3(): markdown
selector
Selects a heading node with the 3 depth.
to_h("Title", 3) | .h3
### Title
.h4(): markdown
selector
Selects a heading node with the 4 depth.
to_h("Title", 4) | .h4
#### Title
.h5(): markdown
selector
Selects a heading node with the 5 depth.
to_h("Title", 5) | .h5
##### Title
.h6(): markdown
selector
Selects a heading node with the 6 depth.
to_h("Title", 6) | .h6
###### Title
.heading(depth: number, ...: dynamic): markdown
selector
Selects a heading node with the specified depth.
to_h("Title", 2) | .heading
## Title
.horizontal_rule(): markdown
selector
Selects a horizontal rule node.
to_hr() | .horizontal_rule
***
.html(): markdown
selector
Selects an HTML node.
to_markdown("<div>hi</div>")[0] | .html
<div>hi</div>
.image(url: string, ...: dynamic): markdown
selector
Selects an image node, optionally filtered by URL (e.g. `.image("a.png")`).
to_image("https://example.com/a.png", "Alt", "") | .image

.image_ref(ident: string, ...: dynamic): markdown
selector
Selects an image reference node, optionally filtered by identifier.
to_markdown("![alt][ref]\n\n[ref]: https://example.com/a.png")[0] | .image_ref
![alt][ref]
.inline_math(): markdown
selector
Selects an inline math node.
to_math_inline("x^2") | .inline_math
$x^2$
.link(url: string, ...: dynamic): markdown
selector
Selects a link node, optionally filtered by URL (e.g. `.link("https://example.com")`).
to_link("https://example.com", "Example", "") | .link
[Example](https://example.com)
.link_ref(ident: string, ...: dynamic): markdown
selector
Selects a link reference node, optionally filtered by identifier.
to_markdown("[text][ref]\n\n[ref]: https://example.com")[0] | .link_ref
[text][ref]
.list(index: number, ...: dynamic): markdown
selector
Selects a list item node, optionally filtered by item index (e.g. `.list(0)`). To filter by checked state, use `.task`/`.todo`/`.done` instead.
to_md_list("Item", 0) | .list
- Item
.math(): markdown
selector
Selects a math node.
to_math("x^2") | .math
$$
x^2
$$
.math_inline(): markdown
selector
Selects a math inline node.
to_math_inline("x^2") | .math_inline
$x^2$
.mdx_flow_expression(): markdown
selector
Selects an MDX flow expression node.
to_mdx("{1 + 1}")[0] | .mdx_flow_expression
{1 + 1}
.mdx_js_esm(): markdown
selector
Selects an MDX JS ESM node.
.mdx_jsx_flow_element(name: string, ...: dynamic): markdown
selector
Selects an MDX JSX flow element node, optionally filtered by tag name.
to_mdx("<Foo />")[0] | .mdx_jsx_flow_element
<Foo />
.mdx_jsx_text_element(name: string, ...: dynamic): markdown
selector
Selects an MDX JSX text element node, optionally filtered by tag name.
to_mdx("Hello <b>world</b>.")[1] | .mdx_jsx_text_element
<b>world</b>
.mdx_text_expression(): markdown
selector
Selects an MDX text expression node.
to_mdx("Value is {1 + 1}.")[1] | .mdx_text_expression
{1 + 1}
.strong(): markdown
selector
Selects a strong (bold) node.
to_strong("Bold") | .strong
**Bold**
.table(row: number, column: number): markdown
selector
Selects a table cell node with the specified row and column.
to_md_table_cell("A1", 0, 0) | .table
A1
.table_align(): markdown
selector
Selects a table align node.
to_md_table_align(["left", "right"]) | .table_align
|:---|---:|
.task(): markdown
selector
Selects a task list node.
to_markdown("- [ ] Todo\n- [x] Done")[0] | .task
- [ ] Todo
.text(): markdown
selector
Selects a text node.
to_md_text("Hello") | .text
Hello
.todo(): markdown
selector
Selects a todo item in the task list node.
to_markdown("- [ ] Todo\n- [x] Done")[0] | .todo
- [ ] Todo
.toml(): markdown
selector
Selects a TOML node.
to_markdown("+++\nkey = 1\n+++\n\nBody")[0] | .toml
+++
key = 1
+++
.wikilink(target: string, ...: dynamic): markdown
selector
Selects an Obsidian-style wikilink node, optionally filtered by target.
to_markdown("[[target]]")[0] | .wikilink
[[target]]
.yaml(): markdown
selector
Selects a YAML node.
to_markdown("---\nkey: 1\n---\n\nBody")[0] | .yaml
---
key: 1
---