Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

flexsearch

Package Overview
Dependencies
Maintainers
1
Versions
87
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flexsearch - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

53

flexsearch.min.js
/*
FlexSearch v0.3.0
FlexSearch v0.3.1
Copyright 2019 Nextapps GmbH

@@ -8,23 +8,30 @@ Author: Thomas Wilkerling

*/
'use strict';(function(v,B,f){var w;(w=f.define)&&w.amd?w([],function(){return B}):(w=f.modules)?w[v.toLowerCase()]=B:"object"===typeof exports?module.exports=B:f[v]=B})("FlexSearch",function O(v){function f(a){"string"===typeof a&&(a=H[a]);a||(a=y);this.id=a.id||P++;this.init(a);w(this,"index",function(){return this.a});w(this,"length",function(){return Object.keys(this.a).length})}function w(a,b,e){Object.defineProperty(a,b,{get:e})}function d(a){return new RegExp(a,"g")}function x(a,b,e){if("undefined"===
typeof e){for(e=0;e<b.length;e+=2)a=a.replace(b[e],b[e+1]);return a}return a.replace(b,e)}function z(a,b,e,c,k,u,g){if(b[e])return b[e];k=k?(9-(g||6))*u+(g||6)*k:u;b[e]=k;k>=g&&(a=a[k+.5>>0],a=a[e]||(a[e]=[]),a[a.length]=c);return k}function q(a,b){if(a)for(var e=Object.keys(a),c=0,k=e.length;c<k;c++){var u=e[c],g=a[u];if(g)for(var h=0,d=g.length;h<d;h++)if(g[h]===b){1===d?delete a[u]:g.splice(h,1);break}else"object"===typeof g[h]&&q(g[h],b)}}function I(a){var b=[];if(!a)return b;for(var e=0,c=0,
k=0,u="",g=a.length,h=0;h<g;h++){var d=a[h];"a"===d||"e"===d||"i"===d||"o"===d||"u"===d||"y"===d?e++:c++;" "!==d&&(u+=d);if(" "===d||e>=(8<g?2:1)&&2<=c||2<=e&&c>=(8<g?2:1)||h===g-1)u&&(b[k]&&2<u.length&&k++,b[k]=b[k]?b[k]+u:u," "===d&&k++,u=""),c=e=0}return b}function E(a){for(var b="",e="",c="",k=0;k<a.length;k++){var d=a[k];if(d!==e)if(k&&"h"===d){if(c="a"===c||"e"===c||"i"===c||"o"===c||"u"===c||"y"===c,("a"===e||"e"===e||"i"===e||"o"===e||"u"===e||"y"===e)&&c||" "===e)b+=d}else b+=d;c=k===a.length-
1?"":a[k+1];e=d}return b}function Q(a,b){var e={};if(a)for(var c=0;c<a.length;c++){var k=b?b(a[c]):a[c];e[k]=String.fromCharCode(65E3-a.length+c)}return e}function R(a,b){var e=[];if(a)for(var c in a)if(a.hasOwnProperty(c)){var k=b?b(c):c;e.push(d("(?=.{"+(k.length+3)+",})"+k+"$"),b?b(a[c]):a[c])}return e}function S(a,b){a=a.length-b.length;return 0>a?1:a?-1:0}function T(a,b){a=a.length-b.length;return 0>a?-1:a?1:0}function U(a,b,e){var c=[],k=[],d=a.length;if(1<d){a.sort(T);for(var g={},h=a[0],C=
h.length,m=0;m<C;)g[h[m++]]=1;for(var n,p=0,l=1;l<d;){var f=!1,q=l===d-1;k=[];h=a[l];C=h.length;for(m=-1;m<C;)if(n=h[++m],g[n]){var r=g[n];if(r===l){if(q){if(c[p++]=n,b&&p===b)return c}else g[n]=l+1;f=!0}else e&&(r=k[r]?k[r]:k[r]=[],r[r.length]=n)}if(!f&&!e)break;l++}if(e&&(p=c.length,(C=k.length)&&(!b||p<b)))for(l=C-1;0<=l;l--)if(n=k[l])for(m=0;m<n.length;m++)if(c[p++]=n[m],b&&p===b)return c}else d&&(c=a[0],b&&c.length>b&&(c=c.slice(0,b)));return c}function F(a){a.C||(a.C=J(function(){a.C=0;var b=
a.async;b&&(a.async=!1);if(a.c.length){for(var e=Date.now(),c;(c=a.c.shift())||0===c;){var d=a.f[c];switch(d[0]){case D.add:a.add(d[1],d[2]);break;case D.remove:a.remove(d[1])}delete a.f[c];if(100<Date.now()-e)break}a.c.length&&F(a)}b&&(a.async=b)},1,"search-async-"+a.id))}function K(a){for(var b=Array(a),e=0;e<a;e++)b[e]={};return b}function V(a,b,e,c){a=v("flexsearch","id"+a,function(){var a,b;self.onmessage=function(c){if(c=c.data)if(c.search){var e=b.search(c.content,c.threshold?{limit:c.limit,
threshold:c.threshold}:c.limit);self.postMessage({id:a,content:c.content,limit:c.limit,result:e})}else c.add?b.add(c.id,c.content):c.update?b.update(c.id,c.content):c.remove?b.remove(c.id):c.clear?b.clear():c.register&&(a=c.id,c.options.cache=!1,c.options.async=!0,c.options.worker=!1,b=(new Function(c.register.substring(c.register.indexOf("{")+1,c.register.lastIndexOf("}"))))(),b=new b(c.options))}},function(a){(a=a.data)&&a.result&&c(a.id,a.content,a.result,a.limit)},b);var d=O.toString();e.id=b;
a.postMessage(b,{register:d,options:e,id:b});return a}var y={encode:"icase",mode:"forward",s:!1,cache:!1,async:!1,b:!1,threshold:0,depth:0},H={memory:{encode:"extra",mode:"strict",threshold:7},speed:{encode:"icase",mode:"strict",threshold:7,depth:2},match:{encode:"extra",mode:"full"},score:{encode:"extra",mode:"strict",threshold:5,depth:4},balance:{encode:"balance",mode:"strict",threshold:6,depth:3},fastest:{encode:"icase",mode:"strict",threshold:9,depth:1}},G=[],P=0,D={add:0,update:1,remove:2},L=
d("[ -/]"),M={},N={};f.create=function(a){return new this(a)};f.registerMatcher=function(a){for(var b in a)a.hasOwnProperty(b)&&G.push(d(b),a[b]);return this};f.registerEncoder=function(a,b){A[a]=b.bind(A);return this};f.registerLanguage=function(a,b){M[a]=b.filter;N[a]=b.stemmer;return this};f.encode=function(a,b){return A[a](b)};f.prototype.init=function(a){this.B=[];a||(a=y);var b=a.profile,e=b?H[b]:{};if(b=a.worker)if(Worker){var c=this;b=parseInt(b,10)||4;c.l=-1;c.m=0;c.g=[];c.A=null;c.i=Array(b);
for(var d=0;d<b;d++)c.i[d]=V(c.id,d,a,function(a,b,e,d){if(c.m!==c.b)return c.g=c.g.concat(e),c.m++,d&&c.g.length>=d&&(c.m=c.b),c.A&&c.m===c.b&&(c.cache&&c.h.set(b,c.g),c.A(c.g),c.g=[]),c})}else a.worker=!1,this.i=null;this.mode=a.mode||e.mode||this.mode||y.mode;this.async=a.async||this.async||y.async;this.b=a.worker||this.b||y.b;this.threshold=a.threshold||e.threshold||this.threshold||y.threshold;this.depth=a.depth||e.depth||this.depth||y.depth;this.s=a.suggest||this.s||y.s;this.o=(b=a.encode||e.encode)&&
A[b]&&A[b].bind(A)||("function"===typeof b?b:this.o||!1);(b=a.matcher)&&this.addMatcher(b);if(b=a.filter)this.filter=Q(M[b]||b,this.o);if(b=a.stemmer)this.stemmer=R(N[b]||b,this.o);this.v=K(10);this.j={};this.a={};this.f={};this.c=[];this.C=0;this.u=!0;this.h=(this.cache=b=a.cache||this.cache||y.cache)?new W(b):!1;return this};f.prototype.encode=function(a){a&&G.length&&(a=x(a,G));a&&this.B.length&&(a=x(a,this.B));a&&this.o&&(a=this.o(a));a&&this.stemmer&&(a=x(a,this.stemmer));return a};f.prototype.addMatcher=
function(a){var b=this.B,e;for(e in a)a.hasOwnProperty(e)&&b.push(d(e),a[e]);return this};f.prototype.add=function(a,b,e){if(b&&"string"===typeof b&&(a||0===a))if(this.a[a]&&!e)this.update(a,b);else{if(this.b)return++this.l>=this.i.length&&(this.l=0),this.i[this.l].postMessage(this.l,{add:!0,id:a,content:b}),this.a[a]=""+this.l,this;if(this.async)return this.f[a]||(this.c[this.c.length]=a),this.f[a]=[D.add,a,b],F(this),this;b=this.encode(b);if(!b.length)return this;e=this.mode;b="function"===typeof e?
e(b):"ngram"===e?I(b):b.split(L);for(var c={_ctx:{}},d=this.threshold,u=this.depth,g=this.v,h=b.length,f=0;f<h;f++){var m=b[f];if(m){var n=m.length,p=(h-f)/h,l="";switch(e){case "reverse":case "both":for(var t=n-1;1<=t;t--)l=m[t]+l,z(g,c,l,a,(n-t)/n,p,d);l="";case "forward":for(t=0;t<n;t++)l+=m[t],z(g,c,l,a,1,p,d);break;case "full":for(t=0;t<n;t++)for(var q=(n-t)/n,r=n;r>t;r--)l=m.substring(t,r),z(g,c,l,a,q,p,d);break;default:if(n=z(g,c,m,a,1,p,d),u&&1<h&&n>=d)for(n=c._ctx[m]||(c._ctx[m]={}),m=this.j[m]||
(this.j[m]=K(10)),p=f-u,l=f+u+1,0>p&&(p=0),l>h&&(l=h);p<l;p++)p!==f&&z(m,n,b[p],a,0,10-(p<f?f-p:p-f),d)}}}this.a[a]="1";this.u=!1}return this};f.prototype.update=function(a,b){this.a[a]&&b&&"string"===typeof b&&(this.remove(a),this.add(a,b,!0));return this};f.prototype.remove=function(a){if(this.a[a]){if(this.b){var b=parseInt(this.a[a],10);this.i[b].postMessage(b,{remove:!0,id:a});delete this.a[a];return this}if(this.async)return this.f[a]||(this.c[this.c.length]=a),this.f[a]=[D.remove,a],F(this),
this;for(b=0;10>b;b++)q(this.v[b],a);this.depth&&q(this.j,a);delete this.a[a];this.u=!1}return this};f.prototype.search=function(a,b,e){var c=[];if("object"===typeof a){e=a.callback||b;b=a.limit;var d=a.threshold;a=a.query}d||(d=this.threshold||0);"function"===typeof b?(e=b,b=1E3):b||0===b||(b=1E3);if(this.b)for(this.A=e,this.m=0,this.g=[],c=0;c<this.b;c++)this.i[c].postMessage(c,{search:!0,limit:b,threshold:d,content:a});else if(e){var f=this;J(function(){e(f.search(a,b));f=null},1,"search-"+this.id)}else{if(!a||
"string"!==typeof a)return c;var g=a;if(this.cache)if(this.u){var h=this.h.get(a);if(h)return h}else this.h.clear(),this.u=!0;g=this.encode(g);if(!g.length)return c;h=this.mode;g="function"===typeof h?h(g):"ngram"===h?I(g):g.split(L);h=g.length;var q=!0,m=[],n={};if(1<h)if(this.depth){var p=!0;var l=g[0];n[l]="1"}else g.sort(S);var t;if(!p||(t=this.j)[l])for(var v=p?1:0;v<h;v++){var r=g[v];if(r&&!n[r]){for(var w=void 0,y=!1,x=[],z=0,A=9;A>=d;A--)w=(p?t[l]:this.v)[A],w[r]&&(x[z++]=w[r],y=!0);if(y)m[m.length]=
1<z?m.concat.apply([],x):x[0];else if(!this.s){q=!1;break}n[r]="1"}l=r}else q=!1;q&&(c=U(m,b,this.s));this.cache&&this.h.set(a,c);return c}};f.prototype.clear=function(){this.destroy();return this.init()};f.prototype.destroy=function(){this.cache&&(this.h.clear(),this.h=null);this.filter=this.stemmer=this.v=this.j=this.a=this.f=this.c=null;return this};var A={icase:function(a){return a.toLowerCase()},simple:function(){var a=[d("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"),"a",d("[\u00e8\u00e9\u00ea\u00eb]"),
"e",d("[\u00ec\u00ed\u00ee\u00ef]"),"i",d("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),"o",d("[\u00f9\u00fa\u00fb\u00fc\u0171]"),"u",d("[\u00fd\u0177\u00ff]"),"y",d("\u00f1"),"n",d("\u00e7"),"c",d("\u00df"),"s",d(" & ")," and ",d("[-/]")," ",d("[^a-z0-9 ]"),"",d("\\s\\s+")," "];return function(b){b=x(b.toLowerCase(),a);return" "!==b?b:""}}(),advanced:function(){var a=[d("ae"),"a",d("ai"),"ei",d("ay"),"ei",d("ey"),"ei",d("oe"),"o",d("ue"),"u",d("ie"),"i",d("sz"),"s",d("zs"),"s",d("sh"),"s",d("ck"),"k",
d("cc"),"k",d("dt"),"t",d("ph"),"f",d("pf"),"f",d("ou"),"o",d("uo"),"u"];return function(b,d){if(!b)return b;b=this.simple(b);2<b.length&&(b=x(b,a));d||1<b.length&&(b=E(b));return b}}(),extra:function(){var a=[d("p"),"b",d("z"),"s",d("[cgq]"),"k",d("n"),"m",d("d"),"t",d("[vw]"),"f",d("[aeiouy]"),""];return function(b){if(!b)return b;b=this.advanced(b,!0);if(1<b.length){b=b.split(" ");for(var d=0;d<b.length;d++){var c=b[d];1<c.length&&(b[d]=c[0]+x(c.substring(1),a))}b=b.join(" ");b=E(b)}return b}}(),
balance:function(){var a=[d("[-/]")," ",d("[^a-z0-9 ]"),"",d("\\s\\s+")," "];return function(b){return E(x(b.toLowerCase(),a))}}()},J=function(){var a={};return function(b,d,c){var e=a[c];e&&clearTimeout(e);return a[c]=setTimeout(b,d)}}(),W=function(){function a(a){this.clear();this.w=!0!==a&&a}a.prototype.clear=function(){this.cache={};this.count={};this.index={};this.a=[]};a.prototype.set=function(a,d){if(this.w&&"undefined"===typeof this.cache[a]){var b=this.a.length;if(b===this.w){b--;var e=this.a[b];
delete this.cache[e];delete this.count[e];delete this.index[e]}this.index[a]=b;this.a[b]=a;this.count[a]=-1;this.cache[a]=d;this.get(a)}else this.cache[a]=d};a.prototype.get=function(a){var b=this.cache[a];if(this.w&&b){var c=++this.count[a],d=this.index,f=d[a];if(0<f){for(var g=this.a,h=f;this.count[g[--f]]<=c&&-1!==f;);f++;if(f!==h){for(c=h;c>f;c--)h=g[c-1],g[c]=h,d[h]=c;g[f]=a;d[a]=f}}}return b};return a}();return f}(function(){var v=Object.create(null),B=!("undefined"===typeof Blob||"undefined"===
typeof URL||!URL.createObjectURL);return function(f,w,d,x,z){var q=f;f=B?URL.createObjectURL(new Blob(["("+d.toString()+")()"],{type:"text/javascript"})):"../"+q+".min.js";q+="-"+w;v[q]||(v[q]=[]);v[q][z]=new Worker(f);v[q][z].onmessage=x;return{postMessage:function(d,f){v[q][d].postMessage(f)}}}}()),this);
'use strict';function J(g){var h=0;return function(){return h<g.length?{done:!1,value:g[h++]}:{done:!0}}}function K(g){var h="undefined"!=typeof Symbol&&Symbol.iterator&&g[Symbol.iterator];return h?h.call(g):{next:J(g)}}var S="undefined"!=typeof window&&window===this?this:"undefined"!=typeof global&&null!=global?global:this,T="function"==typeof Object.defineProperties?Object.defineProperty:function(g,h,e){g!=Array.prototype&&g!=Object.prototype&&(g[h]=e.value)};
function U(g,h){if(h){var e=S;g=g.split(".");for(var k=0;k<g.length-1;k++){var a=g[k];a in e||(e[a]={});e=e[a]}g=g[g.length-1];k=e[g];h=h(k);h!=k&&null!=h&&T(e,g,{configurable:!0,writable:!0,value:h})}}
U("Promise",function(g){function h(d){this.b=0;this.g=void 0;this.a=[];var a=this.c();try{d(a.resolve,a.reject)}catch(D){a.reject(D)}}function e(){this.a=null}function k(d){return d instanceof h?d:new h(function(a){a(d)})}if(g)return g;e.prototype.b=function(d){if(null==this.a){this.a=[];var a=this;this.c(function(){a.g()})}this.a.push(d)};var a=S.setTimeout;e.prototype.c=function(d){a(d,0)};e.prototype.g=function(){for(;this.a&&this.a.length;){var d=this.a;this.a=[];for(var a=0;a<d.length;++a){var h=
d[a];d[a]=null;try{h()}catch(v){this.f(v)}}}this.a=null};e.prototype.f=function(d){this.c(function(){throw d;})};h.prototype.c=function(){function d(d){return function(e){h||(h=!0,d.call(a,e))}}var a=this,h=!1;return{resolve:d(this.o),reject:d(this.f)}};h.prototype.o=function(d){if(d===this)this.f(new TypeError("A Promise cannot resolve to itself"));else if(d instanceof h)this.s(d);else{a:switch(typeof d){case "object":var a=null!=d;break a;case "function":a=!0;break a;default:a=!1}a?this.m(d):this.i(d)}};
h.prototype.m=function(a){var d=void 0;try{d=a.then}catch(D){this.f(D);return}"function"==typeof d?this.u(d,a):this.i(a)};h.prototype.f=function(a){this.j(2,a)};h.prototype.i=function(a){this.j(1,a)};h.prototype.j=function(a,h){if(0!=this.b)throw Error("Cannot settle("+a+", "+h+"): Promise already settled in state"+this.b);this.b=a;this.g=h;this.l()};h.prototype.l=function(){if(null!=this.a){for(var a=0;a<this.a.length;++a)l.b(this.a[a]);this.a=null}};var l=new e;h.prototype.s=function(a){var d=this.c();
a.w(d.resolve,d.reject)};h.prototype.u=function(a,h){var d=this.c();try{a.call(h,d.resolve,d.reject)}catch(v){d.reject(v)}};h.prototype.then=function(a,e){function d(a,d){return"function"==typeof a?function(d){try{g(a(d))}catch(E){k(E)}}:d}var g,k,m=new h(function(a,d){g=a;k=d});this.w(d(a,g),d(e,k));return m};h.prototype.catch=function(a){return this.then(void 0,a)};h.prototype.w=function(a,h){function d(){switch(e.b){case 1:a(e.g);break;case 2:h(e.g);break;default:throw Error("Unexpected state: "+
e.b);}}var e=this;null==this.a?l.b(d):this.a.push(d)};h.resolve=k;h.reject=function(a){return new h(function(d,h){h(a)})};h.race=function(a){return new h(function(d,h){for(var e=K(a),g=e.next();!g.done;g=e.next())k(g.value).w(d,h)})};h.all=function(a){var d=K(a),e=d.next();return e.done?k([]):new h(function(a,h){function g(d){return function(h){m[d]=h;l--;0==l&&a(m)}}var m=[],l=0;do m.push(void 0),l++,k(e.value).w(g(m.length-1),h),e=d.next();while(!e.done)})};return h});
(function(g,h,e){var k;(k=e.define)&&k.amd?k([],function(){return h}):(k=e.modules)?k[g.toLowerCase()]=h:"object"===typeof exports?module.exports=h:e[g]=h})("FlexSearch",function aa(g){function e(b){E(b)&&(b=L[b]);b||(b=w);this.id=b.id||ba++;this.init(b);k(this,"index",function(){return this.a});k(this,"length",function(){return Object.keys(this.a).length})}function k(b,c,a){Object.defineProperty(b,c,{get:a})}function a(b){return new RegExp(b,"g")}function l(b,c){for(var a=0;a<c.length;a+=2)b=b.replace(c[a],
c[a+1]);return b}function d(b,c,a,f,A,d,e){if(c[a])return c[a];A=A?(9-(e||6))*d+(e||6)*A:d;c[a]=A;A>=e&&(b=b[A+.5>>0],b=b[a]||(b[a]=[]),b[b.length]=f);return A}function m(b,c){if(b)for(var a=Object.keys(b),f=0,A=a.length;f<A;f++){var d=a[f],e=b[d];if(e)for(var r=0,g=e.length;r<g;r++)if(e[r]===c){1===g?delete b[d]:e.splice(r,1);break}else"object"===typeof e[r]&&m(e[r],c)}}function D(b){var c=[];if(!b)return c;for(var a=0,f=0,d=0,e="",g=b.length,r=0;r<g;r++){var z=b[r];"a"===z||"e"===z||"i"===z||"o"===
z||"u"===z||"y"===z?a++:f++;" "!==z&&(e+=z);if(" "===z||a>=(8<g?2:1)&&2<=f||2<=a&&f>=(8<g?2:1)||r===g-1)e&&(c[d]&&2<e.length&&d++,c[d]=c[d]?c[d]+e:e," "===z&&d++,e=""),f=a=0}return c}function v(b){for(var c="",a="",f="",d=0;d<b.length;d++){var e=b[d];if(e!==a)if(d&&"h"===e){if(f="a"===f||"e"===f||"i"===f||"o"===f||"u"===f||"y"===f,("a"===a||"e"===a||"i"===a||"o"===a||"u"===a||"y"===a)&&f||" "===a)c+=e}else c+=e;f=d===b.length-1?"":b[d+1];a=e}return c}function V(b,c){var a={};if(b)for(var f=0;f<b.length;f++){var d=
c?c(b[f]):b[f];a[d]=String.fromCharCode(65E3-b.length+f)}return a}function Z(b,c){var d=[];if(b)for(var f in b)if(b.hasOwnProperty(f)){var e=c?c(f):f;d.push(a("(?=.{"+(e.length+3)+",})"+e+"$"),c?c(b[f]):b[f])}return d}function W(b,c){b=b.length-c.length;return 0>b?1:b?-1:0}function X(b,c){b=b.length-c.length;return 0>b?-1:b?1:0}function Y(b,c,a){var f=[],d=[],e=b.length;if(1<e){b.sort(X);for(var g={},r=b[0],t=r.length,k=0;k<t;)g[r[k++]]=1;for(var n,p=0,q=0;++q<e;){var u=!1,m=q===e-1;d=[];r=b[q];t=
r.length;for(k=0;k<t;)if(n=r[k++],g[n]){var l=g[n];if(l===q){if(m){if(f[p++]=n,c&&p===c)return f}else g[n]=q+1;u=!0}else a&&(l=d[l]||(d[l]=[]),l[l.length]=n)}if(!u&&!a)break}if(a&&(p=f.length,(q=d.length)&&(!c||p<c)))for(;q--;)if(n=d[q])for(b=0,a=n.length;b<a;b++)if(f[p++]=n[b],c&&p===c)return f}else e&&(f=b[0],c&&f.length>c&&(f=f.slice(0,c)));return f}function E(b){return"string"===typeof b}function H(b){return"function"===typeof b}function x(b){return"undefined"===typeof b}function B(b){b.D||(b.D=
M(function(){b.D=0;var c=b.async;c&&(b.async=!1);if(b.b.length){for(var a=Date.now(),f;(f=b.b.shift())||0===f;){var d=b.c[f];switch(d[0]){case C.add:b.add(d[1],d[2]);break;case C.remove:b.remove(d[1])}delete b.c[f];if(100<Date.now()-a)break}b.b.length&&B(b)}c&&(b.async=c)},1,"search-async-"+b.id))}function N(b){for(var c=Array(b),a=0;a<b;a++)c[a]={};return c}function ca(b,c,a,f){b=g("flexsearch","id"+b,function(){var b,c;self.onmessage=function(a){if(a=a.data)if(a.search){var f=c.search(a.content,
a.threshold?{limit:a.limit,threshold:a.threshold}:a.limit);self.postMessage({id:b,content:a.content,limit:a.limit,result:f})}else a.add?c.add(a.id,a.content):a.update?c.update(a.id,a.content):a.remove?c.remove(a.id):a.clear?c.clear():a.register&&(b=a.id,a.options.cache=!1,a.options.async=!0,a.options.worker=!1,c=(new Function(a.register.substring(a.register.indexOf("{")+1,a.register.lastIndexOf("}"))))(),c=new c(a.options))}},function(b){(b=b.data)&&b.result&&f(b.id,b.content,b.result,b.limit)},c);
var d=aa.toString();a.id=c;b.postMessage(c,{register:d,options:a,id:c});return b}var w={encode:"icase",mode:"forward",v:!1,cache:!1,async:!1,h:!1,threshold:0,depth:0},L={memory:{encode:"extra",mode:"strict",threshold:7},speed:{encode:"icase",mode:"strict",threshold:7,depth:2},match:{encode:"extra",mode:"full"},score:{encode:"extra",mode:"strict",threshold:5,depth:4},balance:{encode:"balance",mode:"strict",threshold:6,depth:3},fastest:{encode:"icase",mode:"strict",threshold:9,depth:1}},F=[],ba=0,C=
{add:0,update:1,remove:2},O=a("[ -/]"),P={},Q={},R=function(){for(var b=Object.getOwnPropertyNames({}.__proto__),c={},a=0;a<b.length;a++)c[b[a]]=1;return c}();e.create=function(b){return new e(b)};e.registerMatcher=function(b){for(var c in b)b.hasOwnProperty(c)&&F.push(a(c),b[c]);return this};e.registerEncoder=function(b,c){y[b]=c.bind(y);return this};e.registerLanguage=function(b,c){P[b]=c.filter;Q[b]=c.stemmer;return this};e.encode=function(b,c){return R[b]?c:y[b](c)};e.prototype.init=function(b){this.C=
[];b||(b=w);var c=b.profile,a=c?L[c]:{};if(c=b.worker)if(Worker){var f=this,d=parseInt(c,10)||4;f.l=-1;f.m=0;f.f=[];f.B=null;f.i=Array(d);for(var e=0;e<d;e++)f.i[e]=ca(f.id,e,b,function(b,c,a,d){if(f.m!==f.h)return f.f=f.f.concat(a),f.m++,d&&f.f.length>=d&&(f.m=f.h),f.B&&f.m===f.h&&(f.cache&&f.g.set(c,f.f),f.B(f.f),f.f=[]),f})}else b.worker=!1,this.i=null;this.mode=b.mode||a.mode||this.mode||w.mode;this.async=x(c=b.async)?this.async||w.async:c;this.h=x(c=b.worker)?this.h||w.h:c;this.threshold=x(c=
b.threshold)?a.threshold||this.threshold||w.threshold:c;this.depth=x(c=b.depth)?a.depth||this.depth||w.depth:c;this.v=x(c=b.suggest)?this.v||w.v:c;this.o=(c=x(c=b.encode)?a.encode:c)&&y[c]&&y[c].bind(y)||(H(c)?c:this.o||!1);(c=b.matcher)&&this.addMatcher(c);if(c=b.filter)this.filter=V(P[c]||c,this.o);if(c=b.stemmer)this.stemmer=Z(Q[c]||c,this.o);this.u=N(10);this.j={};this.a={};this.c={};this.b=[];this.D=0;this.s=!0;this.g=(this.cache=c=x(c=b.cache)?this.cache||w.cache:c)?new da(c):!1;return this};
e.prototype.encode=function(b){b&&F.length&&(b=l(b,F));b&&this.C.length&&(b=l(b,this.C));b&&this.o&&(b=this.o(b));b&&this.stemmer&&(b=l(b,this.stemmer));return b};e.prototype.addMatcher=function(b){var c=this.C,d;for(d in b)b.hasOwnProperty(d)&&c.push(a(d),b[d]);return this};e.prototype.add=function(b,c,a){if(c&&E(c)&&(b&&!R[b]||0===b))if(this.a[b]&&!a)this.update(b,c);else{if(this.h)return++this.l>=this.i.length&&(this.l=0),this.i[this.l].postMessage(this.l,{add:!0,id:b,content:c}),this.a[b]=""+
this.l,this;if(this.async)return this.c[b]||(this.b[this.b.length]=b),this.c[b]=[C.add,b,c],B(this),this;c=this.encode(c);if(!c.length)return this;a=this.mode;c=H(a)?a(c):"ngram"===a?D(c):c.split(O);for(var f={_ctx:{}},e=this.threshold,g=this.depth,k=this.u,r=c.length,t=0;t<r;t++){var l=c[t];if(l){var n=l.length,p=(r-t)/r,q="";switch(a){case "reverse":case "both":for(var u=n-1;1<=u;u--)q=l[u]+q,d(k,f,q,b,(n-u)/n,p,e);q="";case "forward":for(u=0;u<n;u++)q+=l[u],d(k,f,q,b,1,p,e);break;case "full":for(u=
0;u<n;u++)for(var m=(n-u)/n,v=n;v>u;v--)q=l.substring(u,v),d(k,f,q,b,m,p,e);break;default:if(n=d(k,f,l,b,1,p,e),g&&1<r&&n>=e)for(n=f._ctx[l]||(f._ctx[l]={}),l=this.j[l]||(this.j[l]=N(10)),p=t-g,q=t+g+1,0>p&&(p=0),q>r&&(q=r);p<q;p++)p!==t&&d(l,n,c[p],b,0,10-(p<t?t-p:p-t),e)}}}this.a[b]=1;this.s=!1}return this};e.prototype.update=function(b,c){this.a[b]&&E(c)&&(this.remove(b),this.add(b,c,!0));return this};e.prototype.remove=function(b){if(this.a[b]){if(this.h){var c=this.a[b];this.i[c].postMessage(c,
{remove:!0,id:b});delete this.a[b];return this}if(this.async)return this.c[b]||(this.b[this.b.length]=b),this.c[b]=[C.remove,b],B(this),this;for(c=0;10>c;c++)m(this.u[c],b);this.depth&&m(this.j,b);delete this.a[b];this.s=!1}return this};e.prototype.search=function(b,c,a,f){var d=b,e=[];if("object"===typeof b){(a=b.callback||c)&&(d.callback=null);c=b.limit;var g=b.threshold;b=b.query}g||(g=this.threshold||0);H(c)?(a=c,c=1E3):c||0===c||(c=1E3);if(this.h)for(this.B=a,this.m=0,this.f=[],e=0;e<this.h;e++)this.i[e].postMessage(e,
{search:!0,limit:c,threshold:g,content:b});else if(a){var k=this;M(function(){a(k.search(d,c,null,!0));k=null},1,"search-"+this.id)}else{if(!f&&this.async){var l=this;return new Promise(function(b){b(l.search(d,c,null,!0));l=null})}if(!b||!E(b))return e;d=b;if(this.cache)if(this.s){if(f=this.g.get(b))return f}else this.g.clear(),this.s=!0;d=this.encode(d);if(!d.length)return e;f=this.mode;f=H(f)?f(d):"ngram"===f?D(d):d.split(O);var t=f.length,n=!0,p=[],q={};if(1<t)if(this.depth){var m=!0;var v=f[0];
q[v]=1}else f.sort(W);var w;if(!m||(w=this.j)[v])for(var x=m?1:0;x<t;x++){var y=f[x];if(y&&!q[y]){var G=void 0;G=void 0;for(var C=!1,B=[],F=0,I=9;I>=g;I--)if(G=(m?w[v]:this.u)[I],G=G[y])B[F++]=G,C=!0;if(C)p[p.length]=1<F?p.concat.apply([],B):B[0];else if(!this.v){n=!1;break}q[y]=1}v=y}else n=!1;n&&(e=Y(p,c,this.v));this.cache&&this.g.set(b,e);return e}};e.prototype.clear=function(){this.destroy();return this.init()};e.prototype.destroy=function(){this.cache&&(this.g.clear(),this.g=null);this.filter=
this.stemmer=this.u=this.j=this.a=this.c=this.b=null;return this};var y={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(" & ")," and ",a("[-/]")," ",a("[^a-z0-9 ]"),"",a("\\s\\s+")," "];return function(c){c=
l(c.toLowerCase(),b);return" "!==c?c:""}}(),advanced:function(){var b=[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("pf"),"f",a("ou"),"o",a("uo"),"u"];return function(c,a){if(!c)return c;c=this.simple(c);2<c.length&&(c=l(c,b));a||1<c.length&&(c=v(c));return c}}(),extra:function(){var b=[a("p"),"b",a("z"),"s",a("[cgq]"),"k",a("n"),"m",a("d"),"t",a("[vw]"),"f",a("[aeiouy]"),
""];return function(a){if(!a)return a;a=this.advanced(a,!0);if(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]+l(d.substring(1),b))}a=a.join(" ");a=v(a)}return a}}(),balance:function(){var b=[a("[-/]")," ",a("[^a-z0-9 ]"),"",a("\\s\\s+")," "];return function(a){return v(l(a.toLowerCase(),b))}}()},M=function(){var b={};return function(a,d,f){var c=b[f];c&&clearTimeout(c);return b[f]=setTimeout(a,d)}}(),da=function(){function a(a){this.clear();this.A=!0!==a&&
a}a.prototype.clear=function(){this.cache={};this.count={};this.index={};this.a=[]};a.prototype.set=function(a,b){if(this.A&&x(this.cache[a])){var c=this.a.length;if(c===this.A){c--;var d=this.a[c];delete this.cache[d];delete this.count[d];delete this.index[d]}this.index[a]=c;this.a[c]=a;this.count[a]=-1;this.cache[a]=b;this.get(a)}else this.cache[a]=b};a.prototype.get=function(a){var b=this.cache[a];if(this.A&&b){var c=++this.count[a],d=this.index,e=d[a];if(0<e){for(var g=this.a,k=e;this.count[g[--e]]<=
c&&-1!==e;);e++;if(e!==k){for(c=k;c>e;c--)k=g[c-1],g[c]=k,d[k]=c;g[e]=a;d[a]=e}}}return b};return a}();return e}(function(){var g=Object.create(null),h="undefined"!==typeof Blob&&"undefined"!==typeof URL&&URL.createObjectURL;return function(e,k,a,l,d){var m=e;e=h?URL.createObjectURL(new Blob(["("+a.toString()+")()"],{type:"text/javascript"})):"../"+m+".min.js";m+="-"+k;g[m]||(g[m]=[]);g[m][d]=new Worker(e);g[m][d].onmessage=l;return{postMessage:function(a,d){g[m][a].postMessage(d)}}}}()),this);
{
"name": "flexsearch",
"version": "0.3.0",
"version": "0.3.1",
"description": "Next-Generation full text search library with zero dependencies.",

@@ -27,6 +27,6 @@ "homepage": "https://github.com/nextapps-de/flexsearch/",

"scripts": {
"build": "node compile RELEASE=min DEBUG=false PROFILER=false SUPPORT_WORKER=true SUPPORT_ENCODER=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_PRESETS=true SUPPORT_LANG_DE=false SUPPORT_LANG_EN=false",
"build-light": "node compile RELEASE=light DEBUG=false PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=false SUPPORT_CACHE=false SUPPORT_ASYNC=false SUPPORT_PRESETS=false SUPPORT_LANG_DE=false SUPPORT_LANG_EN=false",
"build-compact": "node compile RELEASE=compact DEBUG=false PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=true SUPPORT_CACHE=true SUPPORT_ASYNC=false SUPPORT_PRESETS=true SUPPORT_LANG_DE=false SUPPORT_LANG_EN=false",
"build-custom": "node compile RELEASE=custom DEBUG=false PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=false SUPPORT_CACHE=false SUPPORT_ASYNC=false SUPPORT_PRESETS=false SUPPORT_LANG_DE=false SUPPORT_LANG_EN=false",
"build": "node compile RELEASE=min DEBUG=false PROFILER=false SUPPORT_WORKER=true SUPPORT_ENCODER=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_PRESETS=true SUPPORT_SUGGESTIONS=true SUPPORT_LANG_DE=false SUPPORT_LANG_EN=false",
"build-light": "node compile RELEASE=light DEBUG=false PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=false SUPPORT_CACHE=false SUPPORT_ASYNC=false SUPPORT_PRESETS=false SUPPORT_SUGGESTIONS=false SUPPORT_LANG_DE=false SUPPORT_LANG_EN=false",
"build-compact": "node compile RELEASE=compact DEBUG=false PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=true SUPPORT_CACHE=false SUPPORT_ASYNC=true SUPPORT_PRESETS=true SUPPORT_SUGGESTIONS=false SUPPORT_LANG_DE=false SUPPORT_LANG_EN=false",
"build-custom": "node compile RELEASE=custom DEBUG=false PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=false SUPPORT_CACHE=false SUPPORT_ASYNC=false SUPPORT_PRESETS=false SUPPORT_SUGGESTIONS=false SUPPORT_LANG_DE=false SUPPORT_LANG_EN=false",
"build-lang": "node compile RELEASE=lang",

@@ -63,4 +63,4 @@ "build-all": "npm run build && npm run build-light && npm run build-compact && npm run build-lang",

"phantomjs-prebuilt": "^2.1.16",
"updtr": "^2.0.0"
"updtr": "^3.0.0"
}
}

