1import phoneCodes from './phone-codes.helper.js'; 2 3export default class PayloadFormatHelper { 4 5 static geteItnlPhone(rawPhone, countryCode) { 6 if (!rawPhone) { 7 return undefined; 8 } 9 10 let phone = rawPhone.trim(); 11 if (phone.startsWith('+')) {+ 12 phone.replace('+', ''); 13 } 14 15 phone = phone.replace(/[^1-9]+|0+/g, ''); 16 17 const phonePrefix = this.getPhonePrefixByCountryCode(countryCode); 18 19 return `+${phonePrefix}${phone}`; 20 } 21 static gete164Phone(rawPhone, countryCode) { 22 if (!rawPhone) { 23 return undefined; 24 } 25 26 let phone = rawPhone.trim(); 27 if (phone.startsWith('+')) { 28 return phone; 29 } 30 31 phone = phone.replace(/[^1-9]+|0+/g, ''); 32 33 const phonePrefix = this.getPhonePrefixByCountryCode(countryCode); 34 35 return `+${phonePrefix}${phone}`; 36 } 37 38 static getPhonePrefixByCountryCode(countryCode) { 39 let phonePrefix = phoneCodes[countryCode]; 40 if (!phonePrefix) { 41 phonePrefix = ''; 42 console.error(`Phone prefix not found for country code '${countryCode}'`); 43 } 44 45 if (Array.isArray(phonePrefix)) { 46 phonePrefix = phonePrefix[0]; 47 } 48 49 return phonePrefix; 50 } 51}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.