hangul 0.3.0 copy "hangul: ^0.3.0" to clipboard
hangul: ^0.3.0 copied to clipboard

Work with korean hangul characters (한글). Validate characters, split syllables into jamo, merge jamos into syllables.

Hangul #

This package is an utility to manipulate korean hangul characters (한글) in dart.

Install #

$ dart pub add hangul

Getting Started #

The library is composed of 2 modules:

  • HangulSyllable: to validate and create hangul syllables from jamos and to destruct syllables into jamos.
  • HangulInput: to create hangul sentences from input string in order to emulate keyboard strokes.

HangulSyllable #

The basics of the library is to manipulate hangul syllables.

A hangul syllable is composed of 3 jamos:

  • A "cho" jamo that is the first consonant.
  • A "jung" jamo that is the vowel
  • An optional "jong" jamo that is the last consonant.

Note that "double" characters such as ᅯ, ㅉ or ㅄ are considered as jamos.

Split a syllable into 2 or 3 jamos #

HangulSyllable.fromString will split a given hangul syllable and return an instance of HangulSyllable.

It throws if the given string is not a valid syllable.

import 'package:hangul/hangul.dart';

final syllable = HangulSyllable.fromString('쪲');

syllable.cho == 'ㅉ'; // true
syllable.jung == 'ㅖ'; // true
syllable.jong == 'ㅄ'; // true

Assemble 2 or 3 jamos into a single syllable #

HangulSyllable constructor allows to instantiate a syllable from 3 valid jamos.

It throws if one of the given string is not a valid jamo (order for cho, jung and jong matters).

import 'package:hangul/hangul.dart';

final syllable = HangulSyllable('ㅉ', 'ㅖ', 'ㅄ');

syllable.tostring() == '쪲'; // true

The following will throw:

import 'package:hangul/hangul.dart';

HangulSyllable('ㅆ', 'a');

// thrown AssertionError with message "Invalid character provided for jung."

HangulInput #

The class HangulInput will simulate the behavior of keyboard strokes. The goal is to make it possible to implement virtual keyboards. It can also be used to combine a string of jamos together into a string of syllables.

import 'package:hangul/hangul.dart';

final input = HangulInput('');

input.pushCharacter('ㄷ');
input.pushCharacter('ㅏ');
input.pushCharacter('ㄹ');
input.pushCharacter('ㄱ');
input.pushCharacter('ㅇ');
input.pushCharacter('ㅡ');
input.pushCharacter('ㄴ');

print(input.text); // 닭은

input.backspace();
print(input.text); // 닭ㅇ

input.backspace();
input.backspace();
print(input.text); // 달

utilities #

import 'package:hangul/hangul.dart';

// check jamo
isValidJamo('ㄱ');  // true
isValidCho('ㄱ');  // true
isValidJung('ㅏ'); // true
isValidJong('ㄱ'); // true
isValidJong('ㅄ'); // true
isValidCho('ㅏ');  // false
isValidCho('ㅄ');  // false

// can also be used from character code
isValidJamoCode('ㄱ'.codeUnitAt(0));  // true
isValidChoCode('ㄱ'.codeUnitAt(0));  // true
isValidJungCode('ㅏ'.codeUnitAt(0)); // true
isValidJongCode('ㄱ'.codeUnitAt(0)); // true

// check syllable
isHangulSyllable('쪲');   // true
isHangulSyllable('쪲가'); // false
isHangulSyllable('ㄱ');   // false
isHangulSyllable('q');   // false

// can also be used from character code
isHangulSyllableCode('쪲'.codeUnitAt(0));   // true

// list of valid cho jung and jong are also exported:
final Set allJamos = {...choJamos, ...jungJamos, ...jongJamos};
9
likes
0
pub points
65%
popularity

Publisher

verified publishersouf.fr

Work with korean hangul characters (한글). Validate characters, split syllables into jamo, merge jamos into syllables.

Repository (GitLab)
View/report issues

License

unknown (LICENSE)

More

Packages that depend on hangul