Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/fix-josa-pick-abbreviation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'es-hangul': patch
---

fix: `josa.pick`도 `josa`처럼 대문자 약어를 한글 발음 기준으로 처리합니다. (예: `josa.pick('URL', '이/가')` → `'이'`)
7 changes: 7 additions & 0 deletions src/core/josa/josa.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,11 @@ describe('josa.pick', () => {
expect(josa('URL', '이에요/예요')).toBe('URL이에요');
expect(josa('CSS', '이에요/예요')).toBe('CSS예요');
});

it('영어로된 약어일 경우, josa.pick도 마지막 알파벳을 한국어로 바꾼뒤 조사를 고른다.', () => {
expect(josa.pick('URL', '이/가')).toBe('이');
expect(josa.pick('CSS', '이/가')).toBe('가');
expect(josa.pick('URL', '으로/로')).toBe('로');
expect(josa.pick('URL', '와/과')).toBe('과');
});
});
12 changes: 5 additions & 7 deletions src/core/josa/josa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ export function josa<T extends string, U extends JosaOption>(word: T, josa: U):
return word as `${T}${ExtractJosaOption<U>}`;
}

if (/^[A-Z]+$/.test(word)) {
const lastChar = word[word.length - 1];
const koreanPronunciationOfLastChar = ALPHABET_TO_KOREAN[lastChar];

return (word + josaPicker(koreanPronunciationOfLastChar, josa)) as `${T}${ExtractJosaOption<U>}`;
}

return (word + josaPicker(word, josa)) as `${T}${ExtractJosaOption<U>}`;
}

Expand All @@ -44,6 +37,11 @@ function josaPicker<T extends JosaOption>(word: string, josa: T): ExtractJosaOpt
return josa.split('/')[0] as ExtractJosaOption<T>;
}

// 대문자로만 이루어진 약어는 마지막 알파벳의 한글 발음을 기준으로 조사를 고른다.
if (/^[A-Z]+$/.test(word)) {
word = ALPHABET_TO_KOREAN[word[word.length - 1]];
}

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

Expand Down