https://github.com/remeinium/singlish
Singlish (Romanized Sinhala) with phonetic precision and zero-latency IME support. Built for the modern web by Remeinium Siyabasa Labs
https://github.com/remeinium/singlish
ime javascript library npm package phonetic pnpm remeinium roamanized singlish sinhala siyabasa transliterate transliteration transliterator yarn
Last synced: 4 months ago
JSON representation
Singlish (Romanized Sinhala) with phonetic precision and zero-latency IME support. Built for the modern web by Remeinium Siyabasa Labs
- Host: GitHub
- URL: https://github.com/remeinium/singlish
- Owner: remeinium
- License: other
- Created: 2026-02-12T21:04:48.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2026-02-14T18:34:04.000Z (5 months ago)
- Last Synced: 2026-02-14T20:38:57.447Z (5 months ago)
- Topics: ime, javascript, library, npm, package, phonetic, pnpm, remeinium, roamanized, singlish, sinhala, siyabasa, transliterate, transliteration, transliterator, yarn
- Language: TypeScript
- Homepage: https://labs.remeinium.com/siyabasa/singlish
- Size: 172 KB
- Stars: 1
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# @siyabasa/singlish
A deterministic, high-performance transliteration engine for Singlish (Romanized Sinhala) with phonetic precision and zero-latency IME support. Built for the modern web by **Remeinium Siyabasa Labs**.
[](https://www.npmjs.com/package/@siyabasa/singlish)
[](https://bundlephobia.com/package/@siyabasa/singlish)
[](https://github.com/remeinium/singlish/blob/main/LICENSE)
## Design Philosophy
The Singlish Input Method Editor (IME) landscape has long been fragmented by ad-hoc regex replacements and non-standard transliteration schemes. **@siyabasa/singlish** introduces a rigourous, computer-science first approach to Sinhala transliteration:
- **Deterministic Phoneme Tokenization**: Unlike simple string replacement, our engine tokenizes Roman input into phonetic units before rendering, ensuring 100% accuracy for complex conjuncts (*yansaya*, *rakaransaya*) and vowel modifiers.
- **Zero-Latency Architecture**: Optimized for the critical rendering path. The core conversion engine operates in O(n) time complexity using a prefix-trie based lookahead parser.
- **Universal Runtime**: Isomorphic design that runs seamlessly on the Edge, Node.js, and in the Browser.
## Architecture
The engine uses a two-stage compilation process:
1. **Lexical Analysis**: Input text is scanned and tokenized into phonemes using a greedy matching algorithm against a compiled trie of 400+ phoneme patterns.
2. **Contextual Rendering**: A state-machine renderer processes the token stream to handle inherent vowels, *hal-kirima*, and context-dependent glyph shaping (e.g., standard *ra* vs *rakaransaya* forms).
## Installation
```bash
npm install @siyabasa/singlish
# or
yarn add @siyabasa/singlish
# or
pnpm add @siyabasa/singlish
```
## Quick Start
### Core Transliteration
The core API is stateless and synchronous, designed for high-throughput server-side rendering or bulk text processing.
```typescript
import { convertSinglishToSinhala } from '@siyabasa/singlish';
const output = convertSinglishToSinhala('aayuboowan');
// Output: "ආයුබෝවන්"
```
### React IME Hook
For building rich text editors or chat interfaces, use the `useSinglishConverter` hook. It manages cursor position, input history, and IME state automatically.
```tsx
import { useSinglishConverter } from '@siyabasa/singlish';
export function Editor() {
const { inputProps, enabled, toggle } = useSinglishConverter({ enabled: true });
return (
Input Method
{enabled ? '🇱🇰 Siyabasa IME' : '🇺🇸 English'}
);
}
```
### Auto-Attach (Zero Config)
For legacy applications or rapid prototyping, the Auto-Attach module uses a `MutationObserver` to automatically hydrate all input fields in the DOM with Singlish capabilities.
```typescript
import { createAutoAttach, createUIToggle } from '@siyabasa/singlish';
// Automatically attaches to all input[type="text"] and textarea elements
const autoAttach = createAutoAttach({
exclude: '[data-no-ime]' // Optional exclusion selector
});
// Mounts a floating toggle widget
const toggle = createUIToggle({
position: 'bottom-right',
theme: 'auto'
});
toggle.mount();
```
## CITATION for Phonetic Transliteration
Singlish uses a phonetic mapping scheme, inspired by the standard method popularized by **[Helakuru](https://helakuru.lk)**. This means you type the sound of the letter rather than the key position (as in Wijesekara layout).
> **Writing using the Phonetic Method**
>
> "The Phonetic Method is a Sinhalese typing system first introduced by Helakuru for mobile phone keyboards. It allows you to type Sinhala characters by using English letters that match their sound." — *Helakuru.lk*
We acknowledge and credit Helakuru for their innovation in establishing this now-standard mapping for digital Sinhala typing."
> [Read more](https://facts.helakuru.lk/sinhala-typing/phonetic)
- **Short vowels**: `a` (අ), `i` (ඉ), `u` (උ), `e` (එ), `o` (ඔ)
- **Long vowels**: Double the letter (`aa` -> ආ, `ii` -> ඊ)
- **Consonants**: Standard mappings (`k` -> ක, `g` -> ග)
- **Aspirated (Mahaprana)**: Add `h` (`kh` -> ඛ, `bh` -> භ)
- **Retroflex (Murdhaja)**: Capitalize (`T` -> ට, `D` -> ඩ, `N` -> ණ)
## API Reference
### `convertSinglishToSinhala(text: string, options?: ConversionOptions): string`
Pure function to transpile Singlish text to Sinhala Unicode.
### `convertWithMetadata(text: string): ConversionResult`
Extended version of the core converter that provides tokenization details and conversion metrics.
### `useSinglishConverter(options?: HookOptions)`
React hook that returns spreadable input props (`value`, `onChange`, `onKeyDown`, etc.) for seamless IME integration.
## License
ROSL 1.0 © [Remeinium Siyabasa Labs](https://labs.remeinium.com/siyabasa)
---
Built with ❤️ for the Sinhala NLP Community