[참조] https://tk2rush90.blog.me/221085154547
[참조] http://blog.naver.com/PostView.nhn?blogId=azure0777&logNo=221414175631&categoryNo=0&parentCategoryNo=0&viewDate=¤tPage=1&postListTopCurrentPage=1&from=postView&userTopListOpen=true&userTopListCount=5&userTopListManageOpen=false&userTopListCurrentPage=1
- 자음 유니코드
let uni = 12593; // 유니코드를 문자로 변환하는 함수 12593~12622
String.fromCharCode();
while(uni) {
let kor = String.fromCharCode(uni);
console.log("kor : " + kor + " - uni);
if(kor === "ㅎ") break;
uni++;
}
- 모음 유니코드 : 12623 ~ 12643
- 문자 내에서 초성, 중성, 종성으로 쓰이는 자모음은 위 표와 같으며, 종성은 숫자 1마다, 중성은 29마다, 초성은 589마다 값이 변한다는 사실을 알 수 있다. 이 내용을 토대로 한글 문자를 분리하는 기능을 만들어보자.
- 한글 문자 분리
function getConstantVowel(kor) {
const f = ['ㄱ', 'ㄲ', 'ㄴ', 'ㄷ', 'ㄸ', 'ㄹ', 'ㅁ',
'ㅂ', 'ㅃ', 'ㅅ', 'ㅆ', 'ㅇ', 'ㅈ', 'ㅉ',
'ㅊ', 'ㅋ', 'ㅌ', 'ㅍ', 'ㅎ'];
const s = ['ㅏ', 'ㅐ', 'ㅑ', 'ㅒ', 'ㅓ', 'ㅔ', 'ㅕ',
'ㅖ', 'ㅗ', 'ㅘ', 'ㅙ', 'ㅚ', 'ㅛ', 'ㅜ',
'ㅝ', 'ㅞ', 'ㅟ', 'ㅠ', 'ㅡ', 'ㅢ', 'ㅣ'];
const t = ['', 'ㄱ', 'ㄲ', 'ㄳ', 'ㄴ', 'ㄵ', 'ㄶ',
'ㄷ', 'ㄹ', 'ㄺ', 'ㄻ', 'ㄼ', 'ㄽ', 'ㄾ',
'ㄿ', 'ㅀ', 'ㅁ', 'ㅂ', 'ㅄ', 'ㅅ', 'ㅆ',
'ㅇ', 'ㅈ', 'ㅊ', 'ㅋ', 'ㅌ', 'ㅍ', 'ㅎ'];
const ga = 44032;
let uni = kor.charCodeAt(0);
uni = uni - ga;
let fn = parseInt(uni / 588);
let sn = parseInt((uni - (fn * 588)) / 28);
let tn = parseInt(uni % 28);
return {
f: f[fn],
s: s[sn],
t: t[tn]
};
}
- 받침 유무 ( ~가/이 구분용 )
function checkBatchimEnding(word) {
if (typeof word !== 'string') return null;
var lastLetter = word[word.length - 1];
var uni = lastLetter.charCodeAt(0);
if (uni < 44032 || uni > 55203) return null;
return (uni - 44032) % 28 != 0;
}