user 6 anni fa
parent
commit
a967e1be71

+ 1 - 0
lib/contact-address.d.ts

@@ -4,6 +4,7 @@ export declare class ContactAddress {
     static isValidPhoneNumber(search: string): boolean;
     static isValidEmailAddress(search: string): boolean;
     static parseEmail(search: string): string | undefined;
+    static formatAddress(type: string, address: string): string;
     static formatPhoneNumber(phoneNumber: string): string;
     type: string;
     address: string;

+ 7 - 4
lib/contact-address.js

@@ -48,6 +48,12 @@ class ContactAddress {
             return undefined;
         }
     }
+    static formatAddress(type, address) {
+        if (type === 'phone' && ContactAddress.isValidPhoneNumber(address)) {
+            return ContactAddress.formatPhoneNumber(address);
+        }
+        return address;
+    }
     static formatPhoneNumber(phoneNumber) {
         if (phoneNumber.startsWith('+1') && phoneNumber.length === 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}`;
     }
     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;

File diff suppressed because it is too large
+ 1 - 1
lib/contact-address.js.map


+ 8 - 4
src/contact-address.ts

@@ -53,6 +53,13 @@ export class ContactAddress {
     }
   }
 
+  public static formatAddress(type: string, address: string) {
+    if (type === 'phone' && ContactAddress.isValidPhoneNumber(address)) {
+      return ContactAddress.formatPhoneNumber(address);
+    }
+    return address;
+  }
+
   public static formatPhoneNumber(phoneNumber: string): string {
     if (phoneNumber.startsWith('+1') && phoneNumber.length === 12) {
       return '(' + phoneNumber.substring(2, 5) + ') ' + phoneNumber.substring(5, 8) + '-' + phoneNumber.substring(8, 12);
@@ -84,9 +91,6 @@ export class ContactAddress {
   }
 
   public formattedAddress() {
-    if (this.type === 'phone' && ContactAddress.isValidPhoneNumber(this.address)) {
-      return ContactAddress.formatPhoneNumber(this.address);
-    }
-    return this.address;
+    return ContactAddress.formatAddress(this.type, this.address);
   }
 }