contact-book.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. if (item.me) {
  18. for (const address of item.addrs) {
  19. if (address.type === 'phone') {
  20. result.push(contact_address_1.ContactAddress.formatPhoneNumber(address.address));
  21. }
  22. }
  23. }
  24. }
  25. return result;
  26. }
  27. getFromEmailAddresses() {
  28. const result = [];
  29. for (const item of this.items) {
  30. if (item.me) {
  31. for (const address of item.addrs) {
  32. if (address.type === 'email') {
  33. result.push(address.address);
  34. }
  35. }
  36. }
  37. }
  38. return result;
  39. }
  40. getAllGroups() {
  41. return Object.keys(this.items.reduce((accum, contact) => {
  42. for (const group of contact.groups) {
  43. accum[group] = true;
  44. }
  45. return accum;
  46. }, {}));
  47. }
  48. lookupByAddress(addressType, addressValue) {
  49. return this.items.find(item => item.matchesAddressExactly(addressType, addressValue));
  50. }
  51. lookupById(id) {
  52. return this.items.find(item => item.id === id);
  53. }
  54. search(search) {
  55. return this.items.filter(i => i.search(search));
  56. }
  57. }
  58. exports.ContactBook = ContactBook;
  59. //# sourceMappingURL=contact-book.js.map