| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- "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 parseEmail(search) {
- const ats = search.replace(/[^@]/g, '');
- if (ats.length === 1) {
- return search.trim();
- }
- else {
- return undefined;
- }
- }
- 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}`;
- }
- }
- exports.ContactAddress = ContactAddress;
- //# sourceMappingURL=contact-address.js.map
|