contact-book.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. class ContactBook {
  4. constructor(items) {
  5. this.items = items;
  6. }
  7. getPrimaryEmailAddress() {
  8. return this.getFromEmailAddresses()[0];
  9. }
  10. getPrimaryPhoneNumber() {
  11. return this.getFromPhoneNumbers()[0];
  12. }
  13. getFromPhoneNumbers() {
  14. const result = [];
  15. for (const item of this.items) {
  16. for (const address of item.canSendFromAddrs) {
  17. if (address.startsWith('phone:')) {
  18. result.push(address);
  19. }
  20. }
  21. }
  22. return result;
  23. }
  24. getFromEmailAddresses() {
  25. const result = [];
  26. for (const item of this.items) {
  27. for (const address of item.canSendFromAddrs) {
  28. if (address.startsWith('email:')) {
  29. result.push(address);
  30. }
  31. }
  32. }
  33. return result;
  34. }
  35. lookupByAddress(addressType, addressValue) {
  36. return this.items.find(item => item.matchesAddressExactly(addressType, addressValue));
  37. }
  38. lookupById(id) {
  39. return this.items.find(item => item.id === id);
  40. }
  41. search(search) {
  42. return this.items.filter(i => i.search(search));
  43. }
  44. }
  45. exports.ContactBook = ContactBook;
  46. //# sourceMappingURL=contact-book.js.map