js_bun

bun-specific js bindings

js
bun
moon add mizchi/js_bun@0.12.2
Download zip
Author
Version
0.12.2
License
MIT
Last updated
15 hours ago
Downloads
18

Dependencies

README

#
Bun

#external
pub type Bun

#
Bun::argv

fn Bun::argv(self : Bun) -> Array[String]

Get command line arguments (excluding the binary and script path)

#
Bun::as_any

fn Bun::as_any(self : Bun) ->
Any

#
Bun::cwd

fn Bun::cwd(self : Bun) -> String

Get current working directory (Bun.cwd is a property, not a function)

#
Bun::env

fn Bun::env(self : Bun) ->
Any

Get all environment variables as an object

#
Bun::env_get

fn Bun::env_get(self : Bun, key : String) -> String?

Get environment variable

#
Bun::escapeHTML

fn Bun::escapeHTML(self : Bun, html : String) -> String

Escape HTML string (Bun.escapeHTML)

#
Bun::exit

fn Bun::exit(self : Bun, code? : Int) -> Unit

Exit the process

#
Bun::file_arrayBuffer

async fn Bun::file_arrayBuffer(self : Bun, path : String) ->
ArrayBuffer

Read a file as ArrayBuffer

#
Bun::file_text

async fn Bun::file_text(self : Bun, path : String) -> String

Read a file as text

#
Bun::hash_

fn Bun::hash_(self : Bun, data :
Any
, algorithm? : String) ->
Any

Hash data with specified algorithm (Bun.hash) Algorithms: "sha1", "sha256", "sha512", "md5", etc.

#
Bun::main_

fn Bun::main_(self : Bun) -> String

Get the main module path NOTE: If you define ::main, moon coverage analyze will fail https://github.com/moonbitlang/moonbit-docs/issues/1071

#
Bun::nanoseconds

fn Bun::nanoseconds(self : Bun) -> Int

Get a high-resolution timestamp in nanoseconds

#
Bun::password_hash

async fn Bun::password_hash(self : Bun, password : String) -> String

Hash a password using bcrypt

#
Bun::password_verify

async fn Bun::password_verify(self : Bun, password : String, hash : String) -> Bool

Verify a password against a hash

#
Bun::peek

fn Bun::peek(self : Bun, promise :
Any
) ->
Any

Peek at a Promise state (Bun.peek)

#
Bun::revision

fn Bun::revision(self : Bun) -> String

Get Bun revision

#
Bun::serve

fn Bun::serve(self : Bun, port? : Int, hostname? : String, fetch :
Any
) -> Server

Create an HTTP server with a fetch handler

#
Bun::sleep

async fn Bun::sleep(self : Bun, ms : Int) -> Unit

Sleep for a duration in milliseconds

#
Bun::spawn

fn Bun::spawn(self : Bun, opts : SpawnOptions) -> Subprocess

Spawn a subprocess

#
Bun::spawnSync

fn Bun::spawnSync(self : Bun, opts : SpawnOptions) ->
Any

Spawn a subprocess synchronously

#
Bun::stringWidth

fn Bun::stringWidth(self : Bun, text : String) -> Int

Get string display width (Bun.stringWidth)

#
Bun::test_

fn[E : Show + Error] Bun::test_(self : Bun, name : String, f : (TestContext) -> Unit raise E) -> Unit

Bun.test(name, fn) - wrapper for convenience

#
Bun::test_async

fn Bun::test_async(self : Bun, name : String, f : async (TestContext) -> Unit) -> Unit

Bun.test(name, async fn) - wrapper for convenience

#
Bun::version

fn Bun::version(self : Bun) -> String

Get Bun version

#
Bun::which

fn Bun::which(self : Bun, bin : String) -> String?

Find executable in PATH (Bun.which)

#
Bun::write

async fn Bun::write(self : Bun, path : String, data :
Any
) -> Int

Write data to a file

#
CryptoHasher

#external
pub type CryptoHasher

#
CryptoHasher::as_any

#
CryptoHasher::digest_base64

fn CryptoHasher::digest_base64(self : CryptoHasher) -> String

Get digest as base64 string

#
CryptoHasher::digest_buffer

