UNPKG

elasticlunr

Version:

Lightweight full-text search engine in Javascript for browser search and offline search.

32 lines (28 loc) 847 B
/*! * elasticlunr.trimmer * Copyright (C) @YEAR Oliver Nightingale * Copyright (C) @YEAR Wei Song */ /** * 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. * * @module * @param {String} token The token to pass through the filter * @return {String} * @see elasticlunr.Pipeline */ 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');