npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

dhivehi-input

v1.1.1

Published

Modern Dhivehi/Thaana input system for JavaScript and Vue.js applications

Readme

Dhivehi Input

npm version License: MIT

A modern, lightweight JavaScript library for enabling Dhivehi/Thaana text input in web applications. Automatically converts English keyboard input to Dhivehi characters in real-time.

✨ Features

  • 🚀 Easy to use: Just add dhivehi-input class to any input element
  • ⌨️ Multiple keyboard layouts: Phonetic, Phonetic Hassan Hameed, Typewriter
  • 🔧 Vue.js integration: Composable and directive support
  • 📦 Standalone: Works without frameworks
  • 🔄 Automatic RTL: Sets right-to-left direction automatically
  • 👀 Dynamic detection: Automatically detects new elements added to DOM
  • 🎯 Modern ES6+: Clean, maintainable code
  • 📱 Zero dependencies: Pure JavaScript implementation
  • 💡 TypeScript support: Full type definitions included

📦 Installation

npm install dhivehi-input

Or with yarn:

yarn add dhivehi-input

Or use via CDN:

<script src="https://unpkg.com/dhivehi-input/lib/standalone.umd.min.js"></script>

🚀 Quick Start

Method 1: Simple Class-Based Usage (Recommended)

The simplest way to add Dhivehi input to any element:

<input type="text" class="dhivehi-input" placeholder="ލިޔުއްވާ">

That's it! The input will automatically convert English typing to Dhivehi characters.

Method 2: Custom Keyboard Layout

<input type="text" class="dhivehi-input" data-dhivehi-keyboard="phonetic-hh">
<input type="text" class="dhivehi-input" data-dhivehi-keyboard="typewriter">

Method 3: Programmatic Usage

import DhivehiInput from 'dhivehi-input';

// Create instance
const dhivehi = new DhivehiInput({
    keyboard: 'phonetic',
    className: 'my-dhivehi-input'
});

// Setup specific element
dhivehi.setupElement(document.getElementById('my-input'));

🔧 Vue.js Integration

Plugin Installation

import { createApp } from 'vue';
import DhivehiInputPlugin from 'dhivehi-input/vue';

const app = createApp({});
app.use(DhivehiInputPlugin);

Using the Directive

<template>
  <!-- Simple usage -->
  <input v-dhivehi-input type="text">
  
  <!-- With custom keyboard -->
  <input v-dhivehi-input="'phonetic-hh'" type="text">
  
  <!-- With options -->
  <input v-dhivehi-input="{ keyboard: 'typewriter', enabled: true }" type="text">
</template>

Using the Composable

<script setup>
import { useDhivehiInput } from 'dhivehi-input/vue';

const { translateChar, setupElement, keyboards } = useDhivehiInput();

// Translate individual characters
const dhivehiChar = translateChar('a'); // Returns 'އ'

// Get available keyboards
console.log(Object.keys(keyboards.value)); // ['phonetic', 'phonetic-hh', 'typewriter']
</script>

⌨️ Keyboard Layouts

Phonetic (Default)

  • ID: phonetic
  • Description: Most popular layout, maps English letters to similar sounding Dhivehi letters
  • Example: aއ, sސ, dދ

Phonetic Hassan Hameed

  • ID: phonetic-hh
  • Description: Alternative phonetic layout with different mappings for certain characters
  • Example: Similar to phonetic but with variations for alifu, sukun, etc.

Typewriter

  • ID: typewriter
  • Description: Traditional typewriter layout used in government offices
  • Example: Based on physical Dhivehi typewriter key positions

📖 API Reference

Core Functions

import { translateChar, insertTextAtCursor, DhivehiInput } from 'dhivehi-input';

// Translate single character
const translated = translateChar('a', 'phonetic'); // 'އ'

// Insert text at cursor
insertTextAtCursor(inputElement, 'ޖޮއްލާ');

// Create instance
const dhivehi = new DhivehiInput(options);

Configuration Options

const config = {
    keyboard: 'phonetic',           // Default keyboard layout
    className: 'dhivehi-input',     // CSS class to detect
    activeClassName: 'dhivehi-input-active', // Applied to active elements
    enableRtl: true,                // Enable RTL styling
    autoInit: true                  // Auto-initialize on creation
};

Instance Methods

const dhivehi = new DhivehiInput();

// Setup/remove elements
dhivehi.setupElement(element);
dhivehi.removeElement(element);

// Control observation
dhivehi.startObserver();
dhivehi.stopObserver();

// Keyboard management
dhivehi.setKeyboard(element, 'phonetic-hh');
dhivehi.getKeyboards(); // ['phonetic', 'phonetic-hh', 'typewriter']

// Cleanup
dhivehi.destroy();

🎨 Styling

The library automatically applies appropriate RTL styling. You can customize the appearance:

.dhivehi-input {
    font-family: 'MV Boli', 'Faruma', Thaana, Arabic, sans-serif;
    direction: rtl;
    text-align: right;
}

.dhivehi-input-active:focus {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    border-color: #3b82f6;
}

🌐 Browser Support

  • Chrome 60+
  • Firefox 55+
  • Safari 12+
  • Edge 79+
  • IE 11+ (with polyfills)

📱 Supported Elements

Works with:

  • <input type="text">
  • <input type="search">
  • <input type="url">
  • <input type="tel">
  • <input type="password">
  • <textarea>
  • Any element with contenteditable="true"

🔍 Advanced Usage

Multiple Instances

// Different configurations for different sections
const adminDhivehi = new DhivehiInput({
    className: 'admin-dhivehi',
    keyboard: 'typewriter'
});

const userDhivehi = new DhivehiInput({
    className: 'user-dhivehi', 
    keyboard: 'phonetic'
});

Custom Event Handling

// Listen for Dhivehi input events
document.addEventListener('dhivehi:input', (event) => {
    console.log(`Typed: ${event.detail.originalChar} → ${event.detail.translatedChar}`);
});

// Listen for setup events
document.addEventListener('dhivehi:setup', (event) => {
    console.log(`Element setup with keyboard: ${event.detail.keyboard}`);
});

Dynamic Keyboard Switching

const dhivehi = new DhivehiInput();

// Switch keyboard for specific element
dhivehi.setKeyboard(inputElement, 'phonetic-hh');

// Or via data attribute
inputElement.dataset.dhivehiKeyboard = 'typewriter';

🛠️ Development

# Clone the repository
git clone https://github.com/yourusername/dhivehi-input.git
cd dhivehi-input

# Install dependencies
npm install

# Build the library
npm run build

# Build and watch for changes
npm run dev

# Format code
npm run format

# Lint code
npm run lint

📄 Examples

Check out the examples/ directory for complete implementation examples:

  • Basic HTML usage
  • Vue.js integration
  • React integration (coming soon)
  • Advanced customization

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

📞 Support

If you have any questions or need help integrating this library, please:

  1. Check the documentation
  2. Search existing issues
  3. Create a new issue

Made with ❤️ for the Maldivian developer community