Skip to content

Instantly share code, notes, and snippets.

@hi-ogawa
Last active February 28, 2023 10:39
Show Gist options
  • Save hi-ogawa/b925d9090d2fc3eba6e704783996884d to your computer and use it in GitHub Desktop.
Save hi-ogawa/b925d9090d2fc3eba6e704783996884d to your computer and use it in GitHub Desktop.
List hangul syllables
/*
$ node hangle-syllables.js
가 : ㄱ ㅏ
각 : ㄱ ㅏ ㄱ
갂 : ㄱ ㅏ ㄲ
갃 : ㄱ ㅏ ㄳ
간 : ㄱ ㅏ ㄴ
갅 : ㄱ ㅏ ㄵ
갆 : ㄱ ㅏ ㄶ
...
references
- https://en.wikipedia.org/wiki/Hangul_consonant_and_vowel_tables
*/
//
// jamo
//
// 0x3131 ... (30)
const CONSONANTS = [
'ㄱ', 'ㄲ', 'ㄳ', 'ㄴ', 'ㄵ', 'ㄶ', 'ㄷ',
'ㄸ', 'ㄹ', 'ㄺ', 'ㄻ', 'ㄼ', 'ㄽ', 'ㄾ',
'ㄿ', 'ㅀ', 'ㅁ', 'ㅂ', 'ㅃ', 'ㅄ', 'ㅅ',
'ㅆ', 'ㅇ', 'ㅈ', 'ㅉ', 'ㅊ', 'ㅋ', 'ㅌ',
'ㅍ', 'ㅎ'
]
const CONSONANTS_NON_INITIAL = ['ㄳ', 'ㄵ', 'ㄶ', 'ㄺ', 'ㄻ', 'ㄼ', 'ㄽ', 'ㄾ', 'ㄿ', 'ㅀ', 'ㅄ'];
const CONSONANTS_NON_FINAL = ['ㄸ', 'ㅃ', 'ㅉ'];
// 0x314f ... (21)
const VOWELS = [
'ㅏ', 'ㅐ', 'ㅑ', 'ㅒ', 'ㅓ',
'ㅔ', 'ㅕ', 'ㅖ', 'ㅗ', 'ㅘ', 'ㅙ', 'ㅚ',
'ㅛ', 'ㅜ', 'ㅝ', 'ㅞ', 'ㅟ', 'ㅠ', 'ㅡ',
'ㅢ', 'ㅣ'
]
//
// syllable
//
const INITIALS = CONSONANTS.filter(s => !CONSONANTS_NON_INITIAL.includes(s));
const MEDIALS = VOWELS;
const FINALS = ["", ...CONSONANTS.filter(s => !CONSONANTS_NON_FINAL.includes(s))];
const SYLLABLE_OFFSET = 0xac00;
let offset = SYLLABLE_OFFSET;
for (const i of INITIALS) {
for (const m of MEDIALS) {
for (const f of FINALS) {
const s = String.fromCodePoint(offset++);
console.log(s, ":", i, m, f);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment