TypeScript Binding
TypeScript Binding
Section titled “TypeScript Binding”The @vgerbot/plantuml package wraps the Rust core compiled to WASM. It auto-detects the environment and loads the appropriate WASM build.
Install
Section titled “Install”npm install @vgerbot/plantumlThe API is the same in browser and Node.js:
import { renderSvg, renderPreproc } from '@vgerbot/plantuml';
const svg = await renderSvg('@startuml\nAlice -> Bob: hello\nBob --> Alice: hi\n@enduml');console.log(svg);
const preproc = await renderPreproc('@startuml\n!define FOO bar\nAlice -> Bob: FOO\n@enduml');console.log(preproc);How it works
Section titled “How it works”The package ships two WASM targets:
web(ES module +fetch) — used in the browser. The module’sdefault()export initializes the WASM instance.nodejs(require+fs) — used in Node.js. Auto-initializes on require.
renderSvg and renderPreproc are async because WASM initialization happens lazily on the first call.
Rendered example
Section titled “Rendered example”Source
@startuml
Alice -> Bob: hello
Bob --> Alice: hi
@enduml
Building from source
Section titled “Building from source”See WASM Build for instructions on rebuilding the WASM module with wasm-pack.