From 21e7215bebf5926dacd84f8e0585b05098e0ec13 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 13 Jul 2022 19:09:13 -0500 Subject: [PATCH] Remove legacy phone formatting code --- app/soapbox/utils/__tests__/phone.test.ts | 29 ----------------------- app/soapbox/utils/phone.ts | 29 ----------------------- 2 files changed, 58 deletions(-) delete mode 100644 app/soapbox/utils/__tests__/phone.test.ts diff --git a/app/soapbox/utils/__tests__/phone.test.ts b/app/soapbox/utils/__tests__/phone.test.ts deleted file mode 100644 index 2908601b86..0000000000 --- a/app/soapbox/utils/__tests__/phone.test.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { formatPhoneNumber } from '../phone'; - -describe('Phone unit tests', () => { - it('Properly formats', () => { - let number = ''; - expect(formatPhoneNumber('1', number)).toEqual(''); - - number = '5'; - expect(formatPhoneNumber('1', number)).toEqual('+1 (5'); - - number = '55'; - expect(formatPhoneNumber('1', number)).toEqual('+1 (55'); - - number = '555'; - expect(formatPhoneNumber('1', number)).toEqual('+1 (555'); - - number = '55513'; - expect(formatPhoneNumber('1', number)).toEqual('+1 (555) 13'); - - number = '555135'; - expect(formatPhoneNumber('1', number)).toEqual('+1 (555) 135'); - - number = '5551350'; - expect(formatPhoneNumber('1', number)).toEqual('+1 (555) 135-0'); - - number = '5551350123'; - expect(formatPhoneNumber('1', number)).toEqual('+1 (555) 135-0123'); - }); -}); diff --git a/app/soapbox/utils/phone.ts b/app/soapbox/utils/phone.ts index 39dfdbcd74..9cc175f5d5 100644 --- a/app/soapbox/utils/phone.ts +++ b/app/soapbox/utils/phone.ts @@ -10,37 +10,8 @@ type CountryCode = typeof COUNTRY_CODES[number]; /** Check whether a given value is a country code. */ const isCountryCode = (value: any): value is CountryCode => COUNTRY_CODES.includes(value); -function removeFormattingFromNumber(number = '') { - if (number) { - return number.toString().replace(/\D/g, ''); - } - - return number; -} - -function formatPhoneNumber(countryCode: CountryCode, phoneNumber = '') { - let formattedPhoneNumber = ''; - const strippedPhone = removeFormattingFromNumber(phoneNumber); - - for (let i = 0; i < strippedPhone.length && i < 10; i++) { - const character = strippedPhone.charAt(i); - if (i === 0) { - const prefix = `+${countryCode} (`; - formattedPhoneNumber += prefix + character; - } else if (i === 3) { - formattedPhoneNumber += `) ${character}`; - } else if (i === 6) { - formattedPhoneNumber += `-${character}`; - } else { - formattedPhoneNumber += character; - } - } - return formattedPhoneNumber; -} - export { COUNTRY_CODES, CountryCode, isCountryCode, - formatPhoneNumber, };