├── .editorconfig ├── .gitignore ├── LICENSE ├── README.md ├── bench.png ├── demos ├── clippy.png ├── compare.html ├── inverted-index.html ├── lib │ ├── FuzzySearch.js │ ├── FuzzySearch2.min.js │ ├── elasticlunr.min.js │ ├── fast-fuzzy.iife.min.js │ ├── flexsearch.light.js │ ├── fuse.min.js │ ├── fuzzball.umd.min.js │ ├── fuzzbunny.iife.js │ ├── fuzzy-min.js │ ├── fuzzy-tools.iife.js │ ├── fuzzyMatch.js │ ├── fuzzysearch.js │ ├── fuzzyset.js │ ├── fuzzysort.min.js │ ├── fzf.iife.min.js │ ├── fzy.js │ ├── itemsjs.min.js │ ├── js-search.min.js │ ├── liquidmetal.js │ ├── lunr.js │ ├── m31-fuzzy-search.umd.js │ ├── match-sorter.umd.min.js │ ├── minisearch.min.js │ ├── ndx.min.js │ ├── orama.iife.js │ ├── quick-score.min.js │ ├── search-index.js │ ├── sifter.min.js │ └── wade.js └── testdata.json ├── dist ├── uFuzzy.cjs ├── uFuzzy.d.ts ├── uFuzzy.iife.js ├── uFuzzy.iife.min.js └── uFuzzy.mjs ├── jsconfig.json ├── package.json ├── rollup.config.js ├── src └── uFuzzy.mjs └── uFuzzy.png /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | indent_size = 4 6 | end_of_line = lf 7 | charset = utf-8 8 | insert_final_newline = true 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Leon Sorokin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /bench.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leeoniya/uFuzzy/0c8bc57d1c1150307f1a61ce27c4b843bf9a0ee3/bench.png -------------------------------------------------------------------------------- /demos/clippy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leeoniya/uFuzzy/0c8bc57d1c1150307f1a61ce27c4b843bf9a0ee3/demos/clippy.png -------------------------------------------------------------------------------- /demos/inverted-index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | With inverted index 6 | 7 | 8 | 9 |

 10 | 
 11 | 		
 12 | 		
165 | 	
166 | 


