Socket
Socket
Sign inDemoInstall

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 5.0.1-beta to 5.0.2-beta

9

CHANGELOG.md

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

# Version 5.0.2-beta
- Added indexing for increased performance over large lists
- Added `Fuse.createIndex`, which created and returns an index. This function can be used to pre-generate the index, which you can then save, and ultimately pass to the `Fuse` instance.
- **Breaking changes:**
- Removed `id` option
- Changed format of the search results
- Updated TypeScript definitions
# Version 5.0.1-beta

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

52

dist/fuse.d.ts

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

// Type definitions for Fuse.js v5.0.1-beta
// Type definitions for Fuse.js v5.0.2-beta
// TypeScript Version: 3.1

@@ -7,11 +7,21 @@

interface SearchOpts {
interface SearchOpt {
limit?: number
}
// TODO: Needs more work to actually make sense in TypeScript
interface FuseIndexRecord {
idx: number
$: any
}
declare class Fuse<T, O extends Fuse.FuseOptions<T>> {
constructor(list: ReadonlyArray<T>, options?: O)
constructor(
list: ReadonlyArray<T>,
options?: O,
index?: ReadonlyArray<FuseIndexRecord>,
)
search<
/** Type of item of return */
R = O extends { id: string } ? string : T,
R = T,
/** include score (boolean) */

@@ -23,3 +33,3 @@ S = O['includeScore'],

pattern: string,
opts?: SearchOpts,
opts?: SearchOpt,
): S extends true

@@ -33,9 +43,20 @@ ? M extends true

setCollection(list: ReadonlyArray<T>): ReadonlyArray<T>
list: ReadonlyArray<T>
setCollection(
list: ReadonlyArray<T>,
index?: ReadonlyArray<FuseIndexRecord>,
): void
setIndex(index: ReadonlyArray<FuseIndexRecord>): void
}
declare namespace Fuse {
export interface FuseResultMatch {
indices: ReadonlyArray<number>[]
key?: string
refIndex?: number
value?: string
}
export interface FuseResultWithScore<T> {
item: T
refIndex: number
score: number

@@ -45,21 +66,20 @@ }

item: T
matches: any
refIndex: number
matches: ReadonlyArray<FuseResultMatch>
}
export interface FuseOptions<T> {
id?: keyof T | string
caseSensitive?: boolean
distance?: number
findAllMatches?: boolean
getFn?: (obj: any, path: string) => any
includeMatches?: boolean
includeScore?: boolean
keys?: (keyof T | string)[] | { name: keyof T | string; weight: number }[]
location?: number
minMatchCharLength?: number
shouldSort?: boolean
sortFn?: (a: { score: number }, b: { score: number }) => number
getFn?: (obj: any, path: string) => any
keys?: (keyof T | string)[] | { name: keyof T | string; weight: number }[]
verbose?: boolean
location?: number
distance?: number
threshold?: number
minMatchCharLength?: number
findAllMatches?: boolean
useExtendedSearch?: boolean
}
}
/*!
* Fuse.js v5.0.1-beta - Lightweight fuzzy-search (http://fusejs.io)
* Fuse.js v5.0.2-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 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}}}])}));
!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=5)}([function(t,e){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)}t.exports={isDefined:function(t){return null!=t},isArray:function(t){return Array.isArray?Array.isArray(t):"[object Array]"===Object.prototype.toString.call(t)},isString:function(t){return"string"==typeof t},isNumber:function(t){return"number"==typeof t},isObject:function(t){return"object"===r(t)},toString: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)}}},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(7),o=r(10),a=r(2).MAX_BITS,s=function(){function t(e,r){var n=r.location,i=void 0===n?0:n,s=r.distance,c=void 0===s?100:s,u=r.threshold,h=void 0===u?.6:u,f=r.isCaseSensitive,l=void 0!==f&&f,v=r.findAllMatches,p=void 0!==v&&v,d=r.minMatchCharLength,y=void 0===d?1:d,g=r.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:i,distance:c,threshold:h,isCaseSensitive:l,findAllMatches:p,includeMatches:m,minMatchCharLength:y},e.length>a)throw new Error("Pattern length exceeds max of ".concat(a,"."));this.pattern=l?e:e.toLowerCase(),this.patternAlphabet=o(this.pattern)}var e,r,s;return e=t,(r=[{key:"searchIn",value:function(t){var e=t.$,r=this.options,n=r.isCaseSensitive,o=r.includeMatches;if(n||(e=e.toLowerCase()),this.pattern===e){var a={isMatch:!0,score:0};return o&&(a.matchedIndices=[[0,e.length-1]]),a}var s=this.options,c=s.location,u=s.distance,h=s.threshold,f=s.findAllMatches,l=s.minMatchCharLength;return i(e,this.pattern,this.patternAlphabet,{location:c,distance:u,threshold:h,findAllMatches:f,minMatchCharLength:l,includeMatches:o})}}])&&n(e.prototype,r),s&&n(e,s),t}();t.exports=s},function(t,e){t.exports.MAX_BITS=32},function(t,e){t.exports=function(t,e){var r=e.n,n=void 0===r?3:r,i=e.pad,o=void 0===i||i,a=e.sort,s=void 0!==a&&a,c=[];if(null==t)return c;t=t.toLowerCase(),o&&(t=" ".concat(t," "));var u=t.length-n+1;if(u<1)return c;for(;u--;)c[u]=t.substr(u,n);return s&&c.sort((function(t,e){return t==e?0:t<e?-1:1})),c}},function(t,e,r){var n=r(0),i=n.isDefined,o=n.isString,a=n.isNumber,s=n.isArray,c=n.toString;t.exports=function(t,e){var r=[],n=!1;return function t(e,u){if(u){var h=u.indexOf("."),f=u,l=null;-1!==h&&(f=u.slice(0,h),l=u.slice(h+1));var v=e[f];if(i(v))if(l||!o(v)&&!a(v))if(s(v)){n=!0;for(var p=0,d=v.length;p<d;p+=1)t(v[p],l)}else l&&t(v,l);else r.push(c(v))}else r.push(e)}(t,e),n?r:r[0]}},function(t,e,r){function n(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 i(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?n(Object(r),!0).forEach((function(e){o(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function o(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function a(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function s(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 c=r(6),u=c.BitapSearch,h=c.ExtendedSearch,f=c.NGramSearch,l=r(0),v=l.isArray,p=l.isDefined,d=l.isString,y=l.isNumber,g=(l.isObject,r(4)),m=r(24),b=m.createIndex,x=m.KeyStore,S=r(27),k=S.transformMatches,M=S.transformScore,w=r(2).MAX_BITS,_={isCaseSensitive:!1,distance:100,findAllMatches:!1,getFn:g,includeMatches:!1,includeScore:!1,keys:[],location:0,minMatchCharLength:1,shouldSort:!0,sortFn:function(t,e){return t.score-e.score},threshold:.6,useExtendedSearch:!1},O=function(){function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:_,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;a(this,t),this.options=i({},_,{},r),this.options.isCaseSensitive=r.caseSensitive,delete this.options.caseSensitive,this._processKeys(this.options.keys),this.setCollection(e,n)}var e,r,n;return e=t,(r=[{key:"setCollection",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;this.list=t,this.listIsStringArray=d(t[0]),e?this.setIndex(e):this.setIndex(this._createIndex())}},{key:"setIndex",value:function(t){this._indexedList=t}},{key:"_processKeys",value:function(e){this._keyStore=new x(e),t.verbose}},{key:"_createIndex",value:function(){return b(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,o=null;o=n?new h(t,this.options):t.length>w?new f(t,this.options):new u(t,this.options);var a=this._searchUsing(o);return this._computeScore(a),i&&this._sort(a),e.limit&&y(e.limit)&&(a=a.slice(0,e.limit)),this._format(a)}},{key:"_searchUsing",value:function(t){var e=this._indexedList,r=[],n=this.options.includeMatches;if(this.listIsStringArray)for(var i=0,o=e.length;i<o;i+=1){var a=e[i],s=a.$,c=a.idx;if(p(s)){var u=t.searchIn(a),h=u.isMatch,f=u.score;if(h){var l={score:f,value:s};n&&(l.indices=u.matchedIndices),r.push({item:s,idx:c,matches:[l]})}}}else for(var d=this._keyStore.keys(),y=this._keyStore.count(),g=0,m=e.length;g<m;g+=1){var b=e[g],x=b.$,S=b.idx;if(p(x)){for(var k=[],M=0;M<y;M+=1){var w=d[M],_=x[w];if(p(_))if(v(_))for(var O=0,j=_.length;O<j;O+=1){var P=_[O],A=P.$,I=P.idx;if(p(A)){var C=t.searchIn(P),L=C.isMatch,F=C.score;if(L){var E={score:F,key:w,value:A,idx:I};n&&(E.indices=C.matchedIndices),k.push(E)}}}else{var N=_.$,$=t.searchIn(_),z=$.isMatch,T=$.score;if(!z)continue;var D={score:T,key:w,value:N};n&&(D.indices=$.matchedIndices),k.push(D)}}k.length&&r.push({idx:S,item:x,matches:k})}}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,o=i.length,a=1,s=0;s<o;s+=1){var c=i[s],u=c.key,h=this._keyStore.get(u,"weight"),f=h||1,l=0===c.score&&h&&h>0?Number.EPSILON:c.score;a*=Math.pow(l,f)}n.score=a}}},{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,o=[];n&&o.push(k),i&&o.push(M);for(var a=0,s=t.length;a<s;a+=1){var c=t[a],u=c.idx,h={item:this.list[u],refIndex:u};if(o.length)for(var f=0,l=o.length;f<l;f+=1)o[f](c,h);e.push(h)}return e}}])&&s(e.prototype,r),n&&s(e,n),t}();O.createIndex=b,t.exports=O},function(t,e,r){t.exports={BitapSearch:r(1),ExtendedSearch:r(11),NGramSearch:r(18)}},function(t,e,r){var n=r(8),i=r(9);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,f=void 0===h?.6:h,l=o.findAllMatches,v=void 0!==l&&l,p=o.minMatchCharLength,d=void 0===p?1:p,y=o.includeMatches,g=void 0!==y&&y,m=e.length,b=t.length,x=Math.max(0,Math.min(s,b)),S=f,k=t.indexOf(e,x),M=[],w=0;w<b;w+=1)M[w]=0;if(-1!==k){var _=n(e,{errors:0,currentLocation:k,expectedLocation:x,distance:u});if(S=Math.min(_,S),-1!==(k=t.lastIndexOf(e,x+m))){var O=n(e,{errors:0,currentLocation:k,expectedLocation:x,distance:u});S=Math.min(O,S)}}k=-1;for(var j=[],P=1,A=m+b,I=1<<(m<=31?m-1:30),C=0;C<m;C+=1){for(var L=0,F=A;L<F;){n(e,{errors:C,currentLocation:x+F,expectedLocation:x,distance:u})<=S?L=F:A=F,F=Math.floor((A-L)/2+L)}A=F;var E=Math.max(1,x-F+1),N=v?b:Math.min(x+F,b)+m,$=Array(N+2);$[N+1]=(1<<C)-1;for(var z=N;z>=E;z-=1){var T=z-1,D=r[t.charAt(T)];if(D&&(M[T]=1),$[z]=($[z+1]<<1|1)&D,0!==C&&($[z]|=(j[z+1]|j[z])<<1|1|j[z+1]),$[z]&I&&(P=n(e,{errors:C,currentLocation:T,expectedLocation:x,distance:u}))<=S){if(S=P,(k=T)<=x)break;E=Math.max(1,2*x-k)}}if(n(e,{errors:C+1,currentLocation:x,expectedLocation:x,distance:u})>S)break;j=$}var W={isMatch:k>=0,score:P||.001};return g&&(W.matchedIndices=i(M,d)),W}},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,f=Math.abs(s-o);return u?h+f/u:f?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(12),o=r(13),a=r(14),s=r(15),c=r(16),u=r(17),h=r(1),f=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,f;return e=t,(r=[{key:"searchIn",value:function(t){var e=t.$,r=this.query;e=this.options.isCaseSensitive?e:e.toLowerCase();for(var n=!1,i=0,o=r.length;i<o;i+=1){var a=r[i],s=null;n=!0;for(var c=0,u=a.length;c<u;c+=1){var h=a[c];if(!(s=this._search(h,e)).isMatch){n=!1;break}}if(n)return s}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),f&&n(e,f),t}();t.exports=f},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,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(3),o=r(19).jaccardDistance,a=function(){function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.patternNgram=i(e,{sort:!0})}var e,r,a;return e=t,(r=[{key:"searchIn",value:function(t){var e=t.ng;e||(e=i(t.$,{sort:!0}),t.ng=e);var r=o(this.patternNgram,e);return{score:r,isMatch:r<1}}}])&&n(e.prototype,r),a&&n(e,a),t}();t.exports=a},function(t,e,r){t.exports={jaccardDistance:r(20)}},function(t,e,r){var n=r(21),i=n.union,o=n.intersection;t.exports=function(t,e){var r=i(t,e);return 1-o(t,e).length/r.length}},function(t,e,r){t.exports={union:r(22),intersection:r(23)}},function(t,e){t.exports=function(t,e){for(var r=[],n=0,i=0;n<t.length&&i<e.length;){var o=t[n],a=e[i];o<a?(r.push(o),n+=1):a<o?(r.push(a),i+=1):(r.push(a),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}},function(t,e){t.exports=function(t,e){for(var r=[],n=0,i=0;n<t.length&&i<e.length;){var o=t[n],a=e[i];o==a?(r.push(o),n+=1,i+=1):o<a?n+=1:(o>a||(n+=1),i+=1)}return r}},function(t,e,r){t.exports={createIndex:r(25),KeyStore:r(26)}},function(t,e,r){var n=r(0),i=n.isArray,o=n.isDefined,a=n.isString,s=r(4),c=r(3);t.exports=function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r.getFn,u=void 0===n?s:n,h=r.ngrams,f=void 0!==h&&h,l=[];if(a(e[0]))for(var v=0,p=e.length;v<p;v+=1){var d=e[v];if(o(d)){var y={$:d,idx:v};f&&(y.ng=c(d,{sort:!0})),l.push(y)}}else for(var g=t.length,m=0,b=e.length;m<b;m+=1){for(var x=e[m],S={idx:m,$:{}},k=0;k<g;k+=1){var M=t[k],w=u(x,M);if(o(w))if(i(w)){for(var _=[],O=[{arrayIndex:-1,value:w}];O.length;){var j=O.pop(),P=j.arrayIndex,A=j.value;if(o(A))if(a(A)){var I={$:A,idx:P};f&&(I.ng=c(A,{sort:!0})),_.push(I)}else if(i(A))for(var C=0,L=A.length;C<L;C+=1)O.push({arrayIndex:C,value:A[C]})}S.$[M]=_}else{var F={$:w};f&&(F.ng=c(w,{sort:!0})),S.$[M]=F}}l.push(S)}return l}},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(0).isString,o=function(){function t(e){if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this._keys={},this._keyNames=[],this._length=e.length,this._hasWeights=!1,e.length&&i(e[0]))for(var r=0;r<this._length;r+=1){var n=e[r];this._keys[n]={weight:1},this._keyNames.push(n)}else{for(var o=0,a=0;a<this._length;a+=1){var s=e[a];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(u<=0||u>=1)throw new Error('"weight" property in key must bein the range of (0, 1)');this._keys[c]={weight:u},o+=u,this._hasWeights=!0}if(o>1)throw new Error("Total of keyWeights cannot exceed 1")}}var e,r,o;return e=t,(r=[{key:"get",value:function(t,e){return this._keys[t]?this._keys[t][e]:null}},{key:"keys",value:function(){return this._keyNames}},{key:"count",value:function(){return this._length}},{key:"toJSON",value:function(){return JSON.stringify(this._keys)}}])&&n(e.prototype,r),o&&n(e,o),t}();t.exports=o},function(t,e,r){t.exports={transformMatches:r(28),transformScore:r(29)}},function(t,e){t.exports=function(t,e){var r=t.matches;e.matches=[];for(var n=0,i=r.length;n<i;n+=1){var o=r[n];if(0!==o.indices.length){var a={indices:o.indices,value:o.value};o.key&&(a.key=o.key),o.idx>-1&&(a.refIndex=o.idx),e.matches.push(a)}}}},function(t,e){t.exports=function(t,e){e.score=t.score}}])}));

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

},
"version": "5.0.1-beta",
"version": "5.0.2-beta",
"description": "Lightweight fuzzy-search",

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

@@ -18,2 +18,3 @@ <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>

- _Added [enhanced searching](https://fusejs.io/#extended-search)_
- _Added [indexing](https://fusejs.io/#indexing) for increased performance over large lists_

@@ -20,0 +21,0 @@ ---

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