forked from krisk/Fuse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuse.min.js
More file actions
13 lines (13 loc) · 2.4 KB
/
Copy pathfuse.min.js
File metadata and controls
13 lines (13 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
/**
* Fuse - Lightweight fuzzy-search
*
* Copyright (c) 2012 Kirollos Risk <kirollos@gmail.com>.
* All Rights Reserved. Apache Software License 2.0
*
* http://www.apache.org/licenses/LICENSE-2.0
*/
(function(){function w(e,b){function n(e,c){var d=e/a,b=Math.abs(g-c);return f?d+b/f:b?1:d}b=b||{};var g=b.location||0,f=b.distance||100,y=b.threshold||0.6;e=b.caseSensitive?e:e.toLowerCase();var a=e.length;if(32<a)throw Error("Pattern length is too long");var s=1<<a-1,q=function(){for(var b={},c=0,c=0;c<a;c++)b[e.charAt(c)]=0;for(c=0;c<a;c++)b[e.charAt(c)]|=1<<e.length-c-1;return b}();this.search=function(f){f=b.caseSensitive?f:f.toLowerCase();if(e===f)return{isMatch:!0,score:0};var c,d,r=f.length,
l=y,k=f.indexOf(e,g),p,h,t=a+r,u,m,v=1,w=[];-1!=k&&(l=Math.min(n(0,k),l),k=f.lastIndexOf(e,g+a),-1!=k&&(l=Math.min(n(0,k),l)));k=-1;for(c=0;c<a;c++){p=0;for(h=t;p<h;)n(c,g+h)<=l?p=h:t=h,h=Math.floor((t-p)/2+p);t=h;p=Math.max(1,g-h+1);d=Math.min(g+h,r)+a;h=Array(d+2);for(h[d+1]=(1<<c)-1;d>=p;d--)if(m=q[f.charAt(d-1)],h[d]=0===c?(h[d+1]<<1|1)&m:(h[d+1]<<1|1)&m|(u[d+1]|u[d])<<1|1|u[d+1],h[d]&s&&(v=n(c,d-1),v<=l))if(l=v,k=d-1,w.push(k),k>g)p=Math.max(1,2*g-k);else break;if(n(c+1,g)>l)break;u=h}return{isMatch:0<=
k,score:v}}}function m(e,b){this.data=e;b=b||{};var n=b.keys||[];this.search=function(g){function f(a,c,b){void 0!==a&&null!==a&&"string"===typeof a&&(r=m.search(a),r.isMatch&&((p=k[b])?p.score=Math.min(p.score,r.score):(k[b]={item:c,score:r.score},l.push(k[b]))))}var m=new w(g,b),a=z(e),s=a.length,q=-1,x=n.length,c,d,r,l=[],k={},p;g=[];if("string"===typeof e[a[0]])for(;++q<s;)f(e[a[q]],q,q);else for(;++q<s;)for(d=e[a[q]],c=-1;++c<x;)f(d[n[c]],d,q);l.sort(function(a,b){return a.score-b.score});s=
l.length;for(a=0;a<s;a++)g.push(b.id?l[a].item[b.id]:l[a].item);return g}}var z=Object.keys||function(){var e=Object.prototype.hasOwnProperty,b=!{toString:null}.propertyIsEnumerable("toString"),n="toString toLocaleString valueOf hasOwnProperty isPrototypeOf propertyIsEnumerable constructor".split(" "),g=n.length;return function(f){if("object"!==typeof f&&("function"!==typeof f||null===f))throw new TypeError("Object.keys called on non-object");var m=[],a;for(a in f)e.call(f,a)&&m.push(a);if(b)for(a=
0;a<g;a++)e.call(f,n[a])&&m.push(n[a]);return m}}();"undefined"!==typeof module&&"undefined"!==typeof module.exports?"function"===typeof module.setExports?module.setExports(m):module.exports=m:window.Fuse=m})();