Skip to main content

Install

Every tab below runs the same document — pick whichever host fits what you're building. If you'd rather not install anything yet, every concept page from here on has a Run button built right into the page; nothing to set up.

hello.stof
str message: "Hello, Stof!"

fn greet() -> str {
`${self.message} Data and logic, together.`
}

#[main]
fn main() {
pln(self.greet());
}

Install:

npm i @formata/stof

@formata/stof on npm →

Run:

index.ts
import { stofAsync } from '@formata/stof';

const doc = await stofAsync`
message: "Hello, Stof!"

fn greet() -> str {
\`\${self.message} Data and logic, together.\`
}

#[main]
fn main() {
pln(self.greet());
}
`;

// Bridge Stof's pln(...) to your host's console
doc.lib('Std', 'pln', (...args: unknown[]) => console.log(...args));

await doc.run();
Hello, Stof! Data and logic, together.

Initializing in a Browser or Bundler

stofAsync above works with zero setup in Node, Deno, and Bun — Stof's WASM binary loads automatically. A bundler processes imports differently, so that auto-detection doesn't always apply — pick whichever pattern matches your setup:

Vite
import { initStof } from '@formata/stof';
import stofWasm from '@formata/stof/wasm?url';

await initStof(stofWasm);
Other bundlers (webpack, Rollup, etc.)
import { initStof } from '@formata/stof';
import stofWasm from '@formata/stof/wasm';

await initStof(await stofWasm());
note

Webpack specifically doesn't handle a raw .wasm import out of the box — if that import throws a parse error, add a rule telling webpack to treat .wasm files as a binary asset instead of trying to parse them as JavaScript:

module: {
rules: [{ test: /\.wasm$/, type: 'asset/resource' }]
}

Call initStof() once, before creating any document. After that, the lower-level StofDoc constructor works the same way stofAsync and StofDoc.parse(...) do elsewhere on this page — those two just handle this step for you automatically in Node, Deno, and Bun:

import { initStof, StofDoc } from '@formata/stof';

await initStof();

const doc = new StofDoc();
doc.parse(`
name: "Alice"
age: 30
fn greet() -> str {
'Hello, ' + self.name
}
`);

console.log(await doc.call('greet')); // "Hello, Alice"
console.log(doc.get('age')); // 30
tip

Using VS Code? The Stof extension adds syntax highlighting for .stof files — search "Stof" in the extensions tab, or install it directly from the marketplace link.