--------------------------------------------------------------------------------
/demos/lib/FuzzySearch.js:
--------------------------------------------------------------------------------
1 | !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.FuzzySearch=t():e.FuzzySearch=t()}("undefined"!=typeof window?window:this,(()=>(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};function r(e,t){for(var r=0;ra});var n=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}var t,n,o;return t=e,o=[{key:"getDescendantProperty",value:function(t,r){var n,o,i,a,s,c,f=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];if(r){if(-1===(i=r.indexOf("."))?n=r:(n=r.slice(0,i),o=r.slice(i+1)),null!=(a=t[n]))if(o||"string"!=typeof a&&"number"!=typeof a)if("[object Array]"===Object.prototype.toString.call(a))for(s=0,c=a.length;s0&&void 0!==arguments[0]?arguments[0]:[],r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};o(this,e),Array.isArray(r)||(n=r,r=[]),this.haystack=t,this.keys=r,this.options=Object.assign({caseSensitive:!1,sort:!1},n)}var t,r,a;return t=e,r=[{key:"search",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";if(""===t)return this.haystack;for(var r=[],o=0;o1?o[o.length-1]-o[0]+2:2+o[0])}},{key:"nearestIndexesFor",value:function(t,r){var n=r.split(""),o=[];return e.indexesOfFirstLetter(t,r).forEach((function(e,r){var i=e+1;o[r]=[e];for(var a=1;a0?a.substr(d):a}function e(a){var b=a.length;if(!b)return null;for(var c=g(a[0]),d=0;++de?1:e>d?-1:0}function j(a,b,c,d,e,f,g){this.normalized=a,this.words=b,this.tokens_groups=c,this.fused_str=d,this.fused_map=e,this.fused_score=0,this.has_children=f,this.children=g}function k(a,b,c){this.tokens=a,this.map=b,this.gate=c;for(var d=a.length,e=-1,f=new Array(d);++ed&&(e=b[d++],"*"!==e&&""!==e);){if(null==a||!(e in a))return c;a=a[e]}if(null==a)return c;var i=Object.prototype.toString.call(a),j="[object Array]"===i,k="[object Object]"===i;if(d===h)if(j)for(f=-1,g=a.length;++fc;c++)r(f[c],d,e);return d}function r(a,b,c){var d=a.length;0!=d&&(d>=3&&t(a,6,b,c),d>=2&&s(a,4,b,c),u(a[0],b,c))}function s(a,b,c,d){for(var e=Math.min(a.length,b),f=0;e-1>f;f++)for(var g=f+1;e>g;g++)u(a[f]+a[g],c,d);return c}function t(a,b,c,d){for(var e=Math.min(a.length,b),f=0;e-2>f;f++)for(var g=f+1;e-1>g;g++)for(var h=g+1;e>h;h++)u(a[f]+a[g]+a[h],c,d);return c}function u(a,b,c){a in c||(c[a]=!0,b.push(a))}function v(a,b){var c={};if(0==a.length)return[];for(var d=0;de;e++)h[e]={};var i,j=new D(a,h,c,d),k=B(j,0,0).score,l=0;for(e=0;g>e&&(i=h[e][l],i);e++)b[e]=f=i.index,f>-1&&(l|=1<G&&(i=G);var j,k,l,m=f[c],n=0,o=-1,p=h-1>c,q=e[c+1];for(j=0;i>j;j++){var r=1<k))){if(p){l=b|r;var s=l in q?q[l]:B(a,l,c+1);k+=s.score,j=n&&(n=k,o=j)}}p&&(l=b,k=l in q?q[l].score:B(a,l,c+1).score,k>n&&(n=k,o=-1));var t=new C(n,o);return e[c][b]=t,t}function C(a,b){this.score=a,this.index=b}function D(a,b,c,d){this.score_grid=a,this.cache_tree=b,this.score_thresholds=c,this.order_bonus=d}function E(a,b){var c,d,e=a.slice();for(a.length=b,c=0;b>c;c++)a[c]=-1;for(c=0;c-1&&b>d&&(a[d]=c)}a.defaultOptions={minimum_match:1,thresh_include:2,thresh_relative_to_best:.5,field_good_enough:20,bonus_match_start:.5,bonus_token_order:2,bonus_position_decay:.7,score_per_token:!0,score_test_fused:!1,score_acronym:!1,token_sep:" .,-:",score_round:.1,output_limit:0,sorter:i,normalize:x,filter:null,output_map:"item",join_str:", ",token_query_min_length:2,token_field_min_length:3,token_query_max_length:64,token_field_max_length:64,token_fused_max_length:64,token_min_rel_size:.6,token_max_rel_size:10,interactive_debounce:150,interactive_mult:1.2,interactive_burst:3,source:[],keys:[],lazy:!1,token_re:/\s+/g,identify_item:null,use_index_store:!1,store_thresh:.7,store_max_results:1500};var F={keys:[],tags:[],index:[],index_map:{},nb_indexed:0,store:{},tags_re:null,acro_re:null,token_re:null,options:null,dirty:!1,query:null,results:[],start_time:0,search_time:0},G=32;b.update=function(a,b,c){for(var d in c)c.hasOwnProperty(d)&&b.hasOwnProperty(d)&&(a[d]=void 0===c[d]?b[d]:c[d])},a.setOptions=function(a,d,e,f,g,h){g?(c(a,f),a.options=new b(e,d)):b.update(a.options,e,d),h.call(a,d)},c(a.prototype,{setOptions:function(b,c){void 0===c&&(c=b.reset||!1),a.setOptions(this,b,a.defaultOptions,F,c,this._optionsHook)},_optionsHook:function(a){var b=this.options;"output_map"in a&&"string"==typeof a.output_map&&("alias"===b.output_map?b.output_map=this.aliasResult:b.output_map=d(b.output_map,["root","."])),this.source=b.source;var c;if("keys"in a&&void 0!==(c=a.keys)){var h,i,j=Object.prototype.toString.call(c);if(this.tags=null,"[object String]"===j)this.keys=c.length?[c]:[];else if("[object Object]"===j){this.keys=[],this.tags=[],h=0;for(var k in c)c.hasOwnProperty(k)&&(this.tags[h]=k,this.keys[h]=c[k],h++)}else this.keys=c;for(c=this.keys,i=c.length,h=-1;++h0&&e>d&&(e=d),"function"!=typeof b)return a.slice(0,e);for(var f=new Array(e),g=-1;++g0&&d>c&&(d=c),""===b)return a.slice(0,d);var e,f,g=new Array(d);if(-1===b.indexOf("."))for(f=-1;++f=c&&(h[++f]=d);return h},c(a.prototype,{_prepQuery:function(b){var c,d,e,f,g,h,i,k=this.options,l=k.score_per_token,m=k.score_test_fused,n=k.token_fused_max_length,o=k.token_field_min_length,p=k.token_field_max_length,q=this.tags,r=this.tags_re,s=q.length,t=this.token_re;if(l&&s&&r){var u,v=0,w=0,x=new Array(s+1),y=r.exec(b);for(g=null!==y;null!==y;)u=y.index,x[w]=b.substring(v,u),v=u+y[0].length,w=q.indexOf(y[1])+1,y=r.exec(b);x[w]=b.substring(v),f=[];for(var z=-1;++za&&(a=this.fused_score),this.has_children)for(var h=this.children,i=-1,j=h.length;++iG?a.posVector(b):a.bitVector(b,{},0)},a.mapAlphabet=function(b){for(var c=b.length,d=new Array(c),e=-1;++eG?d[e]=a.posVector(f):d[e]=a.bitVector(f,{},0)}return d},a.bitVector=function(a,b,c){for(var d,e=a.length,f=-1,g=c;++fd;){for(var g=[],h={},i=0,j=0;++d=G){c=new k([l],a.posVector(l),4294967295);break}if(m+i>=G){d--;break}g.push(l),a.bitVector(l,h,i),j|=(1<0&&f.push(new k(g,h,j)),c&&(f.push(c),c=null)}return f},a.prototype.score=function(b,c){var d=a.alphabet(b);return a.score_map(b,c,d,this.options)},a.score_map=function(b,c,d,e){var f,g,h=b.length,i=c.length,j=e.bonus_match_start,k=i>h?h:i;if(0===k)return 0;var l=(h+i)/(2*h*i),m=0;if(b===c)m=k;else for(;b[m]===c[m]&&++mG)return g=a.llcs_large(b,c,d,m),l*g*g+j*m;var n,o,p=(1<>1&1431655765,q=(858993459&q)+(q>>2&858993459),g=16843009*(q+(q>>4)&252645135)>>24,g+=m,l*g*g+j*m},a.score_single=function(b,c,d){var e=b.tokens[0],f=e.length,g=c.length;return gd.token_max_rel_size*f?[0]:[a.score_map(e,c,b.map,d)]},a.score_pack=function(b,c,d){var e=b.tokens,f=e.length;if(1==f)return a.score_single(b,c,d);for(var g,h,i=4294967295,j=0|b.gate,k=b.map,l=-1,m=c.length;++lm||m>p*w)q[s]=0,r+=w;else{if(v===c)u=t=w;else{var x=m>w?w:m;for(u=0;v[u]===c[u]&&++u>>r&(1<>>u;y;)y&=y-1,t++}r+=w;var z=(w+m)/(2*w*m);q[s]=z*t*t+n*u}}return q},a.llcs_large=function(a,b,c,d){var e,f,g,h,i,j;void 0===d&&(d=0),g=d?[new l(0,d),new l(1/0,1/0)]:[new l(1/0,1/0)];var k,m,n,o,p,q,r=d,s=g.length,t=b.length;for(q=d;t>q;q++){var u=b[q];if(u in c){k=c[u];var v=new Array(Math.min(2*s,r+2));for(h=-1,m=0,f=k[0],j=-1,o=-1;++of;)f=k[++m];f>=e?v[++h]=n:(f===i?v[h].end++:1===p?(n.start=f,n.end=f+1,v[++h]=n):v[++h]=new l(f,f+1),p>1&&(n.start++,v[++h]=n))}e>f&&(v[++h]=n,r++),g=v,s=++h}}return r},c(a.prototype,{search:function(b){var c=Date.now();this.start_time=c;var d=this.options;this.dirty&&d.lazy&&(this._buildIndexFromSource(),this.dirty=!1);var e=this.query=this._prepQuery(b),f=this.index,g=[];d.use_index_store&&(f=this._storeSearch(e,f)),d.filter&&(f=d.filter.call(this,f));var h=this._searchIndex(e,f,g);g=a.filterGTE(g,"score",h),"function"==typeof d.sorter&&(g=g.sort(d.sorter)),(d.output_map||d.output_limit>0)&&(g="function"==typeof d.output_map?a.map(g,d.output_map,this,d.output_limit):a.mapField(g,d.output_map,d.output_limit));var i=Date.now();return this.search_time=i-c,this.results=g,g},_searchIndex:function(b,c,d){for(var e=this.options,f=e.bonus_position_decay,g=e.field_good_enough,i=e.thresh_relative_to_best,j=e.score_per_token,k=e.score_round,l=e.thresh_include,m=0,n=b.children,o=-1,p=c.length;++oy&&(y=F,z=D)}if(y*=1+v,v*=f,y>s&&(s=y,t=w,u=z,y>g))break}if(j){var H=b.scoreItem();s=.5*s+.5*H}if(s>m){m=s;var I=s*i;I>l&&(l=I)}s>l&&(s=Math.round(s/k)*k,d.push(new h(q.item,r,s,t,u,r[0][0].join(" "))))}return l},_scoreField:function(b,c){var d=c.tokens_groups,e=d.length,f=b.length;if(!e||!f)return 0;for(var g,h,i,j,k,l=0,m=-1,n=this.options,o=n.bonus_token_order,p=n.minimum_match,q=-1;++qh||o>h-g&&k>0&&u[k]<=u[k-1])&&(t[k]=g,u[k]=v);var w=r.score_item;for(k=-1;++kp){var x=u[k],y=x-m,z=o*(1/(1+Math.abs(y)));y>0&&(z*=2),l+=z,g+=z,m=x}g>w[k]&&(w[k]=g)}}if(n.score_test_fused){for(var A=n.score_acronym?f-1:f,B=b[0],C=0;++Cl?D:l,D>c.fused_score&&(c.fused_score=D)}return l}}),c(a.prototype,{_prepItem:function(b,c){for(var d=a.generateFields(b,c),e=d.length,f=-1;++f2*this.options.token_field_min_length&&(k=a.filterSize(k,this.options.token_field_min_length,this.options.token_field_max_length)),this.options.score_acronym&&k.push(j.replace(this.acro_re,"$1")),g[h]=k}return new m(b,d)},add:function(a,b){void 0===b&&(b=!0);var c,d="function"==typeof this.options.identify_item?this.options.identify_item(a):null;null===d?(c=this.nb_indexed,this.nb_indexed++):d in this.index_map?c=this.index_map[d]:(this.index_map[d]=this.nb_indexed,c=this.nb_indexed,this.nb_indexed++);var e=this._prepItem(a,this.keys);this.index[c]=e,b&&(this.source[c]=a),this.options.use_index_store&&this._storeAdd(e,c)},_buildIndexFromSource:function(){var a=this.source.length;this.index=new Array(a),this.index_map={},this.nb_indexed=0;for(var b=-1;++b=b&&(i[++g]=c>e?d:d.substr(0,c));return i},c(a.defaultOptions,{highlight_prefix:!1,highlight_bridge_gap:2,highlight_before:'',highlight_after:""}),a.prototype.highlight=function(b,c){var d,e,f=this.query.normalized;return c&&c.length&&(d=this.tags.indexOf(c))>-1&&(e=this.query.children[d])&&(f+=(f.length?" ":"")+e.normalized),a.highlight(f,b,this.options)},a.highlight=function(b,c,d){if(void 0===d&&(d=a.defaultOptions),!c)return"";var e=d.highlight_before,f=d.highlight_after,g=d.score_per_token,h=d.score_test_fused,i=d.score_acronym,j=d.token_re,k=d.normalize(b),l=d.normalize(c),m=k.split(j),n=l.split(j),o=[],p=[];z(c,j,o,p);var q=[],r=[],s=0,t=0;if(g&&(t=a.matchTokens(n,m,r,d,!1)),(h||!g||i)&&(s=a.score_map(k,l,a.alphabet(k),d)+d.bonus_token_order),0===t&&0===s)return c;(!g||s>t)&&(m=[k],n=[l],o=[c],r=[0]);for(var u=o.length,v=-1;++vB&&q.push(A.substring(B,G)),q.push(e+A.substring(G,H)+f),B=H}q.push(A.substring(B)+p[v])}else q.push(o[v]+p[v])}return q.join("")},a.align=function(b,c,d,e,f){void 0===f&&(f=a.defaultOptions);var g,h,i=100,j=-10,k=-1,l=0,m=1,n=2,o=3,p=f.score_acronym,q=f.token_sep,r=Math.min(b.length+1,f.token_query_max_length),s=Math.min(c.length+1,f.token_field_max_length),t=s>r?r:s,u=0;if(b===c)u=r,r=0;else if(f.highlight_prefix){for(g=0;t>g&&b[g]===c[g];g++)u++;u&&(b=b.substring(u),c=c.substring(u),r-=u,s-=u)}var v=0,w=0,x=0,y=new Array(r*s),z=s-1;if(r>1&&s>1){var A,B,C,D,E=new Array(s),F=new Array(s),G=0;for(h=0;s>h;h++)F[h]=0,E[h]=0,y[h]=l;for(g=1;r>g;g++)for(G=0,A=E[0],z++,y[z]=l,h=1;s>h;h++)switch(D=F[h]=Math.max(F[h]+k,E[h]+j),G=Math.max(G+k,E[h-1]+j),C=p?b[g-1]!==c[h-1]?-(1/0):A+i+(2>g||q.indexOf(b[g-2])>-1?i:0)+(2>h||q.indexOf(c[h-2])>-1?i:0):b[g-1]===c[h-1]?A+i:-(1/0),A=E[h],B=E[h]=Math.max(C,D,G,0),z++,B){case G:y[z]=n;break;case C:y[z]=o,B>v&&(v=B,w=g,x=h);break;case D:y[z]=m;break;default:y[z]=l}}var H=f.highlight_bridge_gap,I=0;if(v>0){g=w,h=x,z=g*s+h,I=x,e.push(x+u);for(var J=!0;J;)switch(y[z]){case m:g--,z-=s;break;case n:h--,z--;break;case o:I-h>H&&(d.push(I+u),e.push(h+u)),h--,g--,I=h,z-=s+1;break;case l:default:J=!1}d.push(I+u)}return u&&(I>0&&H>=I?d[d.length-1]=0:(d.push(0),e.push(u))),d.reverse(),e.reverse(),v+u},a.matchTokens=function(b,c,d,e,f){void 0===e&&(e=a.defaultOptions),void 0===f&&(f=!1);var g,h,i,j,k,l,m,n=e.minimum_match,o=e.thresh_relative_to_best,p=[],q=b.length,r=c.length,s=a.mapAlphabet(b),t=n,u=-1,v=-1,w=0,x=[];for(g=0;q>g;g++)if(i=[],d[g]=-1,t=n,j=b[g],j.length){for(l=s[g],h=0;r>h;h++)k=c[h],k.length?(m=a.score_map(j,k,l,e),i[h]=m,m>n&&w++,m>t&&(t=m,u=g,v=h)):i[h]=0;x[g]=t,p[g]=i}else{for(h=0;r>h;h++)i[h]=0;p[g]=i}if(0===w)return 0;if(1===w)return d[u]=v,f&&E(d,r),t;for(g=0;go;o++){for(var r=e[o],s=0;i>s&&(r=this._queue[s](r,o,e),void 0!==r&&null!==r);s++);void 0!==r&&null!==r&&t.push(r)}return t},t.Pipeline.prototype.reset=function(){this._queue=[]},t.Pipeline.prototype.get=function(){return this._queue},t.Pipeline.prototype.toJSON=function(){return this._queue.map(function(e){return t.Pipeline.warnIfFunctionNotRegistered(e),e.label})},t.Index=function(){this._fields=[],this._ref="id",this.pipeline=new t.Pipeline,this.documentStore=new t.DocumentStore,this.index={},this.eventEmitter=new t.EventEmitter,this._idfCache={},this.on("add","remove","update",function(){this._idfCache={}}.bind(this))},t.Index.prototype.on=function(){var e=Array.prototype.slice.call(arguments);return this.eventEmitter.addListener.apply(this.eventEmitter,e)},t.Index.prototype.off=function(e,t){return this.eventEmitter.removeListener(e,t)},t.Index.load=function(e){e.version!==t.version&&t.utils.warn("version mismatch: current "+t.version+" importing "+e.version);var n=new this;n._fields=e.fields,n._ref=e.ref,n.documentStore=t.DocumentStore.load(e.documentStore),n.pipeline=t.Pipeline.load(e.pipeline),n.index={};for(var i in e.index)n.index[i]=t.InvertedIndex.load(e.index[i]);return n},t.Index.prototype.addField=function(e){return this._fields.push(e),this.index[e]=new t.InvertedIndex,this},t.Index.prototype.setRef=function(e){return this._ref=e,this},t.Index.prototype.saveDocument=function(e){return this.documentStore=new t.DocumentStore(e),this},t.Index.prototype.addDoc=function(e,n){if(e){var n=void 0===n?!0:n,i=e[this._ref];this.documentStore.addDoc(i,e),this._fields.forEach(function(n){var o=this.pipeline.run(t.tokenizer(e[n]));this.documentStore.addFieldLength(i,n,o.length);var r={};o.forEach(function(e){e in r?r[e]+=1:r[e]=1},this);for(var s in r){var u=r[s];u=Math.sqrt(u),this.index[n].addToken(s,{ref:i,tf:u})}},this),n&&this.eventEmitter.emit("add",e,this)}},t.Index.prototype.removeDocByRef=function(e){if(e&&this.documentStore.isDocStored()!==!1&&this.documentStore.hasDoc(e)){var t=this.documentStore.getDoc(e);this.removeDoc(t,!1)}},t.Index.prototype.removeDoc=function(e,n){if(e){var n=void 0===n?!0:n,i=e[this._ref];this.documentStore.hasDoc(i)&&(this.documentStore.removeDoc(i),this._fields.forEach(function(n){var o=this.pipeline.run(t.tokenizer(e[n]));o.forEach(function(e){this.index[n].removeToken(e,i)},this)},this),n&&this.eventEmitter.emit("remove",e,this))}},t.Index.prototype.updateDoc=function(e,t){var t=void 0===t?!0:t;this.removeDocByRef(e[this._ref],!1),this.addDoc(e,!1),t&&this.eventEmitter.emit("update",e,this)},t.Index.prototype.idf=function(e,t){var n="@"+t+"/"+e;if(Object.prototype.hasOwnProperty.call(this._idfCache,n))return this._idfCache[n];var i=this.index[t].getDocFreq(e),o=1+Math.log(this.documentStore.length/(i+1));return this._idfCache[n]=o,o},t.Index.prototype.getFields=function(){return this._fields.slice()},t.Index.prototype.search=function(e,n){if(!e)return[];e="string"==typeof e?{any:e}:JSON.parse(JSON.stringify(e));var i=null;null!=n&&(i=JSON.stringify(n));for(var o=new t.Configuration(i,this.getFields()).get(),r={},s=Object.keys(e),u=0;u0&&t.push(e);for(var i in n)"docs"!==i&&"df"!==i&&this.expandToken(e+i,t,n[i]);return t},t.InvertedIndex.prototype.toJSON=function(){return{root:this.root}},t.Configuration=function(e,n){var e=e||"";if(void 0==n||null==n)throw new Error("fields should not be null");this.config={};var i;try{i=JSON.parse(e),this.buildUserConfig(i,n)}catch(o){t.utils.warn("user configuration parse failed, will use default configuration"),this.buildDefaultConfig(n)}},t.Configuration.prototype.buildDefaultConfig=function(e){this.reset(),e.forEach(function(e){this.config[e]={boost:1,bool:"OR",expand:!1}},this)},t.Configuration.prototype.buildUserConfig=function(e,n){var i="OR",o=!1;if(this.reset(),"bool"in e&&(i=e.bool||i),"expand"in e&&(o=e.expand||o),"fields"in e)for(var r in e.fields)if(n.indexOf(r)>-1){var s=e.fields[r],u=o;void 0!=s.expand&&(u=s.expand),this.config[r]={boost:s.boost||0===s.boost?s.boost:1,bool:s.bool||i,expand:u}}else t.utils.warn("field name in user configuration not found in index instance fields");else this.addAllFields2UserConfig(i,o,n)},t.Configuration.prototype.addAllFields2UserConfig=function(e,t,n){n.forEach(function(n){this.config[n]={boost:1,bool:e,expand:t}},this)},t.Configuration.prototype.get=function(){return this.config},t.Configuration.prototype.reset=function(){this.config={}},lunr.SortedSet=function(){this.length=0,this.elements=[]},lunr.SortedSet.load=function(e){var t=new this;return t.elements=e,t.length=e.length,t},lunr.SortedSet.prototype.add=function(){var e,t;for(e=0;e1;){if(r===e)return o;e>r&&(t=o),r>e&&(n=o),i=n-t,o=t+Math.floor(i/2),r=this.elements[o]}return r===e?o:-1},lunr.SortedSet.prototype.locationFor=function(e){for(var t=0,n=this.elements.length,i=n-t,o=t+Math.floor(i/2),r=this.elements[o];i>1;)e>r&&(t=o),r>e&&(n=o),i=n-t,o=t+Math.floor(i/2),r=this.elements[o];return r>e?o:e>r?o+1:void 0},lunr.SortedSet.prototype.intersect=function(e){for(var t=new lunr.SortedSet,n=0,i=0,o=this.length,r=e.length,s=this.elements,u=e.elements;;){if(n>o-1||i>r-1)break;s[n]!==u[i]?s[n]u[i]&&i++:(t.add(s[n]),n++,i++)}return t},lunr.SortedSet.prototype.clone=function(){var e=new lunr.SortedSet;return e.elements=this.toArray(),e.length=e.elements.length,e},lunr.SortedSet.prototype.union=function(e){var t,n,i;this.length>=e.length?(t=this,n=e):(t=e,n=this),i=t.clone();for(var o=0,r=n.toArray();oo;++o)t[o]=0;for(o=0;30-n>o;++o)t[o+n]=o/n|0;for(i=r,o=0;30>o;++o)e[o]=i,i+=1<o;++o)t.table[o]=0;for(o=0;r>o;++o)t.table[e[n+o]]++;for(t.table[0]=0,i=0,o=0;16>o;++o)g[o]=i,i+=t.table[o];for(o=0;r>o;++o)e[n+o]&&(t.trans[g[e[n+o]]++]=o)}function y(t){t.bitcount--||(t.tag=t.source[t.sourceIndex++],t.bitcount=7);var e=1&t.tag;return t.tag>>>=1,e}function b(t,e,n){if(!e)return n;for(;24>t.bitcount;)t.tag|=t.source[t.sourceIndex++]<>>16-e;return t.tag>>>=e,t.bitcount-=e,r+n}function A(t,e){for(;24>t.bitcount;)t.tag|=t.source[t.sourceIndex++]<>>=1,++o,n+=e.table[o],r-=e.table[o]}while(r>=0);return t.tag=i,t.bitcount-=o,e.trans[n+r]}function m(t,e,n){var r,o,i,a,s,c;for(r=b(t,5,257),o=b(t,5,1),i=b(t,4,4),a=0;19>a;++a)d[a]=0;for(a=0;i>a;++a){var u=b(t,3,0);d[f[a]]=u}for(p(l,d,0,19),s=0;r+o>s;){var h=A(t,l);switch(h){case 16:var g=d[s-1];for(c=b(t,2,3);c;--c)d[s++]=g;break;case 17:for(c=b(t,3,3);c;--c)d[s++]=0;break;case 18:for(c=b(t,7,11);c;--c)d[s++]=0;break;default:d[s++]=h}}p(e,d,0,r),p(n,d,r,o)}function v(t,e,n){for(;;){var r,o,i,f,l=A(t,e);if(256===l)return 0;if(256>l)t.dest[t.destLen++]=l;else for(r=b(t,a[l-=257],s[l]),o=A(t,n),f=i=t.destLen-b(t,c[o],u[o]);i+r>f;++f)t.dest[t.destLen++]=t.dest[f]}}function x(t){for(var e,n;t.bitcount>8;)t.sourceIndex--,t.bitcount-=8;if((e=256*(e=t.source[t.sourceIndex+1])+t.source[t.sourceIndex])!==(65535&~(256*t.source[t.sourceIndex+3]+t.source[t.sourceIndex+2])))return-3;for(t.sourceIndex+=4,n=e;n;--n)t.dest[t.destLen++]=t.source[t.sourceIndex++];return t.bitcount=0,0}!function(t,e){var n;for(n=0;7>n;++n)t.table[n]=0;for(t.table[7]=24,t.table[8]=152,t.table[9]=112,n=0;24>n;++n)t.trans[n]=256+n;for(n=0;144>n;++n)t.trans[24+n]=n;for(n=0;8>n;++n)t.trans[168+n]=280+n;for(n=0;112>n;++n)t.trans[176+n]=144+n;for(n=0;5>n;++n)e.table[n]=0;for(e.table[5]=32,n=0;32>n;++n)e.trans[n]=n}(o,i),h(a,s,4,3),h(c,u,2,1),a[28]=0,s[28]=258;const S=18===new Uint8Array(new Uint32Array([305419896]).buffer)[0],U=(t,e,n)=>{let r=t[e];t[e]=t[n],t[n]=r};var w={swap32LE:t=>{S&&(t=>{const e=t.length;for(let n=0;e>n;n+=4)U(t,n,n+3),U(t,n+1,n+2)})(t)}};const z=function(t,e){var n,a,s=new r(t,e);do{switch(n=y(s),b(s,2,0)){case 0:a=x(s);break;case 1:a=v(s,o,i);break;case 2:m(s,s.ltree,s.dtree),a=v(s,s.ltree,s.dtree);break;default:a=-3}if(0!==a)throw Error("Data error")}while(!n);return s.dest.length>s.destLen?"function"==typeof s.dest.slice?s.dest.slice(0,s.destLen):s.dest.subarray(0,s.destLen):s.dest},{swap32LE:B}=w;var I={exports:{}};!function(t){!function(){t.exports=function(){var t="3.7.5",e=t,n="function"==typeof atob,r="function"==typeof btoa,o="function"==typeof Buffer,i="function"==typeof TextDecoder?new TextDecoder:void 0,a="function"==typeof TextEncoder?new TextEncoder:void 0,s=Array.prototype.slice.call("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="),c=function(t){var e={};return t.forEach((function(t,n){return e[t]=n})),e}(s),u=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,f=String.fromCharCode.bind(String),l="function"==typeof Uint8Array.from?Uint8Array.from.bind(Uint8Array):function(t){return new Uint8Array(Array.prototype.slice.call(t,0))},d=function(t){return t.replace(/=/g,"").replace(/[+\/]/g,(function(t){return"+"==t?"-":"_"}))},h=function(t){return t.replace(/[^A-Za-z0-9\+\/]/g,"")},g=function(t){for(var e,n,r,o,i="",a=t.length%3,c=0;t.length>c;){if((n=t.charCodeAt(c++))>255||(r=t.charCodeAt(c++))>255||(o=t.charCodeAt(c++))>255)throw new TypeError("invalid character found");i+=s[(e=n<<16|r<<8|o)>>18&63]+s[e>>12&63]+s[e>>6&63]+s[63&e]}return a?i.slice(0,a-3)+"===".substring(a):i},p=r?function(t){return btoa(t)}:o?function(t){return Buffer.from(t,"binary").toString("base64")}:g,y=o?function(t){return Buffer.from(t).toString("base64")}:function(t){for(var e=[],n=0,r=t.length;r>n;n+=4096)e.push(f.apply(null,t.subarray(n,n+4096)));return p(e.join(""))},b=function(t,e){return void 0===e&&(e=!1),e?d(y(t)):y(t)},A=function(t){if(2>t.length)return 128>(e=t.charCodeAt(0))?t:2048>e?f(192|e>>>6)+f(128|63&e):f(224|e>>>12&15)+f(128|e>>>6&63)+f(128|63&e);var e=65536+1024*(t.charCodeAt(0)-55296)+(t.charCodeAt(1)-56320);return f(240|e>>>18&7)+f(128|e>>>12&63)+f(128|e>>>6&63)+f(128|63&e)},m=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,v=function(t){return t.replace(m,A)},x=o?function(t){return Buffer.from(t,"utf8").toString("base64")}:a?function(t){return y(a.encode(t))}:function(t){return p(v(t))},S=function(t,e){return void 0===e&&(e=!1),e?d(x(t)):x(t)},U=function(t){return S(t,!0)},w=/[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g,z=function(t){switch(t.length){case 4:var e=((7&t.charCodeAt(0))<<18|(63&t.charCodeAt(1))<<12|(63&t.charCodeAt(2))<<6|63&t.charCodeAt(3))-65536;return f(55296+(e>>>10))+f(56320+(1023&e));case 3:return f((15&t.charCodeAt(0))<<12|(63&t.charCodeAt(1))<<6|63&t.charCodeAt(2));default:return f((31&t.charCodeAt(0))<<6|63&t.charCodeAt(1))}},B=function(t){return t.replace(w,z)},I=function(t){if(t=t.replace(/\s+/g,""),!u.test(t))throw new TypeError("malformed base64.");t+="==".slice(2-(3&t.length));for(var e,n,r,o="",i=0;t.length>i;)e=c[t.charAt(i++)]<<18|c[t.charAt(i++)]<<12|(n=c[t.charAt(i++)])<<6|(r=c[t.charAt(i++)]),o+=64===n?f(e>>16&255):64===r?f(e>>16&255,e>>8&255):f(e>>16&255,e>>8&255,255&e);return o},C=n?function(t){return atob(h(t))}:o?function(t){return Buffer.from(t,"base64").toString("binary")}:I,L=o?function(t){return l(Buffer.from(t,"base64"))}:function(t){return l(C(t).split("").map((function(t){return t.charCodeAt(0)})))},E=function(t){return L(V(t))},D=o?function(t){return Buffer.from(t,"base64").toString("utf8")}:i?function(t){return i.decode(L(t))}:function(t){return B(C(t))},V=function(t){return h(t.replace(/[-_]/g,(function(t){return"-"==t?"+":"/"})))},k=function(t){return D(V(t))},T=function(t){return{value:t,enumerable:!1,writable:!0,configurable:!0}},j=function(){var t=function(t,e){return Object.defineProperty(String.prototype,t,T(e))};t("fromBase64",(function(){return k(this)})),t("toBase64",(function(t){return S(this,t)})),t("toBase64URI",(function(){return S(this,!0)})),t("toBase64URL",(function(){return S(this,!0)})),t("toUint8Array",(function(){return E(this)}))},M=function(){var t=function(t,e){return Object.defineProperty(Uint8Array.prototype,t,T(e))};t("toBase64",(function(t){return b(this,t)})),t("toBase64URI",(function(){return b(this,!0)})),t("toBase64URL",(function(){return b(this,!0)}))},O={version:t,VERSION:e,atob:C,atobPolyfill:I,btoa:p,btoaPolyfill:g,fromBase64:k,toBase64:S,encode:S,encodeURI:U,encodeURL:U,utob:v,btou:B,decode:k,isValid:function(t){if("string"!=typeof t)return!1;var e=t.replace(/\s+/g,"").replace(/={0,2}$/,"");return!/[^\s0-9a-zA-Z\+/]/.test(e)||!/[^\s0-9a-zA-Z\-_]/.test(e)},fromUint8Array:b,toUint8Array:E,extendString:j,extendUint8Array:M,extendBuiltins:function(){j(),M()},Base64:{}};return Object.keys(O).forEach((function(t){return O.Base64[t]=O[t]})),O}()}("undefined"!=typeof self?self:"undefined"!=typeof window&&window)}(I);const C=1,L=2,E=4,D=8,V=16,k=32,T=64,j=128,M=256,O=512,P=1024,F=2048,X=4096,H=8192,Y=class{constructor(t){const e="function"==typeof t.readUInt32BE&&"function"==typeof t.slice;if(e||t instanceof Uint8Array){let n;if(e)this.highStart=t.readUInt32LE(0),this.errorValue=t.readUInt32LE(4),n=t.readUInt32LE(8),t=t.slice(12);else{const e=new DataView(t.buffer);this.highStart=e.getUint32(0,!0),this.errorValue=e.getUint32(4,!0),n=e.getUint32(8,!0),t=t.subarray(12)}t=z(t,new Uint8Array(n)),t=z(t,new Uint8Array(n)),B(t),this.data=new Uint32Array(t.buffer)}else({data:this.data,highStart:this.highStart,errorValue:this.errorValue}=t)}get(t){let e;return 0>t||t>1114111?this.errorValue:55296>t||t>56319&&65535>=t?(e=(this.data[t>>5]<<2)+(31&t),this.data[e]):t>65535?this.highStart>t?(e=this.data[2080+(t>>11)],e=this.data[e+(t>>5&63)],e=(e<<2)+(31&t),this.data[e]):this.data[this.data.length-4]:(e=(this.data[2048+(t-55296>>5)]<<2)+(31&t),this.data[e])}},Z=I.exports.Base64,Q=new Y(Z.toUint8Array("ABAOAAAAAACwiAAAAYkHdvjtnH+IFkUYxx/v3vPe7uw8UkjsD43ChKICDQsT3iIJy4gSiZAjkn5JUFlaiFmjccT9ESkpGBGVIlQgWSkY/QDBoMgrQv0jRJDAfkCXhUmgRX23d4ebnndmd3Z3ZnfVeeDDzM7MPs8zv57Zd2+5hd1Ed4ClYAisBuuUsqLpMHgJjIBNFu1fBW8l1O8AO8Ee8Cn4HIyCg+CI0u4Y+AmMgVPgDOhuEHWBPjAZXAy2gjfA9kb73hlx+i7SK8AHYDf4BOwHB8AoOAyOguPgB/ArOKlcnwHdPe32/Uin9LTvvwTph0gv62nbubKnXT+nZ1z/DcjfFF8vQno7uEaxH923BGVXN9v5Zcgvj/VFPIT8Y/H1k0jXxPn1SEfARjBdab8V+TfB22CXUh5xd3OcZTH3g6di1LZJbLNs55q96M9n4J9Gm6hsfzQvcT8fbfy//TyUf8vG4Lses/5jcd2PSE/IcQan4/o/UXYadE0kaoJBMG1ivNbidNbETr1XoWyuplwyHFN0fFai/8/EY7BIKY/68EpCvwP+mc/m/2vNGnBhp1eZ51bCmgsEAoFAIBAIBAKBQKAO3Irfrg3lfc4qi/cXd+Kee5TfvAd6ieY0ie5D2cNx+eNInwZLmu33gWuRn4/8C3H9CNJNYEt8/TrS35HuSPktvRP1z0LPOvAceB4IsB5saIa6UBfqQl2oc123AjwBVjWrP7MCgcC5y/ue/56yqXv87+qcIU2Z+ny8tuHHpyxsvrDNITDXgqkDRJcPdJY/wMo24/oQmDqZaPHkdplAuhv8ApqDRDeCVj/OAvD9BUSX9qF8Qpt7lTxnZ7+5TmVtrGMM7XchP3sS0SNgGzg4yU5HIBAIBM5NfsO5QDgfjuM54STOw7/Az/F3QtfhfF4Qn9F/gxMouxm/WU7F9afBQuUM7+rtPF+jb0b6ese/I7sI+emadhEzUT5bqbsW+esNbSMWoG6hWo/8gOLPUqUu+v5rKEHX8oS6iEXQexd7XlmBe1aCNWAp6kSsYyjHc82Liv2Xkd/C/HkN1w/Geren+KryToa2PtlQg2c9zijGZnGJ9kaibzZh84jmmfx4TeYpK9H3usMKqxnDCWxsdLY/3ygy9h+l/LYbYHtuXw2/rfsSPo0a/Jrn6PvPrzL2+7CmfV88lkc9j+F7cRzYU4N48DF8uA3n/T7Fly9q4Jdvoth0uLf9LORC11hvO/0D6RnQfRa99+2Hr1NS/M26VvfEe2jaWTAOvG8zzgKf8zCrYL++qUEfbumeQAjTVnQp+QmW99gQpDoJ4+9uHZe5/l3OW/M8x6WUZaduUvUc5p13NTXlz3VpGbCVrGNe5zOnjvGlrDWY1IdWShuuQ9fWh6h+VSV1Wit1lvNhHFz1zeUYtCg5ntvOSStDW5cITRnF5RJ+rcasJHExztwu910tl6LzLYsvuvvzilB0mvSaxt/V+SY0EMurfkjbrTjfInf+FJGkNdzSlOukZaDo3snqs7RZpqj2Gx7sS52D5O79k+93W2W/T3NhQxe3VeF16pwn4eI8qev7Sl1s0PnPy5PalSV57Pp6XuDxrypR9wBR8nOCzm/eXuYp5d4s/lV1XvL+lG2b+2AaQ1nPr23Hrc7z0WT5qvZL0v7QtdX5zdu6HMei+gV1ri8et4XSVpCfdeB7fRWNRy79UP0RCT4Jyre/88bbKsQUawUrV69dxjd+nlXxbCKos79pz1BpOqucz0gEdZ5hMk+aa7Wdy/7xZ5Yqhc+nyHivrkyQ/reM7tziuFojfM7zxtq0505XYutvHrtVnzNl2ONrTGdPkLv9ZjNHOoShnCh5nLLYKOKfK4qK7bjx/gqyj9lFJc2Wz/HIqyMSYaGnqM8+xp6vB1/6feg22UmLFUno1rurvelz7yT1UVfORW3L7+d6fMcAXdzxIVK3TNNioZpSyj2242izpky6y5S0fpr6q5ZXJT7O1qrmQRVB+rkQ1Dk3vvYttyGoc+51/mUVkYLtXvTx7MCvbUnzW2czyR8pql4XUlbcN9l1pSfPfOl0JV2bylyKoM4959sHQfr9Vpbk2V8u4ry0ndcvH5I1xggP9qVem/PHZL+qeGLrc945tLnHtG/LEtdjr4urxMpM92X1RZDd+pLtsorUydeCaiuvbtdSpQ9l2M4SU01nvI1e35L3uS5Jlw8pe1ykCKo2JtrGK9O9ujOlimcD6Y9LEWQ+7019d2VDLVPrTCLrsvjsQ1TfJVJM12pZmm5b4Xptx6HM9SpFkP2c6drJa5/iSr+pD7r+CNLvATVfpST1RYog/fwKTdsyxLVNQfnWrkyziGltJK2hLLptzjHXIsh+/HytmyQfpPA5VNtzXWWLzbiVsc9sbWSJ7UWE69KNh6v9kya2c6TzMa0fwpD37TtvQ6wuiw9CA9cny33Mj2pLte9Kp6996HO/83HPQ5r+ov5mvU9Qte/fIrGJP7axPO/9eXX6kjLPKZNd17iyZdOHLP31JSbfXY6hC59c+ZZ136TZ9SFlj6cvmVkSrkSQn3NG5KBqEVSeH6Ji/vvnhFWjSlfFNDwzyMgqLvvKxXffbeASBWo+Zj4p2x6TfwE=")),R=new Y(Z.toUint8Array("AAACAAAAAACAOAAAAbYBSf7t2S1IBEEYBuDVDZ7FYrQMNsFiu3hgEYOI0SCXRIUrB8JhEZtgs5gEg1GMFk02m82oGI02m+9xezCOczv/uwv3fvAwc/PzfXOzcdqzWdaBDdiGPdiHdjE+DS3RNDuCfsn8idQ/g3OH3BdwKf0e96/gumTfYcncLdzBPTzAo+RZ+f0Cr/AG7/AJX4738x1wtz9FO5PX/50n6UXMNdfg/0lERERERERERERERETpdedHBvDRql4nq0cXtW9af98qdRby0Vvp8K4W0V+C5Xw0t4J2bfjeBp3cnEu1brnnCTYNa7eKdz91XP7WO9Lb4GqRb7cY6xbtAdqeVOsY/QGcevw/tb6OT85YhvfKYEx9CMuxKsKnrs+eJtVInVvHJ0eVYVvTZk2siFVLOCjb61PTZX3MdVWEyP7fjzpmMxdzTyq2Ebue6x61nXRGnzndWpf1an7dXmGYE4Y1ptqqKsK1nu26Ju0ty+maV2Rpvk+qnDZjKUIobUiesdAQE/jmCTmHmsskpFZsVYbtmXRcaoSGUPomunW2derQhDPFjtT1Q/eb8vnm990fq35oHVt11bU9m89c7DNI8Qs="));function W(t,e){return 0!=(t&e)}function N(t,e){const n=t.length;let r=0,o=0;for(let i=e;n>i+1;i++){const n=t[i+0],a=t[i+1];switch(W(n,k)||(r=0),o){case 2:case 0:o=W(n,H)?1:0;break;case 1:o=W(n,D)?1:W(n,V)&&W(a,H)?2:0}if(!W(n,C)||!W(a,L)){if(W(n,E|C|L))return i+1-e;if(W(a,E|C|L))return i+1-e;if(!(W(n,M)&&W(a,M|O|F|X)||W(n,F|O)&&W(a,O|P)||W(n,X|P)&&W(a,P)||W(a,D|V)||W(a,j)||W(n,T)||2===o)){if(!W(n,k)||!W(a,k)||r%2!=0)return i+1-e;r++}}}return n-e}var q=e((function(t){const e=[],n=[0],r=[];for(let e=0;t.length>e;){const o=t.codePointAt(e);r.push(Q.get(o)|R.get(o)),e+=o>65535?2:1,n.push(e)}for(let o=0;r.length>o;){const i=N(r,o);e.push(t.slice(n[o],n[o+i])),o+=i}return e}));const K=t=>t.normalize("NFKD").split(""),G=/^\s+$/,J=/^[`~!@#$%^&*()\-=_+{}[\]\|\\;':",./<>?]+$/,_={insertOrder:"insertOrder",bestMatch:"bestMatch"},$={keySelector:t=>t,threshold:.6,ignoreCase:!0,ignoreSymbols:!0,normalizeWhitespace:!0,returnMatchData:!1,useDamerau:!0,useSellers:!0,useSeparatedUnicode:!1,sortBy:_.bestMatch},tt=()=>{},et=t=>t instanceof Array?t:[t];function nt(t,e){const n=e.ignoreCase?t.toLocaleLowerCase():t,r=[],o=[];let i=!0,a=0;const s=e.useSeparatedUnicode?K(n):q(n);for(const t of s)G.lastIndex=0,J.lastIndex=0,e.normalizeWhitespace&&G.test(t)?i||(r.push(" "),o.push(a),i=!0):e.ignoreSymbols&&J.test(t)||(r.push(e.useSeparatedUnicode?t:t.normalize()),o.push(a),i=!1),a+=t.length;for(o.push(t.length);" "===r[r.length-1];)r.pop(),o.pop();return{original:t,normal:r,map:o}}function rt(t,e){return{index:e[t.start],length:e[t.end+1]-e[t.start]}}function ot(t,e){if(0===e)return{index:0,length:0};let n=e;for(let e=t.length-2;e>0&&n>1;e--){const r=t[e];n=r[n-1]>r[n]?n:n-1}return{start:n-1,end:e-1}}function it(){return{start:0,end:0}}const at=()=>!0,st=(t,e)=>e>t;function ct(t,e){return{score:1-t[t.length-1][e-1]/(Math.max(t.length,e)-1),scoreIndex:e-1}}function ut(t,e){if(1===t.length)return{score:1,scoreIndex:0};const n=t[t.length-1];let r=n[0],o=0;for(let t=1;e>t;t++){const e=n[t];r>e&&(r=e,o=t)}return{score:1-r/(t.length-1),scoreIndex:o}}function ft(t,e){const n=Array(t);for(let r=0;t>r;r++)n[r]=Array(e),n[r][0]=r;for(let t=0;e>t;t++)n[0][t]=t;return n}function lt(t,e){const n=Array(t);n[0]=Array(e).fill(0);for(let r=1;t>r;r++)n[r]=Array(e),n[r][0]=r;return n}function dt(t,e,n,r,o){const i=n[r],a=n[r+1];let s,c=a[o]+1;(s=i[o+1]+1)o;o++)dt(t,e,n,o,r)}function gt(t,e,n,r){if(0!==r){t.length>0&&dt(t,e,n,0,r);for(let o=1;t.length>o;o++){const i=n[o],a=n[o+1],s=t[o]===e[r]?0:1;let c,u=a[r]+1;(c=i[r+1]+1)t;t++){const n=e[t];null==r.children[n]&&(r.children[n]={children:{},candidates:[],depth:0}),r.depth=Math.max(r.depth,e.length-t),r=r.children[n]}r.candidates.push(n)}function yt(t,e,n,r){for(const o of n){const n=et(r.keySelector(o)).map(((t,n)=>({index:e,keyIndex:n,item:o,normalized:nt(t,r)})));e++;for(const e of n)pt(t,e.normalized.normal,e)}}function bt(t,e){const n=e.score-t.score;if(0!==n)return n;const r=t.match.start-e.match.start;if(0!==r)return r;const o=t.keyIndex-e.keyIndex;if(0!==o)return o;const i=t.lengthDiff-e.lengthDiff;return 0!==i?i:At(t,e)}function At(t,e){return t.index-e.index}function mt(t){switch(t){case _.bestMatch:return bt;case _.insertOrder:return At;default:throw Error("unknown sortBy method "+t)}}function vt(t,e,n,r,o,i,a){const s={item:n.item,normalized:n.normalized,score:r,match:o,index:n.index,keyIndex:n.keyIndex,lengthDiff:i};null==e[n.index]?(e[n.index]=t.length,t.push(s)):0>a(s,t[e[n.index]])&&(t[e[n.index]]=s)}const xt=Math.max,St=t=>t;function Ut(t,e,n,r,o){const i=e+o,a=Math.min(n.length,e+t.depth+1),s=Math.ceil((i+a)/2);return 1-(s-a)/s>=r}function wt(t,e,n,r,o,i){return 1-Math.min(o,i-(t.depth+1))/n.length>=r}function zt(t,e,n){const r=n.useSellers?lt:ft,o={score:n.useDamerau?gt:ht,getLength:n.useSellers?St:xt,shouldUpdateScore:n.useSellers?st:at,shouldContinue:n.useSellers?wt:Ut,walkBack:n.useSellers?ot:it,compareItems:mt(n.sortBy)},i={},a=[],s=r(t.length+1,e.depth+1);if(0>=n.threshold||0===t.length)for(const n of e.candidates)vt(a,i,n,0,{index:0,length:0},t.length,o.compareItems);!function(t,e,n,r,o,i,a){const s=[];for(const n in t.children)s.push([t.children[n],1,n,0,e.length]);const c=Array(t.depth);for(;0!==s.length;){const[t,u,f,l,d]=s.pop();c[u-1]=f,n.score(e,c,r,u-1);const h=u,g=r[r.length-1][h];let p=l,y=d;if(n.shouldUpdateScore(g,d)&&(p=h,y=g),t.candidates.length>0){const s=1-y/n.getLength(e.length,u);if(s>=a.threshold){const a=ot(r,p),c=Math.abs(u-e.length);for(const e of t.candidates)vt(o,i,e,s,a,c,n.compareItems)}}for(const r in t.children){const o=t.children[r];n.shouldContinue(o,u,e,a.threshold,y,g)&&s.push([o,u+1,r,p,y])}}}(e,t,o,s,a,i,n);const c=a.sort(o.compareItems);if(n.returnMatchData){const t=n.useSellers?rt:tt;return c.map((e=>({item:e.item,original:e.normalized.original,key:e.normalized.normal.join(""),score:e.score,match:t(e.match,e.normalized.map)})))}return c.map((t=>t.item))}return t.Searcher=class{constructor(t,e){this.options=Object.assign({},$,e),this.trie={children:{},candidates:[],depth:0},yt(this.trie,0,t,this.options),this.count=t.length}add(...t){yt(this.trie,this.count,t,this.options),this.count+=t.length}search(t,e){return e=Object.assign({},this.options,e),zt(nt(t,this.options).normal,this.trie,e)}},t.fuzzy=function(t,e,n){const r=(n={...$,...n}).useSellers?lt:ft,o=n.useDamerau?gt:ht,i=n.useSellers?ut:ct;t=nt(t,n).normal;const a=nt(e,n),s=r(t.length+1,a.normal.length+1);for(let e=0;a.normal.length>e;e++)o(t,a.normal,s,e);const c=i(s,a.normal.length+1);return n.returnMatchData?{item:e,original:a.original,key:a.normal.join(""),score:c.score,match:n.useSellers?rt(ot(s,c.scoreIndex),a.map):void 0}:c.score},t.search=function(t,e,n){const r={children:{},candidates:[],depth:0};return yt(r,0,e,n={...$,...n}),zt(nt(t,n).normal,r,n)},t.sortKind=_,t}({});
2 | 


--------------------------------------------------------------------------------
/demos/lib/flexsearch.light.js:
--------------------------------------------------------------------------------
 1 | /**!
 2 |  * FlexSearch.js v0.7.31 (Light)
 3 |  * Author and Copyright: Thomas Wilkerling
 4 |  * Licence: Apache-2.0
 5 |  * Hosted by Nextapps GmbH
 6 |  * https://github.com/nextapps-de/flexsearch
 7 |  */
 8 | (function(self){'use strict';function t(a){return"undefined"!==typeof a?a:!0}function v(a){const c=Array(a);for(let b=0;b=this.h&&(r||!m[k])){var h=J(p,d,q),f="";switch(this.B){case "full":if(2h;g--)if(g-h>=this.h){var l=J(p,d,q,e,h);f=k.substring(h,g);K(this,m,f,l,a,b)}break}case "reverse":if(1=this.h&&K(this,
12 | m,f,J(p,d,q,e,g),a,b);f=""}case "forward":if(1=this.h&&K(this,m,f,h,a,b);break}default:if(this.C&&(h=Math.min(h/this.C(c,k,q)|0,p-1)),K(this,m,k,h,a,b),r&&1=this.h&&!e[k]){e[k]=1;const u=this.j&&k>h;K(this,n,u?h:k,J(f+(d/2>f?0:1),d,q,g-1,l-1),a,b,u?k:h)}}}}this.m||(this.register[a]=1)}}return this};
13 | function J(a,c,b,d,e){return b&&1=this.h&&!b[p])if(this.g||h||this.map[p])l[r++]=p,b[p]=1;else return d;a=l;e=a.length}if(!e)return d;c||(c=100);g=this.i&&1=d)))break;if(m){if(h)return O(l,d,0);c[c.length]=l;return}}return!b&&l}function O(a,c,b){a=1===a.length?a[0]:[].concat.apply([],a);return b||a.length>c?a.slice(b,b+c):a}
17 | function P(a,c,b,d){b?(d=d&&c>b,a=(a=a[d?c:b])&&a[d?b:c]):a=a[c];return a}I.prototype.contain=function(a){return!!this.register[a]};I.prototype.update=function(a,c){return this.remove(a).add(a,c)};I.prototype.remove=function(a,c){const b=this.register[a];if(b){if(this.m)for(let d=0,e;d!"#$%&'()*+,-./0123456789:;<=>?@
 33 |     // ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
 34 |     const CODE_a = `a`.charCodeAt(0);
 35 |     const CODE_z = `z`.charCodeAt(0);
 36 |     const CODE_A = `A`.charCodeAt(0);
 37 |     const CODE_Z = `Z`.charCodeAt(0);
 38 |     const CODE_0 = `0`.charCodeAt(0);
 39 |     const CODE_9 = `9`.charCodeAt(0);
 40 |     const CODE_EXCL_MARK = `!`.charCodeAt(0);
 41 |     const CODE_SLASH = `/`.charCodeAt(0);
 42 |     const CODE_COLON = `:`.charCodeAt(0);
 43 |     const CODE_AT = `@`.charCodeAt(0);
 44 |     const CODE_SQ_BKT = `[`.charCodeAt(0);
 45 |     const CODE_CARET = `\``.charCodeAt(0);
 46 |     const CODE_CURLY_BKT = `{`.charCodeAt(0);
 47 |     const CODE_TILDE = `~`.charCodeAt(0);
 48 |     const CODE_START_UNICODE = 127;
 49 | 
 50 |     /**
 51 |      * @param {number} charCode
 52 |      * @returns {boolean}
 53 |      */
 54 |     function _isUpperCase(charCode) {
 55 |       return charCode >= CODE_A && charCode <= CODE_Z;
 56 |     }
 57 | 
 58 |     /**
 59 |      * @param {number} charCode
 60 |      * @returns {boolean}
 61 |      */
 62 |     function _isCodeAlphaNum(charCode) {
 63 |       // 0 - 126 charCodes are ascii, 127 onwards are unicode code points
 64 |       return (
 65 |         (charCode >= CODE_a && charCode <= CODE_z) ||
 66 |         _isUpperCase(charCode) ||
 67 |         (charCode >= CODE_0 && charCode <= CODE_9) ||
 68 |         charCode >= CODE_START_UNICODE
 69 |       );
 70 |     }
 71 | 
 72 |     /**
 73 |      * @param {number} charCode
 74 |      * @returns {boolean}
 75 |      */
 76 |     function _isCodePunctuation(charCode) {
 77 |       // rather than create a uint8 typed array as a lookup table
 78 |       // uglifyjs inlines this function in prod builds. JIT should inline too.
 79 |       // we're calling it charCode rather than 'code' because of an uglifyjs bug
 80 |       // see: https://github.com/mishoo/UglifyJS2/issues/2842
 81 |       return (
 82 |         (charCode >= CODE_EXCL_MARK && charCode <= CODE_SLASH) ||
 83 |         (charCode >= CODE_COLON && charCode <= CODE_AT) ||
 84 |         (charCode >= CODE_SQ_BKT && charCode <= CODE_CARET) ||
 85 |         (charCode >= CODE_CURLY_BKT && charCode <= CODE_TILDE)
 86 |       );
 87 |     }
 88 | 
 89 |     /**
 90 |      * A skip index marks word and punctuation boundaries
 91 |      * We use this to skip around the targetStr and quickly find prefix matches
 92 |      * @param {string} targetStr
 93 |      * @returns {number[]}
 94 |      */
 95 |     function _getTargetSkips(targetStr) {
 96 |       const targetSkips = [];
 97 |       let wasAlphaNum = false;
 98 |       let wasUpperCase = false;
 99 | 
100 |       for (let i = 0, len = targetStr.length; i < len; ++i) {
101 |         const code = targetStr.charCodeAt(i);
102 |         const isAlphaNum = _isCodeAlphaNum(code);
103 |         const isUpperCase = _isUpperCase(code);
104 | 
105 |         if ((isAlphaNum && !wasAlphaNum) || (isUpperCase && !wasUpperCase) || _isCodePunctuation(code)) {
106 |           targetSkips.push(i);
107 |         }
108 | 
109 |         wasAlphaNum = isAlphaNum;
110 |         wasUpperCase = isUpperCase;
111 |       }
112 | 
113 |       // We push the length as the last skip so when matching
114 |       // every range aligns between skip[i] and skip[i + 1]
115 |       // and we don't have to do extraneous overflow checks
116 |       targetSkips.push(targetStr.length);
117 | 
118 |       // NOTE: these can possibly be cached on the items for a faster search next time
119 |       return targetSkips;
120 |     }
121 | 
122 |     /**
123 |      * performs a prefix match e.g 'usam' matches '[u]nited [s]tates of [am]erica
124 |      * @param {number} skipIdx - skip index where to start search from
125 |      * @param {string} searchStr - lowercased search string
126 |      * @param {string} targetStr - lowercased target string
127 |      * @param {number[]} targetSkips - skip boundary indices
128 |      * @returns {number[] | null}
129 |      *  - the [idx, len, ...] ranges where the match occured
130 |      *  - null if no match found
131 |      */
132 |     function _fuzzyPrefixMatch(skipIdx, searchStr, targetStr, targetSkips) {
133 |       let searchIdx = 0;
134 |       const searchLen = searchStr.length;
135 |       /** @type {number[]} */
136 |       const ranges = [];
137 | 
138 |       for (let skipLen = targetSkips.length - 1; skipIdx < skipLen; ++skipIdx) {
139 |         const startIdx = targetSkips[skipIdx];
140 |         const endIdx = targetSkips[skipIdx + 1];
141 |         let targetIdx = startIdx;
142 |         let matchLen = 0;
143 | 
144 |         while (targetIdx < endIdx && searchIdx < searchLen) {
145 |           const targetChar = targetStr[targetIdx];
146 |           const searchChar = searchStr[searchIdx];
147 | 
148 |           if (targetChar === searchChar) {
149 |             ++targetIdx;
150 |             ++searchIdx;
151 |             ++matchLen;
152 |             continue;
153 |           }
154 | 
155 |           // spaces shouldn't break matching
156 |           if (targetChar === ` `) {
157 |             ++targetIdx;
158 |             continue;
159 |           }
160 |           if (searchChar === ` `) {
161 |             ++searchIdx;
162 |             continue;
163 |           }
164 | 
165 |           break;
166 |         }
167 | 
168 |         if (matchLen) {
169 |           // make contiguous ranges if possible
170 |           const rangesLen = ranges.length;
171 |           if (rangesLen >= 2 && ranges[rangesLen - 2] + ranges[rangesLen - 1] === startIdx) {
172 |             ranges[rangesLen - 1] += matchLen;
173 |           } else {
174 |             ranges.push(startIdx, matchLen);
175 |           }
176 |         }
177 | 
178 |         if (searchIdx === searchLen) {
179 |           // search is fully matched, return ranges
180 |           return ranges;
181 |         }
182 |       }
183 | 
184 |       return null;
185 |     }
186 | 
187 |     /**
188 |      * Returns the string parts for highlighting from the matched ranges
189 |      * @example ('my example', [3, 2]) would return ['my ', 'ex', 'ample']
190 |      * @param {string} targetStr - the string that was matched
191 |      * @param {number[]} ranges - [idx1, len1, idx2, len2] matched ranges
192 |      * @returns {string[]} - ['no match', 'match', 'no match', 'match']
193 |      */
194 |     function highlightsFromRanges(targetStr, ranges) {
195 |       const highlights = [];
196 |       let lastIndex = 0;
197 |       let rangesIdx = 0;
198 | 
199 |       for (; rangesIdx < ranges.length; rangesIdx += 2) {
200 |         const startIndex = ranges[rangesIdx];
201 |         const endIndex = startIndex + ranges[rangesIdx + 1];
202 |         highlights.push(targetStr.slice(lastIndex, startIndex));
203 |         highlights.push(targetStr.slice(startIndex, endIndex));
204 |         lastIndex = endIndex;
205 |       }
206 | 
207 |       if (lastIndex < targetStr.length) {
208 |         highlights.push(targetStr.slice(lastIndex));
209 |       }
210 | 
211 |       return highlights;
212 |     }
213 | 
214 |     /**
215 |      * fuzzyScoreItem is called by fuzzyMatch, it's a slightly lower level call
216 |      * If perf is of importance and you want to avoid lowercase + trim + highlighting on every item
217 |      * Use this and only call highlightsFromRanges for only the items that are displayed
218 |      * @param {string} targetStr - lowercased trimmed target string to search on
219 |      * @param {string} searchStr - lowercased trimmed search string
220 |      * @returns {{score: number, ranges: number[]} | null} - null if no match
221 |      */
222 |     function fuzzyScoreItem(targetStr, searchStr) {
223 |       if (!targetStr) {
224 |         return null;
225 |       }
226 | 
227 |       // empty search string is technically a match of nothing
228 |       if (!searchStr) {
229 |         return {
230 |           score: 0,
231 |           ranges: [],
232 |         };
233 |       }
234 | 
235 |       // if user enters a quoted search then only perform substring match
236 |       // e.g "la matches [{La}s Vegas] but not [Los Angeles]
237 |       // NOTE: ending quote is optional so user can get incremental matching as they type.
238 |       const isQuotedSearchStr = searchStr[0] === '"';
239 |       if (isQuotedSearchStr) {
240 |         searchStr = searchStr.slice(1, searchStr.endsWith(`"`) ? -1 : searchStr.length);
241 |       }
242 | 
243 |       // try substring search first
244 |       // js engine uses boyer moore algo which is very fast O(m/n)
245 |       const lCaseTargetStr = targetStr.toLowerCase();
246 |       const matchIdx = lCaseTargetStr.indexOf(searchStr);
247 |       const searchLen = searchStr.length;
248 | 
249 |       if (matchIdx >= 0) {
250 |         const isWordPrefix = matchIdx > 0 && !_isCodeAlphaNum(targetStr.charCodeAt(matchIdx - 1));
251 |         return {
252 |           score: _getMatchScore(matchIdx, searchLen, isWordPrefix),
253 |           ranges: [matchIdx, searchLen],
254 |         };
255 |       }
256 | 
257 |       // if we didn't match a single character as a substr, we won't fuzzy match it either, exit early.
258 |       // if quoted search, exit after substring search as well, since user doesn't want fuzzy search.
259 |       if (searchLen === 1 || isQuotedSearchStr) {
260 |         return null;
261 |       }
262 | 
263 |       // fall back to fuzzy matching which matches word prefixes or punctuations
264 |       // because we've precomputed targetSkips, its O(m+n) for avg case
265 |       // the skip array helps us make faster alignments, rather than letter by letter
266 |       const targetSkips = _getTargetSkips(targetStr);
267 | 
268 |       for (let skipIdx = 0, skipLen = targetSkips.length - 1; skipIdx < skipLen; ++skipIdx) {
269 |         if (lCaseTargetStr[targetSkips[skipIdx]] === searchStr[0]) {
270 |           // possible alignment, perform prefix match
271 |           const ranges = _fuzzyPrefixMatch(skipIdx, searchStr, lCaseTargetStr, targetSkips);
272 |           if (ranges) {
273 |             let score = 0;
274 |             for (let i = 0, len = ranges.length; i < len; i += 2) {
275 |               score += _getMatchScore(ranges[i], ranges[i + 1], true /*isWordPrefix*/);
276 |             }
277 |             return {score, ranges};
278 |           }
279 |         }
280 |       }
281 | 
282 |       return null;
283 |     }
284 | 
285 |     /**
286 |      * Fuzzy match and return the score, highlights, and lowercased matchStr (for sort)
287 |      * @param {string} targetStr - target to search on / haystack string
288 |      * @param {string} searchStr - search filter / needle string
289 |      * @returns {{score: number, highlights: string[]} | null} - null if no match
290 |      */
291 |     function fuzzyMatch(targetStr, searchStr) {
292 |       targetStr = targetStr || ``;
293 |       searchStr = (searchStr || ``).trim().toLowerCase();
294 |       const match = fuzzyScoreItem(targetStr, searchStr);
295 | 
296 |       if (match) {
297 |         return {
298 |           score: match.score,
299 |           highlights: highlightsFromRanges(targetStr, match.ranges),
300 |         };
301 |       }
302 | 
303 |       return null;
304 |     }
305 | 
306 |     /**
307 |      * @template Item
308 |      * @typedef {{item: Item, score: number, highlights: {[K in keyof Item]?: string[]}}} FuzzyFilterResult
309 |      */
310 | 
311 |     /**
312 |      * Searches an array of items on props and returns filtered + sorted array with scores and highlights
313 |      * @template Item
314 |      * @param {Item[]} items
315 |      * @param {string} searchStr
316 |      * @param {{fields: (keyof Item)[]}} options
317 |      * @returns {FuzzyFilterResult[]}
318 |      */
319 |     function fuzzyFilter(items, searchStr, options) {
320 |       /** @type {FuzzyFilterResult[]} */
321 |       const results = [];
322 |       const searchStrLowerCased = (searchStr || ``).trim().toLowerCase();
323 |       const fields = options ? options.fields : null;
324 |       if (!fields || !Array.isArray(fields) || fields.length == 0) {
325 |         throw new Error(`invalid fields, did you forget to pass {fields: [...]} as options param?`);
326 |       }
327 | 
328 |       for (const item of items) {
329 |         /** @type {FuzzyFilterResult | null} */
330 |         let result = null;
331 |         for (const field of fields) {
332 |           const value = item[field];
333 |           if (typeof value === `string` && value) {
334 |             const match = fuzzyScoreItem(value, searchStrLowerCased);
335 |             if (match) {
336 |               result = result || {item, score: 0, highlights: {}};
337 |               result.score = Math.max(match.score, result.score);
338 |               result.highlights[field] = highlightsFromRanges(value, match.ranges);
339 |             }
340 |           }
341 |         }
342 |         if (result) {
343 |           results.push(result);
344 |         }
345 |       }
346 | 
347 |       // sort if searchStr is not empty, otherwise preserve original order, since its a pass through
348 |       if (searchStrLowerCased) {
349 |         results.sort((a, b) => {
350 |           // sort by score, then alphabetically by each field
351 |           let diff = b.score - a.score;
352 |           for (let i = 0, len = fields.length; diff === 0 && i < len; ++i) {
353 |             const field = fields[i];
354 |             const valA = a.item[field];
355 |             const valB = b.item[field];
356 |             // @ts-ignore string comparison
357 |             diff = (valA || ``).localeCompare(valB);
358 |           }
359 |           return diff;
360 |         });
361 |       }
362 | 
363 |       return results;
364 |     }
365 | 
366 |     exports.fuzzyFilter = fuzzyFilter;
367 |     exports.fuzzyMatch = fuzzyMatch;
368 |     exports.fuzzyScoreItem = fuzzyScoreItem;
369 |     exports.highlightsFromRanges = highlightsFromRanges;
370 | 
371 |     return exports;
372 | 
373 |   })({});


--------------------------------------------------------------------------------
/demos/lib/fuzzy-min.js:
--------------------------------------------------------------------------------
1 | (function(){var root=this;var fuzzy={};if(typeof exports!=="undefined"){module.exports=fuzzy}else{root.fuzzy=fuzzy}fuzzy.simpleFilter=function(pattern,array){return array.filter(function(str){return fuzzy.test(pattern,str)})};fuzzy.test=function(pattern,str){return fuzzy.match(pattern,str)!==null};fuzzy.match=function(pattern,str,opts){opts=opts||{};var patternIdx=0,result=[],len=str.length,totalScore=0,currScore=0,pre=opts.pre||"",post=opts.post||"",compareString=opts.caseSensitive&&str||str.toLowerCase(),ch;pattern=opts.caseSensitive&&pattern||pattern.toLowerCase();for(var idx=0;idx Object.assign(R, { [el]: 1 }), {})
 49 |         : isObject(fields)
 50 |           ? fields
 51 |           : { [fields]: 1 }
 52 |     ).map(([k, rate]) => ({
 53 |       rate: parseFloat(rate) || 1,
 54 |       field: k,
 55 |       path: k
 56 |     }));
 57 |     if (fieldsList.length == 0) return null;
 58 |     return (value) => {
 59 |       if (isString(fields)) return getValue(value, fields);
 60 |       return fieldsList.reduce(
 61 |         (R, el) => Object.assign(
 62 |           R,
 63 |           { [el.field]: el.rate === 1
 64 |             ? getValue(value, el.path)
 65 |             : { ...el, value: getValue(value, el.path) }
 66 |           }
 67 |         ),
 68 |         {}
 69 |       );
 70 |     };
 71 |   }
 72 | 
 73 |   function getRegExpWithFrom(reg, from = undefined) {
 74 |     return new RegExp(`(.{${from && from > 0 ? from : 0},}?)(${reg.source})`, reg.flags);
 75 |   }
 76 | 
 77 |   function searchIn(where, what, from = undefined) {
 78 |     const isRegExp = what instanceof RegExp;
 79 |     if (isRegExp) {
 80 |       const regExpWithFrom = getRegExpWithFrom(what, from);
 81 |       const { 1: before = false, 2: found = '' } = regExpWithFrom.exec(where) || {};
 82 |       if (!found) return [-1, ''];
 83 |       return [before.length, found];
 84 |     }
 85 |     const start = where.indexOf(what, from);
 86 |     return [start, start >= 0 ? what : ''];
 87 |   }
 88 | 
 89 |   function computeScore(begin, end, fullLength, wordNumber) {
 90 |     const wordLen = end - begin + 1;
 91 |     const kd = (1 / fullLength) * wordLen;
 92 |     const kp = begin || 0.001;
 93 |     const kw = 1 + (1 / fullLength) * wordNumber;
 94 |     return kd * kp * kw;
 95 |   }
 96 | 
 97 |   function matchString(what, where, options) {
 98 |     if (!what || !where) return null;
 99 |     const {
100 |       caseSensitive,
101 |       withScore,
102 |       withWrapper,
103 |       withRanges
104 |     } = defaultOptions(options);
105 |     const isWords = Array.isArray(what);
106 |     if (isWords && what.length == 0) return null;
107 | 
108 |     const preparedWhat = caseSensitive
109 |       ? (isWords ? what : String(what))
110 |       : (
111 |         isWords
112 |           ? what.map(it => (isRegExp(it) ? it : String(it).toLocaleLowerCase()))
113 |           : String(what).toLocaleLowerCase()
114 |       );
115 |     const originalWhere = String(where);
116 |     if (!preparedWhat || !originalWhere || (!isWords && preparedWhat.length > originalWhere.length)) {
117 |       return null;
118 |     }
119 |     // preparedWhere will be undefined if caseSensitive is true, it is needed to save memory
120 |     const preparedWhere = caseSensitive ? undefined : originalWhere.toLocaleLowerCase();
121 | 
122 |     let wrapped = null;
123 |     let ranges = null;
124 |     let chunkBegin = 0;
125 |     let scoreList = [];
126 |     const wrapperFunc =
127 |       !withWrapper || isFunction(withWrapper)
128 |         ? withWrapper
129 |         : (w) => withWrapper.replace('{?}', w);
130 | 
131 |     const wordAction = (prev, next) => {
132 |       if (prev < 0) {
133 |         if (withWrapper) {
134 |           wrapped = next > 0 ? originalWhere.slice(0, next) : '';
135 |         }
136 |         if (withRanges) {
137 |           ranges = [];
138 |         }
139 |         chunkBegin = next;
140 |       } else if (next - prev > 1) {
141 |         if (withWrapper) {
142 |           const chunk = originalWhere.slice(chunkBegin, prev + 1);
143 |           wrapped += wrapperFunc(chunk) + originalWhere.slice(prev + 1, next);
144 |         }
145 |         if (withRanges) {
146 |           ranges.push({
147 |             begin: chunkBegin,
148 |             end: Math.min(prev, originalWhere.length - 1)
149 |           });
150 |         }
151 |         if (withScore) {
152 |           scoreList.push(
153 |             computeScore(chunkBegin, prev, preparedWhat.length, scoreList.length)
154 |           );
155 |         }
156 |         chunkBegin = next;
157 |       }
158 |     };
159 | 
160 |     let pos = -1;
161 |     for (let i = 0; i < preparedWhat.length; i++) {
162 |       const chunk = isWords ? preparedWhat[i] : preparedWhat.charAt(i);
163 |       let [nextPos, found] = searchIn(preparedWhere || originalWhere, chunk, pos + 1);
164 | 
165 |       if (nextPos < 0) return null;
166 | 
167 |       if (isWords && found.length > 1) {
168 |         wordAction(pos, nextPos);
169 |         nextPos = nextPos + found.length - 1;
170 |         pos = nextPos - 1;
171 |       }
172 |       wordAction(pos, nextPos);
173 |       pos = nextPos;
174 |     }
175 |     wordAction(pos, pos + originalWhere.length);
176 | 
177 |     return Object.assign(
178 |       {
179 |         score: withScore
180 |           ? scoreList.reduce((p, c) => p + c, 0)
181 |           : 1
182 |       },
183 |       withWrapper ? { wrapped } : {},
184 |       withRanges ? { ranges } : {}
185 |     );
186 |   }
187 | 
188 |   function isValidRate(rate) {
189 |     const result = rate == null || (rate > 0 && rate <= 1);
190 |     if (!result) {
191 |       console.warn(
192 |         'fuzzy-tools',
193 |         'rate should be `> 0` and `<= 1`, another value will be ignored. Current value: ',
194 |         rate
195 |       );
196 |     }
197 |     return result;
198 |   }
199 | 
200 |   function matchList(what, whereList, options) {
201 |     const isArray = Array.isArray(whereList);
202 |     if (
203 |       !what ||
204 |       !whereList ||
205 |       (!isArray && !isObject(whereList)) ||
206 |       whereList.length == 0
207 |     ) {
208 |       return null;
209 |     }
210 | 
211 |     const { withScore, rates } = defaultOptions(options);
212 |     const results = Object.entries(whereList).reduce((R, [key, el]) => {
213 |       const realKey = isArray ? Number(key) : key;
214 |       const elValue = !el || isString(el) ? el : el.value;
215 |       const elRate = el && isObject(el) && Object.prototype.hasOwnProperty.call(el, 'rate') && isValidRate(el.rate)
216 |         ? el.rate
217 |         : (rates && rates[realKey] != null && isValidRate(rates[realKey]) ? rates[realKey] : null);
218 | 
219 |       const result = matchString(what, elValue, options);
220 |       if (result) {
221 |         R[realKey] = Object.assign(
222 |           result,
223 |           { original: elValue, index: realKey },
224 |           elRate == null
225 |             ? {}
226 |             : { score: result.score / elRate, rate: elRate }
227 |         );
228 |       }
229 |       return R;
230 |     }, {});
231 | 
232 |     if (Object.values(results).length === 0) return null;
233 |     if (!withScore) return { score: 1, matches: results };
234 | 
235 |     const values = Object.values(results);
236 |     return values.reduce(
237 |       (R, el) => {
238 |         R.score = Math.min(R.score, el.score);
239 |         return R;
240 |       },
241 |       { score: Number.POSITIVE_INFINITY, matches: results }
242 |     );
243 |   }
244 | 
245 |   function match(what, where, options) {
246 |     if (!what || !where) {
247 |       return null;
248 |     }
249 |     return Array.isArray(where) || isObject(where)
250 |       ? matchList(what, where, options)
251 |       : matchString(what, where, options);
252 |   }
253 | 
254 |   function filter(what, dataList, options) {
255 |     if (!what || !dataList || !Array.isArray(dataList)) {
256 |       return [];
257 |     }
258 |     const { extract, itemWrapper } = defaultOptions(options);
259 |     const extractFunc =
260 |       !extract || isFunction(extract) ? extract : getDataExtractor(extract);
261 | 
262 |     return dataList.reduce((R, row, i) => {
263 |       const data = extract ? extractFunc(row) : row;
264 |       const fuzzyResult = match(what, data, options);
265 |       if (fuzzyResult) {
266 |         const el = itemWrapper
267 |           ? itemWrapper(row, fuzzyResult, { index: i, result: R })
268 |           : row;
269 |         if (el) {
270 |           R.push(el);
271 |         }
272 |       }
273 |       return R;
274 |     }, []);
275 |   }
276 | 
277 |   exports.filter = filter;
278 |   exports.match = match;
279 |   exports.matchList = matchList;
280 |   exports.matchString = matchString;
281 | 
282 |   return exports;
283 | 
284 | })({});
285 | 


