The Kodexa Document TypeScript SDK (@kodexa-ai/document-wasm-ts) brings high-performance document processing to JavaScript environments. Powered by WebAssembly, it works in both Node.js and modern browsers while delivering near-native performance.
Requirements
Node.js 16 or higher
npm or yarn package manager
Modern browser with WebAssembly support
ES2020+ compatibility
Installation
Install from npm:
npm install @kodexa-ai/document-wasm-ts
Or with yarn:
yarn add @kodexa-ai/document-wasm-ts
Setup
Node.js setup is straightforward: import { Kodexa } from '@kodexa-ai/document-wasm-ts' ;
async function main () {
// Initialize the WASM runtime
await Kodexa . init ();
// Create and work with documents
const doc = await Kodexa . createDocument ();
console . log ( 'Document ready' );
// Clean up when done
doc . dispose ();
}
main ();
Browser setup requires loading additional scripts: <! DOCTYPE html >
< html >
< head >
<!-- sql.js for in-browser SQLite -->
< script src = "https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.11.0/sql-wasm.js" ></ script >
<!-- Kodexa bridge and Go WASM runtime -->
< script src = "node_modules/@kodexa-ai/document-wasm-ts/dist/sqljs-bridge.bundle.js" ></ script >
< script src = "node_modules/@kodexa-ai/document-wasm-ts/dist/wasm_exec.js" ></ script >
</ head >
< body >
< script type = "module" >
import { Kodexa } from './node_modules/@kodexa-ai/document-wasm-ts/dist/index.js' ;
async function init () {
await Kodexa . init ();
const doc = await Kodexa . fromText ( 'Hello from the browser!' );
const root = await doc . getRoot ();
console . log ( 'Content:' , root . content );
doc . dispose ();
}
init ();
</ script >
</ body >
</ html >
Verify Installation
Test your setup:
import { Kodexa } from '@kodexa-ai/document-wasm-ts' ;
async function verify () {
await Kodexa . init ();
if ( Kodexa . isLoaded ()) {
console . log ( 'Kodexa SDK initialized successfully' );
const doc = await Kodexa . createDocument ();
console . log ( 'Document created' );
doc . dispose ();
}
}
verify ();
Core Concepts
Initialization
Unlike the Python SDK, the TypeScript SDK requires explicit initialization:
import { Kodexa } from '@kodexa-ai/document-wasm-ts' ;
// Must call init() before any other operations
await Kodexa . init ();
// Check if ready
if ( Kodexa . isLoaded ()) {
// Safe to use
}
Async API
All document operations are asynchronous:
// Creating documents
const doc = await Kodexa . createDocument ();
const textDoc = await Kodexa . fromText ( 'Content' );
const jsonDoc = await Kodexa . fromJson ( '{"data": "json"}' );
// Node operations
const root = await doc . getRoot ();
const children = await root . getChildren ();
const content = await root . getContent ();
Memory Management
WebAssembly memory must be explicitly freed. Always call dispose() when done with documents to prevent memory leaks.
const doc = await Kodexa . fromText ( 'Content' );
try {
// Work with document
const root = await doc . getRoot ();
// ...
} finally {
// Always dispose
doc . dispose ();
}
For application shutdown:
// Browser
window . addEventListener ( 'beforeunload' , () => {
Kodexa . cleanup ();
});
// Node.js
process . on ( 'exit' , () => {
Kodexa . cleanup ();
});
Configuration
WASM Location
In browser environments, configure the WASM file location:
// Before calling Kodexa.init()
window . KODEXA_WASM_BASE_URL = '/path/to/wasm/files' ;
await Kodexa . init ();
Logging
Control the logging level:
await Kodexa . init ();
// Set log level: 'debug' | 'info' | 'warn' | 'error'
Kodexa . setLogLevel ( 'debug' );
What’s Next?
Getting Started Learn the basics of creating and manipulating documents
API Reference Explore the complete API documentation
Property Value Package Name @kodexa-ai/document-wasm-tsnpm npmjs.com/package/@kodexa-ai/document-wasm-ts License Apache-2.0 Repository github.com/kodexa-ai/kodexa-document