Install Bun:
curl -fsSL https://bun.sh/install | bash
Run a JavaScript/TypeScript file:
bun index.js
Run a package.json script:
bun run dev
Test your code:
bun test
Install a package:
bun install express
Execute a command:
bunx cowsay 'Hello, world!'
Get the current Bun version:
bun version
Hash a password:
bun hash password
Escape an HTML string:
bun escape "<script>alert('Hello, world!')</script>"
Check if two objects are deeply equal:
bun deep-equal {a: 1, b: 2} {a: 1, b: 2}
Detect when code is executed with Bun:
bun is-bun
Get the directory of the current file:
bun cwd
Get the file name of the current file:
bun filename
Convert a file URL to an absolute path:
bun url-to-path file:///path/to/file.js
Compress and decompress data with gzip:
bun gzip data
bun gunzip data
Convert an absolute path to a file URL:
bun path-to-url /path/to/file
Sleep for a fixed number of milliseconds:
bun sleep 1000
Compress and decompress data with DEFLATE:
bun deflate data
bun inflate data
For more information, please refer to the Bun documentation: https://bun.sh/.