Skip to content

Conversation

@prgmr99
Copy link
Member

@prgmr99 prgmr99 commented Sep 9, 2025

Description

프론트엔드에서 흔히 사용되는 전화번호 자동 하이픈(-) 추가 기능을 구현한 formatPhoneNumber 유틸리티 함수를 추가합니다.

다양한 케이스에 대응할 수 있도록 함수를 구현하고, vitest를 이용한 테스트 코드를 작성하여 안정성을 높였습니다.

주요 변경 사항

  • formatPhoneNumber 함수 신규 구현
  • 휴대폰, 서울/기타 지역번호, 8자리 대표번호 등 한국의 주요 전화번호 형식을 자동으로 포맷팅합니다.

close #35

@prgmr99 prgmr99 requested a review from klmhyeonwoo September 9, 2025 07:31
@prgmr99 prgmr99 self-assigned this Sep 9, 2025
@prgmr99 prgmr99 added the enhancement New feature or request label Sep 9, 2025
@klmhyeonwoo
Copy link
Member

klmhyeonwoo commented Sep 9, 2025

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 74.77% 163 / 218
🔵 Statements 74.77% 163 / 218
🔵 Functions 94.73% 18 / 19
🔵 Branches 92.3% 72 / 78
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
package/formatUtil/formatPhoneNumber/index.ts 100% 100% 100% 100%
Generated in workflow #56 for commit 93b24f3 by the Vitest Coverage Report Action

@prgmr99
Copy link
Member Author

prgmr99 commented Sep 9, 2025

formatUtil에 추가하긴 했는데,,
stringUtil보다는 장기적으로 다른 함수들을 포함하는데, 적합할 것 같아서 분리해보았습니다..!!

의견 부탁드려용~

},
];

export const formatPhoneNumber = (phoneNumber: 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.

continue를 사용하지 않고 아래와 같이 find 메서드를 사용하는 방법도 있을 것 같아요!
이 함수.. 너무너무 유용하게 잘 쓸 것 같은데요.. 너무너무 고생하셨습니다 (:

export const formatPhoneNumber = (phoneNumber: string): string => {
  if (!phoneNumber) return "";

  const digitsOnly = phoneNumber.replace(/\D/g, "");

  const matched = formatRules.find(
    (r) => (!r.prefix || digitsOnly.startsWith(r.prefix)) && digitsOnly.length === r.length
  );

  return matched ? digitsOnly.replace(matched.format, matched.replacement) : digitsOnly;
};

Choose a reason for hiding this comment

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

피드백 감사합니다..!!
find라는 키워드가 들어가면서 무엇을 하려는지 더 명확한 느낌도 있는 것 같아요!

Copy link
Member

Choose a reason for hiding this comment

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

오 피드백 반영해주셔서 감사합니다 :-)

@klmhyeonwoo
Copy link
Member

formatUtil 너무 좋은데! 해당 폴더의 루트 index.ts가 비어져있는거같은데 구성해주실 수 있으신가요?!

@prgmr99
Copy link
Member Author

prgmr99 commented Sep 10, 2025

formatUtil 너무 좋은데! 해당 폴더의 루트 index.ts가 비어져있는거같은데 구성해주실 수 있으신가요?!

앗..! 바로 추가했습니다!

@prgmr99 prgmr99 merged commit 721d3ae into main Sep 10, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

formatUtil > formatPhoneNumber

4 participants