@@ -73,3 +73,3 @@ <p align="center">

<td>
<a href="#webworker">Web-Worker Sharding</a> (not available in Node.js)
<a href="#profiles">Presets</a>
</td>

@@ -83,7 +83,16 @@ <td>x</td>

<td>
<a href="#contextual">Contextual Indexes</a>
<a href="#async">Async Processing</a>
</td>
<td>x</td>
<td>x</td>
<td>-</td>
</tr>
<tr></tr>
<tr>
<td>
<a href="#webworker">Web-Worker Sharding</a> (not available in Node.js)
</td>
<td>x</td>
<td>-</td>
<td>-</td>
</tr>

@@ -93,3 +102,3 @@ <tr></tr>

<td>
Partial Matching
<a href="#contextual">Contextual Indexes</a>
</td>

@@ -103,3 +112,3 @@ <td>x</td>

<td>
Multi-Phrase Search
Partial Matching
</td>

@@ -113,3 +122,3 @@ <td>x</td>

<td>
Relevance-based Scoring
Multi-Phrase Search
</td>

@@ -123,7 +132,7 @@ <td>x</td>

<td>
Auto-Balanced Cache by Popularity
Relevance-based Scoring
</td>
<td>x</td>
<td>x</td>
<td>-</td>
<td>x</td>
</tr>

