Formats
Every format below is a string identifier — parse(data, target, 'json'), stringify('yaml', target), import toml './file'. Which ones are actually loaded depends on the host; check with format('name') from Std before relying on one. If a file's format isn't loaded at all, import doesn't throw — it falls back to raw bytes instead.
Data Formats: json, yaml, toml
All three behave identically — plain fields in, plain fields out, no functions or types survive the round-trip:
const object = new { a: 'hello', b: 42, c: true };
stringify('json', object); // {"a":"hello","b":42,"c":true}
stringify('yaml', object); // a: hello\nb: 42\nc: true\n
stringify('toml', object); // a = "hello"\nb = 42\nc = true\n
Stof's Own Formats: stof, bstf
The only two formats that round-trip everything — functions, prototypes, schemas, attributes — not just plain data. stof is the text form (your source files use it by default); bstf is the binary equivalent, more compact, same fidelity.
const bytes = blobify('bstf', self);
// bytes now contains this entire object — data, functions, types, all of it
Text & Bytes: text, bytes
Both wrap raw content into a single field, rather than trying to interpret structure — text produces a str field named text; bytes produces a blob field named bytes, with automatic UTF-8 conversion if the source was a string.
parse('hello, there', target, 'text'); // target.text == 'hello, there'
parse('hello, there', target, 'bytes'); // target.bytes == <blob>
Web Format: urlencoded
Also available under the alias www-form. Nested objects use bracket notation, the same convention browsers use for form submissions:
stringify('urlencoded', new { sub: new { val: 42 }, msg: 'hi' });
// sub%5Bval%5D=42&msg=hi
Rich Documents: pdf, image, docx, md
Each of these needs its corresponding library loaded (Pdf, Image, Md all have their own reference pages; docx doesn't have a dedicated library beyond .text() extraction). Importing a file in one of these formats lands on a specific, fixed field name — not the filename:
| Format | Field name | Import example |
|---|---|---|
pdf | pdf | import './report.pdf' → self.pdf |
image | image | import './photo.png' → self.image |
docx | (as named) | import './doc.docx' as self.Doc → self.Doc.text() |
md | md | import './notes.md' → self.md |
Packages: pkg
Covered in depth on Import & Export — reads an import field from a pkg.stof manifest and pulls in whatever paths it lists, paired with the @ path shortcut for stof/.
When a Format Isn't Loaded
This is worth knowing explicitly: importing a file whose format isn't available doesn't fail the whole parse. It falls back to loading the raw content as bytes instead, on the assumption that raw access to something is more useful than an error — a document built without the Pdf library still gets the PDF's bytes, just not .extract_text().