--------------------------------------------------------------------------------
/demos/lib/fuzzyMatch.js:
--------------------------------------------------------------------------------
 1 | /**
 2 |  * Attempts to do a partial input search, e.g. allowing to search for a text (needle)
 3 |  * in another text (stack) by skipping some letters in-between. All letters from
 4 |  * the needle must exist in the stack in the same order to find a match.
 5 |  *
 6 |  * The search is case sensitive. Convert stack and needle to lower case
 7 |  * to make it case insensitive.
 8 |  *
 9 |  * @param stack - main text to be searched
10 |  * @param needle - partial text to find in the stack
11 |  *
12 |  * @internal
13 |  */
14 | function fuzzyMatch(stack, needle) {
15 | 	let distance = 0,
16 | 		searchIndex = stack.indexOf(needle);
17 | 	// Remove whitespace from needle as a temporary solution to treat separate string
18 | 	// queries as 'AND'
19 | 	needle = needle.replace(/\s/g, '');
20 | 
21 | 	const ranges = [];
22 | 
23 | 	if (searchIndex !== -1) {
24 | 		return {
25 | 			distance: 0,
26 | 			found: true,
27 | 			ranges: [{ start: searchIndex, end: searchIndex + needle.length - 1 }],
28 | 		};
29 | 	}
30 | 
31 | 	for (const letter of needle) {
32 | 		const letterIndex = stack.indexOf(letter, searchIndex);
33 | 
34 | 		if (letterIndex === -1) {
35 | 			return {
36 | 				distance: Infinity,
37 | 				ranges: [],
38 | 				found: false
39 | 			};
40 | 		}
41 | 		// do not cumulate the distance if it's the first letter
42 | 		if (searchIndex !== -1) {
43 | 			distance += letterIndex - searchIndex;
44 | 		}
45 | 		searchIndex = letterIndex + 1;
46 | 
47 | 		if (ranges.length === 0) {
48 | 			ranges.push({ start: letterIndex, end: letterIndex });
49 | 		} else {
50 | 			const lastRange = ranges[ranges.length - 1];
51 | 			if (letterIndex === lastRange.end + 1) {
52 | 				lastRange.end++;
53 | 			} else {
54 | 				ranges.push({ start: letterIndex, end: letterIndex });
55 | 			}
56 | 		}
57 | 	}
58 | 
59 | 	return {
60 | 		distance: distance,
61 | 		ranges,
62 | 		found: true,
63 | 	};
64 | }


