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

fuse.js

Package Overview
Dependencies
Maintainers
1
Versions
113
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fuse.js - npm Package Compare versions

Comparing version 4.0.4-beta to 5.0.0-beta

9

CHANGELOG.md

@@ -0,1 +1,10 @@

# Version 5.0.0-beta
- Added ability to search patterns longer > 32 characters
- Removed `maxPatternLength` option
# Version 4.1.0-beta
- Perf optimization on nested array search
# Version 4.0.4-beta

@@ -2,0 +11,0 @@

4

dist/fuse.d.ts

@@ -1,2 +0,2 @@

// Type definitions for Fuse.js v4.0.4-beta
// Type definitions for Fuse.js v5.0.0-beta
// TypeScript Version: 3.1

@@ -54,3 +54,2 @@

verbose?: boolean
tokenSeparator?: RegExp
matchAllTokens?: boolean

@@ -60,3 +59,2 @@ location?: number

threshold?: number
maxPatternLength?: number
minMatchCharLength?: number

@@ -63,0 +61,0 @@ findAllMatches?: boolean

/*!
* Fuse.js v4.0.4-beta - Lightweight fuzzy-search (http://fusejs.io)
* Fuse.js v5.0.0-beta - Lightweight fuzzy-search (http://fusejs.io)
*

@@ -9,2 +9,2 @@ * Copyright (c) 2012-2020 Kirollos Risk (http://kiro.me)

*/
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("Fuse",[],e):"object"==typeof exports?exports.Fuse=e():t.Fuse=e()}(this,(function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=1)}([function(t,e,r){function n(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var i=r(2),o=r(3),a=r(6),s=function(){function t(e,r){var n=r.location,i=void 0===n?0:n,o=r.distance,s=void 0===o?100:o,c=r.threshold,u=void 0===c?.6:c,h=r.maxPatternLength,l=void 0===h?32:h,f=r.isCaseSensitive,v=void 0!==f&&f,d=r.tokenSeparator,p=void 0===d?/ +/g:d,y=r.findAllMatches,g=void 0!==y&&y,m=r.minMatchCharLength,b=void 0===m?1:m,x=r.includeMatches,M=void 0!==x&&x;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.options={location:i,distance:s,threshold:u,maxPatternLength:l,isCaseSensitive:v,tokenSeparator:p,findAllMatches:g,includeMatches:M,minMatchCharLength:b},this.pattern=v?e:e.toLowerCase(),this.pattern.length<=l&&(this.patternAlphabet=a(this.pattern))}var e,r,s;return e=t,(r=[{key:"search",value:function(t){var e=this.options,r=e.isCaseSensitive,n=e.includeMatches;if(r||(t=t.toLowerCase()),this.pattern===t){var a={isMatch:!0,score:0};return n&&(a.matchedIndices=[[0,t.length-1]]),a}var s=this.options,c=s.maxPatternLength,u=s.tokenSeparator;if(this.pattern.length>c)return i(t,this.pattern,u);var h=this.options,l=h.location,f=h.distance,v=h.threshold,d=h.findAllMatches,p=h.minMatchCharLength;return o(t,this.pattern,this.patternAlphabet,{location:l,distance:f,threshold:v,findAllMatches:d,minMatchCharLength:p,includeMatches:n})}}])&&n(e.prototype,r),s&&n(e,s),t}();t.exports=s},function(t,e,r){function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function i(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var o=r(0),a=r(7),s=r(14),c=s.get,u=s.isArray,h=function(){function t(e,r){var n=r.location,i=void 0===n?0:n,o=r.distance,a=void 0===o?100:o,s=r.threshold,u=void 0===s?.6:s,h=r.maxPatternLength,l=void 0===h?32:h,f=r.caseSensitive,v=void 0!==f&&f,d=r.tokenSeparator,p=void 0===d?/ +/g:d,y=r.findAllMatches,g=void 0!==y&&y,m=r.minMatchCharLength,b=void 0===m?1:m,x=r.id,M=void 0===x?null:x,k=r.keys,S=void 0===k?[]:k,_=r.shouldSort,w=void 0===_||_,A=r.getFn,L=void 0===A?c:A,P=r.sortFn,C=void 0===P?function(t,e){return t.score-e.score}:P,O=r.matchAllTokens,F=void 0!==O&&O,j=r.includeMatches,z=void 0!==j&&j,I=r.includeScore,E=void 0!==I&&I,N=r.useExtendedSearch,T=void 0!==N&&N,W=r.verbose,$=void 0!==W&&W;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.options={location:i,distance:a,threshold:u,maxPatternLength:l,isCaseSensitive:v,tokenSeparator:p,findAllMatches:g,minMatchCharLength:b,id:M,keys:S,includeMatches:z,includeScore:E,shouldSort:w,getFn:L,sortFn:C,verbose:$,matchAllTokens:F,useExtendedSearch:T},this.setCollection(e),this._processKeys(S)}var e,r,s;return e=t,(r=[{key:"setCollection",value:function(t){return this.list=t,t}},{key:"_processKeys",value:function(t){if(this._keyWeights={},this._keyNames=[],t.length&&"string"==typeof t[0])for(var e=0,r=t.length;e<r;e+=1){var n=t[e];this._keyWeights[n]=1,this._keyNames.push(n)}else{for(var i=0,o=0,a=t.length;o<a;o+=1){var s=t[o];if(!s.hasOwnProperty("name"))throw new Error('Missing "name" property in key object');var c=s.name;if(this._keyNames.push(c),!s.hasOwnProperty("weight"))throw new Error('Missing "weight" property in key object');var u=s.weight;if(this._keyWeights[c]=u,u<0||u>1)throw new Error('"weight" property in key must bein the range of [0, 1)');i+=u}if(i>1)throw new Error("Total of weights cannot exceed 1")}}},{key:"search",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{limit:!1};this._log('---------\nSearch pattern: "'.concat(t,'"'));var r=this.options,n=null;n=this.options.useExtendedSearch?new a(t,r):new o(t,r);var i=this._search({searcher:n});return this._computeScore(i),this.options.shouldSort&&this._sort(i),e.limit&&"number"==typeof e.limit&&(i=i.slice(0,e.limit)),this._format(i)}},{key:"_search",value:function(t){var e=t.searcher,r=this.list,n={},i=[];if("string"==typeof r[0]){for(var o=0,a=r.length;o<a;o+=1)this._analyze({key:"",value:r[o],record:o,index:o},{resultMap:n,results:i,searcher:e});return i}for(var s=this.options.getFn,c=this._keyNames,u=c.length,h=0,l=r.length;h<l;h+=1)for(var f=r[h],v=0;v<u;v+=1){var d=c[v];this._analyze({key:d,value:s(f,d),record:f,index:h},{resultMap:n,results:i,searcher:e})}return i}},{key:"_analyze",value:function(t,e){var r=this,n=t.key,i=t.arrayIndex,o=void 0===i?-1:i,a=t.value,s=t.record,c=t.index,h=e.searcher,l=e.resultMap,f=void 0===l?{}:l,v=e.results,d=void 0===v?[]:v,p=this.options.includeMatches;!function t(e,i,o,a){if(null!=i)if("string"==typeof i){r._log("\nKey: ".concat(""===n?"--":n));var s=h.search(i),c=s.isMatch,l=s.score;if(r._log('Full text: "'.concat(i,'", score: ').concat(l)),!c)return;var v={key:n,arrayIndex:e,value:i,score:l};p&&(v.matchedIndices=s.matchedIndices);var y=f[a];y?y.output.push(v):(f[a]={item:o,output:[v]},d.push(f[a]))}else if(u(i))for(var g=0,m=i.length;g<m;g+=1)t(g,i[g],o,a)}(o,a,s,c)}},{key:"_computeScore",value:function(t){this._log("\n\nComputing score:\n");for(var e=this._keyWeights,r=!!Object.keys(e).length,n=0,i=t.length;n<i;n+=1){for(var o=t[n],a=o.output,s=a.length,c=1,u=-1,h=0;h<s;h+=1){var l=a[h],f=l.key,v=r?e[f]:1,d=0===l.score&&e&&e[f]>0?Number.EPSILON:l.score;u=-1==u?l.score:Math.min(u,l.score),c*=Math.pow(d,v)}o.score=c,o.$score=u,this._log(o)}}},{key:"_sort",value:function(t){this._log("\n\nSorting...."),t.sort(this.options.sortFn)}},{key:"_format",value:function(t){var e=[];if(this.options.verbose){var r=[];this._log("\n\nOutput:\n\n",JSON.stringify(t,(function(t,e){if("object"===n(e)&&null!==e){if(-1!==r.indexOf(e))return;r.push(e)}return e}),2)),r=null}var i=[];this.options.includeMatches&&i.push((function(t,e){var r=t.output;e.matches=[];for(var n=0,i=r.length;n<i;n+=1){var o=r[n];if(0!==o.matchedIndices.length){var a={indices:o.matchedIndices,value:o.value};o.key&&(a.key=o.key),o.hasOwnProperty("arrayIndex")&&o.arrayIndex>-1&&(a.arrayIndex=o.arrayIndex),e.matches.push(a)}}})),this.options.includeScore&&i.push((function(t,e){e.score=t.score}));for(var o=0,a=t.length;o<a;o+=1){var s=t[o];if(this.options.id&&(s.item=this.options.getFn(s.item,this.options.id)[0]),i.length){for(var c={item:s.item},u=0,h=i.length;u<h;u+=1)i[u](s,c);e.push(c)}else e.push(s.item)}return e}},{key:"_log",value:function(){var t;this.options.verbose&&(t=console).log.apply(t,arguments)}}])&&i(e.prototype,r),s&&i(e,s),t}();t.exports=h},function(t,e){var r=/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g;t.exports=function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:/ +/g,i=new RegExp(e.replace(r,"\\$&").replace(n,"|")),o=t.match(i),a=!!o,s=[];if(a)for(var c=0,u=o.length;c<u;c+=1){var h=o[c];s.push([t.indexOf(h),h.length-1])}return{score:a?.5:1,isMatch:a,matchedIndices:s}}},function(t,e,r){var n=r(4),i=r(5);t.exports=function(t,e,r,o){for(var a=o.location,s=void 0===a?0:a,c=o.distance,u=void 0===c?100:c,h=o.threshold,l=void 0===h?.6:h,f=o.findAllMatches,v=void 0!==f&&f,d=o.minMatchCharLength,p=void 0===d?1:d,y=o.includeMatches,g=void 0!==y&&y,m=s,b=t.length,x=l,M=t.indexOf(e,m),k=e.length,S=[],_=0;_<b;_+=1)S[_]=0;if(-1!==M){var w=n(e,{errors:0,currentLocation:M,expectedLocation:m,distance:u});if(x=Math.min(w,x),-1!==(M=t.lastIndexOf(e,m+k))){var A=n(e,{errors:0,currentLocation:M,expectedLocation:m,distance:u});x=Math.min(A,x)}}M=-1;for(var L=[],P=1,C=k+b,O=1<<(k<=31?k-1:30),F=0;F<k;F+=1){for(var j=0,z=C;j<z;){n(e,{errors:F,currentLocation:m+z,expectedLocation:m,distance:u})<=x?j=z:C=z,z=Math.floor((C-j)/2+j)}C=z;var I=Math.max(1,m-z+1),E=v?b:Math.min(m+z,b)+k,N=Array(E+2);N[E+1]=(1<<F)-1;for(var T=E;T>=I;T-=1){var W=T-1,$=r[t.charAt(W)];if($&&(S[W]=1),N[T]=(N[T+1]<<1|1)&$,0!==F&&(N[T]|=(L[T+1]|L[T])<<1|1|L[T+1]),N[T]&O&&(P=n(e,{errors:F,currentLocation:W,expectedLocation:m,distance:u}))<=x){if(x=P,(M=W)<=m)break;I=Math.max(1,2*m-M)}}if(n(e,{errors:F+1,currentLocation:m,expectedLocation:m,distance:u})>x)break;L=N}var K={isMatch:M>=0,score:P||.001};return g&&(K.matchedIndices=i(S,p)),K}},function(t,e){t.exports=function(t,e){var r=e.errors,n=void 0===r?0:r,i=e.currentLocation,o=void 0===i?0:i,a=e.expectedLocation,s=void 0===a?0:a,c=e.distance,u=void 0===c?100:c,h=n/t.length,l=Math.abs(s-o);return u?h+l/u:l?1:h}},function(t,e){t.exports=function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,r=[],n=-1,i=-1,o=0,a=t.length;o<a;o+=1){var s=t[o];s&&-1===n?n=o:s||-1===n||((i=o-1)-n+1>=e&&r.push([n,i]),n=-1)}return t[o-1]&&o-n>=e&&r.push([n,o-1]),r}},function(t,e){t.exports=function(t){for(var e={},r=t.length,n=0;n<r;n+=1)e[t.charAt(n)]=0;for(var i=0;i<r;i+=1)e[t.charAt(i)]|=1<<r-i-1;return e}},function(t,e,r){function n(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var i=r(8),o=r(9),a=r(10),s=r(11),c=r(12),u=r(13),h=r(0),l=function(){function t(e,r){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t);var n=r.isCaseSensitive;this.options=r,this.pattern=n?e:e.toLowerCase(),this.query=function(t){return t.split("|").map((function(t){return t.trim().split(/ +/g)}))}(this.pattern),this._fuzzyCache={}}var e,r,l;return e=t,(r=[{key:"search",value:function(t){var e=this.query;t=this.options.isCaseSensitive?t:t.toLowerCase();for(var r=!1,n=0,i=e.length;n<i;n+=1){var o=e[n],a=null;r=!0;for(var s=0,c=o.length;s<c;s+=1){var u=o[s];if(!(a=this._search(u,t)).isMatch){r=!1;break}}if(r)return a}return{isMatch:!1,score:1}}},{key:"_search",value:function(t,e){if(i.isForPattern(t))return i.match(t,e);if(a.isForPattern(t))return a.match(t,e);if(s.isForPattern(t))return s.match(t,e);if(u.isForPattern(t))return u.match(t,e);if(c.isForPattern(t))return c.match(t,e);if(o.isForPattern(t))return o.match(t,e);var r=this._fuzzyCache[t];return r||(r=new h(t,this.options),this._fuzzyCache[t]=r),r.search(e)}}])&&n(e.prototype,r),l&&n(e,l),t}();t.exports=l},function(t,e){var r=function(t){return t.substr(1)};t.exports={isForPattern:function(t){return"'"==t.charAt(0)},sanitize:r,match:function(t,e){var n=r(t);return{isMatch:e.indexOf(n)>-1,score:0}}}},function(t,e){var r=function(t){return t.substr(1)};t.exports={isForPattern:function(t){return"!"==t.charAt(0)},sanitize:r,match:function(t,e){var n=r(t);return{isMatch:-1===e.indexOf(n),score:0}}}},function(t,e){var r=function(t){return t.substr(1)};t.exports={isForPattern:function(t){return"^"==t.charAt(0)},sanitize:r,match:function(t,e){var n=r(t);return{isMatch:e.startsWith(n),score:0}}}},function(t,e){var r=function(t){return t.substr(2)};t.exports={isForPattern:function(t){return"!"==t.charAt(0)&&"^"==t.charAt(1)},sanitize:r,match:function(t,e){var n=r(t);return{isMatch:!e.startsWith(n),score:0}}}},function(t,e){var r=function(t){return t.substr(0,t.length-1)};t.exports={isForPattern:function(t){return"$"==t.charAt(t.length-1)},sanitize:r,match:function(t,e){var n=r(t);return{isMatch:e.endsWith(n),score:0}}}},function(t,e){var r=function(t){return t.substring(1,t.length-1)};t.exports={isForPattern:function(t){return"!"==t.charAt(0)&&"$"==t.charAt(t.length-1)},sanitize:r,match:function(t,e){var n=r(t);return{isMatch:!e.endsWith(n),score:0}}}},function(t,e){var r=function(t){return Array.isArray?Array.isArray(t):"[object Array]"===Object.prototype.toString.call(t)},n=function(t){return null==t?"":function(t){if("string"==typeof t)return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}(t)},i=function(t){return"string"==typeof t},o=function(t){return"number"==typeof t};t.exports={get:function(t,e){var a=[];return function t(e,s){if(s){var c=s.indexOf("."),u=s,h=null;-1!==c&&(u=s.slice(0,c),h=s.slice(c+1));var l=e[u];if(null!=l)if(h||!i(l)&&!o(l))if(r(l))for(var f=0,v=l.length;f<v;f+=1)t(l[f],h);else h&&t(l,h);else a.push(n(l))}else a.push(e)}(t,e),a},isArray:r,isString:i,isNum:o,toString:n}}])}));
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("Fuse",[],e):"object"==typeof exports?exports.Fuse=e():t.Fuse=e()}(this,(function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=2)}([function(t,e,n){function r(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}var o=n(3),i=n(6),a=n(1).MAX_BITS,s=function(){function t(e,n){var r=n.location,o=void 0===r?0:r,s=n.distance,c=void 0===s?100:s,u=n.threshold,h=void 0===u?.6:u,l=n.isCaseSensitive,f=void 0!==l&&l,v=n.findAllMatches,d=void 0!==v&&v,p=n.minMatchCharLength,y=void 0===p?1:p,g=n.includeMatches,m=void 0!==g&&g;if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.options={location:o,distance:c,threshold:h,isCaseSensitive:f,findAllMatches:d,includeMatches:m,minMatchCharLength:y},e.length>a)throw new Error("Pattern length exceeds max of ".concat(a,"."));this.pattern=f?e:e.toLowerCase(),this.patternAlphabet=i(this.pattern)}var e,n,s;return e=t,(n=[{key:"searchIn",value:function(t){var e=this.options,n=e.isCaseSensitive,r=e.includeMatches;if(n||(t=t.toLowerCase()),this.pattern===t){var i={isMatch:!0,score:0};return r&&(i.matchedIndices=[[0,t.length-1]]),i}var a=this.options,s=a.location,c=a.distance,u=a.threshold,h=a.findAllMatches,l=a.minMatchCharLength;return o(t,this.pattern,this.patternAlphabet,{location:s,distance:c,threshold:u,findAllMatches:h,minMatchCharLength:l,includeMatches:r})}}])&&r(e.prototype,n),s&&r(e,s),t}();t.exports=s},function(t,e){t.exports.MAX_BITS=32},function(t,e,n){function r(t){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function o(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}var i=n(0),a=n(7),s=n(14),c=n(21),u=c.get,h=c.isArray,l=n(22),f=l.withMatches,v=l.withScore,d=n(1).MAX_BITS,p=function(){function t(e,n){var r=n.location,o=void 0===r?0:r,i=n.distance,a=void 0===i?100:i,s=n.threshold,c=void 0===s?.6:s,h=n.caseSensitive,l=void 0!==h&&h,f=n.findAllMatches,v=void 0!==f&&f,d=n.minMatchCharLength,p=void 0===d?1:d,y=n.id,g=void 0===y?null:y,m=n.keys,b=void 0===m?[]:m,x=n.shouldSort,M=void 0===x||x,w=n.getFn,k=void 0===w?u:w,_=n.sortFn,S=void 0===_?function(t,e){return t.score-e.score}:_,A=n.matchAllTokens,C=void 0!==A&&A,P=n.includeMatches,I=void 0!==P&&P,L=n.includeScore,O=void 0!==L&&L,F=n.useExtendedSearch,j=void 0!==F&&F,z=n.verbose,E=void 0!==z&&z;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.options={location:o,distance:a,threshold:c,isCaseSensitive:l,findAllMatches:v,minMatchCharLength:p,id:g,keys:b,includeMatches:I,includeScore:O,shouldSort:M,getFn:k,sortFn:S,verbose:E,matchAllTokens:C,useExtendedSearch:j},this.setCollection(e),this._processKeys(b)}var e,n,c;return e=t,(n=[{key:"setCollection",value:function(t){return this.list=t,this.listIsStringArray="string"==typeof t[0],t}},{key:"_processKeys",value:function(t){if(this._keyWeights={},this._keyNames=[],t.length&&"string"==typeof t[0])for(var e=0,n=t.length;e<n;e+=1){var r=t[e];this._keyWeights[r]=1,this._keyNames.push(r)}else{for(var o=0,i=0,a=t.length;i<a;i+=1){var s=t[i];if(!s.hasOwnProperty("name"))throw new Error('Missing "name" property in key object');var c=s.name;if(this._keyNames.push(c),!s.hasOwnProperty("weight"))throw new Error('Missing "weight" property in key object');var u=s.weight;if(this._keyWeights[c]=u,u<0||u>1)throw new Error('"weight" property in key must bein the range of [0, 1)');o+=u}if(o>1)throw new Error("Total of weights cannot exceed 1")}}},{key:"search",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{limit:!1};this._log('---------\nSearch pattern: "'.concat(t,'"'));var n=this.options,r=n.useExtendedSearch,o=n.shouldSort,c=null;c=r?new a(t,this.options):t.length>d?new s(t,this.options):new i(t,this.options);var u=this._searchUsing(c);return this._computeScore(u),o&&this._sort(u),e.limit&&"number"==typeof e.limit&&(u=u.slice(0,e.limit)),this._format(u)}},{key:"_searchUsing",value:function(t){var e=this.list,n={},r=[];if(this.listIsStringArray)for(var o=0,i=e.length;o<i;o+=1)this._analyze(t,{key:"",value:e[o],record:o,index:o},{resultMap:n,results:r});else for(var a=this.options.getFn,s=this._keyNames,c=s.length,u=0,h=e.length;u<h;u+=1)for(var l=e[u],f=0;f<c;f+=1){var v=s[f];this._analyze(t,{key:v,value:a(l,v),record:l,index:u},{resultMap:n,results:r})}return r}},{key:"_analyze",value:function(t,e,n){for(var r=e.key,o=e.value,i=e.record,a=e.index,s=n.resultMap,c=void 0===s?{}:s,u=n.results,l=void 0===u?[]:u,f=this.options.includeMatches,v=[{arrayIndex:-1,value:o,record:i,index:a}];v.length;){var d=v.pop(),p=d.arrayIndex,y=d.value,g=d.record,m=d.index;if(null!=y)if("string"==typeof y){this._log("\nKey: ".concat(""===r?"--":r));var b=t.searchIn(y),x=b.isMatch,M=b.score;if(this._log('Full text: "'.concat(y,'", score: ').concat(M)),!x)continue;var w={key:r,arrayIndex:p,value:y,score:M};f&&(w.matchedIndices=b.matchedIndices);var k=c[m];k?k.output.push(w):(c[m]={item:g,output:[w]},l.push(c[m]))}else if(h(y))for(var _=0,S=y.length;_<S;_+=1)v.push({arrayIndex:_,value:y[_],record:g,index:m})}}},{key:"_computeScore",value:function(t){this._log("\n\nComputing score:\n");for(var e=this._keyWeights,n=!!Object.keys(e).length,r=0,o=t.length;r<o;r+=1){for(var i=t[r],a=i.output,s=a.length,c=1,u=-1,h=0;h<s;h+=1){var l=a[h],f=l.key,v=n?e[f]:1,d=0===l.score&&e&&e[f]>0?Number.EPSILON:l.score;u=-1==u?l.score:Math.min(u,l.score),c*=Math.pow(d,v)}i.score=c,i.$score=u,this._log(i)}}},{key:"_sort",value:function(t){this._log("\n\nSorting...."),t.sort(this.options.sortFn)}},{key:"_format",value:function(t){var e=[],n=this.options,o=n.includeMatches,i=n.includeScore,a=n.id,s=n.getFn;if(n.verbose){var c=[];this._log("\n\nOutput:\n\n",JSON.stringify(t,(function(t,e){if("object"===r(e)&&null!==e){if(-1!==c.indexOf(e))return;c.push(e)}return e}),2)),c=null}var u=[];o&&u.push(f),i&&u.push(v);for(var h=0,l=t.length;h<l;h+=1){var d=t[h];if(a&&(d.item=s(d.item,a)[0]),u.length){for(var p={item:d.item},y=0,g=u.length;y<g;y+=1)u[y](d,p);e.push(p)}else e.push(d.item)}return e}},{key:"_log",value:function(){var t;this.options.verbose&&(t=console).log.apply(t,arguments)}}])&&o(e.prototype,n),c&&o(e,c),t}();t.exports=p},function(t,e,n){var r=n(4),o=n(5);t.exports=function(t,e,n,i){for(var a=i.location,s=void 0===a?0:a,c=i.distance,u=void 0===c?100:c,h=i.threshold,l=void 0===h?.6:h,f=i.findAllMatches,v=void 0!==f&&f,d=i.minMatchCharLength,p=void 0===d?1:d,y=i.includeMatches,g=void 0!==y&&y,m=e.length,b=t.length,x=Math.max(0,Math.min(s,b)),M=l,w=t.indexOf(e,x),k=[],_=0;_<b;_+=1)k[_]=0;if(-1!==w){var S=r(e,{errors:0,currentLocation:w,expectedLocation:x,distance:u});if(M=Math.min(S,M),-1!==(w=t.lastIndexOf(e,x+m))){var A=r(e,{errors:0,currentLocation:w,expectedLocation:x,distance:u});M=Math.min(A,M)}}w=-1;for(var C=[],P=1,I=m+b,L=1<<(m<=31?m-1:30),O=0;O<m;O+=1){for(var F=0,j=I;F<j;){r(e,{errors:O,currentLocation:x+j,expectedLocation:x,distance:u})<=M?F=j:I=j,j=Math.floor((I-F)/2+F)}I=j;var z=Math.max(1,x-j+1),E=v?b:Math.min(x+j,b)+m,T=Array(E+2);T[E+1]=(1<<O)-1;for(var N=E;N>=z;N-=1){var W=N-1,B=n[t.charAt(W)];if(B&&(k[W]=1),T[N]=(T[N+1]<<1|1)&B,0!==O&&(T[N]|=(C[N+1]|C[N])<<1|1|C[N+1]),T[N]&L&&(P=r(e,{errors:O,currentLocation:W,expectedLocation:x,distance:u}))<=M){if(M=P,(w=W)<=x)break;z=Math.max(1,2*x-w)}}if(r(e,{errors:O+1,currentLocation:x,expectedLocation:x,distance:u})>M)break;C=T}var K={isMatch:w>=0,score:P||.001};return g&&(K.matchedIndices=o(k,p)),K}},function(t,e){t.exports=function(t,e){var n=e.errors,r=void 0===n?0:n,o=e.currentLocation,i=void 0===o?0:o,a=e.expectedLocation,s=void 0===a?0:a,c=e.distance,u=void 0===c?100:c,h=r/t.length,l=Math.abs(s-i);return u?h+l/u:l?1:h}},function(t,e){t.exports=function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=[],r=-1,o=-1,i=0,a=t.length;i<a;i+=1){var s=t[i];s&&-1===r?r=i:s||-1===r||((o=i-1)-r+1>=e&&n.push([r,o]),r=-1)}return t[i-1]&&i-r>=e&&n.push([r,i-1]),n}},function(t,e){t.exports=function(t){for(var e={},n=t.length,r=0;r<n;r+=1)e[t.charAt(r)]=0;for(var o=0;o<n;o+=1)e[t.charAt(o)]|=1<<n-o-1;return e}},function(t,e,n){function r(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}var o=n(8),i=n(9),a=n(10),s=n(11),c=n(12),u=n(13),h=n(0),l=function(){function t(e,n){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t);var r=n.isCaseSensitive;this.options=n,this.pattern=r?e:e.toLowerCase(),this.query=function(t){return t.split("|").map((function(t){return t.trim().split(/ +/g)}))}(this.pattern),this._fuzzyCache={}}var e,n,l;return e=t,(n=[{key:"searchIn",value:function(t){var e=this.query;t=this.options.isCaseSensitive?t:t.toLowerCase();for(var n=!1,r=0,o=e.length;r<o;r+=1){var i=e[r],a=null;n=!0;for(var s=0,c=i.length;s<c;s+=1){var u=i[s];if(!(a=this._search(u,t)).isMatch){n=!1;break}}if(n)return a}return{isMatch:!1,score:1}}},{key:"_search",value:function(t,e){if(o.isForPattern(t))return o.match(t,e);if(a.isForPattern(t))return a.match(t,e);if(s.isForPattern(t))return s.match(t,e);if(u.isForPattern(t))return u.match(t,e);if(c.isForPattern(t))return c.match(t,e);if(i.isForPattern(t))return i.match(t,e);var n=this._fuzzyCache[t];return n||(n=new h(t,this.options),this._fuzzyCache[t]=n),n.search(e)}}])&&r(e.prototype,n),l&&r(e,l),t}();t.exports=l},function(t,e){var n=function(t){return t.substr(1)};t.exports={isForPattern:function(t){return"'"==t.charAt(0)},sanitize:n,match:function(t,e){var r=n(t);return{isMatch:e.indexOf(r)>-1,score:0}}}},function(t,e){var n=function(t){return t.substr(1)};t.exports={isForPattern:function(t){return"!"==t.charAt(0)},sanitize:n,match:function(t,e){var r=n(t);return{isMatch:-1===e.indexOf(r),score:0}}}},function(t,e){var n=function(t){return t.substr(1)};t.exports={isForPattern:function(t){return"^"==t.charAt(0)},sanitize:n,match:function(t,e){var r=n(t);return{isMatch:e.startsWith(r),score:0}}}},function(t,e){var n=function(t){return t.substr(2)};t.exports={isForPattern:function(t){return"!"==t.charAt(0)&&"^"==t.charAt(1)},sanitize:n,match:function(t,e){var r=n(t);return{isMatch:!e.startsWith(r),score:0}}}},function(t,e){var n=function(t){return t.substr(0,t.length-1)};t.exports={isForPattern:function(t){return"$"==t.charAt(t.length-1)},sanitize:n,match:function(t,e){var r=n(t);return{isMatch:e.endsWith(r),score:0}}}},function(t,e){var n=function(t){return t.substring(1,t.length-1)};t.exports={isForPattern:function(t){return"!"==t.charAt(0)&&"$"==t.charAt(t.length-1)},sanitize:n,match:function(t,e){var r=n(t);return{isMatch:!e.endsWith(r),score:0}}}},function(t,e,n){function r(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}var o=n(15),i=n(16).jaccardDistance,a=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:3,n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return o(t,e,n).sort((function(t,e){return t==e?0:t<e?-1:1}))},s=function(){function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),console.log(e),this.patternNgram=a(e)}var e,n,o;return e=t,(n=[{key:"searchIn",value:function(t){var e=a(t),n=i(this.patternNgram,e);return{score:n,isMatch:n<1}}}])&&r(e.prototype,n),o&&r(e,o),t}();t.exports=s},function(t,e){t.exports=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:3,n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],r=[];if(null==t)return r;t=t.toLowerCase(),n&&(t=" ".concat(t," "));var o=t.length-e+1;if(o<1)return r;for(;o--;)r[o]=t.substr(o,e);return r}},function(t,e,n){t.exports={jaccardDistance:n(17)}},function(t,e,n){var r=n(18),o=r.union,i=r.intersection;t.exports=function(t,e){var n=o(t,e);return 1-i(t,e).length/n.length}},function(t,e,n){t.exports={union:n(19),intersection:n(20)}},function(t,e){t.exports=function(t,e){for(var n=[],r=0,o=0;r<t.length&&o<e.length;){var i=t[r],a=e[o];i<a?(n.push(i),r+=1):a<i?(n.push(a),o+=1):(n.push(a),r+=1,o+=1)}for(;r<t.length;)n.push(t[r]),r+=1;for(;o<e.length;)n.push(e[o]),o+=1;return n}},function(t,e){t.exports=function(t,e){for(var n=[],r=0,o=0;r<t.length&&o<e.length;){var i=t[r],a=e[o];i==a?(n.push(i),r+=1,o+=1):i<a?r+=1:(i>a||(r+=1),o+=1)}return n}},function(t,e){var n=function(t){return Array.isArray?Array.isArray(t):"[object Array]"===Object.prototype.toString.call(t)},r=function(t){return null==t?"":function(t){if("string"==typeof t)return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}(t)},o=function(t){return"string"==typeof t},i=function(t){return"number"==typeof t};t.exports={get:function(t,e){var a=[];return function t(e,s){if(s){var c=s.indexOf("."),u=s,h=null;-1!==c&&(u=s.slice(0,c),h=s.slice(c+1));var l=e[u];if(null!=l)if(h||!o(l)&&!i(l))if(n(l))for(var f=0,v=l.length;f<v;f+=1)t(l[f],h);else h&&t(l,h);else a.push(r(l))}else a.push(e)}(t,e),a},isArray:n,isString:o,isNum:i,toString:r}},function(t,e){t.exports={withMatches:function(t,e){var n=t.output;e.matches=[];for(var r=0,o=n.length;r<o;r+=1){var i=n[r];if(0!==i.matchedIndices.length){var a={indices:i.matchedIndices,value:i.value};i.key&&(a.key=i.key),i.hasOwnProperty("arrayIndex")&&i.arrayIndex>-1&&(a.arrayIndex=i.arrayIndex),e.matches.push(a)}}},withScore:function(t,e){e.score=t.score}}}])}));

