From 777f83b2b5dacc00828521298c160663de4d8c82 Mon Sep 17 00:00:00 2001 From: Ida Marie Andreassen Date: Fri, 8 Nov 2024 14:14:11 +0100 Subject: [PATCH] Refactor function --- src/components/utils/formatPhoneNumber.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/utils/formatPhoneNumber.ts b/src/components/utils/formatPhoneNumber.ts index 4f6676519..fc1108a29 100644 --- a/src/components/utils/formatPhoneNumber.ts +++ b/src/components/utils/formatPhoneNumber.ts @@ -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; }