diff --git a/.changeset/kind-birds-provide.md b/.changeset/kind-birds-provide.md new file mode 100644 index 00000000..589c9a22 --- /dev/null +++ b/.changeset/kind-birds-provide.md @@ -0,0 +1,5 @@ +--- +"es-hangul": major +--- + +fix: 일관된 한글 이름 규칙 설정 함수명에서 꼭 필요하지 않다면 hangul이라는 워딩을 제거합니다 diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 1bba496f..3a80ad0e 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -74,4 +74,4 @@ import hangul from 'es-hangul' // hangul default export에 묶어서도 제공 hangul.getSimilarity(...) hangul.disassemble(...) hangul.josa(...) - +``` diff --git a/docs/src/pages/docs/api/getChoseong.en.mdx b/docs/src/pages/docs/api/getChoseong.en.mdx index 0d479ea5..9335dc86 100644 --- a/docs/src/pages/docs/api/getChoseong.en.mdx +++ b/docs/src/pages/docs/api/getChoseong.en.mdx @@ -8,7 +8,7 @@ Extracts the Choseong from a Korean word. (Example: 사과 -> 'ㅅㄱ') ```typescript function getChoseong( - // Korean string from which to extract the choseong + // Korean string from which to extract the choseong word: string ): string; ``` @@ -16,7 +16,7 @@ function getChoseong( ## Examples ```tsx -getChoseong('사과') // 'ㅅㄱ' -getChoseong('리액트') // 'ㄹㅇㅌ' -getChoseong('띄어 쓰기') // 'ㄸㅇ ㅆㄱ' +getChoseong('사과'); // 'ㅅㄱ' +getChoseong('리액트'); // 'ㄹㅇㅌ' +getChoseong('띄어 쓰기'); // 'ㄸㅇ ㅆㄱ' ``` diff --git a/docs/src/pages/docs/api/getChoseong.ko.mdx b/docs/src/pages/docs/api/getChoseong.ko.mdx index 35fd374a..acab11d2 100644 --- a/docs/src/pages/docs/api/getChoseong.ko.mdx +++ b/docs/src/pages/docs/api/getChoseong.ko.mdx @@ -18,7 +18,7 @@ function getChoseong( ## Examples ```tsx -getChoseong('사과') // 'ㅅㄱ' -getChoseong('리액트') // 'ㄹㅇㅌ' -getChoseong('띄어 쓰기') // 'ㄸㅇ ㅆㄱ' +getChoseong('사과'); // 'ㅅㄱ' +getChoseong('리액트'); // 'ㄹㅇㅌ' +getChoseong('띄어 쓰기'); // 'ㄸㅇ ㅆㄱ' ``` diff --git a/docs/src/pages/docs/api/hasBatchim.en.mdx b/docs/src/pages/docs/api/hasBatchim.en.mdx index 4e1c22c8..b5fe9e55 100644 --- a/docs/src/pages/docs/api/hasBatchim.en.mdx +++ b/docs/src/pages/docs/api/hasBatchim.en.mdx @@ -3,20 +3,21 @@ title: hasBatchim --- # hasBatchim + Checks if the last character of a Korean string has a batchim (jongseong). -```typescript +````typescript hasBatchim( - str: string, - // checking for single batchim + str: string, + // checking for single batchim options?: { single?: boolean } ): boolean - + ```typescript hasBatchim('값') // true hasBatchim('토') // false hasBatchim('갑', { single: true }) // true hasBatchim('값', { single: true }) // false hasBatchim('토', { single: true }) // false - ```` +```` diff --git a/docs/src/pages/docs/api/hasBatchim.ko.mdx b/docs/src/pages/docs/api/hasBatchim.ko.mdx index 73cf58c5..73eac438 100644 --- a/docs/src/pages/docs/api/hasBatchim.ko.mdx +++ b/docs/src/pages/docs/api/hasBatchim.ko.mdx @@ -6,19 +6,18 @@ title: hasBatchim 한글 문자열의 마지막 글자가 받침이 있는지 확인합니다. - -```typescript +````typescript hasBatchim( - str: string, + str: string, // 홑받침 여부를 확인할지 여부 options?: { single?: boolean } ): boolean - + ```typescript hasBatchim('값') // true hasBatchim('토') // false hasBatchim('갑', { single: true }) // true hasBatchim('값', { single: true }) // false hasBatchim('토', { single: true }) // false - ```` +```` diff --git a/src/_internal/hangul.spec.ts b/src/_internal/hangul.spec.ts index 684f9272..a2ce1c9f 100644 --- a/src/_internal/hangul.spec.ts +++ b/src/_internal/hangul.spec.ts @@ -1,6 +1,6 @@ import { - binaryAssembleHangulCharacters, - binaryAssembleHangul, + binaryAssembleCharacters, + binaryAssemble, isHangulAlphabet, isHangulCharacter, isHangul, @@ -72,102 +72,102 @@ describe('parse', () => { }); }); -describe('binaryAssembleHangulCharacters', () => { +describe('binaryAssembleCharacters', () => { it('초성과 중성만 조합', () => { - expect(binaryAssembleHangulCharacters('ㄱ', 'ㅏ')).toEqual('가'); + expect(binaryAssembleCharacters('ㄱ', 'ㅏ')).toEqual('가'); }); it('초성과 중성이 합쳐진 문자와 종성을 조합', () => { - expect(binaryAssembleHangulCharacters('가', 'ㅇ')).toEqual('강'); + expect(binaryAssembleCharacters('가', 'ㅇ')).toEqual('강'); }); it('초성과 중성과 종성이 합쳐진 문자와 자음을 조합하여 겹받침 만들기', () => { - expect(binaryAssembleHangulCharacters('갑', 'ㅅ')).toEqual('값'); + expect(binaryAssembleCharacters('갑', 'ㅅ')).toEqual('값'); }); it('초성과 중성이 합쳐진 문자와 모음을 조립하여 겹모음 만들기', () => { - expect(binaryAssembleHangulCharacters('고', 'ㅏ')).toEqual('과'); + expect(binaryAssembleCharacters('고', 'ㅏ')).toEqual('과'); }); it('초성과 중성(겹모음)이 합쳐진 문자와 자음을 조합', () => { - expect(binaryAssembleHangulCharacters('과', 'ㄱ')).toEqual('곽'); + expect(binaryAssembleCharacters('과', 'ㄱ')).toEqual('곽'); }); it('초성과 중성(겹모음)과 종성이 합쳐진 문자와 자음을 조합하여 겹받침 만들기', () => { - expect(binaryAssembleHangulCharacters('완', 'ㅈ')).toEqual('왅'); + expect(binaryAssembleCharacters('완', 'ㅈ')).toEqual('왅'); }); it('모음만 있는 문자와 모음을 조합하여 겹모음 만들기', () => { - expect(binaryAssembleHangulCharacters('ㅗ', 'ㅏ')).toEqual('ㅘ'); + expect(binaryAssembleCharacters('ㅗ', 'ㅏ')).toEqual('ㅘ'); }); it('초성과 중성과 종성이 합쳐진 문자의 연음 법칙', () => { - expect(binaryAssembleHangulCharacters('톳', 'ㅡ')).toEqual('토스'); + expect(binaryAssembleCharacters('톳', 'ㅡ')).toEqual('토스'); }); it('초성과 종성(겹모음)과 종성이 합쳐진 문자의 연음 법칙', () => { - expect(binaryAssembleHangulCharacters('왅', 'ㅓ')).toEqual('완저'); + expect(binaryAssembleCharacters('왅', 'ㅓ')).toEqual('완저'); }); it('초성과 중성과 종성(겹받침)이 합쳐진 문자의 연음 법칙', () => { - expect(binaryAssembleHangulCharacters('닭', 'ㅏ')).toEqual('달가'); - expect(binaryAssembleHangulCharacters('깎', 'ㅏ')).toEqual('까까'); + expect(binaryAssembleCharacters('닭', 'ㅏ')).toEqual('달가'); + expect(binaryAssembleCharacters('깎', 'ㅏ')).toEqual('까까'); }); it('문법에 맞지 않는 문자를 조합하면 단순 Join 한다. (문법 순서 틀림)', () => { - expect(binaryAssembleHangulCharacters('ㅏ', 'ㄱ')).toEqual('ㅏㄱ'); - expect(binaryAssembleHangulCharacters('까', 'ㅃ')).toEqual('까ㅃ'); - expect(binaryAssembleHangulCharacters('ㅘ', 'ㅏ')).toEqual('ㅘㅏ'); + expect(binaryAssembleCharacters('ㅏ', 'ㄱ')).toEqual('ㅏㄱ'); + expect(binaryAssembleCharacters('까', 'ㅃ')).toEqual('까ㅃ'); + expect(binaryAssembleCharacters('ㅘ', 'ㅏ')).toEqual('ㅘㅏ'); }); it('순서대로 입력했을 때 조합이 불가능한 문자라면 단순 Join 한다.', () => { - expect(binaryAssembleHangulCharacters('뼈', 'ㅣ')).toEqual('뼈ㅣ'); + expect(binaryAssembleCharacters('뼈', 'ㅣ')).toEqual('뼈ㅣ'); }); it('소스가 두 글자 이상이라면 Invalid source 에러를 발생시킨다.', () => { - expect(() => binaryAssembleHangulCharacters('가나', 'ㄴ')).toThrowError( + expect(() => binaryAssembleCharacters('가나', 'ㄴ')).toThrowError( 'Invalid source character: 가나. Source must be one character.' ); - expect(() => binaryAssembleHangulCharacters('ㄱㄴ', 'ㅏ')).toThrowError( + expect(() => binaryAssembleCharacters('ㄱㄴ', 'ㅏ')).toThrowError( 'Invalid source character: ㄱㄴ. Source must be one character.' ); }); it('다음 문자가 한글 문자 한 글자가 아니라면 Invalid next character 에러를 발생시킨다.', () => { assert.throws( - () => binaryAssembleHangulCharacters('ㄱ', 'a'), + () => binaryAssembleCharacters('ㄱ', 'a'), Error, 'Invalid next character: a. Next character must be one of the choseong, jungseong, or jongseong.' ); assert.throws( - () => binaryAssembleHangulCharacters('ㄱ', 'ㅡㅏ'), + () => binaryAssembleCharacters('ㄱ', 'ㅡㅏ'), Error, 'Invalid next character: ㅡㅏ. Next character must be one of the choseong, jungseong, or jongseong.' ); }); }); -describe('binaryAssembleHangul', () => { +describe('binaryAssemble', () => { it('문장과 모음을 조합하여 다음 글자를 생성한다.', () => { - expect(binaryAssembleHangul('저는 고양이를 좋아합닏', 'ㅏ')).toEqual('저는 고양이를 좋아합니다'); + expect(binaryAssemble('저는 고양이를 좋아합닏', 'ㅏ')).toEqual('저는 고양이를 좋아합니다'); }); it('문장과 자음을 조합하여 홑받침을 생성한다.', () => { - expect(binaryAssembleHangul('저는 고양이를 좋아하', 'ㅂ')).toEqual('저는 고양이를 좋아합'); + expect(binaryAssemble('저는 고양이를 좋아하', 'ㅂ')).toEqual('저는 고양이를 좋아합'); }); it('문장과 자음을 조합하여 겹받침을 생성한다.', () => { - expect(binaryAssembleHangul('저는 고양이를 좋아합', 'ㅅ')).toEqual('저는 고양이를 좋아핪'); + expect(binaryAssemble('저는 고양이를 좋아합', 'ㅅ')).toEqual('저는 고양이를 좋아핪'); }); it('조합이 불가능한 자음이 입력되면 단순 Join 한다.', () => { - expect(binaryAssembleHangul('저는 고양이를 좋아합', 'ㄲ')).toEqual('저는 고양이를 좋아합ㄲ'); - expect(binaryAssembleHangul('저는 고양이를 좋아합', 'ㅂ')).toEqual('저는 고양이를 좋아합ㅂ'); + expect(binaryAssemble('저는 고양이를 좋아합', 'ㄲ')).toEqual('저는 고양이를 좋아합ㄲ'); + expect(binaryAssemble('저는 고양이를 좋아합', 'ㅂ')).toEqual('저는 고양이를 좋아합ㅂ'); }); it('조합이 불가능한 모음이 입력되면 단순 Join 한다.', () => { - expect(binaryAssembleHangul('저는 고양이를 좋아하', 'ㅏ')).toEqual('저는 고양이를 좋아하ㅏ'); - expect(binaryAssembleHangul('저는 고양이를 좋아합니다', 'ㅜ')).toEqual('저는 고양이를 좋아합니다ㅜ'); + expect(binaryAssemble('저는 고양이를 좋아하', 'ㅏ')).toEqual('저는 고양이를 좋아하ㅏ'); + expect(binaryAssemble('저는 고양이를 좋아합니다', 'ㅜ')).toEqual('저는 고양이를 좋아합니다ㅜ'); }); describe('assertHangul', () => { diff --git a/src/_internal/hangul.ts b/src/_internal/hangul.ts index 5d2c5a7e..00601a21 100644 --- a/src/_internal/hangul.ts +++ b/src/_internal/hangul.ts @@ -1,9 +1,9 @@ import assert, { excludeLastElement, isBlank, joinString } from '.'; import { canBeChoseong, canBeJungseong, canBeJongseong } from '../canBe'; -import { combineHangulCharacter, combineVowels, curriedCombineHangulCharacter } from '../combineHangulCharacter'; +import { combineCharacter, combineVowels, curriedCombineCharacter } from '../combineCharacter'; import { disassembleToGroups } from '../disassemble'; import { hasBatchim } from '../hasBatchim'; -import { removeLastHangulCharacter } from '../removeLastHangulCharacter'; +import { removeLastCharacter } from '../removeLastCharacter'; export function isHangulCharacter(character: string) { return /^[가-힣]$/.test(character); @@ -48,23 +48,23 @@ export function safeParseHangul(actual: unknown): SafeParseSuccess | SafeParseEr } /** - * @name binaryAssembleHangulAlphabets + * @name binaryAssembleAlphabets * @description * 두 개의 한글 자모를 합칩니다. 완성된 한글 문자는 취급하지 않습니다. * @example * ``` - * binaryAssembleHangulAlphabets('ㄱ', 'ㅏ') // 가 - * binaryAssembleHangulAlphabets('ㅗ', 'ㅏ') // ㅘ + * binaryAssembleAlphabets('ㄱ', 'ㅏ') // 가 + * binaryAssembleAlphabets('ㅗ', 'ㅏ') // ㅘ * ``` */ -export function binaryAssembleHangulAlphabets(source: string, nextCharacter: string) { +export function binaryAssembleAlphabets(source: string, nextCharacter: string) { if (canBeJungseong(`${source}${nextCharacter}`)) { return combineVowels(source, nextCharacter); } const isConsonantSource = canBeJungseong(source) === false; if (isConsonantSource && canBeJungseong(nextCharacter)) { - return combineHangulCharacter(source, nextCharacter); + return combineCharacter(source, nextCharacter); } return joinString(source, nextCharacter); @@ -79,15 +79,15 @@ export function linkHangulCharacters(source: string, nextCharacter: string) { const sourceJamo = disassembleToGroups(source)[0]; const [, lastJamo] = excludeLastElement(sourceJamo); - return joinString(removeLastHangulCharacter(source), combineHangulCharacter(lastJamo, nextCharacter)); + return joinString(removeLastCharacter(source), combineCharacter(lastJamo, nextCharacter)); } /** - * @name binaryAssembleHangulCharacters + * @name binaryAssembleCharacters * @description * 인자로 받은 한글 문자 2개를 합성합니다. * ```typescript - * binaryAssembleHangulCharacters( + * binaryAssembleCharacters( * // 소스 문자 * source: string * // 다음 문자 @@ -95,12 +95,12 @@ export function linkHangulCharacters(source: string, nextCharacter: string) { * ): string * ``` * @example - * binaryAssembleHangulCharacters('ㄱ', 'ㅏ') // 가 - * binaryAssembleHangulCharacters('가', 'ㅇ') // 강 - * binaryAssembleHangulCharacters('갑', 'ㅅ') // 값 - * binaryAssembleHangulCharacters('깎', 'ㅏ') // 까까 + * binaryAssembleCharacters('ㄱ', 'ㅏ') // 가 + * binaryAssembleCharacters('가', 'ㅇ') // 강 + * binaryAssembleCharacters('갑', 'ㅅ') // 값 + * binaryAssembleCharacters('깎', 'ㅏ') // 까까 */ -export function binaryAssembleHangulCharacters(source: string, nextCharacter: string) { +export function binaryAssembleCharacters(source: string, nextCharacter: string) { assert( isHangulCharacter(source) || isHangulAlphabet(source), `Invalid source character: ${source}. Source must be one character.` @@ -115,7 +115,7 @@ export function binaryAssembleHangulCharacters(source: string, nextCharacter: st const isSingleCharacter = sourceJamos.length === 1; if (isSingleCharacter) { const sourceCharacter = sourceJamos[0]; - return binaryAssembleHangulAlphabets(sourceCharacter, nextCharacter); + return binaryAssembleAlphabets(sourceCharacter, nextCharacter); } const [restJamos, lastJamo] = excludeLastElement(sourceJamos); @@ -126,7 +126,7 @@ export function binaryAssembleHangulCharacters(source: string, nextCharacter: st return linkHangulCharacters(source, nextCharacter); } - const fixConsonant = curriedCombineHangulCharacter; + const fixConsonant = curriedCombineCharacter; const combineJungseong = fixConsonant(restJamos[0]); if (canBeJungseong(`${lastJamo}${nextCharacter}`)) { @@ -162,11 +162,11 @@ export function binaryAssembleHangulCharacters(source: string, nextCharacter: st } /** - * @name binaryAssembleHangul + * @name binaryAssemble * @description * 인자로 받은 한글 문장과 한글 문자 하나를 합성합니다. * ```typescript - * binaryAssembleHangul( + * binaryAssemble( * // 한글 문장 * source: string * // 한글 문자 @@ -174,18 +174,16 @@ export function binaryAssembleHangulCharacters(source: string, nextCharacter: st * ): string * ``` * @example - * binaryAssembleHangul('저는 고양이를 좋아합닏', 'ㅏ') // 저는 고양이를 좋아합니다 - * binaryAssembleHangul('저는 고양이를 좋아합', 'ㅅ') // 저는 고양이를 좋아핪 - * binaryAssembleHangul('저는 고양이를 좋아하', 'ㅏ') // 저는 고양이를 좋아하ㅏ + * binaryAssemble('저는 고양이를 좋아합닏', 'ㅏ') // 저는 고양이를 좋아합니다 + * binaryAssemble('저는 고양이를 좋아합', 'ㅅ') // 저는 고양이를 좋아핪 + * binaryAssemble('저는 고양이를 좋아하', 'ㅏ') // 저는 고양이를 좋아하ㅏ */ -export function binaryAssembleHangul(source: string, nextCharacter: string) { +export function binaryAssemble(source: string, nextCharacter: string) { const [rest, lastCharacter] = excludeLastElement(source.split('')); const needJoinString = isBlank(lastCharacter) || isBlank(nextCharacter); return joinString( ...rest, - needJoinString - ? joinString(lastCharacter, nextCharacter) - : binaryAssembleHangulCharacters(lastCharacter, nextCharacter) + needJoinString ? joinString(lastCharacter, nextCharacter) : binaryAssembleCharacters(lastCharacter, nextCharacter) ); } diff --git a/src/assemble.spec.ts b/src/assemble.spec.ts index 831a698b..2c4448c5 100644 --- a/src/assemble.spec.ts +++ b/src/assemble.spec.ts @@ -1,13 +1,13 @@ -import { assembleHangul } from './assemble'; +import { assemble } from './assemble'; -describe('assembleHangul', () => { +describe('assemble', () => { it('온전한 한글과 한글 문자 조합', () => { - expect(assembleHangul(['아버지가', ' ', '방ㅇ', 'ㅔ ', '들ㅇ', 'ㅓ갑니다'])).toEqual('아버지가 방에 들어갑니다'); + expect(assemble(['아버지가', ' ', '방ㅇ', 'ㅔ ', '들ㅇ', 'ㅓ갑니다'])).toEqual('아버지가 방에 들어갑니다'); }); it('온전한 한글만 조합', () => { - expect(assembleHangul(['아버지가', ' ', '방에 ', '들어갑니다'])).toEqual('아버지가 방에 들어갑니다'); + expect(assemble(['아버지가', ' ', '방에 ', '들어갑니다'])).toEqual('아버지가 방에 들어갑니다'); }); it('온전하지 않은 한글만 조합', () => { - expect(assembleHangul(['ㅇ', 'ㅏ', 'ㅂ', 'ㅓ', 'ㅈ', 'ㅣ'])).toEqual('아버지'); + expect(assemble(['ㅇ', 'ㅏ', 'ㅂ', 'ㅓ', 'ㅈ', 'ㅣ'])).toEqual('아버지'); }); }); diff --git a/src/assemble.ts b/src/assemble.ts index 554fa8ea..66ebbf06 100644 --- a/src/assemble.ts +++ b/src/assemble.ts @@ -1,22 +1,22 @@ import { disassemble } from './disassemble'; -import { binaryAssembleHangul } from './_internal/hangul'; +import { binaryAssemble } from './_internal/hangul'; /** - * @name assembleHangul + * @name assemble * @description * 인자로 받은 배열에 담긴 한글 문장과 문자를 한글 규칙에 맞게 합성합니다. * ```typescript - * assembleHangul( + * assemble( * // 한글 문자와 문장을 담고 있는 배열 * words: string[] * ): string * ``` * @example - * assembleHangul(['아버지가', ' ', '방ㅇ', 'ㅔ ', '들ㅇ', 'ㅓ갑니다']) // 아버지가 방에 들어갑니다 - * assembleHangul(['아버지가', ' ', '방에 ', '들어갑니다']) // 아버지가 방에 들어갑니다 - * assembleHangul(['ㅇ', 'ㅏ', 'ㅂ', 'ㅓ', 'ㅈ', 'ㅣ']) // 아버지 + * assemble(['아버지가', ' ', '방ㅇ', 'ㅔ ', '들ㅇ', 'ㅓ갑니다']) // 아버지가 방에 들어갑니다 + * assemble(['아버지가', ' ', '방에 ', '들어갑니다']) // 아버지가 방에 들어갑니다 + * assemble(['ㅇ', 'ㅏ', 'ㅂ', 'ㅓ', 'ㅈ', 'ㅣ']) // 아버지 */ -export function assembleHangul(words: string[]) { +export function assemble(words: string[]) { const disassembled = disassemble(words.join('')).split(''); - return disassembled.reduce(binaryAssembleHangul); + return disassembled.reduce(binaryAssemble); } diff --git a/src/combineHangulCharacter.spec.ts b/src/combineCharacter.spec.ts similarity index 66% rename from src/combineHangulCharacter.spec.ts rename to src/combineCharacter.spec.ts index 5bd0845c..1e7e4f24 100644 --- a/src/combineHangulCharacter.spec.ts +++ b/src/combineCharacter.spec.ts @@ -1,32 +1,32 @@ -import { combineHangulCharacter, combineVowels } from './combineHangulCharacter'; +import { combineCharacter, combineVowels } from './combineCharacter'; -describe('combineHangulCharacter', () => { +describe('combineCharacter', () => { it('종성으로 겹받침으로 구성될 수 있는 문자 두 개를 받으면 겹받침을 생성한다. (ㄱ, ㅏ, ㅂㅅ)', () => { - expect(combineHangulCharacter('ㄱ', 'ㅏ', 'ㅂㅅ')).toEqual('값'); + expect(combineCharacter('ㄱ', 'ㅏ', 'ㅂㅅ')).toEqual('값'); }); it('종성이 입력되지 않았다면 받침이 없는 문자로 합성한다. (ㅌ, ㅗ)', () => { - expect(combineHangulCharacter('ㅌ', 'ㅗ')).toEqual('토'); + expect(combineCharacter('ㅌ', 'ㅗ')).toEqual('토'); }); it('종성이 입력되었다면 받침을 추가한다. (ㅌ, ㅗ, ㅅ)', () => { - expect(combineHangulCharacter('ㅌ', 'ㅗ', 'ㅅ')).toEqual('톳'); + expect(combineCharacter('ㅌ', 'ㅗ', 'ㅅ')).toEqual('톳'); }); it('초성이 될 수 없는 문자가 초성으로 입력되면 에러를 반환한다. (ㅏ, ㅏ, ㄱ)', () => { - expect(() => combineHangulCharacter('ㅏ', 'ㅏ', 'ㄱ')).toThrowError('Invalid hangul Characters: ㅏ, ㅏ, ㄱ'); + expect(() => combineCharacter('ㅏ', 'ㅏ', 'ㄱ')).toThrowError('Invalid hangul Characters: ㅏ, ㅏ, ㄱ'); }); it('중성이 될 수 없는 문자가 중성으로 입력되면 에러를 반환한다. (ㄱ, ㄴ, ㅃ)', () => { - expect(() => combineHangulCharacter('ㄱ', 'ㄴ', 'ㅃ')).toThrowError('Invalid hangul Characters: ㄱ, ㄴ, ㅃ'); + expect(() => combineCharacter('ㄱ', 'ㄴ', 'ㅃ')).toThrowError('Invalid hangul Characters: ㄱ, ㄴ, ㅃ'); }); it('종성이 될 수 없는 문자가 종성으로 입력되면 에러를 반환한다. (ㄱ, ㅏ, ㅃ)', () => { - expect(() => combineHangulCharacter('ㄱ', 'ㅏ', 'ㅃ')).toThrowError('Invalid hangul Characters: ㄱ, ㅏ, ㅃ'); + expect(() => combineCharacter('ㄱ', 'ㅏ', 'ㅃ')).toThrowError('Invalid hangul Characters: ㄱ, ㅏ, ㅃ'); }); it('온전한 한글 문자가 하나라도 입력되면 에러를 반환한다. (가, ㅏ, ㄱ)', () => { - expect(() => combineHangulCharacter('가', 'ㅏ', 'ㄱ')).toThrowError('Invalid hangul Characters: 가, ㅏ, ㄱ'); + expect(() => combineCharacter('가', 'ㅏ', 'ㄱ')).toThrowError('Invalid hangul Characters: 가, ㅏ, ㄱ'); }); }); diff --git a/src/combineHangulCharacter.ts b/src/combineCharacter.ts similarity index 81% rename from src/combineHangulCharacter.ts rename to src/combineCharacter.ts index 79e890c3..762d8145 100644 --- a/src/combineHangulCharacter.ts +++ b/src/combineCharacter.ts @@ -8,11 +8,11 @@ import { } from './constants'; /** - * @name combineHangulCharacter + * @name combineCharacter * @description * 인자로 초성, 중성, 종성을 받아 하나의 한글 문자를 반환합니다. * ```typescript - * combineHangulCharacter( + * combineCharacter( * // 초성 * firstCharacter: string * // 중성 @@ -22,10 +22,10 @@ import { * ): string * ``` * @example - * combineHangulCharacter('ㄱ', 'ㅏ', 'ㅂㅅ') // '값' - * combineHangulCharacter('ㅌ', 'ㅗ') // '토' + * combineCharacter('ㄱ', 'ㅏ', 'ㅂㅅ') // '값' + * combineCharacter('ㅌ', 'ㅗ') // '토' */ -export function combineHangulCharacter(firstCharacter: string, middleCharacter: string, lastCharacter = '') { +export function combineCharacter(firstCharacter: string, middleCharacter: string, lastCharacter = '') { if ( canBeChoseong(firstCharacter) === false || canBeJungseong(middleCharacter) === false || @@ -51,19 +51,19 @@ export function combineHangulCharacter(firstCharacter: string, middleCharacter: } /** - * @name curriedCombineHangulCharacter + * @name curriedCombineCharacter * @description - * 인자로 초성, 중성, 종성을 받아 하나의 한글 문자를 반환하는 `combineHangulCharacter` 함수의 커링된 버전입니다. + * 인자로 초성, 중성, 종성을 받아 하나의 한글 문자를 반환하는 `combineCharacter` 함수의 커링된 버전입니다. * @example - * const combineMiddleHangulCharacter = curriedCombineHangulCharacter('ㄱ') + * const combineMiddleHangulCharacter = curriedCombineCharacter('ㄱ') * const combineLastHangulCharacter = combineMiddleHangulCharacter('ㅏ') * combineLastHangulCharacter('ㄱ') // '각' */ -export const curriedCombineHangulCharacter = +export const curriedCombineCharacter = (firstCharacter: string) => (middleCharacter: string) => (lastCharacter = '') => - combineHangulCharacter(firstCharacter, middleCharacter, lastCharacter); + combineCharacter(firstCharacter, middleCharacter, lastCharacter); /** * @name combineVowels diff --git a/src/convertQwertyToHangulAlphabet.spec.ts b/src/convertQwertyToAlphabet.spec.ts similarity index 68% rename from src/convertQwertyToHangulAlphabet.spec.ts rename to src/convertQwertyToAlphabet.spec.ts index 0130e75f..07e1cf2d 100644 --- a/src/convertQwertyToHangulAlphabet.spec.ts +++ b/src/convertQwertyToAlphabet.spec.ts @@ -1,33 +1,33 @@ -import { convertQwertyToHangul, convertQwertyToHangulAlphabet } from './convertQwertyToHangulAlphabet'; +import { convertQwertyToHangul, convertQwertyToAlphabet } from './convertQwertyToAlphabet'; -describe('convertQwertyToHangulAlphabet', () => { +describe('convertQwertyToAlphabet', () => { it('영어 알파벳을 한글 음소로 바꾼다.', () => { - expect(convertQwertyToHangulAlphabet('abc')).toBe('ㅁㅠㅊ'); + expect(convertQwertyToAlphabet('abc')).toBe('ㅁㅠㅊ'); }); it('쌍/자모음에 대응하지 않는 영어 알파벳을 한글 음소로 바꾼다.', () => { - expect(convertQwertyToHangulAlphabet('ABC')).toBe('ㅁㅠㅊ'); + expect(convertQwertyToAlphabet('ABC')).toBe('ㅁㅠㅊ'); }); it('영어 알파벳은 한글 음소로 바꾸고, 한글 음절은 유지한다.', () => { - expect(convertQwertyToHangulAlphabet('vm론트')).toBe('ㅍㅡ론트'); + expect(convertQwertyToAlphabet('vm론트')).toBe('ㅍㅡ론트'); }); it('분해된 한글 음소는 유지한다.', () => { - expect(convertQwertyToHangulAlphabet('ㅍㅡㄹㅗㄴㅌㅡ')).toBe('ㅍㅡㄹㅗㄴㅌㅡ'); + expect(convertQwertyToAlphabet('ㅍㅡㄹㅗㄴㅌㅡ')).toBe('ㅍㅡㄹㅗㄴㅌㅡ'); }); it('영어 알파벳이 아닌 입력은 유지한다.', () => { - expect(convertQwertyToHangulAlphabet('4월/20dlf!')).toBe('4월/20ㅇㅣㄹ!'); + expect(convertQwertyToAlphabet('4월/20dlf!')).toBe('4월/20ㅇㅣㄹ!'); }); it('영문 대문자는 쌍자/모음으로 바꾼다.', () => { - expect(convertQwertyToHangulAlphabet('RㅏㄱEㅜrl')).toBe('ㄲㅏㄱㄸㅜㄱㅣ'); - expect(convertQwertyToHangulAlphabet('ㅇPdml')).toBe('ㅇㅖㅇㅡㅣ'); + expect(convertQwertyToAlphabet('RㅏㄱEㅜrl')).toBe('ㄲㅏㄱㄸㅜㄱㅣ'); + expect(convertQwertyToAlphabet('ㅇPdml')).toBe('ㅇㅖㅇㅡㅣ'); }); it('빈 문자열은 빈 문자열을 반환한다.', () => { - expect(convertQwertyToHangulAlphabet('')).toBe(''); + expect(convertQwertyToAlphabet('')).toBe(''); }); }); diff --git a/src/convertQwertyToHangulAlphabet.ts b/src/convertQwertyToAlphabet.ts similarity index 81% rename from src/convertQwertyToHangulAlphabet.ts rename to src/convertQwertyToAlphabet.ts index e57af259..b4c1ae3f 100644 --- a/src/convertQwertyToHangulAlphabet.ts +++ b/src/convertQwertyToAlphabet.ts @@ -1,15 +1,15 @@ import { hasProperty } from './_internal'; -import { assembleHangul } from './assemble'; +import { assemble } from './assemble'; import { QWERTY_KEYBOARD_MAP } from './constants'; /** - * @name convertQwertyToHangulAlphabet + * @name convertQwertyToAlphabet * @description * 영어 알파벳을 qwerty 자판과 매칭되는 한글 음소로 변환합니다. * @param word 한글 음소로 변환하고자 하는 영문 * @returns 영어 알파벳이 포함되지 않은 한글 음소, 음절, 기타 문자로 이루어진 문자열 */ -export function convertQwertyToHangulAlphabet(word: string): string { +export function convertQwertyToAlphabet(word: string): string { return word .split('') .map(inputText => (hasProperty(QWERTY_KEYBOARD_MAP, inputText) ? QWERTY_KEYBOARD_MAP[inputText] : inputText)) @@ -27,5 +27,5 @@ export function convertQwertyToHangul(word: string): string { if (!word) { return ''; } - return assembleHangul([...convertQwertyToHangulAlphabet(word)]); + return assemble([...convertQwertyToAlphabet(word)]); } diff --git a/src/index.ts b/src/index.ts index 37c1ebad..44ab09b2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,13 +1,14 @@ -export { assembleHangul } from './assemble'; -export { combineHangulCharacter, combineVowels } from './combineHangulCharacter'; -export { convertQwertyToHangul, convertQwertyToHangulAlphabet } from './convertQwertyToHangulAlphabet'; +export { assemble } from './assemble'; +export { combineCharacter, combineVowels } from './combineCharacter'; +export { convertQwertyToHangul, convertQwertyToAlphabet } from './convertQwertyToAlphabet'; export { disassemble, disassembleToGroups } from './disassemble'; export { disassembleCompleteCharacter } from './disassembleCompleteCharacter'; export { josa } from './josa'; -export { removeLastHangulCharacter } from './removeLastHangulCharacter'; +export { removeLastCharacter } from './removeLastCharacter'; export { romanize } from './romanize'; export { standardizePronunciation } from './standardizePronunciation'; export { susa } from './susa'; export { hasBatchim } from './hasBatchim'; export { canBeChoseong, canBeJongseong, canBeJungseong } from './canBe'; export { getChoseong } from './getChoseong'; +export { amountToHangul } from './amountToHangul'; diff --git a/src/removeLastHangulCharacter.spec.ts b/src/removeLastCharacter.spec.ts similarity index 52% rename from src/removeLastHangulCharacter.spec.ts rename to src/removeLastCharacter.spec.ts index 49e74fb9..ded3c260 100644 --- a/src/removeLastHangulCharacter.spec.ts +++ b/src/removeLastCharacter.spec.ts @@ -1,37 +1,37 @@ -import { removeLastHangulCharacter } from './removeLastHangulCharacter'; +import { removeLastCharacter } from './removeLastCharacter'; -describe('removeLastHangulCharacter', () => { +describe('removeLastCharacter', () => { it('마지막 문자가 겹받침인 경우 홑받침으로 바꾼다.', () => { - expect(removeLastHangulCharacter('안녕하세요 값')).toBe('안녕하세요 갑'); - expect(removeLastHangulCharacter('안녕하세요 값이')).toBe('안녕하세요 값ㅇ'); + expect(removeLastCharacter('안녕하세요 값')).toBe('안녕하세요 갑'); + expect(removeLastCharacter('안녕하세요 값이')).toBe('안녕하세요 값ㅇ'); }); it('마지막 문자가 초성과 중성의 조합으로 끝날 경우 초성만 남긴다.', () => { - expect(removeLastHangulCharacter('프론트엔드')).toBe('프론트엔ㄷ'); - expect(removeLastHangulCharacter('끓다')).toBe('끓ㄷ'); - expect(removeLastHangulCharacter('관사')).toBe('관ㅅ'); - expect(removeLastHangulCharacter('괴사')).toBe('괴ㅅ'); + expect(removeLastCharacter('프론트엔드')).toBe('프론트엔ㄷ'); + expect(removeLastCharacter('끓다')).toBe('끓ㄷ'); + expect(removeLastCharacter('관사')).toBe('관ㅅ'); + expect(removeLastCharacter('괴사')).toBe('괴ㅅ'); }); it('마지막 문자가 초성과 중성과 종성의 조합으로 끝날 경우 초성과 중성이 조합된 문자만 남긴다.', () => { - expect(removeLastHangulCharacter('일요일')).toBe('일요이'); - expect(removeLastHangulCharacter('완전')).toBe('완저'); - expect(removeLastHangulCharacter('왅전')).toBe('왅저'); - expect(removeLastHangulCharacter('깎')).toBe('까'); + expect(removeLastCharacter('일요일')).toBe('일요이'); + expect(removeLastCharacter('완전')).toBe('완저'); + expect(removeLastCharacter('왅전')).toBe('왅저'); + expect(removeLastCharacter('깎')).toBe('까'); }); it('마지막 문자가 초성과 중성의 조합으로 끝나며, 중성 입력 시 국제 표준 한글 레이아웃 기준 단일키로 처리되지 않는 이중모음 (ㅗ/ㅜ/ㅡ 계 이중모음) 인 경우 초성과 중성의 시작 모음만 남긴다.', () => { - expect(removeLastHangulCharacter('전화')).toBe('전호'); - expect(removeLastHangulCharacter('예의')).toBe('예으'); - expect(removeLastHangulCharacter('신세계')).toBe('신세ㄱ'); // 'ㅖ'의 경우 단일키 처리가 가능한 이중모음이므로 모음이 남지 않는다. + expect(removeLastCharacter('전화')).toBe('전호'); + expect(removeLastCharacter('예의')).toBe('예으'); + expect(removeLastCharacter('신세계')).toBe('신세ㄱ'); // 'ㅖ'의 경우 단일키 처리가 가능한 이중모음이므로 모음이 남지 않는다. }); it('마지막 문자가 초성과 중성과 종성의 조합으로 끝나며, 중성 입력 시 국제 표준 한글 레이아웃 기준 단일키로 처리되지 않는 이중모음 (ㅗ/ㅜ/ㅡ 계 이중모음) 인 경우 초성과 중성만 남긴다.', () => { - expect(removeLastHangulCharacter('수확')).toBe('수화'); + expect(removeLastCharacter('수확')).toBe('수화'); }); it('마지막 문자가 초성과 중성과 종성의 조합으로 끝나며, 종성이 겹자음인 경우 초성과 중성과 종성의 시작 자음만 남긴다.', () => { - expect(removeLastHangulCharacter('끓')).toBe('끌'); + expect(removeLastCharacter('끓')).toBe('끌'); }); it('마지막 문자가 초성과 중성과 종성의 조합으로 끝나며, 중성 입력 시 국제 표준 한글 레이아웃 기준 단일키로 처리되지 않는 이중모음 (ㅗ/ㅜ/ㅡ 계 이중모음)이고 종성이 겹자음인 경우 초성과 중성과 종성의 시작 자음만 남긴다.', () => { - expect(removeLastHangulCharacter('왅')).toBe('완'); + expect(removeLastCharacter('왅')).toBe('완'); }); it('빈 문자열일 경우 빈 문자열을 반환한다.', () => { - expect(removeLastHangulCharacter('')).toBe(''); + expect(removeLastCharacter('')).toBe(''); }); }); diff --git a/src/removeLastCharacter.ts b/src/removeLastCharacter.ts new file mode 100644 index 00000000..0aed34fe --- /dev/null +++ b/src/removeLastCharacter.ts @@ -0,0 +1,49 @@ +import { combineCharacter } from './combineCharacter'; +import { excludeLastElement } from './_internal'; +import { canBeJungseong } from './canBe'; +import { disassembleToGroups } from './disassemble'; + +/** + * @name removeLastCharacter + * @description + * 인자로 주어진 한글 문자열에서 가장 마지막 문자 하나를 제거하여 반환합니다. + * ```typescript + * removeLastCharacter( + * // 한글 문자열 + * words: string + * ): string + * ``` + * @example + * removeLastCharacter('안녕하세요 값') // 안녕하세요 갑 + * removeLastCharacter('프론트엔드') // 프론트엔ㄷ + * removeLastCharacter('일요일') // 일요이 + * removeLastCharacter('전화') // 전호 + * removeLastCharacter('신세계') // 신세ㄱ + */ +export function removeLastCharacter(words: string) { + const lastCharacter = words[words.length - 1]; + if (lastCharacter == null) { + return ''; + } + + const result = (() => { + const disassembleLastCharacter = disassembleToGroups(lastCharacter); + const [lastCharacterWithoutLastAlphabet] = excludeLastElement(disassembleLastCharacter[0]); + if (lastCharacterWithoutLastAlphabet.length <= 3) { + const [first, middle, last] = lastCharacterWithoutLastAlphabet; + if (middle != null) { + return canBeJungseong(last) + ? combineCharacter(first, `${middle}${last}`) + : combineCharacter(first, middle, last); + } + + return first; + } else { + const [first, firstJungsung, secondJungsung, firstJongsung] = lastCharacterWithoutLastAlphabet; + + return combineCharacter(first, `${firstJungsung}${secondJungsung}`, firstJongsung); + } + })(); + + return [words.substring(0, words.length - 1), result].join(''); +} diff --git a/src/removeLastHangulCharacter.ts b/src/removeLastHangulCharacter.ts index 07160aca..0aed34fe 100644 --- a/src/removeLastHangulCharacter.ts +++ b/src/removeLastHangulCharacter.ts @@ -1,26 +1,26 @@ -import { combineHangulCharacter } from './combineHangulCharacter'; +import { combineCharacter } from './combineCharacter'; import { excludeLastElement } from './_internal'; import { canBeJungseong } from './canBe'; import { disassembleToGroups } from './disassemble'; /** - * @name removeLastHangulCharacter + * @name removeLastCharacter * @description * 인자로 주어진 한글 문자열에서 가장 마지막 문자 하나를 제거하여 반환합니다. * ```typescript - * removeLastHangulCharacter( + * removeLastCharacter( * // 한글 문자열 * words: string * ): string * ``` * @example - * removeLastHangulCharacter('안녕하세요 값') // 안녕하세요 갑 - * removeLastHangulCharacter('프론트엔드') // 프론트엔ㄷ - * removeLastHangulCharacter('일요일') // 일요이 - * removeLastHangulCharacter('전화') // 전호 - * removeLastHangulCharacter('신세계') // 신세ㄱ + * removeLastCharacter('안녕하세요 값') // 안녕하세요 갑 + * removeLastCharacter('프론트엔드') // 프론트엔ㄷ + * removeLastCharacter('일요일') // 일요이 + * removeLastCharacter('전화') // 전호 + * removeLastCharacter('신세계') // 신세ㄱ */ -export function removeLastHangulCharacter(words: string) { +export function removeLastCharacter(words: string) { const lastCharacter = words[words.length - 1]; if (lastCharacter == null) { return ''; @@ -33,15 +33,15 @@ export function removeLastHangulCharacter(words: string) { const [first, middle, last] = lastCharacterWithoutLastAlphabet; if (middle != null) { return canBeJungseong(last) - ? combineHangulCharacter(first, `${middle}${last}`) - : combineHangulCharacter(first, middle, last); + ? combineCharacter(first, `${middle}${last}`) + : combineCharacter(first, middle, last); } return first; } else { const [first, firstJungsung, secondJungsung, firstJongsung] = lastCharacterWithoutLastAlphabet; - return combineHangulCharacter(first, `${firstJungsung}${secondJungsung}`, firstJongsung); + return combineCharacter(first, `${firstJungsung}${secondJungsung}`, firstJongsung); } })(); diff --git a/src/romanize.ts b/src/romanize.ts index 14955228..f2d5f7a7 100644 --- a/src/romanize.ts +++ b/src/romanize.ts @@ -1,9 +1,9 @@ import { isHangulCharacter } from './_internal/hangul'; -import { assembleHangul } from './assemble'; +import { assemble } from './assemble'; +import { canBeChoseong } from './canBe'; import { 종성_알파벳_발음, 중성_알파벳_발음, 초성_알파벳_발음 } from './constants'; -import { disassembleCompleteHangulCharacter } from './disassembleCompleteHangulCharacter'; +import { disassembleCompleteCharacter } from './disassembleCompleteCharacter'; import { standardizePronunciation } from './standardizePronunciation'; -import { canBeChoseong } from './utils'; /** * 주어진 한글 문자열을 로마자로 변환합니다. @@ -23,17 +23,17 @@ const romanizeSyllableHangul = (arrayHangul: string[], index: number): string => const syllable = arrayHangul[index]; if (isHangulCharacter(syllable)) { - const disassemble = disassembleCompleteHangulCharacter(syllable) as NonNullable< - ReturnType + const disassemble = disassembleCompleteCharacter(syllable) as NonNullable< + ReturnType >; let choseong: (typeof 초성_알파벳_발음)[keyof typeof 초성_알파벳_발음] | 'l' = 초성_알파벳_발음[disassemble.first]; - const jungseong = 중성_알파벳_발음[assembleHangul([disassemble.middle]) as keyof typeof 중성_알파벳_발음]; + const jungseong = 중성_알파벳_발음[assemble([disassemble.middle]) as keyof typeof 중성_알파벳_발음]; const jongseong = 종성_알파벳_발음[disassemble.last as keyof typeof 종성_알파벳_발음]; // 'ㄹ'은 모음 앞에서는 'r'로, 자음 앞이나 어말에서는 'l'로 적는다. 단, 'ㄹㄹ'은 'll'로 적는다. (ex.울릉, 대관령), if (disassemble.first === 'ㄹ' && index > 0 && isHangulCharacter(arrayHangul[index - 1])) { - const prevDisassemble = disassembleCompleteHangulCharacter(arrayHangul[index - 1]); + const prevDisassemble = disassembleCompleteCharacter(arrayHangul[index - 1]); if (prevDisassemble?.last === 'ㄹ') { choseong = 'l'; diff --git a/src/standardizePronunciation/index.ts b/src/standardizePronunciation/index.ts index 847ef6b4..5700f1fd 100644 --- a/src/standardizePronunciation/index.ts +++ b/src/standardizePronunciation/index.ts @@ -1,7 +1,7 @@ import { isNotUndefined, joinString } from '../_internal'; import { isHangulAlphabet, isHangulCharacter } from '../_internal/hangul'; -import { combineHangulCharacter } from '../combineHangulCharacter'; -import { disassembleCompleteHangulCharacter } from '../disassembleCompleteHangulCharacter'; +import { combineCharacter } from '../combineCharacter'; +import { disassembleCompleteCharacter } from '../disassembleCompleteCharacter'; import { transform12th, transform13And14th, @@ -88,7 +88,7 @@ function 음절분해(hangulPhrase: string): { return true; }) - .map(disassembleCompleteHangulCharacter) + .map(disassembleCompleteCharacter) .filter(isNotUndefined); return { notHangulPhrase, disassembleHangul }; @@ -146,7 +146,7 @@ function applyRules(params: ApplyParameters): { function assembleChangedHangul(disassembleHangul: Syllable[], notHangulPhrase: NotHangul[]): string { const changedSyllables = disassembleHangul .filter(isNotUndefined) - .map(syllable => combineHangulCharacter(syllable.first, syllable.middle, syllable.last)); + .map(syllable => combineCharacter(syllable.first, syllable.middle, syllable.last)); for (const { index, syllable } of notHangulPhrase) { changedSyllables.splice(index, 0, syllable); diff --git a/src/standardizePronunciation/rules/rules.types.ts b/src/standardizePronunciation/rules/rules.types.ts index 46eca0d6..53cf6fbb 100644 --- a/src/standardizePronunciation/rules/rules.types.ts +++ b/src/standardizePronunciation/rules/rules.types.ts @@ -1,8 +1,8 @@ -import { disassembleCompleteHangulCharacter } from '../../disassembleCompleteHangulCharacter'; +import { disassembleCompleteCharacter } from '../../disassembleCompleteCharacter'; export type NonUndefined = T extends undefined ? never : T; export type Nullable = T | null | undefined; -export type Syllable = NonUndefined>; +export type Syllable = NonUndefined>; export type ReturnSyllables = { current: Syllable; next: Syllable; diff --git a/src/standardizePronunciation/rules/transform12th.spec.ts b/src/standardizePronunciation/rules/transform12th.spec.ts index be0c23d3..5a649def 100644 --- a/src/standardizePronunciation/rules/transform12th.spec.ts +++ b/src/standardizePronunciation/rules/transform12th.spec.ts @@ -1,11 +1,11 @@ import { defined } from '../../_internal'; -import { disassembleCompleteHangulCharacter } from '../../disassembleCompleteHangulCharacter'; +import { disassembleCompleteCharacter } from '../../disassembleCompleteCharacter'; import { transform12th } from './transform12th'; describe('transform12th', () => { it('"ㅎ, ㄶ, ㅀ" 뒤에 "ㄱ, ㄷ, ㅈ"이 결합되는 경우에는, 뒤 음절 첫소리와 합쳐서 "ㅋ, ㅌ, ㅊ"으로 발음한다', () => { - const current = defined(disassembleCompleteHangulCharacter('놓')); - const next = defined(disassembleCompleteHangulCharacter('고')); + const current = defined(disassembleCompleteCharacter('놓')); + const next = defined(disassembleCompleteCharacter('고')); expect(transform12th(current, next)).toEqual({ current: { @@ -22,8 +22,8 @@ describe('transform12th', () => { }); it('받침 "ㄱ, ㄺ, ㄷ, ㅂ, ㄼ, ㅈ, ㄵ"이 뒤 음절 첫소리 "ㅎ"과 결합되는 경우에도, 역시 두 음을 합쳐서 "ㅋ, ㅌ, ㅍ, ㅊ"으로 발음한다', () => { - const current = defined(disassembleCompleteHangulCharacter('각')); - const next = defined(disassembleCompleteHangulCharacter('하')); + const current = defined(disassembleCompleteCharacter('각')); + const next = defined(disassembleCompleteCharacter('하')); expect(transform12th(current, next)).toEqual({ current: { @@ -40,8 +40,8 @@ describe('transform12th', () => { }); it('"ㅎ, ㄶ, ㅀ" 뒤에 "ㅅ"이 결합되는 경우에는, "ㅅ"을 "ㅆ"으로 발음한다', () => { - const current = defined(disassembleCompleteHangulCharacter('닿')); - const next = defined(disassembleCompleteHangulCharacter('소')); + const current = defined(disassembleCompleteCharacter('닿')); + const next = defined(disassembleCompleteCharacter('소')); expect(transform12th(current, next)).toEqual({ current: { @@ -58,8 +58,8 @@ describe('transform12th', () => { }); it('"ㅎ" 뒤에 "ㄴ"이 결합되는 경우에는 "ㄴ"으로 발음한다', () => { - const current = defined(disassembleCompleteHangulCharacter('놓')); - const next = defined(disassembleCompleteHangulCharacter('는')); + const current = defined(disassembleCompleteCharacter('놓')); + const next = defined(disassembleCompleteCharacter('는')); expect(transform12th(current, next)).toEqual({ current: { @@ -76,8 +76,8 @@ describe('transform12th', () => { }); it('"ㄶ, ㅀ" 뒤에 "ㄴ"이 결합되는 경우에는, "ㅎ"을 발음하지 않는다', () => { - const current = defined(disassembleCompleteHangulCharacter('않')); - const next = defined(disassembleCompleteHangulCharacter('네')); + const current = defined(disassembleCompleteCharacter('않')); + const next = defined(disassembleCompleteCharacter('네')); expect(transform12th(current, next)).toEqual({ current: { @@ -94,8 +94,8 @@ describe('transform12th', () => { }); it('"ㅎ, ㄶ, ㅀ" 뒤에 모음으로 시작된 어미나 접미사가 결합되는 경우에는 "ㅎ"을 발음하지 않는다', () => { - const current = defined(disassembleCompleteHangulCharacter('낳')); - const next = defined(disassembleCompleteHangulCharacter('은')); + const current = defined(disassembleCompleteCharacter('낳')); + const next = defined(disassembleCompleteCharacter('은')); expect(transform12th(current, next)).toEqual({ current: { @@ -112,7 +112,7 @@ describe('transform12th', () => { }); it('"ㅎ, ㄶ, ㅀ" 뒤에 모음으로 시작된 어미나 접미사가 결합되는 경우에는 "ㅎ"을 발음하지 않는다', () => { - const current = defined(disassembleCompleteHangulCharacter('많')); + const current = defined(disassembleCompleteCharacter('많')); const next = null; expect(transform12th(current, next)).toEqual({ diff --git a/src/standardizePronunciation/rules/transform13And14th.spec.ts b/src/standardizePronunciation/rules/transform13And14th.spec.ts index 671b9687..f09e636a 100644 --- a/src/standardizePronunciation/rules/transform13And14th.spec.ts +++ b/src/standardizePronunciation/rules/transform13And14th.spec.ts @@ -1,11 +1,11 @@ import { defined } from '../../_internal'; -import { disassembleCompleteHangulCharacter } from '../../disassembleCompleteHangulCharacter'; +import { disassembleCompleteCharacter } from '../../disassembleCompleteCharacter'; import { transform13And14th } from './transform13And14th'; describe('transform13And14th', () => { it('13항을 적용합니다.', () => { - const current = defined(disassembleCompleteHangulCharacter('깎')); - const next = defined(disassembleCompleteHangulCharacter('아')); + const current = defined(disassembleCompleteCharacter('깎')); + const next = defined(disassembleCompleteCharacter('아')); expect(transform13And14th(current, next)).toEqual({ current: { @@ -22,8 +22,8 @@ describe('transform13And14th', () => { }); it('14항을 적용합니다.', () => { - const current = defined(disassembleCompleteHangulCharacter('닭')); - const next = defined(disassembleCompleteHangulCharacter('을')); + const current = defined(disassembleCompleteCharacter('닭')); + const next = defined(disassembleCompleteCharacter('을')); expect(transform13And14th(current, next)).toEqual({ current: { diff --git a/src/standardizePronunciation/rules/transform16th.spec.ts b/src/standardizePronunciation/rules/transform16th.spec.ts index e226bdd1..ee38a500 100644 --- a/src/standardizePronunciation/rules/transform16th.spec.ts +++ b/src/standardizePronunciation/rules/transform16th.spec.ts @@ -1,11 +1,11 @@ import { defined } from '../../_internal'; -import { disassembleCompleteHangulCharacter } from '../../disassembleCompleteHangulCharacter'; +import { disassembleCompleteCharacter } from '../../disassembleCompleteCharacter'; import { transform16th } from './transform16th'; describe('transform16th', () => { it('한글 자모의 이름은 그 받침소리를 연음하되, "ㄷ, ㅈ, ㅊ, ㅋ, ㅌ, ㅍ, ㅎ"의 경우에는 특별히 다음과 같이 발음한다', () => { - const current = defined(disassembleCompleteHangulCharacter('귿')); - const next = defined(disassembleCompleteHangulCharacter('이')); + const current = defined(disassembleCompleteCharacter('귿')); + const next = defined(disassembleCompleteCharacter('이')); const phrase = '디귿이'; const index = 1; @@ -31,8 +31,8 @@ describe('transform16th', () => { }); it('자모의 이름이 "ㄱ, ㄴ, ㄹ, ㅁ, ㅂ, ㅅ, ㅇ"일 경우', () => { - const current = defined(disassembleCompleteHangulCharacter('역')); - const next = defined(disassembleCompleteHangulCharacter('이')); + const current = defined(disassembleCompleteCharacter('역')); + const next = defined(disassembleCompleteCharacter('이')); const phrase = '기역이'; const index = 1; diff --git a/src/standardizePronunciation/rules/transform17th.spec.ts b/src/standardizePronunciation/rules/transform17th.spec.ts index aab32447..a371d420 100644 --- a/src/standardizePronunciation/rules/transform17th.spec.ts +++ b/src/standardizePronunciation/rules/transform17th.spec.ts @@ -1,11 +1,11 @@ import { defined } from '../../_internal'; -import { disassembleCompleteHangulCharacter } from '../../disassembleCompleteHangulCharacter'; +import { disassembleCompleteCharacter } from '../../disassembleCompleteCharacter'; import { transform17th } from './transform17th'; describe('transform17th', () => { it('받침 "ㄷ", "ㅌ(ㄾ)"이 조사나 접미사의 모음 "ㅣ"와 결합되는 경우에는, "ㅈ", "ㅊ"으로 바꾸어서 뒤 음절 첫소리로 옮겨 발음한다', () => { - const current = defined(disassembleCompleteHangulCharacter('굳')); - const next = defined(disassembleCompleteHangulCharacter('이')); + const current = defined(disassembleCompleteCharacter('굳')); + const next = defined(disassembleCompleteCharacter('이')); expect(transform17th(current, next)).toEqual({ current: { @@ -22,8 +22,8 @@ describe('transform17th', () => { }); it('"ㄷ" 뒤에 접미사 "히"가 결합되어 "티"를 이루는 것은 "치"로 발음한다', () => { - const current = defined(disassembleCompleteHangulCharacter('굳')); - const next = defined(disassembleCompleteHangulCharacter('히')); + const current = defined(disassembleCompleteCharacter('굳')); + const next = defined(disassembleCompleteCharacter('히')); expect(transform17th(current, next)).toEqual({ current: { diff --git a/src/standardizePronunciation/rules/transform17th.ts b/src/standardizePronunciation/rules/transform17th.ts index bf3ab074..094a714c 100644 --- a/src/standardizePronunciation/rules/transform17th.ts +++ b/src/standardizePronunciation/rules/transform17th.ts @@ -1,4 +1,4 @@ -import { hasProperty } from '../../utils'; +import { hasProperty } from '../../_internal'; import { 음의_동화_받침 } from '../standardizePronunciation.constants'; import { ReturnSyllables, Syllable } from './rules.types'; diff --git a/src/standardizePronunciation/rules/transform18th.spec.ts b/src/standardizePronunciation/rules/transform18th.spec.ts index f7146469..c8f0da0d 100644 --- a/src/standardizePronunciation/rules/transform18th.spec.ts +++ b/src/standardizePronunciation/rules/transform18th.spec.ts @@ -1,11 +1,11 @@ import { defined } from '../../_internal'; -import { disassembleCompleteHangulCharacter } from '../../disassembleCompleteHangulCharacter'; +import { disassembleCompleteCharacter } from '../../disassembleCompleteCharacter'; import { transform18th } from './transform18th'; describe('transform18th', () => { it('받침 "ㄱ, ㄲ, ㅋ, ㄳ, ㄺ"일 경우', () => { - const current = defined(disassembleCompleteHangulCharacter('먹')); - const next = defined(disassembleCompleteHangulCharacter('는')); + const current = defined(disassembleCompleteCharacter('먹')); + const next = defined(disassembleCompleteCharacter('는')); expect(transform18th(current, next)).toEqual({ current: { @@ -17,8 +17,8 @@ describe('transform18th', () => { }); it('받침 "ㄷ, ㅅ, ㅆ, ㅈ, ㅊ, ㅌ, ㅎ"일 경우', () => { - const current = defined(disassembleCompleteHangulCharacter('닫')); - const next = defined(disassembleCompleteHangulCharacter('는')); + const current = defined(disassembleCompleteCharacter('닫')); + const next = defined(disassembleCompleteCharacter('는')); expect(transform18th(current, next)).toEqual({ current: { @@ -30,8 +30,8 @@ describe('transform18th', () => { }); it('받침 "ㅂ, ㅍ, ㄼ, ㄿ, ㅄ"일 경우', () => { - const current = defined(disassembleCompleteHangulCharacter('잡')); - const next = defined(disassembleCompleteHangulCharacter('는')); + const current = defined(disassembleCompleteCharacter('잡')); + const next = defined(disassembleCompleteCharacter('는')); expect(transform18th(current, next)).toEqual({ current: { diff --git a/src/standardizePronunciation/rules/transform19th.spec.ts b/src/standardizePronunciation/rules/transform19th.spec.ts index b15c3434..f7858357 100644 --- a/src/standardizePronunciation/rules/transform19th.spec.ts +++ b/src/standardizePronunciation/rules/transform19th.spec.ts @@ -1,11 +1,11 @@ import { defined } from '../../_internal'; -import { disassembleCompleteHangulCharacter } from '../../disassembleCompleteHangulCharacter'; +import { disassembleCompleteCharacter } from '../../disassembleCompleteCharacter'; import { transform19th } from './transform19th'; describe('transform19th', () => { it('받침 "ㅁ, ㅇ" 뒤에 연결되는 "ㄹ"은 "ㄴ"으로 발음한다', () => { - const current = defined(disassembleCompleteHangulCharacter('담')); - const next = defined(disassembleCompleteHangulCharacter('력')); + const current = defined(disassembleCompleteCharacter('담')); + const next = defined(disassembleCompleteCharacter('력')); expect(transform19th(current, next)).toEqual({ next: { @@ -17,8 +17,8 @@ describe('transform19th', () => { }); it('받침 "ㄱ, ㅂ" 뒤에 연결되는 "ㄹ"도 "ㄴ"으로 발음한다', () => { - const current = defined(disassembleCompleteHangulCharacter('막')); - const next = defined(disassembleCompleteHangulCharacter('론')); + const current = defined(disassembleCompleteCharacter('막')); + const next = defined(disassembleCompleteCharacter('론')); expect(transform19th(current, next)).toEqual({ next: { diff --git a/src/standardizePronunciation/rules/transform20th.spec.ts b/src/standardizePronunciation/rules/transform20th.spec.ts index c61ad2e0..9efd4335 100644 --- a/src/standardizePronunciation/rules/transform20th.spec.ts +++ b/src/standardizePronunciation/rules/transform20th.spec.ts @@ -1,11 +1,11 @@ import { defined } from '../../_internal'; -import { disassembleCompleteHangulCharacter } from '../../disassembleCompleteHangulCharacter'; +import { disassembleCompleteCharacter } from '../../disassembleCompleteCharacter'; import { transform20th } from './transform20th'; describe('transform20th', () => { it('"ㄴ"은 "ㄹ"의 앞이나 뒤에서 "ㄹ"로 발음한다', () => { - const current = defined(disassembleCompleteHangulCharacter('난')); - const next = defined(disassembleCompleteHangulCharacter('로')); + const current = defined(disassembleCompleteCharacter('난')); + const next = defined(disassembleCompleteCharacter('로')); expect(transform20th(current, next)).toEqual({ current: { @@ -22,8 +22,8 @@ describe('transform20th', () => { }); it('첫소리 "ㄴ"이 "ㅀ, ㄾ" 뒤에 연결되는 경우에도 "ㄹ"로 발음한다', () => { - const current = defined(disassembleCompleteHangulCharacter('닳')); - const next = defined(disassembleCompleteHangulCharacter('는')); + const current = defined(disassembleCompleteCharacter('닳')); + const next = defined(disassembleCompleteCharacter('는')); expect(transform20th(current, next)).toEqual({ current: { diff --git a/src/standardizePronunciation/rules/transform9And10And11th.spec.ts b/src/standardizePronunciation/rules/transform9And10And11th.spec.ts index b19a7d43..6f10d4de 100644 --- a/src/standardizePronunciation/rules/transform9And10And11th.spec.ts +++ b/src/standardizePronunciation/rules/transform9And10And11th.spec.ts @@ -1,11 +1,11 @@ import { defined } from '../../_internal'; -import { disassembleCompleteHangulCharacter } from '../../disassembleCompleteHangulCharacter'; +import { disassembleCompleteCharacter } from '../../disassembleCompleteCharacter'; import { transform9And10And11th } from './transform9And10And11th'; describe('transform9And10And11th', () => { it('9항 - 받침 "ㄲ, ㅋ" / "ㅅ, ㅆ, ㅈ, ㅊ, ㅌ" / "ㅍ"은 어말 또는 자음 앞에서 각각 대표음 "ㄱ, ㄷ, ㅂ"으로 발음한다.', () => { - const current = defined(disassembleCompleteHangulCharacter('닦')); - const next = disassembleCompleteHangulCharacter('다'); + const current = defined(disassembleCompleteCharacter('닦')); + const next = disassembleCompleteCharacter('다'); expect(transform9And10And11th(current, next)).toEqual({ current: { @@ -17,8 +17,8 @@ describe('transform9And10And11th', () => { }); it('10항 - 겹받침 "ㄳ" / "ㄵ" / "ㄼ, ㄽ, ㄾ" / "ㅄ"은 어말 또는 자음 앞에서 각각 "ㄱ, ㄴ, ㄹ, ㅂ"으로 발음한다.', () => { - const current = defined(disassembleCompleteHangulCharacter('앉')); - const next = disassembleCompleteHangulCharacter('다'); + const current = defined(disassembleCompleteCharacter('앉')); + const next = disassembleCompleteCharacter('다'); expect(transform9And10And11th(current, next)).toEqual({ current: { @@ -30,8 +30,8 @@ describe('transform9And10And11th', () => { }); it('11항 - 겹받침 "ㄺ" / "ㄻ" / "ㄿ"은 어말 또는 자음 앞에서 각각 "ㄱ, ㅁ, ㅂ"으로 발음한다.', () => { - const current = defined(disassembleCompleteHangulCharacter('흙')); - const next = disassembleCompleteHangulCharacter('과'); + const current = defined(disassembleCompleteCharacter('흙')); + const next = disassembleCompleteCharacter('과'); expect(transform9And10And11th(current, next)).toEqual({ current: { diff --git a/src/standardizePronunciation/rules/transform9And10And11th.ts b/src/standardizePronunciation/rules/transform9And10And11th.ts index 5886c250..65643fbe 100644 --- a/src/standardizePronunciation/rules/transform9And10And11th.ts +++ b/src/standardizePronunciation/rules/transform9And10And11th.ts @@ -1,4 +1,4 @@ -import { hasProperty } from '../../utils'; +import { hasProperty } from '../../_internal'; import { 받침_대표음_발음, 음가가_없는_자음 } from '../standardizePronunciation.constants'; import { Nullable, ReturnSyllables, Syllable } from './rules.types'; diff --git a/src/standardizePronunciation/rules/transformHardConversion.spec.ts b/src/standardizePronunciation/rules/transformHardConversion.spec.ts index 827f85a5..39323f48 100644 --- a/src/standardizePronunciation/rules/transformHardConversion.spec.ts +++ b/src/standardizePronunciation/rules/transformHardConversion.spec.ts @@ -1,11 +1,11 @@ import { defined } from '../../_internal'; -import { disassembleCompleteHangulCharacter } from '../../disassembleCompleteHangulCharacter'; +import { disassembleCompleteCharacter } from '../../disassembleCompleteCharacter'; import { transformHardConversion } from './transformHardConversion'; describe('transformHardConversion', () => { it('23항 - 받침 "ㄱ(ㄲ, ㅋ, ㄳ, ㄺ), ㄷ(ㅅ, ㅆ, ㅈ, ㅊ, ㅌ), ㅂ(ㅍ, ㄼ, ㄿ, ㅄ)" 뒤에 연결되는 "ㄱ, ㄷ, ㅂ, ㅅ, ㅈ"은 된소리로 발음한다', () => { - const current = defined(disassembleCompleteHangulCharacter('국')); - const next = defined(disassembleCompleteHangulCharacter('밥')); + const current = defined(disassembleCompleteCharacter('국')); + const next = defined(disassembleCompleteCharacter('밥')); expect(transformHardConversion(current, next)).toEqual({ next: { @@ -17,8 +17,8 @@ describe('transformHardConversion', () => { }); it('24항 - 어간 받침 "ㄴ(ㄵ), ㅁ(ㄻ)" 뒤에 결합되는 어미의 첫소리 "ㄱ, ㄷ, ㅅ, ㅈ"은 된소리로 발음한다', () => { - const current = defined(disassembleCompleteHangulCharacter('신')); - const next = defined(disassembleCompleteHangulCharacter('고')); + const current = defined(disassembleCompleteCharacter('신')); + const next = defined(disassembleCompleteCharacter('고')); expect(transformHardConversion(current, next)).toEqual({ next: { @@ -30,8 +30,8 @@ describe('transformHardConversion', () => { }); it('25항 - 어간 받침 "ㄼ, ㄾ" 뒤에 결합되는 어미의 첫소리 "ㄱ, ㄷ, ㅅ, ㅈ"은 된소리로 발음한다', () => { - const current = defined(disassembleCompleteHangulCharacter('넓')); - const next = defined(disassembleCompleteHangulCharacter('게')); + const current = defined(disassembleCompleteCharacter('넓')); + const next = defined(disassembleCompleteCharacter('게')); expect(transformHardConversion(current, next)).toEqual({ next: { diff --git a/src/standardizePronunciation/rules/transformHardConversion.ts b/src/standardizePronunciation/rules/transformHardConversion.ts index 3062ba46..53275f1d 100644 --- a/src/standardizePronunciation/rules/transformHardConversion.ts +++ b/src/standardizePronunciation/rules/transformHardConversion.ts @@ -1,5 +1,5 @@ import { arrayIncludes } from '../../_internal'; -import { hasProperty } from '../../utils'; +import { hasProperty } from '../../_internal'; import { 된소리, 된소리_받침, 어간_받침 } from '../standardizePronunciation.constants'; import { ReturnSyllables, Syllable } from './rules.types'; diff --git a/src/standardizePronunciation/rules/transformNLAssimilation.spec.ts b/src/standardizePronunciation/rules/transformNLAssimilation.spec.ts index 6ae0dfce..5c183a80 100644 --- a/src/standardizePronunciation/rules/transformNLAssimilation.spec.ts +++ b/src/standardizePronunciation/rules/transformNLAssimilation.spec.ts @@ -1,11 +1,11 @@ import { defined } from '../../_internal'; -import { disassembleCompleteHangulCharacter } from '../../disassembleCompleteHangulCharacter'; +import { disassembleCompleteCharacter } from '../../disassembleCompleteCharacter'; import { transformNLAssimilation } from './transformNLAssimilation'; describe('transformNLAssimilation', () => { it('받침이 "ㄱ, ㄴ, ㄷ, ㅁ, ㅂ, ㅇ"이고 다음 음절이 "야, 여, 요, 유, 이, 얘, 예"로 이어지는 경우', () => { - const current = defined(disassembleCompleteHangulCharacter('맨')); - const next = defined(disassembleCompleteHangulCharacter('입')); + const current = defined(disassembleCompleteCharacter('맨')); + const next = defined(disassembleCompleteCharacter('입')); expect(transformNLAssimilation(current, next)).toEqual({ current: { @@ -22,8 +22,8 @@ describe('transformNLAssimilation', () => { }); it('받침이 "ㄹ"이고 다음 음절이 "야, 여, 요, 유, 이, 얘, 예"로 이어지는 경우', () => { - const current = defined(disassembleCompleteHangulCharacter('알')); - const next = defined(disassembleCompleteHangulCharacter('약')); + const current = defined(disassembleCompleteCharacter('알')); + const next = defined(disassembleCompleteCharacter('약')); expect(transformNLAssimilation(current, next)).toEqual({ current: { @@ -40,8 +40,8 @@ describe('transformNLAssimilation', () => { }); it('ㄴ/ㄹ이 되기 위한 조건이지만 현재 음절의 중성의 ∙(아래아)가 하나가 아닐 경우에는 덧나지 않고 연음규칙이 적용된다', () => { - const current = defined(disassembleCompleteHangulCharacter('양')); - const next = defined(disassembleCompleteHangulCharacter('이')); + const current = defined(disassembleCompleteCharacter('양')); + const next = defined(disassembleCompleteCharacter('이')); expect(transformNLAssimilation(current, next)).toEqual({ current: {