@altiore/form
Advanced tools
Comparing version 4.2.14 to 4.2.15
@@ -102,43 +102,51 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
export var formatPhone = function formatPhoneNumber(phoneNumberString) { | ||
var match = phoneNumberString.match(/^(\+?38?\s?|\+?7?\s?)?(\s?\(?\d{3}\)?\s?|\s?\(?\d{2}|\s?\(?\d|\s?\(?)?(\d{3}|\d{2}|\d)?(\s?-?\s?\d{2}|\s?-?\s?\d|\s?-?\s?)?(\s?-?\s?\d{4}|\s?-?\s?\d{3}|\s?-?\s?\d{2}|\s?-?\s?\d|\s?-?\s?)?$/); | ||
if (match) { | ||
var res = ''; | ||
if (match[1]) { | ||
res += match[1][0] === '+' ? match[1] : "+" + match[1]; | ||
try { | ||
var match = phoneNumberString.match(/^(\+?38?\s?|\+?7?\s?)?(\s?\(?\d{3}\)?\s?|\s?\(?\d{2}|\s?\(?\d|\s?\(?)?(\d{3}|\d{2}|\d)?(\s?-?\s?\d{2}|\s?-?\s?\d|\s?-?\s?)?(\s?-?\s?\d{4}|\s?-?\s?\d{3}|\s?-?\s?\d{2}|\s?-?\s?\d|\s?-?\s?)?$/); | ||
if (match) { | ||
var res = ''; | ||
if (match[1]) { | ||
res += match[1][0] === '+' ? match[1] : "+" + match[1]; | ||
} | ||
else if (phoneNumberString.length) { | ||
res = getCountryCode() + res; | ||
} | ||
if (match[2]) { | ||
res = | ||
res.replace(/\s$/gi, '') + ' (' + match[2].replace(/^[\s(]/gi, ''); | ||
} | ||
if (match[3]) { | ||
res = res.replace(/\)?\s?$/gi, '') + ') ' + match[3]; | ||
} | ||
else if (match[4]) { | ||
res = res.replace(/\)?\s?$/gi, '') + ') '; | ||
} | ||
if (match[4]) { | ||
res = | ||
res.replace(/\s?-?\s?$/gi, '') + | ||
(digitStrArr.includes(match[4][0]) | ||
? ' - ' + match[4] | ||
: digitStrArr.includes(match[4][1]) || | ||
digitStrArr.includes(match[4][2]) | ||
? match[4].replace(/^\s?-?\s?/gi, ' - ') | ||
: match[4]); | ||
} | ||
if (match[5]) { | ||
res = | ||
res.replace(/\s?-?\s?$/gi, '') + | ||
(digitStrArr.includes(match[5][0]) | ||
? ' - ' + match[5] | ||
: digitStrArr.includes(match[5][1]) || | ||
digitStrArr.includes(match[5][2]) | ||
? match[5].replace(/^\s?-?\s?/gi, ' - ') | ||
: match[5]); | ||
} | ||
return res; | ||
} | ||
else if (phoneNumberString.length) { | ||
res = getCountryCode() + res; | ||
} | ||
if (match[2]) { | ||
res = res.replace(/\s$/gi, '') + ' (' + match[2].replace(/^[\s(]/gi, ''); | ||
} | ||
if (match[3]) { | ||
res = res.replace(/\)?\s?$/gi, '') + ') ' + match[3]; | ||
} | ||
else if (match[4]) { | ||
res = res.replace(/\)?\s?$/gi, '') + ') '; | ||
} | ||
if (match[4]) { | ||
res = | ||
res.replace(/\s?-?\s?$/gi, '') + | ||
(digitStrArr.includes(match[4][0]) | ||
? ' - ' + match[4] | ||
: digitStrArr.includes(match[4][1]) || | ||
digitStrArr.includes(match[4][2]) | ||
? match[4].replace(/^\s?-?\s?/gi, ' - ') | ||
: match[4]); | ||
} | ||
if (match[5]) { | ||
res = | ||
res.replace(/\s?-?\s?$/gi, '') + | ||
(digitStrArr.includes(match[5][0]) | ||
? ' - ' + match[5] | ||
: digitStrArr.includes(match[5][1]) || | ||
digitStrArr.includes(match[5][2]) | ||
? match[5].replace(/^\s?-?\s?/gi, ' - ') | ||
: match[5]); | ||
} | ||
return res; | ||
return formatPhone(phoneNumberString.replace(/[()\s\-+a-zа-я]/gi, '')); | ||
} | ||
return formatPhone(phoneNumberString.replace(/[()\s\-+a-zа-я]/gi, '')); | ||
catch (err) { | ||
console.error('Не удалось форматировать номер телефона'); | ||
console.error(err); | ||
} | ||
return phoneNumberString; | ||
}; | ||
@@ -145,0 +153,0 @@ export var formatValueByType = new Map([[FieldType.PHONE, formatPhone]]); |
{ | ||
"name": "@altiore/form", | ||
"version": "4.2.14", | ||
"version": "4.2.15", | ||
"description": "Form helper for building powerful forms", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
117951
1965