elasticlunr

trimmer

method
elasticlunr.trimmer()

Option name Type Description
token String

The token to pass through the filter

return String

elasticlunr.trimmer is a pipeline function for trimming non word
characters from the begining and end of tokens before they
enter the index.

This implementation may not work correctly for non latin
characters and should either be removed or adapted for use
with languages with non-latin characters.

elasticlunr.trimmer = function (token) {
  if (token === null || token === undefined) {
    throw new Error('token should not be undefined');
  }

  return token
    .replace(/^\W+/, '')
    .replace(/\W+$/, '');
};

elasticlunr.Pipeline.registerFunction(elasticlunr.trimmer, 'trimmer');