diff --git a/src/canBe.ts b/src/canBe.ts index 0e8d7b05..050c9e55 100644 --- a/src/canBe.ts +++ b/src/canBe.ts @@ -1,9 +1,5 @@ import { hasValueInReadOnlyStringList } from './_internal'; -import { - HANGUL_CHARACTERS_BY_FIRST_INDEX, - HANGUL_CHARACTERS_BY_LAST_INDEX, - HANGUL_CHARACTERS_BY_MIDDLE_INDEX, -} from './constants'; +import { CHOSEONGS, JONGSEONGS, JUNSEONGS } from './constants'; /** * @name canBeChoseong @@ -22,8 +18,8 @@ import { * canBeChoseong('ㅏ') // false * canBeChoseong('가') // false */ -export function canBeChoseong(character: string): character is (typeof HANGUL_CHARACTERS_BY_FIRST_INDEX)[number] { - return hasValueInReadOnlyStringList(HANGUL_CHARACTERS_BY_FIRST_INDEX, character); +export function canBeChoseong(character: string): character is (typeof CHOSEONGS)[number] { + return hasValueInReadOnlyStringList(CHOSEONGS, character); } /** @@ -44,8 +40,8 @@ export function canBeChoseong(character: string): character is (typeof HANGUL_CH * canBeJungseong('ㄱㅅ') // false * canBeJungseong('가') // false */ -export function canBeJungseong(character: string): character is (typeof HANGUL_CHARACTERS_BY_MIDDLE_INDEX)[number] { - return hasValueInReadOnlyStringList(HANGUL_CHARACTERS_BY_MIDDLE_INDEX, character); +export function canBeJungseong(character: string): character is (typeof JUNSEONGS)[number] { + return hasValueInReadOnlyStringList(JUNSEONGS, character); } /** @@ -66,6 +62,6 @@ export function canBeJungseong(character: string): character is (typeof HANGUL_C * canBeJongseong('ㅏ') // false * canBeJongseong('ㅗㅏ') // false */ -export function canBeJongseong(character: string): character is (typeof HANGUL_CHARACTERS_BY_LAST_INDEX)[number] { - return hasValueInReadOnlyStringList(HANGUL_CHARACTERS_BY_LAST_INDEX, character); +export function canBeJongseong(character: string): character is (typeof JONGSEONGS)[number] { + return hasValueInReadOnlyStringList(JONGSEONGS, character); } diff --git a/src/combineCharacter.ts b/src/combineCharacter.ts index 762d8145..75647f38 100644 --- a/src/combineCharacter.ts +++ b/src/combineCharacter.ts @@ -2,9 +2,9 @@ import { canBeChoseong, canBeJongseong, canBeJungseong } from './canBe'; import { COMPLETE_HANGUL_START_CHARCODE, DISASSEMBLED_VOWELS_BY_VOWEL, - HANGUL_CHARACTERS_BY_FIRST_INDEX, - HANGUL_CHARACTERS_BY_LAST_INDEX, - HANGUL_CHARACTERS_BY_MIDDLE_INDEX, + CHOSEONGS, + JONGSEONGS, + JUNSEONGS, } from './constants'; /** @@ -14,38 +14,33 @@ import { * ```typescript * combineCharacter( * // 초성 - * firstCharacter: string + * choseong: string * // 중성 - * middleCharacter: string + * jungseong: string * // 종성 - * lastCharacter: string + * jongseong: string * ): string * ``` * @example * combineCharacter('ㄱ', 'ㅏ', 'ㅂㅅ') // '값' * combineCharacter('ㅌ', 'ㅗ') // '토' */ -export function combineCharacter(firstCharacter: string, middleCharacter: string, lastCharacter = '') { - if ( - canBeChoseong(firstCharacter) === false || - canBeJungseong(middleCharacter) === false || - canBeJongseong(lastCharacter) === false - ) { - throw new Error(`Invalid hangul Characters: ${firstCharacter}, ${middleCharacter}, ${lastCharacter}`); +export function combineCharacter(choseong: string, jungseong: string, jongseong = '') { + if (canBeChoseong(choseong) === false || canBeJungseong(jungseong) === false || canBeJongseong(jongseong) === false) { + throw new Error(`Invalid hangul Characters: ${choseong}, ${jungseong}, ${jongseong}`); } - const numOfMiddleCharacters = HANGUL_CHARACTERS_BY_MIDDLE_INDEX.length; - const numOfLastCharacters = HANGUL_CHARACTERS_BY_LAST_INDEX.length; + const numOfJungseongs = JUNSEONGS.length; + const numOfJongseongs = JONGSEONGS.length; - const firstCharacterIndex = HANGUL_CHARACTERS_BY_FIRST_INDEX.indexOf(firstCharacter); - const middleCharacterIndex = HANGUL_CHARACTERS_BY_MIDDLE_INDEX.indexOf(middleCharacter); - const lastCharacterIndex = HANGUL_CHARACTERS_BY_LAST_INDEX.indexOf(lastCharacter); + const choseongIndex = CHOSEONGS.indexOf(choseong as (typeof CHOSEONGS)[number]); + const jungseongIndex = JUNSEONGS.indexOf(jungseong as (typeof JUNSEONGS)[number]); + const jongseongIndex = JONGSEONGS.indexOf(jongseong as (typeof JONGSEONGS)[number]); - const firstIndexOfTargetConsonant = firstCharacterIndex * numOfMiddleCharacters * numOfLastCharacters; - const firstIndexOfTargetVowel = middleCharacterIndex * numOfLastCharacters; + const choseongOfTargetConsonant = choseongIndex * numOfJungseongs * numOfJongseongs; + const choseongOfTargetVowel = jungseongIndex * numOfJongseongs; - const unicode = - COMPLETE_HANGUL_START_CHARCODE + firstIndexOfTargetConsonant + firstIndexOfTargetVowel + lastCharacterIndex; + const unicode = COMPLETE_HANGUL_START_CHARCODE + choseongOfTargetConsonant + choseongOfTargetVowel + jongseongIndex; return String.fromCharCode(unicode); } @@ -60,10 +55,10 @@ export function combineCharacter(firstCharacter: string, middleCharacter: string * combineLastHangulCharacter('ㄱ') // '각' */ export const curriedCombineCharacter = - (firstCharacter: string) => - (middleCharacter: string) => - (lastCharacter = '') => - combineCharacter(firstCharacter, middleCharacter, lastCharacter); + (choseong: string) => + (jungseong: string) => + (jongseong = '') => + combineCharacter(choseong, jungseong, jongseong); /** * @name combineVowels diff --git a/src/constants.ts b/src/constants.ts index 20fa1a03..e9704ff9 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -79,7 +79,7 @@ export const DISASSEMBLED_VOWELS_BY_VOWEL = { /** * 초성으로 올 수 있는 한글 글자 */ -export const HANGUL_CHARACTERS_BY_FIRST_INDEX = [ +export const CHOSEONGS = [ 'ㄱ', 'ㄲ', 'ㄴ', @@ -104,12 +104,12 @@ export const HANGUL_CHARACTERS_BY_FIRST_INDEX = [ /** * 중성으로 올 수 있는 한글 글자 */ -export const HANGUL_CHARACTERS_BY_MIDDLE_INDEX = Object.values(DISASSEMBLED_VOWELS_BY_VOWEL); +export const JUNSEONGS = Object.values(DISASSEMBLED_VOWELS_BY_VOWEL); /** * 종성으로 올 수 있는 한글 글자 */ -export const HANGUL_CHARACTERS_BY_LAST_INDEX = ( +export const JONGSEONGS = ( [ '', 'ㄱ', diff --git a/src/disassemble.ts b/src/disassemble.ts index f16e0b42..4f0b9b3f 100644 --- a/src/disassemble.ts +++ b/src/disassemble.ts @@ -16,7 +16,11 @@ export function disassembleToGroups(str: string) { const disassembledComplete = disassembleCompleteCharacter(letter); if (disassembledComplete != null) { - result.push([...disassembledComplete.first, ...disassembledComplete.middle, ...disassembledComplete.last]); + result.push([ + ...disassembledComplete.choseong, + ...disassembledComplete.jungseong, + ...disassembledComplete.jongseong, + ]); continue; } diff --git a/src/disassembleCompleteCharacter.spec.ts b/src/disassembleCompleteCharacter.spec.ts index 716e3a25..62be5230 100644 --- a/src/disassembleCompleteCharacter.spec.ts +++ b/src/disassembleCompleteCharacter.spec.ts @@ -3,33 +3,33 @@ import { disassembleCompleteCharacter } from './disassembleCompleteCharacter'; describe('disassembleCompleteCharacter', () => { it('값', () => { expect(disassembleCompleteCharacter('값')).toEqual({ - first: 'ㄱ', - middle: 'ㅏ', - last: 'ㅂㅅ', + choseong: 'ㄱ', + jungseong: 'ㅏ', + jongseong: 'ㅂㅅ', }); }); it('리', () => { expect(disassembleCompleteCharacter('리')).toEqual({ - first: 'ㄹ', - middle: 'ㅣ', - last: '', + choseong: 'ㄹ', + jungseong: 'ㅣ', + jongseong: '', }); }); it('빚', () => { expect(disassembleCompleteCharacter('빚')).toEqual({ - first: 'ㅂ', - middle: 'ㅣ', - last: 'ㅈ', + choseong: 'ㅂ', + jungseong: 'ㅣ', + jongseong: 'ㅈ', }); }); it('박', () => { expect(disassembleCompleteCharacter('박')).toEqual({ - first: 'ㅂ', - middle: 'ㅏ', - last: 'ㄱ', + choseong: 'ㅂ', + jungseong: 'ㅏ', + jongseong: 'ㄱ', }); }); diff --git a/src/disassembleCompleteCharacter.ts b/src/disassembleCompleteCharacter.ts index 43e54900..4a4337cb 100644 --- a/src/disassembleCompleteCharacter.ts +++ b/src/disassembleCompleteCharacter.ts @@ -1,17 +1,17 @@ import { COMPLETE_HANGUL_END_CHARCODE, COMPLETE_HANGUL_START_CHARCODE, - HANGUL_CHARACTERS_BY_FIRST_INDEX, - HANGUL_CHARACTERS_BY_LAST_INDEX, - HANGUL_CHARACTERS_BY_MIDDLE_INDEX, + CHOSEONGS, + JONGSEONGS, + JUNSEONGS, NUMBER_OF_JONGSEONG, NUMBER_OF_JUNGSEONG, } from './constants'; interface ReturnTypeDisassembleCompleteCharacter { - first: (typeof HANGUL_CHARACTERS_BY_FIRST_INDEX)[number]; - middle: (typeof HANGUL_CHARACTERS_BY_MIDDLE_INDEX)[number]; - last: (typeof HANGUL_CHARACTERS_BY_LAST_INDEX)[number]; + choseong: (typeof CHOSEONGS)[number]; + jungseong: (typeof JUNSEONGS)[number]; + jongseong: (typeof JONGSEONGS)[number]; } /** @@ -22,10 +22,10 @@ interface ReturnTypeDisassembleCompleteCharacter { * @param {string} letter 분리하고자 하는 완전한 한글 문자열 * * @example - * disassembleCompleteCharacter('값') // { first: 'ㄱ', middle: 'ㅏ', last: 'ㅂㅅ' } - * disassembleCompleteCharacter('리') // { first: 'ㄹ', middle: 'ㅣ', last: '' } - * disassembleCompleteCharacter('빚') // { first: 'ㅂ', middle: 'ㅣ', last: 'ㅈ' } - * disassembleCompleteCharacter('박') // { first: 'ㅂ', middle: 'ㅏ', last: 'ㄱ' } + * disassembleCompleteCharacter('값') // { choseong: 'ㄱ', jungseong: 'ㅏ', jongseong: 'ㅂㅅ' } + * disassembleCompleteCharacter('리') // { choseong: 'ㄹ', jungseong: 'ㅣ', jongseong: '' } + * disassembleCompleteCharacter('빚') // { choseong: 'ㅂ', jungseong: 'ㅣ', jongseong: 'ㅈ' } + * disassembleCompleteCharacter('박') // { choseong: 'ㅂ', jungseong: 'ㅏ', jongseong: 'ㄱ' } */ export function disassembleCompleteCharacter(letter: string): ReturnTypeDisassembleCompleteCharacter | undefined { @@ -39,13 +39,13 @@ export function disassembleCompleteCharacter(letter: string): ReturnTypeDisassem const hangulCode = charCode - COMPLETE_HANGUL_START_CHARCODE; - const lastIndex = hangulCode % NUMBER_OF_JONGSEONG; - const middleIndex = ((hangulCode - lastIndex) / NUMBER_OF_JONGSEONG) % NUMBER_OF_JUNGSEONG; - const firstIndex = Math.floor((hangulCode - lastIndex) / NUMBER_OF_JONGSEONG / NUMBER_OF_JUNGSEONG); + const jongseongIndex = hangulCode % NUMBER_OF_JONGSEONG; + const jungseongIndex = ((hangulCode - jongseongIndex) / NUMBER_OF_JONGSEONG) % NUMBER_OF_JUNGSEONG; + const choseongIndex = Math.floor((hangulCode - jongseongIndex) / NUMBER_OF_JONGSEONG / NUMBER_OF_JUNGSEONG); return { - first: HANGUL_CHARACTERS_BY_FIRST_INDEX[firstIndex], - middle: HANGUL_CHARACTERS_BY_MIDDLE_INDEX[middleIndex], - last: HANGUL_CHARACTERS_BY_LAST_INDEX[lastIndex], + choseong: CHOSEONGS[choseongIndex], + jungseong: JUNSEONGS[jungseongIndex], + jongseong: JONGSEONGS[jongseongIndex], } as const; } diff --git a/src/disassembleCompleteHangulCharacter.spec.ts b/src/disassembleCompleteHangulCharacter.spec.ts new file mode 100644 index 00000000..62be5230 --- /dev/null +++ b/src/disassembleCompleteHangulCharacter.spec.ts @@ -0,0 +1,40 @@ +import { disassembleCompleteCharacter } from './disassembleCompleteCharacter'; + +describe('disassembleCompleteCharacter', () => { + it('값', () => { + expect(disassembleCompleteCharacter('값')).toEqual({ + choseong: 'ㄱ', + jungseong: 'ㅏ', + jongseong: 'ㅂㅅ', + }); + }); + + it('리', () => { + expect(disassembleCompleteCharacter('리')).toEqual({ + choseong: 'ㄹ', + jungseong: 'ㅣ', + jongseong: '', + }); + }); + + it('빚', () => { + expect(disassembleCompleteCharacter('빚')).toEqual({ + choseong: 'ㅂ', + jungseong: 'ㅣ', + jongseong: 'ㅈ', + }); + }); + + it('박', () => { + expect(disassembleCompleteCharacter('박')).toEqual({ + choseong: 'ㅂ', + jungseong: 'ㅏ', + jongseong: 'ㄱ', + }); + }); + + it('완전한 한글 문자열이 아니면 undefined를 반환해야 합니다.', () => { + expect(disassembleCompleteCharacter('ㄱ')).toBeUndefined; + expect(disassembleCompleteCharacter('ㅏ')).toBeUndefined; + }); +}); diff --git a/src/getChoseong.ts b/src/getChoseong.ts index befd95f6..17cedf59 100644 --- a/src/getChoseong.ts +++ b/src/getChoseong.ts @@ -1,4 +1,4 @@ -import { HANGUL_CHARACTERS_BY_FIRST_INDEX, JASO_HANGUL_NFD } from './constants'; +import { CHOSEONGS, JASO_HANGUL_NFD } from './constants'; /** * @name getChoseong @@ -18,7 +18,7 @@ export function getChoseong(word: string) { return word .normalize('NFD') .replace(EXTRACT_CHOSEONG_REGEX, '') // NFD ㄱ-ㅎ, NFC ㄱ-ㅎ 외 문자 삭제 - .replace(CHOOSE_NFD_CHOSEONG_REGEX, $0 => HANGUL_CHARACTERS_BY_FIRST_INDEX[$0.charCodeAt(0) - 0x1100]); // NFD to NFC + .replace(CHOOSE_NFD_CHOSEONG_REGEX, $0 => CHOSEONGS[$0.charCodeAt(0) - 0x1100]); // NFD to NFC } const EXTRACT_CHOSEONG_REGEX = new RegExp( diff --git a/src/hasBatchim.ts b/src/hasBatchim.ts index 9fcfc2a3..02e44c5f 100644 --- a/src/hasBatchim.ts +++ b/src/hasBatchim.ts @@ -1,7 +1,7 @@ import { COMPLETE_HANGUL_END_CHARCODE, COMPLETE_HANGUL_START_CHARCODE, - HANGUL_CHARACTERS_BY_LAST_INDEX, + JONGSEONGS, NUMBER_OF_JONGSEONG, } from './constants'; @@ -50,11 +50,11 @@ export function hasBatchim( const batchimCode = (charCode - COMPLETE_HANGUL_START_CHARCODE) % NUMBER_OF_JONGSEONG; if (options?.only === 'single') { - return HANGUL_CHARACTERS_BY_LAST_INDEX[batchimCode].length === 1; + return JONGSEONGS[batchimCode].length === 1; } if (options?.only === 'double') { - return HANGUL_CHARACTERS_BY_LAST_INDEX[batchimCode].length === 2; + return JONGSEONGS[batchimCode].length === 2; } return batchimCode > 0; diff --git a/src/josa.ts b/src/josa.ts index 8f5de283..906c0b3e 100644 --- a/src/josa.ts +++ b/src/josa.ts @@ -37,7 +37,7 @@ function josaPicker(word: string, josa: JosaOption): string { const has받침 = hasBatchim(word); let index = has받침 ? 0 : 1; - const is종성ㄹ = disassembleCompleteCharacter(word[word.length - 1])?.last === 'ㄹ'; + const is종성ㄹ = disassembleCompleteCharacter(word[word.length - 1])?.jongseong === 'ㄹ'; const isCaseOf로 = has받침 && is종성ㄹ && 로_조사.includes(josa); diff --git a/src/romanize.ts b/src/romanize.ts index f2d5f7a7..4ff0c0fd 100644 --- a/src/romanize.ts +++ b/src/romanize.ts @@ -27,15 +27,16 @@ const romanizeSyllableHangul = (arrayHangul: string[], index: number): string => ReturnType >; - let choseong: (typeof 초성_알파벳_발음)[keyof typeof 초성_알파벳_발음] | 'l' = 초성_알파벳_발음[disassemble.first]; - const jungseong = 중성_알파벳_발음[assemble([disassemble.middle]) as keyof typeof 중성_알파벳_발음]; - const jongseong = 종성_알파벳_발음[disassemble.last as keyof typeof 종성_알파벳_발음]; + let choseong: (typeof 초성_알파벳_발음)[keyof typeof 초성_알파벳_발음] | 'l' = + 초성_알파벳_발음[disassemble.choseong]; + const jungseong = 중성_알파벳_발음[assemble([disassemble.jungseong]) as keyof typeof 중성_알파벳_발음]; + const jongseong = 종성_알파벳_발음[disassemble.jongseong as keyof typeof 종성_알파벳_발음]; // 'ㄹ'은 모음 앞에서는 'r'로, 자음 앞이나 어말에서는 'l'로 적는다. 단, 'ㄹㄹ'은 'll'로 적는다. (ex.울릉, 대관령), - if (disassemble.first === 'ㄹ' && index > 0 && isHangulCharacter(arrayHangul[index - 1])) { + if (disassemble.choseong === 'ㄹ' && index > 0 && isHangulCharacter(arrayHangul[index - 1])) { const prevDisassemble = disassembleCompleteCharacter(arrayHangul[index - 1]); - if (prevDisassemble?.last === 'ㄹ') { + if (prevDisassemble?.jongseong === 'ㄹ') { choseong = 'l'; } } diff --git a/src/standardizePronunciation/index.ts b/src/standardizePronunciation/index.ts index 3c4e20cf..7fd2ad36 100644 --- a/src/standardizePronunciation/index.ts +++ b/src/standardizePronunciation/index.ts @@ -146,7 +146,7 @@ function applyRules(params: ApplyParameters): { function assembleChangedHangul(disassembleHangul: Syllable[], notHangulPhrase: NotHangul[]): string { const changedSyllables = disassembleHangul .filter(isNotUndefined) - .map(syllable => combineCharacter(syllable.first, syllable.middle, syllable.last)); + .map(syllable => combineCharacter(syllable.choseong, syllable.jungseong, syllable.jongseong)); for (const { index, syllable } of notHangulPhrase) { changedSyllables.splice(index, 0, syllable); diff --git a/src/standardizePronunciation/rules/rules.utils.ts b/src/standardizePronunciation/rules/rules.utils.ts index fe0f330c..f857f8e8 100644 --- a/src/standardizePronunciation/rules/rules.utils.ts +++ b/src/standardizePronunciation/rules/rules.utils.ts @@ -1,5 +1,5 @@ import { Syllable } from './rules.types'; -export function replace받침ㅎ(currentSyllable: Syllable): Syllable['last'] { - return currentSyllable.last.replace('ㅎ', '') as Syllable['last']; +export function replace받침ㅎ(currentSyllable: Syllable): Syllable['jongseong'] { + return currentSyllable.jongseong.replace('ㅎ', '') as Syllable['jongseong']; } diff --git a/src/standardizePronunciation/rules/transform12th.spec.ts b/src/standardizePronunciation/rules/transform12th.spec.ts index 5a649def..e3159b53 100644 --- a/src/standardizePronunciation/rules/transform12th.spec.ts +++ b/src/standardizePronunciation/rules/transform12th.spec.ts @@ -9,14 +9,14 @@ describe('transform12th', () => { expect(transform12th(current, next)).toEqual({ current: { - first: 'ㄴ', - middle: 'ㅗ', - last: '', + choseong: 'ㄴ', + jungseong: 'ㅗ', + jongseong: '', }, next: { - first: 'ㅋ', - middle: 'ㅗ', - last: '', + choseong: 'ㅋ', + jungseong: 'ㅗ', + jongseong: '', }, }); }); @@ -27,14 +27,14 @@ describe('transform12th', () => { expect(transform12th(current, next)).toEqual({ current: { - first: 'ㄱ', - middle: 'ㅏ', - last: '', + choseong: 'ㄱ', + jungseong: 'ㅏ', + jongseong: '', }, next: { - first: 'ㅋ', - middle: 'ㅏ', - last: '', + choseong: 'ㅋ', + jungseong: 'ㅏ', + jongseong: '', }, }); }); @@ -45,14 +45,14 @@ describe('transform12th', () => { expect(transform12th(current, next)).toEqual({ current: { - first: 'ㄷ', - middle: 'ㅏ', - last: '', + choseong: 'ㄷ', + jungseong: 'ㅏ', + jongseong: '', }, next: { - first: 'ㅆ', - middle: 'ㅗ', - last: '', + choseong: 'ㅆ', + jungseong: 'ㅗ', + jongseong: '', }, }); }); @@ -63,14 +63,14 @@ describe('transform12th', () => { expect(transform12th(current, next)).toEqual({ current: { - first: 'ㄴ', - middle: 'ㅗ', - last: '', + choseong: 'ㄴ', + jungseong: 'ㅗ', + jongseong: '', }, next: { - first: 'ㄴ', - middle: 'ㅡ', - last: 'ㄴ', + choseong: 'ㄴ', + jungseong: 'ㅡ', + jongseong: 'ㄴ', }, }); }); @@ -81,14 +81,14 @@ describe('transform12th', () => { expect(transform12th(current, next)).toEqual({ current: { - first: 'ㅇ', - middle: 'ㅏ', - last: 'ㄴ', + choseong: 'ㅇ', + jungseong: 'ㅏ', + jongseong: 'ㄴ', }, next: { - first: 'ㄴ', - middle: 'ㅔ', - last: '', + choseong: 'ㄴ', + jungseong: 'ㅔ', + jongseong: '', }, }); }); @@ -99,14 +99,14 @@ describe('transform12th', () => { expect(transform12th(current, next)).toEqual({ current: { - first: 'ㄴ', - middle: 'ㅏ', - last: '', + choseong: 'ㄴ', + jungseong: 'ㅏ', + jongseong: '', }, next: { - first: 'ㅇ', - middle: 'ㅡ', - last: 'ㄴ', + choseong: 'ㅇ', + jungseong: 'ㅡ', + jongseong: 'ㄴ', }, }); }); @@ -117,9 +117,9 @@ describe('transform12th', () => { expect(transform12th(current, next)).toEqual({ current: { - first: 'ㅁ', - middle: 'ㅏ', - last: 'ㄴ', + choseong: 'ㅁ', + jungseong: 'ㅏ', + jongseong: 'ㄴ', }, next: null, }); diff --git a/src/standardizePronunciation/rules/transform12th.ts b/src/standardizePronunciation/rules/transform12th.ts index 70a64cdc..77841f94 100644 --- a/src/standardizePronunciation/rules/transform12th.ts +++ b/src/standardizePronunciation/rules/transform12th.ts @@ -25,26 +25,26 @@ export function transform12th(currentSyllable: Syllable, nextSyllable: Nullable< let current = { ...currentSyllable }; let next = nextSyllable ? { ...nextSyllable } : nextSyllable; - if (!current.last) { + if (!current.jongseong) { return { current, next, }; } - if (arrayIncludes(발음변환_받침_ㅎ, current.last)) { + if (arrayIncludes(발음변환_받침_ㅎ, current.jongseong)) { if (next) { - ({ current, next } = handleNextFirstIsㄱㄷㅈㅅ(current, next)); - ({ current, next } = handleNextFirstIsㄴ(current, next)); - ({ current, next } = handleNextFirstIsㅇ(current, next)); + ({ current, next } = handleNextChoseongIsㄱㄷㅈㅅ(current, next)); + ({ current, next } = handleNextChoseongIsㄴ(current, next)); + ({ current, next } = handleNextChoseongIsㅇ(current, next)); } if (!next) { - ({ current } = handleCurrentLastIsㅇ(current)); + ({ current } = handleCurrentJongseongIsㅇ(current)); } } - ({ current, next } = handleNextFirstIsㅎ(current, next)); + ({ current, next } = handleNextChoseongIsㅎ(current, next)); return { current, @@ -52,62 +52,62 @@ export function transform12th(currentSyllable: Syllable, nextSyllable: Nullable< }; } -function handleNextFirstIsㄱㄷㅈㅅ(current: Syllable, next: Syllable): ReturnSyllables { +function handleNextChoseongIsㄱㄷㅈㅅ(current: Syllable, next: Syllable): ReturnSyllables { const updatedCurrent = { ...current }; const updatedNext = { ...next }; - if (arrayIncludes(['ㄱ', 'ㄷ', 'ㅈ', 'ㅅ'], updatedNext.first)) { - updatedNext.first = 발음변환_받침_ㅎ_발음[updatedNext.first as keyof typeof 발음변환_받침_ㅎ_발음]; - updatedCurrent.last = replace받침ㅎ(updatedCurrent); + if (arrayIncludes(['ㄱ', 'ㄷ', 'ㅈ', 'ㅅ'], updatedNext.choseong)) { + updatedNext.choseong = 발음변환_받침_ㅎ_발음[updatedNext.choseong as keyof typeof 발음변환_받침_ㅎ_발음]; + updatedCurrent.jongseong = replace받침ㅎ(updatedCurrent); } return { current: updatedCurrent, next: updatedNext }; } -function handleNextFirstIsㄴ(current: Syllable, next: Syllable): ReturnSyllables { +function handleNextChoseongIsㄴ(current: Syllable, next: Syllable): ReturnSyllables { const updatedCurrent = { ...current }; const updatedNext = { ...next }; - if (updatedNext.first === 'ㄴ' && arrayIncludes(['ㄴㅎ', 'ㄹㅎ'], updatedCurrent.last)) { - updatedCurrent.last = replace받침ㅎ(updatedCurrent); + if (updatedNext.choseong === 'ㄴ' && arrayIncludes(['ㄴㅎ', 'ㄹㅎ'], updatedCurrent.jongseong)) { + updatedCurrent.jongseong = replace받침ㅎ(updatedCurrent); } return { current: updatedCurrent, next: updatedNext }; } -function handleNextFirstIsㅇ(current: Syllable, next: Syllable): ReturnSyllables { +function handleNextChoseongIsㅇ(current: Syllable, next: Syllable): ReturnSyllables { const updatedCurrent = { ...current }; const updatedNext = { ...next }; - if (updatedNext.first === 음가가_없는_자음) { - if (arrayIncludes(['ㄴㅎ', 'ㄹㅎ'], updatedCurrent.last)) { - updatedCurrent.last = replace받침ㅎ(updatedCurrent); + if (updatedNext.choseong === 음가가_없는_자음) { + if (arrayIncludes(['ㄴㅎ', 'ㄹㅎ'], updatedCurrent.jongseong)) { + updatedCurrent.jongseong = replace받침ㅎ(updatedCurrent); } else { - updatedCurrent.last = ''; + updatedCurrent.jongseong = ''; } } else { - updatedCurrent.last = replace받침ㅎ(updatedCurrent); + updatedCurrent.jongseong = replace받침ㅎ(updatedCurrent); } return { current: updatedCurrent, next: updatedNext }; } -function handleCurrentLastIsㅇ(current: Syllable): Pick { +function handleCurrentJongseongIsㅇ(current: Syllable): Pick { const updatedCurrent = { ...current }; - updatedCurrent.last = replace받침ㅎ(updatedCurrent); + updatedCurrent.jongseong = replace받침ㅎ(updatedCurrent); return { current: updatedCurrent }; } -function handleNextFirstIsㅎ(current: Syllable, next: Nullable): NullableReturnSyllables { +function handleNextChoseongIsㅎ(current: Syllable, next: Nullable): NullableReturnSyllables { const updatedCurrent = { ...current }; const updatedNext = next ? { ...next } : next; - if (arrayIncludes(발음변환_첫소리_ㅎ, updatedCurrent.last) && arrayIncludes(['ㅎ'], updatedNext?.first)) { - updatedNext.first = 발음변환_첫소리_ㅎ_발음[updatedCurrent.last]; + if (arrayIncludes(발음변환_첫소리_ㅎ, updatedCurrent.jongseong) && arrayIncludes(['ㅎ'], updatedNext?.choseong)) { + updatedNext.choseong = 발음변환_첫소리_ㅎ_발음[updatedCurrent.jongseong]; - if (updatedCurrent.last.length === 1) { - updatedCurrent.last = ''; + if (updatedCurrent.jongseong.length === 1) { + updatedCurrent.jongseong = ''; } else { - updatedCurrent.last = updatedCurrent.last[0] as Syllable['last']; + updatedCurrent.jongseong = updatedCurrent.jongseong[0] as Syllable['jongseong']; } } return { current: updatedCurrent, next: updatedNext }; diff --git a/src/standardizePronunciation/rules/transform13And14th.spec.ts b/src/standardizePronunciation/rules/transform13And14th.spec.ts index f09e636a..0c9aa1ec 100644 --- a/src/standardizePronunciation/rules/transform13And14th.spec.ts +++ b/src/standardizePronunciation/rules/transform13And14th.spec.ts @@ -9,14 +9,14 @@ describe('transform13And14th', () => { expect(transform13And14th(current, next)).toEqual({ current: { - first: 'ㄲ', - middle: 'ㅏ', - last: '', + choseong: 'ㄲ', + jungseong: 'ㅏ', + jongseong: '', }, next: { - first: 'ㄲ', - middle: 'ㅏ', - last: '', + choseong: 'ㄲ', + jungseong: 'ㅏ', + jongseong: '', }, }); }); @@ -27,14 +27,14 @@ describe('transform13And14th', () => { expect(transform13And14th(current, next)).toEqual({ current: { - first: 'ㄷ', - middle: 'ㅏ', - last: 'ㄹ', + choseong: 'ㄷ', + jungseong: 'ㅏ', + jongseong: 'ㄹ', }, next: { - first: 'ㄱ', - middle: 'ㅡ', - last: 'ㄹ', + choseong: 'ㄱ', + jungseong: 'ㅡ', + jongseong: 'ㄹ', }, }); }); diff --git a/src/standardizePronunciation/rules/transform13And14th.ts b/src/standardizePronunciation/rules/transform13And14th.ts index faf02bd0..651dcea7 100644 --- a/src/standardizePronunciation/rules/transform13And14th.ts +++ b/src/standardizePronunciation/rules/transform13And14th.ts @@ -19,7 +19,7 @@ export function transform13And14th(currentSyllable: Syllable, nextSyllable: Syll let current = { ...currentSyllable }; let next = { ...nextSyllable }; - const 제13_14항주요조건 = current.last && next.first === 음가가_없는_자음; + const 제13_14항주요조건 = current.jongseong && next.choseong === 음가가_없는_자음; if (!제13_14항주요조건) { return { @@ -38,24 +38,24 @@ export function transform13And14th(currentSyllable: Syllable, nextSyllable: Syll } function is홑받침(current: Syllable): boolean { - return current.last.length === 받침의길이['홀받침']; + return current.jongseong.length === 받침의길이['홀받침']; } function is쌍받침(current: Syllable): boolean { - return current.last.length === 받침의길이['쌍_겹받침'] && current.last[0] === current.last[1]; + return current.jongseong.length === 받침의길이['쌍_겹받침'] && current.jongseong[0] === current.jongseong[1]; } function is겹받침(current: Syllable): boolean { - return current.last.length === 받침의길이['쌍_겹받침'] && current.last[0] !== current.last[1]; + return current.jongseong.length === 받침의길이['쌍_겹받침'] && current.jongseong[0] !== current.jongseong[1]; } function handle홑받침or쌍받침(current: Syllable, next: Syllable): ReturnSyllables { const updatedCurrent = { ...current }; const updatedNext = { ...next }; - if (!arrayIncludes(['ㅇ', ''], updatedCurrent.last) && (is홑받침(updatedCurrent) || is쌍받침(updatedCurrent))) { - updatedNext.first = updatedCurrent.last; - updatedCurrent.last = ''; + if (!arrayIncludes(['ㅇ', ''], updatedCurrent.jongseong) && (is홑받침(updatedCurrent) || is쌍받침(updatedCurrent))) { + updatedNext.choseong = updatedCurrent.jongseong; + updatedCurrent.jongseong = ''; } return { current: updatedCurrent, next: updatedNext }; } @@ -65,12 +65,15 @@ function handle겹받침(current: Syllable, next: Syllable): ReturnSyllables { const updatedNext = { ...next }; if (is겹받침(updatedCurrent)) { - if (updatedCurrent.last[1] === 'ㅅ') { - updatedNext.first = 'ㅆ'; + if (updatedCurrent.jongseong[1] === 'ㅅ') { + updatedNext.choseong = 'ㅆ'; } else { - updatedNext.first = updatedCurrent.last[1] as Syllable['first']; + updatedNext.choseong = updatedCurrent.jongseong[1] as Syllable['choseong']; } - updatedCurrent.last = updatedCurrent.last.replace(updatedCurrent.last[1], '') as Syllable['last']; + updatedCurrent.jongseong = updatedCurrent.jongseong.replace( + updatedCurrent.jongseong[1], + '' + ) as Syllable['jongseong']; } return { current: updatedCurrent, next: updatedNext }; } diff --git a/src/standardizePronunciation/rules/transform16th.spec.ts b/src/standardizePronunciation/rules/transform16th.spec.ts index ee38a500..2b30f921 100644 --- a/src/standardizePronunciation/rules/transform16th.spec.ts +++ b/src/standardizePronunciation/rules/transform16th.spec.ts @@ -18,14 +18,14 @@ describe('transform16th', () => { }) ).toEqual({ current: { - first: 'ㄱ', - middle: 'ㅡ', - last: '', + choseong: 'ㄱ', + jungseong: 'ㅡ', + jongseong: '', }, next: { - first: 'ㅅ', - middle: 'ㅣ', - last: '', + choseong: 'ㅅ', + jungseong: 'ㅣ', + jongseong: '', }, }); }); @@ -45,14 +45,14 @@ describe('transform16th', () => { }) ).toEqual({ current: { - first: 'ㅇ', - middle: 'ㅕ', - last: '', + choseong: 'ㅇ', + jungseong: 'ㅕ', + jongseong: '', }, next: { - first: 'ㄱ', - middle: 'ㅣ', - last: '', + choseong: 'ㄱ', + jungseong: 'ㅣ', + jongseong: '', }, }); }); diff --git a/src/standardizePronunciation/rules/transform16th.ts b/src/standardizePronunciation/rules/transform16th.ts index 1fcae938..5622b6a1 100644 --- a/src/standardizePronunciation/rules/transform16th.ts +++ b/src/standardizePronunciation/rules/transform16th.ts @@ -26,7 +26,7 @@ export function transform16th({ currentSyllable, phrase, index, nextSyllable }: let current = { ...currentSyllable }; let next = { ...nextSyllable }; - const 제16항주요조건 = current.last && next.first === 음가가_없는_자음; + const 제16항주요조건 = current.jongseong && next.choseong === 음가가_없는_자음; if (!제16항주요조건) { return { @@ -57,10 +57,10 @@ function handleSpecialHangulCharacters({ const updatedNext = { ...next }; if (arrayIncludes(특별한_한글_자모, combinedSyllables)) { - const 다음_음절의_초성 = 특별한_한글_자모의_발음[updatedCurrent.last as keyof typeof 특별한_한글_자모의_발음]; + const 다음_음절의_초성 = 특별한_한글_자모의_발음[updatedCurrent.jongseong as keyof typeof 특별한_한글_자모의_발음]; - updatedCurrent.last = ''; - updatedNext.first = 다음_음절의_초성; + updatedCurrent.jongseong = ''; + updatedNext.choseong = 다음_음절의_초성; } return { current: updatedCurrent, next: updatedNext }; } @@ -76,10 +76,10 @@ function handleHangulCharacters({ const updatedNext = { ...next }; if (arrayIncludes(한글_자모, combinedSyllables)) { - updatedNext.first = updatedCurrent.last as typeof updatedNext.first; + updatedNext.choseong = updatedCurrent.jongseong as typeof updatedNext.choseong; - if (updatedCurrent.last !== 'ㅇ') { - updatedCurrent.last = ''; + if (updatedCurrent.jongseong !== 'ㅇ') { + updatedCurrent.jongseong = ''; } } return { current: updatedCurrent, next: updatedNext }; diff --git a/src/standardizePronunciation/rules/transform17th.spec.ts b/src/standardizePronunciation/rules/transform17th.spec.ts index a371d420..0aead226 100644 --- a/src/standardizePronunciation/rules/transform17th.spec.ts +++ b/src/standardizePronunciation/rules/transform17th.spec.ts @@ -9,14 +9,14 @@ describe('transform17th', () => { expect(transform17th(current, next)).toEqual({ current: { - first: 'ㄱ', - middle: 'ㅜ', - last: '', + choseong: 'ㄱ', + jungseong: 'ㅜ', + jongseong: '', }, next: { - first: 'ㅈ', - middle: 'ㅣ', - last: '', + choseong: 'ㅈ', + jungseong: 'ㅣ', + jongseong: '', }, }); }); @@ -27,14 +27,14 @@ describe('transform17th', () => { expect(transform17th(current, next)).toEqual({ current: { - first: 'ㄱ', - middle: 'ㅜ', - last: '', + choseong: 'ㄱ', + jungseong: 'ㅜ', + jongseong: '', }, next: { - first: 'ㅊ', - middle: 'ㅣ', - last: '', + choseong: 'ㅊ', + jungseong: 'ㅣ', + jongseong: '', }, }); }); diff --git a/src/standardizePronunciation/rules/transform17th.ts b/src/standardizePronunciation/rules/transform17th.ts index 094a714c..a98f9a94 100644 --- a/src/standardizePronunciation/rules/transform17th.ts +++ b/src/standardizePronunciation/rules/transform17th.ts @@ -14,7 +14,7 @@ export function transform17th(currentSyllable: Syllable, nextSyllable: Syllable) let current = { ...currentSyllable }; let next = { ...nextSyllable }; - const 제17항주요조건 = next.middle === 'ㅣ'; + const 제17항주요조건 = next.jungseong === 'ㅣ'; if (!제17항주요조건) { return { @@ -23,8 +23,8 @@ export function transform17th(currentSyllable: Syllable, nextSyllable: Syllable) }; } - ({ current, next } = handleFirstIsㅇ(current, next)); - ({ current, next } = handleFirstIsㅎAndㄷ(current, next)); + ({ current, next } = handleChoseongIsㅇ(current, next)); + ({ current, next } = handleChoseongIsㅎAndㄷ(current, next)); return { current, @@ -32,24 +32,24 @@ export function transform17th(currentSyllable: Syllable, nextSyllable: Syllable) }; } -function handleFirstIsㅇ(current: Syllable, next: Syllable): ReturnSyllables { +function handleChoseongIsㅇ(current: Syllable, next: Syllable): ReturnSyllables { const updatedCurrent = { ...current }; const updatedNext = { ...next }; - if (updatedNext.first === 'ㅇ' && hasProperty(음의_동화_받침, updatedCurrent.last)) { - updatedNext.first = 음의_동화_받침[updatedCurrent.last]; - updatedCurrent.last = updatedCurrent.last === 'ㄹㅌ' ? 'ㄹ' : ''; + if (updatedNext.choseong === 'ㅇ' && hasProperty(음의_동화_받침, updatedCurrent.jongseong)) { + updatedNext.choseong = 음의_동화_받침[updatedCurrent.jongseong]; + updatedCurrent.jongseong = updatedCurrent.jongseong === 'ㄹㅌ' ? 'ㄹ' : ''; } return { current: updatedCurrent, next: updatedNext }; } -function handleFirstIsㅎAndㄷ(current: Syllable, next: Syllable): ReturnSyllables { +function handleChoseongIsㅎAndㄷ(current: Syllable, next: Syllable): ReturnSyllables { const updatedCurrent = { ...current }; const updatedNext = { ...next }; - if (updatedNext.first === 'ㅎ' && updatedCurrent.last === 'ㄷ') { - updatedNext.first = 'ㅊ'; - updatedCurrent.last = ''; + if (updatedNext.choseong === 'ㅎ' && updatedCurrent.jongseong === 'ㄷ') { + updatedNext.choseong = 'ㅊ'; + updatedCurrent.jongseong = ''; } return { current: updatedCurrent, next: updatedNext }; } diff --git a/src/standardizePronunciation/rules/transform18th.spec.ts b/src/standardizePronunciation/rules/transform18th.spec.ts index c8f0da0d..f2193cbc 100644 --- a/src/standardizePronunciation/rules/transform18th.spec.ts +++ b/src/standardizePronunciation/rules/transform18th.spec.ts @@ -9,9 +9,9 @@ describe('transform18th', () => { expect(transform18th(current, next)).toEqual({ current: { - first: 'ㅁ', - middle: 'ㅓ', - last: 'ㅇ', + choseong: 'ㅁ', + jungseong: 'ㅓ', + jongseong: 'ㅇ', }, }); }); @@ -22,9 +22,9 @@ describe('transform18th', () => { expect(transform18th(current, next)).toEqual({ current: { - first: 'ㄷ', - middle: 'ㅏ', - last: 'ㄴ', + choseong: 'ㄷ', + jungseong: 'ㅏ', + jongseong: 'ㄴ', }, }); }); @@ -35,9 +35,9 @@ describe('transform18th', () => { expect(transform18th(current, next)).toEqual({ current: { - first: 'ㅈ', - middle: 'ㅏ', - last: 'ㅁ', + choseong: 'ㅈ', + jungseong: 'ㅏ', + jongseong: 'ㅁ', }, }); }); diff --git a/src/standardizePronunciation/rules/transform18th.ts b/src/standardizePronunciation/rules/transform18th.ts index 1f695105..4d806e73 100644 --- a/src/standardizePronunciation/rules/transform18th.ts +++ b/src/standardizePronunciation/rules/transform18th.ts @@ -12,7 +12,7 @@ import { ReturnSyllables, Syllable } from './rules.types'; export function transform18th(currentSyllable: Syllable, nextSyllable: Syllable): Pick { const current = { ...currentSyllable }; - const 제18항주요조건 = current.last && arrayIncludes(['ㄴ', 'ㅁ'], nextSyllable.first); + const 제18항주요조건 = current.jongseong && arrayIncludes(['ㄴ', 'ㅁ'], nextSyllable.choseong); if (!제18항주요조건) { return { @@ -20,16 +20,16 @@ export function transform18th(currentSyllable: Syllable, nextSyllable: Syllable) }; } - if (arrayIncludes(비음화_받침_ㅇ_변환, current.last)) { - current.last = 'ㅇ'; + if (arrayIncludes(비음화_받침_ㅇ_변환, current.jongseong)) { + current.jongseong = 'ㅇ'; } - if (arrayIncludes(비음화_받침_ㄴ_변환, current.last)) { - current.last = 'ㄴ'; + if (arrayIncludes(비음화_받침_ㄴ_변환, current.jongseong)) { + current.jongseong = 'ㄴ'; } - if (arrayIncludes(비음화_받침_ㅁ_변환, current.last)) { - current.last = 'ㅁ'; + if (arrayIncludes(비음화_받침_ㅁ_변환, current.jongseong)) { + current.jongseong = 'ㅁ'; } return { diff --git a/src/standardizePronunciation/rules/transform19th.spec.ts b/src/standardizePronunciation/rules/transform19th.spec.ts index f7858357..41d6db59 100644 --- a/src/standardizePronunciation/rules/transform19th.spec.ts +++ b/src/standardizePronunciation/rules/transform19th.spec.ts @@ -9,9 +9,9 @@ describe('transform19th', () => { expect(transform19th(current, next)).toEqual({ next: { - first: 'ㄴ', - middle: 'ㅕ', - last: 'ㄱ', + choseong: 'ㄴ', + jungseong: 'ㅕ', + jongseong: 'ㄱ', }, }); }); @@ -22,9 +22,9 @@ describe('transform19th', () => { expect(transform19th(current, next)).toEqual({ next: { - first: 'ㄴ', - middle: 'ㅗ', - last: 'ㄴ', + choseong: 'ㄴ', + jungseong: 'ㅗ', + jongseong: 'ㄴ', }, }); }); diff --git a/src/standardizePronunciation/rules/transform19th.ts b/src/standardizePronunciation/rules/transform19th.ts index 2a4b091e..6406705a 100644 --- a/src/standardizePronunciation/rules/transform19th.ts +++ b/src/standardizePronunciation/rules/transform19th.ts @@ -11,10 +11,10 @@ import { ReturnSyllables, Syllable } from './rules.types'; */ export function transform19th(currentSyllable: Syllable, nextSyllable: Syllable): Pick { const next = { ...nextSyllable }; - const 제19항조건 = arrayIncludes(자음동화_받침_ㄴ_변환, currentSyllable.last) && next.first === 'ㄹ'; + const 제19항조건 = arrayIncludes(자음동화_받침_ㄴ_변환, currentSyllable.jongseong) && next.choseong === 'ㄹ'; if (제19항조건) { - next.first = 'ㄴ'; + next.choseong = 'ㄴ'; } return { next }; diff --git a/src/standardizePronunciation/rules/transform20th.spec.ts b/src/standardizePronunciation/rules/transform20th.spec.ts index 9efd4335..b1ffcd19 100644 --- a/src/standardizePronunciation/rules/transform20th.spec.ts +++ b/src/standardizePronunciation/rules/transform20th.spec.ts @@ -9,14 +9,14 @@ describe('transform20th', () => { expect(transform20th(current, next)).toEqual({ current: { - first: 'ㄴ', - middle: 'ㅏ', - last: 'ㄹ', + choseong: 'ㄴ', + jungseong: 'ㅏ', + jongseong: 'ㄹ', }, next: { - first: 'ㄹ', - middle: 'ㅗ', - last: '', + choseong: 'ㄹ', + jungseong: 'ㅗ', + jongseong: '', }, }); }); @@ -27,14 +27,14 @@ describe('transform20th', () => { expect(transform20th(current, next)).toEqual({ current: { - first: 'ㄷ', - middle: 'ㅏ', - last: 'ㄹㅎ', + choseong: 'ㄷ', + jungseong: 'ㅏ', + jongseong: 'ㄹㅎ', }, next: { - first: 'ㄹ', - middle: 'ㅡ', - last: 'ㄴ', + choseong: 'ㄹ', + jungseong: 'ㅡ', + jongseong: 'ㄴ', }, }); }); diff --git a/src/standardizePronunciation/rules/transform20th.ts b/src/standardizePronunciation/rules/transform20th.ts index ef62bae5..970c56d2 100644 --- a/src/standardizePronunciation/rules/transform20th.ts +++ b/src/standardizePronunciation/rules/transform20th.ts @@ -24,8 +24,8 @@ export function transform20th(currentSyllable: Syllable, nextSyllable: Syllable) function applyMainCondition(current: Syllable, next: Syllable): Pick { const updatedCurrent = { ...current }; - if (updatedCurrent.last === 'ㄴ' && next.first === 'ㄹ') { - updatedCurrent.last = 'ㄹ'; + if (updatedCurrent.jongseong === 'ㄴ' && next.choseong === 'ㄹ') { + updatedCurrent.jongseong = 'ㄹ'; } return { current: updatedCurrent }; } @@ -33,8 +33,11 @@ function applyMainCondition(current: Syllable, next: Syllable): Pick { const updatedNext = { ...next }; - if (updatedNext.first === 'ㄴ' && (current.last === 'ㄹ' || arrayIncludes(['ㄹㅎ', 'ㄹㅌ'], current.last))) { - updatedNext.first = 'ㄹ'; + if ( + updatedNext.choseong === 'ㄴ' && + (current.jongseong === 'ㄹ' || arrayIncludes(['ㄹㅎ', 'ㄹㅌ'], current.jongseong)) + ) { + updatedNext.choseong = 'ㄹ'; } return { next: updatedNext }; } diff --git a/src/standardizePronunciation/rules/transform9And10And11th.spec.ts b/src/standardizePronunciation/rules/transform9And10And11th.spec.ts index 6f10d4de..7278ea8b 100644 --- a/src/standardizePronunciation/rules/transform9And10And11th.spec.ts +++ b/src/standardizePronunciation/rules/transform9And10And11th.spec.ts @@ -9,9 +9,9 @@ describe('transform9And10And11th', () => { expect(transform9And10And11th(current, next)).toEqual({ current: { - first: 'ㄷ', - middle: 'ㅏ', - last: 'ㄱ', + choseong: 'ㄷ', + jungseong: 'ㅏ', + jongseong: 'ㄱ', }, }); }); @@ -22,9 +22,9 @@ describe('transform9And10And11th', () => { expect(transform9And10And11th(current, next)).toEqual({ current: { - first: 'ㅇ', - middle: 'ㅏ', - last: 'ㄴ', + choseong: 'ㅇ', + jungseong: 'ㅏ', + jongseong: 'ㄴ', }, }); }); @@ -35,9 +35,9 @@ describe('transform9And10And11th', () => { expect(transform9And10And11th(current, next)).toEqual({ current: { - first: 'ㅎ', - middle: 'ㅡ', - last: 'ㄱ', + choseong: 'ㅎ', + jungseong: 'ㅡ', + jongseong: 'ㄱ', }, }); }); diff --git a/src/standardizePronunciation/rules/transform9And10And11th.ts b/src/standardizePronunciation/rules/transform9And10And11th.ts index 65643fbe..df77a217 100644 --- a/src/standardizePronunciation/rules/transform9And10And11th.ts +++ b/src/standardizePronunciation/rules/transform9And10And11th.ts @@ -16,13 +16,13 @@ export function transform9And10And11th( ): Pick { const current = { ...currentSyllable }; - const is어말 = current.last && !nextSyllable; - const is음가있는자음앞 = current.last && nextSyllable?.first !== 음가가_없는_자음; + const is어말 = current.jongseong && !nextSyllable; + const is음가있는자음앞 = current.jongseong && nextSyllable?.choseong !== 음가가_없는_자음; - const 제9_10_11항주요조건 = (is어말 || is음가있는자음앞) && hasProperty(받침_대표음_발음, current.last); + const 제9_10_11항주요조건 = (is어말 || is음가있는자음앞) && hasProperty(받침_대표음_발음, current.jongseong); if (제9_10_11항주요조건) { - current.last = 받침_대표음_발음[current.last as keyof typeof 받침_대표음_발음]; + current.jongseong = 받침_대표음_발음[current.jongseong as keyof typeof 받침_대표음_발음]; } return { current }; diff --git a/src/standardizePronunciation/rules/transformHardConversion.spec.ts b/src/standardizePronunciation/rules/transformHardConversion.spec.ts index 39323f48..966d43fe 100644 --- a/src/standardizePronunciation/rules/transformHardConversion.spec.ts +++ b/src/standardizePronunciation/rules/transformHardConversion.spec.ts @@ -9,9 +9,9 @@ describe('transformHardConversion', () => { expect(transformHardConversion(current, next)).toEqual({ next: { - first: 'ㅃ', - middle: 'ㅏ', - last: 'ㅂ', + choseong: 'ㅃ', + jungseong: 'ㅏ', + jongseong: 'ㅂ', }, }); }); @@ -22,9 +22,9 @@ describe('transformHardConversion', () => { expect(transformHardConversion(current, next)).toEqual({ next: { - first: 'ㄲ', - middle: 'ㅗ', - last: '', + choseong: 'ㄲ', + jungseong: 'ㅗ', + jongseong: '', }, }); }); @@ -35,9 +35,9 @@ describe('transformHardConversion', () => { expect(transformHardConversion(current, next)).toEqual({ next: { - first: 'ㄲ', - middle: 'ㅔ', - last: '', + choseong: 'ㄲ', + jungseong: 'ㅔ', + jongseong: '', }, }); }); diff --git a/src/standardizePronunciation/rules/transformHardConversion.ts b/src/standardizePronunciation/rules/transformHardConversion.ts index 53275f1d..2b856f08 100644 --- a/src/standardizePronunciation/rules/transformHardConversion.ts +++ b/src/standardizePronunciation/rules/transformHardConversion.ts @@ -17,12 +17,12 @@ export function transformHardConversion( ): Pick { const next = { ...nextSyllable }; - if (hasProperty(된소리, next.first)) { - const 제23항조건 = arrayIncludes(된소리_받침, currentSyllable.last); - const 제24_25항조건 = arrayIncludes(어간_받침, currentSyllable.last) && next.first !== 'ㅂ'; + if (hasProperty(된소리, next.choseong)) { + const 제23항조건 = arrayIncludes(된소리_받침, currentSyllable.jongseong); + const 제24_25항조건 = arrayIncludes(어간_받침, currentSyllable.jongseong) && next.choseong !== 'ㅂ'; if (제23항조건 || 제24_25항조건) { - next.first = 된소리[next.first]; + next.choseong = 된소리[next.choseong]; } } diff --git a/src/standardizePronunciation/rules/transformNLAssimilation.spec.ts b/src/standardizePronunciation/rules/transformNLAssimilation.spec.ts index 5c183a80..b0467421 100644 --- a/src/standardizePronunciation/rules/transformNLAssimilation.spec.ts +++ b/src/standardizePronunciation/rules/transformNLAssimilation.spec.ts @@ -9,14 +9,14 @@ describe('transformNLAssimilation', () => { expect(transformNLAssimilation(current, next)).toEqual({ current: { - first: 'ㅁ', - middle: 'ㅐ', - last: 'ㄴ', + choseong: 'ㅁ', + jungseong: 'ㅐ', + jongseong: 'ㄴ', }, next: { - first: 'ㄴ', - middle: 'ㅣ', - last: 'ㅂ', + choseong: 'ㄴ', + jungseong: 'ㅣ', + jongseong: 'ㅂ', }, }); }); @@ -27,14 +27,14 @@ describe('transformNLAssimilation', () => { expect(transformNLAssimilation(current, next)).toEqual({ current: { - first: 'ㅇ', - middle: 'ㅏ', - last: 'ㄹ', + choseong: 'ㅇ', + jungseong: 'ㅏ', + jongseong: 'ㄹ', }, next: { - first: 'ㄹ', - middle: 'ㅑ', - last: 'ㄱ', + choseong: 'ㄹ', + jungseong: 'ㅑ', + jongseong: 'ㄱ', }, }); }); @@ -45,14 +45,14 @@ describe('transformNLAssimilation', () => { expect(transformNLAssimilation(current, next)).toEqual({ current: { - first: 'ㅇ', - middle: 'ㅑ', - last: 'ㅇ', + choseong: 'ㅇ', + jungseong: 'ㅑ', + jongseong: 'ㅇ', }, next: { - first: 'ㅇ', - middle: 'ㅣ', - last: '', + choseong: 'ㅇ', + jungseong: 'ㅣ', + jongseong: '', }, }); }); diff --git a/src/standardizePronunciation/rules/transformNLAssimilation.ts b/src/standardizePronunciation/rules/transformNLAssimilation.ts index 3f5d0b93..22910c98 100644 --- a/src/standardizePronunciation/rules/transformNLAssimilation.ts +++ b/src/standardizePronunciation/rules/transformNLAssimilation.ts @@ -20,7 +20,7 @@ export function transformNLAssimilation(currentSyllable: Syllable, nextSyllable: let next = { ...nextSyllable }; const ㄴㄹ이덧나는조건 = - current.last && next.first === 'ㅇ' && arrayIncludes(ㄴㄹ이_덧나는_후속음절_모음, next.middle); + current.jongseong && next.choseong === 'ㅇ' && arrayIncludes(ㄴㄹ이_덧나는_후속음절_모음, next.jungseong); if (!ㄴㄹ이덧나는조건) { return { @@ -41,18 +41,18 @@ function applyㄴㄹ덧남(current: Syllable, next: Syllable): ReturnSyllables { const updatedCurrent = { ...current }; const updatedNext = { ...next }; - if (arrayIncludes(ㄴㄹ이_덧나는_모음, updatedCurrent.middle)) { - if (arrayIncludes(ㄴㄹ이_덧나서_받침_ㄴ_변환, updatedCurrent.last)) { - updatedCurrent.last = updatedCurrent.last === 'ㄱ' ? 'ㅇ' : updatedCurrent.last; - updatedNext.first = 'ㄴ'; + if (arrayIncludes(ㄴㄹ이_덧나는_모음, updatedCurrent.jungseong)) { + if (arrayIncludes(ㄴㄹ이_덧나서_받침_ㄴ_변환, updatedCurrent.jongseong)) { + updatedCurrent.jongseong = updatedCurrent.jongseong === 'ㄱ' ? 'ㅇ' : updatedCurrent.jongseong; + updatedNext.choseong = 'ㄴ'; } - if (arrayIncludes(ㄴㄹ이_덧나서_받침_ㄹ_변환, updatedCurrent.last)) { - updatedNext.first = 'ㄹ'; + if (arrayIncludes(ㄴㄹ이_덧나서_받침_ㄹ_변환, updatedCurrent.jongseong)) { + updatedNext.choseong = 'ㄹ'; } } else { // ㄴ/ㄹ이 되기 위한 조건이지만 현재 음절의 중성의 ∙(아래아)가 하나가 아닐 경우에는 덧나지 않고 연음규칙이 적용된다 - updatedNext.first = updatedCurrent.last as typeof updatedNext.first; + updatedNext.choseong = updatedCurrent.jongseong as typeof updatedNext.choseong; } return { current: updatedCurrent, next: updatedNext };