josa.js
1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var _f = [
function (string) { //을/를 구분
return _hasJong(string) ? '을' : '를';
},
function (string) { //은/는 구분
return _hasJong(string) ? '은' : '는';
},
function (string) { //이/가 구분
return _hasJong(string) ? '이' : '가';
},
function (string) { //와/과 구분
return _hasJong(string) ? '과' : '와';
},
function (string) { //으로/로 구분
return _hasJong(string) ? '으로' : '로';
}
],
_formats = {
'을/를': _f[0],
'을': _f[0],
'를': _f[0],
'을를': _f[0],
'은/는': _f[1],
'은': _f[1],
'는': _f[1],
'은는': _f[1],
'이/가': _f[2],
'이': _f[2],
'가': _f[2],
'이가': _f[2],
'와/과': _f[3],
'와': _f[3],
'과': _f[3],
'와과': _f[3],
'으로': _f[4],
'로': _f[4],
'으로/로': _f[4]
};
function _hasJong(string) { //string의 마지막 글자가 받침을 가지는지 확인
string = string.charCodeAt(string.length - 1);
return (string - 0xac00) % 28 > 0;
}
var josa = {
c: function (word, format) {
if (typeof _formats[format] === 'undefined') throw 'Invalid format!';
return _formats[format](word);
},
r: function (word, format) {
return word + josa.c(word, format);
}
};