# All files bulksearch.min.js

82.82% Statements 188/227
72.2% Branches 174/241
76.92% Functions 30/39
100% Lines 14/14

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20

    7x
    178x
    48x
    48x
    48x
    15x
    33x
    31x
    30x
    22x
    6x
    6x
    6x
    6x
     /*
     https://github.com/nextapps-de/bulksearch
     @version: 0.1.2
     @license: Apache 2.0 Licence
    */
    'use strict';(function(m,g,d){d||(d=this);var h;(h=d.define)&&h.amd?h([],function(){return g}):(h=d.modules)?h[m.toLowerCase()]=g:"undefined"!==typeof module?module.exports=g:d[m]=g})("BulkSearch",function(m,g){function d(b){this.id=z++;this.init(b||l);Object.defineProperty(this,"index",{get:function(){return this.a}});Object.defineProperty(this,"length",{get:function(){return Object.keys(this.a).length}})}function h(b,c){return new (("int"===b||"integer"===b?Uint32Array:"short"===b?Uint16Array:"float"===
    b||"double"===b?Float64Array:"byte"===b?Uint8Array:Array)||Array)(c)}function a(b){return new RegExp(b,"g")}function w(b,c,f){Eif("undefined"===typeof f){for(f=0;f<c.length;f+=2)b=b.replace(c[f],c[f+1]);return b}return b.replace(c,f)}function A(b,c){b=b.length-c.length;return 0>b?1:0<b?-1:0}function y(b){for(var c="",f="",k="",e=0;e<b.length;e++){var a=b[e];a!==f&&(0<e&&"h"===a?(k="a"===k||"e"===k||"i"===k||"o"===k||"u"===k||"y"===k,"a"!==f&&"e"!==f&&"i"!==f&&"o"!==f&&"u"!==f&&"y"!==f||!k||(c+=a)):
    c+=a);k=e===b.length-1?"":b[e+1];f=a}return c}var l={type:"integer",result:"id",separator:"~",u:!1,o:!1,h:!1,s:!1,cache:!1,encode:!1,size:4E3,depth:0},p=[],n=1E4,z=0,x={};d.new=function(b){return new this(b)};d.create=function(b){return d.new(b)};d.addMatcher=function(b){for(var c in b)b.hasOwnProperty(c)&&(p[p.length]=[a(c),b[c]])};d.prototype.init=function(b){b&&(this.type=b.type||this.type||l.type,this.result=b.result||this.result||l.result,this.separator=b.separator||this.separator||l.separator,
    this.u=b.strict||this.u||l.u,this.s=b.ordered||this.s||l.s,this.o=b.multi||this.o||l.o,this.h="or"===b["boolean"]||this.h||l.h,this.cache=b.cache||this.cache||l.cache,this.depth=b.depth||this.depth||l.depth,this.encoder=b.encode&&r[b.encode]||this.encoder||l.encode&&r[l.encode]||b.encode,n=b.size||l.size);this.c=[h(this.type,n)];this.a={};this.g={};this.l={};this.b=[""];this.v=0;this.m=!0;this.i=0;this.f=this.cache?new g(3E4,50,!0):!1};d.prototype.encode=function(b){this.encoder&&(b=this.encoder(b));
    if(p.length)for(var c=0;c<p.length;c++){var f=p[c];b=b.replace(f[0],f[1])}return b};d.prototype.add=function(b,c){if("string"===typeof c&&c&&(b||0===b))Iif(this.a[b])this.update(b,c);else{var f={},k=c.split(" ");c="";for(var e=0;e<k.length;e++){var a=k[e];a&&(this.encode&&(a=this.encode(a)),a&&!f[a]&&(f[a]="1",c+=a))}Eif(c){e=this.b;f=this.v;if((k=this.g[c.length])&&k.length){k=this.a[b]=k.pop();a=k[1];var d=e[k[0]];e[k[0]]=d.substring(0,a)+c+d.substring(k[2]);this.i-=c.length}else a=e[f].length,a+
    c.length>n&&(a<n/2&&(n*=2),this.v=++f,a=0,e[f]="",this.c[f]=h(this.type,n)),k=this.a[b]=[f,a,0,0],e[f]+=c+this.separator;Iif(this.c[f].constructor===Array)for(e=0;e<c.length;e++)this.c[f][a++]=b;else console.log(this.c[f].fill),this.c[f].fill(b,a,a+c.length+1),a+=c.length;k[2]=a;Iif(this.depth)for(e=this.depth;1<e;e--)b=c.substring(0,e),this.l[b]||(this.l[b]=[]),this.l[b].push(k);this.m=!1}}};d.prototype.update=function(b,c){if("string"===typeof c&&(b||0===b)){var f=this.a[b];Eif(f){c&&this.encode&&
    (c=this.encode(c));var a=f[1],e=f[2],d=e-a,l=c.length-d,m=c;for(0<l&&(c="");c.length<d;)c=(c+"                                                  ").substring(0,d);var g=this.b,h=f[0],q=g[h];g[h]=q.substring(0,a)+c+q.substring(e);if(0<l||!m)(c=this.g[d])?c=c.length:(this.g[d]=[],c=0),this.g[d][c]=f,this.i+=d,this.a[b]=null,m&&this.add(b,m);this.m=!1}}};d.prototype.remove=function(b){this.update(b,"");delete this.a[b]};var B=a("[ -/]");d.prototype.search=function(b,c,f){if("string"===typeof b&&b)"function"===
    typeof c?(f=c,c=1E3):c||(c=1E3);else return[];var a=b;if(!this.m)this.cache&&(this.j="",this.f.reset()),this.m=!0;else Iif(this.cache){var e=this.f.get(b);if(e)return e}else if(this.j&&-1!==b.indexOf(this.j))return[];if(f){var d=this;m(function(){f(d.search(b,c));d=null},1,"search-"+this.id);return null}for(e=0;" "===b[e];)e++;e&&(a=b.substring(e));if(!a)return[];a=this.o?a.split(B):[a];e=a.length;1<e&&a.sort(A);var l=Array(e);this.encode&&(a[0]=this.encode(a[0]));for(var g=[],h=0;h<this.b.length;h++){for(var n=
    0,q=0,p=this.b[h];-1!==(q=p.indexOf(a[0],n));){n=this.c[h][q];var v=this.a[n];Eif(v){q=v[1];v=v[2];var r=!0;if(1<e){var t=p.substring(q,v);for(var u=1;u<e;u++)if(this.encode&&!l[u]&&(a[u]=this.encode(a[u]),l[u]=!0),a[u])Iif(-1===t.indexOf(a[u]))if(this.h)r=!1;else{r=!1;break}else Iif(this.h){r=!0;break}}if(r&&(t||(t=p.substring(q,v)),t=t.substring(0,this.depth),x[t]?x[t]++:x[t]=1,g[g.length]=n,c&&g.length===c))break;q=v}n=q+1}if(c&&g.length===c)break}g.length?this.j="":this.j||(this.j=b);this.cache&&
    this.f.set(b,g);return g};d.prototype.optimize=function(){var b=this.b,c=this.a,a=this.f;this.reset();for(var d=Object.keys(c),e=0;e<d.length;e++){var g=d[e],h=c[g];h?this.add(g,b[h[0]].substring(h[1],h[2])):delete c[g]}a&&(this.f=a)};d.prototype.info=function(){for(var b=this.i,c=Object.keys(this.a).length,a=0,d=0,e=0;e<this.b.length;e++)d+=this.b[e].length;d&&(b=(100/d*b*100|0)/100,a=this.c[0].constructor===Array?32:this.c[0].byteLength,a=2*d+24*c+this.b.length*n*a);return{id:this.id,length:c,chunks:this.b.length,
    register:Object.keys(this.l).length,depth:this.depth,size:n,bytes:a,fragments:Object.keys(this.g).length,fragmented:b,status:this.m,matchers:p.length}};d.prototype.reset=function(){this.destroy();this.init()};d.prototype.destroy=function(){this.cache&&this.f.reset();this.f=this.l=this.b=this.g=this.a=this.c=null};var r={icase:function(b){return b.toLowerCase()},simple:function(){var b=[a("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"),"a",a("[\u00e8\u00e9\u00ea\u00eb]"),"e",a("[\u00ec\u00ed\u00ee\u00ef]"),
    "i",a("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),"o",a("[\u00f9\u00fa\u00fb\u00fc\u0171]"),"u",a("[\u00fd\u0177\u00ff]"),"y",a("\u00f1"),"n",a("\u00e7"),"c",a("\u00df"),"s",a("[-/]")," ",a("[^a-z0-9 ]"),""];return function(a){return w(a.toLowerCase(),b)}}(),advanced:function(){var b=a(" "),c=[a("ae"),"a",a("ai"),"ei",a("ay"),"ei",a("ey"),"ei",a("oe"),"o",a("ue"),"u",a("ie"),"i",a("sz"),"s",a("zs"),"s",a("sh"),"s",a("ck"),"k",a("cc"),"k",a("dt"),"t",a("ph"),"f",a("ou"),"o",a("uo"),"u"];return function(a,
    d){Iif(!a)return a;a=r.simple(a);2<a.length&&(a=w(a,c));d||(a=a.replace(b,""),1<a.length&&(a=y(a)));return a}}(),extra:function(){var b=[a("p"),"b",a("[sz]"),"c",a("[gq]"),"k",a("[jy]"),"i",a("n"),"m",a("d"),"t",a("[vw]"),"f",a("[aeiouy]"),""];return function(a){Iif(!a)return a;a=r.advanced(a,!0);Eif(1<a.length){a=a.split(" ");for(var c=0;c<a.length;c++){var d=a[c];1<d.length&&(a[c]=d[0]+w(d.substring(1),b))}a=a.join("");a=y(a)}return a}}()};return d}(function(){var m={};return function(g,d,h){var a=
    m[h];a&&clearTimeout(a);return m[h]=setTimeout(g,d)}}(),function(){function m(){this.cache={}}m.prototype.reset=function(){this.cache={}};m.prototype.set=function(g,d){this.cache[g]=d};m.prototype.get=function(g){return this.cache[g]};return m}()),this);