@@ -133,7 +142,7 @@ <tr></tr>

<td>
Suggestions (Results)
<a href="#cache">Auto-Balanced Cache by Popularity</a>
</td>
<td>x</td>
<td>x</td>
<td>-</td>
<td>-</td>
</tr>

@@ -143,7 +152,7 @@ <tr></tr>

<td>
Asynchronous Processing & Concurrency Control
Suggestions (Results)
</td>
<td>x</td>
<td>x</td>
<td>-</td>
<td>-</td>
</tr>

@@ -153,3 +162,3 @@ <tr></tr>

<td>
<a href="#phonetic">Phonetic Mathching</a>
<a href="#phonetic">Phonetic Matching</a>
</td>

@@ -173,3 +182,3 @@ <td>x</td>

<td>4.5 kb</td>
<td>1.9 kb</td>
<td>2.1 kb</td>
</tr>

@@ -201,5 +210,5 @@ </table>

<td>FlexSearch</td>
<td>0.3.0</td>
<td>2.9 kb</td>
<td><b>316336</b></td>
<td>0.3.1</td>
<td>2.1 kb</td>
<td><b>327771</b></td>
</tr>

@@ -212,3 +221,3 @@ <tr></tr>

<td>1.6 kb</td>
<td><b>1524</b></td>
<td><b>1587</b></td>
</tr>