--------------------------------------------------------------------------------
/demos/lib/fuzzysearch.js:
--------------------------------------------------------------------------------
 1 | // https://github.com/bevacqua/fuzzysearch
 2 | function fuzzysearch(needle, haystack) {
 3 |   var hlen = haystack.length;
 4 |   var nlen = needle.length;
 5 |   if (nlen > hlen) {
 6 |     return false;
 7 |   }
 8 |   if (nlen === hlen) {
 9 |     return needle === haystack;
10 |   }
11 |   outer: for (var i = 0, j = 0; i < nlen; i++) {
12 |     var nch = needle.charCodeAt(i);
13 |     while (j < hlen) {
14 |       if (haystack.charCodeAt(j++) === nch) {
15 |         continue outer;
16 |       }
17 |     }
18 |     return false;
19 |   }
20 |   return true;
21 | }
22 | 


--------------------------------------------------------------------------------
/demos/lib/fuzzyset.js:
--------------------------------------------------------------------------------
  1 | var FuzzySet = (function () {
  2 |   'use strict';
  3 | 
  4 |   const FuzzySet = function(arr, useLevenshtein, gramSizeLower, gramSizeUpper) {
  5 |       var fuzzyset = {
  6 | 
  7 |       };
  8 | 
  9 |       // default options
 10 |       arr = arr || [];
 11 |       fuzzyset.gramSizeLower = gramSizeLower || 2;
 12 |       fuzzyset.gramSizeUpper = gramSizeUpper || 3;
 13 |       fuzzyset.useLevenshtein = (typeof useLevenshtein !== 'boolean') ? true : useLevenshtein;
 14 | 
 15 |       // define all the object functions and attributes
 16 |       fuzzyset.exactSet = {};
 17 |       fuzzyset.matchDict = {};
 18 |       fuzzyset.items = {};
 19 | 
 20 |       // helper functions
 21 |       var levenshtein = function(str1, str2) {
 22 |           var current = [], prev, value;
 23 | 
 24 |           for (var i = 0; i <= str2.length; i++)
 25 |               for (var j = 0; j <= str1.length; j++) {
 26 |               if (i && j)
 27 |                   if (str1.charAt(j - 1) === str2.charAt(i - 1))
 28 |                   value = prev;
 29 |                   else
 30 |                   value = Math.min(current[j], current[j - 1], prev) + 1;
 31 |               else
 32 |                   value = i + j;
 33 | 
 34 |               prev = current[j];
 35 |               current[j] = value;
 36 |               }
 37 | 
 38 |           return current.pop();
 39 |       };
 40 | 
 41 |       // return an edit distance from 0 to 1
 42 |       var _distance = function(str1, str2) {
 43 |           if (str1 === null && str2 === null) throw 'Trying to compare two null values';
 44 |           if (str1 === null || str2 === null) return 0;
 45 |           str1 = String(str1); str2 = String(str2);
 46 | 
 47 |           var distance = levenshtein(str1, str2);
 48 |           if (str1.length > str2.length) {
 49 |               return 1 - distance / str1.length;
 50 |           } else {
 51 |               return 1 - distance / str2.length;
 52 |           }
 53 |       };
 54 | 
 55 |       // u00C0-u00FF is latin characters
 56 |       // u0621-u064a is arabic letters
 57 |       // u0660-u0669 is arabic numerals
 58 |       // TODO: figure out way to do this for more languages
 59 |       var _nonWordRe = /[^a-zA-Z0-9\u00C0-\u00FF\u0621-\u064A\u0660-\u0669, ]+/g;
 60 | 
 61 |       var _iterateGrams = function(value, gramSize) {
 62 |           gramSize = gramSize || 2;
 63 |           var simplified = '-' + value.toLowerCase().replace(_nonWordRe, '') + '-',
 64 |               lenDiff = gramSize - simplified.length,
 65 |               results = [];
 66 |           if (lenDiff > 0) {
 67 |               for (var i = 0; i < lenDiff; ++i) {
 68 |                   simplified += '-';
 69 |               }
 70 |           }
 71 |           for (var i = 0; i < simplified.length - gramSize + 1; ++i) {
 72 |               results.push(simplified.slice(i, i + gramSize));
 73 |           }
 74 |           return results;
 75 |       };
 76 | 
 77 |       var _gramCounter = function(value, gramSize) {
 78 |           // return an object where key=gram, value=number of occurrences
 79 |           gramSize = gramSize || 2;
 80 |           var result = {},
 81 |               grams = _iterateGrams(value, gramSize),
 82 |               i = 0;
 83 |           for (i; i < grams.length; ++i) {
 84 |               if (grams[i] in result) {
 85 |                   result[grams[i]] += 1;
 86 |               } else {
 87 |                   result[grams[i]] = 1;
 88 |               }
 89 |           }
 90 |           return result;
 91 |       };
 92 | 
 93 |       // the main functions
 94 |       fuzzyset.get = function(value, defaultValue, minMatchScore) {
 95 |           // check for value in set, returning defaultValue or null if none found
 96 |           if (minMatchScore === undefined) {
 97 |               minMatchScore = .33;
 98 |           }
 99 |           var result = this._get(value, minMatchScore);
100 |           if (!result && typeof defaultValue !== 'undefined') {
101 |               return defaultValue;
102 |           }
103 |           return result;
104 |       };
105 | 
106 |       fuzzyset._get = function(value, minMatchScore) {
107 |           var results = [];
108 |           // start with high gram size and if there are no results, go to lower gram sizes
109 |           for (var gramSize = this.gramSizeUpper; gramSize >= this.gramSizeLower; --gramSize) {
110 |               results = this.__get(value, gramSize, minMatchScore);
111 |               if (results && results.length > 0) {
112 |                   return results;
113 |               }
114 |           }
115 |           return null;
116 |       };
117 | 
118 |       fuzzyset.__get = function(value, gramSize, minMatchScore) {
119 |           var normalizedValue = this._normalizeStr(value),
120 |               matches = {},
121 |               gramCounts = _gramCounter(normalizedValue, gramSize),
122 |               items = this.items[gramSize],
123 |               sumOfSquareGramCounts = 0,
124 |               gram,
125 |               gramCount,
126 |               i,
127 |               index,
128 |               otherGramCount;
129 | 
130 |           for (gram in gramCounts) {
131 |               gramCount = gramCounts[gram];
132 |               sumOfSquareGramCounts += Math.pow(gramCount, 2);
133 |               if (gram in this.matchDict) {
134 |                   for (i = 0; i < this.matchDict[gram].length; ++i) {
135 |                       index = this.matchDict[gram][i][0];
136 |                       otherGramCount = this.matchDict[gram][i][1];
137 |                       if (index in matches) {
138 |                           matches[index] += gramCount * otherGramCount;
139 |                       } else {
140 |                           matches[index] = gramCount * otherGramCount;
141 |                       }
142 |                   }
143 |               }
144 |           }
145 | 
146 |           function isEmptyObject(obj) {
147 |               for(var prop in obj) {
148 |                   if(obj.hasOwnProperty(prop))
149 |                       return false;
150 |               }
151 |               return true;
152 |           }
153 | 
154 |           if (isEmptyObject(matches)) {
155 |               return null;
156 |           }
157 | 
158 |           var vectorNormal = Math.sqrt(sumOfSquareGramCounts),
159 |               results = [],
160 |               matchScore;
161 |           // build a results list of [score, str]
162 |           for (var matchIndex in matches) {
163 |               matchScore = matches[matchIndex];
164 |               results.push([matchScore / (vectorNormal * items[matchIndex][0]), items[matchIndex][1]]);
165 |           }
166 |           var sortDescending = function(a, b) {
167 |               if (a[0] < b[0]) {
168 |                   return 1;
169 |               } else if (a[0] > b[0]) {
170 |                   return -1;
171 |               } else {
172 |                   return 0;
173 |               }
174 |           };
175 |           results.sort(sortDescending);
176 |           if (this.useLevenshtein) {
177 |               var newResults = [],
178 |                   endIndex = Math.min(50, results.length);
179 |               // truncate somewhat arbitrarily to 50
180 |               for (var i = 0; i < endIndex; ++i) {
181 |                   newResults.push([_distance(results[i][1], normalizedValue), results[i][1]]);
182 |               }
183 |               results = newResults;
184 |               results.sort(sortDescending);
185 |           }
186 |           newResults = [];
187 |           results.forEach(function(scoreWordPair) {
188 |               if (scoreWordPair[0] >= minMatchScore) {
189 |                   newResults.push([scoreWordPair[0], this.exactSet[scoreWordPair[1]]]);
190 |               }
191 |           }.bind(this));
192 |           return newResults;
193 |       };
194 | 
195 |       fuzzyset.add = function(value) {
196 |           var normalizedValue = this._normalizeStr(value);
197 |           if (normalizedValue in this.exactSet) {
198 |               return false;
199 |           }
200 | 
201 |           var i = this.gramSizeLower;
202 |           for (i; i < this.gramSizeUpper + 1; ++i) {
203 |               this._add(value, i);
204 |           }
205 |       };
206 | 
207 |       fuzzyset._add = function(value, gramSize) {
208 |           var normalizedValue = this._normalizeStr(value),
209 |               items = this.items[gramSize] || [],
210 |               index = items.length;
211 | 
212 |           items.push(0);
213 |           var gramCounts = _gramCounter(normalizedValue, gramSize),
214 |               sumOfSquareGramCounts = 0,
215 |               gram, gramCount;
216 |           for (gram in gramCounts) {
217 |               gramCount = gramCounts[gram];
218 |               sumOfSquareGramCounts += Math.pow(gramCount, 2);
219 |               if (gram in this.matchDict) {
220 |                   this.matchDict[gram].push([index, gramCount]);
221 |               } else {
222 |                   this.matchDict[gram] = [[index, gramCount]];
223 |               }
224 |           }
225 |           var vectorNormal = Math.sqrt(sumOfSquareGramCounts);
226 |           items[index] = [vectorNormal, normalizedValue];
227 |           this.items[gramSize] = items;
228 |           this.exactSet[normalizedValue] = value;
229 |       };
230 | 
231 |       fuzzyset._normalizeStr = function(str) {
232 |           if (Object.prototype.toString.call(str) !== '[object String]') throw 'Must use a string as argument to FuzzySet functions';
233 |           return str.toLowerCase();
234 |       };
235 | 
236 |       // return length of items in set
237 |       fuzzyset.length = function() {
238 |           var count = 0,
239 |               prop;
240 |           for (prop in this.exactSet) {
241 |               if (this.exactSet.hasOwnProperty(prop)) {
242 |                   count += 1;
243 |               }
244 |           }
245 |           return count;
246 |       };
247 | 
248 |       // return is set is empty
249 |       fuzzyset.isEmpty = function() {
250 |           for (var prop in this.exactSet) {
251 |               if (this.exactSet.hasOwnProperty(prop)) {
252 |                   return false;
253 |               }
254 |           }
255 |           return true;
256 |       };
257 | 
258 |       // return list of values loaded into set
259 |       fuzzyset.values = function() {
260 |           var values = [],
261 |               prop;
262 |           for (prop in this.exactSet) {
263 |               if (this.exactSet.hasOwnProperty(prop)) {
264 |                   values.push(this.exactSet[prop]);
265 |               }
266 |           }
267 |           return values;
268 |       };
269 | 
270 | 
271 |       // initialization
272 |       var i = fuzzyset.gramSizeLower;
273 |       for (i; i < fuzzyset.gramSizeUpper + 1; ++i) {
274 |           fuzzyset.items[i] = [];
275 |       }
276 |       // add all the items to the set
277 |       for (i = 0; i < arr.length; ++i) {
278 |           fuzzyset.add(arr[i]);
279 |       }
280 | 
281 |       return fuzzyset;
282 |   };
283 | 
284 |   return FuzzySet;
285 | 
286 | }());
287 | 


--------------------------------------------------------------------------------
/demos/lib/fuzzysort.min.js:
--------------------------------------------------------------------------------
1 | // https://github.com/farzher/fuzzysort v2.0.4
2 | var e,r;e=this,r=e=>{var r=(e,r)=>{if(e===L)return L;var t=e.target,n=t.length,a=e._indexes;a=a.slice(0,a.len).sort(((e,r)=>e-r));for(var o="",s=0,i=0,f=!1,l=(e=[],0);l{"string"!=typeof e&&(e="");var r=l(e);return{target:e,_targetLower:r._lower,_targetLowerCodes:r.lowerCodes,_nextBeginningIndexes:L,_bitflags:r.bitflags,score:L,_indexes:[0],obj:L}},n=e=>{"string"!=typeof e&&(e=""),e=e.trim();var r=l(e),t=[];if(r.containsSpace){var n=e.split(/\s+/);n=[...new Set(n)];for(var a=0;a{if(e.length>999)return t(e);var r=v.get(e);return void 0!==r||(r=t(e),v.set(e,r)),r},o=e=>{if(e.length>999)return n(e);var r=d.get(e);return void 0!==r||(r=n(e),d.set(e,r)),r},s=(e,r,t)=>{var n=[];n.total=r.length;var o=t&&t.limit||x;if(t&&t.key)for(var s=0;s=o)return n}}else if(t&&t.keys)for(s=0;s=0;--g)(v=_(i,t.keys[g]))?(p(v)||(v=a(v)),v.score=w,v._indexes.len=0,l[g]=v):l[g]=L;if(l.obj=i,l.score=w,n.push(l),n.length>=o)return n}else for(s=0;s=o))return n}return n},i=(e,r,t=!1)=>{if(!1===t&&e.containsSpace)return f(e,r);for(var n=e._lower,a=e.lowerCodes,o=a[0],s=r._targetLowerCodes,i=a.length,l=s.length,v=0,d=0,h=0;;){if(o===s[d]){if(c[h++]=d,++v===i)break;o=a[v]}if(++d>=l)return L}v=0;var _=!1,p=0,x=r._nextBeginningIndexes;x===L&&(x=r._nextBeginningIndexes=g(r.target)),d=0===c[0]?0:x[c[0]-1];var w=0;if(d!==l)for(;;)if(d>=l){if(v<=0)break;if(++w>200)break;--v,d=x[u[--p]]}else if(a[v]===s[d]){if(u[p++]=d,++v===i){_=!0;break}++d}else d=x[d];var b=r._targetLower.indexOf(n,c[0]),y=~b;if(y&&!_)for(var k=0;k24&&(m*=10*(z-24))}else m*=1e3;for(y&&(m/=1+i*i*1),C&&(m/=1+i*i*1),m-=l-i,r.score=m,k=0;k{for(var t=new Set,n=0,a=L,o=0,s=e.spaceSearches,f=0;fn)return v;a.score=n,f=0;for(let e of t)a._indexes[f++]=e;return a._indexes.len=f,a},l=e=>{for(var r=e.length,t=e.toLowerCase(),n=[],a=0,o=!1,s=0;s=97&&i<=122?i-97:i>=48&&i<=57?26:i<=127?30:31):o=!0}return{lowerCodes:n,bitflags:a,containsSpace:o,_lower:t}},g=e=>{for(var r=e.length,t=(e=>{for(var r=e.length,t=[],n=0,a=!1,o=!1,s=0;s=65&&i<=90,l=f||i>=97&&i<=122||i>=48&&i<=57,g=f&&!a||!o||!l;a=f,o=l,g&&(t[n++]=s)}return t})(e),n=[],a=t[0],o=0,s=0;ss?n[s]=a:(a=t[++o],n[s]=void 0===a?r:a);return n},v=new Map,d=new Map,c=[],u=[],h=e=>{for(var r=w,t=e.length,n=0;nr&&(r=o)}}return r===w?L:r},_=(e,r)=>{var t=e[r];if(void 0!==t)return t;var n=r;Array.isArray(r)||(n=r.split("."));for(var a=n.length,o=-1;e&&++o"object"==typeof e,x=1/0,w=-x,b=[];b.total=0;var y,k,C,S,L=null,j=(y=[],k=0,S=e=>{for(var r=0,t=y[r],n=1;n>1]=y[r],n=1+(r<<1)}for(var o=r-1>>1;r>0&&t.score>1)y[r]=y[o];y[r]=t},(C={}).add=e=>{var r=k;y[k++]=e;for(var t=r-1>>1;r>0&&e.score>1)y[r]=y[t];y[r]=e},C.poll=e=>{if(0!==k){var r=y[0];return y[0]=y[--k],S(),r}},C.peek=e=>{if(0!==k)return y[0]},C.replaceTop=e=>{y[0]=e,S()},C);return{single:(e,r)=>{if("farzher"==e)return{target:"farzher was here (^-^*)/",score:0,_indexes:[0]};if(!e||!r)return L;var t=o(e);p(r)||(r=a(r));var n=t.bitflags;return(n&r._bitflags)!==n?L:i(t,r)},go:(e,r,t)=>{if("farzher"==e)return[{target:"farzher was here (^-^*)/",score:0,_indexes:[0],obj:r?r[0]:L}];if(!e)return t&&t.all?s(e,r,t):b;var n=o(e),f=n.bitflags,l=(n.containsSpace,t&&t.threshold||w),g=t&&t.limit||x,v=0,d=0,c=r.length;if(t&&t.key)for(var u=t.key,y=0;yj.peek().score&&j.replaceTop(T)))))}else if(t&&t.keys){var C=t.scoreFn||h,S=t.keys,m=S.length;for(y=0;yj.peek().score&&j.replaceTop(A))))}}else for(y=0;yj.peek().score&&j.replaceTop(T)))))}if(0===v)return b;var M=new Array(v);for(y=v-1;y>=0;--y)M[y]=j.poll();return M.total=v+d,M},highlight:(e,t,n)=>{if("function"==typeof t)return r(e,t);if(e===L)return L;void 0===t&&(t=""),void 0===n&&(n="");var a="",o=0,s=!1,i=e.target,f=i.length,l=e._indexes;l=l.slice(0,l.len).sort(((e,r)=>e-r));for(var g=0;ge._indexes.slice(0,e._indexes.len).sort(((e,r)=>e-r)),cleanup:()=>{v.clear(),d.clear(),c=[],u=[]}}},"function"==typeof define&&define.amd?define([],r):"object"==typeof module&&module.exports?module.exports=r():e.fuzzysort=r();


