8 lines
7.2 KiB
JavaScript
8 lines
7.2 KiB
JavaScript
/**
|
|
* Minified by jsDelivr using UglifyJS v3.4.4.
|
|
* Original file: /npm/fuzzysort@1.1.4/fuzzysort.js
|
|
*
|
|
* Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
|
|
*/
|
|
!function(e,r){"function"==typeof define&&define.amd?define([],r):"object"==typeof module&&module.exports?module.exports=r():e.fuzzysort=r()}(this,function(){var P="undefined"!=typeof require&&"undefined"==typeof window,n=new Map,o=new Map,j=[];j.total=0;var m=[],T=[];function r(){n.clear(),o.clear(),m=[],T=[]}function N(e){for(var r=-9007199254740991,n=e.length-1;0<=n;--n){var o=e[n];if(null!==o){var t=o.score;r<t&&(r=t)}}return-9007199254740991===r?null:r}function S(e,r){var n=e[r];if(void 0!==n)return n;var o=r;Array.isArray(r)||(o=r.split("."));for(var t=o.length,i=-1;e&&++i<t;)e=e[o[i]];return e}function D(e){return"object"==typeof e}var t=function(){var i=[],a=0,e={};function r(){for(var e=0,r=i[e],n=1;n<a;){var o=n+1;e=n,o<a&&i[o].score<i[n].score&&(e=o),i[e-1>>1]=i[e],n=1+(e<<1)}for(var t=e-1>>1;0<e&&r.score<i[t].score;t=(e=t)-1>>1)i[e]=i[t];i[e]=r}return e.add=function(e){var r=a;i[a++]=e;for(var n=r-1>>1;0<r&&e.score<i[n].score;n=(r=n)-1>>1)i[r]=i[n];i[r]=e},e.poll=function(){if(0!==a){var e=i[0];return i[0]=i[--a],r(),e}},e.peek=function(e){if(0!==a)return i[0]},e.replaceTop=function(e){i[0]=e,r()},e},k=t();return function e(A){var L={single:function(e,r,n){return e?(D(e)||(e=L.getPreparedSearch(e)),r?(D(r)||(r=L.getPrepared(r)),((n&&void 0!==n.allowTypo?n.allowTypo:!A||void 0===A.allowTypo||A.allowTypo)?L.algorithm:L.algorithmNoTypo)(e,r,e[0])):null):null},go:function(e,r,n){if(!e)return j;var o=(e=L.prepareSearch(e))[0],t=n&&n.threshold||A&&A.threshold||-9007199254740991,i=n&&n.limit||A&&A.limit||9007199254740991,a=(n&&void 0!==n.allowTypo?n.allowTypo:!A||void 0===A.allowTypo||A.allowTypo)?L.algorithm:L.algorithmNoTypo,l=0,f=0,u=r.length;if(n&&n.keys)for(var s=n.scoreFn||N,p=n.keys,d=p.length,c=u-1;0<=c;--c){for(var g=r[c],v=new Array(d),h=d-1;0<=h;--h)(y=S(g,x=p[h]))?(D(y)||(y=L.getPrepared(y)),v[h]=a(e,y,o)):v[h]=null;v.obj=g;var w=s(v);null!==w&&(w<t||(v.score=w,l<i?(k.add(v),++l):(++f,w>k.peek().score&&k.replaceTop(v))))}else if(n&&n.key){var x=n.key;for(c=u-1;0<=c;--c)(y=S(g=r[c],x))&&(D(y)||(y=L.getPrepared(y)),null!==(m=a(e,y,o))&&(m.score<t||(m={target:m.target,_targetLowerCodes:null,_nextBeginningIndexes:null,score:m.score,indexes:m.indexes,obj:g},l<i?(k.add(m),++l):(++f,m.score>k.peek().score&&k.replaceTop(m)))))}else for(c=u-1;0<=c;--c){var y,m;(y=r[c])&&(D(y)||(y=L.getPrepared(y)),null!==(m=a(e,y,o))&&(m.score<t||(l<i?(k.add(m),++l):(++f,m.score>k.peek().score&&k.replaceTop(m)))))}if(0===l)return j;var T=new Array(l);for(c=l-1;0<=c;--c)T[c]=k.poll();return T.total=l+f,T},goAsync:function(I,B,_){var C=!1,e=new Promise(function(c,g){if(!I)return c(j);var v=(I=L.prepareSearch(I))[0],h=t(),w=B.length-1,x=_&&_.threshold||A&&A.threshold||-9007199254740991,y=_&&_.limit||A&&A.limit||9007199254740991,m=(_&&void 0!==_.allowTypo?_.allowTypo:!A||void 0===A.allowTypo||A.allowTypo)?L.algorithm:L.algorithmNoTypo,T=0,k=0;function b(){if(C)return g("canceled");var e=Date.now();if(_&&_.keys)for(var r=_.scoreFn||N,n=_.keys,o=n.length;0<=w;--w){for(var t=B[w],i=new Array(o),a=o-1;0<=a;--a)(u=S(t,f=n[a]))?(D(u)||(u=L.getPrepared(u)),i[a]=m(I,u,v)):i[a]=null;i.obj=t;var l=r(i);if(null!==l&&!(l<x)&&(i.score=l,T<y?(h.add(i),++T):(++k,l>h.peek().score&&h.replaceTop(i)),w%1e3==0&&10<=Date.now()-e))return void(P?setImmediate(b):setTimeout(b))}else if(_&&_.key){for(var f=_.key;0<=w;--w)if((u=S(t=B[w],f))&&(D(u)||(u=L.getPrepared(u)),null!==(s=m(I,u,v))&&!(s.score<x)&&(s={target:s.target,_targetLowerCodes:null,_nextBeginningIndexes:null,score:s.score,indexes:s.indexes,obj:t},T<y?(h.add(s),++T):(++k,s.score>h.peek().score&&h.replaceTop(s)),w%1e3==0&&10<=Date.now()-e)))return void(P?setImmediate(b):setTimeout(b))}else for(;0<=w;--w){var u,s;if((u=B[w])&&(D(u)||(u=L.getPrepared(u)),null!==(s=m(I,u,v))&&!(s.score<x)&&(T<y?(h.add(s),++T):(++k,s.score>h.peek().score&&h.replaceTop(s)),w%1e3==0&&10<=Date.now()-e)))return void(P?setImmediate(b):setTimeout(b))}if(0===T)return c(j);for(var p=new Array(T),d=T-1;0<=d;--d)p[d]=h.poll();p.total=T+k,c(p)}P?setImmediate(b):b()});return e.cancel=function(){C=!0},e},highlight:function(e,r,n){if(null===e)return null;void 0===r&&(r="<b>"),void 0===n&&(n="</b>");for(var o="",t=0,i=!1,a=e.target,l=a.length,f=e.indexes,u=0;u<l;++u){var s=a[u];if(f[t]===u){if(i||(i=!0,o+=r),++t===f.length){o+=s+n+a.substr(u+1);break}}else i&&(i=!1,o+=n);o+=s}return o},prepare:function(e){if(e)return{target:e,_targetLowerCodes:L.prepareLowerCodes(e),_nextBeginningIndexes:null,score:null,indexes:null,obj:null}},prepareSlow:function(e){if(e)return{target:e,_targetLowerCodes:L.prepareLowerCodes(e),_nextBeginningIndexes:L.prepareNextBeginningIndexes(e),score:null,indexes:null,obj:null}},prepareSearch:function(e){if(e)return L.prepareLowerCodes(e)},getPrepared:function(e){if(999<e.length)return L.prepare(e);var r=n.get(e);return void 0!==r||(r=L.prepare(e),n.set(e,r)),r},getPreparedSearch:function(e){if(999<e.length)return L.prepareSearch(e);var r=o.get(e);return void 0!==r||(r=L.prepareSearch(e),o.set(e,r)),r},algorithm:function(e,r,n){for(var o=r._targetLowerCodes,t=e.length,i=o.length,a=0,l=0,f=0,u=0;;){if(n===o[l]){if(m[u++]=l,++a===t)break;n=e[0===f?a:f===a?a+1:f===a-1?a-1:a]}if(i<=++l)for(;;){if(a<=1)return null;if(0===f){if(n===e[--a])continue;f=a}else{if(1===f)return null;if((n=e[1+(a=--f)])===e[a])continue}l=m[(u=a)-1]+1;break}}var s=a=0,p=!1,d=0,c=r._nextBeginningIndexes;null===c&&(c=r._nextBeginningIndexes=L.prepareNextBeginningIndexes(r.target));var g=l=0===m[0]?0:c[m[0]-1];if(l!==i)for(;;)if(i<=l){if(a<=0){if(t-2<++s)break;if(e[s]===e[s+1])continue;l=g;continue}--a,l=c[T[--d]]}else if(e[0===s?a:s===a?a+1:s===a-1?a-1:a]===o[l]){if(T[d++]=l,++a===t){p=!0;break}++l}else l=c[l];if(p)var v=T,h=d;else v=m,h=u;for(var w=0,x=-1,y=0;y<t;++y)x!==(l=v[y])-1&&(w-=l),x=l;for(p?0!==s&&(w+=-20):(w*=1e3,0!==f&&(w+=-20)),w-=i-t,r.score=w,r.indexes=new Array(h),y=h-1;0<=y;--y)r.indexes[y]=v[y];return r},algorithmNoTypo:function(e,r,n){for(var o=r._targetLowerCodes,t=e.length,i=o.length,a=0,l=0,f=0;;){if(n===o[l]){if(m[f++]=l,++a===t)break;n=e[a]}if(i<=++l)return null}var u=!1,s=a=0,p=r._nextBeginningIndexes;if(null===p&&(p=r._nextBeginningIndexes=L.prepareNextBeginningIndexes(r.target)),(l=0===m[0]?0:p[m[0]-1])!==i)for(;;)if(i<=l){if(a<=0)break;--a,l=p[T[--s]]}else if(e[a]===o[l]){if(T[s++]=l,++a===t){u=!0;break}++l}else l=p[l];if(u)var d=T,c=s;else d=m,c=f;for(var g=0,v=-1,h=0;h<t;++h)v!==(l=d[h])-1&&(g-=l),v=l;for(u||(g*=1e3),g-=i-t,r.score=g,r.indexes=new Array(c),h=c-1;0<=h;--h)r.indexes[h]=d[h];return r},prepareLowerCodes:function(e){for(var r=e.length,n=[],o=e.toLowerCase(),t=0;t<r;++t)n[t]=o.charCodeAt(t);return n},prepareBeginningIndexes:function(e){for(var r=e.length,n=[],o=0,t=!1,i=!1,a=0;a<r;++a){var l=e.charCodeAt(a),f=65<=l&&l<=90,u=f||97<=l&&l<=122||48<=l&&l<=57,s=f&&!t||!i||!u;t=f,i=u,s&&(n[o++]=a)}return n},prepareNextBeginningIndexes:function(e){for(var r=e.length,n=L.prepareBeginningIndexes(e),o=[],t=n[0],i=0,a=0;a<r;++a)a<t?o[a]=t:(t=n[++i],o[a]=void 0===t?r:t);return o},cleanup:r,new:e};return L}()});
|
|
//# sourceMappingURL=/sm/57e217d47ad2be09f5ef2bc70608da208649aef7bbc194f7ee23c51727f8955a.map
|