Skip to content

JavaScript

Lipi Lekhika offers a typesafe, tree-shakable package for JavaScript/TypeScript. It has support for all major javascript packaging formats namely ESM, CommonJS and UMD.

bash npm install lipilekhika

For transliteration use the transliterate function. Pass text as string | string[]; the result is a Promise<string> or Promise<string[]> with the same shape.

import { transliterate } from 'lipilekhika';
const result = await transliterate('na jAyatE mriyatE vA', 'Normal', 'Devanagari');
console.log(result); // न जायते म्रियते वा
  • For commonjs you can use the require('lipilekhika') syntax.
  • The Script/Language names are type safe so you will get editor support for autocompletion for names(including aliases).
  • You can also pass in custom transliteration options to the transliterate as the fourth argument to the function.

The package includes a blazing-fast 🦀 Rust-based WASM implementation that works across all JavaScript environments (Node.js, browsers, Deno, Bun). Use transliterate_wasm() for improved performance and preloadWasm() to avoid initial loading delays.

The package also exports the following constants and utilities:

  • SCRIPT_LIST — Array of all supported script names
  • LANG_LIST — Array of all supported language names mapped to scripts
  • ALL_LANG_SCRIPT_LIST — Combined list of all supported scripts and languages
  • preloadScriptData(name) — Function to preload script data (useful for browsers to avoid fetch latency)
  • getAllOptions(from, to) — Returns available custom transliteration options for a specific script pair

TypeScript Types:

  • TransliterationOptions — Type for custom transliteration options
  • ScriptListType / LangListType — Types for script and language lists
  • ScriptLangType — Type for script/language identifiers (with aliases)

You can also use the package directly in the browser using the ESM and UMD Packages

<script type="module">
import { transliterate } from 'https://cdn.jsdelivr.net/npm/lipilekhika/dist/esm/index.mjs';
transliterate('na jAyatE mriyatE vA', 'Normal', 'Devanagari').then((text) => console.log(text));
</script>
<script src="https://cdn.jsdelivr.net/npm/lipilekhika"></script>
<script>
lipilekhika
.transliterate('na jAyatE mriyatE vA', 'Normal', 'Devanagari')
.then((text) => console.log(text));
</script>

For Browser environments we have a premade plugin for multiple frontend frameworks to use Lipi Lekhika’s realtime typing features.

An environment-agnostic reference guide to implement Realtime typing is any environment is available at the link below.

The package also ships a native Rust-based N-API binding accessible via lipilekhika/node. This gives you near-native performance without the overhead of WASM instantiation.

import { transliterate_node, preloadNode } from 'lipilekhika/node';
import { createTypingContext } from 'lipilekhika/node';
// Optional: preload the native module
await preloadNode();
const result = await transliterate_node('na jAyatE mriyatE vA', 'Normal', 'Devanagari');
console.log(result); // न जायते म्रियते वा
// Typing context (same API as the TS version)
const ctx = createTypingContext('Telugu');
await ctx.ready;
const diff = ctx.takeKeyInput('k');