nepalipi
Nepalipi Benchmark

सरल, स्पष्ट र शुद्ध नेपाली लेखन ।
Right in your browser.

On 4,092 benchmark inputs, Nepalipi matched the expected spelling on its first try 54.08% of the time, compared with 34.31% for Google Input Tools. Run or submit a benchmark.

npm install nepalipi

Keyboard shortcuts

Use 1–5 for Nepali, 6 for English, or ↑ ↓ and Space to choose. Esc keeps numbers literal. Type . for punctuation.

Custom spelling hints

Add Roman inputs and the Nepali spellings you want to see first.

Developer integration

Attach Nepalipi to a text input, search input, or textarea. Nepalipi handles typing shortcuts and applies the selected spelling. Your app supplies the suggestion UI.

Attach to a field

In your project, run npm install nepalipi, then add a field and attach Nepalipi from your JavaScript module.

HTML
<textarea id="message" aria-label="Message"></textarea>
Quick start · JavaScript
import { NepaliPi } from 'nepalipi';

const field = NepaliPi('#message', {
  hints: { pani: ['पानी', 'पनि'] }
});

// Type namaste and press Space to commit it.
// When the field is removed, call field.destroy().

Run the JavaScript after the textarea exists. The example transliterates on Space, and you can add a visible popup using the renderer example.

TypeScript, CommonJS, and direct browser imports

Use the npm import in TypeScript and add the types you need. The package includes its declarations.

TypeScript
import { NepaliPi, type NepaliPiOptions } from 'nepalipi';

const options: NepaliPiOptions = {
  numberShortcuts: true,
  hints: { pani: ['पानी', 'पनि'] }
};
const field = NepaliPi('#message', options);

CommonJS loading requires Node 22.12 or newer. Call NepaliPi() only where the browser DOM is available.

CommonJS
const { NepaliPi } = require('nepalipi');

To run without a bundler, copy the installed package’s entire dist/ folder to /vendor/nepalipi/ on your site. Keep its directory structure intact.

Browser HTML
<textarea id="message" aria-label="Message"></textarea>
<script type="module">
  import { NepaliPi } from '/vendor/nepalipi/index.js';
  NepaliPi('#message');
</script>
Render a custom suggestion popup

Give Nepalipi a separate container. It handles visibility and caret positioning. The renderer updates accessible attributes and wires up pointer selection.

HTML
<textarea id="message"></textarea>
<div id="suggestions" hidden></div>
JavaScript
import { NepaliPi } from 'nepalipi';

function applyAttributes(element, attributes) {
  for (const [name, value] of Object.entries(attributes)) {
    if (value === null) element.removeAttribute(name);
    else element.setAttribute(name, value);
  }
}

const field = NepaliPi('#message', {
  dropdown: {
    container: '#suggestions',
    position: 'caret',
    render(state, { container, controller }) {
      applyAttributes(controller.target, controller.getInputAttributes());
      applyAttributes(container, controller.getListAttributes());

      container.replaceChildren(...state.suggestions.map(suggestion => {
        const option = document.createElement('button');
        option.type = 'button';
        option.textContent = suggestion.label ?? suggestion.text;
        applyAttributes(option, controller.getOptionAttributes(suggestion.id));
        option.onpointerdown = event => event.preventDefault();
        option.onclick = () => controller.choose(suggestion.id);
        return option;
      }));
    }
  }
});

Use position: 'manual' if your app positions the popup. For fully custom rendering, subscribe with field.subscribe(listener), render from state.suggestions, and call the returned unsubscribe function on cleanup.

Configure hints, shortcuts, and errors
enabled and numberShortcuts
Both default to true. Set numberShortcuts: false if the field needs literal digits.
hints and setHints(hints)
Map each Roman key to one spelling or an ordered list. Hints apply to this field only and appear ahead of engine suggestions. Calling setHints() with a map replaces the previous map. Pass {} to clear it.
onError(error, info)
Handle failures in dropdown renderers and subscribers after setup. The callback receives the error, a code, and the target field.
Read state and manage the field lifecycle
getState() and subscribe(listener)
Read suggestions, activeId, open, and mode. The mode identifies a word or punctuation menu. Each suggestion has an ID, text, shortcut number, and kind.
choose(id) and highlight(id)
Use IDs from the current state. Choose from a keyboard or pointer handler so the controller can apply the selection.
open(), dismiss(), and getCaretRect()
Open or close the suggestions, or read the caret position when positioning your own popup.
update(options) and NepaliPi.get(target)
Update a controller or look up one already attached to the field. Attach only once per element.
destroy()
Detach when the field is removed. In frameworks, attach after mount and destroy before unmount.
Subscribe and clean up
const unsubscribe = field.subscribe(state => {
  console.log(state.mode, state.suggestions);
});

// Call both when the component is removed.
unsubscribe();
field.destroy();
View list markup
<ul role="listbox">
  <li>
    <button role="option">
      <strong>नमस्ते</strong>
      <kbd>१</kbd>
    </button>
  </li>
</ul>