@@ -221,3 +230,3 @@ <tr></tr>

<td>3.8 kb</td>
<td><b>739</b></td>
<td><b>771</b></td>
</tr>

@@ -230,3 +239,3 @@ <tr></tr>

<td>3.9 kb</td>
<td><b>544</b></td>
<td><b>584</b></td>
</tr>

@@ -239,3 +248,3 @@ <tr></tr>

<td>8.8 kb</td>
<td><b>310</b></td>
<td><b>322</b></td>
</tr>

@@ -248,3 +257,3 @@ <tr></tr>

<td>5.6 kb</td>
<td><b>286</b></td>
<td><b>319</b></td>
</tr>

@@ -265,3 +274,3 @@ <tr></tr>

<td>3.5 kb</td>
<td><b>72</b></td>
<td><b>107</b></td>
</tr>

@@ -292,3 +301,3 @@ <tr></tr>

<td>FlexSearch</td>
<td>0.3.0</td>
<td>0.3.1</td>
<td>1.33 Mb</td>

@@ -615,2 +624,23 @@ <td>20.31 kb</td>

Perform queries asynchronously (Promise-based):
> Make sure the option "async" is enabled on this instance
```js
index.search("John").then(function(result){
// array of results
});
```
Alternatively ES6:
```js
async function search(query){
return await index.search(query);
}
const result = search("John");
```
Pass custom options for each query:

