/** * Fuse.js v6.0.0 - Lightweight fuzzy-search (http://fusejs.io) * * Copyright (c) 2020 Kiro Risk (http://kiro.me) * All Rights Reserved. Apache Software License 2.0 * * http://www.apache.org/licenses/LICENSE-2.0 */ var e,t;e=this,t=function(){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,r=new Array(t);n0&&void 0!==arguments[0]?arguments[0]:3,t=new Map;return{get:function(n){var r=n.match(w).length;if(t.has(r))return t.get(r);var i=parseFloat((1/Math.sqrt(r)).toFixed(e));return t.set(r,i),i},clear:function(){t.clear()}}}var C=function(){function e(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=n.getFn,i=void 0===r?_.getFn:r;t(this,e),this.norm=O(3),this.getFn=i,this.isCreated=!1,this.setRecords()}return r(e,[{key:"setCollection",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.docs=e}},{key:"setRecords",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.records=e}},{key:"setKeys",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.keys=e}},{key:"create",value:function(){var e=this;!this.isCreated&&this.docs.length&&(this.isCreated=!0,g(this.docs[0])?this.docs.forEach((function(t,n){e._addString(t,n)})):this.docs.forEach((function(t,n){e._addObject(t,n)})),this.norm.clear())}},{key:"add",value:function(e){var t=this.size();g(e)?this._addString(e,t):this._addObject(e,t)}},{key:"removeAt",value:function(e){this.records.splice(e,1);for(var t=e,n=this.size();t2&&void 0!==arguments[2]?arguments[2]:{},r=n.getFn,i=void 0===r?_.getFn:r,o=new C({getFn:i});return o.setKeys(e),o.setCollection(t),o.create(),o}function L(e,t){var n=e.matches;t.matches=[],m(n)&&n.forEach((function(e){if(m(e.indices)&&e.indices.length){var n={indices:e.indices,value:e.value};e.key&&(n.key=e.key),e.idx>-1&&(n.refIndex=e.idx),t.matches.push(n)}}))}function j(e,t){t.score=e.score}function E(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.errors,r=void 0===n?0:n,i=t.currentLocation,o=void 0===i?0:i,c=t.expectedLocation,s=void 0===c?0:c,a=t.distance,u=void 0===a?_.distance:a,h=r/e.length,f=Math.abs(s-o);return u?h+f/u:f?1:h}function I(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:_.minMatchCharLength,n=[],r=-1,i=-1,o=0,c=e.length;o=t&&n.push([r,i]),r=-1)}return e[o-1]&&o-r>=t&&n.push([r,o-1]),n}function $(e){for(var t={},n=e.length,r=0;r1&&void 0!==arguments[1]?arguments[1]:{},i=r.location,o=void 0===i?_.location:i,c=r.threshold,s=void 0===c?_.threshold:c,a=r.distance,u=void 0===a?_.distance:a,h=r.includeMatches,f=void 0===h?_.includeMatches:h,l=r.findAllMatches,d=void 0===l?_.findAllMatches:l,v=r.minMatchCharLength,y=void 0===v?_.minMatchCharLength:v,g=r.isCaseSensitive,p=void 0===g?_.isCaseSensitive:g;t(this,e),this.options={location:o,threshold:s,distance:u,includeMatches:f,findAllMatches:d,minMatchCharLength:y,isCaseSensitive:p},this.pattern=p?n:n.toLowerCase(),this.chunks=[];for(var m=0;m3&&void 0!==arguments[3]?arguments[3]:{},i=r.location,o=void 0===i?_.location:i,c=r.distance,s=void 0===c?_.distance:c,a=r.threshold,u=void 0===a?_.threshold:a,h=r.findAllMatches,f=void 0===h?_.findAllMatches:h,l=r.minMatchCharLength,d=void 0===l?_.minMatchCharLength:l,v=r.includeMatches,y=void 0===v?_.includeMatches:v;if(t.length>32)throw new Error(b(32));var g,p=t.length,m=e.length,k=Math.max(0,Math.min(o,m)),M=u,x=k,S=[];if(y)for(var w=0;w-1;){var O=E(t,{currentLocation:g,expectedLocation:k,distance:s});if(M=Math.min(O,M),x=g+p,y)for(var C=0;C=D;W-=1){var J=W-1,K=n[e.charAt(J)];if(K&&y&&(S[J]=1),q[W]=(q[W+1]<<1|1)&K,0!==R&&(q[W]|=(A[W+1]|A[W])<<1|1|A[W+1]),q[W]&$&&(L=E(t,{errors:R,currentLocation:J,expectedLocation:k,distance:s}))<=M){if(M=L,(x=J)<=k)break;D=Math.max(1,2*k-x)}}var T=E(t,{errors:R+1,currentLocation:k,expectedLocation:k,distance:s});if(T>M)break;A=q}var U={isMatch:x>=0,score:Math.max(.001,L)};return y&&(U.indices=I(S,d)),U}(e,i,o,{location:c+32*n,distance:s,threshold:a,findAllMatches:u,minMatchCharLength:h,includeMatches:r}),g=y.isMatch,p=y.score,m=y.indices;g&&(v=!0),l+=p,g&&m&&(f=[].concat(d(f),d(m)))}));var y={isMatch:v,score:v?l/this.chunks.length:1};return v&&r&&(y.indices=f),y}}]),e}(),P=function(){function e(n){t(this,e),this.pattern=n}return r(e,[{key:"search",value:function(){}}],[{key:"isMultiMatch",value:function(e){return F(e,this.multiRegex)}},{key:"isSingleMatch",value:function(e){return F(e,this.singleRegex)}}]),e}();function F(e,t){var n=e.match(t);return n?n[1]:null}var N=function(e){s(i,e);var n=l(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){for(var t,n=0,r=[],i=this.pattern.length;(t=e.indexOf(this.pattern,n))>-1;)n=t+i,r.push([t,n-1]);var o=!!r.length;return{isMatch:o,score:o?1:0,indices:r}}}],[{key:"type",get:function(){return"exact"}},{key:"multiRegex",get:function(){return/^'"(.*)"$/}},{key:"singleRegex",get:function(){return/^'(.*)$/}}]),i}(P),D=function(e){s(i,e);var n=l(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){var t=-1===e.indexOf(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}}],[{key:"type",get:function(){return"inverse-exact"}},{key:"multiRegex",get:function(){return/^!"(.*)"$/}},{key:"singleRegex",get:function(){return/^!(.*)$/}}]),i}(P),z=function(e){s(i,e);var n=l(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){var t=e.startsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,this.pattern.length-1]}}}],[{key:"type",get:function(){return"prefix-exact"}},{key:"multiRegex",get:function(){return/^\^"(.*)"$/}},{key:"singleRegex",get:function(){return/^\^(.*)$/}}]),i}(P),q=function(e){s(i,e);var n=l(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){var t=!e.startsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}}],[{key:"type",get:function(){return"inverse-prefix-exact"}},{key:"multiRegex",get:function(){return/^!\^"(.*)"$/}},{key:"singleRegex",get:function(){return/^!\^(.*)$/}}]),i}(P),W=function(e){s(i,e);var n=l(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){var t=e.endsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[e.length-this.pattern.length,e.length-1]}}}],[{key:"type",get:function(){return"suffix-exact"}},{key:"multiRegex",get:function(){return/^"(.*)"\$$/}},{key:"singleRegex",get:function(){return/^(.*)\$$/}}]),i}(P),J=function(e){s(i,e);var n=l(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){var t=!e.endsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}}],[{key:"type",get:function(){return"inverse-suffix-exact"}},{key:"multiRegex",get:function(){return/^!"(.*)"\$$/}},{key:"singleRegex",get:function(){return/^!(.*)\$$/}}]),i}(P),K=function(e){s(i,e);var n=l(i);function i(e){var r,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},c=o.location,s=void 0===c?_.location:c,a=o.threshold,u=void 0===a?_.threshold:a,h=o.distance,f=void 0===h?_.distance:h,l=o.includeMatches,d=void 0===l?_.includeMatches:l,v=o.findAllMatches,y=void 0===v?_.findAllMatches:v,g=o.minMatchCharLength,p=void 0===g?_.minMatchCharLength:g,m=o.isCaseSensitive,k=void 0===m?_.isCaseSensitive:m;return t(this,i),(r=n.call(this,e))._bitapSearch=new R(e,{location:s,threshold:u,distance:f,includeMatches:d,findAllMatches:y,minMatchCharLength:p,isCaseSensitive:k}),r}return r(i,[{key:"search",value:function(e){return this._bitapSearch.searchIn(e)}}],[{key:"type",get:function(){return"fuzzy"}},{key:"multiRegex",get:function(){return/^"(.*)"$/}},{key:"singleRegex",get:function(){return/^(.*)$/}}]),i}(P),T=[N,z,q,J,W,D,K],U=T.length,B=/ +(?=([^\"]*\"[^\"]*\")*[^\"]*$)/;function G(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return e.split("|").map((function(e){for(var n=e.trim().split(B).filter((function(e){return e&&!!e.trim()})),r=[],i=0,o=n.length;i1&&void 0!==arguments[1]?arguments[1]:{},i=r.isCaseSensitive,o=void 0===i?_.isCaseSensitive:i,c=r.includeMatches,s=void 0===c?_.includeMatches:c,a=r.minMatchCharLength,u=void 0===a?_.minMatchCharLength:a,h=r.findAllMatches,f=void 0===h?_.findAllMatches:h,l=r.location,d=void 0===l?_.location:l,v=r.threshold,y=void 0===v?_.threshold:v,g=r.distance,p=void 0===g?_.distance:g;t(this,e),this.query=null,this.options={isCaseSensitive:o,includeMatches:s,minMatchCharLength:u,findAllMatches:f,location:d,threshold:y,distance:p},this.pattern=o?n:n.toLowerCase(),this.query=G(this.pattern,this.options)}return r(e,[{key:"searchIn",value:function(e){var t=this.query;if(!t)return{isMatch:!1,score:1};var n=this.options,r=n.includeMatches;e=n.isCaseSensitive?e:e.toLowerCase();for(var i=0,o=[],c=0,s=0,a=t.length;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;t(this,e),this.options=c({},_,{},r),this.options.useExtendedSearch,this._keyStore=new S(this.options.keys),this.setCollection(n,i)}return r(e,[{key:"setCollection",value:function(e,t){if(this._docs=e,t&&!(t instanceof C))throw new Error("Incorrect 'index' type");this._myIndex=t||A(this._keyStore.keys(),this._docs,{getFn:this.options.getFn})}},{key:"add",value:function(e){m(e)&&(this._docs.push(e),this._myIndex.add(e))}},{key:"removeAt",value:function(e){this._docs.splice(e,1),this._myIndex.removeAt(e)}},{key:"getIndex",value:function(){return this._myIndex}},{key:"search",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.limit,r=void 0===n?-1:n,i=this.options,o=i.includeMatches,c=i.includeScore,s=i.shouldSort,a=i.sortFn,u=g(e)?g(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return ie(u,this._keyStore),s&&u.sort(a),p(r)&&r>-1&&(u=u.slice(0,r)),oe(u,this._docs,{includeMatches:o,includeScore:c})}},{key:"_searchStringList",value:function(e){var t=X(e,this.options),n=this._myIndex.records,r=[];return n.forEach((function(e){var n=e.v,i=e.i,o=e.n;if(m(n)){var c=t.searchIn(n),s=c.isMatch,a=c.score,u=c.indices;s&&r.push({item:n,idx:i,matches:[{score:a,value:n,norm:o,indices:u}]})}})),r}},{key:"_searchLogical",value:function(e){var t=this,n=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n.auto,i=void 0===r||r,o=function e(n){var r=Object.keys(n);if(r.length>1&&!ee(n))return e(ne(n));var o=r[0];if(te(n)){var c=n[o];if(!g(c))throw new Error(M(o));var s={key:o,pattern:c};return i&&(s.searcher=X(c,t)),s}var a={children:[],operator:o};return r.forEach((function(t){var r=n[t];y(r)&&r.forEach((function(t){a.children.push(e(t))}))})),a};return ee(e)||(e=ne(e)),o(e)}(e,this.options),r=this._myIndex,i=r.keys,o=r.records,c={},s=[];return o.forEach((function(e){var r=e.$,o=e.i;m(r)&&function e(n,r,o){if(!n.children){var a=n.key,u=n.searcher,h=r[i.indexOf(a)];return t._findMatches({key:a,value:h,searcher:u})}for(var f=n.operator,l=[],v=0;v2&&void 0!==arguments[2]?arguments[2]:{},r=n.includeMatches,i=void 0===r?_.includeMatches:r,o=n.includeScore,c=void 0===o?_.includeScore:o,s=[];return i&&s.push(L),c&&s.push(j),e.map((function(e){var n=e.idx,r={item:t[n],refIndex:n};return s.length&&s.forEach((function(t){t(e,r)})),r}))}return re.version="6.0.0",re.createIndex=A,re.parseIndex=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.getFn,r=void 0===n?_.getFn:n,i=e.keys,o=e.records,c=new C({getFn:r});return c.setKeys(i),c.setRecords(o),c},re.config=_,function(){V.push.apply(V,arguments)}(Q),re},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).Fuse=t();