utils.js 935 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*!
  2. * lunr.utils
  3. * Copyright (C) @YEAR Oliver Nightingale
  4. */
  5. /**
  6. * A namespace containing utils for the rest of the lunr library
  7. */
  8. lunr.utils = {}
  9. /**
  10. * Print a warning message to the console.
  11. *
  12. * @param {String} message The message to be printed.
  13. * @memberOf Utils
  14. */
  15. lunr.utils.warn = (function (global) {
  16. return function (message) {
  17. if (global.console && console.warn) {
  18. console.warn(message)
  19. }
  20. }
  21. })(this)
  22. /**
  23. * Convert an object to a string.
  24. *
  25. * In the case of `null` and `undefined` the function returns
  26. * the empty string, in all other cases the result of calling
  27. * `toString` on the passed object is returned.
  28. *
  29. * @param {Any} obj The object to convert to a string.
  30. * @return {String} string representation of the passed object.
  31. * @memberOf Utils
  32. */
  33. lunr.utils.asString = function (obj) {
  34. if (obj === void 0 || obj === null) {
  35. return ""
  36. } else {
  37. return obj.toString()
  38. }
  39. }