anvim
v0.1.2
Published
ANVIM - A New Vietnamese Input Method (AVIM-compatible Vietnamese input engine in TypeScript)
Maintainers
Readme
anvim
ANVIM - A New Vietnamese Input Method
A modern TypeScript evolution of AVIM (A Vietnamese Input Method), maintaining full compatibility while adding improvements and type safety.
src/anvim.ts: TypeScript port (ANVIM)legacy/avim.js: Original AVIM JavaScript by Hieu Tran Dang (header retained)
Install
npm i anvimUsage
Basic Usage
The simplest way to convert Vietnamese text is using the default anvim function:
import anvim from "anvim";
// TELEX input method (default)
console.log(anvim("xin chaof")); // "xin chào"
console.log(anvim("tooi laf sinh vien"));// "tôi là sinh viên"
console.log(anvim("Vieejt Nam")); // "Việt Nam"
console.log(anvim("ddepj")); // "đẹp"
console.log(anvim("hocj")); // "học"Advanced Usage with AnvimEngine
For more control, use the AnvimEngine class:
import { AnvimEngine } from "anvim";
const engine = new AnvimEngine();
// Real-time typing simulation
let result = "";
for (const char of "thuowng") {
result = engine.processWithKey(result, char);
console.log(`Typed '${char}': ${result}`);
}
// Output: "thương"
// Process entire words
console.log(engine.processWord("tooi")); // "tôi"
console.log(engine.processWord("chaof")); // "chào"Input Methods
// Different input methods
engine.setMethodByString("TELEX"); // tooi → tôi
engine.setMethodByString("VNI"); // to5i → tôi
engine.setMethodByString("VIQR"); // to^'i → tối
engine.setMethodByString("AUTO"); // auto-detect