Skip to main content
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

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();

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?

Package Information

PropertyValue
Package Name@kodexa-ai/document-wasm-ts
npmnpmjs.com/package/@kodexa-ai/document-wasm-ts
LicenseApache-2.0
Repositorygithub.com/kodexa-ai/kodexa-document