@@ -8,3 +8,3 @@ {

},
"version": "4.0.4-beta",
"version": "5.0.0-beta",
"description": "Lightweight fuzzy-search",

@@ -26,3 +26,2 @@ "license": "Apache-2.0",

"clean": "rimraf ./dist",
"pretest": "npm run build",
"test": "jest",

@@ -42,2 +41,3 @@ "prebuild": "npm run clean",

"copy-webpack-plugin": "5.1.1",
"faker": "4.1.0",
"jest": "25.1.0",

@@ -44,0 +44,0 @@ "rimraf": "3.0.2",

<p align="center"><a href="https://fusejs.io" target="_blank" rel="noopener noreferrer"><img width="200" src="https://fusejs.io/assets/images/logo.png" alt="Fuse.js logo"></a></p>
<p align="center">
<a alt="Build Status" href="http://travis-ci.org/krisk/Fuse"><img src="https://secure.travis-ci.org/krisk/Fuse.svg?branch=master" /></a>
<img src="https://github.com/krisk/Fuse/workflows/Node.js%20CI/badge.svg" alt="Node.js CI"/>
<a href="https://www.npmjs.com/package/fuse.js"><img src="https://img.shields.io/npm/v/fuse.js.svg" alt="Version"/></a>

@@ -14,2 +14,9 @@ <a href="https://npmcharts.com/compare/fuse.js?minimal=true"><img src="https://img.shields.io/npm/dm/fuse.js.svg" alt="Downloads" /></a>

#### _What's new in v5.0.0-beta_
- _Added ability to search patterns longer longer than 32 characters_
- _Added [enhanced searching](https://fusejs.io/#extended-search)_
---
## Introduction

@@ -21,3 +28,3 @@

To checkout out [live examples](https://fusejs.io) and docs, visit [fusejs.io](https://fusejs.io).
To checkout out live examples and docs, visit [fusejs.io](https://fusejs.io).

@@ -28,4 +35,2 @@ ## Installation

NPM is the recommended installation method. It pairs nicely with a CommonJS module bundler such as [Webpack](http://webpack.github.io/) or [Browserify](http://browserify.org/).
```sh

@@ -36,6 +41,2 @@ # latest

**CDN**
Available on [cdnjs](https://cdnjs.cloudflare.com/ajax/libs/fuse.js/3.4.5/fuse.min.js) (see the latest version on [the Releases page](https://github.com/krisk/Fuse/releases)).
## Contributing

@@ -49,2 +50,2 @@

Before submitting a pull request, please add relevant tests in `test/index.js`, and execute them via `npm test`.
Before submitting a pull request, please add the relevant tests in the `test/` directory, and execute them via `npm test`.
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