--------------------------------------------------------------------------------
/demos/lib/fzf.iife.min.js:
--------------------------------------------------------------------------------
 1 | /** @license
 2 |  * fzf v0.5.1
 3 |  * Copyright (c) 2021-2022 Ajit
 4 |  * Licensed under BSD 3-Clause
 5 |  */
 6 |  var Fzf = (function (exports) {
 7 | 	'use strict';
 8 | 
 9 | 	/** @license
10 | 	 * fzf v0.5.1
11 | 	 * Copyright (c) 2021-2022 Ajit
12 | 	 * Licensed under BSD 3-Clause
13 | 	 */
14 | 	const t={216:"O",223:"s",248:"o",273:"d",295:"h",305:"i",320:"l",322:"l",359:"t",383:"s",384:"b",385:"B",387:"b",390:"O",392:"c",393:"D",394:"D",396:"d",398:"E",400:"E",402:"f",403:"G",407:"I",409:"k",410:"l",412:"M",413:"N",414:"n",415:"O",421:"p",427:"t",429:"t",430:"T",434:"V",436:"y",438:"z",477:"e",485:"g",544:"N",545:"d",549:"z",564:"l",565:"n",566:"t",567:"j",570:"A",571:"C",572:"c",573:"L",574:"T",575:"s",576:"z",579:"B",580:"U",581:"V",582:"E",583:"e",584:"J",585:"j",586:"Q",587:"q",588:"R",589:"r",590:"Y",591:"y",592:"a",593:"a",595:"b",596:"o",597:"c",598:"d",599:"d",600:"e",603:"e",604:"e",605:"e",606:"e",607:"j",608:"g",609:"g",610:"G",613:"h",614:"h",616:"i",618:"I",619:"l",620:"l",621:"l",623:"m",624:"m",625:"m",626:"n",627:"n",628:"N",629:"o",633:"r",634:"r",635:"r",636:"r",637:"r",638:"r",639:"r",640:"R",641:"R",642:"s",647:"t",648:"t",649:"u",651:"v",652:"v",653:"w",654:"y",655:"Y",656:"z",657:"z",663:"c",665:"B",666:"e",667:"G",668:"H",669:"j",670:"k",671:"L",672:"q",686:"h",867:"a",868:"e",869:"i",870:"o",871:"u",872:"c",873:"d",874:"h",875:"m",876:"r",877:"t",878:"v",879:"x",7424:"A",7427:"B",7428:"C",7429:"D",7431:"E",7432:"e",7433:"i",7434:"J",7435:"K",7436:"L",7437:"M",7438:"N",7439:"O",7440:"O",7441:"o",7442:"o",7443:"o",7446:"o",7447:"o",7448:"P",7449:"R",7450:"R",7451:"T",7452:"U",7453:"u",7454:"u",7455:"m",7456:"V",7457:"W",7458:"Z",7522:"i",7523:"r",7524:"u",7525:"v",7834:"a",7835:"s",8305:"i",8341:"h",8342:"k",8343:"l",8344:"m",8345:"n",8346:"p",8347:"s",8348:"t",8580:"c"};for(let at="̀".codePointAt(0);at<="ͯ".codePointAt(0);++at){const e=String.fromCodePoint(at);for(const n of "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"){const r=(n+e).normalize().codePointAt(0);r>126&&(t[r]=n);}}const e={a:[7844,7863],e:[7870,7879],o:[7888,7907],u:[7912,7921]};for(const at of Object.keys(e)){const n=at.toUpperCase();for(let r=e[at][0];r<=e[at][1];++r)t[r]=r%2==0?n:at;}function n(e){if(e<192||e>8580)return e;const n=t[e];return void 0!==n?n.codePointAt(0):e}function r(t,e){return t>e?t:e}const s=t=>t.split("").map((t=>t.codePointAt(0))),o=t=>t.map((t=>String.fromCodePoint(t))).join(""),i=new Set(" \f\n\r\t\v  \u2028\u2029   \ufeff".split("").map((t=>t.codePointAt(0))));for(let at=" ".codePointAt(0);at<=" ".codePointAt(0);at++)i.add(at);const l=t=>i.has(t),c=t=>{let e=0;for(const n of t){if(!l(n))break;e++;}return e},a=t=>{let e=0;for(let n=t.length-1;n>=0&&l(t[n]);n--)e++;return e},u="".codePointAt(0),f="A".codePointAt(0),h="Z".codePointAt(0),d="a".codePointAt(0),g="z".codePointAt(0),m="0".codePointAt(0),p="9".codePointAt(0);function b(t,e,n){return n?t:e-t-1}var y,P;function w(t){return t?new Set:null}function z(t,e,n){if(null!==e&&e.i16.length>t+n){return [t+n,e.i16.subarray(t,t+n)]}return [t,new Int16Array(n)]}function L(t,e,n){if(null!==e&&e.i32.length>t+n){return [t+n,e.i32.subarray(t,t+n)]}return [t,new Int32Array(n)]}function S(t){return t>=d&&t<=g?1:t>=f&&t<=h?2:t>=m&&t<=p?4:0}function A(t){const e=String.fromCodePoint(t);return e!==e.toUpperCase()?1:e!==e.toLowerCase()?2:null!==e.match(/\p{Number}/gu)?4:null!==e.match(/\p{Letter}/gu)?3:0}function C(t){return t<=u?S(t):A(t)}function v(t,e){return 0===t&&0!==e?8:1===t&&2===e||4!==t&&4===e?7:0===e?8:0}function k(t,e,n,r){let s=t.slice(r),o=s.indexOf(n);if(0===o)return r;if(!e&&n>=d&&n<=g){o>0&&(s=s.slice(0,o));const t=s.indexOf(n-32);t>=0&&(o=t);}return o<0?-1:r+o}function x(t){for(const e of t)if(e>=128)return !1;return !0}function E(t,e,n){if(!x(t))return 0;if(!x(e))return -1;let r=0,s=0;for(let o=0;o0&&(r=s-1),s++;}return r}(P=y||(y={}))[P.NonWord=0]="NonWord",P[P.Lower=1]="Lower",P[P.Upper=2]="Upper",P[P.Letter=3]="Letter",P[P.Number=4]="Number";const N=(t,e,s,o,i,l,c)=>{const a=i.length;if(0===a)return [{start:0,end:0,score:0},w(l)];const f=o.length;if(null!==c&&f*a>c.i16.length)return O(t,e,s,o,i,l);const h=E(o,i,t);if(h<0)return [{start:-1,end:-1,score:0},null];let d=0,g=0,m=null,p=null,b=null,y=null;[d,m]=z(d,c,f),[d,p]=z(d,c,f),[d,b]=z(d,c,f),[g,y]=L(g,c,a);const[,P]=L(g,c,f);for(let n=0;nC||!s&&t>=C)&&(C=t,k=h+w,s&&8===l))break;W=!1;}else M[w]=r(W?q+-1:q+-3,0),B[w]=0,W=!0;q=M[w];}if(x!==a)return [{start:-1,end:-1,score:0},null];if(1===a){const t={start:k,end:k+1,score:C};if(!l)return [t,null];const e=new Set;return e.add(k),[t,e]}const T=y[0],D=N-T+1;let G=null;[d,G]=z(d,c,D*a);{const t=m.subarray(T,N+1);for(const[e,n]of t.entries())G[e]=n;}let[,V]=z(d,c,D*a);{const t=p.subarray(T,N+1);for(const[e,n]of t.entries())V[e]=n;}const J=y.subarray(1),Y=i.slice(1).slice(0,J.length);for(const[n,u]of J.entries()){let t=!1;const e=Y[n],o=n+1,i=o*D,l=P.subarray(u,N+1),c=b.subarray(u).subarray(0,l.length),f=V.subarray(i+u-T).subarray(0,l.length),h=V.subarray(i+u-T-1-D).subarray(0,l.length),d=G.subarray(i+u-T).subarray(0,l.length),g=G.subarray(i+u-T-1-D).subarray(0,l.length),m=G.subarray(i+u-T-1).subarray(0,l.length);m[0]=0;for(const[n,p]of l.entries()){const i=n+u;let l=0,y=0,P=0;if(y=t?m[n]+-1:m[n]+-3,e===p){l=g[n]+16;let t=c[n];P=h[n]+1,8===t?P=1:P>1&&(t=r(t,r(4,b[i-P+1]))),l+tC||!s&&w>=C)&&(C=w,k=i),d[n]=w;}}const Z=w(l);let H=T;if(l&&null!==Z){let t=a-1;H=k;let e=!0;for(;;){const n=t*D,r=H-T,s=G[n+r];let o=0,i=0;if(t>0&&H>=y[t]&&(o=G[n-D+r-1]),H>y[t]&&(i=G[n+r-1]),s>o&&(s>i||s===i&&e)){if(Z.add(H),0===t)break;t--;}e=V[n+r]>1||n+D+r+10,H--;}}return [{start:H,end:k+1,score:C},Z]};function F(t,e,s,o,i,l,c){let a=0,d=0,g=!1,m=0,p=0;const b=w(c);let y=0;i>0&&(y=C(s[i-1]));for(let P=i;P=f&&i<=h?i+=32:i>u&&(i=String.fromCodePoint(i).toLowerCase().codePointAt(0))),e&&(i=n(i)),i===o[a]){c&&null!==b&&b.add(P),d+=16;let t=v(y,l);0===m?p=t:(8===t&&(p=t),t=r(r(t,p),4)),d+=0===a?2*t:t,g=!1,m++,a++;}else d+=g?-1:-3,g=!0,m=0,p=0;y=l;}return [d,b]}const O=(t,e,r,s,o,i,l)=>{if(0===o.length)return [{start:0,end:0,score:0},null];if(E(s,o,t)<0)return [{start:-1,end:-1,score:0},null];let c=0,a=-1,d=-1;const g=s.length,m=o.length;for(let p=0;p=f&&i<=h?i+=32:i>u&&(i=String.fromCodePoint(i).toLowerCase().codePointAt(0))),e&&(i=n(i));if(i===o[b(c,m,r)]&&(a<0&&(a=p),c++,c===m)){d=p+1;break}}if(a>=0&&d>=0){c--;for(let e=d-1;e>=a;e--){let n=s[b(e,g,r)];t||(n>=f&&n<=h?n+=32:n>u&&(n=String.fromCodePoint(n).toLowerCase().codePointAt(0)));if(n===o[b(c,m,r)]&&(c--,c<0)){a=e;break}}if(!r){const t=a;a=g-d,d=g-t;}const[n,l]=F(t,e,s,o,a,d,i);return [{start:a,end:d,score:n},l]}return [{start:-1,end:-1,score:0},null]},R=(t,e,r,s,o,i,l)=>{if(0===o.length)return [{start:0,end:0,score:0},null];const c=s.length,a=o.length;if(c=f&&l<=h?l+=32:l>u&&(l=String.fromCodePoint(l).toLowerCase().codePointAt(0))),e&&(l=n(l));const z=b(d,a,r);if(o[z]===l){if(0===z&&(y=s,m=0===(P=i)?8:v(C(y[P-1]),C(y[P]))),d++,d===a){if(m>p&&(g=w,p=m),8===m)break;w-=d-1,d=0,m=0;}}else w-=d,d=0,m=0;}var y,P;if(g>=0){let n=0,i=0;r?(n=g-a+1,i=g+1):(n=c-(g+1),i=c-(g-a+1));const[l]=F(t,e,s,o,n,i,!1);return [{start:n,end:i,score:l},null]}return [{start:-1,end:-1,score:0},null]};const q=(I=2048,{i16:new Int16Array(102400),i32:new Int32Array(I)});var I,W,j;(j=W||(W={}))[j.Fuzzy=0]="Fuzzy",j[j.Exact=1]="Exact",j[j.Prefix=2]="Prefix",j[j.Suffix=3]="Suffix",j[j.Equal=4]="Equal";const M={0:N,1:R,2:(t,e,r,s,o,i,a)=>{if(0===o.length)return [{start:0,end:0,score:0},null];let u=0;if(l(o[0])||(u=c(s)),s.length-u{let u=s.length;if(0!==o.length&&l(o[o.length-1])||(u-=a(s)),0===o.length)return [{start:u,end:u,score:0},null];const f=u-o.length;if(f<0)return [{start:-1,end:-1,score:0},null];for(const[l,a]of o.entries()){let r=s[l+f];if(t||(r=String.fromCodePoint(r).toLowerCase().codePointAt(0)),e&&(r=n(r)),r!==a)return [{start:-1,end:-1,score:0},null]}const h=u-o.length,d=u,[g]=F(t,e,s,o,h,d,!1);return [{start:h,end:d,score:g},null]},4:(t,e,r,s,i,u,f)=>{const h=i.length;if(0===h)return [{start:-1,end:-1,score:0},null];let d=0;l(i[0])||(d=c(s));let g=0;if(l(i[h-1])||(g=a(s)),s.length-d-g!=h)return [{start:-1,end:-1,score:0},null];let m=!0;if(e){const e=s;for(const[r,s]of i.entries()){let o=e[d+r];if(t||(o=String.fromCodePoint(o).toLowerCase().codePointAt(0)),n(s)!==n(o)){m=!1;break}}}else {let e=o(s).substring(d,s.length-g);t||(e=e.toLowerCase()),m=e===o(i);}return m?[{start:d,end:d+h,score:24*h+8},null]:[{start:-1,end:-1,score:0},null]}};function B(t,e,r,i){let l=!0;{const t=(i=i.trimLeft()).trimRight();i=t.endsWith("\\")&&" "===i[t.length]?t+" ":t;}let c=!1,a=[];a=function(t,e,r,i){const l=(i=i.replace(/\\ /g,"\t")).split(/ +/),c=[];let a=[],u=!1,f=!1;for(const h of l){let i=0,l=!1,d=h.replace(/\t/g," ");const g=d.toLowerCase(),m="case-sensitive"===e||"smart-case"===e&&d!==g,p=r&&g===o(s(g).map(n));if(m||(d=g),t||(i=1),a.length>0&&!f&&"|"===d)u=!1,f=!0;else if(f=!1,d.startsWith("!")&&(l=!0,i=1,d=d.substring(1)),"$"!==d&&d.endsWith("$")&&(i=3,d=d.substring(0,d.length-1)),d.startsWith("'")?(i=t&&!l?1:0,d=d.substring(1)):d.startsWith("^")&&(i=3===i?4:2,d=d.substring(1)),d.
15 | 	length>0){u&&(c.push(a),a=[]);let t=s(d);p&&(t=t.map(n)),a.push({typ:i,inv:l,text:t,caseSensitive:m,normalize:p}),u=!0;}}a.length>0&&c.push(a);return c}(t,e,r,i);t:for(const n of a)for(const[e,r]of n.entries())if(r.inv||(c=!0),(!l||e>0||r.inv||t&&0!==r.typ||!t&&1!==r.typ)&&(l=!1,c))break t;return {str:i,termSets:a,sortable:c,cacheable:l,fuzzy:t}}const U=(t,e,r)=>{let o=!1;switch(e){case"smart-case":t.toLowerCase()!==t&&(o=!0);break;case"case-sensitive":o=!0;break;case"case-insensitive":t=t.toLowerCase(),o=!1;}let i=s(t);return r&&(i=i.map(n)),{queryRunes:i,caseSensitive:o}};function T(t,e,n,r,s,o,i){for(const l of e){const[e,c]=t(n,r,s,l.text,o,!0,i);if(e.start>=0){const t=e.start+l.prefixLength,n=e.end+l.prefixLength;if(null!==c){const r=new Set;return c.forEach((t=>r.add(l.prefixLength+t))),[[t,n],e.score,r]}return [[t,n],e.score,c]}}return [[-1,-1],0,null]}function D(t,e){const n=Object.keys(t).map((t=>parseInt(t,10))).sort(((t,e)=>e-t));let r=[];for(const s of n)if(r=r.concat(t[s]),r.length>=e)break;return r}function G(t,e,n){return r=>{const s=this.runesList[r];if(e.length>s.length)return;let[o,i]=this.algoFn(n,this.opts.normalize,this.opts.forward,s,e,!0,q);if(-1===o.start)return;if(!1===this.opts.fuzzy){i=new Set;for(let t=o.start;t{const r=function(t,e,n,r){const s=[{text:t,prefixLength:0}],o=[];let i=0;const l=new Set;for(const c of e.termSets){let t=[0,0],e=0,a=!1;for(const o of c){let i=M[o.typ];o.typ===W.Fuzzy&&(i=n);const[c,u,f]=T(i,s,o.caseSensitive,o.normalize,r,o.text,q);if(c[0]>=0){if(o.inv)continue;if(t=c,e=u,a=!0,null!==f)f.forEach((t=>l.add(t)));else for(let t=c[0];t0&&(s=Math.min(...r.allPos),o=Math.max(...r.allPos)+1);const i=this.opts.sort?r.totalScore:0;void 0===t[i]&&(t[i]=[]),t[i].push({score:r.totalScore,item:this.items[n],positions:r.allPos,start:s,end:o});}}function J(t){const{queryRunes:e,caseSensitive:n}=U(t,this.opts.casing,this.opts.normalize),r={},s=G.bind(this)(r,e,n);for(let o=0,i=this.runesList.length;o{let i=0,l=Math.min(1e3,e);const c=()=>{if(t.cancelled)return o("search cancelled");for(;iD(s,this.opts.limit)))}function Q(t,e){const n=B(Boolean(this.opts.fuzzy),this.opts.casing,this.opts.normalize,t),r={};return H(e,this.runesList.length,V.bind(this)(r,n),(()=>D(r,this.opts.limit)))}const $={limit:1/0,selector:t=>t,casing:"smart-case",normalize:!0,fuzzy:"v2",tiebreakers:[],sort:!0,forward:!0};class X{constructor(t,...e){switch(this.opts={...$,...e[0]},this.items=t,this.runesList=t.map((t=>s(this.opts.selector(t).normalize()))),this.algoFn=R,this.opts.fuzzy){case"v2":this.algoFn=N;break;case"v1":this.algoFn=O;}}}const _={...$,match:J};class tt extends X{constructor(t,...e){super(t,...e),this.opts={..._,...e[0]};}find(t){if(0===t.length||0===this.items.length)return this.items.slice(0,this.opts.limit).map(rt);return t=t.normalize(),st(this.opts.match.bind(this)(t),this.opts)}}const et={...$,match:K};class nt extends X{constructor(t,...e){super(t,...e),this.opts={...et,...e[0]},this.token={cancelled:!1};}async find(t){if(this.token.cancelled=!0,this.token={cancelled:!1},0===t.length||0===this.items.length)return this.items.slice(0,this.opts.limit).map(rt);return t=t.normalize(),st(await this.opts.match.bind(this)(t,this.token),this.opts)}}const rt=t=>({item:t,start:-1,end:-1,score:0,positions:new Set});function st(t,e){if(e.sort){const{selector:n}=e;t.sort(((t,r)=>{if(t.score===r.score)for(const s of e.tiebreakers){const e=s(t,r,n);if(0!==e)return e}return 0}));}return Number.isFinite(e.limit)&&t.splice(e.limit),t}function ot(t,e,n){return n(t.item).length-n(e.item).length}function it(t,e){return t.start-e.start}class lt{constructor(t,...e){this.finder=new tt(t,...e),this.find=this.finder.find.bind(this.finder);}}class ct{constructor(t,...e){this.finder=new nt(t,...e),this.find=this.finder.find.bind(this.finder);}}
16 | 
17 | 	exports.AsyncFzf = ct;
18 | 	exports.Fzf = lt;
19 | 	exports.asyncBasicMatch = K;
20 | 	exports.asyncExtendedMatch = Q;
21 | 	exports.basicMatch = J;
22 | 	exports.byLengthAsc = ot;
23 | 	exports.byStartAsc = it;
24 | 	exports.extendedMatch = Y;
25 | 
26 | 	return exports;
27 | 
28 | })({});
29 | 


--------------------------------------------------------------------------------
/demos/lib/fzy.js:
--------------------------------------------------------------------------------
  1 | var fzy = (function (exports) {
  2 | 	'use strict';
  3 | 
  4 | 	var SCORE_MIN = -Infinity;
  5 | 	var SCORE_MAX = Infinity;
  6 | 
  7 | 	var SCORE_GAP_LEADING = -0.005;
  8 | 	var SCORE_GAP_TRAILING = -0.005;
  9 | 	var SCORE_GAP_INNER = -0.01;
 10 | 	var SCORE_MATCH_CONSECUTIVE = 1.0;
 11 | 	var SCORE_MATCH_SLASH = 0.9;
 12 | 	var SCORE_MATCH_WORD = 0.8;
 13 | 	var SCORE_MATCH_CAPITAL = 0.7;
 14 | 	var SCORE_MATCH_DOT = 0.6;
 15 | 
 16 | 	function islower(s) {
 17 | 		return s.toLowerCase() === s;
 18 | 	}
 19 | 
 20 | 	function isupper(s) {
 21 | 		return s.toUpperCase() === s;
 22 | 	}
 23 | 
 24 | 	function precompute_bonus(haystack) {
 25 | 		/* Which positions are beginning of words */
 26 | 		var m = haystack.length;
 27 | 		var match_bonus = new Array(m);
 28 | 
 29 | 		var last_ch = '/';
 30 | 		for (var i = 0; i < m; i++) {
 31 | 			var ch = haystack[i];
 32 | 
 33 | 			if (last_ch === '/') {
 34 | 				match_bonus[i] = SCORE_MATCH_SLASH;
 35 | 			} else if (last_ch === '-' || last_ch === '_' || last_ch === ' ') {
 36 | 				match_bonus[i] = SCORE_MATCH_WORD;
 37 | 			} else if (last_ch === '.') {
 38 | 				match_bonus[i] = SCORE_MATCH_DOT;
 39 | 			} else if (islower(last_ch) && isupper(ch)) {
 40 | 				match_bonus[i] = SCORE_MATCH_CAPITAL;
 41 | 			} else {
 42 | 				match_bonus[i] = 0;
 43 | 			}
 44 | 
 45 | 			last_ch = ch;
 46 | 		}
 47 | 
 48 | 		return match_bonus;
 49 | 	}
 50 | 
 51 | 	function compute(needle, haystack, D, M) {
 52 | 		var n = needle.length;
 53 | 		var m = haystack.length;
 54 | 
 55 | 		var lower_needle = needle.toLowerCase();
 56 | 		var lower_haystack = haystack.toLowerCase();
 57 | 
 58 | 		var match_bonus = precompute_bonus(haystack);
 59 | 
 60 | 		/*
 61 | 		 * D[][] Stores the best score for this position ending with a match.
 62 | 		 * M[][] Stores the best possible score at this position.
 63 | 		 */
 64 | 
 65 | 		for (var i = 0; i < n; i++) {
 66 | 			D[i] = new Array(m);
 67 | 			M[i] = new Array(m);
 68 | 
 69 | 			var prev_score = SCORE_MIN;
 70 | 			var gap_score = i === n - 1 ? SCORE_GAP_TRAILING : SCORE_GAP_INNER;
 71 | 
 72 | 			for (var j = 0; j < m; j++) {
 73 | 				if (lower_needle[i] === lower_haystack[j]) {
 74 | 					var score = SCORE_MIN;
 75 | 					if (!i) {
 76 | 						score = (j * SCORE_GAP_LEADING) + match_bonus[j];
 77 | 					} else if (j) { /* i > 0 && j > 0*/
 78 | 						score = Math.max(
 79 | 							M[i - 1][j - 1] + match_bonus[j],
 80 | 
 81 | 							/* consecutive match, doesn't stack with match_bonus */
 82 | 							D[i - 1][j - 1] + SCORE_MATCH_CONSECUTIVE);
 83 | 					}
 84 | 					D[i][j] = score;
 85 | 					M[i][j] = prev_score = Math.max(score, prev_score + gap_score);
 86 | 				} else {
 87 | 					D[i][j] = SCORE_MIN;
 88 | 					M[i][j] = prev_score = prev_score + gap_score;
 89 | 				}
 90 | 			}
 91 | 		}
 92 | 	}
 93 | 
 94 | 	function score(needle, haystack) {
 95 | 		var n = needle.length;
 96 | 		var m = haystack.length;
 97 | 
 98 | 		if (!n || !m)
 99 | 			return SCORE_MIN;
100 | 
101 | 		if (n === m) {
102 | 			/* Since this method can only be called with a haystack which
103 | 			 * matches needle. If the lengths of the strings are equal the
104 | 			 * strings themselves must also be equal (ignoring case).
105 | 			 */
106 | 			return SCORE_MAX;
107 | 		}
108 | 
109 | 		if (m > 1024) {
110 | 			/*
111 | 			 * Unreasonably large candidate: return no score
112 | 			 * If it is a valid match it will still be returned, it will
113 | 			 * just be ranked below any reasonably sized candidates
114 | 			 */
115 | 			return SCORE_MIN;
116 | 		}
117 | 
118 | 		var D = new Array(n);
119 | 		var M = new Array(n);
120 | 
121 | 		compute(needle, haystack, D, M);
122 | 
123 | 		return M[n - 1][m - 1];
124 | 	}
125 | 
126 | 	function positions(needle, haystack) {
127 | 		var n = needle.length;
128 | 		var m = haystack.length;
129 | 
130 | 		var positions = new Array(n);
131 | 
132 | 		if (!n || !m)
133 | 			return positions;
134 | 
135 | 		if (n === m) {
136 | 			for (var i = 0; i < n; i++)
137 | 				positions[i] = i;
138 | 			return positions;
139 | 		}
140 | 
141 | 		if (m > 1024) {
142 | 			return positions;
143 | 		}
144 | 
145 | 		var D = new Array(n);
146 | 		var M = new Array(n);
147 | 
148 | 		compute(needle, haystack, D, M);
149 | 
150 | 		/* backtrack to find the positions of optimal matching */
151 | 		var match_required = false;
152 | 
153 | 		for (var i = n - 1, j = m - 1; i >= 0; i--) {
154 | 			for (; j >= 0; j--) {
155 | 				/*
156 | 				 * There may be multiple paths which result in
157 | 				 * the optimal weight.
158 | 				 *
159 | 				 * For simplicity, we will pick the first one
160 | 				 * we encounter, the latest in the candidate
161 | 				 * string.
162 | 				 */
163 | 				if (D[i][j] !== SCORE_MIN &&
164 | 				    (match_required || D[i][j] === M[i][j])) {
165 | 					/* If this score was determined using
166 | 					 * SCORE_MATCH_CONSECUTIVE, the
167 | 					 * previous character MUST be a match
168 | 					 */
169 | 					match_required =
170 | 					    i && j &&
171 | 					    M[i][j] === D[i - 1][j - 1] + SCORE_MATCH_CONSECUTIVE;
172 | 					positions[i] = j--;
173 | 					break;
174 | 				}
175 | 			}
176 | 		}
177 | 
178 | 		return positions;
179 | 	}
180 | 
181 | 	function hasMatch(needle, haystack) {
182 | 	  needle = needle.toLowerCase();
183 | 	  haystack = haystack.toLowerCase();
184 | 	  var l = needle.length;
185 | 	  for (var i = 0, j = 0; i < l; i += 1) {
186 | 	    j = haystack.indexOf(needle[i], j) + 1;
187 | 	    if (j === 0) return false
188 | 	  }
189 | 	  return true
190 | 	}
191 | 
192 | 	exports.SCORE_GAP_INNER = SCORE_GAP_INNER;
193 | 	exports.SCORE_GAP_LEADING = SCORE_GAP_LEADING;
194 | 	exports.SCORE_GAP_TRAILING = SCORE_GAP_TRAILING;
195 | 	exports.SCORE_MATCH_CAPITAL = SCORE_MATCH_CAPITAL;
196 | 	exports.SCORE_MATCH_CONSECUTIVE = SCORE_MATCH_CONSECUTIVE;
197 | 	exports.SCORE_MATCH_DOT = SCORE_MATCH_DOT;
198 | 	exports.SCORE_MATCH_SLASH = SCORE_MATCH_SLASH;
199 | 	exports.SCORE_MATCH_WORD = SCORE_MATCH_WORD;
200 | 	exports.SCORE_MAX = SCORE_MAX;
201 | 	exports.SCORE_MIN = SCORE_MIN;
202 | 	exports.hasMatch = hasMatch;
203 | 	exports.positions = positions;
204 | 	exports.score = score;
205 | 
206 | 	Object.defineProperty(exports, '__esModule', { value: true });
207 | 
208 | 	return exports;
209 | 
210 | })({});


--------------------------------------------------------------------------------
/demos/lib/js-search.min.js:
--------------------------------------------------------------------------------
1 | !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.JsSearch=t():e.JsSearch=t()}(this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=17)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(7);Object.defineProperty(t,"AllSubstringsIndexStrategy",{enumerable:!0,get:function(){return r.AllSubstringsIndexStrategy}});var i=n(8);Object.defineProperty(t,"ExactWordIndexStrategy",{enumerable:!0,get:function(){return i.ExactWordIndexStrategy}});var o=n(9);Object.defineProperty(t,"PrefixIndexStrategy",{enumerable:!0,get:function(){return o.PrefixIndexStrategy}})},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(10);Object.defineProperty(t,"CaseSensitiveSanitizer",{enumerable:!0,get:function(){return r.CaseSensitiveSanitizer}});var i=n(11);Object.defineProperty(t,"LowerCaseSanitizer",{enumerable:!0,get:function(){return i.LowerCaseSanitizer}})},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(12);Object.defineProperty(t,"TfIdfSearchIndex",{enumerable:!0,get:function(){return r.TfIdfSearchIndex}});var i=n(13);Object.defineProperty(t,"UnorderedSearchIndex",{enumerable:!0,get:function(){return i.UnorderedSearchIndex}})},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=t.StopWordsMap={a:!0,able:!0,about:!0,across:!0,after:!0,all:!0,almost:!0,also:!0,am:!0,among:!0,an:!0,and:!0,any:!0,are:!0,as:!0,at:!0,be:!0,because:!0,been:!0,but:!0,by:!0,can:!0,cannot:!0,could:!0,dear:!0,did:!0,do:!0,does:!0,either:!0,else:!0,ever:!0,every:!0,for:!0,from:!0,get:!0,got:!0,had:!0,has:!0,have:!0,he:!0,her:!0,hers:!0,him:!0,his:!0,how:!0,however:!0,i:!0,if:!0,in:!0,into:!0,is:!0,it:!0,its:!0,just:!0,least:!0,let:!0,like:!0,likely:!0,may:!0,me:!0,might:!0,most:!0,must:!0,my:!0,neither:!0,no:!0,nor:!0,not:!0,of:!0,off:!0,often:!0,on:!0,only:!0,or:!0,other:!0,our:!0,own:!0,rather:!0,said:!0,say:!0,says:!0,she:!0,should:!0,since:!0,so:!0,some:!0,than:!0,that:!0,the:!0,their:!0,them:!0,then:!0,there:!0,these:!0,they:!0,this:!0,tis:!0,to:!0,too:!0,twas:!0,us:!0,wants:!0,was:!0,we:!0,were:!0,what:!0,when:!0,where:!0,which:!0,while:!0,who:!0,whom:!0,why:!0,will:!0,with:!0,would:!0,yet:!0,you:!0,your:!0};r.constructor=!1,r.hasOwnProperty=!1,r.isPrototypeOf=!1,r.propertyIsEnumerable=!1,r.toLocaleString=!1,r.toString=!1,r.valueOf=!1},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(14);Object.defineProperty(t,"SimpleTokenizer",{enumerable:!0,get:function(){return r.SimpleTokenizer}});var i=n(15);Object.defineProperty(t,"StemmingTokenizer",{enumerable:!0,get:function(){return i.StemmingTokenizer}});var o=n(16);Object.defineProperty(t,"StopWordsTokenizer",{enumerable:!0,get:function(){return o.StopWordsTokenizer}})},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){t=t||[],e=e||{};for(var n=e,r=0;r=0&&(l=this._wrapText(l),e=e.substring(0,h)+l+e.substring(i+1),i+=n,y+=n)}return e}},{key:"_wrapText",value:function(e){var t=this._wrapperTagName;return"<"+t+">"+e+""}}]),e}()},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n string.length) return SCORE_NO_MATCH;
 31 | 
 32 |       // match & score all
 33 |       var allScores = [];
 34 |       var search = string.toLowerCase();
 35 |       abbrev = abbrev.toLowerCase();
 36 |       this._scoreAll(string, search, abbrev, -1, 0, [], allScores);
 37 | 
 38 |       // complete miss
 39 |       if (allScores.length == 0) return 0;
 40 | 
 41 |       // sum per-character scores into overall scores,
 42 |       // selecting the maximum score
 43 |       var maxScore = 0.0, maxArray = [];
 44 |       for (var i = 0; i < allScores.length; i++) {
 45 |         var scores = allScores[i];
 46 |         var scoreSum = 0.0;
 47 |         for (var j = 0; j < string.length; j++) { scoreSum += scores[j]; }
 48 |         if (scoreSum > maxScore) {
 49 |           maxScore = scoreSum;
 50 |           maxArray = scores;
 51 |         }
 52 |       }
 53 | 
 54 |       // normalize max score by string length
 55 |       // s. t. the perfect match score = 1
 56 |       maxScore /= string.length;
 57 | 
 58 |       // record maximum score & score array, return
 59 |       this.lastScore = maxScore;
 60 |       this.lastScoreArray = maxArray;
 61 |       return maxScore;
 62 |     },
 63 | 
 64 |     _scoreAll: function(string, search, abbrev, searchIndex, abbrIndex, scores, allScores) {
 65 |       // save completed match scores at end of search
 66 |       if (abbrIndex == abbrev.length) {
 67 |         // add trailing score for the remainder of the match
 68 |         var started = (search.charAt(0) == abbrev.charAt(0));
 69 |         var trailScore = started ? SCORE_TRAILING_BUT_STARTED : SCORE_TRAILING;
 70 |         fillArray(scores, trailScore, scores.length, string.length);
 71 |         // save score clone (since reference is persisted in scores)
 72 |         allScores.push(scores.slice(0));
 73 |         return;
 74 |       }
 75 | 
 76 |       // consume current char to match
 77 |       var c = abbrev.charAt(abbrIndex);
 78 |       abbrIndex++;
 79 | 
 80 |       // cancel match if a character is missing
 81 |       var index = search.indexOf(c, searchIndex);
 82 |       if (index == -1) return;
 83 | 
 84 |       // match all instances of the abbreviaton char
 85 |       var scoreIndex = searchIndex; // score section to update
 86 |       while ((index = search.indexOf(c, searchIndex+1)) != -1) {
 87 |         // score this match according to context
 88 |         if (isNewWord(string, index)) {
 89 |           scores[index-1] = 1;
 90 |           fillArray(scores, SCORE_BUFFER, scoreIndex+1, index-1);
 91 |         }
 92 |         else if (isUpperCase(string, index)) {
 93 |           fillArray(scores, SCORE_BUFFER, scoreIndex+1, index);
 94 |         }
 95 |         else {
 96 |           fillArray(scores, SCORE_NO_MATCH, scoreIndex+1, index);
 97 |         }
 98 |         scores[index] = SCORE_MATCH;
 99 | 
100 |         // consume matched string and continue search
101 |         searchIndex = index;
102 |         this._scoreAll(string, search, abbrev, searchIndex, abbrIndex, scores, allScores);
103 |       }
104 |     }
105 |   };
106 | 
107 |   function isUpperCase(string, index) {
108 |     var c = string.charAt(index);
109 |     return ("A" <= c && c <= "Z");
110 |   }
111 | 
112 |    function isNewWord(string, index) {
113 |     var c = string.charAt(index-1);
114 |     return (WORD_SEPARATORS.indexOf(c) != -1);
115 |   }
116 | 
117 |   function fillArray(array, value, from, to) {
118 |     for (var i = from; i < to; i++) { array[i] = value; }
119 |     return array;
120 |   }
121 | 
122 |   // Export as AMD...
123 |   if (typeof define === 'function' && define.amd) {
124 |     define(function () { return LiquidMetal; });
125 |   }
126 | 
127 |   // ...or as a node module
128 |   else if (typeof module !== 'undefined' && module.exports) {
129 |     module.exports = LiquidMetal;
130 |   }
131 | 
132 |   else {
133 |     global.LiquidMetal = LiquidMetal;
134 |   }
135 | })(typeof window !== 'undefined' ? window : this);
136 | 


