API Reference
Exports
Section titled “Exports”The package exports two main functions for converting Candid definitions.
didToJs
Section titled “didToJs”didToJs(candid: string): string
Compiles a Candid interface string into a JavaScript module string.
Parameters:
candid: The Candid interface definition string.
Returns:
- A string containing the JavaScript module source.
Output Exports: The generated JavaScript module exports:
idlFactory: AnIDL.InterfaceFactoryfunction.init: A function that returns initialization arguments.
const js = didToJs("service:{}")// export const idlFactory ...didToTs
Section titled “didToTs”didToTs(candid: string): string
Compiles a Candid interface string into a TypeScript declaration string.
Parameters:
candid: The Candid interface definition string.
Returns:
- A string containing the TypeScript declaration source.
Output Includes:
- Imports from
@icp-sdk/core(or legacy@dfinity/agent). _SERVICEinterface defining the actor type.idlFactoryandinittype declarations.
const ts = didToTs("service:{}")// export interface _SERVICE ...Module Formats
Section titled “Module Formats”The package builds for multiple targets to ensure compatibility across environments.
| Folder | Format | Environment |
|---|---|---|
dist/web | ES Modules | Browsers |
dist/nodejs | CommonJS | Node.js |
dist/bundler | ES Modules | Bundlers (Webpack, Vite) |
Most modern bundlers (Vite, Next.js) will automatically pick up the correct version via package.json exports.