-
Notifications
You must be signed in to change notification settings - Fork 49
/
josa.ts
54 lines (41 loc) · 1.27 KB
/
josa.ts
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
import { disassembleCompleteHangulCharacter } from './disassembleCompleteHangulCharacter';
import { hasBatchim } from './utils';
type JosaOption =
| '이/가'
| '을/를'
| '은/는'
| '으로/로'
| '와/과'
| '이나/나'
| '이란/란'
| '아/야'
| '이랑/랑'
| '이에요/예요'
| '으로서/로서'
| '으로써/로써'
| '으로부터/로부터';
const 로_조사: JosaOption[] = ['으로/로', '으로서/로서', '으로써/로써', '으로부터/로부터'];
export function josa(word: string, josa: JosaOption): string {
if (word.length === 0) {
return word;
}
return word + josaPicker(word, josa);
}
josa.pick = josaPicker;
function josaPicker(word: string, josa: JosaOption): string {
if (word.length === 0) {
return josa.split('/')[0];
}
const has받침 = hasBatchim(word);
let index = has받침 ? 0 : 1;
const is종성ㄹ = disassembleCompleteHangulCharacter(word[word.length - 1])?.last === 'ㄹ';
const isCaseOf로 = has받침 && is종성ㄹ && 로_조사.includes(josa);
if (josa === '와/과' || isCaseOf로) {
index = index === 0 ? 1 : 0;
}
const isEndsWith이 = word[word.length - 1] === '이';
if (josa === '이에요/예요' && isEndsWith이) {
index = 1;
}
return josa.split('/')[index];
}