kohangul

pub package Dart License: MIT

A consolidated Korean-text toolkit for Dart — particle (josa) selection, 초성 search, number-to-Hangul, jamo assemble/disassemble, and batchim detection, in one well-tested package.

Dart를 위한 한국어 텍스트 툴킷 — 조사 자동 선택, 초성 검색, 숫자-한글 변환, 자모 분해/조합, 받침 판별을 잘 테스트된 패키지 하나로.

English · 한국어

import 'package:kohangul/kohangul.dart';

josa('사과', '이/가');            // '사과가'   (no batchim → 가)
josa('수박', '이/가');            // '수박이'   (batchim → 이)
josa('서울', '으로/로');          // '서울로'   (ㄹ exception)

choseongIncludes('삼국지', 'ㅅㄱ'); // true      (초성 search)
sinoKorean(12345);               // '일만이천삼백사십오'
nativeKoreanCounter(20);         // '스무'      → '스무 살'
disassemble('값');               // 'ㄱㅏㅂㅅ'
assemble(['ㅇ', 'ㅏ', 'ㄴ', 'ㅈ', 'ㅏ']); // '안자'  (연음)
hasBatchim('강');                // true

English

Pure Dart, zero dependencies — works in Flutter, server, and CLI. Dart's Korean text helpers were scattered across small, half-maintained packages; kohangul consolidates the essentials, with tests for the edge cases that actually bite — the 으로/로 ㄹ exception, 스무 vs 스물 before a counter, 만/억 grouping in number readings, and 연음 when assembling jamo.

Install

dependencies:
  kohangul: ^0.1.0
import 'package:kohangul/kohangul.dart';

Josa (particles)

josa(word, pair) appends the correct particle; pickJosa(word, pair) returns just the particle.

josa('책', '을/를');        // '책을'   (batchim → 을)
josa('코', '을/를');        // '코를'   (no batchim → 를)
pickJosa('카페', '으로/로'); // '로'

It handles the 으로/로 family ㄹ-exception and falls back to the Korean reading of a trailing digit or Latin letter when the word doesn't end in Hangul:

josa('아이폰 7', '으로/로'); // '아이폰 7로'  (칠 → ㄹ)
josa('3', '이/가');         // '3이'         (삼 → ㅁ)

Supported pairs (see supportedJosa): 이/가, 을/를, 은/는, 와/과, 이나/나, 이란/란, 아/야, 이랑/랑, 이에요/예요, 이었/였, 이라/라, 이라서/라서, 이라고/라고, 이여/여, 으로/로, 으로서/로서, 으로써/로써, 으로부터/로부터. Order within a pair doesn't matter ('와/과' == '과/와').

getChoseong('한글 검색');          // 'ㅎㄱ ㄱㅅ'  (spaces kept)
choseongIncludes('스크린샷', '스크'); // true       (query may be jamo or words)
choseongIncludes('삼국지', 'ㅅㅈ');   // false

Number → Korean

sinoKorean(1234);          // '천이백삼십사'
sinoKorean(12345);         // '일만이천삼백사십오'
sinoKorean(0);             // '영'

nativeKorean(21);          // '스물하나'   (cardinal)
nativeKoreanCounter(20);   // '스무'       → '스무 살'
nativeKoreanCounter(21);   // '스물한'     → '스물한 명'

Disassemble / assemble

disassemble('읽었다');                 // 'ㅇㅣㄹㄱㅇㅓㅆㄷㅏ'
assemble([disassemble('읽었다')]);     // '읽었다'  (stable round-trip)
assemble(['ㅁ', 'ㅏ', 'ㄴ', 'ㅡ', 'ㄹ']); // '마늘'   (연음 relink)

Batchim & syllable math

hasBatchim('강');                          // true
hasBatchim('값', only: BatchimType.single); // false
getBatchim('값');                           // 'ㅄ'
decomposeSyllable('값');                    // ('ㄱ', 'ㅏ', 'ㅄ')
composeSyllable('ㄱ', 'ㅏ', 'ㅄ');           // '값'
isHangulSyllable('한');                     // true

한국어

순수 Dart, 의존성 0 — Flutter·서버·CLI 어디서나. Dart에 흩어져 있던 한국어 텍스트 처리를 kohangul 하나로 모았고, 실제로 자주 틀리는 엣지 케이스를 테스트로 보장합니다 — 으로/로 ㄹ 예외, 단위 앞 스무/스물, 숫자의 만/억 자릿수, 자모 조합 시 연음.

설치

dependencies:
  kohangul: ^0.1.0

조사

josa(단어, 쌍)은 알맞은 조사를 붙여 반환하고, pickJosa(단어, 쌍)은 조사만 반환합니다. 으로/로 계열의 ㄹ 예외와, 한글로 끝나지 않을 때 끝의 숫자·영문 읽음을 자동 처리합니다.

josa('수박', '이/가');      // '수박이'
josa('서울', '으로/로');    // '서울로'      (ㄹ 예외)
josa('아이폰 7', '으로/로'); // '아이폰 7로'  (칠 → ㄹ)

지원 쌍은 supportedJosa로 확인할 수 있고, 쌍 안의 순서는 무관합니다 ('와/과' == '과/와').

초성 검색

getChoseong('한글 검색');          // 'ㅎㄱ ㄱㅅ'  (공백 유지)
choseongIncludes('스크린샷', '스크'); // true       (자모/단어 모두 가능)

숫자 → 한글

sinoKorean(12345);         // '일만이천삼백사십오'  (한자어)
nativeKorean(21);          // '스물하나'           (고유어)
nativeKoreanCounter(20);   // '스무'               (단위 앞 관형형: 스무 살)

자모 분해 / 조합 · 받침

disassemble('값');                       // 'ㄱㅏㅂㅅ'
assemble(['ㅁ', 'ㅏ', 'ㄴ', 'ㅡ', 'ㄹ']);  // '마늘'  (연음)
hasBatchim('강');                        // true
getBatchim('값');                        // 'ㅄ'

Roadmap

  • romanize() — Revised Romanization with pronunciation rules (assimilation)
  • More josa pairs and standalone English-final handling

Issues and PRs welcome. 이슈와 PR 환영합니다.

License

MIT © 2026 idiotlabs

Libraries

kohangul
A consolidated Korean-text toolkit for Dart: josa (particle) selection, choseong (초성) search, jamo disassemble/assemble, and batchim detection.