TypeScript · React · Tailwind

Type Sinhala.
Phonetically.

ආයුබෝවන්  ·  සිංහල  ·  ශ්‍රී ලංකාව

An npm package for Sinhala phonetic input — drop-in React components with real-time Unicode conversion and word prediction.

Get Started View on GitHub
$ npm install @dnsam/sinhala-phonetics
ayubowanආයුබෝවන්
mamaමම
ammaඅම්මා
kohomadaකොහොමද
aadareආදරේ
rataරට
sinhalaසිංහල
Why use this

Everything you need
for Sinhala input.

Built for developers building Sinhala-language products — from simple text fields to full editors.

Real-time conversion

As you type phonetically, each keystroke is converted to Sinhala Unicode instantly — no submit, no button, no delay.

💡

Word prediction

A built-in dictionary of ~350 common Sinhala words powers prefix-based suggestions. Select one to replace the current word.

🎨

Tailwind CSS styled

Default styles work out of the box. Override any element with className props, or pass unstyled for full control.

🔩

Headless core

Use convertText() and SinhalaPredictor anywhere — Node.js, Deno, Svelte, Vue. No React required for the core.

📦

Dual ESM + CJS

Tree-shakeable ESM and CommonJS builds. Full TypeScript declarations. Works with Vite, Next.js, Webpack, and Rollup.

🔌

Extensible dictionary

Bring your own word list using new SinhalaPredictor(myWords) or extend the built-in one with predictor.addWords().

Phonetic reference

Type this. Get that.

Common phonetic patterns — the same scheme used by Sinhala Google Input Tools.

ayubowanආයුබෝවන්
mamaමම
ammaඅම්මා
thaththaතාත්තා
kohomadaකොහොමද
aadareආදරේ
sinhalaසිංහල
rataරට
gamaගම
gedaraගෙදර
isthuthiඉස්තූති
kramayaක්‍රමය
aa
ii
uu
sh / Shශ / ෂ
th / Thත / ථ
GN
Interactive demo

Try it right here.

Type any Sinhala phonetics in the left pane and watch the Unicode appear live in the right pane. Click a suggestion chip to accept a word prediction.

Live · Real-time conversion
Phonetic Input
Sinhala Unicode Output
ඔබේ සිංහල මෙහි දිස්වේ…
Suggestions — type a word to see predictions
Try an example:
Quick start

Start typing in
three lines of code.

The <SinhalaTypewriter> component handles everything — conversion, state, and the suggestion dropdown.

import { SinhalaTypewriter } from '@dnsam/sinhala-phonetics';

export default function App() {
  return (
    <SinhalaTypewriter
      onChange={(text) => console.log(text)}
      placeholder='Type "ayubowan"…'
      maxSuggestions={5}
    />
  );
}
import { useState } from 'react';
import { SinhalaTypewriter } from '@dnsam/sinhala-phonetics';

export default function Editor() {
  const [text, setText] = useState('');

  return (
    <>
      <SinhalaTypewriter
        value={text}
        onChange={setText}
        onSuggestionSelect={(word) => console.log('picked:', word)}
        rows={6}
      />
      <p>Characters: {text.length}</p>
    </>
  );
}
// Full control — your CSS, no Tailwind required
import { SinhalaTypewriter } from '@dnsam/sinhala-phonetics';

<SinhalaTypewriter
  unstyled
  onChange={setText}
  inputClassName="my-textarea"
  suggestionsClassName="my-dropdown"
  suggestionItemClassName="my-item"
/>

// Or build completely custom UI with the hooks:
import { useSinhalaConverter, useWordPrediction } from '@dnsam/sinhala-phonetics';

const { sinhalaValue, currentWordSinhala, handlePhoneticChange, replaceCurrentWord }
  = useSinhalaConverter();

const suggestions = useWordPrediction(currentWordSinhala, { maxSuggestions: 8 });
// Works in Node, Deno, browser — no React needed
import { convertText, SinhalaPredictor } from '@dnsam/sinhala-phonetics';

convertText('ayubowan');  // → 'ආයුබෝවන්'
convertText('mama');      // → 'මම'
convertText('kohomada');  // → 'කොහොමද'

// Custom dictionary
const predictor = new SinhalaPredictor(['ගෙදර', 'ගෙල', 'ගෙනාවා']);
predictor.addWords(['අම්මා', 'තාත්තා']);
predictor.predict('ගෙ', 3);
// → [{ word: 'ගෙදර' }, { word: 'ගෙල' }, { word: 'ගෙනාවා' }]
API Reference

Everything, documented.

Full TypeScript types ship with the package — your editor will autocomplete every prop.

<SinhalaTypewriter>
React Component

All-in-one input with live Sinhala conversion and word prediction dropdown. Accepts controlled or uncontrolled usage.

  • valuestring — controlled Sinhala value
  • defaultValuestring — uncontrolled initial value
  • onChange(sinhala: string) → void
  • onSuggestionSelect(word: string) → void
  • showSuggestionsboolean — default true
  • maxSuggestionsnumber — default 5
  • unstyledboolean — strip all styles
  • rows / placeholder / disabledstandard textarea props
<SinhalaInput>
React Component

Textarea with live phonetic conversion only — no suggestion dropdown. Use when you manage predictions yourself.

  • value / defaultValuecontrolled / uncontrolled
  • onChange(sinhala: string) → void
  • onPhoneticChange(raw: string) → void
  • className / inputClassNamestyle overrides
useSinhalaConverter
React Hook

Manages all phonetic ↔ Sinhala conversion state. Returns everything you need to build a fully custom input.

  • phoneticValuestring — raw typed input
  • sinhalaValuestring — converted output
  • currentWordSinhalastring — current word converted
  • handlePhoneticChange(raw) → void
  • replaceCurrentWord(word) → void
  • reset() → void
convertText / SinhalaPredictor
Core Utilities

Framework-agnostic functions. Use in any JavaScript/TypeScript environment.

  • convertText(input)string → string
  • new SinhalaPredictor(words?)custom dictionary
  • predictor.predict(prefix, max)→ WordSuggestion[]
  • predictor.addWords(words)extend dictionary
  • SINHALA_WORDSstring[] — built-in dictionary
Get started

Up and running
in minutes.

Three steps and you have a fully working Sinhala input in your React app.

1

Install the package

npm install @dnsam/sinhala-phonetics
2

Add Tailwind content path

// tailwind.config.js
content: [
  './node_modules/@dnsam/
   sinhala-phonetics/dist/**/*.js'
]
3

Use the component

import { SinhalaTypewriter }
  from '@dnsam/sinhala-phonetics';

<SinhalaTypewriter
  onChange={setText}
/>
View on npm →