--------------------------------------------------------------------------------
/demos/lib/match-sorter.umd.min.js:
--------------------------------------------------------------------------------
 1 | !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).matchSorter={})}(this,(function(e){"use strict";var n={exports:{}},t={"À":"A","Á":"A","Â":"A","Ã":"A","Ä":"A","Å":"A","Ấ":"A","Ắ":"A","Ẳ":"A","Ẵ":"A","Ặ":"A","Æ":"AE","Ầ":"A","Ằ":"A","Ȃ":"A","Ả":"A","Ạ":"A","Ẩ":"A","Ẫ":"A","Ậ":"A","Ç":"C","Ḉ":"C","È":"E","É":"E","Ê":"E","Ë":"E","Ế":"E","Ḗ":"E","Ề":"E","Ḕ":"E","Ḝ":"E","Ȇ":"E","Ẻ":"E","Ẽ":"E","Ẹ":"E","Ể":"E","Ễ":"E","Ệ":"E","Ì":"I","Í":"I","Î":"I","Ï":"I","Ḯ":"I","Ȋ":"I","Ỉ":"I","Ị":"I","Ð":"D","Ñ":"N","Ò":"O","Ó":"O","Ô":"O","Õ":"O","Ö":"O","Ø":"O","Ố":"O","Ṍ":"O","Ṓ":"O","Ȏ":"O","Ỏ":"O","Ọ":"O","Ổ":"O","Ỗ":"O","Ộ":"O","Ờ":"O","Ở":"O","Ỡ":"O","Ớ":"O","Ợ":"O","Ù":"U","Ú":"U","Û":"U","Ü":"U","Ủ":"U","Ụ":"U","Ử":"U","Ữ":"U","Ự":"U","Ý":"Y","à":"a","á":"a","â":"a","ã":"a","ä":"a","å":"a","ấ":"a","ắ":"a","ẳ":"a","ẵ":"a","ặ":"a","æ":"ae","ầ":"a","ằ":"a","ȃ":"a","ả":"a","ạ":"a","ẩ":"a","ẫ":"a","ậ":"a","ç":"c","ḉ":"c","è":"e","é":"e","ê":"e","ë":"e","ế":"e","ḗ":"e","ề":"e","ḕ":"e","ḝ":"e","ȇ":"e","ẻ":"e","ẽ":"e","ẹ":"e","ể":"e","ễ":"e","ệ":"e","ì":"i","í":"i","î":"i","ï":"i","ḯ":"i","ȋ":"i","ỉ":"i","ị":"i","ð":"d","ñ":"n","ò":"o","ó":"o","ô":"o","õ":"o","ö":"o","ø":"o","ố":"o","ṍ":"o","ṓ":"o","ȏ":"o","ỏ":"o","ọ":"o","ổ":"o","ỗ":"o","ộ":"o","ờ":"o","ở":"o","ỡ":"o","ớ":"o","ợ":"o","ù":"u","ú":"u","û":"u","ü":"u","ủ":"u","ụ":"u","ử":"u","ữ":"u","ự":"u","ý":"y","ÿ":"y","Ā":"A","ā":"a","Ă":"A","ă":"a","Ą":"A","ą":"a","Ć":"C","ć":"c","Ĉ":"C","ĉ":"c","Ċ":"C","ċ":"c","Č":"C","č":"c","C̆":"C","c̆":"c","Ď":"D","ď":"d","Đ":"D","đ":"d","Ē":"E","ē":"e","Ĕ":"E","ĕ":"e","Ė":"E","ė":"e","Ę":"E","ę":"e","Ě":"E","ě":"e","Ĝ":"G","Ǵ":"G","ĝ":"g","ǵ":"g","Ğ":"G","ğ":"g","Ġ":"G","ġ":"g","Ģ":"G","ģ":"g","Ĥ":"H","ĥ":"h","Ħ":"H","ħ":"h","Ḫ":"H","ḫ":"h","Ĩ":"I","ĩ":"i","Ī":"I","ī":"i","Ĭ":"I","ĭ":"i","Į":"I","į":"i","İ":"I","ı":"i","IJ":"IJ","ij":"ij","Ĵ":"J","ĵ":"j","Ķ":"K","ķ":"k","Ḱ":"K","ḱ":"k","K̆":"K","k̆":"k","Ĺ":"L","ĺ":"l","Ļ":"L","ļ":"l","Ľ":"L","ľ":"l","Ŀ":"L","ŀ":"l","Ł":"l","ł":"l","Ḿ":"M","ḿ":"m","M̆":"M","m̆":"m","Ń":"N","ń":"n","Ņ":"N","ņ":"n","Ň":"N","ň":"n","ʼn":"n","N̆":"N","n̆":"n","Ō":"O","ō":"o","Ŏ":"O","ŏ":"o","Ő":"O","ő":"o","Œ":"OE","œ":"oe","P̆":"P","p̆":"p","Ŕ":"R","ŕ":"r","Ŗ":"R","ŗ":"r","Ř":"R","ř":"r","R̆":"R","r̆":"r","Ȓ":"R","ȓ":"r","Ś":"S","ś":"s","Ŝ":"S","ŝ":"s","Ş":"S","Ș":"S","ș":"s","ş":"s","Š":"S","š":"s","Ţ":"T","ţ":"t","ț":"t","Ț":"T","Ť":"T","ť":"t","Ŧ":"T","ŧ":"t","T̆":"T","t̆":"t","Ũ":"U","ũ":"u","Ū":"U","ū":"u","Ŭ":"U","ŭ":"u","Ů":"U","ů":"u","Ű":"U","ű":"u","Ų":"U","ų":"u","Ȗ":"U","ȗ":"u","V̆":"V","v̆":"v","Ŵ":"W","ŵ":"w","Ẃ":"W","ẃ":"w","X̆":"X","x̆":"x","Ŷ":"Y","ŷ":"y","Ÿ":"Y","Y̆":"Y","y̆":"y","Ź":"Z","ź":"z","Ż":"Z","ż":"z","Ž":"Z","ž":"z","ſ":"s","ƒ":"f","Ơ":"O","ơ":"o","Ư":"U","ư":"u","Ǎ":"A","ǎ":"a","Ǐ":"I","ǐ":"i","Ǒ":"O","ǒ":"o","Ǔ":"U","ǔ":"u","Ǖ":"U","ǖ":"u","Ǘ":"U","ǘ":"u","Ǚ":"U","ǚ":"u","Ǜ":"U","ǜ":"u","Ứ":"U","ứ":"u","Ṹ":"U","ṹ":"u","Ǻ":"A","ǻ":"a","Ǽ":"AE","ǽ":"ae","Ǿ":"O","ǿ":"o","Þ":"TH","þ":"th","Ṕ":"P","ṕ":"p","Ṥ":"S","ṥ":"s","X́":"X","x́":"x","Ѓ":"Г","ѓ":"г","Ќ":"К","ќ":"к","A̋":"A","a̋":"a","E̋":"E","e̋":"e","I̋":"I","i̋":"i","Ǹ":"N","ǹ":"n","Ồ":"O","ồ":"o","Ṑ":"O","ṑ":"o","Ừ":"U","ừ":"u","Ẁ":"W","ẁ":"w","Ỳ":"Y","ỳ":"y","Ȁ":"A","ȁ":"a","Ȅ":"E","ȅ":"e","Ȉ":"I","ȉ":"i","Ȍ":"O","ȍ":"o","Ȑ":"R","ȑ":"r","Ȕ":"U","ȕ":"u","B̌":"B","b̌":"b","Č̣":"C","č̣":"c","Ê̌":"E","ê̌":"e","F̌":"F","f̌":"f","Ǧ":"G","ǧ":"g","Ȟ":"H","ȟ":"h","J̌":"J","ǰ":"j","Ǩ":"K","ǩ":"k","M̌":"M","m̌":"m","P̌":"P","p̌":"p","Q̌":"Q","q̌":"q","Ř̩":"R","ř̩":"r","Ṧ":"S","ṧ":"s","V̌":"V","v̌":"v","W̌":"W","w̌":"w","X̌":"X","x̌":"x","Y̌":"Y","y̌":"y","A̧":"A","a̧":"a","B̧":"B","b̧":"b","Ḑ":"D","ḑ":"d","Ȩ":"E","ȩ":"e","Ɛ̧":"E","ɛ̧":"e","Ḩ":"H","ḩ":"h","I̧":"I","i̧":"i","Ɨ̧":"I","ɨ̧":"i","M̧":"M","m̧":"m","O̧":"O","o̧":"o","Q̧":"Q","q̧":"q","U̧":"U","u̧":"u","X̧":"X","x̧":"x","Z̧":"Z","z̧":"z","й":"и","Й":"И","ё":"е","Ё":"Е"},r=Object.keys(t).join("|"),o=new RegExp(r,"g"),u=new RegExp(r,"");function i(e){return t[e]}var a=function(e){return e.replace(o,i)};n.exports=a,n.exports.has=function(e){return!!e.match(u)},n.exports.remove=a;
 2 | /**
 3 | 	 * @name match-sorter
 4 | 	 * @license MIT license.
 5 | 	 * @copyright (c) 2020 Kent C. Dodds
 6 | 	 * @author Kent C. Dodds  (https://kentcdodds.com)
 7 | 	 */
 8 | const l={CASE_SENSITIVE_EQUAL:7,EQUAL:6,STARTS_WITH:5,WORD_STARTS_WITH:4,CONTAINS:3,ACRONYM:2,MATCHES:1,NO_MATCH:0};c.rankings=l;const s=(e,n)=>String(e.rankedValue).localeCompare(String(n.rankedValue));function c(e,n,t){void 0===t&&(t={});const{keys:r,threshold:o=l.MATCHES,baseSort:u=s,sorter:i=(e=>e.sort(((e,n)=>f(e,n,u))))}=t,a=e.reduce((function(e,u,i){const a=function(e,n,t,r){if(!n){return{rankedValue:e,rank:A(e,t,r),keyIndex:-1,keyThreshold:r.threshold}}const o=function(e,n){const t=[];for(let r=0,o=n.length;r{let{rank:u,rankedValue:i,keyIndex:a,keyThreshold:s}=e,{itemValue:c,attributes:f}=n,O=A(c,t,r),h=i;const{minRanking:E,maxRanking:d,threshold:T}=f;return O=l.MATCHES?O=E:O>d&&(O=d),O>u&&(u=O,a=o,s=T,h=c),{rankedValue:h,rank:u,keyIndex:a,keyThreshold:s}}),{rankedValue:e,rank:l.NO_MATCH,keyIndex:-1,keyThreshold:r.threshold})}(u,r,n,t),{rank:s,keyThreshold:c=o}=a;return s>=c&&e.push({...a,item:u,index:i}),e}),[]);return i(a).map((e=>{let{item:n}=e;return n}))}function A(e,n,t){return e=O(e,t),(n=O(n,t)).length>e.length?l.NO_MATCH:e===n?l.CASE_SENSITIVE_EQUAL:(e=e.toLowerCase())===(n=n.toLowerCase())?l.EQUAL:e.startsWith(n)?l.STARTS_WITH:e.includes(` ${n}`)?l.WORD_STARTS_WITH:e.includes(n)?l.CONTAINS:1===n.length?l.NO_MATCH:function(e){let n="";return e.split(" ").forEach((e=>{e.split("-").forEach((e=>{n+=e.substr(0,1)}))})),n}(e).includes(n)?l.ACRONYM:function(e,n){let t=0,r=0;function o(e,n,r){for(let o=r,u=n.length;o-1))return l.NO_MATCH}return u(r-i)}(e,n)}function f(e,n,t){const{rank:r,keyIndex:o}=e,{rank:u,keyIndex:i}=n;return r===u?o===i?t(e,n):ou?-1:1}function O(e,t){let{keepDiacritics:r}=t;return e=`${e}`,r||(e=n.exports(e)),e}function h(e,n){let t;if("object"==typeof n&&(n=n.key),"function"==typeof n)t=n(e);else if(null==e)t=null;else if(Object.hasOwnProperty.call(e,n))t=e[n];else{if(n.includes("."))return function(e,n){const t=e.split(".");let r=[n];for(let e=0,n=t.length;e{const n=l;let o=0,r=e.length;for(;o>1,s=e[l].k-t;if(s<0)o=l+1;else{if(!(s>0))return n.found=!0,void(n.i=l);r=l}}n.found=!1,n.i=o},s=e=>({k:e,c:null,d:null}),d=(e,t)=>{const n=l;let o=0;for(;void 0!==e&&o1&&(o[t]=o[o.length-1]),o.pop())}o.length>0&&(n=1)}if(null!==l)for(t=0;tt.score-e.score,f=Math.max,u=Math.log,h=String.fromCharCode,g=(e,t,n)=>{null!==e.d&&t.push(n);const o=e.c;if(null!==o)for(let e=0;e{const n=d(e.root,t),o=[];return void 0!==n&&g(n,o,t),o};return e.createIndex=(e,t,l)=>({docs:new o,root:s(0),fSum:new n(e),fAvg:new n(e),removed:0,tokenizer:t,filter:l}),e.expandTerm=a,e.findInvertedIndexNode=d,e.indexAdd=(e,n,d,i)=>{const{root:c,fSum:f,fAvg:u,docs:h,tokenizer:g,filter:a}=e,v=new o,m=new t(n.length);for(let e=0;e{const n=l;let o=c;for(let e=0;e{const{docs:r,root:s,fAvg:i,tokenizer:h,filter:g}=e,v=h(l),m=new Map;for(let l=0;l0){const l=u(1+(r.size-e+.5)/(e+.5));for(let e=0;e0){d=(n+1)*d/(n*(1-o+o*(r.details.fCount[s]/i[s]))+d),e+=d*l*t[s]*a}}if(e>0){const t=r.details.key,n=m.get(t);m.set(t,void 0!==n&&h.has(t)?f(n,e):void 0===n?e:n+e),h.add(t)}}}}}}}}const p=[];return m.forEach(((e,t)=>{p.push({key:t,score:e})})),p.sort(c),p},e.indexRemove=(e,t)=>{const{docs:n,fSum:o,fAvg:l}=e,r=n.get(t);if(void 0!==r){e.removed++,r.removed=!0,n.delete(t);for(let e=0;e0&&(o[e]-=t,l[e]=o[e]/n.size)}}},e.indexVacuum=function(e){i(e.root),e.removed=0},e}({});
3 | 


--------------------------------------------------------------------------------
/demos/lib/quick-score.min.js:
--------------------------------------------------------------------------------
1 | (function(a,b){"object"==typeof exports&&"undefined"!=typeof module?b(exports):"function"==typeof define&&define.amd?define(["exports"],b):(a="undefined"==typeof globalThis?a||self:globalThis,b(a.quickScore={}))})(this,function(a){"use strict";var b=Math.min;function c(b,c){var d=null==b?null:"undefined"!=typeof Symbol&&b[Symbol.iterator]||b["@@iterator"];if(null!=d){var g,h,j,k,l=[],a=!0,m=!1;try{if(j=(d=d.call(b)).next,0===c){if(Object(d)!==d)return;a=!1}else for(;!(a=(g=j.call(d)).done)&&(l.push(g.value),l.length!==c);a=!0);}catch(a){m=!0,h=a}finally{try{if(!a&&null!=d.return&&(k=d.return(),Object(k)!==k))return}finally{if(m)throw h}}return l}}function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function e(a,b){for(var c,d=0;da.length)&&(b=a.length);for(var c=0,d=Array(b);cl.length)return 0;for(var o=d&&d.length,p=m.length;0h.maxIterations)return 0;k++;var q=g.substring(m.location,m.location+p),r=w(f,q,new y(l.location,l.length-m.length+p));if(r.isValid()){n.location=n.isValid()?b(n.location,r.location):r.location,n.max(r.max()),d&&d.push(r.toArray());var s=new y(r.max(),l.max()-r.max()),t=new y(m.location+p,m.length-p),u=e(s,t,n);if(u){var v=s.location-l.location,x=!0,z=h.useSkipReduction(a,c,u,s,l,s,r,n);if(r.location>l.location)if(z&&-1=l.location;A--)-1=l.location;B--)-1%._=&[]+ \t\n\r",uppercaseLetters:function(){for(var a=[],b=0;26>b;b++)a.push(String.fromCharCode(65+b));return a.join("")}(),ignoredScore:.9,skippedScore:.15,emptyQueryScore:0,maxIterations:Math.pow(2,16)},A={longStringLength:150,maxMatchStartPct:.15,minMatchDensityPct:.75,maxMatchDensityPct:.95,beginningOfStringPct:.1},B=function(){function a(b){d(this,a),Object.assign(this,z,b)}return f(a,[{key:"useSkipReduction",value:function(){return!0}},{key:"adjustRemainingScore",value:function(a,b,c,d,e,f){return c*f.length}}]),a}(),C=function(a){function c(a){return d(this,c),e.call(this,Object.assign({},A,a))}g(c,a);var e=m(c);return f(c,[{key:"useSkipReduction",value:function(a,b,c,d,e,f,g){var h=a.length,i=h<=this.longStringLength,j=g.location/h;return i||j=this.minMatchDensityPct?1:l,m=l>=this.maxMatchDensityPct?1:m),d*b(g.length,this.longStringLength)*l*m}}]),c}(B),D=u(),E=new B,F=new B({emptyQueryScore:.9,adjustRemainingScore:function(a,b,c,d,e,f,g){var h=c*f.length;return d||(h+=(g.location-e.location)/2),h}});v.createConfig=u;var G=function(){function a(){var b=0g&&b.push({item:n,score:q,matches:p,_:o})}else for(var r=0;rx&&(x=J,y=D,z=H)}}x>g&&(u.score=x,u.scoreKey=y,u.scoreValue=z,b.push(u))}return b.sort(this.compareScoredStrings),b}},{key:"setKeys",value:function(a,b){if(this.keys=a.slice(),this.sortKey=b,this.keys.length){var c=this.scorer;this.keys=this.keys.map(function(a){var b=a.length?{name:a,scorer:c}:a;if(!Array.isArray(b.name))-10){o.items.push({score:i,id:t})}})}else{t.iterator(t.items,function(r,t){o.items.push({score:1,id:t})})}u=t.getSortFunction(o,e);if(u)o.items.sort(u);o.total=o.items.length;if(typeof e.limit==="number"){o.items=o.items.slice(0,e.limit)}return o};var h=function(r,t){if(typeof r==="number"&&typeof t==="number"){return r>t?1:rt)return 1;if(t>r)return-1;return 0};var o=function(r,t){var e,n,i,o;for(e=1,n=arguments.length;e 0) {
 60 |             output += separator + '@' + empty;
 61 |             empty = 0;
 62 |             separator = ',';
 63 |           }
 64 | 
 65 |           output += separator + element;
 66 |           separator = ',';
 67 |         }
 68 |       }
 69 | 
 70 |       return output + ']';
 71 |     }
 72 | 
 73 |     var parse = function(str) {
 74 |       var arr = [];
 75 |       var stack = [arr];
 76 |       var currentIndex = 1;
 77 | 
 78 |       while(stack.length !== 0) {
 79 |         var currentArr = stack[stack.length - 1];
 80 |         var element = '';
 81 | 
 82 |         for(; currentIndex < str.length; currentIndex++) {
 83 |           var char = str[currentIndex];
 84 |           if(char === ',') {
 85 |             if(element.length !== 0) {
 86 |               if(element[0] === '@') {
 87 |                 var elementInt = parseInt(element.substring(1));
 88 |                 for(var i = 0; i < elementInt; i++) {
 89 |                   currentArr.push(undefined);
 90 |                 }
 91 |               } else {
 92 |                 currentArr.push(parseFloat(element));
 93 |               }
 94 |               element = '';
 95 |             }
 96 |           } else if(char === '[') {
 97 |             var childArr = [];
 98 |             currentArr.push(childArr);
 99 |             stack.push(childArr);
100 |             currentIndex++;
101 |             break;
102 |           } else if(char === ']') {
103 |             stack.pop();
104 |             currentIndex++;
105 |             break;
106 |           } else {
107 |             element += char;
108 |           }
109 |         }
110 | 
111 |         if(element.length !== 0) {
112 |           currentArr.push(parseInt(element));
113 |         }
114 |       }
115 | 
116 |       return arr;
117 |     }
118 | 
119 |     var getTerms = function(entry) {
120 |       if (entry.length === 0) {
121 |         return [];
122 |       }
123 | 
124 |       var terms = entry.split(whitespaceRE);
125 | 
126 |       if(terms[0].length === 0) {
127 |         terms.shift();
128 |       }
129 | 
130 |       if(terms[terms.length - 1].length === 0) {
131 |         terms.pop();
132 |       }
133 | 
134 |       return terms;
135 |     }
136 | 
137 |     var processEntry = function(entry) {
138 |       if(entry.length === 0) {
139 |         return entry;
140 |       } else {
141 |         var processors = config.processors;
142 | 
143 |         for(var i = 0; i < processors.length; i++) {
144 |           entry = processors[i](entry);
145 |         }
146 | 
147 |         return entry;
148 |       }
149 |     }
150 | 
151 |     var update = function(results, resultIndexes, increment, data) {
152 |       var relevance = data[1];
153 |       for(var i = 2; i < data.length; i++) {
154 |         var index = data[i];
155 |         var resultIndex = resultIndexes[index];
156 |         if(resultIndex === undefined) {
157 |           var lastIndex = results.length;
158 |           resultIndexes[index] = lastIndex;
159 |           results[lastIndex] = {
160 |             index: index,
161 |             score: relevance * increment
162 |           };
163 |         } else {
164 |           results[resultIndex].score += relevance * increment;
165 |         }
166 |       }
167 |     }
168 | 
169 |     var Wade = function(data) {
170 |       var search = function(query) {
171 |         var index = search.index;
172 |         var processed = processEntry(query);
173 |         var results = [];
174 |         var resultIndexes = {};
175 | 
176 |         if(processed.length === 0) {
177 |           return results;
178 |         } else {
179 |           var terms = getTerms(processed);
180 |           var termsLength = terms.length;
181 |           var exactTermsLength = termsLength - 1;
182 |           var increment = 1 / termsLength;
183 | 
184 |           exactOuter: for(var i = 0; i < exactTermsLength; i++) {
185 |             var term = terms[i];
186 |             var termLength = term.length - 1;
187 |             var node = index;
188 | 
189 |             for(var j = 0; j <= termLength; j++) {
190 |               var termOffset = node[0][0];
191 |               var termIndex = term.charCodeAt(j) + termOffset;
192 | 
193 |               if(termIndex < 1 || (termOffset === undefined && j === termLength) || node[termIndex] === undefined) {
194 |                 continue exactOuter;
195 |               }
196 | 
197 |               node = node[termIndex];
198 |             }
199 | 
200 |             var nodeData = node[0];
201 |             if(nodeData.length !== 1) {
202 |               update(results, resultIndexes, increment, nodeData);
203 |             }
204 |           }
205 | 
206 |           var lastTerm = terms[exactTermsLength];
207 |           var lastTermLength = lastTerm.length - 1;
208 |           var node$1 = index;
209 | 
210 |           for(var i$1 = 0; i$1 <= lastTermLength; i$1++) {
211 |             var lastTermOffset = node$1[0][0];
212 |             var lastTermIndex = lastTerm.charCodeAt(i$1) + lastTermOffset;
213 | 
214 |             if(lastTermIndex < 1 || (lastTermOffset === undefined && i$1 === lastTermLength) || node$1[lastTermIndex] === undefined) {
215 |               break;
216 |             }
217 | 
218 |             node$1 = node$1[lastTermIndex];
219 |           }
220 | 
221 |           if(node$1 !== undefined) {
222 |             var nodes = [node$1];
223 |             for(var i$2 = 0; i$2 < nodes.length; i$2++) {
224 |               var childNode = nodes[i$2];
225 |               var childNodeData = childNode[0];
226 | 
227 |               if(childNodeData.length !== 1) {
228 |                 update(results, resultIndexes, increment, childNodeData);
229 |               }
230 | 
231 |               for(var j$1 = 1; j$1 < childNode.length; j$1++) {
232 |                 var grandChildNode = childNode[j$1];
233 |                 if(grandChildNode !== undefined) {
234 |                   nodes.push(grandChildNode);
235 |                 }
236 |               }
237 |             }
238 |           }
239 | 
240 |           return results;
241 |         }
242 |       }
243 | 
244 |       if(Array.isArray(data)) {
245 |         search.index = Wade.index(data);
246 |       } else {
247 |         search.index = parse(data);
248 |       }
249 | 
250 |       return search;
251 |     }
252 | 
253 |     Wade.index = function(data) {
254 |       var dataLength = 0;
255 |       var ranges = {};
256 |       var processed = [];
257 | 
258 |       for(var i = 0; i < data.length; i++) {
259 |         var entry = processEntry(data[i]);
260 | 
261 |         if(entry.length !== 0) {
262 |           var terms = getTerms(entry);
263 |           var termsLength = terms.length;
264 | 
265 |           for(var j = 0; j < termsLength; j++) {
266 |             var term = terms[j];
267 |             var processedTerm = [];
268 |             var currentRanges = ranges;
269 | 
270 |             for(var n = 0; n < term.length; n++) {
271 |               var char = term.charCodeAt(n);
272 |               var highByte = char >>> 8;
273 |               var lowByte = char & 0xFF;
274 | 
275 |               if(highByte !== 0) {
276 |                 if(currentRanges.minimum === undefined || highByte < currentRanges.minimum) {
277 |                   currentRanges.minimum = highByte;
278 |                 }
279 | 
280 |                 if(currentRanges.maximum === undefined || highByte > currentRanges.maximum) {
281 |                   currentRanges.maximum = highByte;
282 |                 }
283 | 
284 |                 var nextRanges = currentRanges[highByte];
285 |                 if(nextRanges === undefined) {
286 |                   currentRanges = currentRanges[highByte] = {};
287 |                 } else {
288 |                   currentRanges = nextRanges;
289 |                 }
290 | 
291 |                 processedTerm.push(highByte);
292 |               }
293 | 
294 |               if(currentRanges.minimum === undefined || lowByte < currentRanges.minimum) {
295 |                 currentRanges.minimum = lowByte;
296 |               }
297 | 
298 |               if(currentRanges.maximum === undefined || lowByte > currentRanges.maximum) {
299 |                 currentRanges.maximum = lowByte;
300 |               }
301 | 
302 |               var nextRanges$1 = currentRanges[lowByte];
303 |               if(nextRanges$1 === undefined) {
304 |                 currentRanges = currentRanges[lowByte] = {};
305 |               } else {
306 |                 currentRanges = nextRanges$1;
307 |               }
308 | 
309 |               processedTerm.push(lowByte);
310 |             }
311 | 
312 |             processed.push(i);
313 |             processed.push(termsLength);
314 |             processed.push(processedTerm);
315 |           }
316 |         }
317 | 
318 |         dataLength++;
319 |       }
320 | 
321 |       var indexMinimum = ranges.minimum;
322 |       var indexMaximum = ranges.maximum;
323 |       var indexSize = 1;
324 |       var indexOffset;
325 | 
326 |       if(indexMinimum !== undefined && indexMaximum !== undefined) {
327 |         indexSize = indexMaximum - indexMinimum + 2;
328 |         indexOffset = 1 - indexMinimum;
329 |       }
330 | 
331 |       var nodeDataSets = [];
332 |       var index = new Array(indexSize);
333 |       index[0] = [indexOffset];
334 | 
335 |       for(var i$1 = 0; i$1 < processed.length; i$1 += 3) {
336 |         var dataIndex = processed[i$1];
337 |         var termsLength$1 = processed[i$1 + 1];
338 |         var processedTerm$1 = processed[i$1 + 2];
339 |         var processedTermLength = processedTerm$1.length - 1;
340 |         var node = index;
341 |         var termRanges = ranges;
342 | 
343 |         for(var j$1 = 0; j$1 < processedTermLength; j$1++) {
344 |           var char$1 = processedTerm$1[j$1];
345 |           var charIndex = char$1 + node[0][0];
346 |           var termNode = node[charIndex];
347 |           termRanges = termRanges[char$1];
348 | 
349 |           if(termNode === undefined) {
350 |             var termMinimum = termRanges.minimum;
351 |             var termMaximum = termRanges.maximum;
352 |             termNode = node[charIndex] = new Array(termMaximum - termMinimum + 2);
353 |             termNode[0] = [1 - termMinimum];
354 |           }
355 | 
356 |           node = termNode;
357 |         }
358 | 
359 |         var lastChar = processedTerm$1[processedTermLength];
360 |         var lastCharIndex = lastChar + node[0][0]
361 |         var lastTermNode = node[lastCharIndex];
362 |         termRanges = termRanges[lastChar];
363 | 
364 |         if(lastTermNode === undefined) {
365 |           var lastTermMinimum = termRanges.minimum;
366 |           var lastTermMaximum = termRanges.maximum;
367 |           var lastTermSize = 1;
368 |           var lastTermOffset = (void 0);
369 | 
370 |           if(lastTermMinimum !== undefined && lastTermMaximum !== undefined) {
371 |             lastTermSize = lastTermMaximum - lastTermMinimum + 2;
372 |             lastTermOffset = 1 - lastTermMinimum;
373 |           }
374 | 
375 |           lastTermNode = node[lastCharIndex] = new Array(lastTermSize);
376 |           nodeDataSets.push(lastTermNode[0] = [lastTermOffset, 1 / termsLength$1, dataIndex]);
377 |         } else {
378 |           var nodeData = lastTermNode[0];
379 | 
380 |           if(nodeData.length === 1) {
381 |             nodeData.push(1 / termsLength$1);
382 |             nodeData.push(dataIndex);
383 |             nodeDataSets.push(nodeData);
384 |           } else {
385 |             nodeData[1] += 1 / termsLength$1;
386 |             nodeData.push(dataIndex);
387 |           }
388 |         }
389 |       }
390 | 
391 |       for(var i$2 = 0; i$2 < nodeDataSets.length; i$2++) {
392 |         var nodeData$1 = nodeDataSets[i$2];
393 |         nodeData$1[1] = 1.5 - (nodeData$1[1] / dataLength);
394 |       }
395 | 
396 |       return index;
397 |     }
398 | 
399 |     Wade.save = function(search) {
400 |       return stringify(search.index);
401 |     }
402 | 
403 |     Wade.config = config;
404 | 
405 |     Wade.version = "0.3.3";
406 | 
407 |     return Wade;
408 | }));
409 | 


--------------------------------------------------------------------------------
/dist/uFuzzy.d.ts:
--------------------------------------------------------------------------------
  1 | declare class uFuzzy {
  2 | 	constructor(opts?: uFuzzy.Options);
  3 | 
  4 | 	/** search API composed of filter/info/sort, with a info/ranking threshold (1e3) and fast outOfOrder impl */
  5 | 	search(
  6 | 		haystack: string[],
  7 | 		needle: string,
  8 | 		/** limit how many terms will be permuted, default = 0; 5 will result in up to 5! (120) search iterations. be careful with this! */
  9 | 		outOfOrder?: number,
 10 | 		/** default = 1e3 */
 11 | 		infoThresh?: number,
 12 | 		preFiltered?: uFuzzy.HaystackIdxs | null
 13 | 	): uFuzzy.SearchResult;
 14 | 
 15 | 	/** initial haystack filter, can accept idxs from previous prefix/typeahead match as optimization */
 16 | 	filter(
 17 | 		haystack: string[],
 18 | 		needle: string,
 19 | 		idxs?: uFuzzy.HaystackIdxs
 20 | 	): uFuzzy.HaystackIdxs | null;
 21 | 
 22 | 	/** collects stats about pre-filtered matches, does additional filtering based on term boundary settings, finds highlight ranges */
 23 | 	info(
 24 | 		idxs: uFuzzy.HaystackIdxs,
 25 | 		haystack: string[],
 26 | 		needle: string
 27 | 	): uFuzzy.Info;
 28 | 
 29 | 	/** performs final result sorting via Array.sort(), relying on Info */
 30 | 	sort(
 31 | 		info: uFuzzy.Info,
 32 | 		haystack: string[],
 33 | 		needle: string
 34 | 	): uFuzzy.InfoIdxOrder;
 35 | 
 36 | 	/** utility for splitting needle into terms following defined interSplit/intraSplit opts. useful for out-of-order permutes */
 37 | 	split(needle: string, keepCase?: boolean): uFuzzy.Terms;
 38 | 
 39 | 	/** util for creating out-of-order permutations of a needle terms array */
 40 | 	static permute(arr: unknown[]): unknown[][];
 41 | 
 42 | 	/** util for replacing common diacritics/accents */
 43 | 	static latinize(strings: T): T;
 44 | 
 45 | 	/** util for highlighting matched substr parts of a result */
 46 | 	static highlight(
 47 | 		match: string,
 48 | 		ranges: number[],
 49 | 
 50 | 		mark?: (part: string, matched: boolean) => TMarkedPart,
 51 | 		accum?: TAccum,
 52 | 		append?: (accum: TAccum, part: TMarkedPart) => TAccum | undefined
 53 | 	): TAccum;
 54 | }
 55 | 
 56 | export default uFuzzy;
 57 | 
 58 | declare namespace uFuzzy {
 59 | 	/** needle's terms */
 60 | 	export type Terms = string[];
 61 | 
 62 | 	/** subset of idxs of a haystack array */
 63 | 	export type HaystackIdxs = number[];
 64 | 
 65 | 	/** sorted order in which info facets should be iterated */
 66 | 	export type InfoIdxOrder = number[];
 67 | 
 68 | 	export type AbortedResult = [null, null, null];
 69 | 
 70 | 	export type FilteredResult = [uFuzzy.HaystackIdxs, null, null];
 71 | 
 72 | 	export type RankedResult = [
 73 | 		uFuzzy.HaystackIdxs,
 74 | 		uFuzzy.Info,
 75 | 		uFuzzy.InfoIdxOrder
 76 | 	];
 77 | 
 78 | 	export type SearchResult = FilteredResult | RankedResult | AbortedResult;
 79 | 
 80 | 	/** partial RegExp */
 81 | 	type PartialRegExp = string;
 82 | 
 83 | 	/** what should be considered acceptable term bounds */
 84 | 	export const enum BoundMode {
 85 | 		/** will match 'man' substr anywhere. e.g. tasmania */
 86 | 		Any = 0,
 87 | 		/** will match 'man' at whitespace, punct, case-change, and alpha-num boundaries. e.g. mantis, SuperMan, fooManBar, 0007man */
 88 | 		Loose = 1,
 89 | 		/** will match 'man' at whitespace, punct boundaries only. e.g. mega man, walk_man, man-made, foo.man.bar */
 90 | 		Strict = 2,
 91 | 	}
 92 | 
 93 | 	export const enum IntraMode {
 94 | 		/** allows any number of extra char insertions within a term, but all term chars must be present for a match */
 95 | 		MultiInsert = 0,
 96 | 		/** allows for a single-char substitution, transposition, insertion, or deletion within terms (excluding first and last chars) */
 97 | 		SingleError = 1,
 98 | 	}
 99 | 
100 | 	export type IntraSliceIdxs = [from: number, to: number];
101 | 
102 | 	type CompareFn = (a: string, b: string) => number;
103 | 
104 | 	export interface Options {
105 | 		// whether regexps use a /u unicode flag
106 | 		unicode?: boolean; // false
107 | 
108 | 		/** @deprecated renamed to opts.alpha */
109 | 		letters?: PartialRegExp | null;     // a-z
110 | 
111 | 		// regexp character class [] of chars which should be treated as letters (case insensitive)
112 | 		alpha?: PartialRegExp | null;       // a-z
113 | 
114 | 		/** term segmentation & punct/whitespace merging */
115 | 		interSplit?: PartialRegExp;         // '[^A-Za-z\\d']+'
116 | 		intraSplit?: PartialRegExp | null;  // '[a-z][A-Z]'
117 | 
118 | 		/** inter bounds that will be used to increase lft2/rgt2 info counters */
119 | 		interBound?: PartialRegExp | null;  // '[^A-Za-z\\d]'
120 | 		/** intra bounds that will be used to increase lft1/rgt1 info counters */
121 | 		intraBound?: PartialRegExp | null;  // '[A-Za-z][0-9]|[0-9][A-Za-z]|[a-z][A-Z]'
122 | 
123 | 		/** inter-term modes, during .info() can discard matches when bounds conditions are not met */
124 | 		interLft?: BoundMode;        // 0
125 | 		interRgt?: BoundMode;        // 0
126 | 
127 | 		/** allowance between terms */
128 | 		interChars?: PartialRegExp;  // '.'
129 | 		interIns?: number;           // Infinity
130 | 
131 | 		/** allowance between chars within terms */
132 | 		intraChars?: PartialRegExp;  // '[a-z\\d]'
133 | 		intraIns?: number;           // 0
134 | 
135 | 		/** contractions detection */
136 | 		intraContr?: PartialRegExp;  // "'[a-z]{1,2}\\b"
137 | 
138 | 		/** error tolerance mode within terms. will clamp intraIns to 1 when set to SingleError */
139 | 		intraMode?: IntraMode;       // 0
140 | 
141 | 		/** which part of each term should tolerate errors (when intraMode: 1) */
142 | 		intraSlice?: IntraSliceIdxs; // [1, Infinity]
143 | 
144 | 		/** max substitutions (when intraMode: 1) */
145 | 		intraSub?: 0 | 1; // 0
146 | 		/** max transpositions (when intraMode: 1) */
147 | 		intraTrn?: 0 | 1; // 0
148 | 		/** max omissions/deletions (when intraMode: 1) */
149 | 		intraDel?: 0 | 1; // 0
150 | 
151 | 		/** can dynamically adjust error tolerance rules per term in needle (when intraMode: 1) */
152 | 		intraRules?: (term: string) => {
153 | 			intraSlice?: IntraSliceIdxs;
154 | 			intraIns: 0 | 1;
155 | 			intraSub: 0 | 1;
156 | 			intraTrn: 0 | 1;
157 | 			intraDel: 0 | 1;
158 | 		};
159 | 
160 | 		/** post-filters matches during .info() based on cmp of term in needle vs partial match */
161 | 		intraFilt?: (term: string, match: string, index: number) => boolean; // should this also accept WIP info?
162 | 
163 | 		/** default: toLocaleUpperCase() */
164 | 		toUpper?: (str: string) => string;
165 | 
166 | 		/** default: toLocaleLowerCase() */
167 | 		toLower?: (str: string) => string;
168 | 
169 | 		/** final sorting cmp when all other match metrics are equal */
170 | 		compare?: CompareFn;
171 | 
172 | 		sort?: (info: Info, haystack: string[], needle: string, compare?: CompareFn) => InfoIdxOrder;
173 | 	}
174 | 
175 | 	export interface Info {
176 | 		/** matched idxs from haystack */
177 | 		idx: HaystackIdxs;
178 | 
179 | 		/** match offsets */
180 | 		start: number[];
181 | 
182 | 		/** number of left BoundMode.Strict term boundaries found */
183 | 		interLft2: number[];
184 | 		/** number of right BoundMode.Strict term boundaries found */
185 | 		interRgt2: number[];
186 | 		/** number of left BoundMode.Loose term boundaries found */
187 | 		interLft1: number[];
188 | 		/** number of right BoundMode.Loose term boundaries found */
189 | 		interRgt1: number[];
190 | 
191 | 		/** total number of extra chars matched within all terms. higher = matched terms have more fuzz in them */
192 | 		intraIns: number[];
193 | 		/** total number of chars found in between matched terms. higher = terms are more sparse, have more fuzz in between them */
194 | 		interIns: number[];
195 | 
196 | 		/** total number of matched contiguous chars (substrs but not necessarily full terms) */
197 | 		chars: number[];
198 | 
199 | 		/** number of exactly-matched terms (intra = 0) where both lft and rgt landed on a BoundMode.Loose or BoundMode.Strict boundary */
200 | 		terms: number[];
201 | 
202 | 		/** number of needle terms with case-sensitive partial matches */
203 | 		cases: number[];
204 | 
205 | 		/** offset ranges within match for highlighting: [startIdx0, endIdx0, startIdx1, endIdx1,...] */
206 | 		ranges: number[][];
207 | 	}
208 | }
209 | 
210 | export as namespace uFuzzy;
211 | 


--------------------------------------------------------------------------------
/dist/uFuzzy.iife.min.js:
--------------------------------------------------------------------------------
1 | /*! https://github.com/leeoniya/uFuzzy (v1.0.18) */
2 | var uFuzzy=function(){"use strict";const e=(e,t)=>e>t?1:t>e?-1:0,t=1/0,l=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),n="eexxaacctt",r=/\p{P}/gu,i=["en",{numeric:!0,sensitivity:"base"}],s=(e,t,l)=>e.replace("A-Z",t).replace("a-z",l),a={unicode:!1,alpha:null,interSplit:"[^A-Za-z\\d']+",intraSplit:"[a-z][A-Z]",interBound:"[^A-Za-z\\d]",intraBound:"[A-Za-z]\\d|\\d[A-Za-z]|[a-z][A-Z]",interLft:0,interRgt:0,interChars:".",interIns:t,intraChars:"[a-z\\d']",intraIns:null,intraContr:"'[a-z]{1,2}\\b",intraMode:0,intraSlice:[1,t],intraSub:null,intraTrn:null,intraDel:null,intraFilt:()=>!0,toUpper:e=>e.toLocaleUpperCase(),toLower:e=>e.toLocaleLowerCase(),compare:null,sort:(t,l,n,r=e)=>{let{idx:i,chars:s,terms:a,interLft2:u,interLft1:g,start:f,intraIns:c,interIns:h,cases:o}=t;return i.map(((e,t)=>t)).sort(((e,t)=>s[t]-s[e]||c[e]-c[t]||a[t]+u[t]+.5*g[t]-(a[e]+u[e]+.5*g[e])||h[e]-h[t]||f[e]-f[t]||o[t]-o[e]||r(l[i[e]],l[i[t]])))}},u=(e,l)=>0==l?"":1==l?e+"??":l==t?e+"*?":e+`{0,${l}}?`,g="(?:\\b|_)";function f(t){t=Object.assign({},a,t);let{unicode:f,interLft:c,interRgt:o,intraMode:p,intraSlice:d,intraIns:m,intraSub:x,intraTrn:b,intraDel:R,intraContr:A,intraSplit:I,interSplit:S,intraBound:y,interBound:z,intraChars:E,toUpper:L,toLower:k,compare:C}=t;m??=p,x??=p,b??=p,R??=p,C??="undefined"==typeof Intl?e:new Intl.Collator(...i).compare;let j=t.letters??t.alpha;if(null!=j){let e=L(j),t=k(j);S=s(S,e,t),I=s(I,e,t),z=s(z,e,t),y=s(y,e,t),E=s(E,e,t),A=s(A,e,t)}let Z=f?"u":"";const $='".+?"',w=RegExp($,"gi"+Z),M=RegExp(`(?:\\s+|^)-(?:${E}+|${$})`,"gi"+Z);let{intraRules:B}=t;null==B&&(B=e=>{let t=a.intraSlice,l=0,n=0,r=0,i=0;if(/[^\d]/.test(e)){let s=e.length;s>4?(t=d,l=m,n=x,r=b,i=R):3>s||(r=Math.min(b,1),4==s&&(l=Math.min(m,1)))}return{intraSlice:t,intraIns:l,intraSub:n,intraTrn:r,intraDel:i}});let D=!!I,T=RegExp(I,"g"+Z),U=RegExp(S,"g"+Z),F=RegExp("^"+S+"|"+S+"$","g"+Z),O=RegExp(A,"gi"+Z);const v=(e,t=!1)=>{let l=[];e=(e=e.replace(w,(e=>(l.push(e),n)))).replace(F,""),t||(e=k(e)),D&&(e=e.replace(T,(e=>e[0]+" "+e[1])));let r=0;return e.split(U).filter((e=>""!=e)).map((e=>e===n?l[r++]:e))},N=/[^\d]+|\d+/g,P=(e,n=0,r=!1)=>{let i=v(e);if(0==i.length)return[];let s,a=Array(i.length).fill("");if(i=i.map(((e,t)=>e.replace(O,(e=>(a[t]=e,""))))),1==p)s=i.map(((e,t)=>{if('"'===e[0])return l(e.slice(1,-1));let n="";for(let l of e.matchAll(N)){let e=l[0],{intraSlice:r,intraIns:i,intraSub:s,intraTrn:g,intraDel:f}=B(e);if(i+s+g+f==0)n+=e+a[t];else{let[l,c]=r,h=e.slice(0,l),o=e.slice(c),p=e.slice(l,c);1==i&&1==h.length&&h!=p[0]&&(h+="(?!"+h+")");let d=p.length,m=[e];if(s)for(let e=0;d>e;e++)m.push(h+p.slice(0,e)+E+p.slice(e+1)+o);if(g)for(let e=0;d-1>e;e++)p[e]!=p[e+1]&&m.push(h+p.slice(0,e)+p[e+1]+p[e]+p.slice(e+2)+o);if(f)for(let e=0;d>e;e++)m.push(h+p.slice(0,e+1)+"?"+p.slice(e+1)+o);if(i){let e=u(E,1);for(let t=0;d>t;t++)m.push(h+p.slice(0,t)+e+p.slice(t)+o)}n+="(?:"+m.join("|")+")"+a[t]}}return n}));else{let e=u(E,m);2==n&&m>0&&(e=")("+e+")("),s=i.map(((t,n)=>'"'===t[0]?l(t.slice(1,-1)):t.split("").map(((e,t,l)=>(1==m&&0==t&&l.length>1&&e!=l[t+1]&&(e+="(?!"+e+")"),e))).join(e)+a[n]))}let f=2==c?g:"",h=2==o?g:"",d=h+u(t.interChars,t.interIns)+f;return n>0?r?s=f+"("+s.join(")"+h+"|"+f+"(")+")"+h:(s="("+s.join(")("+d+")(")+")",s="(.??"+f+")"+s+"("+h+".*)"):(s=s.join(d),s=f+s+h),[RegExp(s,"i"+Z),i,a]},_=(e,t,l)=>{let[n]=P(t);if(null==n)return null;let r=[];if(null!=l)for(let t=0;l.length>t;t++){let i=l[t];n.test(e[i])&&r.push(i)}else for(let t=0;e.length>t;t++)n.test(e[t])&&r.push(t);return r};let q=!!y,G=RegExp(z,Z),H=RegExp(y,Z);const J=(e,l,n)=>{let[r,i,s]=P(n,1),a=v(n,!0),[u]=P(n,2),g=i.length,f=Array(g),h=Array(g);for(let e=0;g>e;e++){let t=i[e],l=a[e],n='"'==t[0]?t.slice(1,-1):t+s[e],r='"'==l[0]?l.slice(1,-1):l+s[e];f[e]=n,h[e]=r}let p=e.length,d=Array(p).fill(0),m={idx:Array(p),start:d.slice(),chars:d.slice(),cases:d.slice(),terms:d.slice(),interIns:d.slice(),intraIns:d.slice(),interLft2:d.slice(),interRgt2:d.slice(),interLft1:d.slice(),interRgt1:d.slice(),ranges:Array(p)},x=1==c||1==o,b=0;for(let n=0;e.length>n;n++){let i=l[e[n]],s=i.match(r),a=s.index+s[1].length,p=a,d=!1,R=0,A=0,I=0,S=0,y=0,z=0,E=0,L=0,C=0,j=[];for(let e=0,l=2;g>e;e++,l+=2){let n=k(s[l]),r=f[e],u=r.length,m=n.length,b=n==r;if(s[l]==h[e]&&E++,!b&&s[l+1].length>=u){let t=k(s[l+1]).indexOf(r);t>-1&&(j.push(p,m,t,u),p+=K(s,l,t,u),n=r,m=u,b=!0,0==e&&(a=p))}if(x||b){let t=p-1,g=p+m,f=!1,h=!1;if(-1==t||G.test(i[t]))b&&R++,f=!0;else{if(2==c){d=!0;break}if(q&&H.test(i[t]+i[t+1]))b&&A++,f=!0;else if(1==c){let t=s[l+1],g=p+m;if(t.length>=u){let c,h=0,o=!1,d=RegExp(r,"ig"+Z);for(;c=d.exec(t);){h=c.index;let e=g+h,t=e-1;if(-1==t||G.test(i[t])){R++,o=!0;break}if(H.test(i[t]+i[e])){A++,o=!0;break}}o&&(f=!0,j.push(p,m,h,u),p+=K(s,l,h,u),n=r,m=u,b=!0,0==e&&(a=p))}if(!f){d=!0;break}}}if(g==i.length||G.test(i[g]))b&&I++,h=!0;else{if(2==o){d=!0;break}if(q&&H.test(i[g-1]+i[g]))b&&S++,h=!0;else if(1==o){d=!0;break}}b&&(y+=u,f&&h&&z++)}if(m>u&&(C+=m-u),e>0&&(L+=s[l-1].length),!t.intraFilt(r,n,p)){d=!0;break}g-1>e&&(p+=m+s[l+1].length)}if(!d){m.idx[b]=e[n],m.interLft2[b]=R,m.interLft1[b]=A,m.interRgt2[b]=I,m.interRgt1[b]=S,m.chars[b]=y,m.terms[b]=z,m.cases[b]=E,m.interIns[b]=L,m.intraIns[b]=C,m.start[b]=a;let t=i.match(u),l=t.index+t[1].length,r=j.length,s=r>0?0:1/0,g=r-4;for(let e=2;t.length>e;)if(s>g||j[s]!=l)l+=t[e].length,e++;else{let n=j[s+1],r=j[s+2],i=j[s+3],a=e,u="";for(let e=0;n>e;a++)u+=t[a],e+=t[a].length;t.splice(e,a-e,u),l+=K(t,e,r,i),s+=4}l=t.index+t[1].length;let f=m.ranges[b]=[],c=l,h=l;for(let e=2;t.length>e;e++){let n=t[e].length;l+=n,e%2==0?h=l:n>0&&(f.push(c,h),c=h=l)}h>c&&f.push(c,h),b++}}if(e.length>b)for(let e in m)m[e]=m[e].slice(0,b);return m},K=(e,t,l,n)=>{let r=e[t]+e[t+1].slice(0,l);return e[t-1]+=r,e[t]=e[t+1].slice(l,l+n),e[t+1]=e[t+1].slice(l+n),r.length};return{search:(...e)=>((e,n,i,s=1e3,a)=>{i=i?!0===i?5:i:0;let u=null,g=null,f=[];n=n.replace(M,(e=>{let t=e.trim().slice(1);return t='"'===t[0]?l(t.slice(1,-1)):t.replace(r,""),""!=t&&f.push(t),""}));let c,o=v(n);if(f.length>0){if(c=RegExp(f.join("|"),"i"+Z),0==o.length){let t=[];for(let l=0;e.length>l;l++)c.test(e[l])||t.push(l);return[t,null,null]}}else if(0==o.length)return[null,null,null];if(i>0){let t=v(n);if(t.length>1){let l=t.slice().sort(((e,t)=>t.length-e.length));for(let t=0;l.length>t;t++){if(0==a?.length)return[[],null,null];a=_(e,l[t],a)}if(t.length>i)return[a,null,null];u=h(t).map((e=>e.join(" "))),g=[];let n=new Set;for(let t=0;u.length>t;t++)if(a.length>n.size){let l=a.filter((e=>!n.has(e))),r=_(e,u[t],l);for(let e=0;r.length>e;e++)n.add(r[e]);g.push(r)}else g.push([])}}null==u&&(u=[n],g=[a?.length>0?a:_(e,n)]);let p=null,d=null;if(f.length>0&&(g=g.map((t=>t.filter((t=>!c.test(e[t])))))),s>=g.reduce(((e,t)=>e+t.length),0)){p={},d=[];for(let l=0;g.length>l;l++){let n=g[l];if(null==n||0==n.length)continue;let r=u[l],i=J(n,e,r),s=t.sort(i,e,r,C);if(l>0)for(let e=0;s.length>e;e++)s[e]+=d.length;for(let e in i)p[e]=(p[e]??[]).concat(i[e]);d=d.concat(s)}}return[[].concat(...g),p,d]})(...e),split:v,filter:_,info:J,sort:t.sort}}const c=(()=>{let e={A:"ÁÀÃÂÄĄ",a:"áàãâäą",E:"ÉÈÊËĖ",e:"éèêëę",I:"ÍÌÎÏĮ",i:"íìîïį",O:"ÓÒÔÕÖ",o:"óòôõö",U:"ÚÙÛÜŪŲ",u:"úùûüūų",C:"ÇČĆ",c:"çčć",L:"Ł",l:"ł",N:"ÑŃ",n:"ñń",S:"ŠŚ",s:"šś",Z:"ŻŹ",z:"żź"},t=new Map,l="";for(let n in e)e[n].split("").forEach((e=>{l+=e,t.set(e,n)}));let n=RegExp(`[${l}]`,"g"),r=e=>t.get(e);return e=>{if("string"==typeof e)return e.replace(n,r);let t=Array(e.length);for(let l=0;e.length>l;l++)t[l]=e[l].replace(n,r);return t}})();function h(e){let t,l,n=(e=e.slice()).length,r=[e.slice()],i=Array(n).fill(0),s=1;for(;n>s;)s>i[s]?(t=s%2&&i[s],l=e[s],e[s]=e[t],e[t]=l,++i[s],s=1,r.push(e.slice())):(i[s]=0,++s);return r}const o=(e,t)=>t?`${e}`:e,p=(e,t)=>e+t;return f.latinize=c,f.permute=e=>h([...Array(e.length).keys()]).sort(((e,t)=>{for(let l=0;e.length>l;l++)if(e[l]!=t[l])return e[l]-t[l];return 0})).map((t=>t.map((t=>e[t])))),f.highlight=function(e,t,l=o,n="",r=p){n=r(n,l(e.substring(0,t[0]),!1))??n;for(let i=0;t.length>i;i+=2)n=r(n,l(e.substring(t[i],t[i+1]),!0))??n,t.length-3>i&&(n=r(n,l(e.substring(t[i+1],t[i+2]),!1))??n);return r(n,l(e.substring(t[t.length-1]),!1))??n},f}();
3 | 


