bungibindies/bun
Gleam bindings to the Bun runtime API’s.
Functions
pub fn deep_equals(a: a, b: a) -> Bool
- Utilities
Recursively checks if two objects are equivalent. This is used internally by
expect().toEqual()
inbun/test
.
pub fn deep_equals_strict(a: a, b: a) -> Bool
- Utilities
Recursively checks if two objects are equivalent. This is used internally by
expect().toEqual()
inbun/test
.
pub fn env(key: String) -> Result(String, Nil)
pub fn escape_html(value: a) -> String
- Utilities
Bun.escapeHTML(value: string | object | number | boolean): string
Escapes the following characters from an input string:
"
becomes"
&
becomes&
'
becomes'
<
becomes<
>
becomes>
This function is optimized for large input. On an M1X, it processes 480 MB/s - 20 GB/s, depending on how much data is being escaped and whether there is non-ascii text. Non-string types will be converted to a string before escaping.
pub fn file(path: String) -> BunFile
pub fn file_url_to_path(url: String) -> String
pub fn inspect(value: a) -> String
pub fn main_() -> String
- Utilities
An absolute path to the entrypoint javascript module of the current program (the file that was executed with bun run).
pub fn nanoseconds() -> Float
- Utilities
Returns the number of nanoseconds since the current
bun
process started, as anumber
. Useful for high-precision timing and benchmarking.
pub fn open_in_editor(path: String) -> Nil
pub fn open_in_editor_with_options(
path: String,
options: Map(String, String),
) -> Nil
pub fn path_to_file_url(path: String) -> String
pub fn peek(promise: Promise(a)) -> Result(a, Nil)
- Utilities
Reads a promise’s result without await or .then, but only if the promise has already fulfilled or rejected.
pub fn random_uuid_v7() -> String
- Utilities
Returns a UUID v7, which is monotonic and suitable for sorting and databases.
pub fn random_uuid_v7_buffer() -> Array(Int)
- Utilities
Returns a UUID v7, which is monotonic and suitable for sorting and databases as a buffer.
pub fn resolve_sync(module: String, parent: String) -> String
- Utilities
Resolves a file path or module specifier using Bun’s internal module resolution algorithm. The first argument is the path to resolve, and the second argument is the “root”. If no match is found, an
Error
is thrown.
pub fn revision() -> String
- Utilities
A string containing the git revision of the bun CLI that is currently running.
pub fn serve(
serve_options: ServeOptions,
) -> Result(Server, String)
pub fn sleep(ms: Float) -> Nil
pub fn sleep_sync(ms: Float) -> Nil
pub fn string_width(
value: String,
count_ansi_escape_codes: Bool,
ambiguous_is_narrow: Bool,
) -> Int
- Utilities
Get the column count of a string as it would be displayed in a terminal. Supports ANSI escape codes, emoji, and wide characters.
pub fn version() -> String
pub fn which(executable: String) -> Result(String, Nil)
pub fn which_with_options(
executable: String,
options: Map(String, String),
) -> Result(String, Nil)
pub fn write(destination: BunFile, data: a) -> Promise(Int)
- File I/O
The Bun.write
function is a multi-tool for writing payloads of all kinds to disk.
@param destination — The file to write to @param data — The data to copy into destination. @returns — A promise that resolves with the number of bytes written.