@oiyonet/hangul-math
v1.0.0
Published
Zero-dependency, pure mathematical Korean Hangul Unicode engine: Choseong/Jungseong/Jongseong decomposition, automatic Josa attacher, official Revised Romanization, and Hangul search MCP.
Maintainers
Readme
@oiyonet/hangul-math
Zero-dependency, pure mathematical Korean Hangul Unicode engine: Choseong/Jungseong/Jongseong decomposition, automatic Josa attacher with Rieul (
ㄹ) exception handling, official Revised Romanization, and Hangul search MCP server.
Why @oiyonet/hangul-math?
When AI agents generate Korean text or build Korean search features, they consistently make grammatical postposition mistakes (홍길동를, 사과이) or struggle with initial consonant indexing (초성 검색).
Existing packages are often unmaintained, bundle massive dictionary assets, or fail in modern Edge/Cloudflare/Bun environments.
@oiyonet/hangul-math provides:
- 100% Zero-Dependency: Ultra-lightweight (<6KB), runs purely on Unicode math (
(code - 0xAC00)offset arithmetic). - Universal Runtime: Works in Node.js, Browsers, Cloudflare Workers, Edge runtimes, Bun, and Deno.
- Flawless Josa Attacher: Handles regular batchim, numbers (
101->101은), and grammatical exceptions like the Rieul (ㄹ) rule for으로/로(서울+로=서울로,부산+으로=부산으로). - Official Romanization: Implements the official Revised Romanization of Korean (국어의 로마자 표기법 - 문화체육관광부 고시 제2014-42호).
- Dual MCP & CLI: Ready-to-use MCP tools for AI coding agents (
hangul-mcp) and terminal CLI (hangul-math).
1. Quick Start (CLI)
# 1. Automatic Postposition (조사) attachment
npx @oiyonet/hangul-math josa "홍길동" "은/는" # => 홍길동은
npx @oiyonet/hangul-math josa "사과" "을/를" # => 사과를
npx @oiyonet/hangul-math josa "서울" "으로/로" # => 서울로 (ㄹ 받침 특례!)
npx @oiyonet/hangul-math josa "부산" "으로/로" # => 부산으로
# 2. Extract Choseong (초성)
npx @oiyonet/hangul-math choseong "인공지능 에이전트" # => ㅇㄱㅈㄴ ㅇㅇㅈㅌ
# 3. Choseong Search Matching
npx @oiyonet/hangul-math match "서울특별시 종로구" "ㅅㅇ" # => true
# 4. Official Revised Romanization
npx @oiyonet/hangul-math romanize "독도" # => Dokdo
npx @oiyonet/hangul-math romanize "부산 해운대" # => Busan Haeundae2. MCP Server Configuration
Add hangul-mcp to your agent configuration (~/.claude/settings.json, Cursor MCP settings, or Antigravity config):
{
"mcpServers": {
"hangul": {
"command": "npx",
"args": ["-y", "@oiyonet/hangul-math"]
}
}
}Available MCP Tools:
attach_josa- Attaches the grammatically correct Korean postposition (
은/는,이/가,을/를,과/와,으로/로,아/야,이어/여,이란/란).
- Attaches the grammatically correct Korean postposition (
extract_choseong- Extracts initial consonants from text for search index generation.
match_choseong_search- Checks if a search query matches target text using choseong search.
romanize_korean- Converts Korean names, places, and terms into official Revised Romanization.
dissect_syllable- Returns initial, vowel, and final consonants (
choseong,jungseong,jongseong,hasBatchim) with Unicode offset indices.
- Returns initial, vowel, and final consonants (
3. Programmatic Usage (Node.js / TypeScript)
import {
josa,
hasBatchim,
extractChoseong,
matchChoseong,
romanize,
dissect,
} from '@oiyonet/hangul-math';
// 1. Grammatical Postpositions
console.log(josa('사용자', '이/가')); // "사용자가"
console.log(josa('선생님', '이/가')); // "선생님이"
console.log(josa('글로벌', '으로/로')); // "글로벌로" (ㄹ 받침)
// 2. Choseong Fuzzy Search
const contacts = ['강남역', '서울역', '홍대입구'];
const query = 'ㅅㅇ';
const filtered = contacts.filter((c) => matchChoseong(c, query));
console.log(filtered); // ['서울역']
// 3. Official Romanization
console.log(romanize('한글')); // "Hangeul"
console.log(romanize('종로')); // "Jongno"
// 4. Character Dissection
console.log(dissect('한'));
// { char: '한', isHangul: true, choseong: 'ㅎ', jungseong: 'ㅏ', jongseong: 'ㄴ', hasBatchim: true, lIndex: 18, vIndex: 0, tIndex: 4 }Mathematical Specification
Hangul syllables are mapped via the Unicode standard formula:
SIndex = CodePoint - 0xAC00
LIndex = floor(SIndex / (21 * 28)) // Choseong (19)
VIndex = floor((SIndex % 588) / 28) // Jungseong (21)
TIndex = SIndex % 28 // Jongseong (28)- Total possible syllables: $19 \times 21 \times 28 = 11,172$ combinations.
License
MIT © OIYO Lab
