From ab185b182078aae0d31acf6397b544b078565ba6 Mon Sep 17 00:00:00 2001 From: Eduard Kuzmenko Date: Wed, 9 Feb 2022 19:31:19 +0400 Subject: [PATCH] Support country search by its abbreviation --- src/helpers/formatPhoneNumber.ts | 2 -- src/pages/pageSignIn.ts | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/helpers/formatPhoneNumber.ts b/src/helpers/formatPhoneNumber.ts index 62dee16d..79816a1f 100644 --- a/src/helpers/formatPhoneNumber.ts +++ b/src/helpers/formatPhoneNumber.ts @@ -31,8 +31,6 @@ export function formatPhoneNumber(originalStr: string): { if(!prefixes.size) { I18n.countriesList.forEach(country => { country.country_codes.forEach(code => { - const s = {country, code}; - if(code.prefixes) { code.prefixes.forEach(prefix => { setPrefix(country, code, prefix); diff --git a/src/pages/pageSignIn.ts b/src/pages/pageSignIn.ts index 79824198..a1916ec3 100644 --- a/src/pages/pageSignIn.ts +++ b/src/pages/pageSignIn.ts @@ -244,7 +244,20 @@ let onFirstMount = () => { let _value = countryInputField.value.toLowerCase(); let matches: HelpCountry[] = []; countries.forEach((c) => { - let good = !![c.name, c.default_name].filter(Boolean).find(str => str.toLowerCase().indexOf(_value) !== -1)/* === 0 */;//i.test(c.name); + const names = [ + c.name, + c.default_name, + c.iso2 + ]; + + names.filter(Boolean).forEach(name => { + const abbr = name.split(' ').filter(word => /\w/.test(word)).map(word => word[0]).join(''); + if(abbr.length > 1) { + names.push(abbr); + } + }); + + let good = !!names.filter(Boolean).find(str => str.toLowerCase().indexOf(_value) !== -1)/* === 0 */;//i.test(c.name); liMap.get(c.iso2).forEach(li => li.style.display = good ? '' : 'none'); if(good) matches.push(c);