Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: 문자열에서 한글만 반환하는 extractHangul을 구현합니다. #130

Merged
merged 9 commits into from
Jun 29, 2024

Conversation

Collection50
Copy link
Contributor

@Collection50 Collection50 commented Jun 23, 2024

Overview

문자열에서 한글만 반환하는 extractHangul 을 구현합니다. #108

extractHangul('안녕하세요1234abc'); // '안녕하세요'
extractHangul('abcde'); // ''
extractHangul('안녕하세요ㄱㄴ'); // '안녕하세요ㄱㄴ'
extractHangul('안녕하세요    만나서 반갑습니다'); // '안녕하세요    만나서 반갑습니다'
extractHangul('가나다!-29~라마바.,,사'); // '가나다라마바사'

고민점

  • \s 정규표현식을 통해 \n과 같은 escape 문자열은 한글로 인식되어 처리하고 있습니다.
  • escape 문자열도 필터링할 지에 대해 고민 후, 한글과 혼용되어 사용될 것이라 생각하고 필터링하지 않았습니다.
  • 이부분에 대해 의견주시면 감사하겠습니다 !

PR Checklist

  • I read and included theses actions below
  1. I have read the Contributing Guide
  2. I have written documents and tests, if needed.

Copy link

changeset-bot bot commented Jun 23, 2024

🦋 Changeset detected

Latest commit: f8ef0b9

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Jun 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
es-hangul ❌ Failed (Inspect) Jun 29, 2024 2:17pm

@codecov-commenter
Copy link

codecov-commenter commented Jun 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.80%. Comparing base (b25fcc5) to head (1d3df38).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #130   +/-   ##
=======================================
  Coverage   98.79%   98.80%           
=======================================
  Files          15       16    +1     
  Lines         249      251    +2     
  Branches       55       55           
=======================================
+ Hits          246      248    +2     
  Misses          3        3           

* parseHangul('가나다!-29~라마바.,,사') // '가나다라마바사'
*/

