Skip to content

Commit

Permalink
Refactor function
Browse files Browse the repository at this point in the history
  • Loading branch information
idamand committed Nov 8, 2024
1 parent 41fe82f commit 777f83b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/components/utils/formatPhoneNumber.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export default function formatPhoneNumber(phoneNumber: string) {
const firstDigitsOfPhoneNumber = phoneNumber?.slice(0, 3);
const firstDigitsOfPhoneNumber = phoneNumber.slice(0, 3);
let formattedPhoneNumber = ``;
if (firstDigitsOfPhoneNumber == "+47") {
formattedPhoneNumber = `+${phoneNumber?.slice(1, 3)} ${phoneNumber?.slice(3, 6)} ${phoneNumber?.slice(6, 8)} ${phoneNumber?.slice(8)}`;
formattedPhoneNumber = `+${phoneNumber.slice(1, 3)} ${phoneNumber.slice(3, 6)} ${phoneNumber.slice(6, 8)} ${phoneNumber.slice(8)}`;
} else if (firstDigitsOfPhoneNumber == "+46") {
formattedPhoneNumber = `+${phoneNumber?.slice(1, 3)} 0${phoneNumber?.slice(3, 5)}-${phoneNumber?.slice(5, 8)} ${phoneNumber?.slice(8, 10)} ${phoneNumber?.slice(10)}`;
formattedPhoneNumber = `+${phoneNumber.slice(1, 3)} 0${phoneNumber.slice(3, 5)}-${phoneNumber.slice(5, 8)} ${phoneNumber.slice(8, 10)} ${phoneNumber.slice(10)}`;
} else {
formattedPhoneNumber = phoneNumber ? phoneNumber : "";
formattedPhoneNumber = phoneNumber;
}
return formattedPhoneNumber;
}

0 comments on commit 777f83b

Please sign in to comment.