hangul.dev
A developer toolkit for Hangul processing, encoding, jamo decomposition, and romanization β engineered for the terminal, written for humans.
$ install
Install via your favorite package manager. Works in Node 18+, Deno, Bun, and the browser.
# npm
npm install @hangul/core
# pnpm
pnpm add @hangul/core
# deno
deno add jsr:@hangul/core
import { decompose, compose } from "@hangul/core";
const jamo = decompose("νκΈ");
// β ["γ
","γ
","γ΄","γ±","γ
‘","γΉ"]
const word = compose(["γ
","γ
","γ΄"]);
// β "ν"
interactive_demo()
Click a syllable to decompose it. Click again to recompose. Each jamo is colored by its role: μ΄μ± Β· μ€μ± Β· μ’ μ±.
jamo()
Low-level access to the 24 base jamo and their composition rules. Map any syllable to its underlying components.
export function decompose(syllable: string): Jamo[] {
const code = syllable.charCodeAt(0) - 0xAC00;
const cho = Math.floor(code / 588);
const jung = Math.floor((code % 588) / 28);
const jong = code % 28;
return [CHO[cho], JUNG[jung], JONG[jong]].filter(Boolean);
}
encode()
Convert between Unicode codepoints, KS X 1001, EUC-KR, and UTF-8 representations of any Hangul string.
$ hangul encode "νκΈ" --to=utf8
β ED 95 9C EA B8 80
$ hangul encode "νκΈ" --to=euc-kr
β C7 D1 B1 DB
$ hangul encode "νκΈ" --to=codepoint
β U+D55C U+AE00
romanize()
Romanize Hangul text using the Revised Romanization, McCune-Reischauer, or Yale systems. Pluggable per-call.
import { romanize } from "@hangul/core";
romanize("μλ
νμΈμ");
// β "annyeonghaseyo" (revised)
romanize("μλ
νμΈμ", { system: "mr" });
// β "annyΕnghaseyo" (mccune-reischauer)
romanize("νκΈ", { system: "yale" });
// β "hankul"
syllable_blocks
Hangul is composed by stacking jamo into rectangular syllable blocks. Each block contains a μ΄μ± (initial), μ€μ± (medial vowel), and an optional μ’ μ± (final).
γ
+ γ
+ γ΄
β
γ
γ
γ΄
han
γ± + γ
‘ + γΉ
β
γ±γ
‘γΉ
geul
γ΄ + γ
β
γ΄γ
na
γ
+ γ
+ γ
β
γ
γ
γ
bom
choseong_search()
Korean speakers search by initial consonants alone. Type γ±γ΄ and match γ±μ΄γ΄μ΄, γ±μ¬μΈγ΄, γ±λ‘γ΄ β a powerful UX for Korean autocomplete.
import { choMatch } from "@hangul/core";
choMatch("γ±γ΄", ["κ°λ¨", "κ΄λ루", "μ’
λ‘"]);
// β ["κ°λ¨", "κ΄λ루"]
choMatch("γ
γ±", ["νκΈ", "νΈμ"]);
// β ["νκΈ"]
$ playground
Type any Hangul string. Watch it decompose live, with each jamo color-coded by its role.