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.
Features
Section titled “Features”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
transliteratefunction
Installation
Section titled “Installation”The WASM module is included in the main lipilekhika package — no additional installation required!
npm install lipilekhikapnpm add lipilekhikabun add lipilekhikayarn add lipilekhikaBasic Usage
Section titled “Basic Usage”Simple Transliteration
Section titled “Simple Transliteration”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); // न जायते म्रियते वाWith Custom Options
Section titled “With Custom Options”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 ગઙ્ગા)Preloading the WASM Module
Section titled “Preloading the WASM Module”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 initializationawait preloadWasm();
// Later calls will be instant (no loading delay)const result = await transliterate_wasm('namaste', 'Normal', 'Devanagari');console.log(result); // नमस्तेAPI Reference
Section titled “API Reference”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 nameto: ScriptLangType— Target script/language nameoptions?: TransliterationOptions— Optional custom transliteration options
Returns: Promise<string | string[]> — shape matches text
Example:
const result = await transliterate_wasm('hello', 'Normal', 'Telugu');console.log(result); // హెల్లొpreloadWasm()
Section titled “preloadWasm()”Preloads the WASM module to eliminate initial loading delay.
Returns: Promise<void>
Example:
// During app initializationawait preloadWasm();
// Now WASM calls are instantconst result = await transliterate_wasm('text', 'Normal', 'Devanagari');Performance Comparison
Section titled “Performance Comparison”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
Cross-Environment Support
Section titled “Cross-Environment Support”The WASM module works seamlessly across all JavaScript environments:
Node.js
Section titled “Node.js”import { transliterate_wasm } from 'lipilekhika';
const result = await transliterate_wasm('text', 'Normal', 'Devanagari');console.log(result);Browser (ESM)
Section titled “Browser (ESM)”<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);When to Use WASM vs JavaScript
Section titled “When to Use WASM vs JavaScript”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)
Bundle Size
Section titled “Bundle Size”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!
Technical Details
Section titled “Technical Details”How It Works
Section titled “How It Works”- The WASM module is compiled from the Rust implementation of Lipi Lekhika
- All script data is embedded directly into the WASM binary at compile time
- The module is lazy-loaded on first use (or via
preloadWasm()) - Subsequent calls reuse the loaded module for optimal performance
Browser Compatibility
Section titled “Browser Compatibility”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)