From d671ce005595530961b170dc729d64ae8d49f670 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Tue, 31 Mar 2020 10:44:00 +1100 Subject: [PATCH] Remove phone number libraries --- .eslintignore | 1 - background.html | 2 - background_test.html | 2 - js/libphonenumber-util.js | 295 ------------------------------ js/views/phone-input-view.js | 39 ---- package.json | 2 - preload.js | 2 - test/index.html | 3 - test/libphonenumber_util_test.js | 26 --- ts/util/libphonenumberInstance.ts | 6 - yarn.lock | 10 - 11 files changed, 388 deletions(-) delete mode 100644 js/libphonenumber-util.js delete mode 100644 js/views/phone-input-view.js delete mode 100644 test/libphonenumber_util_test.js delete mode 100644 ts/util/libphonenumberInstance.ts diff --git a/.eslintignore b/.eslintignore index a1a37d7f5..9957d65d8 100644 --- a/.eslintignore +++ b/.eslintignore @@ -19,7 +19,6 @@ test/test.js # Third-party files js/Mp3LameEncoder.min.js js/WebAudioRecorderMp3.js -js/libphonenumber-util.js js/libsignal-protocol-worker.js libtextsecure/libsignal-protocol.js libtextsecure/test/blanket_mocha.js diff --git a/background.html b/background.html index 785d40ec2..c3994d233 100644 --- a/background.html +++ b/background.html @@ -454,7 +454,6 @@ - @@ -501,7 +500,6 @@ - diff --git a/background_test.html b/background_test.html index 39480ba67..8433a9af4 100644 --- a/background_test.html +++ b/background_test.html @@ -454,7 +454,6 @@ - @@ -501,7 +500,6 @@ - diff --git a/js/libphonenumber-util.js b/js/libphonenumber-util.js deleted file mode 100644 index ac13013c8..000000000 --- a/js/libphonenumber-util.js +++ /dev/null @@ -1,295 +0,0 @@ -(function() { - 'use strict'; - - /* - * This file extends the libphonenumber object with a set of phonenumbery - * utility functions. libphonenumber must be included before you call these - * functions, but the order of the files/script-tags doesn't matter. - */ - - window.libphonenumber = window.libphonenumber || {}; - window.libphonenumber.util = { - getRegionCodeForNumber: function(number) { - try { - var parsedNumber = libphonenumber.parse(number); - return libphonenumber.getRegionCodeForNumber(parsedNumber); - } catch (e) { - return 'ZZ'; - } - }, - - splitCountryCode: function(number) { - var parsedNumber = libphonenumber.parse(number); - return { - country_code: parsedNumber.values_[1], - national_number: parsedNumber.values_[2], - }; - }, - - getCountryCode: function(regionCode) { - var cc = libphonenumber.getCountryCodeForRegion(regionCode); - return cc !== 0 ? cc : ''; - }, - - parseNumber: function(number, defaultRegionCode) { - try { - var parsedNumber = libphonenumber.parse(number, defaultRegionCode); - - return { - isValidNumber: libphonenumber.isValidNumber(parsedNumber), - regionCode: libphonenumber.getRegionCodeForNumber(parsedNumber), - countryCode: '' + parsedNumber.getCountryCode(), - nationalNumber: '' + parsedNumber.getNationalNumber(), - e164: libphonenumber.format( - parsedNumber, - libphonenumber.PhoneNumberFormat.E164 - ), - }; - } catch (ex) { - return { error: ex, isValidNumber: false }; - } - }, - - getAllRegionCodes: function() { - return { - AD: 'Andorra', - AE: 'United Arab Emirates', - AF: 'Afghanistan', - AG: 'Antigua and Barbuda', - AI: 'Anguilla', - AL: 'Albania', - AM: 'Armenia', - AO: 'Angola', - AR: 'Argentina', - AS: 'AmericanSamoa', - AT: 'Austria', - AU: 'Australia', - AW: 'Aruba', - AX: 'Åland Islands', - AZ: 'Azerbaijan', - BA: 'Bosnia and Herzegovina', - BB: 'Barbados', - BD: 'Bangladesh', - BE: 'Belgium', - BF: 'Burkina Faso', - BG: 'Bulgaria', - BH: 'Bahrain', - BI: 'Burundi', - BJ: 'Benin', - BL: 'Saint Barthélemy', - BM: 'Bermuda', - BN: 'Brunei Darussalam', - BO: 'Bolivia, Plurinational State of', - BR: 'Brazil', - BS: 'Bahamas', - BT: 'Bhutan', - BW: 'Botswana', - BY: 'Belarus', - BZ: 'Belize', - CA: 'Canada', - CC: 'Cocos (Keeling) Islands', - CD: 'Congo, The Democratic Republic of the', - CF: 'Central African Republic', - CG: 'Congo', - CH: 'Switzerland', - CI: "Cote d'Ivoire", - CK: 'Cook Islands', - CL: 'Chile', - CM: 'Cameroon', - CN: 'China', - CO: 'Colombia', - CR: 'Costa Rica', - CU: 'Cuba', - CV: 'Cape Verde', - CX: 'Christmas Island', - CY: 'Cyprus', - CZ: 'Czech Republic', - DE: 'Germany', - DJ: 'Djibouti', - DK: 'Denmark', - DM: 'Dominica', - DO: 'Dominican Republic', - DZ: 'Algeria', - EC: 'Ecuador', - EE: 'Estonia', - EG: 'Egypt', - ER: 'Eritrea', - ES: 'Spain', - ET: 'Ethiopia', - FI: 'Finland', - FJ: 'Fiji', - FK: 'Falkland Islands (Malvinas)', - FM: 'Micronesia, Federated States of', - FO: 'Faroe Islands', - FR: 'France', - GA: 'Gabon', - GB: 'United Kingdom', - GD: 'Grenada', - GE: 'Georgia', - GF: 'French Guiana', - GG: 'Guernsey', - GH: 'Ghana', - GI: 'Gibraltar', - GL: 'Greenland', - GM: 'Gambia', - GN: 'Guinea', - GP: 'Guadeloupe', - GQ: 'Equatorial Guinea', - GR: 'Ελλάδα', - GT: 'Guatemala', - GU: 'Guam', - GW: 'Guinea-Bissau', - GY: 'Guyana', - HK: 'Hong Kong', - HN: 'Honduras', - HR: 'Croatia', - HT: 'Haiti', - HU: 'Magyarország', - ID: 'Indonesia', - IE: 'Ireland', - IL: 'Israel', - IM: 'Isle of Man', - IN: 'India', - IO: 'British Indian Ocean Territory', - IQ: 'Iraq', - IR: 'Iran, Islamic Republic of', - IS: 'Iceland', - IT: 'Italy', - JE: 'Jersey', - JM: 'Jamaica', - JO: 'Jordan', - JP: 'Japan', - KE: 'Kenya', - KG: 'Kyrgyzstan', - KH: 'Cambodia', - KI: 'Kiribati', - KM: 'Comoros', - KN: 'Saint Kitts and Nevis', - KP: "Korea, Democratic People's Republic of", - KR: 'Korea, Republic of', - KW: 'Kuwait', - KY: 'Cayman Islands', - KZ: 'Kazakhstan', - LA: "Lao People's Democratic Republic", - LB: 'Lebanon', - LC: 'Saint Lucia', - LI: 'Liechtenstein', - LK: 'Sri Lanka', - LR: 'Liberia', - LS: 'Lesotho', - LT: 'Lithuania', - LU: 'Luxembourg', - LV: 'Latvia', - LY: 'Libyan Arab Jamahiriya', - MA: 'Morocco', - MC: 'Monaco', - MD: 'Moldova, Republic of', - ME: 'Црна Гора', - MF: 'Saint Martin', - MG: 'Madagascar', - MH: 'Marshall Islands', - MK: 'Macedonia, The Former Yugoslav Republic of', - ML: 'Mali', - MM: 'Myanmar', - MN: 'Mongolia', - MO: 'Macao', - MP: 'Northern Mariana Islands', - MQ: 'Martinique', - MR: 'Mauritania', - MS: 'Montserrat', - MT: 'Malta', - MU: 'Mauritius', - MV: 'Maldives', - MW: 'Malawi', - MX: 'Mexico', - MY: 'Malaysia', - MZ: 'Mozambique', - NA: 'Namibia', - NC: 'New Caledonia', - NE: 'Niger', - NF: 'Norfolk Island', - NG: 'Nigeria', - NI: 'Nicaragua', - NL: 'Netherlands', - NO: 'Norway', - NP: 'Nepal', - NR: 'Nauru', - NU: 'Niue', - NZ: 'New Zealand', - OM: 'Oman', - PA: 'Panama', - PE: 'Peru', - PF: 'French Polynesia', - PG: 'Papua New Guinea', - PH: 'Philippines', - PK: 'Pakistan', - PL: 'Polska', - PM: 'Saint Pierre and Miquelon', - PR: 'Puerto Rico', - PS: 'Palestinian Territory, Occupied', - PT: 'Portugal', - PW: 'Palau', - PY: 'Paraguay', - QA: 'Qatar', - RE: 'Réunion', - RO: 'Romania', - RS: 'Србија', - RU: 'Russia', - RW: 'Rwanda', - SA: 'Saudi Arabia', - SB: 'Solomon Islands', - SC: 'Seychelles', - SD: 'Sudan', - SE: 'Sweden', - SG: 'Singapore', - SH: 'Saint Helena, Ascension and Tristan Da Cunha', - SI: 'Slovenia', - SJ: 'Svalbard and Jan Mayen', - SK: 'Slovakia', - SL: 'Sierra Leone', - SM: 'San Marino', - SN: 'Senegal', - SO: 'Somalia', - SR: 'Suriname', - ST: 'Sao Tome and Principe', - SV: 'El Salvador', - SY: 'Syrian Arab Republic', - SZ: 'Swaziland', - TC: 'Turks and Caicos Islands', - TD: 'Chad', - TG: 'Togo', - TH: 'Thailand', - TJ: 'Tajikistan', - TK: 'Tokelau', - TL: 'Timor-Leste', - TM: 'Turkmenistan', - TN: 'Tunisia', - TO: 'Tonga', - TR: 'Turkey', - TT: 'Trinidad and Tobago', - TV: 'Tuvalu', - TW: 'Taiwan, Province of China', - TZ: 'Tanzania, United Republic of', - UA: 'Ukraine', - UG: 'Uganda', - US: 'United States', - UY: 'Uruguay', - UZ: 'Uzbekistan', - VA: 'Holy See (Vatican City State)', - VC: 'Saint Vincent and the Grenadines', - VE: 'Venezuela', - VG: 'Virgin Islands, British', - VI: 'Virgin Islands, U.S.', - VN: 'Viet Nam', - VU: 'Vanuatu', - WF: 'Wallis and Futuna', - WS: 'Samoa', - YE: 'Yemen', - YT: 'Mayotte', - ZA: 'South Africa', - ZM: 'Zambia', - ZW: 'Zimbabwe', - }; - }, // getAllRegionCodes - }; // libphonenumber.util -})(); diff --git a/js/views/phone-input-view.js b/js/views/phone-input-view.js deleted file mode 100644 index e9537f901..000000000 --- a/js/views/phone-input-view.js +++ /dev/null @@ -1,39 +0,0 @@ -/* global libphonenumber, Whisper */ - -// eslint-disable-next-line func-names -(function() { - 'use strict'; - - window.Whisper = window.Whisper || {}; - - Whisper.PhoneInputView = Whisper.View.extend({ - tagName: 'div', - className: 'phone-input', - templateName: 'phone-number', - initialize() { - this.$('input.number').intlTelInput(); - }, - events: { - change: 'validateNumber', - keyup: 'validateNumber', - }, - validateNumber() { - const input = this.$('input.number'); - const regionCode = this.$('li.active') - .attr('data-country-code') - .toUpperCase(); - const number = input.val(); - - const parsedNumber = libphonenumber.util.parseNumber(number, regionCode); - if (parsedNumber.isValidNumber) { - this.$('.number-container').removeClass('invalid'); - this.$('.number-container').addClass('valid'); - } else { - this.$('.number-container').removeClass('valid'); - } - input.trigger('validation'); - - return parsedNumber.e164; - }, - }); -})(); diff --git a/package.json b/package.json index d22b1021b..a8ff16325 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,6 @@ "form-data": "^3.0.0", "fs-extra": "9.0.0", "glob": "7.1.2", - "google-libphonenumber": "3.2.2", "got": "8.2.0", "he": "1.2.0", "intl-tel-input": "12.1.15", @@ -132,7 +131,6 @@ "@types/electron-is-dev": "^1.1.1", "@types/filesize": "3.6.0", "@types/fs-extra": "5.0.5", - "@types/google-libphonenumber": "7.4.14", "@types/got": "9.4.1", "@types/jquery": "3.3.29", "@types/js-yaml": "3.12.0", diff --git a/preload.js b/preload.js index 08c73ed67..b6eae9581 100644 --- a/preload.js +++ b/preload.js @@ -337,8 +337,6 @@ window.dataURLToBlobSync = require('blueimp-canvas-to-blob'); window.emojiData = require('emoji-datasource'); window.EmojiPanel = require('emoji-panel'); window.filesize = require('filesize'); -window.libphonenumber = require('google-libphonenumber').PhoneNumberUtil.getInstance(); -window.libphonenumber.PhoneNumberFormat = require('google-libphonenumber').PhoneNumberFormat; window.loadImage = require('blueimp-load-image'); window.getGuid = require('uuid/v4'); window.profileImages = require('./app/profile_images'); diff --git a/test/index.html b/test/index.html index 13477e485..a779fba6d 100644 --- a/test/index.html +++ b/test/index.html @@ -500,7 +500,6 @@ - @@ -548,7 +547,6 @@ - @@ -576,7 +574,6 @@ - diff --git a/test/libphonenumber_util_test.js b/test/libphonenumber_util_test.js deleted file mode 100644 index 0e478e4eb..000000000 --- a/test/libphonenumber_util_test.js +++ /dev/null @@ -1,26 +0,0 @@ -/* global libphonenumber */ - -'use strict'; - -describe('libphonenumber util', () => { - describe('parseNumber', () => { - it('numbers with + are valid without providing regionCode', () => { - const result = libphonenumber.util.parseNumber('+14155555555'); - assert.isTrue(result.isValidNumber); - assert.strictEqual(result.nationalNumber, '4155555555'); - assert.strictEqual(result.e164, '+14155555555'); - assert.strictEqual(result.regionCode, 'US'); - assert.strictEqual(result.countryCode, '1'); - }); - it('variant numbers with the right regionCode are valid', () => { - ['4155555555', '14155555555', '+14155555555'].forEach(number => { - const result = libphonenumber.util.parseNumber(number, 'US'); - assert.isTrue(result.isValidNumber); - assert.strictEqual(result.nationalNumber, '4155555555'); - assert.strictEqual(result.e164, '+14155555555'); - assert.strictEqual(result.regionCode, 'US'); - assert.strictEqual(result.countryCode, '1'); - }); - }); - }); -}); diff --git a/ts/util/libphonenumberInstance.ts b/ts/util/libphonenumberInstance.ts deleted file mode 100644 index 40855ac23..000000000 --- a/ts/util/libphonenumberInstance.ts +++ /dev/null @@ -1,6 +0,0 @@ -import libphonenumber from 'google-libphonenumber'; - -const instance = libphonenumber.PhoneNumberUtil.getInstance(); -const PhoneNumberFormat = libphonenumber.PhoneNumberFormat; - -export { instance, PhoneNumberFormat }; diff --git a/yarn.lock b/yarn.lock index ff06052c3..37b1b7e69 100644 --- a/yarn.lock +++ b/yarn.lock @@ -247,11 +247,6 @@ "@types/minimatch" "*" "@types/node" "*" -"@types/google-libphonenumber@7.4.14": - version "7.4.14" - resolved "https://registry.yarnpkg.com/@types/google-libphonenumber/-/google-libphonenumber-7.4.14.tgz#3625d7aed0c16df920588428c86f0538bd0612ec" - integrity sha512-HGQobTn8CGn0/j7lezIHlGTE1czxQU6NeT7TYtC3OWcbyyUUSfdt4tXSTEGbXmNZlE+xczTDbyR8P6aYGPzG1A== - "@types/got@9.4.1": version "9.4.1" resolved "https://registry.yarnpkg.com/@types/got/-/got-9.4.1.tgz#7479a3a321599b5e17647f3bd9d402b8c55bfee1" @@ -4389,11 +4384,6 @@ glogg@^1.0.1: dependencies: sparkles "^1.0.0" -google-libphonenumber@3.2.2: - version "3.2.2" - resolved "https://registry.yarnpkg.com/google-libphonenumber/-/google-libphonenumber-3.2.2.tgz#3d9d7ba727e99a50812f21b0ed313723b76c5c54" - integrity sha512-ubjGeosYPeusjYbUHy76lCniGTTI0k1rIFc+uKBX+jHQLDmWOSUtlFUxaeoLJ+Y+PAMM6dWp+C1HjHx5BI8kEw== - got@8.2.0: version "8.2.0" resolved "https://registry.yarnpkg.com/got/-/got-8.2.0.tgz#0d11a071d05046348a2f5c0a5fa047fb687fdfc6"