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: 숫자로 된 금액을 국립국어원 규칙의 한글 읽기로 변환합니다. #125

Merged
merged 7 commits into from
Jun 23, 2024

Conversation

crucifyer
Copy link
Contributor

Overview

숫자로 된 금액을 국립국어원 규칙의 한글 읽기로 변환합니다.

amountsToHangul('15,201,100'); // '일천오백이십만천백';
amountsToHangul('120,030원'); // '일십이만삼십' - 숫자 외 문자 무시
amountsToHangul('392.24'); // '삼백구십이' - 소수점 무시

PR Checklist

  • [v] 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 18, 2024

🦋 Changeset detected

Latest commit: a803e90

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 18, 2024

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

Name Status Preview Comments Updated (UTC)
es-hangul ❌ Failed (Inspect) Jun 23, 2024 1:57am

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.

너무 좋은 기능 추가해주셔서 감사해요 🙇

@@ -0,0 +1,24 @@
---
title: amountsToHangul
Copy link
Member

Choose a reason for hiding this comment

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

아래 이유에 따라서, amountToHangul 가 더 적합할 것 같은데, 함수 이름을 amountsToHangul라고 지으신 이유가 궁금해요!

amountToHangul: 단수 형태로, 하나의 특정 금액을 한국어 읽기로 변환하는 함수라는 의미를 전달합니다.
amountsToHangul: 복수 형태로, 여러 금액을 한국어 읽기로 변환하는 함수라는 의미를 전달합니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

고쳤습니다.

}
result.push(HANGUL_NUMBERS[parseInt(str[str.length - 1])]);
return result.join('');
}
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

고쳤습니다.

export function amountsToHangul(str: string) {
str = str.replace(/\..*$/, '') // 소수점 지원 안함
.replace(/[^\d]+/g, ''); // , 표기 등 오류내지 않음
if(str.length > 80) {
Copy link
Member

Choose a reason for hiding this comment

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

80이 magic number가 아닌, 상수로 선언해서 80이라는 숫자가 의미하는 역할에 대해서 표기해주는 것은 어떤가요?

str = str.replace(/\..*$/, '') // 소수점 지원 안함
.replace(/[^\d]+/g, ''); // , 표기 등 오류내지 않음
if(str.length > 80) {
return undefined;
Copy link
Member

Choose a reason for hiding this comment

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

80이상의 단어를 지원하지 않는다면, 이유를 함께 에러를 던져주는것은 어떤가요?
amountesToHangul에서 undefined를 반환한다면, 왜 undefined를 반환하는지 의문이 들 것 같아요.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

상수화 하고, throw new Error 로 했습니다.

expect(amountsToHangul('15,201,100')).toEqual('일천오백이십만천백');
expect(amountsToHangul('120,030원')).toEqual('일십이만삼십'); // 숫자 외 문자 무시
expect(amountsToHangul('392.24')).toEqual('삼백구십이'); // 소수점 무시
});
Copy link
Member

Choose a reason for hiding this comment

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

expect(amountsToHangul('100000000')).toEqual('일억'); 

위와 같은 경우, 일억 으로 기대하였는데 일억만 이라는 반환값이 와서 당황했어요.
일억만이 공식적으로 맞는 표현인지 궁금합니당!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

0 만 잔뜩 넣어보는 테스트를 안해봤네요;;; 수정했습니다.

export const HANGUL_CARDINAL = ['', '십', '백', '천'];

// https://ko.dict.naver.com/#/correct/korean/info?seq=602
// https://github.com/crucifyer/koreanCardinalOrdinal
Copy link
Member

Choose a reason for hiding this comment

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

이 주석이 하는 역할이 궁금해요!
현재 여기에 정의된 함수와 같은 역할을 하는것으로 보이는데, 유저에게 동일한 기능을하는데 많은 정보를 줄 필요가 있나 싶어서요!

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.

감사합니다!

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 95.83333% with 1 line in your changes missing coverage. Please review.

Please upload report for BASE (main@c9afca0). Learn more about missing BASE report.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #125   +/-   ##
=======================================
  Coverage        ?   99.56%           
=======================================
  Files           ?       14           
  Lines           ?      230           
  Branches        ?       51           
=======================================
  Hits            ?      229           
  Misses          ?        1           
  Partials        ?        0           

@okinawaa okinawaa merged commit a56e591 into toss:main Jun 23, 2024
9 of 10 checks passed
@github-actions github-actions bot mentioned this pull request Jun 23, 2024
@okinawaa
Copy link
Member

1.3.6 버전에서 반영되었어요. 정말 감사합니다!!

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

3 participants