Skip to content

Web Assembly

Lipi Lekhika includes a blazing-fast 🦀 Rust-based WebAssembly (WASM) module that brings high-performance transliteration to all JavaScript environments. The WASM implementation provides significant performance improvements while maintaining the same easy-to-use API.

The WASM module offers several advantages over the pure JavaScript implementation:

  • ⚡ Superior Performance — Rust’s compiled WASM code executes significantly faster than JavaScript
  • 📦 Compact Size — Only 114 KB gzipped (base64), including all script data embedded
  • 🌍 Universal Compatibility — Works seamlessly in Node.js, browsers, Deno, Bun, and more
  • 🔒 Type Safety — Built with Rust’s type system for reliability
  • 🎯 Same API — Drop-in replacement for the standard transliterate function

The WASM module is included in the main lipilekhika package — no additional installation required!

Terminal window
npm install lipilekhika

The transliterate_wasm function provides the same interface as transliterate (text: string | string[]):

import { transliterate_wasm } from 'lipilekhika';
const result = await transliterate_wasm('na jAyatE mriyatE vA', 'Normal', 'Devanagari');
console.log(result); // न जायते म्रियते वा

You can pass custom transliteration options just like the standard function:

import { transliterate_wasm } from 'lipilekhika';
const result = await transliterate_wasm(
'गङ्गा',
'Devanagari',
'Gujarati',
{ 'brahmic_to_brahmic:replace_pancham_varga_varna_with_anusvAra': true }
);
console.log(result); // ગંગા (instead of ગઙ્ગા)

To avoid the initial loading delay when first calling transliterate_wasm, you can preload the WASM module:

import { preloadWasm, transliterate_wasm } from 'lipilekhika';
// Preload during app initialization
await preloadWasm();
// Later calls will be instant (no loading delay)
const result = await transliterate_wasm('namaste', 'Normal', 'Devanagari');
console.log(result); // नमस्ते

transliterate_wasm(text, from, to, options?)

Section titled “transliterate_wasm(text, from, to, options?)”

WASM-based transliteration using the Rust implementation.

Parameters:

  • text: string | string[] — One string or many (same options for all)
  • from: ScriptLangType — Source script/language name
  • to: ScriptLangType — Target script/language name
  • options?: TransliterationOptions — Optional custom transliteration options

Returns: Promise<string | string[]> — shape matches text

Example:

const result = await transliterate_wasm('hello', 'Normal', 'Telugu');
console.log(result); // హెల్లొ

Preloads the WASM module to eliminate initial loading delay.

Returns: Promise<void>

Example:

// During app initialization
await preloadWasm();
// Now WASM calls are instant
const result = await transliterate_wasm('text', 'Normal', 'Devanagari');

The WASM implementation provides significant performance improvements, especially for:

  • Large text blocks — Faster processing of lengthy documents
  • Batch operations — Efficient when transliterating multiple texts
  • Complex scripts — Better performance with intricate character mappings
  • Repeated calls — Lower overhead after initial load
  • Benchmarks - 2x faster than the JavaScript implementation

The WASM module works seamlessly across all JavaScript environments:

import { transliterate_wasm } from 'lipilekhika';
const result = await transliterate_wasm('text', 'Normal', 'Devanagari');
console.log(result);
<script type="module">
import { transliterate_wasm } from 'https://cdn.jsdelivr.net/npm/lipilekhika/dist/esm/index.mjs';
const text = await transliterate_wasm('namaste', 'Normal', 'Devanagari');
console.log(text); // नमस्ते
</script>
import { transliterate_wasm } from 'npm:lipilekhika';
const result = await transliterate_wasm('text', 'Normal', 'Devanagari');
console.log(result);
import { transliterate_wasm } from 'lipilekhika';
const result = await transliterate_wasm('text', 'Normal', 'Devanagari');
console.log(result);

Use WASM (transliterate_wasm) when:

  • Processing large volumes of text
  • Performance is critical
  • You’re making repeated transliteration calls
  • Building production applications

Use JavaScript (transliterate) when:

  • Making occasional, small transliterations
  • Bundle size is extremely constrained
  • You need maximum compatibility with older environments
  • Debugging or development (easier stack traces)

The WASM module adds only 114 KB (gzipped base64) to your bundle, which includes:

  • The compiled Rust WASM binary
  • All script data embedded (no external data files needed)
  • Complete transliteration logic

This is remarkably compact considering it includes all the data and logic for 15+ scripts!

  1. The WASM module is compiled from the Rust implementation of Lipi Lekhika
  2. All script data is embedded directly into the WASM binary at compile time
  3. The module is lazy-loaded on first use (or via preloadWasm())
  4. Subsequent calls reuse the loaded module for optimal performance

The WASM module requires WebAssembly support, which is available in:

  • Chrome/Edge 57+
  • Firefox 52+
  • Safari 11+
  • Node.js 8+
  • Deno (all versions)
  • Bun (all versions)