Socket
Socket
Sign inDemoInstall

fuse.js

Package Overview
Dependencies
0
Maintainers
1
Versions
113
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.0.8-beta to 5.0.9-beta

4

CHANGELOG.md

@@ -0,1 +1,5 @@

# Version 5.0.9-beta
- Fixed Fuse global name. Erroenously set as 'Fuse.js'
# Version 5.0.8-beta

@@ -2,0 +6,0 @@

4

dist/fuse.common.js
/**
* Fuse.js v5.0.8-beta - Lightweight fuzzy-search (http://fusejs.io)
* Fuse.js v5.0.9-beta - Lightweight fuzzy-search (http://fusejs.io)
*

@@ -1458,5 +1458,5 @@ * Copyright (c) 2020 Kiro Risk (http://kiro.me)

Fuse.version = '5.0.8-beta';
Fuse.version = '5.0.9-beta';
Fuse.createIndex = createIndex;
module.exports = Fuse;

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

// Type definitions for Fuse.js v5.0.8-beta
// Type definitions for Fuse.js v5.0.9-beta
// TypeScript v3.8.3

@@ -3,0 +3,0 @@

/**
* Fuse.js v5.0.8-beta - Lightweight fuzzy-search (http://fusejs.io)
* Fuse.js v5.0.9-beta - Lightweight fuzzy-search (http://fusejs.io)
*

@@ -1239,5 +1239,5 @@ * Copyright (c) 2020 Kiro Risk (http://kiro.me)

Fuse.version = '5.0.8-beta';
Fuse.version = '5.0.9-beta';
Fuse.createIndex = createIndex;
export default Fuse;
/**
* Fuse.js v5.0.8-beta - Lightweight fuzzy-search (http://fusejs.io)
* Fuse.js v5.0.9-beta - Lightweight fuzzy-search (http://fusejs.io)
*

@@ -13,3 +13,3 @@ * Copyright (c) 2020 Kiro Risk (http://kiro.me)

typeof define === 'function' && define.amd ? define(factory) :
(global = global || self, (global.Fuse = global.Fuse || {}, global.Fuse.js = factory()));
(global = global || self, global.Fuse = factory());
}(this, (function () { 'use strict';

@@ -1463,3 +1463,3 @@

Fuse.version = '5.0.8-beta';
Fuse.version = '5.0.9-beta';
Fuse.createIndex = createIndex;

@@ -1466,0 +1466,0 @@

/**
* Fuse.js v5.0.8-beta - Lightweight fuzzy-search (http://fusejs.io)
* Fuse.js v5.0.9-beta - Lightweight fuzzy-search (http://fusejs.io)
*

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

*/
var t,e;t=this,e=function(){"use strict";function t(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function e(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)}}function r(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}function n(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function i(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function s(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?i(Object(r),!0).forEach((function(e){n(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):i(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function o(t,e){var r=e.errors,n=void 0===r?0:r,i=e.currentLocation,s=void 0===i?0:i,o=e.expectedLocation,a=void 0===o?0:o,h=e.distance,c=void 0===h?100:h,u=n/t.length,f=Math.abs(a-s);return c?u+f/c:f?1:u}var a=function(){function e(r,n){var i=n.location,s=void 0===i?0:i,o=n.distance,a=void 0===o?100:o,h=n.threshold,c=void 0===h?.6:h,u=n.isCaseSensitive,f=void 0!==u&&u,l=n.findAllMatches,v=void 0!==l&&l,d=n.minMatchCharLength,g=void 0===d?1:d,p=n.includeMatches,y=void 0!==p&&p;if(t(this,e),this.options={location:s,distance:a,threshold:c,isCaseSensitive:f,findAllMatches:v,includeMatches:y,minMatchCharLength:g},r.length>32)throw new Error("Pattern length exceeds max of ".concat(32,"."));this.pattern=f?r:r.toLowerCase(),this.patternAlphabet=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}(this.pattern)}return r(e,[{key:"searchIn",value:function(t){var e=t.$;return this.searchInString(e)}},{key:"searchInString",value:function(t){var e=this.options,r=e.isCaseSensitive,n=e.includeMatches;if(r||(t=t.toLowerCase()),this.pattern===t){var i={isMatch:!0,score:0};return n&&(i.matchedIndices=[[0,t.length-1]]),i}var s=this.options,a=s.location,h=s.distance,c=s.threshold,u=s.findAllMatches,f=s.minMatchCharLength;return function(t,e,r,n){for(var i=n.location,s=void 0===i?0:i,a=n.distance,h=void 0===a?100:a,c=n.threshold,u=void 0===c?.6:c,f=n.findAllMatches,l=void 0!==f&&f,v=n.minMatchCharLength,d=void 0===v?1:v,g=n.includeMatches,p=void 0!==g&&g,y=e.length,m=t.length,k=Math.max(0,Math.min(s,m)),M=u,b=t.indexOf(e,k),x=[],_=0;_<m;_+=1)x[_]=0;if(-1!==b){var w=o(e,{errors:0,currentLocation:b,expectedLocation:k,distance:h});if(M=Math.min(w,M),-1!==(b=t.lastIndexOf(e,k+y))){var S=o(e,{errors:0,currentLocation:b,expectedLocation:k,distance:h});M=Math.min(S,M)}}b=-1;for(var O=[],I=1,A=y+m,L=1<<(y<=31?y-1:30),C=0;C<y;C+=1){for(var j=0,$=A;j<$;)o(e,{errors:C,currentLocation:k+$,expectedLocation:k,distance:h})<=M?j=$:A=$,$=Math.floor((A-j)/2+j);A=$;var P=Math.max(1,k-$+1),N=l?m:Math.min(k+$,m)+y,E=Array(N+2);E[N+1]=(1<<C)-1;for(var F=N;F>=P;F-=1){var z=F-1,q=r[t.charAt(z)];if(q&&(x[z]=1),E[F]=(E[F+1]<<1|1)&q,0!==C&&(E[F]|=(O[F+1]|O[F])<<1|1|O[F+1]),E[F]&L&&(I=o(e,{errors:C,currentLocation:z,expectedLocation:k,distance:h}))<=M){if(M=I,(b=z)<=k)break;P=Math.max(1,2*k-b)}}if(o(e,{errors:C+1,currentLocation:k,expectedLocation:k,distance:h})>M)break;O=E}var D={isMatch:b>=0,score:I||.001};return p&&(D.matchedIndices=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,s=0,o=t.length;s<o;s+=1){var a=t[s];a&&-1===n?n=s:a||-1===n||((i=s-1)-n+1>=e&&r.push([n,i]),n=-1)}return t[s-1]&&s-n>=e&&r.push([n,s-1]),r}(x,d)),D}(t,this.pattern,this.patternAlphabet,{location:a,distance:h,threshold:c,findAllMatches:u,minMatchCharLength:f,includeMatches:n})}}]),e}(),h=function(t){return t.substr(1)},c=function(t){return"'"==t.charAt(0)},u=function(t,e){var r=h(t);return{isMatch:e.indexOf(r)>-1,score:0}},f=function(t){return t.substr(1)},l=function(t){return"!"==t.charAt(0)},v=function(t,e){var r=f(t);return{isMatch:-1===e.indexOf(r),score:0}},d=function(t){return t.substr(1)},g=function(t){return"^"==t.charAt(0)},p=function(t,e){var r=d(t);return{isMatch:e.startsWith(r),score:0}},y=function(t){return t.substr(2)},m=function(t){return"!"==t.charAt(0)&&"^"==t.charAt(1)},k=function(t,e){var r=y(t);return{isMatch:!e.startsWith(r),score:0}},M=function(t){return t.substr(0,t.length-1)},b=function(t){return"$"==t.charAt(t.length-1)},x=function(t,e){var r=M(t);return{isMatch:e.endsWith(r),score:0}},_=function(t){return t.substring(1,t.length-1)},w=function(t){return"!"==t.charAt(0)&&"$"==t.charAt(t.length-1)},S=function(t,e){var r=_(t);return{isMatch:!e.endsWith(r),score:0}},O=function(t){return Array.isArray?Array.isArray(t):"[object Array]"===Object.prototype.toString.call(t)},I=function(t){return"string"==typeof t},A=function(t){return"number"==typeof t},L=function(t){return null!=t},C=function(){function e(r,n){t(this,e);var i=n.isCaseSensitive;this.query=null,this.options=n,this._fuzzyCache={},I(r)&&r.trim().length>0&&(this.pattern=i?r:r.toLowerCase(),this.query=function(t){return t.split("|").map((function(t){return t.trim().split(/ +/g)}))}(this.pattern))}return r(e,[{key:"searchIn",value:function(t){var e=this.query;if(!this.query)return{isMatch:!1,score:1};var r=t.$;r=this.options.isCaseSensitive?r:r.toLowerCase();for(var n=!1,i=0,s=e.length;i<s;i+=1){var o=e[i],a=null;n=!0;for(var h=0,c=o.length;h<c;h+=1){var u=o[h];if(!(a=this._search(u,r)).isMatch){n=!1;break}}if(n)return a}return{isMatch:!1,score:1}}},{key:"_search",value:function(t,e){if(c(t))return u(t,e);if(g(t))return p(t,e);if(m(t))return k(t,e);if(w(t))return S(t,e);if(b(t))return x(t,e);if(l(t))return v(t,e);var r=this._fuzzyCache[t];return r||(r=new a(t,this.options),this._fuzzyCache[t]=r),r.searchInString(e)}}]),e}();function j(t,e){var r=e.n,n=void 0===r?3:r,i=e.pad,s=void 0===i||i,o=e.sort,a=void 0!==o&&o,h=[];if(null==t)return h;t=t.toLowerCase(),s&&(t=" ".concat(t," "));var c=t.length-n+1;if(c<1)return h;for(;c--;)h[c]=t.substr(c,n);return a&&h.sort((function(t,e){return t==e?0:t<e?-1:1})),h}var $=function(){function e(r){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{threshold:.6};t(this,e),this.options=n,this.patternNgram=j(r,{sort:!0})}return r(e,[{key:"searchIn",value:function(t){var e=t.ng;e||(e=j(t.$,{sort:!0}),t.ng=e);var r,n,i,s=(r=this.patternNgram,i=function(t,e){for(var r=[],n=0,i=0;n<t.length&&i<e.length;){var s=t[n],o=e[i];s<o?(r.push(s),n+=1):o<s?(r.push(o),i+=1):(r.push(o),n+=1,i+=1)}for(;n<t.length;)r.push(t[n]),n+=1;for(;i<e.length;)r.push(e[i]),i+=1;return r}(r,n=e),1-function(t,e){for(var r=[],n=0,i=0;n<t.length&&i<e.length;){var s=t[n],o=e[i];s==o?(r.push(s),n+=1,i+=1):s<o?n+=1:(s>o||(n+=1),i+=1)}return r}(r,n).length/i.length),o=s<this.options.threshold;return{score:o?s:1,isMatch:o}}}]),e}();function P(t,e){var r=[],n=!1;return function t(e,i){if(i){var s=i.indexOf("."),o=i,a=null;-1!==s&&(o=i.slice(0,s),a=i.slice(s+1));var h=e[o];if(L(h))if(a||!I(h)&&!A(h))if(O(h)){n=!0;for(var c=0,u=h.length;c<u;c+=1)t(h[c],a)}else a&&t(h,a);else r.push(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)}(h))}else r.push(e)}(t,e),n?r:r[0]}function N(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r.getFn,i=void 0===n?P:n,s=r.ngrams,o=void 0!==s&&s,a=[];if(I(e[0]))for(var h=0,c=e.length;h<c;h+=1){var u=e[h];if(L(u)){var f={$:u,idx:h};o&&(f.ng=j(u,{sort:!0})),a.push(f)}}else for(var l=t.length,v=0,d=e.length;v<d;v+=1){for(var g=e[v],p={idx:v,$:{}},y=0;y<l;y+=1){var m=t[y],k=i(g,m);if(L(k))if(O(k)){for(var M=[],b=[{arrayIndex:-1,value:k}];b.length;){var x=b.pop(),_=x.arrayIndex,w=x.value;if(L(w))if(I(w)){var S={$:w,idx:_};o&&(S.ng=j(w,{sort:!0})),M.push(S)}else if(O(w))for(var A=0,C=w.length;A<C;A+=1)b.push({arrayIndex:A,value:w[A]})}p.$[m]=M}else{var $={$:k};o&&($.ng=j(k,{sort:!0})),p.$[m]=$}}a.push(p)}return a}var E=function(){function e(r){if(t(this,e),this._keys={},this._keyNames=[],this._length=r.length,r.length&&I(r[0]))for(var n=0;n<this._length;n+=1){var i=r[n];this._keys[i]={weight:1},this._keyNames.push(i)}else{for(var s=0,o=0;o<this._length;o+=1){var a=r[o];if(!a.hasOwnProperty("name"))throw new Error('Missing "name" property in key object');var h=a.name;if(this._keyNames.push(h),!a.hasOwnProperty("weight"))throw new Error('Missing "weight" property in key object');var c=a.weight;if(c<=0||c>=1)throw new Error('"weight" property in key must bein the range of (0, 1)');this._keys[h]={weight:c},s+=c}for(var u=0;u<this._length;u+=1){var f=this._keyNames[u],l=this._keys[f].weight;this._keys[f].weight=l/s}}}return r(e,[{key:"get",value:function(t,e){return this._keys[t]?this._keys[t][e]:-1}},{key:"keys",value:function(){return this._keyNames}},{key:"count",value:function(){return this._length}},{key:"toJSON",value:function(){return JSON.stringify(this._keys)}}]),e}();function F(t,e){var r=t.matches;if(e.matches=[],L(r))for(var n=0,i=r.length;n<i;n+=1){var s=r[n];if(L(s.indices)&&0!==s.indices.length){var o={indices:s.indices,value:s.value};s.key&&(o.key=s.key),s.idx>-1&&(o.refIndex=s.idx),e.matches.push(o)}}}function z(t,e){e.score=t.score}var q={isCaseSensitive:!1,distance:100,findAllMatches:!1,getFn:P,includeMatches:!1,includeScore:!1,keys:[],location:0,minMatchCharLength:1,shouldSort:!0,sortFn:function(t,e){return t.score-e.score},threshold:.6,useExtendedSearch:!1},D=function(){function e(r){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:q,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;t(this,e),this.options=s({},q,{},n),this.options.isCaseSensitive=n.caseSensitive,delete this.options.caseSensitive,this._processKeys(this.options.keys),this.setCollection(r,i)}return r(e,[{key:"setCollection",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;this.list=t,this.listIsStringArray=I(t[0]),e?this.setIndex(e):this.setIndex(this._createIndex())}},{key:"setIndex",value:function(t){this._indexedList=t}},{key:"_processKeys",value:function(t){this._keyStore=new E(t)}},{key:"_createIndex",value:function(){return N(this._keyStore.keys(),this.list,{getFn:this.options.getFn})}},{key:"search",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{limit:!1},r=this.options,n=r.useExtendedSearch,i=r.shouldSort,s=null;s=n?new C(t,this.options):t.length>32?new $(t,this.options):new a(t,this.options);var o=this._searchUsing(s);return this._computeScore(o),i&&this._sort(o),e.limit&&A(e.limit)&&(o=o.slice(0,e.limit)),this._format(o)}},{key:"_searchUsing",value:function(t){var e=this._indexedList,r=[],n=this.options.includeMatches;if(this.listIsStringArray)for(var i=0,s=e.length;i<s;i+=1){var o=e[i],a=o.$,h=o.idx;if(L(a)){var c=t.searchIn(o),u=c.isMatch,f=c.score;if(u){var l={score:f,value:a};n&&(l.indices=c.matchedIndices),r.push({item:a,idx:h,matches:[l]})}}}else for(var v=this._keyStore.keys(),d=this._keyStore.count(),g=0,p=e.length;g<p;g+=1){var y=e[g],m=y.$,k=y.idx;if(L(m)){for(var M=[],b=0;b<d;b+=1){var x=v[b],_=m[x];if(L(_))if(O(_))for(var w=0,S=_.length;w<S;w+=1){var I=_[w],A=I.$,C=I.idx;if(L(A)){var j=t.searchIn(I),$=j.isMatch,P=j.score;if($){var N={score:P,key:x,value:A,idx:C};n&&(N.indices=j.matchedIndices),M.push(N)}}}else{var E=_.$,F=t.searchIn(_),z=F.isMatch,q=F.score;if(!z)continue;var D={score:q,key:x,value:E};n&&(D.indices=F.matchedIndices),M.push(D)}}M.length&&r.push({idx:k,item:m,matches:M})}}return r}},{key:"_computeScore",value:function(t){for(var e=0,r=t.length;e<r;e+=1){for(var n=t[e],i=n.matches,s=i.length,o=1,a=0;a<s;a+=1){var h=i[a],c=h.key,u=this._keyStore.get(c,"weight"),f=u>-1?u:1,l=0===h.score&&u>-1?Number.EPSILON:h.score;o*=Math.pow(l,f)}n.score=o}}},{key:"_sort",value:function(t){t.sort(this.options.sortFn)}},{key:"_format",value:function(t){var e=[],r=this.options,n=r.includeMatches,i=r.includeScore,s=[];n&&s.push(F),i&&s.push(z);for(var o=0,a=t.length;o<a;o+=1){var h=t[o],c=h.idx,u={item:this.list[c],refIndex:c};if(s.length)for(var f=0,l=s.length;f<l;f+=1)s[f](h,u);e.push(u)}return e}}]),e}();return D.version="5.0.8-beta",D.createIndex=N,D},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):((t=t||self).Fuse=t.Fuse||{},t.Fuse.js=e());
var t,e;t=this,e=function(){"use strict";function t(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function e(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)}}function r(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}function n(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function i(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function s(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?i(Object(r),!0).forEach((function(e){n(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):i(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function o(t,e){var r=e.errors,n=void 0===r?0:r,i=e.currentLocation,s=void 0===i?0:i,o=e.expectedLocation,a=void 0===o?0:o,h=e.distance,c=void 0===h?100:h,u=n/t.length,f=Math.abs(a-s);return c?u+f/c:f?1:u}var a=function(){function e(r,n){var i=n.location,s=void 0===i?0:i,o=n.distance,a=void 0===o?100:o,h=n.threshold,c=void 0===h?.6:h,u=n.isCaseSensitive,f=void 0!==u&&u,l=n.findAllMatches,v=void 0!==l&&l,d=n.minMatchCharLength,g=void 0===d?1:d,p=n.includeMatches,y=void 0!==p&&p;if(t(this,e),this.options={location:s,distance:a,threshold:c,isCaseSensitive:f,findAllMatches:v,includeMatches:y,minMatchCharLength:g},r.length>32)throw new Error("Pattern length exceeds max of ".concat(32,"."));this.pattern=f?r:r.toLowerCase(),this.patternAlphabet=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}(this.pattern)}return r(e,[{key:"searchIn",value:function(t){var e=t.$;return this.searchInString(e)}},{key:"searchInString",value:function(t){var e=this.options,r=e.isCaseSensitive,n=e.includeMatches;if(r||(t=t.toLowerCase()),this.pattern===t){var i={isMatch:!0,score:0};return n&&(i.matchedIndices=[[0,t.length-1]]),i}var s=this.options,a=s.location,h=s.distance,c=s.threshold,u=s.findAllMatches,f=s.minMatchCharLength;return function(t,e,r,n){for(var i=n.location,s=void 0===i?0:i,a=n.distance,h=void 0===a?100:a,c=n.threshold,u=void 0===c?.6:c,f=n.findAllMatches,l=void 0!==f&&f,v=n.minMatchCharLength,d=void 0===v?1:v,g=n.includeMatches,p=void 0!==g&&g,y=e.length,m=t.length,k=Math.max(0,Math.min(s,m)),M=u,b=t.indexOf(e,k),x=[],_=0;_<m;_+=1)x[_]=0;if(-1!==b){var w=o(e,{errors:0,currentLocation:b,expectedLocation:k,distance:h});if(M=Math.min(w,M),-1!==(b=t.lastIndexOf(e,k+y))){var S=o(e,{errors:0,currentLocation:b,expectedLocation:k,distance:h});M=Math.min(S,M)}}b=-1;for(var O=[],I=1,A=y+m,L=1<<(y<=31?y-1:30),C=0;C<y;C+=1){for(var j=0,$=A;j<$;)o(e,{errors:C,currentLocation:k+$,expectedLocation:k,distance:h})<=M?j=$:A=$,$=Math.floor((A-j)/2+j);A=$;var P=Math.max(1,k-$+1),N=l?m:Math.min(k+$,m)+y,E=Array(N+2);E[N+1]=(1<<C)-1;for(var F=N;F>=P;F-=1){var z=F-1,q=r[t.charAt(z)];if(q&&(x[z]=1),E[F]=(E[F+1]<<1|1)&q,0!==C&&(E[F]|=(O[F+1]|O[F])<<1|1|O[F+1]),E[F]&L&&(I=o(e,{errors:C,currentLocation:z,expectedLocation:k,distance:h}))<=M){if(M=I,(b=z)<=k)break;P=Math.max(1,2*k-b)}}if(o(e,{errors:C+1,currentLocation:k,expectedLocation:k,distance:h})>M)break;O=E}var D={isMatch:b>=0,score:I||.001};return p&&(D.matchedIndices=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,s=0,o=t.length;s<o;s+=1){var a=t[s];a&&-1===n?n=s:a||-1===n||((i=s-1)-n+1>=e&&r.push([n,i]),n=-1)}return t[s-1]&&s-n>=e&&r.push([n,s-1]),r}(x,d)),D}(t,this.pattern,this.patternAlphabet,{location:a,distance:h,threshold:c,findAllMatches:u,minMatchCharLength:f,includeMatches:n})}}]),e}(),h=function(t){return t.substr(1)},c=function(t){return"'"==t.charAt(0)},u=function(t,e){var r=h(t);return{isMatch:e.indexOf(r)>-1,score:0}},f=function(t){return t.substr(1)},l=function(t){return"!"==t.charAt(0)},v=function(t,e){var r=f(t);return{isMatch:-1===e.indexOf(r),score:0}},d=function(t){return t.substr(1)},g=function(t){return"^"==t.charAt(0)},p=function(t,e){var r=d(t);return{isMatch:e.startsWith(r),score:0}},y=function(t){return t.substr(2)},m=function(t){return"!"==t.charAt(0)&&"^"==t.charAt(1)},k=function(t,e){var r=y(t);return{isMatch:!e.startsWith(r),score:0}},M=function(t){return t.substr(0,t.length-1)},b=function(t){return"$"==t.charAt(t.length-1)},x=function(t,e){var r=M(t);return{isMatch:e.endsWith(r),score:0}},_=function(t){return t.substring(1,t.length-1)},w=function(t){return"!"==t.charAt(0)&&"$"==t.charAt(t.length-1)},S=function(t,e){var r=_(t);return{isMatch:!e.endsWith(r),score:0}},O=function(t){return Array.isArray?Array.isArray(t):"[object Array]"===Object.prototype.toString.call(t)},I=function(t){return"string"==typeof t},A=function(t){return"number"==typeof t},L=function(t){return null!=t},C=function(){function e(r,n){t(this,e);var i=n.isCaseSensitive;this.query=null,this.options=n,this._fuzzyCache={},I(r)&&r.trim().length>0&&(this.pattern=i?r:r.toLowerCase(),this.query=function(t){return t.split("|").map((function(t){return t.trim().split(/ +/g)}))}(this.pattern))}return r(e,[{key:"searchIn",value:function(t){var e=this.query;if(!this.query)return{isMatch:!1,score:1};var r=t.$;r=this.options.isCaseSensitive?r:r.toLowerCase();for(var n=!1,i=0,s=e.length;i<s;i+=1){var o=e[i],a=null;n=!0;for(var h=0,c=o.length;h<c;h+=1){var u=o[h];if(!(a=this._search(u,r)).isMatch){n=!1;break}}if(n)return a}return{isMatch:!1,score:1}}},{key:"_search",value:function(t,e){if(c(t))return u(t,e);if(g(t))return p(t,e);if(m(t))return k(t,e);if(w(t))return S(t,e);if(b(t))return x(t,e);if(l(t))return v(t,e);var r=this._fuzzyCache[t];return r||(r=new a(t,this.options),this._fuzzyCache[t]=r),r.searchInString(e)}}]),e}();function j(t,e){var r=e.n,n=void 0===r?3:r,i=e.pad,s=void 0===i||i,o=e.sort,a=void 0!==o&&o,h=[];if(null==t)return h;t=t.toLowerCase(),s&&(t=" ".concat(t," "));var c=t.length-n+1;if(c<1)return h;for(;c--;)h[c]=t.substr(c,n);return a&&h.sort((function(t,e){return t==e?0:t<e?-1:1})),h}var $=function(){function e(r){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{threshold:.6};t(this,e),this.options=n,this.patternNgram=j(r,{sort:!0})}return r(e,[{key:"searchIn",value:function(t){var e=t.ng;e||(e=j(t.$,{sort:!0}),t.ng=e);var r,n,i,s=(r=this.patternNgram,i=function(t,e){for(var r=[],n=0,i=0;n<t.length&&i<e.length;){var s=t[n],o=e[i];s<o?(r.push(s),n+=1):o<s?(r.push(o),i+=1):(r.push(o),n+=1,i+=1)}for(;n<t.length;)r.push(t[n]),n+=1;for(;i<e.length;)r.push(e[i]),i+=1;return r}(r,n=e),1-function(t,e){for(var r=[],n=0,i=0;n<t.length&&i<e.length;){var s=t[n],o=e[i];s==o?(r.push(s),n+=1,i+=1):s<o?n+=1:(s>o||(n+=1),i+=1)}return r}(r,n).length/i.length),o=s<this.options.threshold;return{score:o?s:1,isMatch:o}}}]),e}();function P(t,e){var r=[],n=!1;return function t(e,i){if(i){var s=i.indexOf("."),o=i,a=null;-1!==s&&(o=i.slice(0,s),a=i.slice(s+1));var h=e[o];if(L(h))if(a||!I(h)&&!A(h))if(O(h)){n=!0;for(var c=0,u=h.length;c<u;c+=1)t(h[c],a)}else a&&t(h,a);else r.push(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)}(h))}else r.push(e)}(t,e),n?r:r[0]}function N(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r.getFn,i=void 0===n?P:n,s=r.ngrams,o=void 0!==s&&s,a=[];if(I(e[0]))for(var h=0,c=e.length;h<c;h+=1){var u=e[h];if(L(u)){var f={$:u,idx:h};o&&(f.ng=j(u,{sort:!0})),a.push(f)}}else for(var l=t.length,v=0,d=e.length;v<d;v+=1){for(var g=e[v],p={idx:v,$:{}},y=0;y<l;y+=1){var m=t[y],k=i(g,m);if(L(k))if(O(k)){for(var M=[],b=[{arrayIndex:-1,value:k}];b.length;){var x=b.pop(),_=x.arrayIndex,w=x.value;if(L(w))if(I(w)){var S={$:w,idx:_};o&&(S.ng=j(w,{sort:!0})),M.push(S)}else if(O(w))for(var A=0,C=w.length;A<C;A+=1)b.push({arrayIndex:A,value:w[A]})}p.$[m]=M}else{var $={$:k};o&&($.ng=j(k,{sort:!0})),p.$[m]=$}}a.push(p)}return a}var E=function(){function e(r){if(t(this,e),this._keys={},this._keyNames=[],this._length=r.length,r.length&&I(r[0]))for(var n=0;n<this._length;n+=1){var i=r[n];this._keys[i]={weight:1},this._keyNames.push(i)}else{for(var s=0,o=0;o<this._length;o+=1){var a=r[o];if(!a.hasOwnProperty("name"))throw new Error('Missing "name" property in key object');var h=a.name;if(this._keyNames.push(h),!a.hasOwnProperty("weight"))throw new Error('Missing "weight" property in key object');var c=a.weight;if(c<=0||c>=1)throw new Error('"weight" property in key must bein the range of (0, 1)');this._keys[h]={weight:c},s+=c}for(var u=0;u<this._length;u+=1){var f=this._keyNames[u],l=this._keys[f].weight;this._keys[f].weight=l/s}}}return r(e,[{key:"get",value:function(t,e){return this._keys[t]?this._keys[t][e]:-1}},{key:"keys",value:function(){return this._keyNames}},{key:"count",value:function(){return this._length}},{key:"toJSON",value:function(){return JSON.stringify(this._keys)}}]),e}();function F(t,e){var r=t.matches;if(e.matches=[],L(r))for(var n=0,i=r.length;n<i;n+=1){var s=r[n];if(L(s.indices)&&0!==s.indices.length){var o={indices:s.indices,value:s.value};s.key&&(o.key=s.key),s.idx>-1&&(o.refIndex=s.idx),e.matches.push(o)}}}function z(t,e){e.score=t.score}var q={isCaseSensitive:!1,distance:100,findAllMatches:!1,getFn:P,includeMatches:!1,includeScore:!1,keys:[],location:0,minMatchCharLength:1,shouldSort:!0,sortFn:function(t,e){return t.score-e.score},threshold:.6,useExtendedSearch:!1},D=function(){function e(r){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:q,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;t(this,e),this.options=s({},q,{},n),this.options.isCaseSensitive=n.caseSensitive,delete this.options.caseSensitive,this._processKeys(this.options.keys),this.setCollection(r,i)}return r(e,[{key:"setCollection",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;this.list=t,this.listIsStringArray=I(t[0]),e?this.setIndex(e):this.setIndex(this._createIndex())}},{key:"setIndex",value:function(t){this._indexedList=t}},{key:"_processKeys",value:function(t){this._keyStore=new E(t)}},{key:"_createIndex",value:function(){return N(this._keyStore.keys(),this.list,{getFn:this.options.getFn})}},{key:"search",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{limit:!1},r=this.options,n=r.useExtendedSearch,i=r.shouldSort,s=null;s=n?new C(t,this.options):t.length>32?new $(t,this.options):new a(t,this.options);var o=this._searchUsing(s);return this._computeScore(o),i&&this._sort(o),e.limit&&A(e.limit)&&(o=o.slice(0,e.limit)),this._format(o)}},{key:"_searchUsing",value:function(t){var e=this._indexedList,r=[],n=this.options.includeMatches;if(this.listIsStringArray)for(var i=0,s=e.length;i<s;i+=1){var o=e[i],a=o.$,h=o.idx;if(L(a)){var c=t.searchIn(o),u=c.isMatch,f=c.score;if(u){var l={score:f,value:a};n&&(l.indices=c.matchedIndices),r.push({item:a,idx:h,matches:[l]})}}}else for(var v=this._keyStore.keys(),d=this._keyStore.count(),g=0,p=e.length;g<p;g+=1){var y=e[g],m=y.$,k=y.idx;if(L(m)){for(var M=[],b=0;b<d;b+=1){var x=v[b],_=m[x];if(L(_))if(O(_))for(var w=0,S=_.length;w<S;w+=1){var I=_[w],A=I.$,C=I.idx;if(L(A)){var j=t.searchIn(I),$=j.isMatch,P=j.score;if($){var N={score:P,key:x,value:A,idx:C};n&&(N.indices=j.matchedIndices),M.push(N)}}}else{var E=_.$,F=t.searchIn(_),z=F.isMatch,q=F.score;if(!z)continue;var D={score:q,key:x,value:E};n&&(D.indices=F.matchedIndices),M.push(D)}}M.length&&r.push({idx:k,item:m,matches:M})}}return r}},{key:"_computeScore",value:function(t){for(var e=0,r=t.length;e<r;e+=1){for(var n=t[e],i=n.matches,s=i.length,o=1,a=0;a<s;a+=1){var h=i[a],c=h.key,u=this._keyStore.get(c,"weight"),f=u>-1?u:1,l=0===h.score&&u>-1?Number.EPSILON:h.score;o*=Math.pow(l,f)}n.score=o}}},{key:"_sort",value:function(t){t.sort(this.options.sortFn)}},{key:"_format",value:function(t){var e=[],r=this.options,n=r.includeMatches,i=r.includeScore,s=[];n&&s.push(F),i&&s.push(z);for(var o=0,a=t.length;o<a;o+=1){var h=t[o],c=h.idx,u={item:this.list[c],refIndex:c};if(s.length)for(var f=0,l=s.length;f<l;f+=1)s[f](h,u);e.push(u)}return e}}]),e}();return D.version="5.0.9-beta",D.createIndex=N,D},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).Fuse=e();

@@ -16,3 +16,3 @@ {

],
"version": "5.0.8-beta",
"version": "5.0.9-beta",
"description": "Lightweight fuzzy-search",

@@ -19,0 +19,0 @@ "license": "Apache-2.0",

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc