|
@@ -48,6 +48,12 @@ class ContactAddress {
|
|
|
return undefined;
|
|
return undefined;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ static formatAddress(type, address) {
|
|
|
|
|
+ if (type === 'phone' && ContactAddress.isValidPhoneNumber(address)) {
|
|
|
|
|
+ return ContactAddress.formatPhoneNumber(address);
|
|
|
|
|
+ }
|
|
|
|
|
+ return address;
|
|
|
|
|
+ }
|
|
|
static formatPhoneNumber(phoneNumber) {
|
|
static formatPhoneNumber(phoneNumber) {
|
|
|
if (phoneNumber.startsWith('+1') && phoneNumber.length === 12) {
|
|
if (phoneNumber.startsWith('+1') && phoneNumber.length === 12) {
|
|
|
return '(' + phoneNumber.substring(2, 5) + ') ' + phoneNumber.substring(5, 8) + '-' + phoneNumber.substring(8, 12);
|
|
return '(' + phoneNumber.substring(2, 5) + ') ' + phoneNumber.substring(5, 8) + '-' + phoneNumber.substring(8, 12);
|
|
@@ -71,10 +77,7 @@ class ContactAddress {
|
|
|
return `${this.type}:${this.address}`;
|
|
return `${this.type}:${this.address}`;
|
|
|
}
|
|
}
|
|
|
formattedAddress() {
|
|
formattedAddress() {
|
|
|
- if (this.type === 'phone' && ContactAddress.isValidPhoneNumber(this.address)) {
|
|
|
|
|
- return ContactAddress.formatPhoneNumber(this.address);
|
|
|
|
|
- }
|
|
|
|
|
- return this.address;
|
|
|
|
|
|
|
+ return ContactAddress.formatAddress(this.type, this.address);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
exports.ContactAddress = ContactAddress;
|
|
exports.ContactAddress = ContactAddress;
|