@@ -927,2 +957,3 @@

<a name="cache"></a>
#### Enable Auto-Balanced Cache

@@ -1527,3 +1558,3 @@

<tr>
<td>SUPPORT_DEBUG</td>
<td>DEBUG</td>
<td>true, false</td>

@@ -1533,2 +1564,12 @@ </tr>

<tr>
<td>PROFILER</td>
<td>true, false</td>
</tr>
<tr></tr>
<tr>
<td>SUPPORT_ENCODER (built-in encoders)</td>
<td>true, false</td>
</tr>
<tr></tr>
<tr>
<td>SUPPORT_WORKER</td>

@@ -1549,3 +1590,3 @@ <td>true, false</td>

<tr>
<td>SUPPORT_BUILTINS (built-in encoders)</td>
<td>SUPPORT_PRESETS</td>
<td>true, false</td>

@@ -1552,0 +1593,0 @@ </tr>

@@ -516,15 +516,39 @@ if(typeof module !== "undefined"){

expect(flexsearch_async.length).to.equal(3);
expect(flexsearch_async.search("foo")).to.not.have.members([2, 1]);
expect(flexsearch_async.search("bar")).to.not.include(0);
expect(flexsearch_async.search("bar")).to.include(2);
expect(flexsearch_async.search("foobar")).to.not.include(2);
flexsearch_async.search("foo").then(function(result){
expect(result).to.not.have.members([2, 1]);
});
flexsearch_async.search("bar").then(function(result){
expect(result).to.not.include(0);
});
flexsearch_async.search("bar").then(function(result){
expect(result).to.include(2);
});
flexsearch_async.search("foobar").then(function(result){
expect(result).to.not.include(2);
});
setTimeout(function(){
expect(flexsearch_async.length).to.equal(3);
expect(flexsearch_async.search("foo")).to.have.members([2, 1]);
expect(flexsearch_async.search("bar")).to.include(0);
expect(flexsearch_async.search("bar")).to.not.include(2);
expect(flexsearch_async.search("foobar")).to.include(2);
flexsearch_async.search("foo", function(result){
expect(result).to.have.members([2, 1]);
});
flexsearch_async.search("bar", function(result){
expect(result).to.include(0);
});
flexsearch_async.search("bar", function(result){
expect(result).to.not.include(2);
});
flexsearch_async.search("foobar", function(result){
expect(result).to.include(2);
});
done();

@@ -550,7 +574,19 @@

expect(flexsearch_async.length).to.equal(3);
expect(flexsearch_async.search("foo")).to.have.members([2, 1]);
expect(flexsearch_async.search("bar")).to.include(0);
expect(flexsearch_async.search("bar")).to.not.include(2);
expect(flexsearch_async.search("foobar")).to.include(2);
flexsearch_async.search("foo").then(function(result){
expect(result).to.have.members([2, 1]);
});
flexsearch_async.search("bar").then(function(result){
expect(result).to.include(0);
});
flexsearch_async.search("bar").then(function(result){
expect(result).to.not.include(2);
});
flexsearch_async.search("foobar").then(function(result){
expect(result).to.include(2);
});
done();

@@ -575,6 +611,15 @@

expect(flexsearch_async.length).to.equal(0);
expect(flexsearch_async.search("foo")).to.have.lengthOf(0);
expect(flexsearch_async.search("bar")).to.have.lengthOf(0);
expect(flexsearch_async.search("foobar")).to.have.lengthOf(0);
flexsearch_async.search("foo", function(result){
expect(result).to.have.lengthOf(0);
});
flexsearch_async.search("bar", function(result){
expect(result).to.have.lengthOf(0);
});
flexsearch_async.search("foobar", function(result){
expect(result).to.have.lengthOf(0);
});
done();

@@ -773,2 +818,4 @@

expect(flexsearch_worker.length).to.equal(3);
flexsearch_worker.remove(0);

@@ -1046,24 +1093,27 @@ flexsearch_worker.remove(2);

describe("Suggestion", function(){
if(env !== "light"){
it("Should have been suggested properly by relevance", function(){
describe("Suggestion", function(){
var index = new FlexSearch({
encode: "advanced",
mode: "strict",
suggest: true
});
it("Should have been suggested properly by relevance", function(){
index.add(0, "1 2 3 2 4 1 5 3");
index.add(1, "zero one two three four five six seven eight nine ten");
index.add(2, "four two zero one three ten five seven eight six nine");
var index = new FlexSearch({
encode: "advanced",
mode: "strict",
suggest: true
});
expect(index.search("1 3 4 7")).to.have.members([0]);
expect(index.search("1 3 9 7")).to.have.members([0]);
expect(index.search("one foobar two")).to.have.members([1, 2]);
expect(index.search("zero one foobar two foobar")).to.have.members([1, 2]);
//TODO
//expect(index.search("zero one foobar two foobar")[0]).to.equal(1);
index.add(0, "1 2 3 2 4 1 5 3");
index.add(1, "zero one two three four five six seven eight nine ten");
index.add(2, "four two zero one three ten five seven eight six nine");
expect(index.search("1 3 4 7")).to.have.members([0]);
expect(index.search("1 3 9 7")).to.have.members([0]);
expect(index.search("one foobar two")).to.have.members([1, 2]);
expect(index.search("zero one foobar two foobar")).to.have.members([1, 2]);
//TODO
//expect(index.search("zero one foobar two foobar")[0]).to.equal(1);
});
});
});
}

@@ -1070,0 +1120,0 @@ // ------------------------------------------------------------------------

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc