function
YAML.parse
Parse a YAML string into a JavaScript value. Every alias (*name) of an anchored collection yields the same object, and an alias may refer to a collection that contains it, so the result can be cyclic.
The YAML document to parse, as a string or UTF-8 bytes. A Blob that is backed by a file, such as Bun.file(), throws: pass await file.text().
A JavaScript value, or an array of them for a multi-document stream
import { YAML } from "bun";
console.log(YAML.parse("123")) // 123
console.log(YAML.parse("null")) // null
console.log(YAML.parse("false")) // false
console.log(YAML.parse("abc")) // "abc"
console.log(YAML.parse("- abc")) // [ "abc" ]
console.log(YAML.parse("abc: def")) // { "abc": "def" }Referenced types
class Blob
A file-like object of immutable, raw data. Blobs represent data that isn't necessarily in a JavaScript-native format. The File interface is based on Blob, inheriting blob functionality and expanding it to support files on the user's system.
Returns a promise that resolves to the contents of the blob as an ArrayBuffer
Returns a promise that resolves to the contents of the blob as a Uint8Array (array of bytes). Equivalent to
new Uint8Array(await blob.arrayBuffer())Read the data from the blob as a FormData object.
This first decodes the data from UTF-8, then parses it as a
multipart/form-databody or anapplication/x-www-form-urlencodedbody.The blob's
typeproperty determines the format of the body.This is a non-standard addition to the
BlobAPI, to make it conform more closely to theBodyMixinAPI.Wrap this blob in a Bun.Image pipeline. Equivalent to
new Bun.Image(this, options)— the constructor is synchronous (the underlying read happens lazily when an Image terminal is awaited), so this works onBun.file(),Bun.s3(), fd-backed and in-memory blobs alike:await Bun.file("photo.jpg").image().resize(400).webp().write("thumb.webp");Read the data from the blob as a JSON object.
This first decodes the data from UTF-8, then parses it as JSON.
- start?: number,end?: number,contentType?: string
Returns a new
Blobwith the bytes fromstartup to but not includingend. Negative indices count from the end.@param startbyte offset to start at. Defaults to 0.
@param endbyte offset to stop at. Defaults to
size.@param contentTypethe
typeof the newBlob. Returns a readable stream of the blob's contents
Returns a promise that resolves to the contents of the blob as a string