var Tokensearch=function(e,t){if(!e||0===e.length)throw new Error("Empty collection!");var o=this;if(this.collection=[],e.forEach(function(e){o.collection.push({item:e})}),t=t||{},this.delimiter=t.delimiter||Tokensearch.defaultOptions.delimiter,this.maxFilterTokenEntries=t.maxFilterTokenEntries||Tokensearch.defaultOptions.maxFilterTokenEntries,this.defaultThreshold=t.threshold||Tokensearch.defaultOptions.threshold,this.collectionKeys=t.collectionKeys||Tokensearch.defaultOptions.collectionKeys,0===this.collectionKeys.length)throw new Error("No collectionKeys defined!");this.collectionDataTokenSize=this.collectionKeys.length,this._prepareSearchTokens()};Tokensearch.defaultOptions={delimiter:/[\s-]+/,threshold:.7,maxFilterTokenEntries:5,collectionKeys:[]},Tokensearch.prototype._prepareSearchTokens=function(){var e=this;this.collection.forEach(function(t){var o=[];e.collectionKeys.forEach(function(i){t.item[i].trim().toLowerCase().split(e.delimiter).forEach(function(e){o=o.concat(e)})}),t.dataEntryTokens=o.filter(e._onlyUnique)})},Tokensearch.prototype._onlyUnique=function(e,t,o){return o.indexOf(e)===t},Tokensearch.prototype.search=function(e,t){for(var o=[],i=t||this.defaultThreshold,n=e.trim().split(this.delimiter).filter(this._onlyUnique),r=0,s=Math.min(n.length,this.maxFilterTokenEntries);s>r;r++)o.push(n[r].toLowerCase());var c=[],l=0;this.collection.forEach(function(e){var t=0,i=0;e.dataEntryTokens.forEach(function(e){for(var n=o.length,r=0;n>r;r++){var s=o[r];if(e.indexOf(s)>-1){i++,t+=e===s?2:1;break}}}),i&&(t+=i,t>l&&(l=t),c.push({item:e.item,score:t}))});var h=[],a=1/l;return c.forEach(function(e){e.score=1-e.score*a,e.score<=i&&h.push(e)}),h.sort(function(e,t){return e.score-t.score})},module.exports=Tokensearch;
!function(e){"use strict";var t=function(e,o){if(!e||0===e.length)throw new Error("Empty collection!");var i=this;if(this.collection=[],e.forEach(function(e){i.collection.push({item:e})}),o=o||{},this.delimiter=o.delimiter||t.defaultOptions.delimiter,this.maxFilterTokenEntries=o.maxFilterTokenEntries||t.defaultOptions.maxFilterTokenEntries,this.defaultThreshold=o.threshold||t.defaultOptions.threshold,this.collectionKeys=o.collectionKeys||t.defaultOptions.collectionKeys,0===this.collectionKeys.length)throw new Error("No collectionKeys defined!");this.collectionDataTokenSize=this.collectionKeys.length,this._prepareSearchTokens()};t.defaultOptions={delimiter:/[\s-]+/,threshold:.7,maxFilterTokenEntries:5,collectionKeys:[]},t.prototype._prepareSearchTokens=function(){var e=this;this.collection.forEach(function(t){var o=[];e.collectionKeys.forEach(function(i){t.item[i].trim().toLowerCase().split(e.delimiter).forEach(function(e){o=o.concat(e)})}),t.dataEntryTokens=o.filter(e._onlyUnique)})},t.prototype._onlyUnique=function(e,t,o){return o.indexOf(e)===t},t.prototype.search=function(e,t){for(var o=[],i=t||this.defaultThreshold,n=e.trim().split(this.delimiter).filter(this._onlyUnique),r=0,s=Math.min(n.length,this.maxFilterTokenEntries);s>r;r++)o.push(n[r].toLowerCase());var c=[],l=0;this.collection.forEach(function(e){var t=0,i=0;e.dataEntryTokens.forEach(function(e){for(var n=o.length,r=0;n>r;r++){var s=o[r];if(e.indexOf(s)>-1){i++,t+=e===s?2:1;break}}}),i&&(t+=i,t>l&&(l=t),c.push({item:e.item,score:t}))});var h=[],a=1/l;return c.forEach(function(e){e.score=1-e.score*a,e.score<=i&&h.push(e)}),h.sort(function(e,t){return e.score-t.score})},"object"==typeof exports?module.exports=t:"function"==typeof define&&define.amd?define(function(){return t}):e.Tokensearch=t}(this);
update minified lib version