Skip to content
IC Reactor

@ic-reactor/parser

@ic-reactor/parser is the low-level WASM parser behind local Candid compilation in IC Reactor. It converts raw .did source into JavaScript IDL factories, TypeScript declaration strings, or structured schema metadata.

  • Fast and local: Compile Candid without a remote didjs canister.
  • Tooling friendly: Used by @ic-reactor/codegen to turn .did files into generated declarations.
  • Runtime friendly: Can be loaded by @ic-reactor/candid for local CandidAdapter compilation.

Candid to JS

Returns JS source that exports idlFactory and init.

Candid to TS

Returns TypeScript declaration source for the same interface.

Candid Schema

Returns structured types, services, docs, and validation metadata.

WASM Runtime

Implemented in Rust and compiled to WebAssembly.

Terminal window
pnpm add @ic-reactor/parser
import init, { didToJs, didToTs, parseDid } from "@ic-reactor/parser"
const candid = `service : {
greet : (text) -> (text) query;
}`
// Required on the web build (browsers and bundlers); the Node build
// instantiates its WASM module at import time.
await init()
const jsSource = didToJs(candid)
const tsSource = didToTs(candid)
const schema = parseDid(candid)
import { CandidAdapter } from "@ic-reactor/candid"
import { ClientManager } from "@ic-reactor/core"
import { QueryClient } from "@tanstack/query-core"
const adapter = new CandidAdapter({
clientManager: new ClientManager({ queryClient: new QueryClient() }),
})
await adapter.loadParser()
const jsSource = adapter.compileLocal(
"service : { greet : () -> (text) query }"
)