-
Notifications
You must be signed in to change notification settings - Fork 0
feat: formatPhoneNumber util function #36
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
Conversation
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||
|
의견 부탁드려용~ |
| }, | ||
| ]; | ||
|
|
||
| export const formatPhoneNumber = (phoneNumber: string): string => { |
There was a problem hiding this comment.
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;
};There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
피드백 감사합니다..!!
find라는 키워드가 들어가면서 무엇을 하려는지 더 명확한 느낌도 있는 것 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 피드백 반영해주셔서 감사합니다 :-)
|
|
앗..! 바로 추가했습니다! |
Description
프론트엔드에서 흔히 사용되는 전화번호 자동 하이픈(-) 추가 기능을 구현한
formatPhoneNumber유틸리티 함수를 추가합니다.다양한 케이스에 대응할 수 있도록 함수를 구현하고, vitest를 이용한 테스트 코드를 작성하여 안정성을 높였습니다.
주요 변경 사항
formatPhoneNumber함수 신규 구현close #35