lib.js 902 B

123456789101112131415161718192021222324252627282930
  1. /**
  2. * Is current user logged in ?
  3. *
  4. * @returns {boolean}
  5. * True if the user is logged in, false otherwise.
  6. */
  7. isLoggedIn = () => {
  8. return !!Meteor.userId();
  9. };
  10. /**
  11. * Convert a document to a string containing its unique words.
  12. *
  13. * @param {Object} doc
  14. * The source Website document. Extraction uses title and description only.
  15. * @returns {string}
  16. * A string made of the lower-case, orderd, deduplicated words in the document.
  17. */
  18. toWords = (doc) => {
  19. const NONWORD_REGEX = /[\W]/g;
  20. const aTitle = doc.title.split(NONWORD_REGEX);
  21. const aDescription = doc.description.split(NONWORD_REGEX);
  22. const aWords = aTitle.concat(aDescription);
  23. const aLCWords = aWords.map(function (s) { return s.toLocaleLowerCase(); });
  24. const aDWords = _.uniq(aLCWords);
  25. const aDSWords = aDWords.sort();
  26. const result = aDSWords.join(" ").trim();
  27. Meteor._debug(doc, result);
  28. return result;
  29. };