itemsjs
Version:
Created to perform fast search on small json dataset (up to 1000 elements).
1 lines • 57.1 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t||self).itemsjs=e()}(this,function(){var t="object"==typeof global&&global&&global.Object===Object&&global,e="object"==typeof self&&self&&self.Object===Object&&self,r=t||e||Function("return this")(),n=r.Symbol,o=Object.prototype,i=o.hasOwnProperty,s=o.toString,a=n?n.toStringTag:void 0,u=Object.prototype.toString,c="[object Null]",f="[object Undefined]",h=n?n.toStringTag:void 0;function l(t){return null==t?void 0===t?f:c:h&&h in Object(t)?function(t){var e=i.call(t,a),r=t[a];try{t[a]=void 0;var n=!0}catch(t){}var o=s.call(t);return n&&(e?t[a]=r:delete t[a]),o}(t):function(t){return u.call(t)}(t)}function d(t){return null!=t&&"object"==typeof t}var p="[object Symbol]";function w(t){return"symbol"==typeof t||d(t)&&l(t)==p}function g(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r<n;)o[r]=e(t[r],r,t);return o}var v=Array.isArray,y=1/0,_=n?n.prototype:void 0,b=_?_.toString:void 0;function m(t){if("string"==typeof t)return t;if(v(t))return g(t,m)+"";if(w(t))return b?b.call(t):"";var e=t+"";return"0"==e&&1/t==-y?"-0":e}function j(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function S(t){return t}var x="[object AsyncFunction]",O="[object Function]",k="[object GeneratorFunction]",A="[object Proxy]";function E(t){if(!j(t))return!1;var e=l(t);return e==O||e==k||e==x||e==A}var z,F=r["__core-js_shared__"],P=(z=/[^.]+$/.exec(F&&F.keys&&F.keys.IE_PROTO||""))?"Symbol(src)_1."+z:"",T=Function.prototype.toString;function I(t){if(null!=t){try{return T.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var M=/^\[object .+?Constructor\]$/,N=RegExp("^"+Function.prototype.toString.call(Object.prototype.hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function $(t,e){var r=function(t,e){return null==t?void 0:t[e]}(t,e);return function(t){return!(!j(t)||(e=t,P&&P in e))&&(E(t)?N:M).test(I(t));var e}(r)?r:void 0}var W,C,D,V=$(r,"WeakMap"),R=Object.create,U=function(){function t(){}return function(e){if(!j(e))return{};if(R)return R(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}(),q=Date.now,L=function(){try{var t=$(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),B=L,J=B?function(t,e){return B(t,"toString",{configurable:!0,enumerable:!1,value:(r=e,function(){return r}),writable:!0});var r}:S,H=(W=J,C=0,D=0,function(){var t=q(),e=16-(t-D);if(D=t,e>0){if(++C>=800)return arguments[0]}else C=0;return W.apply(void 0,arguments)}),G=H;function Y(t){return t!=t}function K(t,e){return!(null==t||!t.length)&&function(t,e,r){return e==e?function(t,e,r){for(var n=-1,o=t.length;++n<o;)if(t[n]===e)return n;return-1}(t,e):function(t,e,r,n){for(var o=t.length,i=-1;++i<o;)if(e(t[i],i,t))return i;return-1}(t,Y)}(t,e)>-1}var Q=9007199254740991,X=/^(?:0|[1-9]\d*)$/;function Z(t,e){var r=typeof t;return!!(e=null==e?Q:e)&&("number"==r||"symbol"!=r&&X.test(t))&&t>-1&&t%1==0&&t<e}function tt(t,e,r){"__proto__"==e&&B?B(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}function et(t,e){return t===e||t!=t&&e!=e}var rt=Object.prototype.hasOwnProperty;function nt(t,e,r){var n=t[e];rt.call(t,e)&&et(n,r)&&(void 0!==r||e in t)||tt(t,e,r)}function ot(t,e,r,n){var o=!r;r||(r={});for(var i=-1,s=e.length;++i<s;){var a=e[i],u=n?n(r[a],t[a],a,r,t):void 0;void 0===u&&(u=t[a]),o?tt(r,a,u):nt(r,a,u)}return r}var it=Math.max;function st(t,e){return G(function(t,e,r){return e=it(void 0===e?t.length-1:e,0),function(){for(var n=arguments,o=-1,i=it(n.length-e,0),s=Array(i);++o<i;)s[o]=n[e+o];o=-1;for(var a=Array(e+1);++o<e;)a[o]=n[o];return a[e]=r(s),function(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)}(t,this,a)}}(t,e,S),t+"")}var at=9007199254740991;function ut(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=at}function ct(t){return null!=t&&ut(t.length)&&!E(t)}function ft(t,e,r){if(!j(r))return!1;var n=typeof e;return!!("number"==n?ct(r)&&Z(e,r.length):"string"==n&&e in r)&&et(r[e],t)}var ht=Object.prototype;function lt(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||ht)}function dt(t){return d(t)&&"[object Arguments]"==l(t)}var pt=Object.prototype,wt=pt.hasOwnProperty,gt=pt.propertyIsEnumerable,vt=dt(function(){return arguments}())?dt:function(t){return d(t)&&wt.call(t,"callee")&&!gt.call(t,"callee")},yt=vt,_t="object"==typeof exports&&exports&&!exports.nodeType&&exports,bt=_t&&"object"==typeof module&&module&&!module.nodeType&&module,mt=bt&&bt.exports===_t?r.Buffer:void 0,jt=(mt?mt.isBuffer:void 0)||function(){return!1},St={};function xt(t){return function(e){return t(e)}}St["[object Float32Array]"]=St["[object Float64Array]"]=St["[object Int8Array]"]=St["[object Int16Array]"]=St["[object Int32Array]"]=St["[object Uint8Array]"]=St["[object Uint8ClampedArray]"]=St["[object Uint16Array]"]=St["[object Uint32Array]"]=!0,St["[object Arguments]"]=St["[object Array]"]=St["[object ArrayBuffer]"]=St["[object Boolean]"]=St["[object DataView]"]=St["[object Date]"]=St["[object Error]"]=St["[object Function]"]=St["[object Map]"]=St["[object Number]"]=St["[object Object]"]=St["[object RegExp]"]=St["[object Set]"]=St["[object String]"]=St["[object WeakMap]"]=!1;var Ot="object"==typeof exports&&exports&&!exports.nodeType&&exports,kt=Ot&&"object"==typeof module&&module&&!module.nodeType&&module,At=kt&&kt.exports===Ot&&t.process,Et=function(){try{return kt&&kt.require&&kt.require("util").types||At&&At.binding&&At.binding("util")}catch(t){}}(),zt=Et&&Et.isTypedArray,Ft=zt?xt(zt):function(t){return d(t)&&ut(t.length)&&!!St[l(t)]},Pt=Object.prototype.hasOwnProperty;function Tt(t,e){var r=v(t),n=!r&&yt(t),o=!r&&!n&&jt(t),i=!r&&!n&&!o&&Ft(t),s=r||n||o||i,a=s?function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n}(t.length,String):[],u=a.length;for(var c in t)!e&&!Pt.call(t,c)||s&&("length"==c||o&&("offset"==c||"parent"==c)||i&&("buffer"==c||"byteLength"==c||"byteOffset"==c)||Z(c,u))||a.push(c);return a}function It(t,e){return function(r){return t(e(r))}}var Mt=It(Object.keys,Object),Nt=Object.prototype.hasOwnProperty;function $t(t){return ct(t)?Tt(t):function(t){if(!lt(t))return Mt(t);var e=[];for(var r in Object(t))Nt.call(t,r)&&"constructor"!=r&&e.push(r);return e}(t)}var Wt=Object.prototype.hasOwnProperty;function Ct(t){return ct(t)?Tt(t,!0):function(t){if(!j(t))return function(t){var e=[];if(null!=t)for(var r in Object(t))e.push(r);return e}(t);var e=lt(t),r=[];for(var n in t)("constructor"!=n||!e&&Wt.call(t,n))&&r.push(n);return r}(t)}var Dt=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Vt=/^\w*$/;function Rt(t,e){if(v(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!w(t))||Vt.test(t)||!Dt.test(t)||null!=e&&t in Object(e)}var Ut=$(Object,"create"),qt=Object.prototype.hasOwnProperty,Lt=Object.prototype.hasOwnProperty;function Bt(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function Jt(t,e){for(var r=t.length;r--;)if(et(t[r][0],e))return r;return-1}Bt.prototype.clear=function(){this.__data__=Ut?Ut(null):{},this.size=0},Bt.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Bt.prototype.get=function(t){var e=this.__data__;if(Ut){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return qt.call(e,t)?e[t]:void 0},Bt.prototype.has=function(t){var e=this.__data__;return Ut?void 0!==e[t]:Lt.call(e,t)},Bt.prototype.set=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=Ut&&void 0===e?"__lodash_hash_undefined__":e,this};var Ht=Array.prototype.splice;function Gt(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}Gt.prototype.clear=function(){this.__data__=[],this.size=0},Gt.prototype.delete=function(t){var e=this.__data__,r=Jt(e,t);return!(r<0||(r==e.length-1?e.pop():Ht.call(e,r,1),--this.size,0))},Gt.prototype.get=function(t){var e=this.__data__,r=Jt(e,t);return r<0?void 0:e[r][1]},Gt.prototype.has=function(t){return Jt(this.__data__,t)>-1},Gt.prototype.set=function(t,e){var r=this.__data__,n=Jt(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};var Yt=$(r,"Map");function Kt(t,e){var r,n,o=t.__data__;return("string"==(n=typeof(r=e))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?o["string"==typeof e?"string":"hash"]:o.map}function Qt(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function Xt(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError("Expected a function");var r=function(){var n=arguments,o=e?e.apply(this,n):n[0],i=r.cache;if(i.has(o))return i.get(o);var s=t.apply(this,n);return r.cache=i.set(o,s)||i,s};return r.cache=new(Xt.Cache||Qt),r}Qt.prototype.clear=function(){this.size=0,this.__data__={hash:new Bt,map:new(Yt||Gt),string:new Bt}},Qt.prototype.delete=function(t){var e=Kt(this,t).delete(t);return this.size-=e?1:0,e},Qt.prototype.get=function(t){return Kt(this,t).get(t)},Qt.prototype.has=function(t){return Kt(this,t).has(t)},Qt.prototype.set=function(t,e){var r=Kt(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this},Xt.Cache=Qt;var Zt,te,ee=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,re=/\\(\\)?/g,ne=(Zt=Xt(function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(ee,function(t,r,n,o){e.push(n?o.replace(re,"$1"):r||t)}),e},function(t){return 500===te.size&&te.clear(),t}),te=Zt.cache,Zt);function oe(t,e){return v(t)?t:Rt(t,e)?[t]:ne(function(t){return null==t?"":m(t)}(t))}var ie=1/0;function se(t){if("string"==typeof t||w(t))return t;var e=t+"";return"0"==e&&1/t==-ie?"-0":e}function ae(t,e){for(var r=0,n=(e=oe(e,t)).length;null!=t&&r<n;)t=t[se(e[r++])];return r&&r==n?t:void 0}function ue(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t}var ce=n?n.isConcatSpreadable:void 0;function fe(t){return v(t)||yt(t)||!!(ce&&t&&t[ce])}function he(t,e,r,n,o){var i=-1,s=t.length;for(r||(r=fe),o||(o=[]);++i<s;){var a=t[i];e>0&&r(a)?e>1?he(a,e-1,r,n,o):ue(o,a):n||(o[o.length]=a)}return o}var le=It(Object.getPrototypeOf,Object);function de(t){var e=this.__data__=new Gt(t);this.size=e.size}de.prototype.clear=function(){this.__data__=new Gt,this.size=0},de.prototype.delete=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},de.prototype.get=function(t){return this.__data__.get(t)},de.prototype.has=function(t){return this.__data__.has(t)},de.prototype.set=function(t,e){var r=this.__data__;if(r instanceof Gt){var n=r.__data__;if(!Yt||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new Qt(n)}return r.set(t,e),this.size=r.size,this};var pe="object"==typeof exports&&exports&&!exports.nodeType&&exports,we=pe&&"object"==typeof module&&module&&!module.nodeType&&module,ge=we&&we.exports===pe?r.Buffer:void 0,ve=ge?ge.allocUnsafe:void 0;function ye(){return[]}var _e=Object.prototype.propertyIsEnumerable,be=Object.getOwnPropertySymbols,me=be?function(t){return null==t?[]:(t=Object(t),function(e,r){for(var n=-1,o=null==e?0:e.length,i=0,s=[];++n<o;){var a=e[n];_e.call(t,a)&&(s[i++]=a)}return s}(be(t)))}:ye,je=me,Se=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)ue(e,je(t)),t=le(t);return e}:ye;function xe(t,e,r){var n=e(t);return v(t)?n:ue(n,r(t))}function Oe(t){return xe(t,$t,je)}function ke(t){return xe(t,Ct,Se)}var Ae=$(r,"DataView"),Ee=$(r,"Promise"),ze=$(r,"Set"),Fe="[object Map]",Pe="[object Promise]",Te="[object Set]",Ie="[object WeakMap]",Me="[object DataView]",Ne=I(Ae),$e=I(Yt),We=I(Ee),Ce=I(ze),De=I(V),Ve=l;(Ae&&Ve(new Ae(new ArrayBuffer(1)))!=Me||Yt&&Ve(new Yt)!=Fe||Ee&&Ve(Ee.resolve())!=Pe||ze&&Ve(new ze)!=Te||V&&Ve(new V)!=Ie)&&(Ve=function(t){var e=l(t),r="[object Object]"==e?t.constructor:void 0,n=r?I(r):"";if(n)switch(n){case Ne:return Me;case $e:return Fe;case We:return Pe;case Ce:return Te;case De:return Ie}return e});var Re=Ve,Ue=Object.prototype.hasOwnProperty,qe=r.Uint8Array;function Le(t){var e=new t.constructor(t.byteLength);return new qe(e).set(new qe(t)),e}var Be=/\w*$/,Je=n?n.prototype:void 0,He=Je?Je.valueOf:void 0,Ge="[object Boolean]",Ye="[object Date]",Ke="[object Map]",Qe="[object Number]",Xe="[object RegExp]",Ze="[object Set]",tr="[object String]",er="[object Symbol]",rr="[object ArrayBuffer]",nr="[object DataView]",or="[object Float32Array]",ir="[object Float64Array]",sr="[object Int8Array]",ar="[object Int16Array]",ur="[object Int32Array]",cr="[object Uint8Array]",fr="[object Uint8ClampedArray]",hr="[object Uint16Array]",lr="[object Uint32Array]",dr=Et&&Et.isMap,pr=dr?xt(dr):function(t){return d(t)&&"[object Map]"==Re(t)},wr=Et&&Et.isSet,gr=wr?xt(wr):function(t){return d(t)&&"[object Set]"==Re(t)},vr=1,yr=2,_r=4,br="[object Arguments]",mr="[object Function]",jr="[object GeneratorFunction]",Sr="[object Object]",xr={};function Or(t,e,r,n,o,i){var s,a=e&vr,u=e&yr,c=e&_r;if(r&&(s=o?r(t,n,o,i):r(t)),void 0!==s)return s;if(!j(t))return t;var f=v(t);if(f){if(s=function(t){var e=t.length,r=new t.constructor(e);return e&&"string"==typeof t[0]&&Ue.call(t,"index")&&(r.index=t.index,r.input=t.input),r}(t),!a)return function(t,e){var r=-1,n=t.length;for(e||(e=Array(n));++r<n;)e[r]=t[r];return e}(t,s)}else{var h=Re(t),l=h==mr||h==jr;if(jt(t))return function(t,e){if(e)return t.slice();var r=t.length,n=ve?ve(r):new t.constructor(r);return t.copy(n),n}(t,a);if(h==Sr||h==br||l&&!o){if(s=u||l?{}:function(t){return"function"!=typeof t.constructor||lt(t)?{}:U(le(t))}(t),!a)return u?function(t,e){return ot(t,Se(t),e)}(t,function(t,e){return t&&ot(e,Ct(e),t)}(s,t)):function(t,e){return ot(t,je(t),e)}(t,function(t,e){return t&&ot(e,$t(e),t)}(s,t))}else{if(!xr[h])return o?t:{};s=function(t,e,r){var n,o,i=t.constructor;switch(e){case rr:return Le(t);case Ge:case Ye:return new i(+t);case nr:return function(t,e){var r=e?Le(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)}(t,r);case or:case ir:case sr:case ar:case ur:case cr:case fr:case hr:case lr:return function(t,e){var r=e?Le(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)}(t,r);case Ke:return new i;case Qe:case tr:return new i(t);case Xe:return(o=new(n=t).constructor(n.source,Be.exec(n))).lastIndex=n.lastIndex,o;case Ze:return new i;case er:return He?Object(He.call(t)):{}}}(t,h,a)}}i||(i=new de);var d=i.get(t);if(d)return d;i.set(t,s),gr(t)?t.forEach(function(n){s.add(Or(n,e,r,n,t,i))}):pr(t)&&t.forEach(function(n,o){s.set(o,Or(n,e,r,o,t,i))});var p=f?void 0:(c?u?ke:Oe:u?Ct:$t)(t);return function(t,e){for(var r=-1,n=null==t?0:t.length;++r<n&&!1!==e(t[r],r););}(p||t,function(n,o){p&&(n=t[o=n]),nt(s,o,Or(n,e,r,o,t,i))}),s}function kr(t){return Or(t,4)}function Ar(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new Qt;++e<r;)this.add(t[e])}function Er(t,e){for(var r=-1,n=null==t?0:t.length;++r<n;)if(e(t[r],r,t))return!0;return!1}function zr(t,e){return t.has(e)}xr[br]=xr["[object Array]"]=xr["[object ArrayBuffer]"]=xr["[object DataView]"]=xr["[object Boolean]"]=xr["[object Date]"]=xr["[object Float32Array]"]=xr["[object Float64Array]"]=xr["[object Int8Array]"]=xr["[object Int16Array]"]=xr["[object Int32Array]"]=xr["[object Map]"]=xr["[object Number]"]=xr[Sr]=xr["[object RegExp]"]=xr["[object Set]"]=xr["[object String]"]=xr["[object Symbol]"]=xr["[object Uint8Array]"]=xr["[object Uint8ClampedArray]"]=xr["[object Uint16Array]"]=xr["[object Uint32Array]"]=!0,xr["[object Error]"]=xr[mr]=xr["[object WeakMap]"]=!1,Ar.prototype.add=Ar.prototype.push=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},Ar.prototype.has=function(t){return this.__data__.has(t)};var Fr=1,Pr=2;function Tr(t,e,r,n,o,i){var s=r&Fr,a=t.length,u=e.length;if(a!=u&&!(s&&u>a))return!1;var c=i.get(t),f=i.get(e);if(c&&f)return c==e&&f==t;var h=-1,l=!0,d=r&Pr?new Ar:void 0;for(i.set(t,e),i.set(e,t);++h<a;){var p=t[h],w=e[h];if(n)var g=s?n(w,p,h,e,t,i):n(p,w,h,t,e,i);if(void 0!==g){if(g)continue;l=!1;break}if(d){if(!Er(e,function(t,e){if(!zr(d,e)&&(p===t||o(p,t,r,n,i)))return d.push(e)})){l=!1;break}}else if(p!==w&&!o(p,w,r,n,i)){l=!1;break}}return i.delete(t),i.delete(e),l}function Ir(t){var e=-1,r=Array(t.size);return t.forEach(function(t,n){r[++e]=[n,t]}),r}function Mr(t){var e=-1,r=Array(t.size);return t.forEach(function(t){r[++e]=t}),r}var Nr=1,$r=2,Wr="[object Boolean]",Cr="[object Date]",Dr="[object Error]",Vr="[object Map]",Rr="[object Number]",Ur="[object RegExp]",qr="[object Set]",Lr="[object String]",Br="[object Symbol]",Jr="[object ArrayBuffer]",Hr="[object DataView]",Gr=n?n.prototype:void 0,Yr=Gr?Gr.valueOf:void 0,Kr=1,Qr=Object.prototype.hasOwnProperty,Xr=1,Zr="[object Arguments]",tn="[object Array]",en="[object Object]",rn=Object.prototype.hasOwnProperty;function nn(t,e,r,n,o){return t===e||(null==t||null==e||!d(t)&&!d(e)?t!=t&&e!=e:function(t,e,r,n,o,i){var s=v(t),a=v(e),u=s?tn:Re(t),c=a?tn:Re(e),f=(u=u==Zr?en:u)==en,h=(c=c==Zr?en:c)==en,l=u==c;if(l&&jt(t)){if(!jt(e))return!1;s=!0,f=!1}if(l&&!f)return i||(i=new de),s||Ft(t)?Tr(t,e,r,n,o,i):function(t,e,r,n,o,i,s){switch(r){case Hr:if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case Jr:return!(t.byteLength!=e.byteLength||!i(new qe(t),new qe(e)));case Wr:case Cr:case Rr:return et(+t,+e);case Dr:return t.name==e.name&&t.message==e.message;case Ur:case Lr:return t==e+"";case Vr:var a=Ir;case qr:if(a||(a=Mr),t.size!=e.size&&!(n&Nr))return!1;var u=s.get(t);if(u)return u==e;n|=$r,s.set(t,e);var c=Tr(a(t),a(e),n,o,i,s);return s.delete(t),c;case Br:if(Yr)return Yr.call(t)==Yr.call(e)}return!1}(t,e,u,r,n,o,i);if(!(r&Xr)){var d=f&&rn.call(t,"__wrapped__"),p=h&&rn.call(e,"__wrapped__");if(d||p){var w=d?t.value():t,g=p?e.value():e;return i||(i=new de),o(w,g,r,n,i)}}return!!l&&(i||(i=new de),function(t,e,r,n,o,i){var s=r&Kr,a=Oe(t),u=a.length;if(u!=Oe(e).length&&!s)return!1;for(var c=u;c--;){var f=a[c];if(!(s?f in e:Qr.call(e,f)))return!1}var h=i.get(t),l=i.get(e);if(h&&l)return h==e&&l==t;var d=!0;i.set(t,e),i.set(e,t);for(var p=s;++c<u;){var w=t[f=a[c]],g=e[f];if(n)var v=s?n(g,w,f,e,t,i):n(w,g,f,t,e,i);if(!(void 0===v?w===g||o(w,g,r,n,i):v)){d=!1;break}p||(p="constructor"==f)}if(d&&!p){var y=t.constructor,_=e.constructor;y==_||!("constructor"in t)||!("constructor"in e)||"function"==typeof y&&y instanceof y&&"function"==typeof _&&_ instanceof _||(d=!1)}return i.delete(t),i.delete(e),d}(t,e,r,n,o,i))}(t,e,r,n,nn,o))}var on=1,sn=2;function an(t){return t==t&&!j(t)}function un(t,e){return function(r){return null!=r&&r[t]===e&&(void 0!==e||t in Object(r))}}function cn(t,e){return null!=t&&e in Object(t)}var fn=1,hn=2;function ln(t){return"function"==typeof t?t:null==t?S:"object"==typeof t?v(t)?function(t,e){return Rt(t)&&an(e)?un(se(t),e):function(r){var n=function(t,e,r){var n=null==t?void 0:ae(t,e);return void 0===n?void 0:n}(r,t);return void 0===n&&n===e?function(t,e){return null!=t&&function(t,e,r){for(var n=-1,o=(e=oe(e,t)).length,i=!1;++n<o;){var s=se(e[n]);if(!(i=null!=t&&r(t,s)))break;t=t[s]}return i||++n!=o?i:!!(o=null==t?0:t.length)&&ut(o)&&Z(s,o)&&(v(t)||yt(t))}(t,e,cn)}(r,t):nn(e,n,fn|hn)}}(t[0],t[1]):(o=function(t){for(var e=$t(t),r=e.length;r--;){var n=e[r],o=t[n];e[r]=[n,o,an(o)]}return e}(n=t),1==o.length&&o[0][2]?un(o[0][0],o[0][1]):function(t){return t===n||function(t,e,r,n){var o=r.length,i=o;if(null==t)return!i;for(t=Object(t);o--;){var s=r[o];if(s[2]?s[1]!==t[s[0]]:!(s[0]in t))return!1}for(;++o<i;){var a=(s=r[o])[0],u=t[a],c=s[1];if(s[2]){if(void 0===u&&!(a in t))return!1}else{var f=new de;if(!nn(c,u,on|sn,void 0,f))return!1}}return!0}(t,0,o)}):Rt(e=t)?(r=se(e),function(t){return null==t?void 0:t[r]}):function(t){return function(e){return ae(e,t)}}(e);var e,r,n,o}var dn=function(t,e,r){for(var n=-1,o=Object(t),i=r(t),s=i.length;s--;){var a=i[++n];if(!1===e(o[a],a,o))break}return t};function pn(t,e){return t&&dn(t,e,$t)}var wn,gn=(wn=pn,function(t,e){if(null==t)return t;if(!ct(t))return wn(t,e);for(var r=t.length,n=-1,o=Object(t);++n<r&&!1!==e(o[n],n,o););return t});function vn(t,e){var r=-1,n=ct(t)?Array(t.length):[];return gn(t,function(t,o,i){n[++r]=e(t,o,i)}),n}function yn(t,e){return t>e}var _n=Math.min;function bn(t){return function(t){return d(t)&&ct(t)}(t)?t:[]}var mn=st(function(t){var e=g(t,bn);return e.length&&e[0]===t[0]?function(t,e,r){for(var n=K,o=t[0].length,i=t.length,s=i,a=Array(i),u=Infinity,c=[];s--;){var f=t[s];u=_n(f.length,u),a[s]=o>=120&&f.length>=120?new Ar(s&&f):void 0}f=t[0];var h=-1,l=a[0];t:for(;++h<o&&c.length<u;){var d=f[h],p=d;if(d=0!==d?d:0,!(l?zr(l,p):n(c,p,r))){for(s=i;--s;){var w=a[s];if(!(w?zr(w,p):n(t[s],p,r)))continue t}l&&l.push(p),c.push(d)}}return c}(e):[]}),jn=mn;function Sn(t,e){return t<e}function xn(t,e){var r={};return e=ln(e),pn(t,function(t,n,o){tt(r,n,e(t,n,o))}),r}function On(t,e,r){for(var n=-1,o=t.length;++n<o;){var i=t[n],s=e(i);if(null!=s&&(void 0===a?s==s&&!w(s):r(s,a)))var a=s,u=i}return u}function kn(t,e){return t&&t.length?On(t,ln(e),yn):void 0}function An(t,e){for(var r,n=-1,o=t.length;++n<o;){var i=e(t[n]);void 0!==i&&(r=void 0===r?i:r+i)}return r}function En(t,e){return function(t,e){var r=null==t?0:t.length;return r?An(t,e)/r:NaN}(t,ln(e))}function zn(t,e){if(t!==e){var r=void 0!==t,n=null===t,o=t==t,i=w(t),s=void 0!==e,a=null===e,u=e==e,c=w(e);if(!a&&!c&&!i&&t>e||i&&s&&u&&!a&&!c||n&&s&&u||!r&&u||!o)return 1;if(!n&&!i&&!c&&t<e||c&&r&&o&&!n&&!i||a&&r&&o||!s&&o||!u)return-1}return 0}function Fn(t,e,r){e=e.length?g(e,function(t){return v(t)?function(e){return ae(e,1===t.length?t[0]:t)}:t}):[S];var n=-1;return e=g(e,xt(ln)),function(t,e){var n=t.length;for(t.sort(function(t,e){return function(t,e,r){for(var n=-1,o=t.criteria,i=e.criteria,s=o.length,a=r.length;++n<s;){var u=zn(o[n],i[n]);if(u)return n>=a?u:u*("desc"==r[n]?-1:1)}return t.index-e.index}(t,e,r)});n--;)t[n]=t[n].value;return t}(vn(t,function(t,r,o){return{criteria:g(e,function(e){return e(t)}),index:++n,value:t}}))}function Pn(t,e,r,n){return null==t?[]:(v(e)||(e=null==e?[]:[e]),v(r=n?void 0:r)||(r=null==r?[]:[r]),Fn(t,e,r))}var Tn=st(function(t,e){if(null==t)return[];var r=e.length;return r>1&&ft(t,e[0],e[1])?e=[]:r>2&&ft(e[0],e[1],e[2])&&(e=[e[0]]),Fn(t,he(e,1),[])});function In(t,e){return t&&t.length?An(t,ln(e)):0}function Mn(t){if(this.words=[],t)if(Symbol&&Symbol.iterator&&void 0!==t[Symbol.iterator]){const e=t[Symbol.iterator]();let r=e.next();for(;!r.done;)this.add(r.value),r=e.next()}else for(let e=0;e<t.length;e++)this.add(t[e])}Mn.fromWords=function(t){const e=Object.create(Mn.prototype);return e.words=t,e},Mn.prototype.add=function(t){this.resize(t),this.words[t>>>5]|=1<<t},Mn.prototype.flip=function(t){this.resize(t),this.words[t>>>5]^=1<<t},Mn.prototype.clear=function(){this.words.length=0},Mn.prototype.remove=function(t){this.resize(t),this.words[t>>>5]&=~(1<<t)},Mn.prototype.isEmpty=function(t){const e=this.words.length;for(let t=0;t<e;t++)if(0!==this.words[t])return!1;return!0},Mn.prototype.has=function(t){return 0!=(this.words[t>>>5]&1<<t)},Mn.prototype.checkedAdd=function(t){this.resize(t);const e=this.words[t>>>5],r=e|1<<t;return this.words[t>>>5]=r,(r^e)>>>t},Mn.prototype.trim=function(t){let e=this.words.length;for(;e>0&&0===this.words[e-1];)e--;this.words.length=e},Mn.prototype.resize=function(t){const e=t+32>>>5;for(let t=this.words.length;t<e;t++)this.words[t]=0},Mn.prototype.hammingWeight=function(t){return 16843009*((t=(858993459&(t-=t>>>1&1431655765))+(t>>>2&858993459))+(t>>>4)&252645135)>>>24},Mn.prototype.hammingWeight4=function(t,e,r,n){return 16843009*((t=(t=(858993459&(t-=t>>>1&1431655765))+(t>>>2&858993459))+(t>>>4)&252645135)+(e=(e=(858993459&(e-=e>>>1&1431655765))+(e>>>2&858993459))+(e>>>4)&252645135)+(r=(r=(858993459&(r-=r>>>1&1431655765))+(r>>>2&858993459))+(r>>>4)&252645135)+(n=(n=(858993459&(n-=n>>>1&1431655765))+(n>>>2&858993459))+(n>>>4)&252645135))>>>24},Mn.prototype.size=function(){let t=0;const e=this.words.length,r=this.words;for(let n=0;n<e;n++)t+=this.hammingWeight(r[n]);return t},Mn.prototype.array=function(){const t=new Array(this.size());let e=0;const r=this.words.length;for(let n=0;n<r;++n){let r=this.words[n];for(;0!=r;){const o=r&-r;t[e++]=(n<<5)+this.hammingWeight(o-1|0),r^=o}}return t},Mn.prototype.forEach=function(t){const e=this.words.length;for(let r=0;r<e;++r){let e=this.words[r];for(;0!=e;){const n=e&-e;t((r<<5)+this.hammingWeight(n-1|0)),e^=n}}},Mn.prototype[Symbol.iterator]=function(){const t=this.words.length;let e=0,r=this.words[e],n=this.hammingWeight,o=this.words;return{[Symbol.iterator](){return this},next(){for(;e<t;){if(0!==r){const t=r&-r,o=(e<<5)+n(t-1|0);return r^=t,{done:!1,value:o}}e++,e<t&&(r=o[e])}return{done:!0,value:void 0}}}},Mn.prototype.clone=function(){const t=Object.create(Mn.prototype);return t.words=this.words.slice(),t},Mn.prototype.intersects=function(t){const e=Math.min(this.words.length,t.words.length);for(let r=0;r<e;++r)if(0!=(this.words[r]&t.words[r]))return!0;return!1},Mn.prototype.intersection=function(t){const e=Math.min(this.words.length,t.words.length);let r=0;for(;r+7<e;r+=8)this.words[r]&=t.words[r],this.words[r+1]&=t.words[r+1],this.words[r+2]&=t.words[r+2],this.words[r+3]&=t.words[r+3],this.words[r+4]&=t.words[r+4],this.words[r+5]&=t.words[r+5],this.words[r+6]&=t.words[r+6],this.words[r+7]&=t.words[r+7];for(;r<e;++r)this.words[r]&=t.words[r];const n=this.words.length;for(r=e;r<n;++r)this.words[r]=0;return this},Mn.prototype.intersection_size=function(t){const e=Math.min(this.words.length,t.words.length);let r=0;for(let n=0;n<e;++n)r+=this.hammingWeight(this.words[n]&t.words[n]);return r},Mn.prototype.new_intersection=function(t){const e=Object.create(Mn.prototype),r=Math.min(this.words.length,t.words.length);e.words=new Array(r);let n=0;for(;n+7<r;n+=8)e.words[n]=this.words[n]&t.words[n],e.words[n+1]=this.words[n+1]&t.words[n+1],e.words[n+2]=this.words[n+2]&t.words[n+2],e.words[n+3]=this.words[n+3]&t.words[n+3],e.words[n+4]=this.words[n+4]&t.words[n+4],e.words[n+5]=this.words[n+5]&t.words[n+5],e.words[n+6]=this.words[n+6]&t.words[n+6],e.words[n+7]=this.words[n+7]&t.words[n+7];for(;n<r;++n)e.words[n]=this.words[n]&t.words[n];return e},Mn.prototype.equals=function(t){const e=Math.min(this.words.length,t.words.length);for(let r=0;r<e;++r)if(this.words[r]!=t.words[r])return!1;if(this.words.length<t.words.length){const e=t.words.length;for(let r=this.words.length;r<e;++r)if(0!=t.words[r])return!1}else if(t.words.length<this.words.length){const e=this.words.length;for(let r=t.words.length;r<e;++r)if(0!=this.words[r])return!1}return!0},Mn.prototype.difference=function(t){const e=Math.min(this.words.length,t.words.length);let r=0;for(;r+7<e;r+=8)this.words[r]&=~t.words[r],this.words[r+1]&=~t.words[r+1],this.words[r+2]&=~t.words[r+2],this.words[r+3]&=~t.words[r+3],this.words[r+4]&=~t.words[r+4],this.words[r+5]&=~t.words[r+5],this.words[r+6]&=~t.words[r+6],this.words[r+7]&=~t.words[r+7];for(;r<e;++r)this.words[r]&=~t.words[r];return this},Mn.prototype.new_difference=function(t){return this.clone().difference(t)},Mn.prototype.difference2=function(t){const e=Math.min(this.words.length,t.words.length);let r=0;for(;r+7<e;r+=8)t.words[r]=this.words[r]&~t.words[r],t.words[r+1]=this.words[r+1]&~t.words[r+1],t.words[r+2]=this.words[r+2]&~t.words[r+2],t.words[r+3]=this.words[r+3]&~t.words[r+3],t.words[r+4]=this.words[r+4]&~t.words[r+4],t.words[r+5]=this.words[r+5]&~t.words[r+5],t.words[r+6]=this.words[r+6]&~t.words[r+6],t.words[r+7]=this.words[r+7]&~t.words[r+7];for(;r<e;++r)t.words[r]=this.words[r]&~t.words[r];for(r=this.words.length-1;r>=e;--r)t.words[r]=this.words[r];return t.words.length=this.words.length,t},Mn.prototype.difference_size=function(t){const e=Math.min(this.words.length,t.words.length);let r=0,n=0;for(;n<e;++n)r+=this.hammingWeight(this.words[n]&~t.words[n]);const o=this.words.length;for(;n<o;++n)r+=this.hammingWeight(this.words[n]);return r},Mn.prototype.change=function(t){const e=Math.min(this.words.length,t.words.length);let r=0;for(;r+7<e;r+=8)this.words[r]^=t.words[r],this.words[r+1]^=t.words[r+1],this.words[r+2]^=t.words[r+2],this.words[r+3]^=t.words[r+3],this.words[r+4]^=t.words[r+4],this.words[r+5]^=t.words[r+5],this.words[r+6]^=t.words[r+6],this.words[r+7]^=t.words[r+7];for(;r<e;++r)this.words[r]^=t.words[r];for(r=t.words.length-1;r>=e;--r)this.words[r]=t.words[r];return this},Mn.prototype.new_change=function(t){const e=Object.create(Mn.prototype),r=Math.max(this.words.length,t.words.length);e.words=new Array(r);const n=Math.min(this.words.length,t.words.length);let o=0;for(;o+7<n;o+=8)e.words[o]=this.words[o]^t.words[o],e.words[o+1]=this.words[o+1]^t.words[o+1],e.words[o+2]=this.words[o+2]^t.words[o+2],e.words[o+3]=this.words[o+3]^t.words[o+3],e.words[o+4]=this.words[o+4]^t.words[o+4],e.words[o+5]=this.words[o+5]^t.words[o+5],e.words[o+6]=this.words[o+6]^t.words[o+6],e.words[o+7]=this.words[o+7]^t.words[o+7];for(;o<n;++o)e.words[o]=this.words[o]^t.words[o];const i=this.words.length;for(o=n;o<i;++o)e.words[o]=this.words[o];const s=t.words.length;for(o=n;o<s;++o)e.words[o]=t.words[o];return e},Mn.prototype.change_size=function(t){const e=Math.min(this.words.length,t.words.length);let r=0,n=0;for(;n<e;++n)r+=this.hammingWeight(this.words[n]^t.words[n]);const o=this.words.length>t.words.length?this:t,i=o.words.length;for(;n<i;++n)r+=this.hammingWeight(o.words[n]);return r},Mn.prototype.toString=function(){return"{"+this.array().join(",")+"}"},Mn.prototype.union=function(t){const e=Math.min(this.words.length,t.words.length);let r=0;for(;r+7<e;r+=8)this.words[r]|=t.words[r],this.words[r+1]|=t.words[r+1],this.words[r+2]|=t.words[r+2],this.words[r+3]|=t.words[r+3],this.words[r+4]|=t.words[r+4],this.words[r+5]|=t.words[r+5],this.words[r+6]|=t.words[r+6],this.words[r+7]|=t.words[r+7];for(;r<e;++r)this.words[r]|=t.words[r];if(this.words.length<t.words.length){this.resize((t.words.length<<5)-1);const r=t.words.length;for(let n=e;n<r;++n)this.words[n]=t.words[n]}return this},Mn.prototype.new_union=function(t){const e=Object.create(Mn.prototype),r=Math.max(this.words.length,t.words.length);e.words=new Array(r);const n=Math.min(this.words.length,t.words.length);let o=0;for(;o+7<n;o+=8)e.words[o]=this.words[o]|t.words[o],e.words[o+1]=this.words[o+1]|t.words[o+1],e.words[o+2]=this.words[o+2]|t.words[o+2],e.words[o+3]=this.words[o+3]|t.words[o+3],e.words[o+4]=this.words[o+4]|t.words[o+4],e.words[o+5]=this.words[o+5]|t.words[o+5],e.words[o+6]=this.words[o+6]|t.words[o+6],e.words[o+7]=this.words[o+7]|t.words[o+7];for(;o<n;++o)e.words[o]=this.words[o]|t.words[o];const i=this.words.length;for(o=n;o<i;++o)e.words[o]=this.words[o];const s=t.words.length;for(o=n;o<s;++o)e.words[o]=t.words[o];return e},Mn.prototype.union_size=function(t){const e=Math.min(this.words.length,t.words.length);let r=0;for(let n=0;n<e;++n)r+=this.hammingWeight(this.words[n]|t.words[n]);if(this.words.length<t.words.length){const e=t.words.length;for(let n=this.words.length;n<e;++n)r+=this.hammingWeight(0|t.words[n])}else{const e=this.words.length;for(let n=t.words.length;n<e;++n)r+=this.hammingWeight(0|this.words[n])}return r};var Nn=Mn;function $n(){return $n=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},$n.apply(this,arguments)}function Wn(t,e){var r=[];return t.forEach(function(t){e.forEach(function(e){r.push(t.concat(e))})}),r}function Cn(t){return!!~t.search(/\(|\)/)}function Dn(t,e){for(var r=e.split(" "+t+" "),n=[],o=[],i=0;i<r.length;i++)if(Cn(r[i])||o.length>0){o.push(r[i]);var s=""+o;(s.match(/\(/g)||[]).length===(s.match(/\)/g)||[]).length&&(n.push(o.join(" "+t+" ")),o=[])}else n.push(r[i]);return n}var Vn=function t(e){return function(t){for(var e=t[0],r=1;r<t.length;r++)e=e.concat(t[r]);return e}(Dn("OR",(r=e=function(t){if("("===t.charAt(0))for(var e=0,r=0;r<t.length;r++)if("("===t.charAt(r)?e++:")"===t.charAt(r)&&e--,0===e)return r!==t.length-1?t:t.substring(1,t.length-1);return t}(e),e=r.replace(/[\s]+/g," "))).map(function(e){for(var r=Dn("AND",e),n=[],o=[],i=0;i<r.length;i++)Cn(r[i])?n.push(t(r[i])):o.push(r[i]);return n.push([o]),function(t){for(var e=[[]],r=0;r<t.length;r++)e=Wn(e,t[r]);return e}(n)}));var r},Rn=function(t){try{return structuredClone(t)}catch(e){try{return JSON.parse(JSON.stringify(t))}catch(e){return t}}},Un=function(t,e){var r=new Nn([]),n=0;return xn(e,function(e,o){e.forEach(function(e){++n,r=r.new_union(t[o][e]||new Nn([]))})}),0===n?null:r},qn=function(t,e,r){var n=1;return xn(t.bits_data_temp,function(t,o){var i,s,a,u,c,f,h;r[o]&&(i=r[o].order,s=r[o].sort,a=r[o].size,u=r[o].title,c=r[o].show_facet_stats||!1,f=!1!==r[o].chosen_filters_on_top,h=r[o].hide_zero_doc_count||!1);var l,d,p,w,g,y,_=Object.entries(t).map(function(t){var r=[];e&&e.filters&&e.filters[o]&&(r=e.filters[o]);var n=t[1].array().length;if(!h||0!==n||-1!==r.indexOf(t[0]))return{key:t[0],doc_count:n,selected:-1!==r.indexOf(t[0])}}).filter(Boolean);return v(s)?(l=s||["key"],d=i||["asc"]):("term"===s||"key"===s?(l=["key"],d=[i||"asc"]):(l=["doc_count","key"],d=[i||"desc","asc"]),f&&(l.unshift("selected"),d.unshift("desc"))),_=(_=Pn(_,l,d)).slice(0,a||10),c&&(p=[],Object.entries(t).forEach(function(t){if(isNaN(t[0]))throw new Error("You cant use chars to calculate the facet_stats.");t[1].array().length>0&&t[1].forEach(function(){p.push(parseInt(t[0]))})}),w={min:(g=p,g&&g.length?On(g,ln(void 0),Sn):void 0),max:kn(p),avg:En(p),sum:In(p)}),$n({name:o,title:u||(y=o,y.replace(/^[\s_]+|[\s_]+$/g,"").replace(/[_\s]+/g," ").replace(/^[a-z]/,function(t){return t.toUpperCase()})),position:n++,buckets:_},c&&{facet_stats:w})})};function Ln(t,e,r,n,o){e=e||Object.create(null);var i=parseInt(e.per_page||12),s=parseInt(e.page||1),a=e.is_all_filtered_items||!1;if(!1===r.native_search_enabled&&(e.query||e.filter))throw new Error('"query" and "filter" options are not working once native search is disabled');var u,c,f,h=0,l=(new Date).getTime(),d=o.bits_ids();if(e._ids)u=new Nn(e._ids),c=e._ids;else if(e.ids)c=o.internal_ids_from_ids_map(e.ids),u=new Nn(c);else if(n&&(e.query||e.filter)){var p=(new Date).getTime();c=n.search(e.query,e.filter),h=(new Date).getTime()-p,u=new Nn(c)}var w=(new Date).getTime(),g=o.search(e,{query_ids:u});w=(new Date).getTime()-w,u&&(d=u),g.ids&&(d=d.new_intersection(g.ids)),g.not_ids&&(d=d.new_difference(g.not_ids));var v,y=d.array(),_=y.map(function(t){return o.get_item(t)}),b=!1,m=(new Date).getTime();e.sort?_=function(t,e,r){return r&&r[e]&&(e=r[e]),e.field?Pn(t,e.field,e.order||"asc"):t}(_,e.sort,r.sortings):c&&(_=(y=c.filter(function(t){return d.has(t)})).slice((s-1)*i,s*i).map(function(t){return o.get_item(t)}),b=!0),b||(f=a?_:null,_=_.slice((s-1)*i,s*i)),v=(new Date).getTime()-m;var j=(new Date).getTime()-l;return{pagination:{per_page:i,page:s,total:y.length},timings:{total:j,facets:w,search:h,sorting:v},data:{items:_,allFilteredItems:f,aggregations:qn(g,e,r.aggregations)}}}var Bn=function(t){var e={exports:{}};return function(t,e){!function(){var e,r,n,o,i,s,a,u,c,f,h,l,d,p,w,g,v,y,_,b,m,j,S,x,O,k,A,E,z=function(t){var e=new z.Index;return e.pipeline.add(z.trimmer,z.stopWordFilter,z.stemmer),t&&t.call(e,e),e};z.version="1.0.0",z.utils={},z.utils.warn=function(t){return function(e){t.console&&console.warn&&console.warn(e)}}(this),z.utils.asString=function(t){return null==t?"":t.toString()},z.EventEmitter=function(){this.events={}},z.EventEmitter.prototype.addListener=function(){var t=Array.prototype.slice.call(arguments),e=t.pop(),r=t;if("function"!=typeof e)throw new TypeError("last argument must be a function");r.forEach(function(t){this.hasHandler(t)||(this.events[t]=[]),this.events[t].push(e)},this)},z.EventEmitter.prototype.removeListener=function(t,e){if(this.hasHandler(t)){var r=this.events[t].indexOf(e);this.events[t].splice(r,1),this.events[t].length||delete this.events[t]}},z.EventEmitter.prototype.emit=function(t){if(this.hasHandler(t)){var e=Array.prototype.slice.call(arguments,1);this.events[t].forEach(function(t){t.apply(void 0,e)})}},z.EventEmitter.prototype.hasHandler=function(t){return t in this.events},z.tokenizer=function(t){return arguments.length&&null!=t&&null!=t?Array.isArray(t)?t.map(function(t){return z.utils.asString(t).toLowerCase()}):t.toString().trim().toLowerCase().split(z.tokenizer.separator):[]},z.tokenizer.separator=/[\s\-]+/,z.tokenizer.load=function(t){var e=this.registeredFunctions[t];if(!e)throw new Error("Cannot load un-registered function: "+t);return e},z.tokenizer.label="default",z.tokenizer.registeredFunctions={default:z.tokenizer},z.tokenizer.registerFunction=function(t,e){e in this.registeredFunctions&&z.utils.warn("Overwriting existing tokenizer: "+e),t.label=e,this.registeredFunctions[e]=t},z.Pipeline=function(){this._stack=[]},z.Pipeline.registeredFunctions={},z.Pipeline.registerFunction=function(t,e){e in this.registeredFunctions&&z.utils.warn("Overwriting existing registered function: "+e),t.label=e,z.Pipeline.registeredFunctions[t.label]=t},z.Pipeline.warnIfFunctionNotRegistered=function(t){t.label&&t.label in this.registeredFunctions||z.utils.warn("Function is not registered with pipeline. This may cause problems when serialising the index.\n",t)},z.Pipeline.load=function(t){var e=new z.Pipeline;return t.forEach(function(t){var r=z.Pipeline.registeredFunctions[t];if(!r)throw new Error("Cannot load un-registered function: "+t);e.add(r)}),e},z.Pipeline.prototype.add=function(){Array.prototype.slice.call(arguments).forEach(function(t){z.Pipeline.warnIfFunctionNotRegistered(t),this._stack.push(t)},this)},z.Pipeline.prototype.after=function(t,e){z.Pipeline.warnIfFunctionNotRegistered(e);var r=this._stack.indexOf(t);if(-1==r)throw new Error("Cannot find existingFn");this._stack.splice(r+=1,0,e)},z.Pipeline.prototype.before=function(t,e){z.Pipeline.warnIfFunctionNotRegistered(e);var r=this._stack.indexOf(t);if(-1==r)throw new Error("Cannot find existingFn");this._stack.splice(r,0,e)},z.Pipeline.prototype.remove=function(t){var e=this._stack.indexOf(t);-1!=e&&this._stack.splice(e,1)},z.Pipeline.prototype.run=function(t){for(var e=[],r=t.length,n=this._stack.length,o=0;o<r;o++){for(var i=t[o],s=0;s<n&&void 0!==(i=this._stack[s](i,o,t))&&""!==i;s++);void 0!==i&&""!==i&&e.push(i)}return e},z.Pipeline.prototype.reset=function(){this._stack=[]},z.Pipeline.prototype.toJSON=function(){return this._stack.map(function(t){return z.Pipeline.warnIfFunctionNotRegistered(t),t.label})},z.Vector=function(){this._magnitude=null,this.list=void 0,this.length=0},z.Vector.Node=function(t,e,r){this.idx=t,this.val=e,this.next=r},z.Vector.prototype.insert=function(t,e){this._magnitude=void 0;var r=this.list;if(!r)return this.list=new z.Vector.Node(t,e,r),this.length++;if(t<r.idx)return this.list=new z.Vector.Node(t,e,r),this.length++;for(var n=r,o=r.next;null!=o;){if(t<o.idx)return n.next=new z.Vector.Node(t,e,o),this.length++;n=o,o=o.next}return n.next=new z.Vector.Node(t,e,o),this.length++},z.Vector.prototype.magnitude=function(){if(this._magnitude)return this._magnitude;for(var t,e=this.list,r=0;e;)r+=(t=e.val)*t,e=e.next;return this._magnitude=Math.sqrt(r)},z.Vector.prototype.dot=function(t){for(var e=this.list,r=t.list,n=0;e&&r;)e.idx<r.idx?e=e.next:(e.idx>r.idx||(n+=e.val*r.val,e=e.next),r=r.next);return n},z.Vector.prototype.similarity=function(t){return this.dot(t)/(this.magnitude()*t.magnitude())},z.SortedSet=function(){this.length=0,this.elements=[]},z.SortedSet.load=function(t){var e=new this;return e.elements=t,e.length=t.length,e},z.SortedSet.prototype.add=function(){var t,e;for(t=0;t<arguments.length;t++)~this.indexOf(e=arguments[t])||this.elements.splice(this.locationFor(e),0,e);this.length=this.elements.length},z.SortedSet.prototype.toArray=function(){return this.elements.slice()},z.SortedSet.prototype.map=function(t,e){return this.elements.map(t,e)},z.SortedSet.prototype.forEach=function(t,e){return this.elements.forEach(t,e)},z.SortedSet.prototype.indexOf=function(t){for(var e=0,r=this.elements.length,n=r-e,o=e+Math.floor(n/2),i=this.elements[o];n>1;){if(i===t)return o;i<t&&(e=o),i>t&&(r=o),n=r-e,o=e+Math.floor(n/2),i=this.elements[o]}return i===t?o:-1},z.SortedSet.prototype.locationFor=function(t){for(var e=0,r=this.elements.length,n=r-e,o=e+Math.floor(n/2),i=this.elements[o];n>1;)i<t&&(e=o),i>t&&(r=o),n=r-e,o=e+Math.floor(n/2),i=this.elements[o];return i>t?o:i<t?o+1:void 0},z.SortedSet.prototype.intersect=function(t){for(var e=new z.SortedSet,r=0,n=0,o=this.length,i=t.length,s=this.elements,a=t.elements;!(r>o-1||n>i-1);)s[r]!==a[n]?s[r]<a[n]?r++:s[r]>a[n]&&n++:(e.add(s[r]),r++,n++);return e},z.SortedSet.prototype.clone=function(){var t=new z.SortedSet;return t.elements=this.toArray(),t.length=t.elements.length,t},z.SortedSet.prototype.union=function(t){var e,r,n;this.length>=t.length?(e=this,r=t):(e=t,r=this),n=e.clone();for(var o=0,i=r.toArray();o<i.length;o++)n.add(i[o]);return n},z.SortedSet.prototype.toJSON=function(){return this.toArray()},z.Index=function(){this._fields=[],this._ref="id",this.pipeline=new z.Pipeline,this.documentStore=new z.Store,this.tokenStore=new z.TokenStore,this.corpusTokens=new z.SortedSet,this.eventEmitter=new z.EventEmitter,this.tokenizerFn=z.tokenizer,this._idfCache={},this.on("add","remove","update",function(){this._idfCache={}}.bind(this))},z.Index.prototype.on=function(){var t=Array.prototype.slice.call(arguments);return this.eventEmitter.addListener.apply(this.eventEmitter,t)},z.Index.prototype.off=function(t,e){return this.eventEmitter.removeListener(t,e)},z.Index.load=function(t){t.version!==z.version&&z.utils.warn("version mismatch: current "+z.version+" importing "+t.version);var e=new this;return e._fields=t.fields,e._ref=t.ref,e.tokenizer(z.tokenizer.load(t.tokenizer)),e.documentStore=z.Store.load(t.documentStore),e.tokenStore=z.TokenStore.load(t.tokenStore),e.corpusTokens=z.SortedSet.load(t.corpusTokens),e.pipeline=z.Pipeline.load(t.pipeline),e},z.Index.prototype.field=function(t,e){return this._fields.push({name:t,boost:(e=e||{}).boost||1}),this},z.Index.prototype.ref=function(t){return this._ref=t,this},z.Index.prototype.tokenizer=function(t){return t.label&&t.label in z.tokenizer.registeredFunctions||z.utils.warn("Function is not a registered tokenizer. This may cause problems when serialising the index"),this.tokenizerFn=t,this},z.Index.prototype.add=function(t,e){var r={},n=new z.SortedSet,o=t[this._ref];e=void 0===e||e,this._fields.forEach(function(e){var o=this.pipeline.run(this.tokenizerFn(t[e.name]));r[e.name]=o;for(var i=0;i<o.length;i++){var s=o[i];n.add(s),this.corpusTokens.add(s)}},this),this.documentStore.set(o,n);for(var i=0;i<n.length;i++){for(var s=n.elements[i],a=0,u=0;u<this._fields.length;u++){var c=this._fields[u],f=r[c.name],h=f.length;if(h){for(var l=0,d=0;d<h;d++)f[d]===s&&l++;a+=l/h*c.boost}}this.tokenStore.add(s,{ref:o,tf:a})}e&&this.eventEmitter.emit("add",t,this)},z.Index.prototype.remove=function(t,e){var r=t[this._ref];if(e=void 0===e||e,this.documentStore.has(r)){var n=this.documentStore.get(r);this.documentStore.remove(r),n.forEach(function(t){this.tokenStore.remove(t,r)},this),e&&this.eventEmitter.emit("remove",t,this)}},z.Index.prototype.update=function(t,e){e=void 0===e||e,this.remove(t,!1),this.add(t,!1),e&&this.eventEmitter.emit("update",t,this)},z.Index.prototype.idf=function(t){var e="@"+t;if(Object.prototype.hasOwnProperty.call(this._idfCache,e))return this._idfCache[e];var r=this.tokenStore.count(t),n=1;return r>0&&(n=1+Math.log(this.documentStore.length/r)),this._idfCache[e]=n},z.Index.prototype.search=function(t){var e=this.pipeline.run(this.tokenizerFn(t)),r=new z.Vector,n=[],o=this._fields.reduce(function(t,e){return t+e.boost},0);return e.some(function(t){return this.tokenStore.has(t)},this)?(e.forEach(function(t,e,i){var s=1/i.length*this._fields.length*o,a=this,u=this.tokenStore.expand(t).reduce(function(e,n){var o=a.corpusTokens.indexOf(n),i=a.idf(n),u=1,c=new z.SortedSet;if(n!==t){var f=Math.max(3,n.length-t.length);u=1/Math.log(f)}o>-1&&r.insert(o,s*i*u);for(var h=a.tokenStore.get(n),l=Object.keys(h),d=l.length,p=0;p<d;p++)c.add(h[l[p]].ref);return e.union(c)},new z.SortedSet);n.push(u)},this),n.reduce(function(t,e){return t.intersect(e)}).map(function(t){return{ref:t,score:r.similarity(this.documentVector(t))}},this).sort(function(t,e){return e.score-t.score})):[]},z.Index.prototype.documentVector=function(t){for(var e=this.documentStore.get(t),r=e.length,n=new z.Vector,o=0;o<r;o++){var i=e.elements[o],s=this.tokenStore.get(i)[t].tf,a=this.idf(i);n.insert(this.corpusTokens.indexOf(i),s*a)}return n},z.Index.prototype.toJSON=function(){return{version:z.version,fields:this._fields,ref:this._ref,tokenizer:this.tokenizerFn.label,documentStore:this.documentStore.toJSON(),tokenStore:this.tokenStore.toJSON(),corpusTokens:this.corpusTokens.toJSON(),pipeline:this.pipeline.toJSON()}},z.Index.prototype.use=function(t){var e=Array.prototype.slice.call(arguments,1);e.unshift(this),t.apply(this,e)},z.Store=function(){this.store={},this.length=0},z.Store.load=function(t){var e=new this;return e.length=t.length,e.store=Object.keys(t.store).reduce(function(e,r){return e[r]=z.SortedSet.load(t.store[r]),e},{}),e},z.Store.prototype.set=function(t,e){this.has(t)||this.length++,this.store[t]=e},z.Store.prototype.get=function(t){return this.store[t]},z.Store.prototype.has=function(t){return t in this.store},z.Store.prototype.remove=function(t){this.has(t)&&(delete this.store[t],this.length--)},z.Store.prototype.toJSON=function(){return{store:this.store,length:this.length}},z.stemmer=(e={ational:"ate",tional:"tion",enci:"ence",anci:"ance",izer:"ize",bli:"ble",alli:"al",entli:"ent",eli:"e",ousli:"ous",ization:"ize",ation:"ate",ator:"ate",alism:"al",iveness:"ive",fulness:"ful",ousness:"ous",aliti:"al",iviti:"ive",biliti:"ble",logi:"log"},r={icate:"ic",ative:"",alize:"al",iciti:"ic",ical:"ic",ful:"",ness:""},s="^("+(o="[^aeiou][^aeiouy]*")+")?"+(i=(n="[aeiouy]")+"[aeiou]*")+o+"("+i+")?$",a="^("+o+")?"+i+o+i+o,u="^("+o+")?"+n,c=new RegExp("^("+o+")?"+i+o),f=new RegExp(a),h=new RegExp(s),l=new RegExp(u),d=/^(.+?)(ss|i)es$/,p=/^(.+?)([^s])s$/,w=/^(.+?)eed$/,g=/^(.+?)(ed|ing)$/,v=/.$/,y=/(at|bl|iz)$/,_=new RegExp("([^aeiouylsz])\\1$"),b=new RegExp("^"+o+n+"[^aeiouwxy]$"),m=/^(.+?[^aeiou])y$/,j=/^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/,S=/^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/,x=/^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/,O=/^(.+?)(s|t)(ion)$/,k=/^(.+?)e$/,A=/ll$/,E=new RegExp("^"+o+n+"[^aeiouwxy]$"),function(t){var n,o,i,s,a,u,z;if(t.length<3)return t;if("y"==(i=t.substr(0,1))&&(t=i.toUpperCase()+t.substr(1)),a=p,(s=d).test(t)?t=t.replace(s,"$1$2"):a.test(t)&&(t=t.replace(a,"$1$2")),a=g,(s=w).test(t)){var F=s.exec(t);(s=c).test(F[1])&&(t=t.replace(s=v,""))}else a.test(t)&&(F=a.exec(t),(a=l).test(n=F[1])&&(u=_,z=b,(a=y).test(t=n)?t+="e":u.test(t)?t=t.replace(s=v,""):z.test(t)&&(t+="e")));return(s=m).test(t)&&(t=(n=(F=s.exec(t))[1])+"i"),(s=j).test(t)&&(o=(F=s.exec(t))[2],(s=c).test(n=F[1])&&(t=n+e[o])),(s=S).test(t)&&(o=(F=s.exec(t))[2],(s=c).test(n=F[1])&&(t=n+r[o])),a=O,(s=x).test(t)?(F=s.exec(t),(s=f).test(n=F[1])&&(t=n)):a.test(t)&&(F=a.exec(t),(a=f).test(n=F[1]+F[2])&&(t=n)),(s=k).test(t)&&(F=s.exec(t),a=h,u=E,((s=f).test(n=F[1])||a.test(n)&&!u.test(n))&&(t=n)),a=f,(s=A).test(t)&&a.test(t)&&(t=t.replace(s=v,"")),"y"==i&&(t=i.toLowerCase()+t.substr(1)),t}),z.Pipeline.registerFunction(z.stemmer,"stemmer"),z.generateStopWordFilter=function(t){var e=t.reduce(function(t,e){return t[e]=e,t},{});return function(t){if(t&&e[t]!==t)return t}},z.stopWordFilter=z.generateStopWordFilter(["a","able","about","across","after","all","almost","also","am","among","an","and","any","are","as","at","be","because","been","but","by","can","cannot","could","dear","did","do","does","either","else","ever","every","for","from","get","got","had","has","have","he","her","hers","him","his","how","however","i","if","in","into","is","it","its","just","least","let","like","likely","may","me","might","most","must","my","neither","no","nor","not","of","off","often","on","only","or","other","our","own","rather","said","say","says","she","should","since","so","some","than","that","the","their","them","then","there","these","they","this","tis","to","too","twas","us","wants","was","we","were","what","when","where","which","while","who","whom","why","will","with","would","yet","you","your"]),z.Pipeline.registerFunction(z.stopWordFilter,"stopWordFilter"),z.trimmer=function(t){return t.replace(/^\W+/,"").replace(/\W+$/,"")},z.Pipeline.registerFunction(z.trimmer,"trimmer"),z.TokenStore=function(){this.root={docs:{}},this.length=0},z.TokenStore.load=function(t){var e=new this;return e.root=t.root,e.length=t.length,e},z.TokenStore.prototype.add=function(t,e,r){r=r||this.root;var n=t.charAt(0),o=t.slice(1);return n in r||(r[n]={docs:{}}),0===o.length?(r[n].docs[e.ref]=e,void(this.length+=1)):this.add(o,e,r[n])},z.TokenStore.prototype.has=function(t){if(!t)return!1;for(var e=this.root,r=0;r<t.length;r++){if(!e[t.charAt(r)])return!1;e=e[t.charAt(r)]}return!0},z.TokenStore.prototype.getNode=function(t){if(!t)return{};for(var e=this.root,r=0;r<t.length;r++){if(!e[t.charAt(r)])return{};e=e[t.charAt(r)]}return e},z.TokenStore.prototype.get=function(t,e){return this.getNode(t,e).docs||{}},z.TokenStore.prototype.count=function(t,e){return Object.keys(this.get(t,e)).length},z.TokenStore.prototype.remove=function(t,e){if(t){for(var r=this.root,n=0;n<t.length;n++){if(!(t.charAt(n)in r))return;r=r[t.charAt(n)]}delete r.docs[e]}},z.TokenStore.prototype.expand=function(t,e){var r=this.getNode(t);return e=e||[],Object.keys(r.docs||{}).length&&e.push(t),Object.k