सरल, स्पष्ट र शुद्ध नेपाली लेखन ।
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
Nepali suggestions couldn’t start. You can still type or reload to try again.
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.
<textarea id="message" aria-label="Message"></textarea>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.
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.
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.
<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.
<textarea id="message"></textarea>
<div id="suggestions" hidden></div>
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
enabledandnumberShortcuts- Both default to
true. SetnumberShortcuts: falseif the field needs literal digits. hintsandsetHints(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()andsubscribe(listener)- Read
suggestions,activeId,open, andmode. The mode identifies a word or punctuation menu. Each suggestion has an ID, text, shortcut number, and kind. choose(id)andhighlight(id)- Use IDs from the current state. Choose from a keyboard or pointer handler so the controller can apply the selection.
open(),dismiss(), andgetCaretRect()- Open or close the suggestions, or read the caret position when positioning your own popup.
update(options)andNepaliPi.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.
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>