new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Bun · all subjects

runtime/yaml

8 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

YAML file import syntax

Bun natively supports importing .yaml and .yml files. You can import a YAML file like any other source file using import syntax: import config from "./config.yaml"; The imported file is parsed and returned as a JavaScript object with the YAML structure.

YAML named imports with destructuring

You can destructure top-level properties from a YAML file using named imports: import { database, server, features } from "./config.yaml"; Each top-level key in the YAML file becomes an importable named export.

YAML import attributes syntax

Bun supports Import Attributes syntax for YAML imports: import config from "./config.yaml" with { type: "yaml" }; This is an alternative syntax that explicitly declares the import type.

Bun.YAML.parse() runtime function

For parsing YAML strings at runtime, use Bun.YAML.parse(yamlString). This function takes a YAML string and returns a parsed JavaScript object.

YAML imports TypeScript type declarations

To add TypeScript support for YAML imports, create a declaration file with .d.ts appended to the YAML filename. For example, create config.yaml.d.ts alongside config.yaml. In this file, use export = contents where contents has the type definition for the YAML file's structure.

YAML import example with default import

import config from "./config.yaml"; const dbHost = config.database.host; // => "localhost"; const serverPort = config.server.port; // => 3000; const authEnabled = config.features.auth; // => true

YAML import example with destructuring

import { database, server, features } from "./config.yaml"; console.log(database.name); // => "myapp"; console.log(server.timeout); // => 30; console.log(features.rateLimit); // => true

Bun.YAML.parse() example

const yamlString = ` name: John Doe age: 30 hobbies: - reading - coding `; const data = Bun.YAML.parse(yamlString); console.log(data.name); // => "John Doe"; console.log(data.hobbies); // => ["reading", "coding"]

Give your agent this brain