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)
npm i anvim
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("toi yeu Vieejt Nam")); // "tôi yêu Việt Nam"
console.log(anvim("gox tieengs vieetj thaatj down gianr")); // "gõ tiếng việt thật đơn giản"
console.log(anvim("hocj")); // "học"
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"
// 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