rusty_hangul
Hangul string processing in Rust — syllable disassembly, choseong extraction, batchim/josa selection, and jamo assembly — with Node.js and WebAssembly bindings.
Features
- Disassemble Hangul syllables into jamo (NFC and NFD), including grouped output
- Iterate syllables and inspect choseong / jungseong / jongseong
- Extract choseong (initial consonants), leaving non-Hangul characters as-is
- Search text by choseong or progressive syllable prefixes
- Detect batchim (final consonants) and select a matching josa (or the particle alone)
- Assemble jamo back into syllables
Packages
This repository is a Cargo and bun workspace. Tagged releases are on the Releases page.
| Path | Package name | Role |
|---|---|---|
core/ |
rusty_hangul (imported as hangul) |
Rust crate |
node/ |
node |
Node.js native addon via napi-rs |
wasm/ |
wasm (hangul-wasm) |
WebAssembly bindings via wasm-bindgen |
A browser demo lives in examples/browser-basic.
Installation
You need a Rust toolchain. Node.js and WebAssembly bindings also need bun (>= 1.3.3). Node.js bindings require Node >= 20. WebAssembly builds also need wasm-pack.
Rust
The crates.io package is rusty_hangul. In Rust the crate is still hangul, so examples use use hangul::.... The name hangul is already taken on crates.io.
From crates.io:
[]
= "0.1.1"
From a git tag:
[]
= { = "https://github.com/geon2419/rusty_hangul", = "v0.1.1" }
From a local clone, point at core/:
[]
= { = "path/to/rusty_hangul/core" }
Node.js and WebAssembly
Clone this repository at the release tag, then build the binding you need.
# or
import { Hangul, assemble } from "node";
That import works for other packages in this bun workspace. Outside the workspace, point at ./node after a local build.
import init, { disassemble, getChoseong } from "./wasm/pkg/hangul";
await init();
Adjust the WASM import path to match your app. See examples/browser-basic for a Vite setup.
Rust example
use ;
let text = new;
assert_eq!;
assert_eq!;
assert_eq!;
assert!;
assert_eq!;
assert_eq!;
assert!;
let mixed = new;
assert_eq!;
let nfd = new; // 간
assert_eq!;
assert_eq!;
assert!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Node.js example
import { Hangul, assemble } from "node";
const text = new Hangul("안녕하세요");
console.log(text.disassemble()); // "ㅇㅏㄴㄴㅕㅇㅎㅏㅅㅔㅇㅛ"
console.log(text.disassembleToGroups());
// [["ㅇ", "ㅏ", "ㄴ"], ["ㄴ", "ㅕ", "ㅇ"], ["ㅎ", "ㅏ"], ["ㅅ", "ㅔ"], ["ㅇ", "ㅛ"]]
console.log(text.getChoseong()); // "ㅇㄴㅎㅅㅇ"
console.log(text.containsChoseong("ㅇㄴㅎ")); // true
console.log(text.findChoseong("ㅎㅅ")); // { start: 2, end: 4, byteStart, byteEnd }
console.log(text.length); // 5
console.log(text.get(0)); // { original: "안", isHangul: true, choseong: "ㅇ", jungseong: "ㅏ", jongseong: "ㄴ" }
const mixed = new Hangul("Hello 안녕!");
console.log(mixed.getChoseong()); // "Hello ㅇㄴ!"
console.log(new Hangul("한").hasBatchim()); // true
console.log(new Hangul("사과").josa("을/를")); // "사과를"
console.log(new Hangul("수박").josa("아/야")); // "수박아"
console.log(new Hangul("사과").josaParticle("을/를")); // "를"
console.log(assemble("ㄱㅏㅂㅅ")); // "값"
console.log(assemble("ㄱㅏㄱㅅㅏ", "compound-final")); // "갃ㅏ"
WebAssembly example
WASM exposes free functions, not a Hangul class.
import init, {
assemble,
disassemble,
disassembleToGroups,
getChoseong,
hasBatchim,
josa,
josaParticle,
unitAt,
containsChoseong,
findChoseong,
} from "./wasm/pkg/hangul";
await init();
console.log(disassemble("안녕하세요")); // "ㅇㅏㄴㄴㅕㅇㅎㅏㅅㅔㅇㅛ"
console.log(disassembleToGroups("값")); // [["ㄱ", "ㅏ", "ㅂ", "ㅅ"]]
console.log(getChoseong("Hello 안녕!")); // "Hello ㅇㄴ!"
console.log(containsChoseong("한글", "ㅎㄱ")); // true
console.log(findChoseong("한글", "한ㄱ")); // { start: 0, end: 2, ... }
console.log(hasBatchim("한")); // true
console.log(josa("사과", "을/를")); // "사과를"
console.log(josaParticle("사과", "을/를")); // "를"
console.log(unitAt("가A", 1)); // { original: "A", isHangul: false, ... }
console.log(assemble("ㄱㅏㅂㅅ")); // "값"
For AI coding agents
See llms.txt for a short API overview.