Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: josa 함수의 계산과 분기를 최적화하였습니다 #282

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/josa/josa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type JosaOption =
| '으로부터/로부터'
| '이라/라';

const 로_조사: JosaOption[] = ['으로/로', '으로서/로서', '으로써/로써', '으로부터/로부터'];
const 로_조사 = new Set<JosaOption>(['으로/로', '으로서/로서', '으로써/로써', '으로부터/로부터']);

type ExtractJosaOption<T> = T extends `${infer A}/${infer B}` ? A | B : never;

Expand All @@ -37,21 +37,24 @@ function josaPicker<T extends JosaOption>(word: string, josa: T): ExtractJosaOpt
}

const has받침 = hasBatchim(word);
let index = has받침 ? 0 : 1;

const is종성ㄹ = has받침 && disassembleCompleteCharacter(word[word.length - 1])?.jongseong === 'ㄹ';
if (josa === '와/과') {
return josa.split('/')[has받침 ? 1 : 0] as ExtractJosaOption<T>;
}

const isCaseOf로 = has받침 && is종성ㄹ && 로_조사.includes(josa);
const 마지막글자 = word[word.length - 1];
const isEndsWith이 = 마지막글자 === '이';

if (josa === '와/과' || isCaseOf로) {
index = index === 0 ? 1 : 0;
if (josa === '이에요/예요' && isEndsWith이) {
return josa.split('/')[1] as ExtractJosaOption<T>;
}

const isEndsWith이 = word[word.length - 1] === '이';
const is종성ㄹ = has받침 && disassembleCompleteCharacter(마지막글자)?.jongseong === 'ㄹ';
const isCaseOf로 = has받침 && is종성ㄹ && 로_조사.has(josa);

if (josa === '이에요/예요' && isEndsWith이) {
index = 1;
if (isCaseOf로) {
return josa.split('/')[has받침 ? 1 : 0] as ExtractJosaOption<T>;
}

return josa.split('/')[index] as ExtractJosaOption<T>;
return josa.split('/')[has받침 ? 0 : 1] as ExtractJosaOption<T>;
}