trimmer.js 743 B

123456789101112131415161718192021222324252627
  1. /*!
  2. * lunr.trimmer
  3. * Copyright (C) @YEAR Oliver Nightingale
  4. */
  5. /**
  6. * lunr.trimmer is a pipeline function for trimming non word
  7. * characters from the beginning and end of tokens before they
  8. * enter the index.
  9. *
  10. * This implementation may not work correctly for non latin
  11. * characters and should either be removed or adapted for use
  12. * with languages with non-latin characters.
  13. *
  14. * @static
  15. * @implements {lunr.PipelineFunction}
  16. * @param {lunr.Token} token The token to pass through the filter
  17. * @returns {lunr.Token}
  18. * @see lunr.Pipeline
  19. */
  20. lunr.trimmer = function (token) {
  21. return token.update(function (s) {
  22. return s.replace(/^\W+/, '').replace(/\W+$/, '')
  23. })
  24. }
  25. lunr.Pipeline.registerFunction(lunr.trimmer, 'trimmer')