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

thai-typing-validator

v1.0.0

Published

Validate Thai text input according to proper Thai typing rules - prevents invalid vowel and tone mark combinations

Readme

thai-typing-validator

A JavaScript/TypeScript library to validate Thai text input according to proper Thai typing rules. Prevents invalid combinations of vowels and tone marks.

Why This Package?

Thai script has specific rules about how vowel marks and tone marks can be combined. This library ensures that text input follows these rules:

  1. Lower vowels (ุ ู) cannot appear consecutively in the same character group
  2. Base upper vowels (ิ ี ึ) can have one additional mark stacked on top, but cannot stack another ิ ี ึ
  3. Other upper marks can only appear once per character

Perfect for Thai text inputs, content editors, and form validation!

Installation

npm install thai-typing-validator

Usage

Basic Validation (Real-time Input)

const { validateInput } = require('thai-typing-validator');

let currentText = 'ก';

// Try to add ุ
const result1 = validateInput('ุ', currentText);
console.log(result1); // { valid: true, message: '' }
currentText += 'ุ';

// Try to add another ุ (should fail)
const result2 = validateInput('ุ', currentText);
console.log(result2); 
// { valid: false, message: 'Lower vowels (ุ ู) cannot be typed consecutively...' }

HTML Input Integration

const { validateInput } = require('thai-typing-validator');

const input = document.getElementById('thaiInput');
let validText = '';

input.addEventListener('input', (e) => {
  const newValue = e.target.value;
  
  if (newValue.length > validText.length) {
    const newChar = newValue[newValue.length - 1];
    const validation = validateInput(newChar, validText);
    
    if (!validation.valid) {
      e.target.value = validText; // Reject invalid input
      alert(validation.message);
      return;
    }
  }
  
  validText = newValue;
});

Validate Entire Text

const { validateText } = require('thai-typing-validator');

const result = validateText('กุุ'); 
console.log(result);
// {
//   valid: false,
//   errors: [{
//     position: 2,
//     character: 'ุ',
//     message: 'Lower vowels (ุ ู) cannot be typed consecutively...'
//   }]
// }

Sanitize Text

const { sanitizeText } = require('thai-typing-validator');

const clean = sanitizeText('กุุ้');
console.log(clean); // 'กุ้' (removes the invalid second ุ)

TypeScript

import { validateInput, ValidationResult } from 'thai-typing-validator';

const result: ValidationResult = validateInput('ุ', 'ก');
if (!result.valid) {
  console.error(result.message);
}

API Reference

validateInput(newChar: string, currentText: string): ValidationResult

Validates if a new character can be added to the current text.

Returns:

{
  valid: boolean;
  message: string; // Error message if invalid
}

validateText(text: string): TextValidationResult

Validates entire text and returns all errors found.

Returns:

{
  valid: boolean;
  errors: Array<{
    position: number;
    character: string;
    message: string;
  }>;
}

sanitizeText(text: string): string

Removes invalid characters from text according to Thai typing rules.

getLastCharGroup(text: string): string

Gets the last character group (base character + all marks).

isThaiVowelMark(char: string): boolean

Checks if a character is a Thai vowel mark.

isToneMark(char: string): boolean

Checks if a character is a Thai tone mark.

categories

Exports character categories for advanced usage:

  • lowerVowels: ['ุ', 'ู']
  • upperVowels: ['ิ', 'ี', 'ึ', 'ื', 'ั', '็']
  • toneMarks: ['่', '้', '๊', '๋']
  • specialMarks: ['์']
  • baseUpperVowels: ['ิ', 'ี', 'ึ']
  • allUpperMarks: All upper marks combined

Thai Typing Rules

This library enforces the following Thai typing rules:

  1. No consecutive lower vowels: Characters like ุ and ู cannot appear twice in the same character group (e.g., กุุ is invalid)

  2. Stacking rules for ิ ี ึ: These base upper vowels can have one additional mark on top (like tone marks), but you cannot stack another ิ ี or ึ on them

  3. One upper mark per character: For characters without base upper vowels (ิ ี ึ), only one upper mark is allowed

Examples

Valid:

  • กุ (consonant + lower vowel)
  • กิ้ (consonant + base upper vowel + tone mark)
  • กู่ (consonant + lower vowel + tone mark)

Invalid:

  • กุุ (consecutive lower vowels)
  • กิิ (stacking ิ on ิ)
  • กั้่ (two upper marks without base upper vowel)

Browser Support

Works in all modern browsers and Node.js 12+.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT

Author

Sorracha Aiemmeesri


Made with ❤️ for the Thai language community