bungibindies/bun

Gleam bindings to the Bun runtime API’s.

Functions

pub fn deep_equals(a: a, b: a) -> Bool

Bun.deepEquals()

  • Utilities

Recursively checks if two objects are equivalent. This is used internally by expect().toEqual() in bun/test.

pub fn deep_equals_strict(a: a, b: a) -> Bool

Bun.deepEquals()

  • Utilities

Recursively checks if two objects are equivalent. This is used internally by expect().toEqual() in bun/test.

pub fn env(key: String) -> Result(String, Nil)

Bun.env

  • Utilities

Fetches the value of an environment variable.

pub fn escape_html(value: a) -> String

Bun.escapeHTML()

  • Utilities

Bun.escapeHTML(value: string | object | number | boolean): string Escapes the following characters from an input string:

  • " becomes "
  • & becomes &
  • ' becomes '
  • < becomes &lt;
  • > becomes &gt;

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_url_to_path(url: String) -> String

Bun.fileURLToPath()

  • Utilities

Converts a file URL to a file path.

pub fn inspect(value: a) -> String

Bun.inspect()

  • Utilities

Returns a string representation of an object.

pub fn main_() -> String

Bun.main

  • 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

Bun.nanoseconds()

  • Utilities

Returns the number of nanoseconds since the current bun process started, as a number. Useful for high-precision timing and benchmarking.

pub fn open_in_editor(path: String) -> Nil

Bun.openInEditor()

  • Utilities

Opens a file in the user’s editor.

pub fn open_in_editor_with_options(
  path: String,
  options: Map(String, String),
) -> Nil

Bun.openInEditor()

  • Utilities

Opens a file in the user’s editor.

pub fn path_to_file_url(path: String) -> String

Bun.pathToFileURL()

  • Utilities

Converts a file path to a file URL.

pub fn peek(promise: Promise(a)) -> Result(a, Nil)

Bun.peek()

  • 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

Bun.randomUUIDv7()

  • Utilities

Returns a UUID v7, which is monotonic and suitable for sorting and databases.

pub fn random_uuid_v7_buffer() -> Array(Int)

Bun.randomUUIDv7()

  • 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

Bun.resolveSync()

  • 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

Bun.revision

  • Utilities

A string containing the git revision of the bun CLI that is currently running.

pub fn sleep(ms: Float) -> Nil

Bun.sleep()

  • Utilities

Sleeps for the given number of milliseconds.

pub fn sleep_sync(ms: Float) -> Nil

Bun.sleepSync()

  • Utilities

Sleeps for the given number of milliseconds.

pub fn string_width(
  value: String,
  count_ansi_escape_codes: Bool,
  ambiguous_is_narrow: Bool,
) -> Int

Bun.stringWidth()

  • 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

Bun.version

  • Utilities

A string containing the version of the bun CLI that is currently running.

pub fn which(executable: String) -> Result(String, Nil)

Bun.which()

  • Utilities

Returns the path to the given executable if it is in the PATH, otherwise returns an empty string.

pub fn which_with_options(
  executable: String,
  options: Map(String, String),
) -> Result(String, Nil)

Bun.which()

  • Utilities

Returns the path to the given executable if it is in the PATH, otherwise returns an empty string.

Search Document