--------------------------------------------------------------------------------
/jsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 |   "compilerOptions": {
3 |     "checkJs": true,
4 |     "target": "ES2020"
5 |   },
6 |   "include": ["src/*", "dist/*"],
7 |   "exclude": ["node_modules"]
8 | }


--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
 1 | {
 2 |   "name": "@leeoniya/ufuzzy",
 3 |   "version": "1.0.18",
 4 |   "description": "A tiny, efficient fuzzy matcher that doesn't suck",
 5 |   "main": "./dist/uFuzzy.cjs",
 6 |   "module": "./dist/uFuzzy.mjs",
 7 |   "types": "./dist/uFuzzy.d.ts",
 8 |   "type": "module",
 9 |   "scripts": {
10 |     "build": "rollup -c",
11 |     "test": "echo \"Error: no test specified\" && exit 1"
12 |   },
13 |   "repository": {
14 |     "type": "git",
15 |     "url": "git+https://github.com/leeoniya/uFuzzy.git"
16 |   },
17 |   "files": [
18 |     "package.json",
19 |     "README.md",
20 |     "LICENSE",
21 |     "dist"
22 |   ],
23 |   "keywords": [
24 |     "micro",
25 |     "fast",
26 |     "fuzzy",
27 |     "match",
28 |     "search",
29 |     "filter",
30 |     "hint",
31 |     "autocomplete",
32 |     "typeahead",
33 |     "sort"
34 |   ],
35 |   "author": "Leon Sorokin ",
36 |   "license": "MIT",
37 |   "bugs": {
38 |     "url": "https://github.com/leeoniya/uFuzzy/issues"
39 |   },
40 |   "homepage": "https://github.com/leeoniya/uFuzzy#readme",
41 |   "devDependencies": {
42 |     "@rollup/plugin-terser": "^0.4.4",
43 |     "rollup": "^4.30.1"
44 |   }
45 | }
46 | 


