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-keyboard-corrector

v1.0.1

Published

Corrects text typed with the wrong Thai/English keyboard layout

Downloads

18

Readme

Thai Keyboard Corrector — TypeScript Edition

Fixes text typed with the wrong layout between Thai Kedmanee 🆚 English QWERTY.

Install

npm install thai-keyboard-corrector      # or -ts if name taken

Quick Use

import { correct } from "thai-keyboard-corrector";

// Clear cases (≥70% of one script)
console.log(correct("l;ylfu")); // สวัสดี
console.log(correct("ฟหกด")); // asdf
console.log(correct("hello world")); // ้ำสสน ไนพสก

// Unclear cases (<70% threshold, left unchanged)
console.log(correct("hello สวัสดี")); // hello สวัสดี (unchanged)
console.log(correct("สวัสดี hello")); // สวัสดี hello (unchanged)

Browser

<script src="https://cdn.jsdelivr.net/npm/thai-keyboard-corrector@latest/dist/thai-keyboard-corrector.js"></script>
<script>
  console.log(ThaiKeyboardCorrector.correct("l;ylfu")); // สวัสดี
</script>

API

| function | purpose | example | | ------------------- | ------------------------ | -------------------------- | | mapEngToThai(str) | Raw EN→TH character map | mapEngToThai("asdf")"ฟหกด" | | mapThaiToEng(str) | Raw TH→EN character map | mapThaiToEng("ฟหกด")"asdf" | | correct(str) | Smart auto-correction | correct("l;ylfu")"สวัสดี" |

Note: mapThaiToEng() handles both base and shift layers, mapping Thai shifted characters to uppercase English.

How It Works

The correct() function uses a 70% threshold to determine layout:

  • ≥70% Latin characters → Maps entire string to Thai
  • ≥70% Thai characters → Maps entire string to English
  • <70% of either script → Leaves unchanged (unclear ratio)

Keyboard Mapping

The library maps characters based on the Thai Kedmanee keyboard layout:

  • Base layer: English QWERTY → Thai characters (e.g., q, w)
  • Shift layer: Thai shifted characters → Uppercase English (e.g., W, E)
  • Numbers: Thai numerals → Arabic numerals (e.g., 1, 2)
  • Symbols: Preserved as-is

Examples & Test Cases

Clear Cases (Always Swapped)

// 100% Latin → Thai
correct("l;ylfu")        // สวัสดี
correct("asdf")          // ฟหกด
correct("hello world")   // ้ำสสน ไนพสก
correct("qwerty")        // ๆไำพะั
correct("test123")       // ะำหะ123
correct("HELLO")         // ้ำสสน

// 100% Thai → English
correct("ฟหกด")          // asdf
correct("สวัสดี")        // l;ylfu
correct("ประเทศไทย")      // xitgmlwmp
correct("ครับ")          // คiy[
correct("๑๒๓๔๕")         // 12345
correct("ฃฅฆฑ")          // WERT (shifted characters)

Unclear Cases (Left Unchanged)

// Mixed content with unclear ratio
correct("hello สวัสดี")   // hello สวัสดี (50/50 split)
correct("สวัสดี hello")   // สวัสดี hello (50/50 split)
correct("hi สวัสดี")      // hi l;ylfu (25/75 split, Thai ≥70%)
correct("สวัสดี hi")      // l;ylfu hi (75/25 split, Thai ≥70%)

Edge Cases

// No script characters
correct("123456")        // 123456 (unchanged)
correct("!@#$%")         // !@#$% (unchanged)
correct("")              // "" (unchanged)
correct("   ")           // "   " (unchanged)

// Numbers and symbols are preserved
correct("test123")       // ะสสะ123
correct("hello!")        // ้ำสสน!

Use Cases

1. Chat Applications

// User types with wrong layout
const userInput = "l;ylfu";
const corrected = correct(userInput); // "สวัสดี"

2. Form Validation

// Check if input needs correction
const needsCorrection = correct(input) !== input;

3. Real-time Text Processing

// Process text as user types
const processedText = correct(rawInput);

4. Data Cleaning

// Clean mixed keyboard layouts in datasets
const cleaned = correct("hello สวัสดี"); // "hello สวัสดี" (preserved)

License

MIT