From bdeca9f7d484e036a2a11f56e95cc7731636f757 Mon Sep 17 00:00:00 2001 From: Collection50 Date: Thu, 27 Jun 2024 01:27:02 +0900 Subject: [PATCH 01/13] =?UTF-8?q?fix:=20=EC=9D=BC=EA=B4=80=EB=90=9C=20?= =?UTF-8?q?=ED=95=9C=EA=B8=80=20=ED=91=9C=EA=B8=B0=EB=B2=95=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README-en_us.md | 4 +- README.md | 4 +- ...es-demo.tsx => choseong-includes-demo.tsx} | 6 +- .../pages/docs/api/choseongIncludes.en.mdx | 27 +++++++ .../pages/docs/api/choseongIncludes.ko.mdx | 27 +++++++ .../src/pages/docs/api/chosungIncludes.en.mdx | 27 ------- .../src/pages/docs/api/chosungIncludes.ko.mdx | 27 ------- docs/src/pages/docs/introduction.en.mdx | 10 +-- docs/src/pages/docs/introduction.ko.mdx | 10 +-- docs/src/pages/index.en.mdx | 7 +- docs/src/pages/index.ko.mdx | 4 +- src/_internal/hangul.spec.ts | 4 +- src/_internal/hangul.ts | 30 ++++---- ...ludes.spec.ts => choseongIncludes.spec.ts} | 18 ++--- src/choseongIncludes.ts | 29 ++++++++ src/chosungIncludes.ts | 29 -------- src/combineHangulCharacter.ts | 8 +-- src/constants.ts | 4 +- src/disassembleCompleteHangulCharacter.ts | 10 +-- src/index.ts | 2 +- src/utils.spec.ts | 62 ++++++++-------- src/utils.ts | 70 +++++++++---------- 22 files changed, 210 insertions(+), 209 deletions(-) rename docs/src/components/demo/{chosung-includes-demo.tsx => choseong-includes-demo.tsx} (92%) create mode 100644 docs/src/pages/docs/api/choseongIncludes.en.mdx create mode 100644 docs/src/pages/docs/api/choseongIncludes.ko.mdx delete mode 100644 docs/src/pages/docs/api/chosungIncludes.en.mdx delete mode 100644 docs/src/pages/docs/api/chosungIncludes.ko.mdx rename src/{chosungIncludes.spec.ts => choseongIncludes.spec.ts} (60%) create mode 100644 src/choseongIncludes.ts delete mode 100644 src/chosungIncludes.ts diff --git a/README-en_us.md b/README-en_us.md index caacd0a4..a629726c 100644 --- a/README-en_us.md +++ b/README-en_us.md @@ -11,12 +11,12 @@ es-hangul is a library that makes it easy to handle [Hangul](https://en.wikipedi You can easily implement tasks related to Hangul, such as initial consonant search and attaching particles(josas). ```tsx -import { chosungIncludes } from 'es-hangul'; +import { choseongIncludes } from 'es-hangul'; const searchWord = '라면'; const userInput = 'ㄹㅁ'; -const result = chosungIncludes(searchWord, userInput); // true +const result = choseongIncludes(searchWord, userInput); // true ``` ```tsx diff --git a/README.md b/README.md index 58c4b604..c91c9048 100644 --- a/README.md +++ b/README.md @@ -11,12 +11,12 @@ 초성 검색, 조사 붙이기와 같은 한글 작업을 간단히 할 수 있습니다. ```tsx -import { chosungIncludes } from 'es-hangul'; +import { choseongIncludes } from 'es-hangul'; const searchWord = '라면'; const userInput = 'ㄹㅁ'; -const result = chosungIncludes(searchWord, userInput); // true +const result = choseongIncludes(searchWord, userInput); // true ``` ```tsx diff --git a/docs/src/components/demo/chosung-includes-demo.tsx b/docs/src/components/demo/choseong-includes-demo.tsx similarity index 92% rename from docs/src/components/demo/chosung-includes-demo.tsx rename to docs/src/components/demo/choseong-includes-demo.tsx index 393f9ccb..e0d5bf7e 100644 --- a/docs/src/components/demo/chosung-includes-demo.tsx +++ b/docs/src/components/demo/choseong-includes-demo.tsx @@ -1,11 +1,11 @@ import React, { useState } from 'react'; -import { chosungIncludes } from 'es-hangul'; +import { choseongIncludes } from 'es-hangul'; -export function ChosungIncludesDemo() { +export function choseongIncludesDemo() { const [searchWord, setSearchWord] = useState('홍길동'); const [userInput, setUserInput] = useState('ㅎㄱㄷ'); - const result = chosungIncludes(searchWord, userInput); + const result = choseongIncludes(searchWord, userInput); return (
diff --git a/docs/src/pages/docs/api/choseongIncludes.en.mdx b/docs/src/pages/docs/api/choseongIncludes.en.mdx new file mode 100644 index 00000000..d50494bf --- /dev/null +++ b/docs/src/pages/docs/api/choseongIncludes.en.mdx @@ -0,0 +1,27 @@ +import { choseongIncludesDemo } from '@/components/demo/choseong-includes-demo'; + +# choseongIncludes + +Performs a search for matches in the initial consonants of a string. + +```typescript +function choseongIncludes( + // The string to be checked for matching initial consonants (e.g., '프론트엔드') + x: string, + // Initial consonant string (e.g., 'ㅍㄹㅌㅇㄷ') + y: string +): boolean; +``` + +```typescript +choseongIncludes('프론트엔드', 'ㅍㄹㅌ'); // true +choseongIncludes('00프론트엔드', 'ㅍㄹㅌ'); // true +choseongIncludes('프론트엔드', 'ㅍㅌ'); // false +choseongIncludes('프론트엔드', '푸롴트'); // false +``` + +## Demo + +
+ + diff --git a/docs/src/pages/docs/api/choseongIncludes.ko.mdx b/docs/src/pages/docs/api/choseongIncludes.ko.mdx new file mode 100644 index 00000000..3f1058a9 --- /dev/null +++ b/docs/src/pages/docs/api/choseongIncludes.ko.mdx @@ -0,0 +1,27 @@ +import { choseongIncludesDemo } from '@/components/demo/choseong-includes-demo'; + +# choseongIncludes + +문자열의 초성 일치 검색을 수행합니다. + +```typescript +function choseongIncludes( + // 초성 일치하는지 검사할 문자열 (e.g. '프론트엔드') + x: string, + // 초성 문자열 (e.g. 'ㅍㄹㅌㅇㄷ') + y: string +): boolean; +``` + +```typescript +choseongIncludes('프론트엔드', 'ㅍㄹㅌ'); // true +choseongIncludes('00프론트엔드', 'ㅍㄹㅌ'); // true +choseongIncludes('프론트엔드', 'ㅍㅌ'); // false +choseongIncludes('프론트엔드', '푸롴트'); // false +``` + +## 사용해보기 + +
+ + diff --git a/docs/src/pages/docs/api/chosungIncludes.en.mdx b/docs/src/pages/docs/api/chosungIncludes.en.mdx deleted file mode 100644 index 691a7623..00000000 --- a/docs/src/pages/docs/api/chosungIncludes.en.mdx +++ /dev/null @@ -1,27 +0,0 @@ -import { ChosungIncludesDemo } from '@/components/demo/chosung-includes-demo'; - -# chosungIncludes - -Performs a search for matches in the initial consonants of a string. - -```typescript -function chosungIncludes( - // The string to be checked for matching initial consonants (e.g., '프론트엔드') - x: string, - // Initial consonant string (e.g., 'ㅍㄹㅌㅇㄷ') - y: string -): boolean; -``` - -```typescript -chosungIncludes('프론트엔드', 'ㅍㄹㅌ'); // true -chosungIncludes('00프론트엔드', 'ㅍㄹㅌ'); // true -chosungIncludes('프론트엔드', 'ㅍㅌ'); // false -chosungIncludes('프론트엔드', '푸롴트'); // false -``` - -## Demo - -
- - diff --git a/docs/src/pages/docs/api/chosungIncludes.ko.mdx b/docs/src/pages/docs/api/chosungIncludes.ko.mdx deleted file mode 100644 index ce45f872..00000000 --- a/docs/src/pages/docs/api/chosungIncludes.ko.mdx +++ /dev/null @@ -1,27 +0,0 @@ -import { ChosungIncludesDemo } from '@/components/demo/chosung-includes-demo'; - -# chosungIncludes - -문자열의 초성 일치 검색을 수행합니다. - -```typescript -function chosungIncludes( - // 초성 일치하는지 검사할 문자열 (e.g. '프론트엔드') - x: string, - // 초성 문자열 (e.g. 'ㅍㄹㅌㅇㄷ') - y: string -): boolean; -``` - -```typescript -chosungIncludes('프론트엔드', 'ㅍㄹㅌ'); // true -chosungIncludes('00프론트엔드', 'ㅍㄹㅌ'); // true -chosungIncludes('프론트엔드', 'ㅍㅌ'); // false -chosungIncludes('프론트엔드', '푸롴트'); // false -``` - -## 사용해보기 - -
- - diff --git a/docs/src/pages/docs/introduction.en.mdx b/docs/src/pages/docs/introduction.en.mdx index 8a0047de..06a7408f 100644 --- a/docs/src/pages/docs/introduction.en.mdx +++ b/docs/src/pages/docs/introduction.en.mdx @@ -31,19 +31,19 @@ Our library provides strong typing, allowing for easy detection of type errors d ### Full Support for Hangul-related Features -Our library provides a [modern API](./api/chosungIncludes) that can be conveniently used in various applications. +Our library provides a [modern API](./api/choseongIncludes) that can be conveniently used in various applications. -#### First Consonant Search ([chosungIncludes](./api/chosungIncludes)) +#### First Consonant Search ([choseongIncludes](./api/choseongIncludes)) It checks whether an initial consonant is included in a specific word. For example, you can easily find out if the word '라면' (ramyeon) contains the initial consonants 'ㄹㅁ'. -```tsx /chosungIncludes/ -import { chosungIncludes } from 'es-hangul'; +```tsx /choseongIncludes/ +import { choseongIncludes } from 'es-hangul'; const searchWord = '라면'; const userInput = 'ㄹㅁ'; -const result = chosungIncludes(searchWord, userInput); +const result = choseongIncludes(searchWord, userInput); console.log(result); // true ``` diff --git a/docs/src/pages/docs/introduction.ko.mdx b/docs/src/pages/docs/introduction.ko.mdx index 7d7881ac..73b27d6d 100644 --- a/docs/src/pages/docs/introduction.ko.mdx +++ b/docs/src/pages/docs/introduction.ko.mdx @@ -31,19 +31,19 @@ ECMAScript Modules를 이용하여 사용하는 함수만 애플리케이션에 ### 한글을 위한 모든 인터페이스를 제공하는 것을 목표합니다 -다양한 애플리케이션에서 편리하게 사용할 수 있는 [현대적인 API](./api/chosungIncludes)를 제공합니다. +다양한 애플리케이션에서 편리하게 사용할 수 있는 [현대적인 API](./api/choseongIncludes)를 제공합니다. -#### 초성 검색 ([chosungIncludes](./api/chosungIncludes)) +#### 초성 검색 ([choseongIncludes](./api/choseongIncludes)) 초성이 특정 단어에 포함되어 있는지 검사합니다. 예를 들어, '라면'이라는 단어가 'ㄹㅁ'으로 시작하는 초성을 포함하는지 쉽게 알 수 있습니다. -```tsx /chosungIncludes/ -import { chosungIncludes } from 'es-hangul'; +```tsx /choseongIncludes/ +import { choseongIncludes } from 'es-hangul'; const searchWord = '라면'; const userInput = 'ㄹㅁ'; -const result = chosungIncludes(searchWord, userInput); +const result = choseongIncludes(searchWord, userInput); console.log(result); // true ``` diff --git a/docs/src/pages/index.en.mdx b/docs/src/pages/index.en.mdx index 7754a379..e4d60454 100644 --- a/docs/src/pages/index.en.mdx +++ b/docs/src/pages/index.en.mdx @@ -27,18 +27,19 @@ import { Callout, useTheme, Steps } from 'nextra-theme-docs';

A modern JavaScript Hangul library

- es-hangul is a small JavaScript library that helps you conveniently handle Hangul. It provides a convenient and clean API for actions such as searching for initial consonants and attaching particles. + es-hangul is a small JavaScript library that helps you conveniently handle Hangul. It provides a convenient and + clean API for actions such as searching for initial consonants and attaching particles. ```tsx -import { chosungIncludes } from 'es-hangul'; +import { choseongIncludes } from 'es-hangul'; const searchWord = '라면'; const userInput = 'ㄹㅁ'; -const result = chosungIncludes(searchWord, userInput); +const result = choseongIncludes(searchWord, userInput); console.log(result); // true ``` diff --git a/docs/src/pages/index.ko.mdx b/docs/src/pages/index.ko.mdx index 7807a6e8..a86d1f68 100644 --- a/docs/src/pages/index.ko.mdx +++ b/docs/src/pages/index.ko.mdx @@ -34,12 +34,12 @@ import { Callout, useTheme, Steps } from 'nextra-theme-docs'; ```tsx -import { chosungIncludes } from 'es-hangul'; +import { choseongIncludes } from 'es-hangul'; const searchWord = '라면'; const userInput = 'ㄹㅁ'; -const result = chosungIncludes(searchWord, userInput); +const result = choseongIncludes(searchWord, userInput); console.log(result); // true ``` diff --git a/src/_internal/hangul.spec.ts b/src/_internal/hangul.spec.ts index 7cf63bbe..e9ef0d52 100644 --- a/src/_internal/hangul.spec.ts +++ b/src/_internal/hangul.spec.ts @@ -75,12 +75,12 @@ describe('binaryAssembleHangulCharacters', () => { assert.throws( () => binaryAssembleHangulCharacters('ㄱ', 'a'), Error, - 'Invalid next character: a. Next character must be one of the chosung, jungsung, or jongsung.' + 'Invalid next character: a. Next character must be one of the choseong, jungseong, or jongseong.' ); assert.throws( () => binaryAssembleHangulCharacters('ㄱ', 'ㅡㅏ'), Error, - 'Invalid next character: ㅡㅏ. Next character must be one of the chosung, jungsung, or jongsung.' + 'Invalid next character: ㅡㅏ. Next character must be one of the choseong, jungseong, or jongseong.' ); }); }); diff --git a/src/_internal/hangul.ts b/src/_internal/hangul.ts index 6a1479ca..ef709769 100644 --- a/src/_internal/hangul.ts +++ b/src/_internal/hangul.ts @@ -2,7 +2,7 @@ import assert, { excludeLastElement, isBlank, joinString } from '.'; import { combineHangulCharacter, combineVowels, curriedCombineHangulCharacter } from '../combineHangulCharacter'; import { disassembleHangulToGroups } from '../disassemble'; import { removeLastHangulCharacter } from '../removeLastHangulCharacter'; -import { canBeChosung, canBeJongsung, canBeJungsung, hasSingleBatchim } from '../utils'; +import { canBeChoseong, canBeJongseong, canBeJungseong, hasSingleBatchim } from '../utils'; export function isHangulCharacter(character: string) { return /^[가-힣]$/.test(character); @@ -23,12 +23,12 @@ export function isHangulAlphabet(character: string) { * ``` */ export function binaryAssembleHangulAlphabets(source: string, nextCharacter: string) { - if (canBeJungsung(`${source}${nextCharacter}`)) { + if (canBeJungseong(`${source}${nextCharacter}`)) { return combineVowels(source, nextCharacter); } - const isConsonantSource = canBeJungsung(source) === false; - if (isConsonantSource && canBeJungsung(nextCharacter)) { + const isConsonantSource = canBeJungseong(source) === false; + if (isConsonantSource && canBeJungseong(nextCharacter)) { return combineHangulCharacter(source, nextCharacter); } @@ -72,7 +72,7 @@ export function binaryAssembleHangulCharacters(source: string, nextCharacter: st ); assert( isHangulAlphabet(nextCharacter), - `Invalid next character: ${nextCharacter}. Next character must be one of the chosung, jungsung, or jongsung.` + `Invalid next character: ${nextCharacter}. Next character must be one of the choseong, jungseong, or jongseong.` ); const sourceJamos = disassembleHangulToGroups(source)[0]; @@ -85,29 +85,29 @@ export function binaryAssembleHangulCharacters(source: string, nextCharacter: st const [restJamos, lastJamo] = excludeLastElement(sourceJamos); - const needLinking = canBeChosung(lastJamo) && canBeJungsung(nextCharacter); + const needLinking = canBeChoseong(lastJamo) && canBeJungseong(nextCharacter); if (needLinking) { return linkHangulCharacters(source, nextCharacter); } const fixConsonant = curriedCombineHangulCharacter; - const combineJungsung = fixConsonant(restJamos[0]); + const combineJungseong = fixConsonant(restJamos[0]); - if (canBeJungsung(`${lastJamo}${nextCharacter}`)) { - return combineJungsung(`${lastJamo}${nextCharacter}`)(); + if (canBeJungseong(`${lastJamo}${nextCharacter}`)) { + return combineJungseong(`${lastJamo}${nextCharacter}`)(); } - if (canBeJungsung(lastJamo) && canBeJongsung(nextCharacter)) { - return combineJungsung(lastJamo)(nextCharacter); + if (canBeJungseong(lastJamo) && canBeJongseong(nextCharacter)) { + return combineJungseong(lastJamo)(nextCharacter); } - const fixVowel = combineJungsung; - const combineJongsung = fixVowel(restJamos[1]); + const fixVowel = combineJungseong; + const combineJongseong = fixVowel(restJamos[1]); const lastConsonant = lastJamo; - if (hasSingleBatchim(source) && canBeJongsung(`${lastConsonant}${nextCharacter}`)) { - return combineJongsung(`${lastConsonant}${nextCharacter}`); + if (hasSingleBatchim(source) && canBeJongseong(`${lastConsonant}${nextCharacter}`)) { + return combineJongseong(`${lastConsonant}${nextCharacter}`); } return joinString(source, nextCharacter); diff --git a/src/chosungIncludes.spec.ts b/src/choseongIncludes.spec.ts similarity index 60% rename from src/chosungIncludes.spec.ts rename to src/choseongIncludes.spec.ts index 7033278b..245b891f 100644 --- a/src/chosungIncludes.spec.ts +++ b/src/choseongIncludes.spec.ts @@ -1,35 +1,35 @@ -import { chosungIncludes } from './chosungIncludes'; +import { choseongIncludes } from './choseongIncludes'; -describe('chosungIncludes', () => { +describe('choseongIncludes', () => { describe('초성이 포함되어있다고 판단되는 경우', () => { it('"ㅍㄹㅌ" 문자열로 "프론트엔드"를 검색하면 true를 반환한다.', () => { - expect(chosungIncludes('프론트엔드', 'ㅍㄹㅌ')).toBe(true); + expect(choseongIncludes('프론트엔드', 'ㅍㄹㅌ')).toBe(true); }); it('"ㅍㄹㅌ" 문자열로 "00프론트엔드"를 검색하면 true를 반환한다.', () => { - expect(chosungIncludes('00프론트엔드', 'ㅍㄹㅌ')).toBe(true); + expect(choseongIncludes('00프론트엔드', 'ㅍㄹㅌ')).toBe(true); }); it('"ㅍㄹㅌㅇㄷㄱㅂㅈ" 문자열로 "프론트엔드 개발자"를 검색하면 true를 반환한다.', () => { - expect(chosungIncludes('프론트엔드 개발자', 'ㅍㄹㅌㅇㄷㄱㅂㅈ')).toBe(true); + expect(choseongIncludes('프론트엔드 개발자', 'ㅍㄹㅌㅇㄷㄱㅂㅈ')).toBe(true); }); it('"ㅍㄹㅌㅇㄷ ㄱㅂㅈ" 문자열로 "프론트엔드 개발자"를 검색하면 true를 반환한다.', () => { - expect(chosungIncludes('프론트엔드 개발자', 'ㅍㄹㅌㅇㄷ ㄱㅂㅈ')).toBe(true); + expect(choseongIncludes('프론트엔드 개발자', 'ㅍㄹㅌㅇㄷ ㄱㅂㅈ')).toBe(true); }); }); describe('초성이 포함되어있다고 판단되지 않는 경우', () => { it('"ㅍㅌ" 문자열로 "프론트엔드"를 검색하면 false를 반환한다.', () => { - expect(chosungIncludes('프론트엔드', 'ㅍㅌ')).toBe(false); + expect(choseongIncludes('프론트엔드', 'ㅍㅌ')).toBe(false); }); it('빈 문자열로 "프론트엔드 개발자"를 검색하면 false를 반환한다.', () => { - expect(chosungIncludes('프론트엔드 개발자', ' ')).toBe(false); + expect(choseongIncludes('프론트엔드 개발자', ' ')).toBe(false); }); it('"푸롴트" 문자열로 "프론트엔드"를 검색하면 초성으로만 구성되어 있지 않아 false를 반환한다.', () => { - expect(chosungIncludes('프론트엔드', '푸롴트')).toBe(false); + expect(choseongIncludes('프론트엔드', '푸롴트')).toBe(false); }); }); }); diff --git a/src/choseongIncludes.ts b/src/choseongIncludes.ts new file mode 100644 index 00000000..e608af9a --- /dev/null +++ b/src/choseongIncludes.ts @@ -0,0 +1,29 @@ +import { disassembleHangulToGroups } from './disassemble'; +import { canBeChoseong, getChoseong } from './utils'; + +export function choseongIncludes(x: string, y: string) { + const trimmedY = y.replace(/\s/g, ''); + + if (!isOnlyChoseong(trimmedY)) { + return false; + } + + const choseongX = getChoseong(x).replace(/\s/g, ''); + const choseongY = trimmedY; + + return choseongX.includes(choseongY); +} + +/* + * @description 문자열이 한글초성으로만 주어진 경우 + */ +function isOnlyChoseong(str: string) { + const groups = disassembleHangulToGroups(str); + if (groups.length === 0) { + return false; + } + + return groups.every(disassembled => { + return disassembled.length === 1 && canBeChoseong(disassembled[0]); + }); +} diff --git a/src/chosungIncludes.ts b/src/chosungIncludes.ts deleted file mode 100644 index 254d1f30..00000000 --- a/src/chosungIncludes.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { disassembleHangulToGroups } from './disassemble'; -import { canBeChosung, getChosung } from './utils'; - -export function chosungIncludes(x: string, y: string) { - const trimmedY = y.replace(/\s/g, ''); - - if (!isOnlyChosung(trimmedY)) { - return false; - } - - const chosungX = getChosung(x).replace(/\s/g, ''); - const chosungY = trimmedY; - - return chosungX.includes(chosungY); -} - -/* - * @description 문자열이 한글초성으로만 주어진 경우 - */ -function isOnlyChosung(str: string) { - const groups = disassembleHangulToGroups(str); - if (groups.length === 0) { - return false; - } - - return groups.every(disassembled => { - return disassembled.length === 1 && canBeChosung(disassembled[0]); - }); -} diff --git a/src/combineHangulCharacter.ts b/src/combineHangulCharacter.ts index 5e8ddc02..7ace284c 100644 --- a/src/combineHangulCharacter.ts +++ b/src/combineHangulCharacter.ts @@ -5,7 +5,7 @@ import { HANGUL_CHARACTERS_BY_LAST_INDEX, HANGUL_CHARACTERS_BY_MIDDLE_INDEX, } from './constants'; -import { canBeChosung, canBeJongsung, canBeJungsung } from './utils'; +import { canBeChoseong, canBeJongseong, canBeJungseong } from './utils'; /** * @name combineHangulCharacter @@ -27,9 +27,9 @@ import { canBeChosung, canBeJongsung, canBeJungsung } from './utils'; */ export function combineHangulCharacter(firstCharacter: string, middleCharacter: string, lastCharacter = '') { if ( - canBeChosung(firstCharacter) === false || - canBeJungsung(middleCharacter) === false || - canBeJongsung(lastCharacter) === false + canBeChoseong(firstCharacter) === false || + canBeJungseong(middleCharacter) === false || + canBeJongseong(lastCharacter) === false ) { throw new Error(`Invalid hangul Characters: ${firstCharacter}, ${middleCharacter}, ${lastCharacter}`); } diff --git a/src/constants.ts b/src/constants.ts index 217defe3..142cba13 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,7 +1,7 @@ export const COMPLETE_HANGUL_START_CHARCODE = '가'.charCodeAt(0); export const COMPLETE_HANGUL_END_CHARCODE = '힣'.charCodeAt(0); -export const NUMBER_OF_JONGSUNG = 28; -export const NUMBER_OF_JUNGSUNG = 21; +export const NUMBER_OF_JONGSEONG = 28; +export const NUMBER_OF_JUNGSEONG = 21; /** * ㄱ -> 'ㄱ' diff --git a/src/disassembleCompleteHangulCharacter.ts b/src/disassembleCompleteHangulCharacter.ts index 0e255c83..252eee2d 100644 --- a/src/disassembleCompleteHangulCharacter.ts +++ b/src/disassembleCompleteHangulCharacter.ts @@ -4,8 +4,8 @@ import { HANGUL_CHARACTERS_BY_FIRST_INDEX, HANGUL_CHARACTERS_BY_LAST_INDEX, HANGUL_CHARACTERS_BY_MIDDLE_INDEX, - NUMBER_OF_JONGSUNG, - NUMBER_OF_JUNGSUNG, + NUMBER_OF_JONGSEONG, + NUMBER_OF_JUNGSEONG, } from './constants'; interface ReturnTypeDisassembleCompleteHangulCharacter { @@ -41,9 +41,9 @@ export function disassembleCompleteHangulCharacter( const hangulCode = charCode - COMPLETE_HANGUL_START_CHARCODE; - const lastIndex = hangulCode % NUMBER_OF_JONGSUNG; - const middleIndex = ((hangulCode - lastIndex) / NUMBER_OF_JONGSUNG) % NUMBER_OF_JUNGSUNG; - const firstIndex = Math.floor((hangulCode - lastIndex) / NUMBER_OF_JONGSUNG / NUMBER_OF_JUNGSUNG); + 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); return { first: HANGUL_CHARACTERS_BY_FIRST_INDEX[firstIndex], diff --git a/src/index.ts b/src/index.ts index be7f02a3..a560281f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ export * from './assemble'; -export * from './chosungIncludes'; +export * from './choseongIncludes'; export * from './combineHangulCharacter'; export * from './convertQwertyToHangulAlphabet'; export * from './disassemble'; diff --git a/src/utils.spec.ts b/src/utils.spec.ts index cacb0ce0..a593d95a 100644 --- a/src/utils.spec.ts +++ b/src/utils.spec.ts @@ -1,8 +1,8 @@ import { - canBeChosung, - canBeJongsung, - canBeJungsung, - getChosung, + canBeChoseong, + canBeJongseong, + canBeJungseong, + getChoseong, getFirstConsonants, hasBatchim, hasProperty, @@ -57,22 +57,22 @@ describe('hasSingleBatchim', () => { }); }); -describe('getChosung', () => { +describe('getChoseong', () => { it('"사과" 단어에서 초성 "ㅅㄱ"을 추출한다.', () => { - expect(getChosung('사과')).toBe('ㅅㄱ'); + expect(getChoseong('사과')).toBe('ㅅㄱ'); }); it('"프론트엔드" 단어에서 초성 "ㅍㄹㅌㅇㄷ"을 추출한다.', () => { - expect(getChosung('프론트엔드')).toBe('ㅍㄹㅌㅇㄷ'); + expect(getChoseong('프론트엔드')).toBe('ㅍㄹㅌㅇㄷ'); }); it('"ㄴㅈ" 문자에서 초성 "ㄴㅈ"을 추출한다.', () => { - expect(getChosung('ㄴㅈ')).toBe('ㄴㅈ'); + expect(getChoseong('ㄴㅈ')).toBe('ㄴㅈ'); }); it('"리액트" 단어에서 초성 "ㄹㅇㅌ"을 추출한다.', () => { - expect(getChosung('리액트')).toBe('ㄹㅇㅌ'); + expect(getChoseong('리액트')).toBe('ㄹㅇㅌ'); }); it('"띄어 쓰기" 문장에서 초성 "ㄸㅇ ㅆㄱ"을 추출한다.', () => { - expect(getChosung('띄어 쓰기')).toBe('ㄸㅇ ㅆㄱ'); + expect(getChoseong('띄어 쓰기')).toBe('ㄸㅇ ㅆㄱ'); }); }); @@ -147,80 +147,80 @@ describe('hasProperty', () => { }); }); -describe('canBeChosung', () => { +describe('canBeChoseong', () => { describe('초성이 될 수 있다고 판단되는 경우', () => { it('ㄱ', () => { - expect(canBeChosung('ㄱ')).toBe(true); + expect(canBeChoseong('ㄱ')).toBe(true); }); it('ㅃ', () => { - expect(canBeChosung('ㅃ')).toBe(true); + expect(canBeChoseong('ㅃ')).toBe(true); }); }); describe('초성이 될 수 없다고 판단되는 경우', () => { it('ㅏ', () => { - expect(canBeChosung('ㅏ')).toBe(false); + expect(canBeChoseong('ㅏ')).toBe(false); }); it('ㅘ', () => { - expect(canBeChosung('ㅘ')).toBe(false); + expect(canBeChoseong('ㅘ')).toBe(false); }); it('ㄱㅅ', () => { - expect(canBeChosung('ㄱㅅ')).toBe(false); + expect(canBeChoseong('ㄱㅅ')).toBe(false); }); it('가', () => { - expect(canBeChosung('가')).toBe(false); + expect(canBeChoseong('가')).toBe(false); }); }); }); -describe('canBeJungsung', () => { +describe('canBeJungseong', () => { describe('중성이 될 수 있다고 판단되는 경우', () => { it('ㅗㅏ', () => { - expect(canBeJungsung('ㅗㅏ')).toBe(true); + expect(canBeJungseong('ㅗㅏ')).toBe(true); }); it('ㅏ', () => { - expect(canBeJungsung('ㅏ')).toBe(true); + expect(canBeJungseong('ㅏ')).toBe(true); }); }); describe('중성이 될 수 없다고 판단되는 경우', () => { it('ㄱ', () => { - expect(canBeJungsung('ㄱ')).toBe(false); + expect(canBeJungseong('ㄱ')).toBe(false); }); it('ㄱㅅ', () => { - expect(canBeJungsung('ㄱㅅ')).toBe(false); + expect(canBeJungseong('ㄱㅅ')).toBe(false); }); it('가', () => { - expect(canBeJungsung('가')).toBe(false); + expect(canBeJungseong('가')).toBe(false); }); }); }); -describe('canBeJongsung', () => { +describe('canBeJongseong', () => { describe('종성이 될 수 있다고 판단되는 경우', () => { it('ㄱ', () => { - expect(canBeJongsung('ㄱ')).toBe(true); + expect(canBeJongseong('ㄱ')).toBe(true); }); it('ㄱㅅ', () => { - expect(canBeJongsung('ㄱㅅ')).toBe(true); + expect(canBeJongseong('ㄱㅅ')).toBe(true); }); it('ㅂㅅ', () => { - expect(canBeJongsung('ㅂㅅ')).toBe(true); + expect(canBeJongseong('ㅂㅅ')).toBe(true); }); }); describe('종성이 될 수 없다고 판단되는 경우', () => { it('ㅎㄹ', () => { - expect(canBeJongsung('ㅎㄹ')).toBe(false); + expect(canBeJongseong('ㅎㄹ')).toBe(false); }); it('ㅗㅏ', () => { - expect(canBeJongsung('ㅗㅏ')).toBe(false); + expect(canBeJongseong('ㅗㅏ')).toBe(false); }); it('ㅏ', () => { - expect(canBeJongsung('ㅏ')).toBe(false); + expect(canBeJongseong('ㅏ')).toBe(false); }); it('가', () => { - expect(canBeJongsung('ㅏ')).toBe(false); + expect(canBeJongseong('ㅏ')).toBe(false); }); }); }); diff --git a/src/utils.ts b/src/utils.ts index 5213d9c8..02632612 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -58,29 +58,29 @@ export function hasSingleBatchim(str: string) { } /** - * @name getChosung + * @name getChoseong * @description * 단어에서 초성을 추출합니다. (예: `사과` -> `'ㅅㄱ'`) * ```typescript - * getChosung( + * getChoseong( * // 초성을 추출할 단어 * word: string * ): string * ``` * @example - * getChosung('사과') // 'ㅅㄱ' - * getChosung('리액트') // 'ㄹㅇㅌ' - * getChosung('띄어 쓰기') // 'ㄸㅇ ㅆㄱ' + * getChoseong('사과') // 'ㅅㄱ' + * getChoseong('리액트') // 'ㄹㅇㅌ' + * getChoseong('띄어 쓰기') // 'ㄸㅇ ㅆㄱ' */ -export function getChosung(word: string) { - return disassembleHangulToGroups(word).reduce((chosung, [consonant]) => { - return `${chosung}${consonant}`; +export function getChoseong(word: string) { + return disassembleHangulToGroups(word).reduce((choseong, [consonant]) => { + return `${choseong}${consonant}`; }, ''); } /** * @name getFirstConsonants - * @deprecated getChosung을 사용해 주세요. + * @deprecated getChoseong을 사용해 주세요. * @description * 단어에서 초성을 추출합니다. (예: `사과` -> `'ㅅㄱ'`) * ```typescript @@ -101,67 +101,67 @@ export function getFirstConsonants(word: string) { } /** - * @name canBeChosung + * @name canBeChoseong * @description * 인자로 받은 문자가 초성으로 위치할 수 있는 문자인지 검사합니다. * ```typescript - * canBeChosung( + * canBeChoseong( * // 대상 문자 * character: string * ): boolean * ``` * @example - * canBeChosung('ㄱ') // true - * canBeChosung('ㅃ') // true - * canBeChosung('ㄱㅅ') // false - * canBeChosung('ㅏ') // false - * canBeChosung('가') // false + * canBeChoseong('ㄱ') // true + * canBeChoseong('ㅃ') // true + * canBeChoseong('ㄱㅅ') // false + * canBeChoseong('ㅏ') // false + * canBeChoseong('가') // false */ -export function canBeChosung(character: string): character is (typeof HANGUL_CHARACTERS_BY_FIRST_INDEX)[number] { +export function canBeChoseong(character: string): character is (typeof HANGUL_CHARACTERS_BY_FIRST_INDEX)[number] { return hasValueInReadOnlyStringList(HANGUL_CHARACTERS_BY_FIRST_INDEX, character); } /** - * @name canBeJungsung + * @name canBeJungseong * @description * 인자로 받은 문자가 중성으로 위치할 수 있는 문자인지 검사합니다. * ```typescript - * canBeJungsung( + * canBeJungseong( * // 대상 문자 * character: string * ): boolean * ``` * @example - * canBeJungsung('ㅏ') // true - * canBeJungsung('ㅗㅏ') // true - * canBeJungsung('ㅏㅗ') // false - * canBeJungsung('ㄱ') // false - * canBeJungsung('ㄱㅅ') // false - * canBeJungsung('가') // false + * canBeJungseong('ㅏ') // true + * canBeJungseong('ㅗㅏ') // true + * canBeJungseong('ㅏㅗ') // false + * canBeJungseong('ㄱ') // false + * canBeJungseong('ㄱㅅ') // false + * canBeJungseong('가') // false */ -export function canBeJungsung(character: string): character is (typeof HANGUL_CHARACTERS_BY_MIDDLE_INDEX)[number] { +export function canBeJungseong(character: string): character is (typeof HANGUL_CHARACTERS_BY_MIDDLE_INDEX)[number] { return hasValueInReadOnlyStringList(HANGUL_CHARACTERS_BY_MIDDLE_INDEX, character); } /** - * @name canBeJongsung + * @name canBeJongseong * @description * 인자로 받은 문자가 종성으로 위치할 수 있는 문자인지 검사합니다. * ```typescript - * canBeJongsung( + * canBeJongseong( * // 대상 문자 * character: string * ): boolean * ``` * @example - * canBeJongsung('ㄱ') // true - * canBeJongsung('ㄱㅅ') // true - * canBeJongsung('ㅎㄹ') // false - * canBeJongsung('가') // false - * canBeJongsung('ㅏ') // false - * canBeJongsung('ㅗㅏ') // false + * canBeJongseong('ㄱ') // true + * canBeJongseong('ㄱㅅ') // true + * canBeJongseong('ㅎㄹ') // false + * canBeJongseong('가') // false + * canBeJongseong('ㅏ') // false + * canBeJongseong('ㅗㅏ') // false */ -export function canBeJongsung(character: string): character is (typeof HANGUL_CHARACTERS_BY_LAST_INDEX)[number] { +export function canBeJongseong(character: string): character is (typeof HANGUL_CHARACTERS_BY_LAST_INDEX)[number] { return hasValueInReadOnlyStringList(HANGUL_CHARACTERS_BY_LAST_INDEX, character); } From a611eebdb1a33a6919d43926f3ed2e8f4b2e04b7 Mon Sep 17 00:00:00 2001 From: Collection50 Date: Mon, 1 Jul 2024 21:42:17 +0900 Subject: [PATCH 02/13] =?UTF-8?q?fix:=20=EA=B8=B0=EC=A1=B4=EC=9D=98=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=EB=A5=BC=20=EC=9C=A0=EC=A7=80=ED=95=9C=20?= =?UTF-8?q?=EC=B1=84,=20deprecated=20=EB=90=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/choseongIncludes.ts | 2 +- src/chosungIncludes.ts | 18 +++++++++ src/index.ts | 1 + src/utils.ts | 90 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 src/chosungIncludes.ts diff --git a/src/choseongIncludes.ts b/src/choseongIncludes.ts index e608af9a..3dee936b 100644 --- a/src/choseongIncludes.ts +++ b/src/choseongIncludes.ts @@ -17,7 +17,7 @@ export function choseongIncludes(x: string, y: string) { /* * @description 문자열이 한글초성으로만 주어진 경우 */ -function isOnlyChoseong(str: string) { +export function isOnlyChoseong(str: string) { const groups = disassembleHangulToGroups(str); if (groups.length === 0) { return false; diff --git a/src/chosungIncludes.ts b/src/chosungIncludes.ts new file mode 100644 index 00000000..7c4a399b --- /dev/null +++ b/src/chosungIncludes.ts @@ -0,0 +1,18 @@ +import { isOnlyChoseong } from './choseongIncludes'; +import { getChoseong } from './utils'; + +/** + * @deprecated choseongIncludes를 사용해 주세요. + */ +export function chosungIncludes(x: string, y: string) { + const trimmedY = y.replace(/\s/g, ''); + + if (!isOnlyChoseong(trimmedY)) { + return false; + } + + const choseongX = getChoseong(x).replace(/\s/g, ''); + const choseongY = trimmedY; + + return choseongX.includes(choseongY); +} diff --git a/src/index.ts b/src/index.ts index a560281f..9452cc20 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,6 @@ export * from './assemble'; export * from './choseongIncludes'; +export * from './chosungIncludes'; export * from './combineHangulCharacter'; export * from './convertQwertyToHangulAlphabet'; export * from './disassemble'; diff --git a/src/utils.ts b/src/utils.ts index 02632612..0f467b86 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -57,6 +57,28 @@ export function hasSingleBatchim(str: string) { return disassembled.length === 3; } +/** + * @name getChosung + * @deprecated getChoseong을 사용해 주세요. + * @description + * 단어에서 초성을 추출합니다. (예: `사과` -> `'ㅅㄱ'`) + * ```typescript + * getChosung( + * // 초성을 추출할 단어 + * word: string + * ): string + * ``` + * @example + * getChosung('사과') // 'ㅅㄱ' + * getChosung('리액트') // 'ㄹㅇㅌ' + * getChosung('띄어 쓰기') // 'ㄸㅇ ㅆㄱ' + */ +export function getChosung(word: string) { + return disassembleHangulToGroups(word).reduce((choseong, [consonant]) => { + return `${choseong}${consonant}`; + }, ''); +} + /** * @name getChoseong * @description @@ -100,6 +122,28 @@ export function getFirstConsonants(word: string) { }, ''); } +/** + * @name canBeChosung + * @deprecated canBeChoseong을 사용해 주세요. + * @description + * 인자로 받은 문자가 초성으로 위치할 수 있는 문자인지 검사합니다. + * ```typescript + * canBeChosung( + * // 대상 문자 + * character: string + * ): boolean + * ``` + * @example + * canBeChosung('ㄱ') // true + * canBeChosung('ㅃ') // true + * canBeChosung('ㄱㅅ') // false + * canBeChosung('ㅏ') // false + * canBeChosung('가') // false + */ +export function canBeChosung(character: string): character is (typeof HANGUL_CHARACTERS_BY_FIRST_INDEX)[number] { + return hasValueInReadOnlyStringList(HANGUL_CHARACTERS_BY_FIRST_INDEX, character); +} + /** * @name canBeChoseong * @description @@ -121,6 +165,29 @@ export function canBeChoseong(character: string): character is (typeof HANGUL_CH return hasValueInReadOnlyStringList(HANGUL_CHARACTERS_BY_FIRST_INDEX, character); } +/** + * @name canBeJungsung + * @deprecated canBeJungseong을 사용해 주세요. + * @description + * 인자로 받은 문자가 중성으로 위치할 수 있는 문자인지 검사합니다. + * ```typescript + * canBeJungsung( + * // 대상 문자 + * character: string + * ): boolean + * ``` + * @example + * canBeJungsung('ㅏ') // true + * canBeJungsung('ㅗㅏ') // true + * canBeJungsung('ㅏㅗ') // false + * canBeJungsung('ㄱ') // false + * canBeJungsung('ㄱㅅ') // false + * canBeJungsung('가') // false + */ +export function canBeJungsung(character: string): character is (typeof HANGUL_CHARACTERS_BY_MIDDLE_INDEX)[number] { + return hasValueInReadOnlyStringList(HANGUL_CHARACTERS_BY_MIDDLE_INDEX, character); +} + /** * @name canBeJungseong * @description @@ -143,6 +210,29 @@ export function canBeJungseong(character: string): character is (typeof HANGUL_C return hasValueInReadOnlyStringList(HANGUL_CHARACTERS_BY_MIDDLE_INDEX, character); } +/** + * @name canBeJongsung + * @deprecated canBeJongseong을 사용해 주세요. + * @description + * 인자로 받은 문자가 종성으로 위치할 수 있는 문자인지 검사합니다. + * ```typescript + * canBeJongsung( + * // 대상 문자 + * character: string + * ): boolean + * ``` + * @example + * canBeJongsung('ㄱ') // true + * canBeJongsung('ㄱㅅ') // true + * canBeJongsung('ㅎㄹ') // false + * canBeJongsung('가') // false + * canBeJongsung('ㅏ') // false + * canBeJongsung('ㅗㅏ') // false + */ +export function canBeJongsung(character: string): character is (typeof HANGUL_CHARACTERS_BY_LAST_INDEX)[number] { + return hasValueInReadOnlyStringList(HANGUL_CHARACTERS_BY_LAST_INDEX, character); +} + /** * @name canBeJongseong * @description From 67011d4c5dc7c584b61745bb9645dd3a65c3358b Mon Sep 17 00:00:00 2001 From: Collection50 Date: Mon, 1 Jul 2024 21:49:57 +0900 Subject: [PATCH 03/13] =?UTF-8?q?fix:=20main=20=EB=B8=8C=EB=9E=9C=EC=B9=98?= =?UTF-8?q?=EC=99=80=20merge=EB=A5=BC=20=EC=9C=84=ED=95=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/constants.ts | 10 ++++++++++ src/utils.ts | 24 ++++++++++++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 142cba13..3f95c04e 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -3,6 +3,16 @@ export const COMPLETE_HANGUL_END_CHARCODE = '힣'.charCodeAt(0); export const NUMBER_OF_JONGSEONG = 28; export const NUMBER_OF_JUNGSEONG = 21; +const _JASO_HANGUL_NFD = [...'각힣'.normalize('NFD')].map(char => char.charCodeAt(0)); // NFC 에 정의되지 않은 문자는 포함하지 않음 +export const JASO_HANGUL_NFD = { + START_CHOSEONG: _JASO_HANGUL_NFD[0], // ㄱ + START_JUNGSEONG: _JASO_HANGUL_NFD[1], // ㅏ + START_JONGSEONG: _JASO_HANGUL_NFD[2], // ㄱ + END_CHOSEONG: _JASO_HANGUL_NFD[3], // ㅎ + END_JUNGSEONG: _JASO_HANGUL_NFD[4], // ㅣ + END_JONGSEONG: _JASO_HANGUL_NFD[5], // ㅎ +}; + /** * ㄱ -> 'ㄱ' * ㄳ -> 'ㄱㅅ' 으로 나눈다. diff --git a/src/utils.ts b/src/utils.ts index 0f467b86..d90cc571 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -2,10 +2,20 @@ import { HANGUL_CHARACTERS_BY_FIRST_INDEX, HANGUL_CHARACTERS_BY_LAST_INDEX, HANGUL_CHARACTERS_BY_MIDDLE_INDEX, + JASO_HANGUL_NFD, } from './constants'; import { disassembleHangul, disassembleHangulToGroups } from './disassemble'; import { disassembleCompleteHangulCharacter } from './disassembleCompleteHangulCharacter'; +const EXTRACT_CHOSEONG_REGEX = new RegExp( + `[^\\u${JASO_HANGUL_NFD.START_CHOSEONG.toString(16)}-\\u${JASO_HANGUL_NFD.END_CHOSEONG.toString(16)}ㄱ-ㅎ\\s]+`, + 'ug' +); +const CHOOSE_NFD_CHOSEONG_REGEX = new RegExp( + `[\\u${JASO_HANGUL_NFD.START_CHOSEONG.toString(16)}-\\u${JASO_HANGUL_NFD.END_CHOSEONG.toString(16)}]`, + 'g' +); + /** * @name hasBatchim * @description @@ -74,9 +84,10 @@ export function hasSingleBatchim(str: string) { * getChosung('띄어 쓰기') // 'ㄸㅇ ㅆㄱ' */ export function getChosung(word: string) { - return disassembleHangulToGroups(word).reduce((choseong, [consonant]) => { - return `${choseong}${consonant}`; - }, ''); + 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 } /** @@ -95,9 +106,10 @@ export function getChosung(word: string) { * getChoseong('띄어 쓰기') // 'ㄸㅇ ㅆㄱ' */ export function getChoseong(word: string) { - return disassembleHangulToGroups(word).reduce((choseong, [consonant]) => { - return `${choseong}${consonant}`; - }, ''); + 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 } /** From 5ff9af8ad98c4cde89977193b76917ccd54e9d37 Mon Sep 17 00:00:00 2001 From: Collection50 Date: Mon, 1 Jul 2024 21:53:59 +0900 Subject: [PATCH 04/13] =?UTF-8?q?fix:=20conflict=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/constants.ts | 10 ---------- src/utils.ts | 17 +++++------------ 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 7c6bb384..3f95c04e 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -13,16 +13,6 @@ export const JASO_HANGUL_NFD = { END_JONGSEONG: _JASO_HANGUL_NFD[5], // ㅎ }; -const _JASO_HANGUL_NFD = [...'각힣'.normalize('NFD')].map(char => char.charCodeAt(0)); // NFC 에 정의되지 않은 문자는 포함하지 않음 -export const JASO_HANGUL_NFD = { - START_CHOSEONG: _JASO_HANGUL_NFD[0], // ㄱ - START_JUNGSEONG: _JASO_HANGUL_NFD[1], // ㅏ - START_JONGSEONG: _JASO_HANGUL_NFD[2], // ㄱ - END_CHOSEONG: _JASO_HANGUL_NFD[3], // ㅎ - END_JUNGSEONG: _JASO_HANGUL_NFD[4], // ㅣ - END_JONGSEONG: _JASO_HANGUL_NFD[5], // ㅎ -} - /** * ㄱ -> 'ㄱ' * ㄳ -> 'ㄱㅅ' 으로 나눈다. diff --git a/src/utils.ts b/src/utils.ts index d4c9bfb1..80423ed7 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -5,6 +5,7 @@ import { HANGUL_CHARACTERS_BY_LAST_INDEX, HANGUL_CHARACTERS_BY_MIDDLE_INDEX, JASO_HANGUL_NFD, + NUMBER_OF_JONGSEONG, } from './constants'; import { disassembleHangulToGroups } from './disassemble'; @@ -17,15 +18,6 @@ const CHOOSE_NFD_CHOSEONG_REGEX = new RegExp( 'g' ); -const EXTRACT_CHOSEONG_REGEX = new RegExp( - `[^\\u${JASO_HANGUL_NFD.START_CHOSEONG.toString(16)}-\\u${JASO_HANGUL_NFD.END_CHOSEONG.toString(16)}ㄱ-ㅎ\\s]+`, - 'ug' -); -const CHOOSE_NFD_CHOSEONG_REGEX = new RegExp( - `[\\u${JASO_HANGUL_NFD.START_CHOSEONG.toString(16)}-\\u${JASO_HANGUL_NFD.END_CHOSEONG.toString(16)}]`, - 'g' -); - /** * @name hasBatchim * @description @@ -53,7 +45,7 @@ export function hasBatchim(str: string) { return false; } - return (charCode - COMPLETE_HANGUL_START_CHARCODE) % NUMBER_OF_JONGSUNG > 0; + return (charCode - COMPLETE_HANGUL_START_CHARCODE) % NUMBER_OF_JONGSEONG > 0; } /** @@ -84,7 +76,7 @@ export function hasSingleBatchim(str: string) { return false; } - const batchimCode = (charCode - COMPLETE_HANGUL_START_CHARCODE) % NUMBER_OF_JONGSUNG; + const batchimCode = (charCode - COMPLETE_HANGUL_START_CHARCODE) % NUMBER_OF_JONGSEONG; return HANGUL_CHARACTERS_BY_LAST_INDEX[batchimCode].length === 1; } @@ -127,7 +119,8 @@ export function getChosung(word: string) { * getChoseong('띄어 쓰기') // 'ㄸㅇ ㅆㄱ' */ export function getChoseong(word: string) { - return word.normalize('NFD') + 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 } From a6c0c35d06fda629f22b6fa330d2085c4a8fe501 Mon Sep 17 00:00:00 2001 From: Collection50 Date: Mon, 1 Jul 2024 21:59:13 +0900 Subject: [PATCH 05/13] =?UTF-8?q?fix:=20=EB=AC=B8=EC=84=9C=EC=97=90?= =?UTF-8?q?=EB=8A=94=20chosung=20prefix=EB=A5=BC=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README-en_us.md | 4 ++-- README.md | 4 ++-- .../components/demo/choseong-includes-demo.tsx | 6 +++--- docs/src/pages/docs/api/choseongIncludes.en.mdx | 16 ++++++++-------- docs/src/pages/docs/api/choseongIncludes.ko.mdx | 16 ++++++++-------- docs/src/pages/docs/introduction.en.mdx | 10 +++++----- docs/src/pages/docs/introduction.ko.mdx | 10 +++++----- docs/src/pages/index.en.mdx | 4 ++-- docs/src/pages/index.ko.mdx | 4 ++-- 9 files changed, 37 insertions(+), 37 deletions(-) diff --git a/README-en_us.md b/README-en_us.md index a629726c..caacd0a4 100644 --- a/README-en_us.md +++ b/README-en_us.md @@ -11,12 +11,12 @@ es-hangul is a library that makes it easy to handle [Hangul](https://en.wikipedi You can easily implement tasks related to Hangul, such as initial consonant search and attaching particles(josas). ```tsx -import { choseongIncludes } from 'es-hangul'; +import { chosungIncludes } from 'es-hangul'; const searchWord = '라면'; const userInput = 'ㄹㅁ'; -const result = choseongIncludes(searchWord, userInput); // true +const result = chosungIncludes(searchWord, userInput); // true ``` ```tsx diff --git a/README.md b/README.md index c91c9048..58c4b604 100644 --- a/README.md +++ b/README.md @@ -11,12 +11,12 @@ 초성 검색, 조사 붙이기와 같은 한글 작업을 간단히 할 수 있습니다. ```tsx -import { choseongIncludes } from 'es-hangul'; +import { chosungIncludes } from 'es-hangul'; const searchWord = '라면'; const userInput = 'ㄹㅁ'; -const result = choseongIncludes(searchWord, userInput); // true +const result = chosungIncludes(searchWord, userInput); // true ``` ```tsx diff --git a/docs/src/components/demo/choseong-includes-demo.tsx b/docs/src/components/demo/choseong-includes-demo.tsx index e0d5bf7e..c251060d 100644 --- a/docs/src/components/demo/choseong-includes-demo.tsx +++ b/docs/src/components/demo/choseong-includes-demo.tsx @@ -1,11 +1,11 @@ import React, { useState } from 'react'; -import { choseongIncludes } from 'es-hangul'; +import { chosungIncludes } from 'es-hangul'; -export function choseongIncludesDemo() { +export function chosungIncludesDemo() { const [searchWord, setSearchWord] = useState('홍길동'); const [userInput, setUserInput] = useState('ㅎㄱㄷ'); - const result = choseongIncludes(searchWord, userInput); + const result = chosungIncludes(searchWord, userInput); return (
diff --git a/docs/src/pages/docs/api/choseongIncludes.en.mdx b/docs/src/pages/docs/api/choseongIncludes.en.mdx index d50494bf..a2aed372 100644 --- a/docs/src/pages/docs/api/choseongIncludes.en.mdx +++ b/docs/src/pages/docs/api/choseongIncludes.en.mdx @@ -1,11 +1,11 @@ -import { choseongIncludesDemo } from '@/components/demo/choseong-includes-demo'; +import { chosungIncludesDemo } from '@/components/demo/chosung-includes-demo'; -# choseongIncludes +# chosungIncludes Performs a search for matches in the initial consonants of a string. ```typescript -function choseongIncludes( +function chosungIncludes( // The string to be checked for matching initial consonants (e.g., '프론트엔드') x: string, // Initial consonant string (e.g., 'ㅍㄹㅌㅇㄷ') @@ -14,14 +14,14 @@ function choseongIncludes( ``` ```typescript -choseongIncludes('프론트엔드', 'ㅍㄹㅌ'); // true -choseongIncludes('00프론트엔드', 'ㅍㄹㅌ'); // true -choseongIncludes('프론트엔드', 'ㅍㅌ'); // false -choseongIncludes('프론트엔드', '푸롴트'); // false +chosungIncludes('프론트엔드', 'ㅍㄹㅌ'); // true +chosungIncludes('00프론트엔드', 'ㅍㄹㅌ'); // true +chosungIncludes('프론트엔드', 'ㅍㅌ'); // false +chosungIncludes('프론트엔드', '푸롴트'); // false ``` ## Demo
- + diff --git a/docs/src/pages/docs/api/choseongIncludes.ko.mdx b/docs/src/pages/docs/api/choseongIncludes.ko.mdx index 3f1058a9..a2645bef 100644 --- a/docs/src/pages/docs/api/choseongIncludes.ko.mdx +++ b/docs/src/pages/docs/api/choseongIncludes.ko.mdx @@ -1,11 +1,11 @@ -import { choseongIncludesDemo } from '@/components/demo/choseong-includes-demo'; +import { chosungIncludesDemo } from '@/components/demo/chosung-includes-demo'; -# choseongIncludes +# chosungIncludes 문자열의 초성 일치 검색을 수행합니다. ```typescript -function choseongIncludes( +function chosungIncludes( // 초성 일치하는지 검사할 문자열 (e.g. '프론트엔드') x: string, // 초성 문자열 (e.g. 'ㅍㄹㅌㅇㄷ') @@ -14,14 +14,14 @@ function choseongIncludes( ``` ```typescript -choseongIncludes('프론트엔드', 'ㅍㄹㅌ'); // true -choseongIncludes('00프론트엔드', 'ㅍㄹㅌ'); // true -choseongIncludes('프론트엔드', 'ㅍㅌ'); // false -choseongIncludes('프론트엔드', '푸롴트'); // false +chosungIncludes('프론트엔드', 'ㅍㄹㅌ'); // true +chosungIncludes('00프론트엔드', 'ㅍㄹㅌ'); // true +chosungIncludes('프론트엔드', 'ㅍㅌ'); // false +chosungIncludes('프론트엔드', '푸롴트'); // false ``` ## 사용해보기
- + diff --git a/docs/src/pages/docs/introduction.en.mdx b/docs/src/pages/docs/introduction.en.mdx index 06a7408f..8a0047de 100644 --- a/docs/src/pages/docs/introduction.en.mdx +++ b/docs/src/pages/docs/introduction.en.mdx @@ -31,19 +31,19 @@ Our library provides strong typing, allowing for easy detection of type errors d ### Full Support for Hangul-related Features -Our library provides a [modern API](./api/choseongIncludes) that can be conveniently used in various applications. +Our library provides a [modern API](./api/chosungIncludes) that can be conveniently used in various applications. -#### First Consonant Search ([choseongIncludes](./api/choseongIncludes)) +#### First Consonant Search ([chosungIncludes](./api/chosungIncludes)) It checks whether an initial consonant is included in a specific word. For example, you can easily find out if the word '라면' (ramyeon) contains the initial consonants 'ㄹㅁ'. -```tsx /choseongIncludes/ -import { choseongIncludes } from 'es-hangul'; +```tsx /chosungIncludes/ +import { chosungIncludes } from 'es-hangul'; const searchWord = '라면'; const userInput = 'ㄹㅁ'; -const result = choseongIncludes(searchWord, userInput); +const result = chosungIncludes(searchWord, userInput); console.log(result); // true ``` diff --git a/docs/src/pages/docs/introduction.ko.mdx b/docs/src/pages/docs/introduction.ko.mdx index 73b27d6d..7d7881ac 100644 --- a/docs/src/pages/docs/introduction.ko.mdx +++ b/docs/src/pages/docs/introduction.ko.mdx @@ -31,19 +31,19 @@ ECMAScript Modules를 이용하여 사용하는 함수만 애플리케이션에 ### 한글을 위한 모든 인터페이스를 제공하는 것을 목표합니다 -다양한 애플리케이션에서 편리하게 사용할 수 있는 [현대적인 API](./api/choseongIncludes)를 제공합니다. +다양한 애플리케이션에서 편리하게 사용할 수 있는 [현대적인 API](./api/chosungIncludes)를 제공합니다. -#### 초성 검색 ([choseongIncludes](./api/choseongIncludes)) +#### 초성 검색 ([chosungIncludes](./api/chosungIncludes)) 초성이 특정 단어에 포함되어 있는지 검사합니다. 예를 들어, '라면'이라는 단어가 'ㄹㅁ'으로 시작하는 초성을 포함하는지 쉽게 알 수 있습니다. -```tsx /choseongIncludes/ -import { choseongIncludes } from 'es-hangul'; +```tsx /chosungIncludes/ +import { chosungIncludes } from 'es-hangul'; const searchWord = '라면'; const userInput = 'ㄹㅁ'; -const result = choseongIncludes(searchWord, userInput); +const result = chosungIncludes(searchWord, userInput); console.log(result); // true ``` diff --git a/docs/src/pages/index.en.mdx b/docs/src/pages/index.en.mdx index e4d60454..b4d1a4f4 100644 --- a/docs/src/pages/index.en.mdx +++ b/docs/src/pages/index.en.mdx @@ -34,12 +34,12 @@ import { Callout, useTheme, Steps } from 'nextra-theme-docs';
```tsx -import { choseongIncludes } from 'es-hangul'; +import { chosungIncludes } from 'es-hangul'; const searchWord = '라면'; const userInput = 'ㄹㅁ'; -const result = choseongIncludes(searchWord, userInput); +const result = chosungIncludes(searchWord, userInput); console.log(result); // true ``` diff --git a/docs/src/pages/index.ko.mdx b/docs/src/pages/index.ko.mdx index a86d1f68..7807a6e8 100644 --- a/docs/src/pages/index.ko.mdx +++ b/docs/src/pages/index.ko.mdx @@ -34,12 +34,12 @@ import { Callout, useTheme, Steps } from 'nextra-theme-docs'; ```tsx -import { choseongIncludes } from 'es-hangul'; +import { chosungIncludes } from 'es-hangul'; const searchWord = '라면'; const userInput = 'ㄹㅁ'; -const result = choseongIncludes(searchWord, userInput); +const result = chosungIncludes(searchWord, userInput); console.log(result); // true ``` From 63ee040e7fb77d65d384b1e5fb295ca91e3a42e8 Mon Sep 17 00:00:00 2001 From: Collection50 Date: Fri, 5 Jul 2024 16:23:26 +0900 Subject: [PATCH 06/13] =?UTF-8?q?fix:=20ChoseongIncludesDemo=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/src/components/demo/choseong-includes-demo.tsx | 2 +- docs/src/pages/docs/api/choseongIncludes.en.mdx | 4 ++-- docs/src/pages/docs/api/choseongIncludes.ko.mdx | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/src/components/demo/choseong-includes-demo.tsx b/docs/src/components/demo/choseong-includes-demo.tsx index c251060d..cacefbf9 100644 --- a/docs/src/components/demo/choseong-includes-demo.tsx +++ b/docs/src/components/demo/choseong-includes-demo.tsx @@ -1,7 +1,7 @@ import React, { useState } from 'react'; import { chosungIncludes } from 'es-hangul'; -export function chosungIncludesDemo() { +export function ChoseongIncludesDemo() { const [searchWord, setSearchWord] = useState('홍길동'); const [userInput, setUserInput] = useState('ㅎㄱㄷ'); diff --git a/docs/src/pages/docs/api/choseongIncludes.en.mdx b/docs/src/pages/docs/api/choseongIncludes.en.mdx index a2aed372..8e2157a1 100644 --- a/docs/src/pages/docs/api/choseongIncludes.en.mdx +++ b/docs/src/pages/docs/api/choseongIncludes.en.mdx @@ -1,4 +1,4 @@ -import { chosungIncludesDemo } from '@/components/demo/chosung-includes-demo'; +import { ChoseongIncludesDemo } from '@/components/demo/chosung-includes-demo'; # chosungIncludes @@ -24,4 +24,4 @@ chosungIncludes('프론트엔드', '푸롴트'); // false
- + diff --git a/docs/src/pages/docs/api/choseongIncludes.ko.mdx b/docs/src/pages/docs/api/choseongIncludes.ko.mdx index a2645bef..9dfb0a5f 100644 --- a/docs/src/pages/docs/api/choseongIncludes.ko.mdx +++ b/docs/src/pages/docs/api/choseongIncludes.ko.mdx @@ -1,4 +1,4 @@ -import { chosungIncludesDemo } from '@/components/demo/chosung-includes-demo'; +import { ChoseongIncludesDemo } from '@/components/demo/chosung-includes-demo'; # chosungIncludes @@ -24,4 +24,4 @@ chosungIncludes('프론트엔드', '푸롴트'); // false
- + From 3cd80121a0763e4f0fa6d1500b3f8967a6cf7df4 Mon Sep 17 00:00:00 2001 From: Minsoo Kim <57122180+minsoo-web@users.noreply.github.com> Date: Tue, 9 Jul 2024 13:39:16 +0900 Subject: [PATCH 07/13] =?UTF-8?q?chore:=20cspell.json=20=EC=9C=BC=EB=A1=9C?= =?UTF-8?q?=20=EC=84=A4=EC=A0=95=EC=9D=84=20=EB=B3=80=EA=B2=BD=ED=95=A9?= =?UTF-8?q?=EB=8B=88=EB=8B=A4.=20(#172)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc.js | 10 ---------- cspell.json | 3 +++ 2 files changed, 3 insertions(+), 10 deletions(-) create mode 100644 cspell.json diff --git a/.eslintrc.js b/.eslintrc.js index 87dce246..92c40809 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -66,15 +66,5 @@ module.exports = { ], }, ], - '@cspell/spellchecker': [ - 'error', - { - cspell: { - words: ['choseong', 'jungseong', 'jongseong'], - // eslint-disable-next-line @cspell/spellchecker - flagWords: ['chosung', 'jungsung', 'jongsung'], - }, - }, - ], }, }; diff --git a/cspell.json b/cspell.json new file mode 100644 index 00000000..920ede97 --- /dev/null +++ b/cspell.json @@ -0,0 +1,3 @@ +{ + "words": ["choseong", "jungseong", "jongseong"] +} From 18dc23371ddeea88848973535d5cf94d8e35e505 Mon Sep 17 00:00:00 2001 From: Collection50 Date: Thu, 27 Jun 2024 01:27:02 +0900 Subject: [PATCH 08/13] =?UTF-8?q?fix:=20=EC=9D=BC=EA=B4=80=EB=90=9C=20?= =?UTF-8?q?=ED=95=9C=EA=B8=80=20=ED=91=9C=EA=B8=B0=EB=B2=95=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README-en_us.md | 4 +- README.md | 4 +- .../demo/choseong-includes-demo.tsx | 4 +- .../pages/docs/api/choseongIncludes.en.mdx | 10 ++-- .../pages/docs/api/choseongIncludes.ko.mdx | 14 +++--- docs/src/pages/docs/introduction.en.mdx | 10 ++-- docs/src/pages/docs/introduction.ko.mdx | 10 ++-- docs/src/pages/index.en.mdx | 4 +- docs/src/pages/index.ko.mdx | 4 +- src/_internal/hangul.spec.ts | 12 +++-- src/index.ts | 13 +++++ src/utils.ts | 48 +++++++++---------- 12 files changed, 77 insertions(+), 60 deletions(-) diff --git a/README-en_us.md b/README-en_us.md index caacd0a4..a629726c 100644 --- a/README-en_us.md +++ b/README-en_us.md @@ -11,12 +11,12 @@ es-hangul is a library that makes it easy to handle [Hangul](https://en.wikipedi You can easily implement tasks related to Hangul, such as initial consonant search and attaching particles(josas). ```tsx -import { chosungIncludes } from 'es-hangul'; +import { choseongIncludes } from 'es-hangul'; const searchWord = '라면'; const userInput = 'ㄹㅁ'; -const result = chosungIncludes(searchWord, userInput); // true +const result = choseongIncludes(searchWord, userInput); // true ``` ```tsx diff --git a/README.md b/README.md index 58c4b604..c91c9048 100644 --- a/README.md +++ b/README.md @@ -11,12 +11,12 @@ 초성 검색, 조사 붙이기와 같은 한글 작업을 간단히 할 수 있습니다. ```tsx -import { chosungIncludes } from 'es-hangul'; +import { choseongIncludes } from 'es-hangul'; const searchWord = '라면'; const userInput = 'ㄹㅁ'; -const result = chosungIncludes(searchWord, userInput); // true +const result = choseongIncludes(searchWord, userInput); // true ``` ```tsx diff --git a/docs/src/components/demo/choseong-includes-demo.tsx b/docs/src/components/demo/choseong-includes-demo.tsx index cacefbf9..faaf8c8c 100644 --- a/docs/src/components/demo/choseong-includes-demo.tsx +++ b/docs/src/components/demo/choseong-includes-demo.tsx @@ -1,11 +1,11 @@ import React, { useState } from 'react'; -import { chosungIncludes } from 'es-hangul'; +import { choseongIncludes } from 'es-hangul'; export function ChoseongIncludesDemo() { const [searchWord, setSearchWord] = useState('홍길동'); const [userInput, setUserInput] = useState('ㅎㄱㄷ'); - const result = chosungIncludes(searchWord, userInput); + const result = choseongIncludes(searchWord, userInput); return (
diff --git a/docs/src/pages/docs/api/choseongIncludes.en.mdx b/docs/src/pages/docs/api/choseongIncludes.en.mdx index 8e2157a1..cee4236c 100644 --- a/docs/src/pages/docs/api/choseongIncludes.en.mdx +++ b/docs/src/pages/docs/api/choseongIncludes.en.mdx @@ -5,7 +5,7 @@ import { ChoseongIncludesDemo } from '@/components/demo/chosung-includes-demo'; Performs a search for matches in the initial consonants of a string. ```typescript -function chosungIncludes( +function choseongIncludes( // The string to be checked for matching initial consonants (e.g., '프론트엔드') x: string, // Initial consonant string (e.g., 'ㅍㄹㅌㅇㄷ') @@ -14,10 +14,10 @@ function chosungIncludes( ``` ```typescript -chosungIncludes('프론트엔드', 'ㅍㄹㅌ'); // true -chosungIncludes('00프론트엔드', 'ㅍㄹㅌ'); // true -chosungIncludes('프론트엔드', 'ㅍㅌ'); // false -chosungIncludes('프론트엔드', '푸롴트'); // false +choseongIncludes('프론트엔드', 'ㅍㄹㅌ'); // true +choseongIncludes('00프론트엔드', 'ㅍㄹㅌ'); // true +choseongIncludes('프론트엔드', 'ㅍㅌ'); // false +choseongIncludes('프론트엔드', '푸롴트'); // false ``` ## Demo diff --git a/docs/src/pages/docs/api/choseongIncludes.ko.mdx b/docs/src/pages/docs/api/choseongIncludes.ko.mdx index 9dfb0a5f..35c2b702 100644 --- a/docs/src/pages/docs/api/choseongIncludes.ko.mdx +++ b/docs/src/pages/docs/api/choseongIncludes.ko.mdx @@ -1,11 +1,11 @@ -import { ChoseongIncludesDemo } from '@/components/demo/chosung-includes-demo'; +import { ChoseongIncludesDemo } from '@/components/demo/choseong-includes-demo'; -# chosungIncludes +# choseongIncludes 문자열의 초성 일치 검색을 수행합니다. ```typescript -function chosungIncludes( +function choseongIncludes( // 초성 일치하는지 검사할 문자열 (e.g. '프론트엔드') x: string, // 초성 문자열 (e.g. 'ㅍㄹㅌㅇㄷ') @@ -14,10 +14,10 @@ function chosungIncludes( ``` ```typescript -chosungIncludes('프론트엔드', 'ㅍㄹㅌ'); // true -chosungIncludes('00프론트엔드', 'ㅍㄹㅌ'); // true -chosungIncludes('프론트엔드', 'ㅍㅌ'); // false -chosungIncludes('프론트엔드', '푸롴트'); // false +choseongIncludes('프론트엔드', 'ㅍㄹㅌ'); // true +choseongIncludes('00프론트엔드', 'ㅍㄹㅌ'); // true +choseongIncludes('프론트엔드', 'ㅍㅌ'); // false +choseongIncludes('프론트엔드', '푸롴트'); // false ``` ## 사용해보기 diff --git a/docs/src/pages/docs/introduction.en.mdx b/docs/src/pages/docs/introduction.en.mdx index 8a0047de..06a7408f 100644 --- a/docs/src/pages/docs/introduction.en.mdx +++ b/docs/src/pages/docs/introduction.en.mdx @@ -31,19 +31,19 @@ Our library provides strong typing, allowing for easy detection of type errors d ### Full Support for Hangul-related Features -Our library provides a [modern API](./api/chosungIncludes) that can be conveniently used in various applications. +Our library provides a [modern API](./api/choseongIncludes) that can be conveniently used in various applications. -#### First Consonant Search ([chosungIncludes](./api/chosungIncludes)) +#### First Consonant Search ([choseongIncludes](./api/choseongIncludes)) It checks whether an initial consonant is included in a specific word. For example, you can easily find out if the word '라면' (ramyeon) contains the initial consonants 'ㄹㅁ'. -```tsx /chosungIncludes/ -import { chosungIncludes } from 'es-hangul'; +```tsx /choseongIncludes/ +import { choseongIncludes } from 'es-hangul'; const searchWord = '라면'; const userInput = 'ㄹㅁ'; -const result = chosungIncludes(searchWord, userInput); +const result = choseongIncludes(searchWord, userInput); console.log(result); // true ``` diff --git a/docs/src/pages/docs/introduction.ko.mdx b/docs/src/pages/docs/introduction.ko.mdx index 7d7881ac..73b27d6d 100644 --- a/docs/src/pages/docs/introduction.ko.mdx +++ b/docs/src/pages/docs/introduction.ko.mdx @@ -31,19 +31,19 @@ ECMAScript Modules를 이용하여 사용하는 함수만 애플리케이션에 ### 한글을 위한 모든 인터페이스를 제공하는 것을 목표합니다 -다양한 애플리케이션에서 편리하게 사용할 수 있는 [현대적인 API](./api/chosungIncludes)를 제공합니다. +다양한 애플리케이션에서 편리하게 사용할 수 있는 [현대적인 API](./api/choseongIncludes)를 제공합니다. -#### 초성 검색 ([chosungIncludes](./api/chosungIncludes)) +#### 초성 검색 ([choseongIncludes](./api/choseongIncludes)) 초성이 특정 단어에 포함되어 있는지 검사합니다. 예를 들어, '라면'이라는 단어가 'ㄹㅁ'으로 시작하는 초성을 포함하는지 쉽게 알 수 있습니다. -```tsx /chosungIncludes/ -import { chosungIncludes } from 'es-hangul'; +```tsx /choseongIncludes/ +import { choseongIncludes } from 'es-hangul'; const searchWord = '라면'; const userInput = 'ㄹㅁ'; -const result = chosungIncludes(searchWord, userInput); +const result = choseongIncludes(searchWord, userInput); console.log(result); // true ``` diff --git a/docs/src/pages/index.en.mdx b/docs/src/pages/index.en.mdx index b4d1a4f4..e4d60454 100644 --- a/docs/src/pages/index.en.mdx +++ b/docs/src/pages/index.en.mdx @@ -34,12 +34,12 @@ import { Callout, useTheme, Steps } from 'nextra-theme-docs';
```tsx -import { chosungIncludes } from 'es-hangul'; +import { choseongIncludes } from 'es-hangul'; const searchWord = '라면'; const userInput = 'ㄹㅁ'; -const result = chosungIncludes(searchWord, userInput); +const result = choseongIncludes(searchWord, userInput); console.log(result); // true ``` diff --git a/docs/src/pages/index.ko.mdx b/docs/src/pages/index.ko.mdx index 7807a6e8..a86d1f68 100644 --- a/docs/src/pages/index.ko.mdx +++ b/docs/src/pages/index.ko.mdx @@ -34,12 +34,12 @@ import { Callout, useTheme, Steps } from 'nextra-theme-docs'; ```tsx -import { chosungIncludes } from 'es-hangul'; +import { choseongIncludes } from 'es-hangul'; const searchWord = '라면'; const userInput = 'ㄹㅁ'; -const result = chosungIncludes(searchWord, userInput); +const result = choseongIncludes(searchWord, userInput); console.log(result); // true ``` diff --git a/src/_internal/hangul.spec.ts b/src/_internal/hangul.spec.ts index f09f88b2..50d53769 100644 --- a/src/_internal/hangul.spec.ts +++ b/src/_internal/hangul.spec.ts @@ -122,11 +122,15 @@ describe('binaryAssembleHangulCharacters', () => { }); it('다음 문자가 한글 문자 한 글자가 아니라면 Invalid next character 에러를 발생시킨다.', () => { - expect(() => binaryAssembleHangulCharacters('ㄱ', 'a')).toThrowError( - 'Invalid next character: a. Next character must be one of the chosung, jungsung, or jongsung.' + assert.throws( + () => binaryAssembleHangulCharacters('ㄱ', 'a'), + Error, + 'Invalid next character: a. Next character must be one of the choseong, jungseong, or jongseong.' ); - expect(() => binaryAssembleHangulCharacters('ㄱ', 'ㅡㅏ')).toThrowError( - 'Invalid next character: ㅡㅏ. Next character must be one of the chosung, jungsung, or jongsung.' + assert.throws( + () => binaryAssembleHangulCharacters('ㄱ', 'ㅡㅏ'), + Error, + 'Invalid next character: ㅡㅏ. Next character must be one of the choseong, jungseong, or jongseong.' ); }); }); diff --git a/src/index.ts b/src/index.ts index 5e839a05..29aac3c0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,4 @@ +<<<<<<< HEAD export { assembleHangul } from './assemble'; export { chosungIncludes } from './chosungIncludes'; export { combineHangulCharacter, combineVowels, curriedCombineHangulCharacter } from './combineHangulCharacter'; @@ -19,3 +20,15 @@ export { } from './utils'; export { extractHangul } from './extractHangul'; export { acronymizeHangul } from './acronymizeHangul'; +======= +export * from './assemble'; +export * from './choseongIncludes'; +export * from './combineHangulCharacter'; +export * from './convertQwertyToHangulAlphabet'; +export * from './disassemble'; +export * from './disassembleCompleteHangulCharacter'; +export * from './hangulIncludes'; +export * from './josa'; +export * from './removeLastHangulCharacter'; +export * from './utils'; +>>>>>>> bdeca9f (fix: 일관된 한글 표기법 적용) diff --git a/src/utils.ts b/src/utils.ts index 80423ed7..f8a8d74b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -86,15 +86,15 @@ export function hasSingleBatchim(str: string) { * @description * 단어에서 초성을 추출합니다. (예: `사과` -> `'ㅅㄱ'`) * ```typescript - * getChosung( + * getChoseong( * // 초성을 추출할 단어 * word: string * ): string * ``` * @example - * getChosung('사과') // 'ㅅㄱ' - * getChosung('리액트') // 'ㄹㅇㅌ' - * getChosung('띄어 쓰기') // 'ㄸㅇ ㅆㄱ' + * getChoseong('사과') // 'ㅅㄱ' + * getChoseong('리액트') // 'ㄹㅇㅌ' + * getChoseong('띄어 쓰기') // 'ㄸㅇ ㅆㄱ' */ export function getChosung(word: string) { return word @@ -153,17 +153,17 @@ export function getFirstConsonants(word: string) { * @description * 인자로 받은 문자가 초성으로 위치할 수 있는 문자인지 검사합니다. * ```typescript - * canBeChosung( + * canBeChoseong( * // 대상 문자 * character: string * ): boolean * ``` * @example - * canBeChosung('ㄱ') // true - * canBeChosung('ㅃ') // true - * canBeChosung('ㄱㅅ') // false - * canBeChosung('ㅏ') // false - * canBeChosung('가') // false + * canBeChoseong('ㄱ') // true + * canBeChoseong('ㅃ') // true + * canBeChoseong('ㄱㅅ') // false + * canBeChoseong('ㅏ') // false + * canBeChoseong('가') // false */ export function canBeChosung(character: string): character is (typeof HANGUL_CHARACTERS_BY_FIRST_INDEX)[number] { return hasValueInReadOnlyStringList(HANGUL_CHARACTERS_BY_FIRST_INDEX, character); @@ -196,18 +196,18 @@ export function canBeChoseong(character: string): character is (typeof HANGUL_CH * @description * 인자로 받은 문자가 중성으로 위치할 수 있는 문자인지 검사합니다. * ```typescript - * canBeJungsung( + * canBeJungseong( * // 대상 문자 * character: string * ): boolean * ``` * @example - * canBeJungsung('ㅏ') // true - * canBeJungsung('ㅗㅏ') // true - * canBeJungsung('ㅏㅗ') // false - * canBeJungsung('ㄱ') // false - * canBeJungsung('ㄱㅅ') // false - * canBeJungsung('가') // false + * canBeJungseong('ㅏ') // true + * canBeJungseong('ㅗㅏ') // true + * canBeJungseong('ㅏㅗ') // false + * canBeJungseong('ㄱ') // false + * canBeJungseong('ㄱㅅ') // false + * canBeJungseong('가') // false */ export function canBeJungsung(character: string): character is (typeof HANGUL_CHARACTERS_BY_MIDDLE_INDEX)[number] { return hasValueInReadOnlyStringList(HANGUL_CHARACTERS_BY_MIDDLE_INDEX, character); @@ -241,18 +241,18 @@ export function canBeJungseong(character: string): character is (typeof HANGUL_C * @description * 인자로 받은 문자가 종성으로 위치할 수 있는 문자인지 검사합니다. * ```typescript - * canBeJongsung( + * canBeJongseong( * // 대상 문자 * character: string * ): boolean * ``` * @example - * canBeJongsung('ㄱ') // true - * canBeJongsung('ㄱㅅ') // true - * canBeJongsung('ㅎㄹ') // false - * canBeJongsung('가') // false - * canBeJongsung('ㅏ') // false - * canBeJongsung('ㅗㅏ') // false + * canBeJongseong('ㄱ') // true + * canBeJongseong('ㄱㅅ') // true + * canBeJongseong('ㅎㄹ') // false + * canBeJongseong('가') // false + * canBeJongseong('ㅏ') // false + * canBeJongseong('ㅗㅏ') // false */ export function canBeJongsung(character: string): character is (typeof HANGUL_CHARACTERS_BY_LAST_INDEX)[number] { return hasValueInReadOnlyStringList(HANGUL_CHARACTERS_BY_LAST_INDEX, character); From 5ee57f970393f15d36411475c2611a1e0456303a Mon Sep 17 00:00:00 2001 From: Collection50 Date: Mon, 1 Jul 2024 21:42:17 +0900 Subject: [PATCH 09/13] =?UTF-8?q?fix:=20=EA=B8=B0=EC=A1=B4=EC=9D=98=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=EB=A5=BC=20=EC=9C=A0=EC=A7=80=ED=95=9C=20?= =?UTF-8?q?=EC=B1=84,=20deprecated=20=EB=90=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 1 + src/utils.ts | 40 ++++++++++++++++++++-------------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/index.ts b/src/index.ts index 29aac3c0..efef6d3a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -23,6 +23,7 @@ export { acronymizeHangul } from './acronymizeHangul'; ======= export * from './assemble'; export * from './choseongIncludes'; +export * from './chosungIncludes'; export * from './combineHangulCharacter'; export * from './convertQwertyToHangulAlphabet'; export * from './disassemble'; diff --git a/src/utils.ts b/src/utils.ts index f8a8d74b..2a5bd3c8 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -153,17 +153,17 @@ export function getFirstConsonants(word: string) { * @description * 인자로 받은 문자가 초성으로 위치할 수 있는 문자인지 검사합니다. * ```typescript - * canBeChoseong( + * canBeChosung( * // 대상 문자 * character: string * ): boolean * ``` * @example - * canBeChoseong('ㄱ') // true - * canBeChoseong('ㅃ') // true - * canBeChoseong('ㄱㅅ') // false - * canBeChoseong('ㅏ') // false - * canBeChoseong('가') // false + * canBeChosung('ㄱ') // true + * canBeChosung('ㅃ') // true + * canBeChosung('ㄱㅅ') // false + * canBeChosung('ㅏ') // false + * canBeChosung('가') // false */ export function canBeChosung(character: string): character is (typeof HANGUL_CHARACTERS_BY_FIRST_INDEX)[number] { return hasValueInReadOnlyStringList(HANGUL_CHARACTERS_BY_FIRST_INDEX, character); @@ -196,18 +196,18 @@ export function canBeChoseong(character: string): character is (typeof HANGUL_CH * @description * 인자로 받은 문자가 중성으로 위치할 수 있는 문자인지 검사합니다. * ```typescript - * canBeJungseong( + * canBeJungsung( * // 대상 문자 * character: string * ): boolean * ``` * @example - * canBeJungseong('ㅏ') // true - * canBeJungseong('ㅗㅏ') // true - * canBeJungseong('ㅏㅗ') // false - * canBeJungseong('ㄱ') // false - * canBeJungseong('ㄱㅅ') // false - * canBeJungseong('가') // false + * canBeJungsung('ㅏ') // true + * canBeJungsung('ㅗㅏ') // true + * canBeJungsung('ㅏㅗ') // false + * canBeJungsung('ㄱ') // false + * canBeJungsung('ㄱㅅ') // false + * canBeJungsung('가') // false */ export function canBeJungsung(character: string): character is (typeof HANGUL_CHARACTERS_BY_MIDDLE_INDEX)[number] { return hasValueInReadOnlyStringList(HANGUL_CHARACTERS_BY_MIDDLE_INDEX, character); @@ -241,18 +241,18 @@ export function canBeJungseong(character: string): character is (typeof HANGUL_C * @description * 인자로 받은 문자가 종성으로 위치할 수 있는 문자인지 검사합니다. * ```typescript - * canBeJongseong( + * canBeJongsung( * // 대상 문자 * character: string * ): boolean * ``` * @example - * canBeJongseong('ㄱ') // true - * canBeJongseong('ㄱㅅ') // true - * canBeJongseong('ㅎㄹ') // false - * canBeJongseong('가') // false - * canBeJongseong('ㅏ') // false - * canBeJongseong('ㅗㅏ') // false + * canBeJongsung('ㄱ') // true + * canBeJongsung('ㄱㅅ') // true + * canBeJongsung('ㅎㄹ') // false + * canBeJongsung('가') // false + * canBeJongsung('ㅏ') // false + * canBeJongsung('ㅗㅏ') // false */ export function canBeJongsung(character: string): character is (typeof HANGUL_CHARACTERS_BY_LAST_INDEX)[number] { return hasValueInReadOnlyStringList(HANGUL_CHARACTERS_BY_LAST_INDEX, character); From cad991649170979a53641af125c1455908982e76 Mon Sep 17 00:00:00 2001 From: Collection50 Date: Tue, 9 Jul 2024 14:40:19 +0900 Subject: [PATCH 10/13] =?UTF-8?q?docs:=20chosung~=20=EB=AC=B8=EC=84=9C=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...des-demo.tsx => chosung-includes-demo.tsx} | 6 ++--- .../pages/docs/api/choseongIncludes.en.mdx | 2 +- .../src/pages/docs/api/chosungIncludes.en.mdx | 27 +++++++++++++++++++ .../src/pages/docs/api/chosungIncludes.ko.mdx | 27 +++++++++++++++++++ src/index.ts | 14 ---------- 5 files changed, 58 insertions(+), 18 deletions(-) rename docs/src/components/demo/{choseong-includes-demo.tsx => chosung-includes-demo.tsx} (92%) create mode 100644 docs/src/pages/docs/api/chosungIncludes.en.mdx create mode 100644 docs/src/pages/docs/api/chosungIncludes.ko.mdx diff --git a/docs/src/components/demo/choseong-includes-demo.tsx b/docs/src/components/demo/chosung-includes-demo.tsx similarity index 92% rename from docs/src/components/demo/choseong-includes-demo.tsx rename to docs/src/components/demo/chosung-includes-demo.tsx index faaf8c8c..393f9ccb 100644 --- a/docs/src/components/demo/choseong-includes-demo.tsx +++ b/docs/src/components/demo/chosung-includes-demo.tsx @@ -1,11 +1,11 @@ import React, { useState } from 'react'; -import { choseongIncludes } from 'es-hangul'; +import { chosungIncludes } from 'es-hangul'; -export function ChoseongIncludesDemo() { +export function ChosungIncludesDemo() { const [searchWord, setSearchWord] = useState('홍길동'); const [userInput, setUserInput] = useState('ㅎㄱㄷ'); - const result = choseongIncludes(searchWord, userInput); + const result = chosungIncludes(searchWord, userInput); return (
diff --git a/docs/src/pages/docs/api/choseongIncludes.en.mdx b/docs/src/pages/docs/api/choseongIncludes.en.mdx index cee4236c..3d17d25c 100644 --- a/docs/src/pages/docs/api/choseongIncludes.en.mdx +++ b/docs/src/pages/docs/api/choseongIncludes.en.mdx @@ -1,6 +1,6 @@ import { ChoseongIncludesDemo } from '@/components/demo/chosung-includes-demo'; -# chosungIncludes +# choseongIncludes Performs a search for matches in the initial consonants of a string. diff --git a/docs/src/pages/docs/api/chosungIncludes.en.mdx b/docs/src/pages/docs/api/chosungIncludes.en.mdx new file mode 100644 index 00000000..986deebb --- /dev/null +++ b/docs/src/pages/docs/api/chosungIncludes.en.mdx @@ -0,0 +1,27 @@ +import { ChosungIncludesDemo } from '@/components/demo/chosung-includes-demo'; + +# chosungIncludes (deprecated, Please use choseongIncludes) + +Performs a search for matches in the initial consonants of a string. + +```typescript +function chosungIncludes( + // The string to be checked for matching initial consonants (e.g., '프론트엔드') + x: string, + // Initial consonant string (e.g., 'ㅍㄹㅌㅇㄷ') + y: string +): boolean; +``` + +```typescript +chosungIncludes('프론트엔드', 'ㅍㄹㅌ'); // true +chosungIncludes('00프론트엔드', 'ㅍㄹㅌ'); // true +chosungIncludes('프론트엔드', 'ㅍㅌ'); // false +chosungIncludes('프론트엔드', '푸롴트'); // false +``` + +## Demo + +
+ + diff --git a/docs/src/pages/docs/api/chosungIncludes.ko.mdx b/docs/src/pages/docs/api/chosungIncludes.ko.mdx new file mode 100644 index 00000000..989fc5ca --- /dev/null +++ b/docs/src/pages/docs/api/chosungIncludes.ko.mdx @@ -0,0 +1,27 @@ +import { ChosungIncludesDemo } from '@/components/demo/chosung-includes-demo'; + +# chosungIncludes (deprecated, choseongIncludes를 사용해주세요) + +문자열의 초성 일치 검색을 수행합니다. + +```typescript +function chosungIncludes( + // 초성 일치하는지 검사할 문자열 (e.g. '프론트엔드') + x: string, + // 초성 문자열 (e.g. 'ㅍㄹㅌㅇㄷ') + y: string +): boolean; +``` + +```typescript +chosungIncludes('프론트엔드', 'ㅍㄹㅌ'); // true +chosungIncludes('00프론트엔드', 'ㅍㄹㅌ'); // true +chosungIncludes('프론트엔드', 'ㅍㅌ'); // false +chosungIncludes('프론트엔드', '푸롴트'); // false +``` + +## 사용해보기 + +
+ + diff --git a/src/index.ts b/src/index.ts index efef6d3a..5e839a05 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,3 @@ -<<<<<<< HEAD export { assembleHangul } from './assemble'; export { chosungIncludes } from './chosungIncludes'; export { combineHangulCharacter, combineVowels, curriedCombineHangulCharacter } from './combineHangulCharacter'; @@ -20,16 +19,3 @@ export { } from './utils'; export { extractHangul } from './extractHangul'; export { acronymizeHangul } from './acronymizeHangul'; -======= -export * from './assemble'; -export * from './choseongIncludes'; -export * from './chosungIncludes'; -export * from './combineHangulCharacter'; -export * from './convertQwertyToHangulAlphabet'; -export * from './disassemble'; -export * from './disassembleCompleteHangulCharacter'; -export * from './hangulIncludes'; -export * from './josa'; -export * from './removeLastHangulCharacter'; -export * from './utils'; ->>>>>>> bdeca9f (fix: 일관된 한글 표기법 적용) From b54423cfdb9ffacb433c2b97ef2d5ad98a701a38 Mon Sep 17 00:00:00 2001 From: Collection50 Date: Sat, 13 Jul 2024 00:16:53 +0900 Subject: [PATCH 11/13] =?UTF-8?q?fix:=20choseongIncludes=EC=9D=98=20?= =?UTF-8?q?=EC=9D=B8=EB=8D=B1=EC=8B=B1=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.ts b/src/index.ts index 5e839a05..0cb8f2e5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,6 @@ export { assembleHangul } from './assemble'; export { chosungIncludes } from './chosungIncludes'; +export { choseongIncludes } from './choseongIncludes'; export { combineHangulCharacter, combineVowels, curriedCombineHangulCharacter } from './combineHangulCharacter'; export { convertQwertyToHangul, convertQwertyToHangulAlphabet } from './convertQwertyToHangulAlphabet'; export { disassembleHangul, disassembleHangulToGroups } from './disassemble'; From 672e8e18fa5c52f2044ed0202a73c6da3857ae58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=B0=AC=ED=98=81?= Date: Sat, 13 Jul 2024 00:35:57 +0900 Subject: [PATCH 12/13] Create fifty-wolves-melt.md --- .changeset/fifty-wolves-melt.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/fifty-wolves-melt.md diff --git a/.changeset/fifty-wolves-melt.md b/.changeset/fifty-wolves-melt.md new file mode 100644 index 00000000..ae08c362 --- /dev/null +++ b/.changeset/fifty-wolves-melt.md @@ -0,0 +1,5 @@ +--- +"es-hangul": patch +--- + +fix: chosung => choseong으로 변환하는 규칙을 적용합니다 From 44db24e8ac77886d3f5859c2bf4b71fdbc4ba1e9 Mon Sep 17 00:00:00 2001 From: Collection50 Date: Sat, 13 Jul 2024 00:46:10 +0900 Subject: [PATCH 13/13] =?UTF-8?q?fix:=20import=20CI=20=EC=98=A4=EB=A5=98?= =?UTF-8?q?=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/_internal/hangul.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/_internal/hangul.ts b/src/_internal/hangul.ts index b109d62d..882af421 100644 --- a/src/_internal/hangul.ts +++ b/src/_internal/hangul.ts @@ -132,17 +132,18 @@ export function binaryAssembleHangulCharacters(source: string, nextCharacter: st return combineJungseong(`${lastJamo}${nextCharacter}`)(); } - if (canBeJungsung(`${secondaryLastJamo}${lastJamo}`) && canBeJongsung(nextCharacter)) { - return combineJungsung(`${secondaryLastJamo}${lastJamo}`)(nextCharacter); + if (canBeJungseong(`${secondaryLastJamo}${lastJamo}`) && canBeJongseong(nextCharacter)) { + return combineJungseong(`${secondaryLastJamo}${lastJamo}`)(nextCharacter); } - if (canBeJungsung(lastJamo) && canBeJongsung(nextCharacter)) { - return combineJungsung(lastJamo)(nextCharacter); + if (canBeJungseong(lastJamo) && canBeJongseong(nextCharacter)) { + return combineJungseong(lastJamo)(nextCharacter); } - const fixVowel = combineJungsung; - const combineJongsung = fixVowel( - canBeJungsung(`${restJamos[1]}${restJamos[2]}`) ? `${restJamos[1]}${restJamos[2]}` : restJamos[1] + const fixVowel = combineJungseong; + + const combineJongseong = fixVowel( + canBeJungseong(`${restJamos[1]}${restJamos[2]}`) ? `${restJamos[1]}${restJamos[2]}` : restJamos[1] ); const lastConsonant = lastJamo;