contact-book.js 1.7 KB

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