@vm75/inditrans
v0.18.0
Published
A functional transliterator library for the most common Indic/Brahmic scripts.
Maintainers
Readme
@vm75/inditrans
A transliteration library for Indic/Brahmic and Roman scripts for Node.js and the browser. Powered by a C++23 engine compiled to WASM for near-native performance, with no server dependency.
- ITRANS toggle transliteration — wrap any region in
##…##to pass it through unchanged. - XML/HTML tag pass-through — tags are never transliterated.
- Special handling for Tamil, Malayalam, Gurmukhi, and other scripts tuned for readability.
- Vedic accent support for Vedic scriptures.
- Full TypeScript typings included.
Supported scripts
Optional Urdu pronunciation
transliterateUrduWithLexicon(text, to, bytes, options) accepts an IUL1 or IUL2
pack as a Uint8Array to override the bundled experimental dictionary. Ordinary
Urdu conversion uses that dictionary without downloading data. A single reading
is selected without contextual disambiguation. Unknown, explicitly marked and
mixed-script words use the ordinary Urdu reader. Option.DisableInference bypasses the lexicon.
The pack-generation format and its current limitations are described in
lexicon compilation and runtime behavior.
Indic/Brahmic: Assamese, Bengali, Burmese, Devanagari, Grantha, Gujarati, Gurmukhi, Kannada, Khmer, Malayalam, Oriya, Sinhala, Tamil, Telugu, Thai, Tibetan
Roman schemes: IAST · IPA · ISO 15919 · ITRANS · TITUS · Indlish (my own take on a readable Roman representation for Indian scripts)
ITRANS notation notes
inditrans implements uniform phonemic vowel mapping adhering to the ITRANS specification:
- Short vowels:
eandoencode short vowels (e.g. Kannadaಎ/ೆ, Teluguఎ/ె, Tamilஎ/ெ, Malayalamഎ/െ, Devanagariऎ/ॆ).^eand^oremain supported as aliases. - Long vowels:
EandOencode long vowels (e.g. Kannadaಏ/ೇ, Teluguఏ/ే, Tamilஏ/ே, Malayalamഏ/േ, Devanagariए/े). - Examples:
te$\to$तॆ/ತೆ,tE$\to$ते/ತೇ;tere bina$\to$ತೆರೆ ಬಿನ(Kannada),tErE bina$\to$ತೇರೇ ಬಿನ(Kannada) /तेरे बिन(Devanagari).
Requirements
- Node.js ≥ 18.3 (or modern browser with WebAssembly support)
Installation
npm install @vm75/inditrans
# or
yarn add @vm75/inditransQuick start
import * as inditrans from '@vm75/inditrans';
async function main() {
// init() must complete before transliterate() is called
await inditrans.init();
const result = inditrans.transliterate(
"श्री॒ गु॒रु॒भ्यो नमः॒ । ह॒रिः॒ ओ३म् ॥",
inditrans.Script.devanagari,
inditrans.Script.tamil,
inditrans.Option.IgnoreVedicAccents | inditrans.Option.TamilSuperscripted,
);
console.log(result);
}
main();API
init(): Promise<void>
Loads and initialises the WASM module. Must be awaited before any other call.
transliterate(text, from, to, options?): string
Transliterates text from the from script to the to script.
| Parameter | Type | Description |
|---|---|---|
| text | string | Input text |
| from | Script | Source script |
| to | Script | Target script |
| options | Option | Bitwise combination of option flags (default: Option.None) |
isScriptSupported(script: string): boolean
Returns true when the given script name is recognised.
Options
| Option | Value | Description |
|---|---|---|
| Option.None | 0 | No options (default) |
| Option.TamilTraditional | 1 | Traditional Tamil consonants only |
| Option.TamilSuperscripted | 2 | Superscripted Tamil consonants |
| Option.DevanagariTraditional | 128 | Traditional Devanagari orthography (maps Dravidian short e/o and consonants) |
| Option.ASCIINumerals | 4 | Force ASCII numerals in output |
| Option.IgnoreVedicAccents | 8 | Strip Vedic accent markers |
| Option.RetainSpecialMarkers | 16 | Keep non-standard character markers |
| Option.NoXMLTagHandling | 32 | Treat XML/HTML tags as plain text |
| Option.DisableInference | 64 | Disable anuswara assimilation and contextual Tamil pronunciation/letter inference |
For Tamil source text, Option.TamilSuperscripted automatically enables DisableInference. The same flag on Tamil output does not disable inference. When disabled, a mapped anuswara spelling is emitted rather than assimilated to the next consonant.
Combine flags with the bitwise OR operator: Option.IgnoreVedicAccents | Option.TamilSuperscripted.
Development
yarn install # install dependencies
yarn test # build WASM and run testsDocumentation
License
Forward accuracy and Urdu
Script.urdu (alias Script.nastaliq) supports Urdu/Perso-Arabic text. Use a
Nastaliq-capable font and RTL text direction in your application. The returned
string is ordinary Unicode in logical order. Explicit vowels, aspirates and
shadda are supported; ordinary unvocalized Urdu needs lexical information to
recover omitted vowels, so bare consonants receive no guessed vowel.
Targets use their native letters or documented phonetic approximations; source distinctions may merge. ISO input now accepts the additional spreadsheet notations, including ê, ŭ, ĉ, ž, w and the Urdu loan-letter spellings. Artificial extended-vowel separators/accents have been replaced by native approximations. Real supported accents remain separate marks. There is no round-trip guarantee.
The script profiles implement transliteration, not complete language-specific pronunciation. See the repository's mapping review for exact notation behavior and limitations.
Reusable Urdu pronunciation lexicon (experimental)
For repeated Urdu conversions, create new UrduPronunciationLexicon(iulBytes)
and call lexicon.transliterate(text, Script.iast) as often as needed.
Always call lexicon.dispose() in a finally block; do not use a disposed
lexicon. Invalid lexicon bytes throw at construction. The original one-shot
transliterateUrduWithLexicon() remains available.