--------------------------------------------------------------------------------
/rollup.config.js:
--------------------------------------------------------------------------------
  1 | import * as fs from 'fs';
  2 | 
  3 | import terser from '@rollup/plugin-terser';
  4 | 
  5 | const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
  6 | const ver = "v" + pkg.version;
  7 | const urlVer = "https://github.com/leeoniya/uFuzzy (" + ver + ")";
  8 | const banner = [
  9 | 	"/**",
 10 | 	"* Copyright (c) " + new Date().getFullYear() + ", Leon Sorokin",
 11 | 	"* All rights reserved. (MIT Licensed)",
 12 | 	"*",
 13 | 	"* uFuzzy.js (μFuzzy)",
 14 | 	"* A tiny, efficient fuzzy matcher that doesn't suck",
 15 | 	"* " + urlVer,
 16 | 	"*/",
 17 | 	"",
 18 | ].join("\n");
 19 | 
 20 | function bannerlessESM() {
 21 | 	return {
 22 | 		name: 'stripBanner',
 23 | 		resolveId(importee) {
 24 | 			if (importee == 'uFuzzy')
 25 | 				return importee;
 26 | 			return null;
 27 | 		},
 28 | 		load(id) {
 29 | 			if (id == 'uFuzzy')
 30 | 				return fs.readFileSync('./dist/uFuzzy.mjs', 'utf8').replace(/\/\*\*.*?\*\//gms, '');
 31 | 			return null;
 32 | 		}
 33 | 	};
 34 | }
 35 | 
 36 | const terserOpts = {
 37 | 	compress: {
 38 | 		inline: 0,
 39 | 		passes: 2,
 40 | 		keep_fargs: false,
 41 | 		pure_getters: true,
 42 | 		unsafe: true,
 43 | 		unsafe_comps: true,
 44 | 		unsafe_math: true,
 45 | 		unsafe_undefined: true,
 46 | 	},
 47 | 	output: {
 48 | 		comments: /^!/
 49 | 	}
 50 | };
 51 | 
 52 | export default [
 53 | 	{
 54 | 		input: './src/uFuzzy.mjs',
 55 | 		output: {
 56 | 			name: 'uFuzzy',
 57 | 			file: './dist/uFuzzy.mjs',
 58 | 			format: 'es',
 59 | 			banner,
 60 | 		},
 61 | 	},
 62 | 	{
 63 | 		input: './src/uFuzzy.mjs',
 64 | 		output: {
 65 | 			name: 'uFuzzy',
 66 | 			file: './dist/uFuzzy.cjs',
 67 | 			format: 'cjs',
 68 | 			exports: "auto",
 69 | 			banner,
 70 | 		},
 71 | 	},
 72 | 	{
 73 | 		input: 'uFuzzy',
 74 | 		output: {
 75 | 			name: 'uFuzzy',
 76 | 			file: './dist/uFuzzy.iife.js',
 77 | 			format: 'iife',
 78 | 			esModule: false,
 79 | 			banner,
 80 | 		},
 81 | 		plugins: [
 82 | 			bannerlessESM(),
 83 | 		]
 84 | 	},
 85 | 	{
 86 | 		input: 'uFuzzy',
 87 | 		output: {
 88 | 			name: 'uFuzzy',
 89 | 			file: './dist/uFuzzy.iife.min.js',
 90 | 			format: 'iife',
 91 | 			esModule: false,
 92 | 			banner: "/*! " + urlVer + " */",
 93 | 		},
 94 | 		plugins: [
 95 | 			bannerlessESM(),
 96 | 			terser(terserOpts),
 97 | 		]
 98 | 	},
 99 | ];
100 | 


--------------------------------------------------------------------------------
/uFuzzy.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leeoniya/uFuzzy/0c8bc57d1c1150307f1a61ce27c4b843bf9a0ee3/uFuzzy.png


--------------------------------------------------------------------------------