export function parseHangul(str: string): string {
Copy link
Member

@manudeli manudeli Jun 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@okinawaa #121 이름짓기 이슈가 해결되고 승인되면 좋겠습니다
@Collection50 같이 이슈 봐주시면 좋겠어요

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@manudeli #121 이슈에 의견이 필요하다는 말씀일까요??

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네 맞아요 ~Hangul을 사용할 것인지 말것인지에 대한 의견이 필요해요

@crucifyer
Copy link
Contributor

이 함수 명칭은 removeUnHangul 같은 지운다는 뜻을 포함했으면 좋겠습니다.

정규식에서 + 는 큰 단위의 반복을 줄여 성능을 높이는 효과가 있습니다.
bench: https://jsfiddle.net/crucify/g74b5d1h/

ps. 저 식대로면 ㅠㅠ 같은 문자도 지워지는데 함수의 역할이 무엇인가요?

@okinawaa
Copy link
Member

이 함수 명칭은 removeUnHangul 같은 지운다는 뜻을 포함했으면 좋겠습니다.

이 부분에 동의하여, 한글을 지운다는 맥락을 설명할 수 있는 함수명, 혹은 주석에 "한글을 추출" 한다고 작성해주신것을 따라 extractHangul 정도는 어떨까요? 현재 parseHangul이 약간 함수의 동작을 정확히 설명하기에 모호하다고 생각이 들어서요. !

@okinawaa
Copy link
Member

escape 문자열도 필터링할 지에 대해 고민 후, 한글과 혼용되어 사용될 것이라 생각하고 필터링하지 않았습니다.

이 부분은 현재 구현대로 띄어쓰기는 삭제하지 않는 것이 좋을 것 같아요~ 라이브러리를 사용하는쪽에서 정말 띄어쓰기를 삭제하고 싶으면 사용하는 쪽에서 제어할 것 이라고 생각해요

@Collection50
Copy link
Contributor Author

@crucifyer 피드백 해주셔서 감사합니다 !

@Collection50
Copy link
Contributor Author

@okinawaa

이 부분에 동의하여, 한글을 지운다는 맥락을 설명할 수 있는 함수명, 혹은 주석에 "한글을 추출" 한다고 작성해주신것을 따라 extractHangul 정도는 어떨까요? 현재 parseHangul이 약간 함수의 동작을 정확히 설명하기에 모호하다고 생각이 들어서요. !

테스트 코드 보완과 함께 수정 완료 했습니다 !

@manudeli manudeli changed the title feat: 문자열에서 한글만 반환하는 parseHangul을 구현합니다. feat: 문자열에서 한글만 반환하는 extractHangul을 구현합니다. Jun 25, 2024
@@ -0,0 +1,51 @@
import { extractHangul } from './extractHangul';

describe('extractHangul 함수 테스트', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

일관성을 유지하기 위해서 , 함수 테스트 글자를 지우는것은 어떨까요?

Suggested change
describe('extractHangul 함수 테스트', () => {
describe('extractHangul', () => {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 !

Comment on lines 4 to 27
it('숫자와 알파벳 추출', () => {
expect(extractHangul('안녕하세요1234abc!@#')).toBe('안녕하세요');
});

it('한글이 없는 문자열', () => {
expect(extractHangul('1234abc')).toBe('');
});

it('한글과 공백만 남기고 다른 문자는 추출', () => {
expect(extractHangul('한글과 영어가 섞인 문장입니다. Hello!')).toBe('한글과 영어가 섞인 문장입니다 ');
});

it('특수문자 추출', () => {
expect(extractHangul('특수문자!@#가 들어간 경우')).toBe('특수문자가 들어간 경우');
});

it('숫자와 특수문자 추출', () => {
expect(extractHangul('숫자1234와 특수문자!@# 추출')).toBe('숫자와 특수문자 추출');
});

it('공백 유지', () => {
expect(extractHangul('공백도 유지됩니다 이렇게')).toBe('공백도 유지됩니다 이렇게');
});

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

추후 다른 PR에서 작업되도 좋겠습니다,
현재 it구문이 너무 병렬적으로 나와있으니 인지적으로 힘든 것 같아요.
비슷한 맥락인 것들은 describe 메서드를 사용해 한번 grouping해주면 좋을 것 같아요

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 추가적인 PR 만들겠습니다 !

Copy link
Member

@okinawaa okinawaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extractHangul에 대한 문서 작업도 진행해주시면 감사하겠습니다.
API가 실제로 추가되는것이기때문에 문서에서도 표현되었으면 좋겠어요!

import { extractHangul } from './extractHangul';

describe('extractHangul', () => {
it('숫자와 알파벳 추출', () => {
Copy link
Member

@okinawaa okinawaa Jun 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

숫자

Suggested change
it('숫자와 알파벳 추출', () => {
it('숫자와 알파벳과 특수문자를 제외한 한글 추출', () => {

Comment on lines 11 to 22

it('한글과 공백만 남기고 다른 문자는 추출', () => {
expect(extractHangul('한글과 영어가 섞인 문장입니다. Hello!')).toBe('한글과 영어가 섞인 문장입니다 ');
});

it('특수문자 추출', () => {
expect(extractHangul('특수문자!@#가 들어간 경우')).toBe('특수문자가 들어간 경우');
});

it('숫자와 특수문자 추출', () => {
expect(extractHangul('숫자1234와 특수문자!@# 추출')).toBe('숫자와 특수문자 추출');
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

한글을 추출하여, return값으로 주는것이기때문에
한글을 추출하고, 다른건 제외한다는 표현을 사용하면 좋을 것 같아요

@Collection50
Copy link
Contributor Author

@okinawaa
중복되는 테스트 코드를 삭제하여 가독성 향상했습니다 !
문서 작성 완료했습니다 !

* extractHangul('가나다!-29~라마바.,,사') // '가나다라마바사'
*/

export function extractHangul(str: string): string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

실제 사용할 수 있도록 src/index.ts에서 export 해주시면 좋을 것 같아요

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

완료했습니다 ! 감사합니다 !

Copy link
Member

@okinawaa okinawaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

긴 작업 감사합니다!

@okinawaa okinawaa merged commit acd6edb into toss:main Jun 29, 2024
2 of 10 checks passed
@github-actions github-actions bot mentioned this pull request Jun 29, 2024
seungrodotlee pushed a commit to seungrodotlee/es-hangul that referenced this pull request Jul 6, 2024
* feat: parseHangul

* fix: parseHangul의 이름을 extractHangul로 수정 및 테스트 코드 보완

* test: 일관된 테스트 코드 작성이 될 수 있도록 describe 설명 수정

* test: 테스트 코드 수정

* docs: extractHangul의 문서 작성

* test: 테스트 문구 수정

* fix: index.ts에 export 추가

* Create fresh-students-sit.md

---------

Co-authored-by: 박찬혁 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants