Comparing version 5.0.7-beta to 5.0.8-beta
@@ -0,1 +1,11 @@ | ||
# Version 5.0.8-beta | ||
- Changed bundler to Rollup. | ||
- Added ES6 modules for bundlers and browsers (`fuse.esm.js`) (fixed #262) | ||
- Added CommonJS builds (`fuse.common.js`) | ||
## Breaking Changes | ||
- The minimified version is finally actually called `fuse.min.js` | ||
# Version 5.0.7-beta | ||
@@ -19,7 +29,9 @@ | ||
- 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 | ||
## Breaking Changes | ||
- Removed `id` option | ||
- Changed format of the search results | ||
- Updated TypeScript definitions | ||
# Version 5.0.1-beta | ||
@@ -26,0 +38,0 @@ |
@@ -1,3 +0,3 @@ | ||
// Type definitions for Fuse.js v5.0.7-beta | ||
// TypeScript Version: 3.1 | ||
// Type definitions for Fuse.js v5.0.8-beta | ||
// TypeScript v3.8.3 | ||
@@ -7,76 +7,219 @@ export = Fuse | ||
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>> { | ||
declare class Fuse<T, O extends Fuse.IFuseOptions<T>> { | ||
constructor( | ||
list: ReadonlyArray<T>, | ||
options?: O, | ||
index?: ReadonlyArray<FuseIndexRecord>, | ||
index?: ReadonlyArray<Fuse.FuseIndexRecord>, | ||
) | ||
search< | ||
/** Type of item of return */ | ||
R = T, | ||
/** include score (boolean) */ | ||
S = O['includeScore'], | ||
/** include matches (boolean) */ | ||
M = O['includeMatches'] | ||
>( | ||
/** | ||
* Search function for the Fuse instance. | ||
* | ||
* ```typescript | ||
* const list: MyType[] = [myType1, myType2, etc...] | ||
* const options: Fuse.IFuseOptions<MyType> = { | ||
* keys: ['key1', 'key2'] | ||
* } | ||
* | ||
* const myFuse = new Fuse(list, options) | ||
* let result = myFuse.search('pattern') | ||
* ``` | ||
* | ||
* @param pattern The pattern to search | ||
* @param options `Fuse.FuseSearchOptions` | ||
* @returns An array of search results | ||
*/ | ||
search<R = T>( | ||
pattern: string, | ||
opts?: SearchOpt, | ||
): S extends true | ||
? M extends true | ||
? (Fuse.FuseResultWithMatches<R> & Fuse.FuseResultWithScore<R>)[] | ||
: Fuse.FuseResultWithScore<R>[] | ||
: M extends true | ||
? Fuse.FuseResultWithMatches<R>[] | ||
: R[] | ||
options?: Fuse.FuseSearchOptions, | ||
): Fuse.FuseResult<R>[] | ||
setCollection( | ||
list: ReadonlyArray<T>, | ||
index?: ReadonlyArray<FuseIndexRecord>, | ||
index?: ReadonlyArray<Fuse.FuseIndexRecord>, | ||
): void | ||
setIndex(index: ReadonlyArray<FuseIndexRecord>): void | ||
setIndex(index: ReadonlyArray<Fuse.FuseIndexRecord>): void | ||
/** | ||
* Return the current version | ||
*/ | ||
static version: string | ||
/** | ||
* Use this method to pre-generate the index from the list, and pass it | ||
* directly into the Fuse instance. | ||
* | ||
* _Note that Fuse will automatically index the table if one isn't provided | ||
* during instantiation._ | ||
* | ||
* ```typescript | ||
* const list: MyType[] = [myType1, myType2, etc...] | ||
* | ||
* const index = Fuse.createIndex<MyType>( | ||
* keys: ['key1', 'key2'] | ||
* list: list | ||
* ) | ||
* | ||
* const options: Fuse.IFuseOptions<MyType> = { | ||
* keys: ['key1', 'key2'] | ||
* } | ||
* | ||
* const myFuse = new Fuse(list, options, index) | ||
* ``` | ||
* @param keys The keys to index | ||
* @param list The list from which to create an index | ||
* @param options? | ||
* @returns An indexed list | ||
*/ | ||
static createIndex<U>( | ||
keys: Fuse.FuseOptionKeyObject[] | string[], | ||
list: ReadonlyArray<U>, | ||
options?: Fuse.FuseIndexOptions<U>, | ||
): ReadonlyArray<Fuse.FuseIndexRecord> | ||
} | ||
declare namespace Fuse { | ||
export interface FuseResultMatch { | ||
type FuseGetFunction<T> = ( | ||
obj: T, | ||
path: string, | ||
) => ReadonlyArray<string> | string | ||
export type FuseIndexOptions<T> = { | ||
getFn: FuseGetFunction<T> | ||
ngrams: boolean | ||
} | ||
// { | ||
// title: { '$': "Old Man's War" }, | ||
// 'author.firstName': { '$': 'Codenar' } | ||
// } | ||
// | ||
// OR | ||
// | ||
// { | ||
// tags: [ | ||
// { $: 'nonfiction', idx: 1 }, | ||
// { $: 'web development', idx: 0 }, | ||
// ] | ||
// } | ||
export type FuseSortFunctionItem = { | ||
[key: string]: { $: string } | { $: string; idx: number }[] | ||
} | ||
// { | ||
// score: 0.001, | ||
// key: 'author.firstName', | ||
// value: 'Codenar', | ||
// indices: [ [ 0, 3 ] ] | ||
// } | ||
export type FuseSortFunctionMatch = { | ||
score: number | ||
key: string | ||
value: string | ||
indices: ReadonlyArray<number>[] | ||
key?: string | ||
refIndex?: number | ||
value?: string | ||
} | ||
export interface FuseResultWithScore<T> { | ||
item: T | ||
refIndex: number | ||
// { | ||
// score: 0, | ||
// key: 'tags', | ||
// value: 'nonfiction', | ||
// idx: 1, | ||
// indices: [ [ 0, 9 ] ] | ||
// } | ||
export type FuseSortFunctionMatchList = FuseSortFunctionMatch & { | ||
idx: number | ||
} | ||
export type FuseSortFunctionArg = { | ||
idx: number | ||
item: FuseSortFunctionItem | ||
score: number | ||
matches?: (FuseSortFunctionMatch | FuseSortFunctionMatchList)[] | ||
} | ||
export interface FuseResultWithMatches<T> { | ||
item: T | ||
refIndex: number | ||
matches: ReadonlyArray<FuseResultMatch> | ||
export type FuseSortFunction = ( | ||
a: FuseSortFunctionArg, | ||
b: FuseSortFunctionArg, | ||
) => number | ||
// title: { | ||
// '$': "Old Man's War", | ||
// ng: [ | ||
// ' ma', ' ol', ' wa', | ||
// "'s ", "an'", 'ar ', | ||
// 'd m', 'ld ', 'man', | ||
// "n's", 'old', 's w', | ||
// 'war' | ||
// ] | ||
// } | ||
type RecordEntryObject = { $: string; ng?: ReadonlyArray<string> } | ||
// 'author.tags.name': [{ | ||
// '$': 'pizza lover', | ||
// idx: 2, | ||
// ng: [ | ||
// ' lo', ' pi', 'a l', | ||
// 'er ', 'izz', 'lov', | ||
// 'ove', 'piz', 'ver', | ||
// 'za ', 'zza' | ||
// ] | ||
// } | ||
type RecordEntryArrayItem = ReadonlyArray<RecordEntryObject & { idx: number }> | ||
// TODO: this makes it difficult to infer the type. Need to think more about this | ||
type RecordEntry = { [key: string]: RecordEntryObject | RecordEntryArrayItem } | ||
type FuseIndexRecord = { | ||
idx: number | ||
$: RecordEntry | ||
} | ||
export interface FuseOptions<T> { | ||
// { | ||
// name: 'title', | ||
// weight: 0.7 | ||
// } | ||
export type FuseOptionKeyObject = { | ||
name: string | ||
weight: number | ||
} | ||
export interface IFuseOptions<T> { | ||
caseSensitive?: boolean | ||
distance?: number | ||
findAllMatches?: boolean | ||
getFn?: (obj: any, path: string) => any | ||
getFn?: FuseGetFunction<T> | ||
includeMatches?: boolean | ||
includeScore?: boolean | ||
keys?: (keyof T | string)[] | { name: keyof T | string; weight: number }[] | ||
keys?: FuseOptionKeyObject[] | string[] | ||
location?: number | ||
minMatchCharLength?: number | ||
shouldSort?: boolean | ||
sortFn?: (a: { score: number }, b: { score: number }) => number | ||
sortFn?: FuseSortFunction | ||
threshold?: number | ||
useExtendedSearch?: boolean | ||
} | ||
// Denotes the start/end indices of a match | ||
// start end | ||
// ↓ ↓ | ||
type RangeTuple = [number, number] | ||
export type FuseResultMatch = { | ||
indices: ReadonlyArray<RangeTuple>[] | ||
key?: string | ||
refIndex?: number | ||
value?: string | ||
} | ||
export type FuseSearchOptions = { | ||
limit: number | ||
} | ||
export type FuseResult<T> = { | ||
item: T | ||
refIndex: number | ||
score?: number | ||
matches?: ReadonlyArray<FuseResultMatch> | ||
} | ||
} |
1470
dist/fuse.js
@@ -1,9 +0,1467 @@ | ||
/*! | ||
* Fuse.js v5.0.7-beta - Lightweight fuzzy-search (http://fusejs.io) | ||
* | ||
* Copyright (c) 2012-2020 Kirollos Risk (http://kiro.me) | ||
/** | ||
* Fuse.js v5.0.8-beta - Lightweight fuzzy-search (http://fusejs.io) | ||
* | ||
* Copyright (c) 2020 Kiro Risk (http://kiro.me) | ||
* All Rights Reserved. Apache Software License 2.0 | ||
* | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
!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),s=r(2).MAX_BITS,a=function(){function t(e,r){var n=r.location,i=void 0===n?0:n,a=r.distance,c=void 0===a?100:a,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>s)throw new Error("Pattern length exceeds max of ".concat(s,"."));this.pattern=l?e:e.toLowerCase(),this.patternAlphabet=o(this.pattern)}var e,r,a;return e=t,(r=[{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 o={isMatch:!0,score:0};return n&&(o.matchedIndices=[[0,t.length-1]]),o}var s=this.options,a=s.location,c=s.distance,u=s.threshold,h=s.findAllMatches,f=s.minMatchCharLength;return i(t,this.pattern,this.patternAlphabet,{location:a,distance:c,threshold:u,findAllMatches:h,minMatchCharLength:f,includeMatches:n})}}])&&n(e.prototype,r),a&&n(e,a),t}();t.exports=a},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,s=e.sort,a=void 0!==s&&s,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 a&&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,s=n.isNumber,a=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)&&!s(v))if(a(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 s(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function a(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;s(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 s=this._searchUsing(o);return this._computeScore(s),i&&this._sort(s),e.limit&&y(e.limit)&&(s=s.slice(0,e.limit)),this._format(s)}},{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 s=e[i],a=s.$,c=s.idx;if(p(a)){var u=t.searchIn(s),h=u.isMatch,f=u.score;if(h){var l={score:f,value:a};n&&(l.indices=u.matchedIndices),r.push({item:a,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 A=_[O],P=A.$,I=A.idx;if(p(P)){var C=t.searchIn(A),L=C.isMatch,F=C.score;if(L){var N={score:F,key:w,value:P,idx:I};n&&(N.indices=C.matchedIndices),k.push(N)}}}else{var E=_.$,$=t.searchIn(_),z=$.isMatch,D=$.score;if(!z)continue;var T={score:D,key:w,value:E};n&&(T.indices=$.matchedIndices),k.push(T)}}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,s=1,a=0;a<o;a+=1){var c=i[a],u=c.key,h=this._keyStore.get(u,"weight"),f=h>-1?h:1,l=0===c.score&&h>-1?Number.EPSILON:c.score;s*=Math.pow(l,f)}n.score=s}}},{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 s=0,a=t.length;s<a;s+=1){var c=t[s],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}}])&&a(e.prototype,r),n&&a(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 s=o.location,a=void 0===s?0:s,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(a,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=[],A=1,P=m+b,I=1<<(m<=31?m-1:30),C=0;C<m;C+=1){for(var L=0,F=P;L<F;){n(e,{errors:C,currentLocation:x+F,expectedLocation:x,distance:u})<=S?L=F:P=F,F=Math.floor((P-L)/2+L)}P=F;var N=Math.max(1,x-F+1),E=v?b:Math.min(x+F,b)+m,$=Array(E+2);$[E+1]=(1<<C)-1;for(var z=E;z>=N;z-=1){var D=z-1,T=r[t.charAt(D)];if(T&&(M[D]=1),$[z]=($[z+1]<<1|1)&T,0!==C&&($[z]|=(j[z+1]|j[z])<<1|1|j[z+1]),$[z]&I&&(A=n(e,{errors:C,currentLocation:D,expectedLocation:x,distance:u}))<=S){if(S=A,(k=D)<=x)break;N=Math.max(1,2*x-k)}}if(n(e,{errors:C+1,currentLocation:x,expectedLocation:x,distance:u})>S)break;j=$}var B={isMatch:k>=0,score:A||.001};return g&&(B.matchedIndices=i(M,d)),B}},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,s=e.expectedLocation,a=void 0===s?0:s,c=e.distance,u=void 0===c?100:c,h=n/t.length,f=Math.abs(a-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,s=t.length;o<s;o+=1){var a=t[o];a&&-1===n?n=o:a||-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),s=r(14),a=r(15),c=r(16),u=r(17),h=r(1),f=r(0).isString,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.query=null,this.options=r,this._fuzzyCache={},f(e)&&e.trim().length>0&&(this.pattern=n?e:e.toLowerCase(),this.query=function(t){return t.split("|").map((function(t){return t.trim().split(/ +/g)}))}(this.pattern))}var e,r,l;return e=t,(r=[{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,o=e.length;i<o;i+=1){var s=e[i],a=null;n=!0;for(var c=0,u=s.length;c<u;c+=1){var h=s[c];if(!(a=this._search(h,r)).isMatch){n=!1;break}}if(n)return a}return{isMatch:!1,score:1}}},{key:"_search",value:function(t,e){if(i.isForPattern(t))return i.match(t,e);if(s.isForPattern(t))return s.match(t,e);if(a.isForPattern(t))return a.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.searchInString(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,r){function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}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(3),s=r(19).jaccardDistance,a=function(){function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{threshold:.6};n(this,t),this.options=r,this.patternNgram=o(e,{sort:!0})}var e,r,a;return e=t,(r=[{key:"searchIn",value:function(t){var e=t.ng;e||(e=o(t.$,{sort:!0}),t.ng=e);var r=s(this.patternNgram,e),n=r<this.options.threshold;return{score:n?r:1,isMatch:n}}}])&&i(e.prototype,r),a&&i(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],s=e[i];o<s?(r.push(o),n+=1):s<o?(r.push(s),i+=1):(r.push(s),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],s=e[i];o==s?(r.push(o),n+=1,i+=1):o<s?n+=1:(o>s||(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,s=n.isString,a=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?a:n,h=r.ngrams,f=void 0!==h&&h,l=[];if(s(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(),A=j.arrayIndex,P=j.value;if(o(P))if(s(P)){var I={$:P,idx:A};f&&(I.ng=c(P,{sort:!0})),_.push(I)}else if(i(P))for(var C=0,L=P.length;C<L;C+=1)O.push({arrayIndex:C,value:P[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,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,s=0;s<this._length;s+=1){var a=e[s];if(!a.hasOwnProperty("name"))throw new Error('Missing "name" property in key object');var c=a.name;if(this._keyNames.push(c),!a.hasOwnProperty("weight"))throw new Error('Missing "weight" property in key object');var u=a.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}for(var h=0;h<this._length;h+=1){var f=this._keyNames[h],l=this._keys[f].weight;this._keys[f].weight=l/o}}}var e,r,o;return e=t,(r=[{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)}}])&&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,r){var n=r(0),i=(n.isArray,n.isDefined);n.isString,n.isNumber,n.isObject;t.exports=function(t,e){var r=t.matches;if(e.matches=[],i(r))for(var n=0,o=r.length;n<o;n+=1){var s=r[n];if(i(s.indices)&&0!==s.indices.length){var a={indices:s.indices,value:s.value};s.key&&(a.key=s.key),s.idx>-1&&(a.refIndex=s.idx),e.matches.push(a)}}}},function(t,e){t.exports=function(t,e){e.score=t.score}}])})); | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global = global || self, (global.Fuse = global.Fuse || {}, global.Fuse.js = factory())); | ||
}(this, (function () { 'use strict'; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
} | ||
return target; | ||
} | ||
function bitapScore(pattern, _ref) { | ||
var _ref$errors = _ref.errors, | ||
errors = _ref$errors === void 0 ? 0 : _ref$errors, | ||
_ref$currentLocation = _ref.currentLocation, | ||
currentLocation = _ref$currentLocation === void 0 ? 0 : _ref$currentLocation, | ||
_ref$expectedLocation = _ref.expectedLocation, | ||
expectedLocation = _ref$expectedLocation === void 0 ? 0 : _ref$expectedLocation, | ||
_ref$distance = _ref.distance, | ||
distance = _ref$distance === void 0 ? 100 : _ref$distance; | ||
var accuracy = errors / pattern.length; | ||
var proximity = Math.abs(expectedLocation - currentLocation); | ||
if (!distance) { | ||
// Dodge divide by zero error. | ||
return proximity ? 1.0 : accuracy; | ||
} | ||
return accuracy + proximity / distance; | ||
} | ||
function matchedIndiced() { | ||
var matchmask = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
var minMatchCharLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
var matchedIndices = []; | ||
var start = -1; | ||
var end = -1; | ||
var i = 0; | ||
for (var len = matchmask.length; i < len; i += 1) { | ||
var match = matchmask[i]; | ||
if (match && start === -1) { | ||
start = i; | ||
} else if (!match && start !== -1) { | ||
end = i - 1; | ||
if (end - start + 1 >= minMatchCharLength) { | ||
matchedIndices.push([start, end]); | ||
} | ||
start = -1; | ||
} | ||
} // (i-1 - start) + 1 => i - start | ||
if (matchmask[i - 1] && i - start >= minMatchCharLength) { | ||
matchedIndices.push([start, i - 1]); | ||
} | ||
return matchedIndices; | ||
} | ||
function bitapSearch(text, pattern, patternAlphabet, _ref) { | ||
var _ref$location = _ref.location, | ||
location = _ref$location === void 0 ? 0 : _ref$location, | ||
_ref$distance = _ref.distance, | ||
distance = _ref$distance === void 0 ? 100 : _ref$distance, | ||
_ref$threshold = _ref.threshold, | ||
threshold = _ref$threshold === void 0 ? 0.6 : _ref$threshold, | ||
_ref$findAllMatches = _ref.findAllMatches, | ||
findAllMatches = _ref$findAllMatches === void 0 ? false : _ref$findAllMatches, | ||
_ref$minMatchCharLeng = _ref.minMatchCharLength, | ||
minMatchCharLength = _ref$minMatchCharLeng === void 0 ? 1 : _ref$minMatchCharLeng, | ||
_ref$includeMatches = _ref.includeMatches, | ||
includeMatches = _ref$includeMatches === void 0 ? false : _ref$includeMatches; | ||
var patternLen = pattern.length; // Set starting location at beginning text and initialize the alphabet. | ||
var textLen = text.length; // Handle the case when location > text.length | ||
var expectedLocation = Math.max(0, Math.min(location, textLen)); // Highest score beyond which we give up. | ||
var currentThreshold = threshold; // Is there a nearby exact match? (speedup) | ||
var bestLocation = text.indexOf(pattern, expectedLocation); // a mask of the matches | ||
var matchMask = []; | ||
for (var i = 0; i < textLen; i += 1) { | ||
matchMask[i] = 0; | ||
} | ||
if (bestLocation !== -1) { | ||
var score = bitapScore(pattern, { | ||
errors: 0, | ||
currentLocation: bestLocation, | ||
expectedLocation: expectedLocation, | ||
distance: distance | ||
}); | ||
currentThreshold = Math.min(score, currentThreshold); // What about in the other direction? (speed up) | ||
bestLocation = text.lastIndexOf(pattern, expectedLocation + patternLen); | ||
if (bestLocation !== -1) { | ||
var _score = bitapScore(pattern, { | ||
errors: 0, | ||
currentLocation: bestLocation, | ||
expectedLocation: expectedLocation, | ||
distance: distance | ||
}); | ||
currentThreshold = Math.min(_score, currentThreshold); | ||
} | ||
} // Reset the best location | ||
bestLocation = -1; | ||
var lastBitArr = []; | ||
var finalScore = 1; | ||
var binMax = patternLen + textLen; | ||
var mask = 1 << (patternLen <= 31 ? patternLen - 1 : 30); | ||
for (var _i = 0; _i < patternLen; _i += 1) { | ||
// Scan for the best match; each iteration allows for one more error. | ||
// Run a binary search to determine how far from the match location we can stray | ||
// at this error level. | ||
var binMin = 0; | ||
var binMid = binMax; | ||
while (binMin < binMid) { | ||
var _score3 = bitapScore(pattern, { | ||
errors: _i, | ||
currentLocation: expectedLocation + binMid, | ||
expectedLocation: expectedLocation, | ||
distance: distance | ||
}); | ||
if (_score3 <= currentThreshold) { | ||
binMin = binMid; | ||
} else { | ||
binMax = binMid; | ||
} | ||
binMid = Math.floor((binMax - binMin) / 2 + binMin); | ||
} // Use the result from this iteration as the maximum for the next. | ||
binMax = binMid; | ||
var start = Math.max(1, expectedLocation - binMid + 1); | ||
var finish = findAllMatches ? textLen : Math.min(expectedLocation + binMid, textLen) + patternLen; // Initialize the bit array | ||
var bitArr = Array(finish + 2); | ||
bitArr[finish + 1] = (1 << _i) - 1; | ||
for (var j = finish; j >= start; j -= 1) { | ||
var currentLocation = j - 1; | ||
var charMatch = patternAlphabet[text.charAt(currentLocation)]; | ||
if (charMatch) { | ||
matchMask[currentLocation] = 1; | ||
} // First pass: exact match | ||
bitArr[j] = (bitArr[j + 1] << 1 | 1) & charMatch; // Subsequent passes: fuzzy match | ||
if (_i !== 0) { | ||
bitArr[j] |= (lastBitArr[j + 1] | lastBitArr[j]) << 1 | 1 | lastBitArr[j + 1]; | ||
} | ||
if (bitArr[j] & mask) { | ||
finalScore = bitapScore(pattern, { | ||
errors: _i, | ||
currentLocation: currentLocation, | ||
expectedLocation: expectedLocation, | ||
distance: distance | ||
}); // This match will almost certainly be better than any existing match. | ||
// But check anyway. | ||
if (finalScore <= currentThreshold) { | ||
// Indeed it is | ||
currentThreshold = finalScore; | ||
bestLocation = currentLocation; // Already passed `loc`, downhill from here on in. | ||
if (bestLocation <= expectedLocation) { | ||
break; | ||
} // When passing `bestLocation`, don't exceed our current distance from `expectedLocation`. | ||
start = Math.max(1, 2 * expectedLocation - bestLocation); | ||
} | ||
} | ||
} // No hope for a (better) match at greater error levels. | ||
var _score2 = bitapScore(pattern, { | ||
errors: _i + 1, | ||
currentLocation: expectedLocation, | ||
expectedLocation: expectedLocation, | ||
distance: distance | ||
}); | ||
if (_score2 > currentThreshold) { | ||
break; | ||
} | ||
lastBitArr = bitArr; | ||
} | ||
var result = { | ||
isMatch: bestLocation >= 0, | ||
// Count exact matches (those with a score of 0) to be "almost" exact | ||
score: !finalScore ? 0.001 : finalScore | ||
}; | ||
if (includeMatches) { | ||
result.matchedIndices = matchedIndiced(matchMask, minMatchCharLength); | ||
} | ||
return result; | ||
} | ||
function patternAlphabet(pattern) { | ||
var mask = {}; | ||
var len = pattern.length; | ||
for (var i = 0; i < len; i += 1) { | ||
mask[pattern.charAt(i)] = 0; | ||
} | ||
for (var _i = 0; _i < len; _i += 1) { | ||
mask[pattern.charAt(_i)] |= 1 << len - _i - 1; | ||
} | ||
return mask; | ||
} | ||
// Machine word size | ||
var MAX_BITS = 32; | ||
var BitapSearch = /*#__PURE__*/function () { | ||
function BitapSearch(pattern, _ref) { | ||
var _ref$location = _ref.location, | ||
location = _ref$location === void 0 ? 0 : _ref$location, | ||
_ref$distance = _ref.distance, | ||
distance = _ref$distance === void 0 ? 100 : _ref$distance, | ||
_ref$threshold = _ref.threshold, | ||
threshold = _ref$threshold === void 0 ? 0.6 : _ref$threshold, | ||
_ref$isCaseSensitive = _ref.isCaseSensitive, | ||
isCaseSensitive = _ref$isCaseSensitive === void 0 ? false : _ref$isCaseSensitive, | ||
_ref$findAllMatches = _ref.findAllMatches, | ||
findAllMatches = _ref$findAllMatches === void 0 ? false : _ref$findAllMatches, | ||
_ref$minMatchCharLeng = _ref.minMatchCharLength, | ||
minMatchCharLength = _ref$minMatchCharLeng === void 0 ? 1 : _ref$minMatchCharLeng, | ||
_ref$includeMatches = _ref.includeMatches, | ||
includeMatches = _ref$includeMatches === void 0 ? false : _ref$includeMatches; | ||
_classCallCheck(this, BitapSearch); | ||
this.options = { | ||
location: location, | ||
distance: distance, | ||
threshold: threshold, | ||
isCaseSensitive: isCaseSensitive, | ||
findAllMatches: findAllMatches, | ||
includeMatches: includeMatches, | ||
minMatchCharLength: minMatchCharLength | ||
}; | ||
if (pattern.length > MAX_BITS) { | ||
throw new Error("Pattern length exceeds max of ".concat(MAX_BITS, ".")); | ||
} | ||
this.pattern = isCaseSensitive ? pattern : pattern.toLowerCase(); | ||
this.patternAlphabet = patternAlphabet(this.pattern); | ||
} | ||
_createClass(BitapSearch, [{ | ||
key: "searchIn", | ||
value: function searchIn(value) { | ||
var text = value.$; | ||
return this.searchInString(text); | ||
} | ||
}, { | ||
key: "searchInString", | ||
value: function searchInString(text) { | ||
var _this$options = this.options, | ||
isCaseSensitive = _this$options.isCaseSensitive, | ||
includeMatches = _this$options.includeMatches; | ||
if (!isCaseSensitive) { | ||
text = text.toLowerCase(); | ||
} // Exact match | ||
if (this.pattern === text) { | ||
var result = { | ||
isMatch: true, | ||
score: 0 | ||
}; | ||
if (includeMatches) { | ||
result.matchedIndices = [[0, text.length - 1]]; | ||
} | ||
return result; | ||
} // Otherwise, use Bitap algorithm | ||
var _this$options2 = this.options, | ||
location = _this$options2.location, | ||
distance = _this$options2.distance, | ||
threshold = _this$options2.threshold, | ||
findAllMatches = _this$options2.findAllMatches, | ||
minMatchCharLength = _this$options2.minMatchCharLength; | ||
return bitapSearch(text, this.pattern, this.patternAlphabet, { | ||
location: location, | ||
distance: distance, | ||
threshold: threshold, | ||
findAllMatches: findAllMatches, | ||
minMatchCharLength: minMatchCharLength, | ||
includeMatches: includeMatches | ||
}); | ||
} | ||
}]); | ||
return BitapSearch; | ||
}(); | ||
// Token: 'file | ||
// Match type: exact-match | ||
// Description: Items that include `file` | ||
var isForPattern = function isForPattern(pattern) { | ||
return pattern.charAt(0) == "'"; | ||
}; | ||
var sanitize = function sanitize(pattern) { | ||
return pattern.substr(1); | ||
}; | ||
var match = function match(pattern, text) { | ||
var sanitizedPattern = sanitize(pattern); | ||
var index = text.indexOf(sanitizedPattern); | ||
var isMatch = index > -1; | ||
return { | ||
isMatch: isMatch, | ||
score: 0 | ||
}; | ||
}; | ||
var exactMatch = { | ||
isForPattern: isForPattern, | ||
sanitize: sanitize, | ||
match: match | ||
}; | ||
// Token: !fire | ||
// Match type: inverse-exact-match | ||
// Description: Items that do not include `fire` | ||
var isForPattern$1 = function isForPattern(pattern) { | ||
return pattern.charAt(0) == '!'; | ||
}; | ||
var sanitize$1 = function sanitize(pattern) { | ||
return pattern.substr(1); | ||
}; | ||
var match$1 = function match(pattern, text) { | ||
var sanitizedPattern = sanitize$1(pattern); | ||
var isMatch = text.indexOf(sanitizedPattern) === -1; | ||
return { | ||
isMatch: isMatch, | ||
score: 0 | ||
}; | ||
}; | ||
var inverseExactMatch = { | ||
isForPattern: isForPattern$1, | ||
sanitize: sanitize$1, | ||
match: match$1 | ||
}; | ||
// Token: ^file | ||
// Match type: prefix-exact-match | ||
// Description: Items that start with `file` | ||
var isForPattern$2 = function isForPattern(pattern) { | ||
return pattern.charAt(0) == '^'; | ||
}; | ||
var sanitize$2 = function sanitize(pattern) { | ||
return pattern.substr(1); | ||
}; | ||
var match$2 = function match(pattern, text) { | ||
var sanitizedPattern = sanitize$2(pattern); | ||
var isMatch = text.startsWith(sanitizedPattern); | ||
return { | ||
isMatch: isMatch, | ||
score: 0 | ||
}; | ||
}; | ||
var prefixExactMatch = { | ||
isForPattern: isForPattern$2, | ||
sanitize: sanitize$2, | ||
match: match$2 | ||
}; | ||
// Token: !^fire | ||
// Match type: inverse-prefix-exact-match | ||
// Description: Items that do not start with `fire` | ||
var isForPattern$3 = function isForPattern(pattern) { | ||
return pattern.charAt(0) == '!' && pattern.charAt(1) == '^'; | ||
}; | ||
var sanitize$3 = function sanitize(pattern) { | ||
return pattern.substr(2); | ||
}; | ||
var match$3 = function match(pattern, text) { | ||
var sanitizedPattern = sanitize$3(pattern); | ||
var isMatch = !text.startsWith(sanitizedPattern); | ||
return { | ||
isMatch: isMatch, | ||
score: 0 | ||
}; | ||
}; | ||
var inversePrefixExactMatch = { | ||
isForPattern: isForPattern$3, | ||
sanitize: sanitize$3, | ||
match: match$3 | ||
}; | ||
// Token: .file$ | ||
// Match type: suffix-exact-match | ||
// Description: Items that end with `.file` | ||
var isForPattern$4 = function isForPattern(pattern) { | ||
return pattern.charAt(pattern.length - 1) == '$'; | ||
}; | ||
var sanitize$4 = function sanitize(pattern) { | ||
return pattern.substr(0, pattern.length - 1); | ||
}; | ||
var match$4 = function match(pattern, text) { | ||
var sanitizedPattern = sanitize$4(pattern); | ||
var isMatch = text.endsWith(sanitizedPattern); | ||
return { | ||
isMatch: isMatch, | ||
score: 0 | ||
}; | ||
}; | ||
var suffixExactMatch = { | ||
isForPattern: isForPattern$4, | ||
sanitize: sanitize$4, | ||
match: match$4 | ||
}; | ||
// Token: !.file$ | ||
// Match type: inverse-suffix-exact-match | ||
// Description: Items that do not end with `.file` | ||
var isForPattern$5 = function isForPattern(pattern) { | ||
return pattern.charAt(0) == '!' && pattern.charAt(pattern.length - 1) == '$'; | ||
}; | ||
var sanitize$5 = function sanitize(pattern) { | ||
return pattern.substring(1, pattern.length - 1); | ||
}; | ||
var match$5 = function match(pattern, text) { | ||
var sanitizedPattern = sanitize$5(pattern); | ||
var isMatch = !text.endsWith(sanitizedPattern); | ||
return { | ||
isMatch: isMatch, | ||
score: 0 | ||
}; | ||
}; | ||
var inverseSuffixExactMatch = { | ||
isForPattern: isForPattern$5, | ||
sanitize: sanitize$5, | ||
match: match$5 | ||
}; | ||
var INFINITY = 1 / 0; | ||
var isArray = function isArray(value) { | ||
return !Array.isArray ? Object.prototype.toString.call(value) === '[object Array]' : Array.isArray(value); | ||
}; // Adapted from: | ||
// https://github.com/lodash/lodash/blob/f4ca396a796435422bd4fd41fadbd225edddf175/.internal/baseToString.js | ||
var baseToString = function baseToString(value) { | ||
// Exit early for strings to avoid a performance hit in some environments. | ||
if (typeof value == 'string') { | ||
return value; | ||
} | ||
var result = value + ''; | ||
return result == '0' && 1 / value == -INFINITY ? '-0' : result; | ||
}; | ||
var toString = function toString(value) { | ||
return value == null ? '' : baseToString(value); | ||
}; | ||
var isString = function isString(value) { | ||
return typeof value === 'string'; | ||
}; | ||
var isNumber = function isNumber(value) { | ||
return typeof value === 'number'; | ||
}; | ||
var isDefined = function isDefined(value) { | ||
return value !== undefined && value !== null; | ||
}; | ||
// Example: | ||
// "^core go$ | rb$ | py$ xy$" => [["^core", "go$"], ["rb$"], ["py$", "xy$"]] | ||
var queryfy = function queryfy(pattern) { | ||
return pattern.split('|').map(function (item) { | ||
return item.trim().split(/ +/g); | ||
}); | ||
}; | ||
/** | ||
* Command-like searching | ||
* ====================== | ||
* | ||
* Given multiple search terms delimited by spaces.e.g. `^jscript .python$ ruby !java`, | ||
* search in a given text. | ||
* | ||
* Search syntax: | ||
* | ||
* | Token | Match type | Description | | ||
* | ----------- | -------------------------- | -------------------------------------- | | ||
* | `jscript` | fuzzy-match | Items that match `jscript` | | ||
* | `'python` | exact-match | Items that include `python` | | ||
* | `!ruby` | inverse-exact-match | Items that do not include `ruby` | | ||
* | `^java` | prefix-exact-match | Items that start with `java` | | ||
* | `!^earlang` | inverse-prefix-exact-match | Items that do not start with `earlang` | | ||
* | `.js$` | suffix-exact-match | Items that end with `.js` | | ||
* | `!.go$` | inverse-suffix-exact-match | Items that do not end with `.go` | | ||
* | ||
* A single pipe character acts as an OR operator. For example, the following | ||
* query matches entries that start with `core` and end with either`go`, `rb`, | ||
* or`py`. | ||
* | ||
* ``` | ||
* ^core go$ | rb$ | py$ | ||
* ``` | ||
*/ | ||
var ExtendedSearch = /*#__PURE__*/function () { | ||
function ExtendedSearch(pattern, options) { | ||
_classCallCheck(this, ExtendedSearch); | ||
var isCaseSensitive = options.isCaseSensitive; | ||
this.query = null; | ||
this.options = options; // A <pattern>:<BitapSearch> key-value pair for optimizing searching | ||
this._fuzzyCache = {}; | ||
if (isString(pattern) && pattern.trim().length > 0) { | ||
this.pattern = isCaseSensitive ? pattern : pattern.toLowerCase(); | ||
this.query = queryfy(this.pattern); | ||
} | ||
} | ||
_createClass(ExtendedSearch, [{ | ||
key: "searchIn", | ||
value: function searchIn(value) { | ||
var query = this.query; | ||
if (!this.query) { | ||
return { | ||
isMatch: false, | ||
score: 1 | ||
}; | ||
} | ||
var text = value.$; | ||
text = this.options.isCaseSensitive ? text : text.toLowerCase(); | ||
var matchFound = false; | ||
for (var i = 0, qLen = query.length; i < qLen; i += 1) { | ||
var parts = query[i]; | ||
var result = null; | ||
matchFound = true; | ||
for (var j = 0, pLen = parts.length; j < pLen; j += 1) { | ||
var token = parts[j]; | ||
result = this._search(token, text); | ||
if (!result.isMatch) { | ||
// AND condition, short-circuit and move on to next part | ||
matchFound = false; | ||
break; | ||
} | ||
} // OR condition, so if TRUE, return | ||
if (matchFound) { | ||
return result; | ||
} | ||
} // Nothing was matched | ||
return { | ||
isMatch: false, | ||
score: 1 | ||
}; | ||
} | ||
}, { | ||
key: "_search", | ||
value: function _search(pattern, text) { | ||
if (exactMatch.isForPattern(pattern)) { | ||
return exactMatch.match(pattern, text); | ||
} else if (prefixExactMatch.isForPattern(pattern)) { | ||
return prefixExactMatch.match(pattern, text); | ||
} else if (inversePrefixExactMatch.isForPattern(pattern)) { | ||
return inversePrefixExactMatch.match(pattern, text); | ||
} else if (inverseSuffixExactMatch.isForPattern(pattern)) { | ||
return inverseSuffixExactMatch.match(pattern, text); | ||
} else if (suffixExactMatch.isForPattern(pattern)) { | ||
return suffixExactMatch.match(pattern, text); | ||
} else if (inverseExactMatch.isForPattern(pattern)) { | ||
return inverseExactMatch.match(pattern, text); | ||
} else { | ||
var searcher = this._fuzzyCache[pattern]; | ||
if (!searcher) { | ||
searcher = new BitapSearch(pattern, this.options); | ||
this._fuzzyCache[pattern] = searcher; | ||
} | ||
return searcher.searchInString(text); | ||
} | ||
} | ||
}]); | ||
return ExtendedSearch; | ||
}(); | ||
var NGRAM_LEN = 3; | ||
function ngram(text, _ref) { | ||
var _ref$n = _ref.n, | ||
n = _ref$n === void 0 ? NGRAM_LEN : _ref$n, | ||
_ref$pad = _ref.pad, | ||
pad = _ref$pad === void 0 ? true : _ref$pad, | ||
_ref$sort = _ref.sort, | ||
sort = _ref$sort === void 0 ? false : _ref$sort; | ||
var nGrams = []; | ||
if (text === null || text === undefined) { | ||
return nGrams; | ||
} | ||
text = text.toLowerCase(); | ||
if (pad) { | ||
text = " ".concat(text, " "); | ||
} | ||
var index = text.length - n + 1; | ||
if (index < 1) { | ||
return nGrams; | ||
} | ||
while (index--) { | ||
nGrams[index] = text.substr(index, n); | ||
} | ||
if (sort) { | ||
nGrams.sort(function (a, b) { | ||
return a == b ? 0 : a < b ? -1 : 1; | ||
}); | ||
} | ||
return nGrams; | ||
} | ||
// Assumes arrays are sorted | ||
function union (arr1, arr2) { | ||
var result = []; | ||
var i = 0; | ||
var j = 0; | ||
while (i < arr1.length && j < arr2.length) { | ||
var item1 = arr1[i]; | ||
var item2 = arr2[j]; | ||
if (item1 < item2) { | ||
result.push(item1); | ||
i += 1; | ||
} else if (item2 < item1) { | ||
result.push(item2); | ||
j += 1; | ||
} else { | ||
result.push(item2); | ||
i += 1; | ||
j += 1; | ||
} | ||
} | ||
while (i < arr1.length) { | ||
result.push(arr1[i]); | ||
i += 1; | ||
} | ||
while (j < arr2.length) { | ||
result.push(arr2[j]); | ||
j += 1; | ||
} | ||
return result; | ||
} | ||
// Assumes arrays are sorted | ||
function intersection(arr1, arr2) { | ||
var result = []; | ||
var i = 0; | ||
var j = 0; | ||
while (i < arr1.length && j < arr2.length) { | ||
var item1 = arr1[i]; | ||
var item2 = arr2[j]; | ||
if (item1 == item2) { | ||
result.push(item1); | ||
i += 1; | ||
j += 1; | ||
} else if (item1 < item2) { | ||
i += 1; | ||
} else if (item1 > item2) { | ||
j += 1; | ||
} else { | ||
i += 1; | ||
j += 1; | ||
} | ||
} | ||
return result; | ||
} | ||
function jaccardDistance(nGram1, nGram2) { | ||
var nGramUnion = union(nGram1, nGram2); | ||
var nGramIntersection = intersection(nGram1, nGram2); | ||
return 1 - nGramIntersection.length / nGramUnion.length; | ||
} | ||
var NGramSearch = /*#__PURE__*/function () { | ||
function NGramSearch(pattern) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { | ||
threshold: 0.6 | ||
}; | ||
_classCallCheck(this, NGramSearch); | ||
// Create the ngram, and sort it | ||
this.options = options; | ||
this.patternNgram = ngram(pattern, { | ||
sort: true | ||
}); | ||
} | ||
_createClass(NGramSearch, [{ | ||
key: "searchIn", | ||
value: function searchIn(value) { | ||
var textNgram = value.ng; | ||
if (!textNgram) { | ||
textNgram = ngram(value.$, { | ||
sort: true | ||
}); | ||
value.ng = textNgram; | ||
} | ||
var jacardResult = jaccardDistance(this.patternNgram, textNgram); | ||
var isMatch = jacardResult < this.options.threshold; | ||
return { | ||
score: isMatch ? jacardResult : 1, | ||
isMatch: isMatch | ||
}; | ||
} | ||
}]); | ||
return NGramSearch; | ||
}(); | ||
function get(obj, path) { | ||
var list = []; | ||
var arr = false; | ||
var _get = function _get(obj, path) { | ||
if (!path) { | ||
// If there's no path left, we've gotten to the object we care about. | ||
list.push(obj); | ||
} else { | ||
var dotIndex = path.indexOf('.'); | ||
var key = path; | ||
var remaining = null; | ||
if (dotIndex !== -1) { | ||
key = path.slice(0, dotIndex); | ||
remaining = path.slice(dotIndex + 1); | ||
} | ||
var value = obj[key]; | ||
if (isDefined(value)) { | ||
if (!remaining && (isString(value) || isNumber(value))) { | ||
list.push(toString(value)); | ||
} else if (isArray(value)) { | ||
arr = true; // Search each item in the array. | ||
for (var i = 0, len = value.length; i < len; i += 1) { | ||
_get(value[i], remaining); | ||
} | ||
} else if (remaining) { | ||
// An object. Recurse further. | ||
_get(value, remaining); | ||
} | ||
} | ||
} | ||
}; | ||
_get(obj, path); | ||
if (arr) { | ||
return list; | ||
} | ||
return list[0]; | ||
} | ||
function createIndex(keys, list) { | ||
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, | ||
_ref$getFn = _ref.getFn, | ||
getFn = _ref$getFn === void 0 ? get : _ref$getFn, | ||
_ref$ngrams = _ref.ngrams, | ||
ngrams = _ref$ngrams === void 0 ? false : _ref$ngrams; | ||
var indexedList = []; // List is Array<String> | ||
if (isString(list[0])) { | ||
// Iterate over every string in the list | ||
for (var i = 0, len = list.length; i < len; i += 1) { | ||
var value = list[i]; | ||
if (isDefined(value)) { | ||
// if (!isCaseSensitive) { | ||
// value = value.toLowerCase() | ||
// } | ||
var record = { | ||
$: value, | ||
idx: i | ||
}; | ||
if (ngrams) { | ||
record.ng = ngram(value, { | ||
sort: true | ||
}); | ||
} | ||
indexedList.push(record); | ||
} | ||
} | ||
} else { | ||
// List is Array<Object> | ||
var keysLen = keys.length; | ||
for (var _i = 0, _len = list.length; _i < _len; _i += 1) { | ||
var item = list[_i]; | ||
var _record = { | ||
idx: _i, | ||
$: {} | ||
}; // Iterate over every key (i.e, path), and fetch the value at that key | ||
for (var j = 0; j < keysLen; j += 1) { | ||
var key = keys[j]; | ||
var _value = getFn(item, key); | ||
if (!isDefined(_value)) { | ||
continue; | ||
} | ||
if (isArray(_value)) { | ||
var subRecords = []; | ||
var stack = [{ | ||
arrayIndex: -1, | ||
value: _value | ||
}]; | ||
while (stack.length) { | ||
var _stack$pop = stack.pop(), | ||
arrayIndex = _stack$pop.arrayIndex, | ||
_value2 = _stack$pop.value; | ||
if (!isDefined(_value2)) { | ||
continue; | ||
} | ||
if (isString(_value2)) { | ||
// if (!isCaseSensitive) { | ||
// v = v.toLowerCase() | ||
// } | ||
var subRecord = { | ||
$: _value2, | ||
idx: arrayIndex | ||
}; | ||
if (ngrams) { | ||
subRecord.ng = ngram(_value2, { | ||
sort: true | ||
}); | ||
} | ||
subRecords.push(subRecord); | ||
} else if (isArray(_value2)) { | ||
for (var k = 0, arrLen = _value2.length; k < arrLen; k += 1) { | ||
stack.push({ | ||
arrayIndex: k, | ||
value: _value2[k] | ||
}); | ||
} | ||
} | ||
} | ||
_record.$[key] = subRecords; | ||
} else { | ||
// if (!isCaseSensitive) { | ||
// value = value.toLowerCase() | ||
// } | ||
var _subRecord = { | ||
$: _value | ||
}; | ||
if (ngrams) { | ||
_subRecord.ng = ngram(_value, { | ||
sort: true | ||
}); | ||
} | ||
_record.$[key] = _subRecord; | ||
} | ||
} | ||
indexedList.push(_record); | ||
} | ||
} | ||
return indexedList; | ||
} | ||
var KeyStore = /*#__PURE__*/function () { | ||
function KeyStore(keys) { | ||
_classCallCheck(this, KeyStore); | ||
this._keys = {}; | ||
this._keyNames = []; | ||
this._length = keys.length; // Iterate over every key | ||
if (keys.length && isString(keys[0])) { | ||
for (var i = 0; i < this._length; i += 1) { | ||
var key = keys[i]; | ||
this._keys[key] = { | ||
weight: 1 | ||
}; | ||
this._keyNames.push(key); | ||
} | ||
} else { | ||
var totalWeight = 0; | ||
for (var _i = 0; _i < this._length; _i += 1) { | ||
var _key = keys[_i]; | ||
if (!_key.hasOwnProperty('name')) { | ||
throw new Error('Missing "name" property in key object'); | ||
} | ||
var keyName = _key.name; | ||
this._keyNames.push(keyName); | ||
if (!_key.hasOwnProperty('weight')) { | ||
throw new Error('Missing "weight" property in key object'); | ||
} | ||
var weight = _key.weight; | ||
if (weight <= 0 || weight >= 1) { | ||
throw new Error('"weight" property in key must bein the range of (0, 1)'); | ||
} | ||
this._keys[keyName] = { | ||
weight: weight | ||
}; | ||
totalWeight += weight; | ||
} // Normalize weights so that their sum is equal to 1 | ||
for (var _i2 = 0; _i2 < this._length; _i2 += 1) { | ||
var _keyName = this._keyNames[_i2]; | ||
var keyWeight = this._keys[_keyName].weight; | ||
this._keys[_keyName].weight = keyWeight / totalWeight; | ||
} | ||
} | ||
} | ||
_createClass(KeyStore, [{ | ||
key: "get", | ||
value: function get(key, name) { | ||
return this._keys[key] ? this._keys[key][name] : -1; | ||
} | ||
}, { | ||
key: "keys", | ||
value: function keys() { | ||
return this._keyNames; | ||
} | ||
}, { | ||
key: "count", | ||
value: function count() { | ||
return this._length; | ||
} | ||
}, { | ||
key: "toJSON", | ||
value: function toJSON() { | ||
return JSON.stringify(this._keys); | ||
} | ||
}]); | ||
return KeyStore; | ||
}(); | ||
function transformMatches(result, data) { | ||
var matches = result.matches; | ||
data.matches = []; | ||
if (!isDefined(matches)) { | ||
return; | ||
} | ||
for (var i = 0, len = matches.length; i < len; i += 1) { | ||
var match = matches[i]; | ||
if (!isDefined(match.indices) || match.indices.length === 0) { | ||
continue; | ||
} | ||
var obj = { | ||
indices: match.indices, | ||
value: match.value | ||
}; | ||
if (match.key) { | ||
obj.key = match.key; | ||
} | ||
if (match.idx > -1) { | ||
obj.refIndex = match.idx; | ||
} | ||
data.matches.push(obj); | ||
} | ||
} | ||
function transformScore(result, data) { | ||
data.score = result.score; | ||
} | ||
var FuseOptions = { | ||
// When true, the algorithm continues searching to the end of the input even if a perfect | ||
// match is found before the end of the same input. | ||
isCaseSensitive: false, | ||
// Determines how close the match must be to the fuzzy location (specified above). | ||
// An exact letter match which is 'distance' characters away from the fuzzy location | ||
// would score as a complete mismatch. A distance of '0' requires the match be at | ||
// the exact location specified, a threshold of '1000' would require a perfect match | ||
// to be within 800 characters of the fuzzy location to be found using a 0.8 threshold. | ||
distance: 100, | ||
// Minimum number of characters that must be matched before a result is considered a match | ||
findAllMatches: false, | ||
// The get function to use when fetching an object's properties. | ||
// The default will search nested paths *ie foo.bar.baz* | ||
getFn: get, | ||
includeMatches: false, | ||
includeScore: false, | ||
// List of properties that will be searched. This also supports nested properties. | ||
keys: [], | ||
// Approximately where in the text is the pattern expected to be found? | ||
location: 0, | ||
// Minimum number of characters that must be matched before a result is considered a match | ||
minMatchCharLength: 1, | ||
// Whether to sort the result list, by score | ||
shouldSort: true, | ||
// Default sort function | ||
sortFn: function sortFn(a, b) { | ||
return a.score - b.score; | ||
}, | ||
// At what point does the match algorithm give up. A threshold of '0.0' requires a perfect match | ||
// (of both letters and location), a threshold of '1.0' would match anything. | ||
threshold: 0.6, | ||
// Enabled extended-searching | ||
useExtendedSearch: false | ||
}; | ||
var Fuse = /*#__PURE__*/function () { | ||
function Fuse(list) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : FuseOptions; | ||
var index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; | ||
_classCallCheck(this, Fuse); | ||
this.options = _objectSpread2({}, FuseOptions, {}, options); // `caseSensitive` is deprecated, use `isCaseSensitive` instead | ||
this.options.isCaseSensitive = options.caseSensitive; | ||
delete this.options.caseSensitive; | ||
this._processKeys(this.options.keys); | ||
this.setCollection(list, index); | ||
} | ||
_createClass(Fuse, [{ | ||
key: "setCollection", | ||
value: function setCollection(list) { | ||
var index = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
this.list = list; | ||
this.listIsStringArray = isString(list[0]); | ||
if (index) { | ||
this.setIndex(index); | ||
} else { | ||
this.setIndex(this._createIndex()); | ||
} | ||
} | ||
}, { | ||
key: "setIndex", | ||
value: function setIndex(listIndex) { | ||
this._indexedList = listIndex; | ||
} | ||
}, { | ||
key: "_processKeys", | ||
value: function _processKeys(keys) { | ||
this._keyStore = new KeyStore(keys); | ||
} | ||
}, { | ||
key: "_createIndex", | ||
value: function _createIndex() { | ||
return createIndex(this._keyStore.keys(), this.list, { | ||
getFn: this.options.getFn | ||
}); | ||
} | ||
}, { | ||
key: "search", | ||
value: function search(pattern) { | ||
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { | ||
limit: false | ||
}; | ||
var _this$options = this.options, | ||
useExtendedSearch = _this$options.useExtendedSearch, | ||
shouldSort = _this$options.shouldSort; | ||
var searcher = null; | ||
if (useExtendedSearch) { | ||
searcher = new ExtendedSearch(pattern, this.options); | ||
} else if (pattern.length > MAX_BITS) { | ||
searcher = new NGramSearch(pattern, this.options); | ||
} else { | ||
searcher = new BitapSearch(pattern, this.options); | ||
} | ||
var results = this._searchUsing(searcher); | ||
this._computeScore(results); | ||
if (shouldSort) { | ||
this._sort(results); | ||
} | ||
if (opts.limit && isNumber(opts.limit)) { | ||
results = results.slice(0, opts.limit); | ||
} | ||
return this._format(results); | ||
} | ||
}, { | ||
key: "_searchUsing", | ||
value: function _searchUsing(searcher) { | ||
var list = this._indexedList; | ||
var results = []; | ||
var includeMatches = this.options.includeMatches; // List is Array<String> | ||
if (this.listIsStringArray) { | ||
// Iterate over every string in the list | ||
for (var i = 0, len = list.length; i < len; i += 1) { | ||
var value = list[i]; | ||
var text = value.$, | ||
idx = value.idx; | ||
if (!isDefined(text)) { | ||
continue; | ||
} | ||
var searchResult = searcher.searchIn(value); | ||
var isMatch = searchResult.isMatch, | ||
score = searchResult.score; | ||
if (!isMatch) { | ||
continue; | ||
} | ||
var match = { | ||
score: score, | ||
value: text | ||
}; | ||
if (includeMatches) { | ||
match.indices = searchResult.matchedIndices; | ||
} | ||
results.push({ | ||
item: text, | ||
idx: idx, | ||
matches: [match] | ||
}); | ||
} | ||
} else { | ||
// List is Array<Object> | ||
var keyNames = this._keyStore.keys(); | ||
var keysLen = this._keyStore.count(); | ||
for (var _i = 0, _len = list.length; _i < _len; _i += 1) { | ||
var _list$_i = list[_i], | ||
item = _list$_i.$, | ||
_idx = _list$_i.idx; | ||
if (!isDefined(item)) { | ||
continue; | ||
} | ||
var matches = []; // Iterate over every key (i.e, path), and fetch the value at that key | ||
for (var j = 0; j < keysLen; j += 1) { | ||
var key = keyNames[j]; | ||
var _value = item[key]; | ||
if (!isDefined(_value)) { | ||
continue; | ||
} | ||
if (isArray(_value)) { | ||
for (var k = 0, _len2 = _value.length; k < _len2; k += 1) { | ||
var arrItem = _value[k]; | ||
var _text = arrItem.$; | ||
var _idx2 = arrItem.idx; | ||
if (!isDefined(_text)) { | ||
continue; | ||
} | ||
var _searchResult = searcher.searchIn(arrItem); | ||
var _isMatch = _searchResult.isMatch, | ||
_score = _searchResult.score; | ||
if (!_isMatch) { | ||
continue; | ||
} | ||
var _match = { | ||
score: _score, | ||
key: key, | ||
value: _text, | ||
idx: _idx2 | ||
}; | ||
if (includeMatches) { | ||
_match.indices = _searchResult.matchedIndices; | ||
} | ||
matches.push(_match); | ||
} | ||
} else { | ||
var _text2 = _value.$; | ||
var _searchResult2 = searcher.searchIn(_value); | ||
var _isMatch2 = _searchResult2.isMatch, | ||
_score2 = _searchResult2.score; | ||
if (!_isMatch2) { | ||
continue; | ||
} | ||
var _match2 = { | ||
score: _score2, | ||
key: key, | ||
value: _text2 | ||
}; | ||
if (includeMatches) { | ||
_match2.indices = _searchResult2.matchedIndices; | ||
} | ||
matches.push(_match2); | ||
} | ||
} | ||
if (matches.length) { | ||
results.push({ | ||
idx: _idx, | ||
item: item, | ||
matches: matches | ||
}); | ||
} | ||
} | ||
} | ||
return results; | ||
} | ||
}, { | ||
key: "_computeScore", | ||
value: function _computeScore(results) { | ||
for (var i = 0, len = results.length; i < len; i += 1) { | ||
var result = results[i]; | ||
var matches = result.matches; | ||
var scoreLen = matches.length; | ||
var totalWeightedScore = 1; | ||
for (var j = 0; j < scoreLen; j += 1) { | ||
var item = matches[j]; | ||
var key = item.key; | ||
var keyWeight = this._keyStore.get(key, 'weight'); | ||
var weight = keyWeight > -1 ? keyWeight : 1; | ||
var score = item.score === 0 && keyWeight > -1 ? Number.EPSILON : item.score; | ||
totalWeightedScore *= Math.pow(score, weight); | ||
} | ||
result.score = totalWeightedScore; | ||
} | ||
} | ||
}, { | ||
key: "_sort", | ||
value: function _sort(results) { | ||
results.sort(this.options.sortFn); | ||
} | ||
}, { | ||
key: "_format", | ||
value: function _format(results) { | ||
var finalOutput = []; | ||
var _this$options2 = this.options, | ||
includeMatches = _this$options2.includeMatches, | ||
includeScore = _this$options2.includeScore; | ||
var transformers = []; | ||
if (includeMatches) { transformers.push(transformMatches); } | ||
if (includeScore) { transformers.push(transformScore); } | ||
for (var i = 0, len = results.length; i < len; i += 1) { | ||
var result = results[i]; | ||
var idx = result.idx; | ||
var data = { | ||
item: this.list[idx], | ||
refIndex: idx | ||
}; | ||
if (transformers.length) { | ||
for (var j = 0, _len3 = transformers.length; j < _len3; j += 1) { | ||
transformers[j](result, data); | ||
} | ||
} | ||
finalOutput.push(data); | ||
} | ||
return finalOutput; | ||
} | ||
}]); | ||
return Fuse; | ||
}(); | ||
Fuse.version = '5.0.8-beta'; | ||
Fuse.createIndex = createIndex; | ||
return Fuse; | ||
}))); |
{ | ||
"name": "fuse.js", | ||
"author": { | ||
"name": "Kirollos Risk", | ||
"name": "Kiro Risk", | ||
"email": "kirollos@gmail.com", | ||
"url": "http://kiro.me" | ||
}, | ||
"version": "5.0.7-beta", | ||
"main": "./dist/fuse.common.js", | ||
"module": "./dist/fuse.esm.js", | ||
"unpkg": "./dist/fuse.js", | ||
"jsdelivr": "./dist/fuse.js", | ||
"typings": "./dist/fuse.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"version": "5.0.8-beta", | ||
"description": "Lightweight fuzzy-search", | ||
@@ -21,11 +29,9 @@ "license": "Apache-2.0", | ||
], | ||
"main": "dist/fuse.js", | ||
"types": "dist/fuse.d.ts", | ||
"scripts": { | ||
"clean": "rimraf ./dist", | ||
"dev": "rollup -w -c scripts/configs.js --environment TARGET:umd-dev", | ||
"dev:cjs": "rollup -w -c scripts/configs.js --environment TARGET:commonjs", | ||
"dev:esm": "rollup -w -c scripts/configs.js --environment TARGET:esm", | ||
"build": "node scripts/build.main.js", | ||
"test": "jest", | ||
"prebuild": "npm run clean", | ||
"build": "webpack --config ./configs/webpack.output.js", | ||
"predev": "npm run clean", | ||
"dev": "webpack --progress --colors --watch --config ./configs/webpack.dev.js" | ||
"release": "bash scripts/release.sh" | ||
}, | ||
@@ -35,14 +41,20 @@ "devDependencies": { | ||
"@babel/core": "^7.3.4", | ||
"@babel/plugin-proposal-object-rest-spread": "7.9.0", | ||
"@babel/preset-env": "7.3.4", | ||
"@babel/preset-typescript": "^7.3.3", | ||
"@types/jest": "^24.0.11", | ||
"@babel/preset-typescript": "7.9.0", | ||
"@rollup/plugin-buble": "0.21.1", | ||
"@rollup/plugin-node-resolve": "7.1.1", | ||
"@rollup/plugin-replace": "2.3.1", | ||
"@types/jest": "25.1.4", | ||
"babel-loader": "^8.0.5", | ||
"copy-webpack-plugin": "5.1.1", | ||
"faker": "4.1.0", | ||
"jest": "25.1.0", | ||
"rimraf": "3.0.2", | ||
"rollup": "2.1.0", | ||
"rollup-plugin-babel": "4.4.0", | ||
"rollup-plugin-copy": "3.3.0", | ||
"terser-webpack-plugin": "2.3.5", | ||
"typescript": "3.8.3", | ||
"webpack": "4.42.0", | ||
"webpack-cli": "3.3.11", | ||
"webpack-merge": "4.2.2" | ||
"webpack-cli": "3.3.11" | ||
}, | ||
@@ -52,6 +64,3 @@ "engines": { | ||
}, | ||
"files": [ | ||
"dist/" | ||
], | ||
"dependencies": {} | ||
} |
@@ -14,8 +14,10 @@ <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> | ||
#### _What's new in v5 (beta)_ | ||
## Supporting Fuse.js | ||
- _Added ability to search patterns longer than 32 characters_ | ||
- _Added [enhanced searching](https://fusejs.io/#extended-search)_ | ||
- _Added [indexing](https://fusejs.io/#indexing) for increased performance over large lists_ | ||
Through contributions, donations, and sponsorship, you allow Fuse.js to thrive. Also, you will be recognized as a beacon of support to open-source developers. | ||
- [Become a backer or sponsor on **GitHub**.](https://github.com/sponsors/krisk) | ||
- [Become a backer or sponsor on **Patreon**.](https://patreon.com/fusejs) | ||
- [One-time donation via **PayPal**.](https://www.paypal.me/kirorisk) | ||
--- | ||
@@ -27,2 +29,6 @@ | ||
### Browser Compatibility | ||
Fuse.js supports all browsers that are ES5-compliant (IE8 and below are not supported). | ||
## Documentation | ||
@@ -37,14 +43,25 @@ | ||
```sh | ||
# latest | ||
$ npm install --save fuse.js | ||
``` | ||
## Contributing | ||
**Yarn** | ||
### Coding conventions | ||
```sh | ||
$ yarn add fuse.js | ||
``` | ||
Code should be run through [Standard Format](https://www.npmjs.com/package/standard-format). | ||
**CDN** | ||
### Testing | ||
Available on CDN via [jsDelivr](https://cdn.jsdelivr.net/npm/fuse.js/dist/). | ||
Before submitting a pull request, please add the relevant tests in the `test/` directory, and execute them via `npm test`. | ||
### Explanation of Different Builds | ||
In the [`dist/` directory of the NPM package](https://cdn.jsdelivr.net/npm/fuse.js/dist/) you will find many different builds of Fuse.js. Here's an [overview](dist/README.md) of the difference between them. | ||
## Issues | ||
This repository serves as [the main issue tracker](https://github.com/krisk/Fuse/issues). When creating issues, it's important to follow common guidelines to make them extra clear. Here is a few links to help you achieve that: | ||
- [GitHub Guides: Mastering Issues](https://guides.github.com/features/issues/) | ||
- [Wiredcraft: How We Write Github Issues](https://wiredcraft.com/blog/how-we-write-our-github-issues/) | ||
- [NYC Planning Digital: Writing Useful Github Issues](https://medium.com/nyc-planning-digital/writing-a-proper-github-issue-97427d62a20f) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10
3600
65
152264
20
1