Import Statement
Enabling Stof import statements.
Stof import statements use the file system library. Although this library is not enabled by default in a WebAssembly context, we can add it ourselves.
This is for non-browser JavaScript, where system access is available.
Text Files
For the Stof import statement, we need the 'fs.read(..)' function. This function is used internally by the loaded formats in the document.
import { Stof } from 'jsr:@formata/stof';
const doc = await Stof.create();
doc.insertLibrary('fs', [
['read', (path: string): string => Deno.readTextFileSync(path)]
]);
doc.importString('stof', `
import 'import.toml'; // Calls fs.read('import.toml') in the background...
#[main]
fn main() {
console.log('Hello, ' + self.name);
}
`);
doc.run();
> deno run --allow-all example.ts
Hello, Bob Smith
Last updated
Was this helpful?