"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class ContactAddress { static fromPrefixedString(prefixed) { const components = prefixed.split(/:/); const type = components.shift(); if (type == null) { throw new Error('Invalid input: ' + prefixed); } const unprefixed = components.join(':'); return new ContactAddress(type, unprefixed); } static parsePhoneNumber(search) { const remains = search.replace(/[0-9 +()-]/g, ''); if (remains !== '') { return undefined; } const digits = search.replace(/[^0-9]/g, ''); if (digits.length > 16) { return undefined; } if (!search.startsWith('+') && digits.length === 10) { return '+1' + digits; } return '+' + digits; } static isValidPhoneNumber(search) { const remains = search.replace(/[0-9 +()-]/g, ''); if (remains !== '') { return false; } const digits = search.replace(/[^0-9]/g, ''); if (digits.length > 16 || digits.length < 3) { return false; } return true; } static isValidEmailAddress(search) { const ats = search.replace(/[^@]/g, ''); return ats.length === 1; } static parseEmail(search) { const ats = search.replace(/[^@]/g, ''); if (ats.length === 1) { return search.trim(); } else { 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); } return phoneNumber; } constructor(type, address) { this.type = type; this.address = address; } matches(search) { if (this.address.toLowerCase().trim().indexOf(search.toLowerCase().trim()) >= 0) { return true; } return false; } matchesExactly(addressType, addressValue) { return (this.type === addressType) && (this.address.toLowerCase().trim() === addressValue.toLowerCase().trim()); } toPrefixedString() { return `${this.type}:${this.address}`; } formattedAddress() { return ContactAddress.formatAddress(this.type, this.address); } } exports.ContactAddress = ContactAddress; //# sourceMappingURL=contact-address.js.map