Get digest as ArrayBuffer

#
CryptoHasher::digest_hex

fn CryptoHasher::digest_hex(self : CryptoHasher) -> String

Get digest as hex string

#
CryptoHasher::new

fn CryptoHasher::new(algorithm : String) -> CryptoHasher

Create a new CryptoHasher with specified algorithm

#
CryptoHasher::update

fn CryptoHasher::update(self : CryptoHasher, data :
Any
) -> Unit

Update hasher with data

#
Expectation

#external
pub type Expectation

expect() function for assertions

#
Expectation::as_any

#
Expectation::toBe

fn Expectation::toBe(self : Expectation, expected :
Any
) -> Unit

Assert that the value equals the expected value

#
Expectation::toBeDefined

fn Expectation::toBeDefined(self : Expectation) -> Unit

Assert that the value is defined (not undefined)

#
Expectation::toBeFalsy

fn Expectation::toBeFalsy(self : Expectation) -> Unit

Assert that the value is falsy

#
Expectation::toBeNull

fn Expectation::toBeNull(self : Expectation) -> Unit

Assert that the value is null

#
Expectation::toBeTruthy

fn Expectation::toBeTruthy(self : Expectation) -> Unit

Assert that the value is truthy

#
Expectation::toBeUndefined

fn Expectation::toBeUndefined(self : Expectation) -> Unit

Assert that the value is undefined

#
Expectation::toContain

fn Expectation::toContain(self : Expectation, substring : String) -> Unit

Assert that a string contains a substring

#
Expectation::toEqual

fn Expectation::toEqual(self : Expectation, expected :
Any
) -> Unit

Assert that the value equals the expected value (deep equality)

#
Glob

#external
pub type Glob

#
Glob::as_any

fn Glob::as_any(self : Glob) ->
Any

#
Glob::match_

fn Glob::match_(self : Glob, path : String) -> Bool

Match a string against the glob pattern

#
Glob::new

fn Glob::new(pattern : String) -> Glob

Create a Glob matcher with pattern

#
Glob::scan

fn Glob::scan(self : Glob, cwd? : String) ->
Any

Scan files matching the glob pattern

#
Server

#external
pub type Server

#
Server::as_any

fn Server::as_any(self : Server) ->
Any

#
Server::hostname

fn Server::hostname(self : Server) -> String

Get the server hostname

#
Server::port

fn Server::port(self : Server) -> Int

Get the server port

#
Server::stop

fn Server::stop(self : Server) -> Unit

Stop the server

#
SpawnOptions

pub struct SpawnOptions {
cmd : Array[String]
cwd : String?
env :
Any
?
stdin : String?
stdout : String?
stderr : String?
}

Spawn options for Bun.spawn()

#
SpawnOptions::new

fn SpawnOptions::new(cmd : Array[String]) -> SpawnOptions

Create spawn options from command array

#
Subprocess

#external
pub type Subprocess

#
Subprocess::as_any

#
Subprocess::exitCode

fn Subprocess::exitCode(self : Subprocess) -> Int?

Get exit code (if process has exited)

#
Subprocess::exited

async fn Subprocess::exited(self : Subprocess) -> Int

Wait for the process to exit

#
Subprocess::kill

fn Subprocess::kill(self : Subprocess, signal? : Int) -> Unit

Kill the subprocess

#
Subprocess::pid

fn Subprocess::pid(self : Subprocess) -> Int

Get process ID

#
Subprocess::stderr

Get stderr reader

#
Subprocess::stdin

Get stdin writer

#
Subprocess::stdout

Get stdout reader

#
TestContext

#external
pub type TestContext

#
TestContext::as_any

#
TestContext::name

fn TestContext::name(self : TestContext) -> String

Get the test name

#
bun

fn bun() -> Bun

Bun global object

#
expect

fn expect(value :
Any
) -> Expectation

Create an expectation

#
is_bun

fn is_bun() -> Bool

Returns true if running in Bun

#
random_uuid_v7

fn random_uuid_v7() -> String

Generate UUIDv7 (Bun.randomUUIDv7)
fn unlink_sync(path : String) -> Unit

Delete a file (uses Node.js fs.unlinkSync for compatibility)

Source Files

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io