From be05938e07adcf6e2a42ceee9b6ce10ad113f378 Mon Sep 17 00:00:00 2001 From: Kiro Risk <565580+krisk@users.noreply.github.com> Date: Wed, 17 Jun 2020 09:06:37 -0700 Subject: [PATCH] Build 6.2.0 --- dist/fuse.basic.common.js | 26 ++++++-------------------- dist/fuse.basic.esm.js | 27 ++++++++------------------- dist/fuse.basic.esm.min.js | 4 ++-- dist/fuse.basic.js | 26 ++++++-------------------- dist/fuse.basic.min.js | 4 ++-- dist/fuse.common.js | 26 ++++++-------------------- dist/fuse.d.ts | 2 +- dist/fuse.esm.js | 27 ++++++++------------------- dist/fuse.esm.min.js | 4 ++-- dist/fuse.js | 4 ++-- dist/fuse.min.js | 4 ++-- 11 files changed, 45 insertions(+), 109 deletions(-) diff --git a/dist/fuse.basic.common.js b/dist/fuse.basic.common.js index de937dd6c..7ffa57e72 100644 --- a/dist/fuse.basic.common.js +++ b/dist/fuse.basic.common.js @@ -1,5 +1,5 @@ /** - * Fuse.js v6.2.0-beta.1 - Lightweight fuzzy-search (http://fusejs.io) + * Fuse.js v6.2.0 - Lightweight fuzzy-search (http://fusejs.io) * * Copyright (c) 2020 Kiro Risk (http://kiro.me) * All Rights Reserved. Apache Software License 2.0 @@ -340,10 +340,7 @@ var AdvancedOptions = { // When `true`, the calculation for the relevance score (used for sorting) will // ignore the field-length norm. // More info: https://fusejs.io/concepts/scoring-theory.html#field-length-norm - ignoreFieldNorm: false, - // When `true`, if the search query is empty, return the whole list instead - // of an empty array. - matchEmptyQuery: false + ignoreFieldNorm: false }; var Config = _objectSpread2({}, BasicOptions, {}, MatchOptions, {}, FuzzyOptions, {}, AdvancedOptions); @@ -551,7 +548,8 @@ function createIndex(keys, docs) { var myIndex = new FuseIndex({ getFn: getFn }); - myIndex.setKeys(keys); + var keyStore = new KeyStore(keys); + myIndex.setKeys(keyStore.keys()); myIndex.setSources(docs); myIndex.create(); return myIndex; @@ -1183,19 +1181,7 @@ var Fuse = /*#__PURE__*/function () { includeScore = _this$options.includeScore, shouldSort = _this$options.shouldSort, sortFn = _this$options.sortFn, - ignoreFieldNorm = _this$options.ignoreFieldNorm, - matchEmptyQuery = _this$options.matchEmptyQuery; - - if (matchEmptyQuery && (!isDefined(query) || isBlank(query))) { - return this._docs.map(function (doc, idx) { - return { - item: doc, - score: 1, - refIndex: idx - }; - }); - } - + ignoreFieldNorm = _this$options.ignoreFieldNorm; var results = isString(query) ? isString(this._docs[0]) ? this._searchStringList(query) : this._searchObjectList(query) : this._searchLogical(query); computeScore$1(results, this._keyStore, { ignoreFieldNorm: ignoreFieldNorm @@ -1406,7 +1392,7 @@ function format(results, docs) { }); } -Fuse.version = '6.2.0-beta.1'; +Fuse.version = '6.2.0'; Fuse.createIndex = createIndex; Fuse.parseIndex = parseIndex; Fuse.config = Config; diff --git a/dist/fuse.basic.esm.js b/dist/fuse.basic.esm.js index 65764d613..25bee5817 100644 --- a/dist/fuse.basic.esm.js +++ b/dist/fuse.basic.esm.js @@ -1,5 +1,5 @@ /** - * Fuse.js v6.2.0-beta.1 - Lightweight fuzzy-search (http://fusejs.io) + * Fuse.js v6.2.0 - Lightweight fuzzy-search (http://fusejs.io) * * Copyright (c) 2020 Kiro Risk (http://kiro.me) * All Rights Reserved. Apache Software License 2.0 @@ -218,10 +218,7 @@ const AdvancedOptions = { // When `true`, the calculation for the relevance score (used for sorting) will // ignore the field-length norm. // More info: https://fusejs.io/concepts/scoring-theory.html#field-length-norm - ignoreFieldNorm: false, - // When `true`, if the search query is empty, return the whole list instead - // of an empty array. - matchEmptyQuery: false + ignoreFieldNorm: false }; var Config = { @@ -392,8 +389,9 @@ class FuseIndex { } function createIndex(keys, docs, { getFn = Config.getFn } = {}) { - let myIndex = new FuseIndex({ getFn }); - myIndex.setKeys(keys); + const myIndex = new FuseIndex({ getFn }); + const keyStore = new KeyStore(keys); + myIndex.setKeys(keyStore.keys()); myIndex.setSources(docs); myIndex.create(); return myIndex @@ -401,7 +399,7 @@ function createIndex(keys, docs, { getFn = Config.getFn } = {}) { function parseIndex(data, { getFn = Config.getFn } = {}) { const { keys, records } = data; - let myIndex = new FuseIndex({ getFn }); + const myIndex = new FuseIndex({ getFn }); myIndex.setKeys(keys); myIndex.setIndexRecords(records); return myIndex @@ -986,18 +984,9 @@ class Fuse { includeScore, shouldSort, sortFn, - ignoreFieldNorm, - matchEmptyQuery + ignoreFieldNorm } = this.options; - if (matchEmptyQuery && (!isDefined(query) || isBlank(query))) { - return this._docs.map((doc, idx) => ({ - item: doc, - score: 1, - refIndex: idx - })) - } - let results = isString(query) ? isString(this._docs[0]) ? this._searchStringList(query) @@ -1179,7 +1168,7 @@ function format( }) } -Fuse.version = '6.2.0-beta.1'; +Fuse.version = '6.2.0'; Fuse.createIndex = createIndex; Fuse.parseIndex = parseIndex; Fuse.config = Config; diff --git a/dist/fuse.basic.esm.min.js b/dist/fuse.basic.esm.min.js index 4c22cb61f..9a85f8b43 100644 --- a/dist/fuse.basic.esm.min.js +++ b/dist/fuse.basic.esm.min.js @@ -1,9 +1,9 @@ /** - * Fuse.js v6.2.0-beta.1 - Lightweight fuzzy-search (http://fusejs.io) + * Fuse.js v6.2.0 - 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 e(e){return Array.isArray?Array.isArray(e):"[object Array]"===Object.prototype.toString.call(e)}function t(e){return"string"==typeof e}function s(e){return"number"==typeof e}function n(e){return null!=e}function i(e){return!e.trim().length}const r=Object.prototype.hasOwnProperty;class o{constructor(e){this._keys={},this._keyNames=[];let s=0;e.forEach(e=>{let n,i=1;if(t(e))n=e;else{if(!r.call(e,"name"))throw new Error(`Missing ${"name"} property in key`);if(n=e.name,r.call(e,"weight")&&(i=e.weight,i<=0))throw new Error((e=>`Property 'weight' in key '${e}' must be a positive integer`)(n))}this._keyNames.push(n),this._keys[n]={weight:i},s+=i}),this._keyNames.forEach(e=>{this._keys[e].weight/=s})}get(e,t){return this._keys[e]&&this._keys[e][t]}keys(){return this._keyNames}toJSON(){return JSON.stringify(this._keys)}}var c={isCaseSensitive:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(e,t)=>e.score===t.score?e.idx{if(r){const a=r.indexOf(".");let l=r,d=null;-1!==a&&(l=r.slice(0,a),d=r.slice(a+1));const u=i[l];if(!n(u))return;if(d||!t(u)&&!s(u))if(e(u)){c=!0;for(let e=0,t=u.length;e{this._addString(e,t)}):this.docs.forEach((e,t)=>{this._addObject(e,t)}),this.norm.clear())}add(e){const s=this.size();t(e)?this._addString(e,s):this._addObject(e,s)}removeAt(e){this.records.splice(e,1);for(let t=e,s=this.size();t{let h=this.getFn(s,r);if(n(h))if(e(h)){let s=[];const r=[{nestedArrIndex:-1,value:h}];for(;r.length;){const{nestedArrIndex:o,value:c}=r.pop();if(n(c))if(t(c)&&!i(c)){let e={v:c,i:o,n:this.norm.get(c)};s.push(e)}else e(c)&&c.forEach((e,t)=>{r.push({nestedArrIndex:t,value:e})})}o.$[c]=s}else if(!i(h)){let e={v:h,n:this.norm.get(h)};o.$[c]=e}}),this.records.push(o)}toJSON(){return{keys:this.keys,records:this.records}}}function l(e,t,{getFn:s=c.getFn}={}){let n=new a({getFn:s});return n.setKeys(e),n.setSources(t),n.create(),n}function d(e,t){const s=e.matches;t.matches=[],n(s)&&s.forEach(e=>{if(!n(e.indices)||!e.indices.length)return;const{indices:s,value:i}=e;let r={indices:s,value:i};e.key&&(r.key=e.key),e.idx>-1&&(r.refIndex=e.idx),t.matches.push(r)})}function u(e,t){t.score=e.score}function f(e,{errors:t=0,currentLocation:s=0,expectedLocation:n=0,distance:i=c.distance,ignoreLocation:r=c.ignoreLocation}={}){const o=t/e.length;if(r)return o;const h=Math.abs(n-s);return i?o+h/i:h?1:o}function g(e,t,s,{location:n=c.location,distance:i=c.distance,threshold:r=c.threshold,findAllMatches:o=c.findAllMatches,minMatchCharLength:h=c.minMatchCharLength,includeMatches:a=c.includeMatches,ignoreLocation:l=c.ignoreLocation}={}){if(t.length>32)throw new Error(`Pattern length exceeds max of ${32}.`);const d=t.length,u=e.length,g=Math.max(0,Math.min(n,u));let p=r,m=g;const y=h>1||a,M=y?Array(u):[];let x;for(;(x=e.indexOf(t,m))>-1;){let e=f(t,{currentLocation:x,expectedLocation:g,distance:i,ignoreLocation:l});if(p=Math.min(e,p),m=x+d,y){let e=0;for(;e=h;r-=1){let o=r-1,c=s[e.charAt(o)];if(y&&(M[o]=+!!c),x[r]=(x[r+1]<<1|1)&c,n&&(x[r]|=(L[r+1]|L[r])<<1|1|L[r+1]),x[r]&v&&(_=f(t,{errors:n,currentLocation:o,expectedLocation:g,distance:i,ignoreLocation:l}),_<=p)){if(p=_,m=o,m<=g)break;h=Math.max(1,2*g-m)}}if(f(t,{errors:n+1,currentLocation:g,expectedLocation:g,distance:i,ignoreLocation:l})>p)break;L=x}const S={isMatch:m>=0,score:Math.max(.001,_)};if(y){const e=function(e=[],t=c.minMatchCharLength){let s=[],n=-1,i=-1,r=0;for(let o=e.length;r=t&&s.push([n,i]),n=-1)}return e[r-1]&&r-n>=t&&s.push([n,r-1]),s}(M,h);e.length?a&&(S.indices=e):S.isMatch=!1}return S}function p(e){let t={};for(let s=0,n=e.length;s{this.chunks.push({pattern:e,alphabet:p(e),startIndex:t})},d=this.pattern.length;if(d>32){let e=0;const t=d%32,s=d-t;for(;e{const{isMatch:p,score:m,indices:y}=g(e,t,u,{location:n+f,distance:i,threshold:r,findAllMatches:o,minMatchCharLength:c,includeMatches:s,ignoreLocation:h});p&&(d=!0),l+=m,p&&y&&(a=[...a,...y])});let u={isMatch:d,score:d?l/this.chunks.length:1};return d&&s&&(u.indices=a),u}}const y=[];function M(e,t){for(let s=0,n=y.length;s!1)){const t=[];for(let s=0,n=this._docs.length;s({item:e,score:1,refIndex:t}));let p=t(e)?t(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return function(e,t,{ignoreFieldNorm:s=c.ignoreFieldNorm}){e.forEach(e=>{let n=1;e.matches.forEach(({key:e,norm:i,score:r})=>{const o=t.get(e,"weight");n*=Math.pow(0===r&&o?Number.EPSILON:r,(o||1)*(s?1:i))}),e.score=n})}(p,this._keyStore,{ignoreFieldNorm:f}),a&&p.sort(l),s(r)&&r>-1&&(p=p.slice(0,r)),function(e,t,{includeMatches:s=c.includeMatches,includeScore:n=c.includeScore}={}){const i=[];s&&i.push(d);n&&i.push(u);return e.map(e=>{const{idx:s}=e,n={item:t[s],refIndex:s};return i.length&&i.forEach(t=>{t(e,n)}),n})}(p,this._docs,{includeMatches:o,includeScore:h})}_searchStringList(e){const t=M(e,this.options),{records:s}=this._myIndex,i=[];return s.forEach(({v:e,i:s,n:r})=>{if(!n(e))return;const{isMatch:o,score:c,indices:h}=t.searchIn(e);o&&i.push({item:e,idx:s,matches:[{score:c,value:e,norm:r,indices:h}]})}),i}_searchLogical(e){throw new Error("Logical search is not available")}_searchObjectList(e){const t=M(e,this.options),{keys:s,records:i}=this._myIndex,r=[];return i.forEach(({$:e,i:i})=>{if(!n(e))return;let o=[];s.forEach((s,n)=>{o.push(...this._findMatches({key:s,value:e[n],searcher:t}))}),o.length&&r.push({idx:i,item:e,matches:o})}),r}_findMatches({key:t,value:s,searcher:i}){if(!n(s))return[];let r=[];if(e(s))s.forEach(({v:e,i:s,n:o})=>{if(!n(e))return;const{isMatch:c,score:h,indices:a}=i.searchIn(e);c&&r.push({score:h,key:t,value:e,idx:s,norm:o,indices:a})});else{const{v:e,n:n}=s,{isMatch:o,score:c,indices:h}=i.searchIn(e);o&&r.push({score:c,key:t,value:e,norm:n,indices:h})}return r}}x.version="6.2.0-beta.1",x.createIndex=l,x.parseIndex=function(e,{getFn:t=c.getFn}={}){const{keys:s,records:n}=e;let i=new a({getFn:t});return i.setKeys(s),i.setIndexRecords(n),i},x.config=c;export default x; \ No newline at end of file +function e(e){return Array.isArray?Array.isArray(e):"[object Array]"===Object.prototype.toString.call(e)}function t(e){return"string"==typeof e}function s(e){return"number"==typeof e}function n(e){return null!=e}function i(e){return!e.trim().length}const r=Object.prototype.hasOwnProperty;class o{constructor(e){this._keys={},this._keyNames=[];let s=0;e.forEach(e=>{let n,i=1;if(t(e))n=e;else{if(!r.call(e,"name"))throw new Error(`Missing ${"name"} property in key`);if(n=e.name,r.call(e,"weight")&&(i=e.weight,i<=0))throw new Error((e=>`Property 'weight' in key '${e}' must be a positive integer`)(n))}this._keyNames.push(n),this._keys[n]={weight:i},s+=i}),this._keyNames.forEach(e=>{this._keys[e].weight/=s})}get(e,t){return this._keys[e]&&this._keys[e][t]}keys(){return this._keyNames}toJSON(){return JSON.stringify(this._keys)}}var c={isCaseSensitive:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(e,t)=>e.score===t.score?e.idx{if(r){const a=r.indexOf(".");let l=r,d=null;-1!==a&&(l=r.slice(0,a),d=r.slice(a+1));const u=i[l];if(!n(u))return;if(d||!t(u)&&!s(u))if(e(u)){c=!0;for(let e=0,t=u.length;e{this._addString(e,t)}):this.docs.forEach((e,t)=>{this._addObject(e,t)}),this.norm.clear())}add(e){const s=this.size();t(e)?this._addString(e,s):this._addObject(e,s)}removeAt(e){this.records.splice(e,1);for(let t=e,s=this.size();t{let h=this.getFn(s,r);if(n(h))if(e(h)){let s=[];const r=[{nestedArrIndex:-1,value:h}];for(;r.length;){const{nestedArrIndex:o,value:c}=r.pop();if(n(c))if(t(c)&&!i(c)){let e={v:c,i:o,n:this.norm.get(c)};s.push(e)}else e(c)&&c.forEach((e,t)=>{r.push({nestedArrIndex:t,value:e})})}o.$[c]=s}else if(!i(h)){let e={v:h,n:this.norm.get(h)};o.$[c]=e}}),this.records.push(o)}toJSON(){return{keys:this.keys,records:this.records}}}function l(e,t,{getFn:s=c.getFn}={}){const n=new a({getFn:s}),i=new o(e);return n.setKeys(i.keys()),n.setSources(t),n.create(),n}function d(e,t){const s=e.matches;t.matches=[],n(s)&&s.forEach(e=>{if(!n(e.indices)||!e.indices.length)return;const{indices:s,value:i}=e;let r={indices:s,value:i};e.key&&(r.key=e.key),e.idx>-1&&(r.refIndex=e.idx),t.matches.push(r)})}function u(e,t){t.score=e.score}function f(e,{errors:t=0,currentLocation:s=0,expectedLocation:n=0,distance:i=c.distance,ignoreLocation:r=c.ignoreLocation}={}){const o=t/e.length;if(r)return o;const h=Math.abs(n-s);return i?o+h/i:h?1:o}function g(e,t,s,{location:n=c.location,distance:i=c.distance,threshold:r=c.threshold,findAllMatches:o=c.findAllMatches,minMatchCharLength:h=c.minMatchCharLength,includeMatches:a=c.includeMatches,ignoreLocation:l=c.ignoreLocation}={}){if(t.length>32)throw new Error(`Pattern length exceeds max of ${32}.`);const d=t.length,u=e.length,g=Math.max(0,Math.min(n,u));let p=r,m=g;const y=h>1||a,M=y?Array(u):[];let x;for(;(x=e.indexOf(t,m))>-1;){let e=f(t,{currentLocation:x,expectedLocation:g,distance:i,ignoreLocation:l});if(p=Math.min(e,p),m=x+d,y){let e=0;for(;e=h;r-=1){let o=r-1,c=s[e.charAt(o)];if(y&&(M[o]=+!!c),x[r]=(x[r+1]<<1|1)&c,n&&(x[r]|=(L[r+1]|L[r])<<1|1|L[r+1]),x[r]&v&&(_=f(t,{errors:n,currentLocation:o,expectedLocation:g,distance:i,ignoreLocation:l}),_<=p)){if(p=_,m=o,m<=g)break;h=Math.max(1,2*g-m)}}if(f(t,{errors:n+1,currentLocation:g,expectedLocation:g,distance:i,ignoreLocation:l})>p)break;L=x}const w={isMatch:m>=0,score:Math.max(.001,_)};if(y){const e=function(e=[],t=c.minMatchCharLength){let s=[],n=-1,i=-1,r=0;for(let o=e.length;r=t&&s.push([n,i]),n=-1)}return e[r-1]&&r-n>=t&&s.push([n,r-1]),s}(M,h);e.length?a&&(w.indices=e):w.isMatch=!1}return w}function p(e){let t={};for(let s=0,n=e.length;s{this.chunks.push({pattern:e,alphabet:p(e),startIndex:t})},d=this.pattern.length;if(d>32){let e=0;const t=d%32,s=d-t;for(;e{const{isMatch:p,score:m,indices:y}=g(e,t,u,{location:n+f,distance:i,threshold:r,findAllMatches:o,minMatchCharLength:c,includeMatches:s,ignoreLocation:h});p&&(d=!0),l+=m,p&&y&&(a=[...a,...y])});let u={isMatch:d,score:d?l/this.chunks.length:1};return d&&s&&(u.indices=a),u}}const y=[];function M(e,t){for(let s=0,n=y.length;s!1)){const t=[];for(let s=0,n=this._docs.length;s{let n=1;e.matches.forEach(({key:e,norm:i,score:r})=>{const o=t.get(e,"weight");n*=Math.pow(0===r&&o?Number.EPSILON:r,(o||1)*(s?1:i))}),e.score=n})}(l,this._keyStore,{ignoreFieldNorm:a}),o&&l.sort(h),s(n)&&n>-1&&(l=l.slice(0,n)),function(e,t,{includeMatches:s=c.includeMatches,includeScore:n=c.includeScore}={}){const i=[];s&&i.push(d);n&&i.push(u);return e.map(e=>{const{idx:s}=e,n={item:t[s],refIndex:s};return i.length&&i.forEach(t=>{t(e,n)}),n})}(l,this._docs,{includeMatches:i,includeScore:r})}_searchStringList(e){const t=M(e,this.options),{records:s}=this._myIndex,i=[];return s.forEach(({v:e,i:s,n:r})=>{if(!n(e))return;const{isMatch:o,score:c,indices:h}=t.searchIn(e);o&&i.push({item:e,idx:s,matches:[{score:c,value:e,norm:r,indices:h}]})}),i}_searchLogical(e){throw new Error("Logical search is not available")}_searchObjectList(e){const t=M(e,this.options),{keys:s,records:i}=this._myIndex,r=[];return i.forEach(({$:e,i:i})=>{if(!n(e))return;let o=[];s.forEach((s,n)=>{o.push(...this._findMatches({key:s,value:e[n],searcher:t}))}),o.length&&r.push({idx:i,item:e,matches:o})}),r}_findMatches({key:t,value:s,searcher:i}){if(!n(s))return[];let r=[];if(e(s))s.forEach(({v:e,i:s,n:o})=>{if(!n(e))return;const{isMatch:c,score:h,indices:a}=i.searchIn(e);c&&r.push({score:h,key:t,value:e,idx:s,norm:o,indices:a})});else{const{v:e,n:n}=s,{isMatch:o,score:c,indices:h}=i.searchIn(e);o&&r.push({score:c,key:t,value:e,norm:n,indices:h})}return r}}x.version="6.2.0",x.createIndex=l,x.parseIndex=function(e,{getFn:t=c.getFn}={}){const{keys:s,records:n}=e,i=new a({getFn:t});return i.setKeys(s),i.setIndexRecords(n),i},x.config=c;export default x; \ No newline at end of file diff --git a/dist/fuse.basic.js b/dist/fuse.basic.js index b79c17f65..ec780d982 100644 --- a/dist/fuse.basic.js +++ b/dist/fuse.basic.js @@ -1,5 +1,5 @@ /** - * Fuse.js v6.2.0-beta.1 - Lightweight fuzzy-search (http://fusejs.io) + * Fuse.js v6.2.0 - Lightweight fuzzy-search (http://fusejs.io) * * Copyright (c) 2020 Kiro Risk (http://kiro.me) * All Rights Reserved. Apache Software License 2.0 @@ -344,10 +344,7 @@ // When `true`, the calculation for the relevance score (used for sorting) will // ignore the field-length norm. // More info: https://fusejs.io/concepts/scoring-theory.html#field-length-norm - ignoreFieldNorm: false, - // When `true`, if the search query is empty, return the whole list instead - // of an empty array. - matchEmptyQuery: false + ignoreFieldNorm: false }; var Config = _objectSpread2({}, BasicOptions, {}, MatchOptions, {}, FuzzyOptions, {}, AdvancedOptions); @@ -555,7 +552,8 @@ var myIndex = new FuseIndex({ getFn: getFn }); - myIndex.setKeys(keys); + var keyStore = new KeyStore(keys); + myIndex.setKeys(keyStore.keys()); myIndex.setSources(docs); myIndex.create(); return myIndex; @@ -1187,19 +1185,7 @@ includeScore = _this$options.includeScore, shouldSort = _this$options.shouldSort, sortFn = _this$options.sortFn, - ignoreFieldNorm = _this$options.ignoreFieldNorm, - matchEmptyQuery = _this$options.matchEmptyQuery; - - if (matchEmptyQuery && (!isDefined(query) || isBlank(query))) { - return this._docs.map(function (doc, idx) { - return { - item: doc, - score: 1, - refIndex: idx - }; - }); - } - + ignoreFieldNorm = _this$options.ignoreFieldNorm; var results = isString(query) ? isString(this._docs[0]) ? this._searchStringList(query) : this._searchObjectList(query) : this._searchLogical(query); computeScore$1(results, this._keyStore, { ignoreFieldNorm: ignoreFieldNorm @@ -1410,7 +1396,7 @@ }); } - Fuse.version = '6.2.0-beta.1'; + Fuse.version = '6.2.0'; Fuse.createIndex = createIndex; Fuse.parseIndex = parseIndex; Fuse.config = Config; diff --git a/dist/fuse.basic.min.js b/dist/fuse.basic.min.js index fafff3ba0..a214e33ee 100644 --- a/dist/fuse.basic.min.js +++ b/dist/fuse.basic.min.js @@ -1,9 +1,9 @@ /** - * Fuse.js v6.2.0-beta.1 - Lightweight fuzzy-search (http://fusejs.io) + * Fuse.js v6.2.0 - 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 */ -var e,t;e=this,t=function(){"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function t(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,r=new Array(t);n0&&void 0!==arguments[0]?arguments[0]:3,t=new Map;return{get:function(n){var r=n.match(p).length;if(t.has(r))return t.get(r);var i=parseFloat((1/Math.sqrt(r)).toFixed(e));return t.set(r,i),i},clear:function(){t.clear()}}}var k=function(){function t(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=n.getFn,i=void 0===r?y.getFn:r;e(this,t),this.norm=m(3),this.getFn=i,this.isCreated=!1,this.setIndexRecords()}return n(t,[{key:"setSources",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.docs=e}},{key:"setIndexRecords",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.records=e}},{key:"setKeys",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.keys=e}},{key:"create",value:function(){var e=this;!this.isCreated&&this.docs.length&&(this.isCreated=!0,h(this.docs[0])?this.docs.forEach((function(t,n){e._addString(t,n)})):this.docs.forEach((function(t,n){e._addObject(t,n)})),this.norm.clear())}},{key:"add",value:function(e){var t=this.size();h(e)?this._addString(e,t):this._addObject(e,t)}},{key:"removeAt",value:function(e){this.records.splice(e,1);for(var t=e,n=this.size();t2&&void 0!==arguments[2]?arguments[2]:{},r=n.getFn,i=void 0===r?y.getFn:r,o=new k({getFn:i});return o.setKeys(e),o.setSources(t),o.create(),o}function M(e,t){var n=e.matches;t.matches=[],d(n)&&n.forEach((function(e){if(d(e.indices)&&e.indices.length){var n={indices:e.indices,value:e.value};e.key&&(n.key=e.key),e.idx>-1&&(n.refIndex=e.idx),t.matches.push(n)}}))}function x(e,t){t.score=e.score}function L(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.errors,r=void 0===n?0:n,i=t.currentLocation,o=void 0===i?0:i,a=t.expectedLocation,s=void 0===a?0:a,c=t.distance,h=void 0===c?y.distance:c,u=t.ignoreLocation,d=void 0===u?y.ignoreLocation:u,f=r/e.length;if(d)return f;var l=Math.abs(s-o);return h?f+l/h:l?1:f}function _(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:y.minMatchCharLength,n=[],r=-1,i=-1,o=0,a=e.length;o=t&&n.push([r,i]),r=-1)}return e[o-1]&&o-r>=t&&n.push([r,o-1]),n}function w(e){for(var t={},n=0,r=e.length;n1&&void 0!==arguments[1]?arguments[1]:{},o=i.location,a=void 0===o?y.location:o,s=i.threshold,c=void 0===s?y.threshold:s,h=i.distance,u=void 0===h?y.distance:h,d=i.includeMatches,f=void 0===d?y.includeMatches:d,l=i.findAllMatches,v=void 0===l?y.findAllMatches:l,g=i.minMatchCharLength,p=void 0===g?y.minMatchCharLength:g,m=i.isCaseSensitive,k=void 0===m?y.isCaseSensitive:m,b=i.ignoreLocation,M=void 0===b?y.ignoreLocation:b;if(e(this,t),this.options={location:a,threshold:c,distance:u,includeMatches:f,findAllMatches:v,minMatchCharLength:p,isCaseSensitive:k,ignoreLocation:M},this.pattern=k?n:n.toLowerCase(),this.chunks=[],this.pattern.length){var x=function(e,t){r.chunks.push({pattern:e,alphabet:w(e),startIndex:t})},L=this.pattern.length;if(L>32){for(var _=0,O=L%32,S=L-O;_3&&void 0!==arguments[3]?arguments[3]:{},i=r.location,o=void 0===i?y.location:i,a=r.distance,s=void 0===a?y.distance:a,c=r.threshold,h=void 0===c?y.threshold:c,u=r.findAllMatches,d=void 0===u?y.findAllMatches:u,f=r.minMatchCharLength,v=void 0===f?y.minMatchCharLength:f,g=r.includeMatches,p=void 0===g?y.includeMatches:g,m=r.ignoreLocation,k=void 0===m?y.ignoreLocation:m;if(t.length>32)throw new Error(l(32));for(var b,M=t.length,x=e.length,w=Math.max(0,Math.min(o,x)),O=h,S=w,A=v>1||p,E=A?Array(x):[];(b=e.indexOf(t,S))>-1;){var I=L(t,{currentLocation:b,expectedLocation:w,distance:s,ignoreLocation:k});if(O=Math.min(I,O),S=b+M,A)for(var j=0;j=K;T-=1){var q=T-1,U=n[e.charAt(q)];if(A&&(E[q]=+!!U),Q[T]=(Q[T+1]<<1|1)&U,$&&(Q[T]|=(C[T+1]|C[T])<<1|1|C[T+1]),Q[T]&P&&(F=L(t,{errors:$,currentLocation:q,expectedLocation:w,distance:s,ignoreLocation:k}))<=O){if(O=F,(S=q)<=w)break;K=Math.max(1,2*w-S)}}var B=L(t,{errors:$+1,currentLocation:w,expectedLocation:w,distance:s,ignoreLocation:k});if(B>O)break;C=Q}var G={isMatch:S>=0,score:Math.max(.001,F)};if(A){var H=_(E,v);H.length?p&&(G.indices=H):G.isMatch=!1}return G}(e,n,i,{location:s+o,distance:c,threshold:h,findAllMatches:u,minMatchCharLength:d,includeMatches:r,ignoreLocation:f}),k=m.isMatch,b=m.score,M=m.indices;k&&(p=!0),g+=b,k&&M&&(v=[].concat(a(v),a(M)))}));var m={isMatch:p,score:p?g/this.chunks.length:1};return p&&r&&(m.indices=v),m}}]),t}(),S=[];function A(e,t){for(var n=0,r=S.length;n1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;if(e(this,t),this.options=o({},y,{},r),this.options.useExtendedSearch)throw new Error("Extended search is not available");this._keyStore=new g(this.options.keys),this.setCollection(n,i)}return n(t,[{key:"setCollection",value:function(e,t){if(this._docs=e,t&&!(t instanceof k))throw new Error("Incorrect 'index' type");this._myIndex=t||b(this._keyStore.keys(),this._docs,{getFn:this.options.getFn})}},{key:"add",value:function(e){d(e)&&(this._docs.push(e),this._myIndex.add(e))}},{key:"remove",value:function(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:function(){return!1},t=[],n=0,r=this._docs.length;n1&&void 0!==arguments[1]?arguments[1]:{},n=t.limit,r=void 0===n?-1:n,i=this.options,o=i.includeMatches,a=i.includeScore,s=i.shouldSort,c=i.sortFn,l=i.ignoreFieldNorm,v=i.matchEmptyQuery;if(v&&(!d(e)||f(e)))return this._docs.map((function(e,t){return{item:e,score:1,refIndex:t}}));var g=h(e)?h(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return I(g,this._keyStore,{ignoreFieldNorm:l}),s&&g.sort(c),u(r)&&r>-1&&(g=g.slice(0,r)),j(g,this._docs,{includeMatches:o,includeScore:a})}},{key:"_searchStringList",value:function(e){var t=A(e,this.options),n=this._myIndex.records,r=[];return n.forEach((function(e){var n=e.v,i=e.i,o=e.n;if(d(n)){var a=t.searchIn(n),s=a.isMatch,c=a.score,h=a.indices;s&&r.push({item:n,idx:i,matches:[{score:c,value:n,norm:o,indices:h}]})}})),r}},{key:"_searchLogical",value:function(e){throw new Error("Logical search is not available")}},{key:"_searchObjectList",value:function(e){var t=this,n=A(e,this.options),r=this._myIndex,i=r.keys,o=r.records,s=[];return o.forEach((function(e){var r=e.$,o=e.i;if(d(r)){var c=[];i.forEach((function(e,i){c.push.apply(c,a(t._findMatches({key:e,value:r[i],searcher:n})))})),c.length&&s.push({idx:o,item:r,matches:c})}})),s}},{key:"_findMatches",value:function(e){var t=e.key,n=e.value,r=e.searcher;if(!d(n))return[];var i=[];if(c(n))n.forEach((function(e){var n=e.v,o=e.i,a=e.n;if(d(n)){var s=r.searchIn(n),c=s.isMatch,h=s.score,u=s.indices;c&&i.push({score:h,key:t,value:n,idx:o,norm:a,indices:u})}}));else{var o=n.v,a=n.n,s=r.searchIn(o),h=s.isMatch,u=s.score,f=s.indices;h&&i.push({score:u,key:t,value:o,norm:a,indices:f})}return i}}]),t}();function I(e,t,n){var r=n.ignoreFieldNorm,i=void 0===r?y.ignoreFieldNorm:r;e.forEach((function(e){var n=1;e.matches.forEach((function(e){var r=e.key,o=e.norm,a=e.score,s=t.get(r,"weight");n*=Math.pow(0===a&&s?Number.EPSILON:a,(s||1)*(i?1:o))})),e.score=n}))}function j(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n.includeMatches,i=void 0===r?y.includeMatches:r,o=n.includeScore,a=void 0===o?y.includeScore:o,s=[];return i&&s.push(M),a&&s.push(x),e.map((function(e){var n=e.idx,r={item:t[n],refIndex:n};return s.length&&s.forEach((function(t){t(e,r)})),r}))}return E.version="6.2.0-beta.1",E.createIndex=b,E.parseIndex=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.getFn,r=void 0===n?y.getFn:n,i=e.keys,o=e.records,a=new k({getFn:r});return a.setKeys(i),a.setIndexRecords(o),a},E.config=y,E},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).Fuse=t(); \ No newline at end of file +var e,t;e=this,t=function(){"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function t(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,r=new Array(t);n0&&void 0!==arguments[0]?arguments[0]:3,t=new Map;return{get:function(n){var r=n.match(p).length;if(t.has(r))return t.get(r);var i=parseFloat((1/Math.sqrt(r)).toFixed(e));return t.set(r,i),i},clear:function(){t.clear()}}}var k=function(){function t(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=n.getFn,i=void 0===r?y.getFn:r;e(this,t),this.norm=m(3),this.getFn=i,this.isCreated=!1,this.setIndexRecords()}return n(t,[{key:"setSources",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.docs=e}},{key:"setIndexRecords",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.records=e}},{key:"setKeys",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.keys=e}},{key:"create",value:function(){var e=this;!this.isCreated&&this.docs.length&&(this.isCreated=!0,h(this.docs[0])?this.docs.forEach((function(t,n){e._addString(t,n)})):this.docs.forEach((function(t,n){e._addObject(t,n)})),this.norm.clear())}},{key:"add",value:function(e){var t=this.size();h(e)?this._addString(e,t):this._addObject(e,t)}},{key:"removeAt",value:function(e){this.records.splice(e,1);for(var t=e,n=this.size();t2&&void 0!==arguments[2]?arguments[2]:{},r=n.getFn,i=void 0===r?y.getFn:r,o=new k({getFn:i}),a=new g(e);return o.setKeys(a.keys()),o.setSources(t),o.create(),o}function M(e,t){var n=e.matches;t.matches=[],d(n)&&n.forEach((function(e){if(d(e.indices)&&e.indices.length){var n={indices:e.indices,value:e.value};e.key&&(n.key=e.key),e.idx>-1&&(n.refIndex=e.idx),t.matches.push(n)}}))}function x(e,t){t.score=e.score}function L(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.errors,r=void 0===n?0:n,i=t.currentLocation,o=void 0===i?0:i,a=t.expectedLocation,s=void 0===a?0:a,c=t.distance,h=void 0===c?y.distance:c,u=t.ignoreLocation,d=void 0===u?y.ignoreLocation:u,l=r/e.length;if(d)return l;var f=Math.abs(s-o);return h?l+f/h:f?1:l}function w(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:y.minMatchCharLength,n=[],r=-1,i=-1,o=0,a=e.length;o=t&&n.push([r,i]),r=-1)}return e[o-1]&&o-r>=t&&n.push([r,o-1]),n}function _(e){for(var t={},n=0,r=e.length;n1&&void 0!==arguments[1]?arguments[1]:{},o=i.location,a=void 0===o?y.location:o,s=i.threshold,c=void 0===s?y.threshold:s,h=i.distance,u=void 0===h?y.distance:h,d=i.includeMatches,l=void 0===d?y.includeMatches:d,f=i.findAllMatches,v=void 0===f?y.findAllMatches:f,g=i.minMatchCharLength,p=void 0===g?y.minMatchCharLength:g,m=i.isCaseSensitive,k=void 0===m?y.isCaseSensitive:m,b=i.ignoreLocation,M=void 0===b?y.ignoreLocation:b;if(e(this,t),this.options={location:a,threshold:c,distance:u,includeMatches:l,findAllMatches:v,minMatchCharLength:p,isCaseSensitive:k,ignoreLocation:M},this.pattern=k?n:n.toLowerCase(),this.chunks=[],this.pattern.length){var x=function(e,t){r.chunks.push({pattern:e,alphabet:_(e),startIndex:t})},L=this.pattern.length;if(L>32){for(var w=0,O=L%32,S=L-O;w3&&void 0!==arguments[3]?arguments[3]:{},i=r.location,o=void 0===i?y.location:i,a=r.distance,s=void 0===a?y.distance:a,c=r.threshold,h=void 0===c?y.threshold:c,u=r.findAllMatches,d=void 0===u?y.findAllMatches:u,l=r.minMatchCharLength,v=void 0===l?y.minMatchCharLength:l,g=r.includeMatches,p=void 0===g?y.includeMatches:g,m=r.ignoreLocation,k=void 0===m?y.ignoreLocation:m;if(t.length>32)throw new Error(f(32));for(var b,M=t.length,x=e.length,_=Math.max(0,Math.min(o,x)),O=h,S=_,A=v>1||p,E=A?Array(x):[];(b=e.indexOf(t,S))>-1;){var I=L(t,{currentLocation:b,expectedLocation:_,distance:s,ignoreLocation:k});if(O=Math.min(I,O),S=b+M,A)for(var j=0;j=K;q-=1){var U=q-1,B=n[e.charAt(U)];if(A&&(E[U]=+!!B),T[q]=(T[q+1]<<1|1)&B,$&&(T[q]|=(C[q+1]|C[q])<<1|1|C[q+1]),T[q]&P&&(F=L(t,{errors:$,currentLocation:U,expectedLocation:_,distance:s,ignoreLocation:k}))<=O){if(O=F,(S=U)<=_)break;K=Math.max(1,2*_-S)}}var G=L(t,{errors:$+1,currentLocation:_,expectedLocation:_,distance:s,ignoreLocation:k});if(G>O)break;C=T}var H={isMatch:S>=0,score:Math.max(.001,F)};if(A){var Q=w(E,v);Q.length?p&&(H.indices=Q):H.isMatch=!1}return H}(e,n,i,{location:s+o,distance:c,threshold:h,findAllMatches:u,minMatchCharLength:d,includeMatches:r,ignoreLocation:l}),k=m.isMatch,b=m.score,M=m.indices;k&&(p=!0),g+=b,k&&M&&(v=[].concat(a(v),a(M)))}));var m={isMatch:p,score:p?g/this.chunks.length:1};return p&&r&&(m.indices=v),m}}]),t}(),S=[];function A(e,t){for(var n=0,r=S.length;n1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;if(e(this,t),this.options=o({},y,{},r),this.options.useExtendedSearch)throw new Error("Extended search is not available");this._keyStore=new g(this.options.keys),this.setCollection(n,i)}return n(t,[{key:"setCollection",value:function(e,t){if(this._docs=e,t&&!(t instanceof k))throw new Error("Incorrect 'index' type");this._myIndex=t||b(this._keyStore.keys(),this._docs,{getFn:this.options.getFn})}},{key:"add",value:function(e){d(e)&&(this._docs.push(e),this._myIndex.add(e))}},{key:"remove",value:function(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:function(){return!1},t=[],n=0,r=this._docs.length;n1&&void 0!==arguments[1]?arguments[1]:{},n=t.limit,r=void 0===n?-1:n,i=this.options,o=i.includeMatches,a=i.includeScore,s=i.shouldSort,c=i.sortFn,d=i.ignoreFieldNorm,l=h(e)?h(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return I(l,this._keyStore,{ignoreFieldNorm:d}),s&&l.sort(c),u(r)&&r>-1&&(l=l.slice(0,r)),j(l,this._docs,{includeMatches:o,includeScore:a})}},{key:"_searchStringList",value:function(e){var t=A(e,this.options),n=this._myIndex.records,r=[];return n.forEach((function(e){var n=e.v,i=e.i,o=e.n;if(d(n)){var a=t.searchIn(n),s=a.isMatch,c=a.score,h=a.indices;s&&r.push({item:n,idx:i,matches:[{score:c,value:n,norm:o,indices:h}]})}})),r}},{key:"_searchLogical",value:function(e){throw new Error("Logical search is not available")}},{key:"_searchObjectList",value:function(e){var t=this,n=A(e,this.options),r=this._myIndex,i=r.keys,o=r.records,s=[];return o.forEach((function(e){var r=e.$,o=e.i;if(d(r)){var c=[];i.forEach((function(e,i){c.push.apply(c,a(t._findMatches({key:e,value:r[i],searcher:n})))})),c.length&&s.push({idx:o,item:r,matches:c})}})),s}},{key:"_findMatches",value:function(e){var t=e.key,n=e.value,r=e.searcher;if(!d(n))return[];var i=[];if(c(n))n.forEach((function(e){var n=e.v,o=e.i,a=e.n;if(d(n)){var s=r.searchIn(n),c=s.isMatch,h=s.score,u=s.indices;c&&i.push({score:h,key:t,value:n,idx:o,norm:a,indices:u})}}));else{var o=n.v,a=n.n,s=r.searchIn(o),h=s.isMatch,u=s.score,l=s.indices;h&&i.push({score:u,key:t,value:o,norm:a,indices:l})}return i}}]),t}();function I(e,t,n){var r=n.ignoreFieldNorm,i=void 0===r?y.ignoreFieldNorm:r;e.forEach((function(e){var n=1;e.matches.forEach((function(e){var r=e.key,o=e.norm,a=e.score,s=t.get(r,"weight");n*=Math.pow(0===a&&s?Number.EPSILON:a,(s||1)*(i?1:o))})),e.score=n}))}function j(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n.includeMatches,i=void 0===r?y.includeMatches:r,o=n.includeScore,a=void 0===o?y.includeScore:o,s=[];return i&&s.push(M),a&&s.push(x),e.map((function(e){var n=e.idx,r={item:t[n],refIndex:n};return s.length&&s.forEach((function(t){t(e,r)})),r}))}return E.version="6.2.0",E.createIndex=b,E.parseIndex=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.getFn,r=void 0===n?y.getFn:n,i=e.keys,o=e.records,a=new k({getFn:r});return a.setKeys(i),a.setIndexRecords(o),a},E.config=y,E},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).Fuse=t(); \ No newline at end of file diff --git a/dist/fuse.common.js b/dist/fuse.common.js index dd0c08ce0..42d37aa3b 100644 --- a/dist/fuse.common.js +++ b/dist/fuse.common.js @@ -1,5 +1,5 @@ /** - * Fuse.js v6.2.0-beta.1 - Lightweight fuzzy-search (http://fusejs.io) + * Fuse.js v6.2.0 - Lightweight fuzzy-search (http://fusejs.io) * * Copyright (c) 2020 Kiro Risk (http://kiro.me) * All Rights Reserved. Apache Software License 2.0 @@ -418,10 +418,7 @@ var AdvancedOptions = { // When `true`, the calculation for the relevance score (used for sorting) will // ignore the field-length norm. // More info: https://fusejs.io/concepts/scoring-theory.html#field-length-norm - ignoreFieldNorm: false, - // When `true`, if the search query is empty, return the whole list instead - // of an empty array. - matchEmptyQuery: false + ignoreFieldNorm: false }; var Config = _objectSpread2({}, BasicOptions, {}, MatchOptions, {}, FuzzyOptions, {}, AdvancedOptions); @@ -629,7 +626,8 @@ function createIndex(keys, docs) { var myIndex = new FuseIndex({ getFn: getFn }); - myIndex.setKeys(keys); + var keyStore = new KeyStore(keys); + myIndex.setKeys(keyStore.keys()); myIndex.setSources(docs); myIndex.create(); return myIndex; @@ -1823,19 +1821,7 @@ var Fuse = /*#__PURE__*/function () { includeScore = _this$options.includeScore, shouldSort = _this$options.shouldSort, sortFn = _this$options.sortFn, - ignoreFieldNorm = _this$options.ignoreFieldNorm, - matchEmptyQuery = _this$options.matchEmptyQuery; - - if (matchEmptyQuery && (!isDefined(query) || isBlank(query))) { - return this._docs.map(function (doc, idx) { - return { - item: doc, - score: 1, - refIndex: idx - }; - }); - } - + ignoreFieldNorm = _this$options.ignoreFieldNorm; var results = isString(query) ? isString(this._docs[0]) ? this._searchStringList(query) : this._searchObjectList(query) : this._searchLogical(query); computeScore$1(results, this._keyStore, { ignoreFieldNorm: ignoreFieldNorm @@ -2118,7 +2104,7 @@ function format(results, docs) { }); } -Fuse.version = '6.2.0-beta.1'; +Fuse.version = '6.2.0'; Fuse.createIndex = createIndex; Fuse.parseIndex = parseIndex; Fuse.config = Config; diff --git a/dist/fuse.d.ts b/dist/fuse.d.ts index d88008cfd..174f2e103 100644 --- a/dist/fuse.d.ts +++ b/dist/fuse.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Fuse.js v6.2.0-beta.0 +// Type definitions for Fuse.js v6.2.0 // TypeScript v3.9.5 export default Fuse diff --git a/dist/fuse.esm.js b/dist/fuse.esm.js index 8a586cc9a..37181c354 100644 --- a/dist/fuse.esm.js +++ b/dist/fuse.esm.js @@ -1,5 +1,5 @@ /** - * Fuse.js v6.2.0-beta.1 - Lightweight fuzzy-search (http://fusejs.io) + * Fuse.js v6.2.0 - Lightweight fuzzy-search (http://fusejs.io) * * Copyright (c) 2020 Kiro Risk (http://kiro.me) * All Rights Reserved. Apache Software License 2.0 @@ -216,10 +216,7 @@ const AdvancedOptions = { // When `true`, the calculation for the relevance score (used for sorting) will // ignore the field-length norm. // More info: https://fusejs.io/concepts/scoring-theory.html#field-length-norm - ignoreFieldNorm: false, - // When `true`, if the search query is empty, return the whole list instead - // of an empty array. - matchEmptyQuery: false + ignoreFieldNorm: false }; var Config = { @@ -390,8 +387,9 @@ class FuseIndex { } function createIndex(keys, docs, { getFn = Config.getFn } = {}) { - let myIndex = new FuseIndex({ getFn }); - myIndex.setKeys(keys); + const myIndex = new FuseIndex({ getFn }); + const keyStore = new KeyStore(keys); + myIndex.setKeys(keyStore.keys()); myIndex.setSources(docs); myIndex.create(); return myIndex @@ -399,7 +397,7 @@ function createIndex(keys, docs, { getFn = Config.getFn } = {}) { function parseIndex(data, { getFn = Config.getFn } = {}) { const { keys, records } = data; - let myIndex = new FuseIndex({ getFn }); + const myIndex = new FuseIndex({ getFn }); myIndex.setKeys(keys); myIndex.setIndexRecords(records); return myIndex @@ -1411,18 +1409,9 @@ class Fuse { includeScore, shouldSort, sortFn, - ignoreFieldNorm, - matchEmptyQuery + ignoreFieldNorm } = this.options; - if (matchEmptyQuery && (!isDefined(query) || isBlank(query))) { - return this._docs.map((doc, idx) => ({ - item: doc, - score: 1, - refIndex: idx - })) - } - let results = isString(query) ? isString(this._docs[0]) ? this._searchStringList(query) @@ -1662,7 +1651,7 @@ function format( }) } -Fuse.version = '6.2.0-beta.1'; +Fuse.version = '6.2.0'; Fuse.createIndex = createIndex; Fuse.parseIndex = parseIndex; Fuse.config = Config; diff --git a/dist/fuse.esm.min.js b/dist/fuse.esm.min.js index 83e38b9bc..d271653cf 100644 --- a/dist/fuse.esm.min.js +++ b/dist/fuse.esm.min.js @@ -1,9 +1,9 @@ /** - * Fuse.js v6.2.0-beta.1 - Lightweight fuzzy-search (http://fusejs.io) + * Fuse.js v6.2.0 - 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(t){return Array.isArray?Array.isArray(t):"[object Array]"===Object.prototype.toString.call(t)}function e(t){return"string"==typeof t}function s(t){return"number"==typeof t}function n(t){return null!=t}function i(t){return!t.trim().length}const r=Object.prototype.hasOwnProperty;class c{constructor(t){this._keys={},this._keyNames=[];let s=0;t.forEach(t=>{let n,i=1;if(e(t))n=t;else{if(!r.call(t,"name"))throw new Error(`Missing ${"name"} property in key`);if(n=t.name,r.call(t,"weight")&&(i=t.weight,i<=0))throw new Error((t=>`Property 'weight' in key '${t}' must be a positive integer`)(n))}this._keyNames.push(n),this._keys[n]={weight:i},s+=i}),this._keyNames.forEach(t=>{this._keys[t].weight/=s})}get(t,e){return this._keys[t]&&this._keys[t][e]}keys(){return this._keyNames}toJSON(){return JSON.stringify(this._keys)}}var o={isCaseSensitive:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score===e.score?t.idx{if(r){const a=r.indexOf(".");let l=r,u=null;-1!==a&&(l=r.slice(0,a),u=r.slice(a+1));const d=i[l];if(!n(d))return;if(u||!e(d)&&!s(d))if(t(d)){o=!0;for(let t=0,e=d.length;t{this._addString(t,e)}):this.docs.forEach((t,e)=>{this._addObject(t,e)}),this.norm.clear())}add(t){const s=this.size();e(t)?this._addString(t,s):this._addObject(t,s)}removeAt(t){this.records.splice(t,1);for(let e=t,s=this.size();e{let h=this.getFn(s,r);if(n(h))if(t(h)){let s=[];const r=[{nestedArrIndex:-1,value:h}];for(;r.length;){const{nestedArrIndex:c,value:o}=r.pop();if(n(o))if(e(o)&&!i(o)){let t={v:o,i:c,n:this.norm.get(o)};s.push(t)}else t(o)&&o.forEach((t,e)=>{r.push({nestedArrIndex:e,value:t})})}c.$[o]=s}else if(!i(h)){let t={v:h,n:this.norm.get(h)};c.$[o]=t}}),this.records.push(c)}toJSON(){return{keys:this.keys,records:this.records}}}function l(t,e,{getFn:s=o.getFn}={}){let n=new a({getFn:s});return n.setKeys(t),n.setSources(e),n.create(),n}function u(t,e){const s=t.matches;e.matches=[],n(s)&&s.forEach(t=>{if(!n(t.indices)||!t.indices.length)return;const{indices:s,value:i}=t;let r={indices:s,value:i};t.key&&(r.key=t.key),t.idx>-1&&(r.refIndex=t.idx),e.matches.push(r)})}function d(t,e){e.score=t.score}function g(t,{errors:e=0,currentLocation:s=0,expectedLocation:n=0,distance:i=o.distance,ignoreLocation:r=o.ignoreLocation}={}){const c=e/t.length;if(r)return c;const h=Math.abs(n-s);return i?c+h/i:h?1:c}function f(t,e,s,{location:n=o.location,distance:i=o.distance,threshold:r=o.threshold,findAllMatches:c=o.findAllMatches,minMatchCharLength:h=o.minMatchCharLength,includeMatches:a=o.includeMatches,ignoreLocation:l=o.ignoreLocation}={}){if(e.length>32)throw new Error(`Pattern length exceeds max of ${32}.`);const u=e.length,d=t.length,f=Math.max(0,Math.min(n,d));let p=r,m=f;const M=h>1||a,x=M?Array(d):[];let y;for(;(y=t.indexOf(e,m))>-1;){let t=g(e,{currentLocation:y,expectedLocation:f,distance:i,ignoreLocation:l});if(p=Math.min(t,p),m=y+u,M){let t=0;for(;t=h;r-=1){let c=r-1,o=s[t.charAt(c)];if(M&&(x[c]=+!!o),y[r]=(y[r+1]<<1|1)&o,n&&(y[r]|=(k[r+1]|k[r])<<1|1|k[r+1]),y[r]&v&&(L=g(e,{errors:n,currentLocation:c,expectedLocation:f,distance:i,ignoreLocation:l}),L<=p)){if(p=L,m=c,m<=f)break;h=Math.max(1,2*f-m)}}if(g(e,{errors:n+1,currentLocation:f,expectedLocation:f,distance:i,ignoreLocation:l})>p)break;k=y}const S={isMatch:m>=0,score:Math.max(.001,L)};if(M){const t=function(t=[],e=o.minMatchCharLength){let s=[],n=-1,i=-1,r=0;for(let c=t.length;r=e&&s.push([n,i]),n=-1)}return t[r-1]&&r-n>=e&&s.push([n,r-1]),s}(x,h);t.length?a&&(S.indices=t):S.isMatch=!1}return S}function p(t){let e={};for(let s=0,n=t.length;s{this.chunks.push({pattern:t,alphabet:p(t),startIndex:e})},u=this.pattern.length;if(u>32){let t=0;const e=u%32,s=u-e;for(;t{const{isMatch:p,score:m,indices:M}=f(t,e,d,{location:n+g,distance:i,threshold:r,findAllMatches:c,minMatchCharLength:o,includeMatches:s,ignoreLocation:h});p&&(u=!0),l+=m,p&&M&&(a=[...a,...M])});let d={isMatch:u,score:u?l/this.chunks.length:1};return u&&s&&(d.indices=a),d}}class M{constructor(t){this.pattern=t}static isMultiMatch(t){return x(t,this.multiRegex)}static isSingleMatch(t){return x(t,this.singleRegex)}search(){}}function x(t,e){const s=t.match(e);return s?s[1]:null}class y extends M{constructor(t){super(t)}static get type(){return"exact"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(t){let e,s=0;const n=[],i=this.pattern.length;for(;(e=t.indexOf(this.pattern,s))>-1;)s=e+i,n.push([e,s-1]);const r=!!n.length;return{isMatch:r,score:r?1:0,indices:n}}}class k extends M{constructor(t,{location:e=o.location,threshold:s=o.threshold,distance:n=o.distance,includeMatches:i=o.includeMatches,findAllMatches:r=o.findAllMatches,minMatchCharLength:c=o.minMatchCharLength,isCaseSensitive:h=o.isCaseSensitive}={}){super(t),this._bitapSearch=new m(t,{location:e,threshold:s,distance:n,includeMatches:i,findAllMatches:r,minMatchCharLength:c,isCaseSensitive:h})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(t){return this._bitapSearch.searchIn(t)}}const L=[y,class extends M{constructor(t){super(t)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(t){const e=t.startsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,this.pattern.length-1]}}},class extends M{constructor(t){super(t)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(t){const e=!t.startsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,t.length-1]}}},class extends M{constructor(t){super(t)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(t){const e=!t.endsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,t.length-1]}}},class extends M{constructor(t){super(t)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(t){const e=t.endsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[t.length-this.pattern.length,t.length-1]}}},class extends M{constructor(t){super(t)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(t){const e=-1===t.indexOf(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,t.length-1]}}},k],_=L.length,v=/ +(?=([^\"]*\"[^\"]*\")*[^\"]*$)/;const S=new Set([k.type,y.type]);class C{constructor(t,{isCaseSensitive:e=o.isCaseSensitive,includeMatches:s=o.includeMatches,minMatchCharLength:n=o.minMatchCharLength,findAllMatches:i=o.findAllMatches,location:r=o.location,threshold:c=o.threshold,distance:h=o.distance}={}){this.query=null,this.options={isCaseSensitive:e,includeMatches:s,minMatchCharLength:n,findAllMatches:i,location:r,threshold:c,distance:h},this.pattern=e?t:t.toLowerCase(),this.query=function(t,e={}){return t.split("|").map(t=>{let s=t.trim().split(v).filter(t=>t&&!!t.trim()),n=[];for(let t=0,i=s.length;t!(!t[E]&&!t[I]),b=t=>({[E]:Object.keys(t).map(e=>({[e]:t[e]}))});function F(s,n,{auto:i=!0}={}){const r=s=>{let c=Object.keys(s);if(c.length>1&&!$(s))return r(b(s));let o=c[0];if((e=>!t(e)&&"object"==typeof e&&!$(e))(s)){const t=s[o];if(!e(t))throw new Error((t=>"Invalid value for key "+t)(o));const r={key:o,pattern:t};return i&&(r.searcher=A(t,n)),r}let h={children:[],operator:o};return c.forEach(e=>{const n=s[e];t(n)&&n.forEach(t=>{h.children.push(r(t))})}),h};return $(s)||(s=b(s)),r(s)}class O{constructor(t,e={},s){this.options={...o,...e},this.options.useExtendedSearch,this._keyStore=new c(this.options.keys),this.setCollection(t,s)}setCollection(t,e){if(this._docs=t,e&&!(e instanceof a))throw new Error("Incorrect 'index' type");this._myIndex=e||l(this._keyStore.keys(),this._docs,{getFn:this.options.getFn})}add(t){n(t)&&(this._docs.push(t),this._myIndex.add(t))}remove(t=(()=>!1)){const e=[];for(let s=0,n=this._docs.length;s({item:t,score:1,refIndex:e}));let p=e(t)?e(this._docs[0])?this._searchStringList(t):this._searchObjectList(t):this._searchLogical(t);return function(t,e,{ignoreFieldNorm:s=o.ignoreFieldNorm}){t.forEach(t=>{let n=1;t.matches.forEach(({key:t,norm:i,score:r})=>{const c=e.get(t,"weight");n*=Math.pow(0===r&&c?Number.EPSILON:r,(c||1)*(s?1:i))}),t.score=n})}(p,this._keyStore,{ignoreFieldNorm:g}),a&&p.sort(l),s(r)&&r>-1&&(p=p.slice(0,r)),function(t,e,{includeMatches:s=o.includeMatches,includeScore:n=o.includeScore}={}){const i=[];s&&i.push(u);n&&i.push(d);return t.map(t=>{const{idx:s}=t,n={item:e[s],refIndex:s};return i.length&&i.forEach(e=>{e(t,n)}),n})}(p,this._docs,{includeMatches:c,includeScore:h})}_searchStringList(t){const e=A(t,this.options),{records:s}=this._myIndex,i=[];return s.forEach(({v:t,i:s,n:r})=>{if(!n(t))return;const{isMatch:c,score:o,indices:h}=e.searchIn(t);c&&i.push({item:t,idx:s,matches:[{score:o,value:t,norm:r,indices:h}]})}),i}_searchLogical(t){const e=F(t,this.options),{keys:s,records:i}=this._myIndex,r={},c=[],o=(t,e,n)=>{if(!t.children){const{key:n,searcher:i}=t,r=e[s.indexOf(n)];return this._findMatches({key:n,value:r,searcher:i})}{const s=t.operator;let i=[];for(let r=0;r{r[n].matches.push(...t)}))}};return i.forEach(({$:t,i:s})=>{n(t)&&o(e,t,s)}),c}_searchObjectList(t){const e=A(t,this.options),{keys:s,records:i}=this._myIndex,r=[];return i.forEach(({$:t,i:i})=>{if(!n(t))return;let c=[];s.forEach((s,n)=>{c.push(...this._findMatches({key:s,value:t[n],searcher:e}))}),c.length&&r.push({idx:i,item:t,matches:c})}),r}_findMatches({key:e,value:s,searcher:i}){if(!n(s))return[];let r=[];if(t(s))s.forEach(({v:t,i:s,n:c})=>{if(!n(t))return;const{isMatch:o,score:h,indices:a}=i.searchIn(t);o&&r.push({score:h,key:e,value:t,idx:s,norm:c,indices:a})});else{const{v:t,n:n}=s,{isMatch:c,score:o,indices:h}=i.searchIn(t);c&&r.push({score:o,key:e,value:t,norm:n,indices:h})}return r}}O.version="6.2.0-beta.1",O.createIndex=l,O.parseIndex=function(t,{getFn:e=o.getFn}={}){const{keys:s,records:n}=t;let i=new a({getFn:e});return i.setKeys(s),i.setIndexRecords(n),i},O.config=o,function(...t){w.push(...t)}(C);export default O; \ No newline at end of file +function t(t){return Array.isArray?Array.isArray(t):"[object Array]"===Object.prototype.toString.call(t)}function e(t){return"string"==typeof t}function s(t){return"number"==typeof t}function n(t){return null!=t}function i(t){return!t.trim().length}const r=Object.prototype.hasOwnProperty;class c{constructor(t){this._keys={},this._keyNames=[];let s=0;t.forEach(t=>{let n,i=1;if(e(t))n=t;else{if(!r.call(t,"name"))throw new Error(`Missing ${"name"} property in key`);if(n=t.name,r.call(t,"weight")&&(i=t.weight,i<=0))throw new Error((t=>`Property 'weight' in key '${t}' must be a positive integer`)(n))}this._keyNames.push(n),this._keys[n]={weight:i},s+=i}),this._keyNames.forEach(t=>{this._keys[t].weight/=s})}get(t,e){return this._keys[t]&&this._keys[t][e]}keys(){return this._keyNames}toJSON(){return JSON.stringify(this._keys)}}var o={isCaseSensitive:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score===e.score?t.idx{if(r){const a=r.indexOf(".");let l=r,u=null;-1!==a&&(l=r.slice(0,a),u=r.slice(a+1));const d=i[l];if(!n(d))return;if(u||!e(d)&&!s(d))if(t(d)){o=!0;for(let t=0,e=d.length;t{this._addString(t,e)}):this.docs.forEach((t,e)=>{this._addObject(t,e)}),this.norm.clear())}add(t){const s=this.size();e(t)?this._addString(t,s):this._addObject(t,s)}removeAt(t){this.records.splice(t,1);for(let e=t,s=this.size();e{let h=this.getFn(s,r);if(n(h))if(t(h)){let s=[];const r=[{nestedArrIndex:-1,value:h}];for(;r.length;){const{nestedArrIndex:c,value:o}=r.pop();if(n(o))if(e(o)&&!i(o)){let t={v:o,i:c,n:this.norm.get(o)};s.push(t)}else t(o)&&o.forEach((t,e)=>{r.push({nestedArrIndex:e,value:t})})}c.$[o]=s}else if(!i(h)){let t={v:h,n:this.norm.get(h)};c.$[o]=t}}),this.records.push(c)}toJSON(){return{keys:this.keys,records:this.records}}}function l(t,e,{getFn:s=o.getFn}={}){const n=new a({getFn:s}),i=new c(t);return n.setKeys(i.keys()),n.setSources(e),n.create(),n}function u(t,e){const s=t.matches;e.matches=[],n(s)&&s.forEach(t=>{if(!n(t.indices)||!t.indices.length)return;const{indices:s,value:i}=t;let r={indices:s,value:i};t.key&&(r.key=t.key),t.idx>-1&&(r.refIndex=t.idx),e.matches.push(r)})}function d(t,e){e.score=t.score}function g(t,{errors:e=0,currentLocation:s=0,expectedLocation:n=0,distance:i=o.distance,ignoreLocation:r=o.ignoreLocation}={}){const c=e/t.length;if(r)return c;const h=Math.abs(n-s);return i?c+h/i:h?1:c}function f(t,e,s,{location:n=o.location,distance:i=o.distance,threshold:r=o.threshold,findAllMatches:c=o.findAllMatches,minMatchCharLength:h=o.minMatchCharLength,includeMatches:a=o.includeMatches,ignoreLocation:l=o.ignoreLocation}={}){if(e.length>32)throw new Error(`Pattern length exceeds max of ${32}.`);const u=e.length,d=t.length,f=Math.max(0,Math.min(n,d));let p=r,m=f;const M=h>1||a,x=M?Array(d):[];let y;for(;(y=t.indexOf(e,m))>-1;){let t=g(e,{currentLocation:y,expectedLocation:f,distance:i,ignoreLocation:l});if(p=Math.min(t,p),m=y+u,M){let t=0;for(;t=h;r-=1){let c=r-1,o=s[t.charAt(c)];if(M&&(x[c]=+!!o),y[r]=(y[r+1]<<1|1)&o,n&&(y[r]|=(k[r+1]|k[r])<<1|1|k[r+1]),y[r]&v&&(L=g(e,{errors:n,currentLocation:c,expectedLocation:f,distance:i,ignoreLocation:l}),L<=p)){if(p=L,m=c,m<=f)break;h=Math.max(1,2*f-m)}}if(g(e,{errors:n+1,currentLocation:f,expectedLocation:f,distance:i,ignoreLocation:l})>p)break;k=y}const S={isMatch:m>=0,score:Math.max(.001,L)};if(M){const t=function(t=[],e=o.minMatchCharLength){let s=[],n=-1,i=-1,r=0;for(let c=t.length;r=e&&s.push([n,i]),n=-1)}return t[r-1]&&r-n>=e&&s.push([n,r-1]),s}(x,h);t.length?a&&(S.indices=t):S.isMatch=!1}return S}function p(t){let e={};for(let s=0,n=t.length;s{this.chunks.push({pattern:t,alphabet:p(t),startIndex:e})},u=this.pattern.length;if(u>32){let t=0;const e=u%32,s=u-e;for(;t{const{isMatch:p,score:m,indices:M}=f(t,e,d,{location:n+g,distance:i,threshold:r,findAllMatches:c,minMatchCharLength:o,includeMatches:s,ignoreLocation:h});p&&(u=!0),l+=m,p&&M&&(a=[...a,...M])});let d={isMatch:u,score:u?l/this.chunks.length:1};return u&&s&&(d.indices=a),d}}class M{constructor(t){this.pattern=t}static isMultiMatch(t){return x(t,this.multiRegex)}static isSingleMatch(t){return x(t,this.singleRegex)}search(){}}function x(t,e){const s=t.match(e);return s?s[1]:null}class y extends M{constructor(t){super(t)}static get type(){return"exact"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(t){let e,s=0;const n=[],i=this.pattern.length;for(;(e=t.indexOf(this.pattern,s))>-1;)s=e+i,n.push([e,s-1]);const r=!!n.length;return{isMatch:r,score:r?1:0,indices:n}}}class k extends M{constructor(t,{location:e=o.location,threshold:s=o.threshold,distance:n=o.distance,includeMatches:i=o.includeMatches,findAllMatches:r=o.findAllMatches,minMatchCharLength:c=o.minMatchCharLength,isCaseSensitive:h=o.isCaseSensitive}={}){super(t),this._bitapSearch=new m(t,{location:e,threshold:s,distance:n,includeMatches:i,findAllMatches:r,minMatchCharLength:c,isCaseSensitive:h})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(t){return this._bitapSearch.searchIn(t)}}const L=[y,class extends M{constructor(t){super(t)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(t){const e=t.startsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,this.pattern.length-1]}}},class extends M{constructor(t){super(t)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(t){const e=!t.startsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,t.length-1]}}},class extends M{constructor(t){super(t)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(t){const e=!t.endsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,t.length-1]}}},class extends M{constructor(t){super(t)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(t){const e=t.endsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[t.length-this.pattern.length,t.length-1]}}},class extends M{constructor(t){super(t)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(t){const e=-1===t.indexOf(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,t.length-1]}}},k],_=L.length,v=/ +(?=([^\"]*\"[^\"]*\")*[^\"]*$)/;const S=new Set([k.type,y.type]);class C{constructor(t,{isCaseSensitive:e=o.isCaseSensitive,includeMatches:s=o.includeMatches,minMatchCharLength:n=o.minMatchCharLength,findAllMatches:i=o.findAllMatches,location:r=o.location,threshold:c=o.threshold,distance:h=o.distance}={}){this.query=null,this.options={isCaseSensitive:e,includeMatches:s,minMatchCharLength:n,findAllMatches:i,location:r,threshold:c,distance:h},this.pattern=e?t:t.toLowerCase(),this.query=function(t,e={}){return t.split("|").map(t=>{let s=t.trim().split(v).filter(t=>t&&!!t.trim()),n=[];for(let t=0,i=s.length;t!(!t[I]&&!t[$]),b=t=>({[I]:Object.keys(t).map(e=>({[e]:t[e]}))});function F(s,n,{auto:i=!0}={}){const r=s=>{let c=Object.keys(s);if(c.length>1&&!E(s))return r(b(s));let o=c[0];if((e=>!t(e)&&"object"==typeof e&&!E(e))(s)){const t=s[o];if(!e(t))throw new Error((t=>"Invalid value for key "+t)(o));const r={key:o,pattern:t};return i&&(r.searcher=A(t,n)),r}let h={children:[],operator:o};return c.forEach(e=>{const n=s[e];t(n)&&n.forEach(t=>{h.children.push(r(t))})}),h};return E(s)||(s=b(s)),r(s)}class O{constructor(t,e={},s){this.options={...o,...e},this.options.useExtendedSearch,this._keyStore=new c(this.options.keys),this.setCollection(t,s)}setCollection(t,e){if(this._docs=t,e&&!(e instanceof a))throw new Error("Incorrect 'index' type");this._myIndex=e||l(this._keyStore.keys(),this._docs,{getFn:this.options.getFn})}add(t){n(t)&&(this._docs.push(t),this._myIndex.add(t))}remove(t=(()=>!1)){const e=[];for(let s=0,n=this._docs.length;s{let n=1;t.matches.forEach(({key:t,norm:i,score:r})=>{const c=e.get(t,"weight");n*=Math.pow(0===r&&c?Number.EPSILON:r,(c||1)*(s?1:i))}),t.score=n})}(l,this._keyStore,{ignoreFieldNorm:a}),c&&l.sort(h),s(n)&&n>-1&&(l=l.slice(0,n)),function(t,e,{includeMatches:s=o.includeMatches,includeScore:n=o.includeScore}={}){const i=[];s&&i.push(u);n&&i.push(d);return t.map(t=>{const{idx:s}=t,n={item:e[s],refIndex:s};return i.length&&i.forEach(e=>{e(t,n)}),n})}(l,this._docs,{includeMatches:i,includeScore:r})}_searchStringList(t){const e=A(t,this.options),{records:s}=this._myIndex,i=[];return s.forEach(({v:t,i:s,n:r})=>{if(!n(t))return;const{isMatch:c,score:o,indices:h}=e.searchIn(t);c&&i.push({item:t,idx:s,matches:[{score:o,value:t,norm:r,indices:h}]})}),i}_searchLogical(t){const e=F(t,this.options),{keys:s,records:i}=this._myIndex,r={},c=[],o=(t,e,n)=>{if(!t.children){const{key:n,searcher:i}=t,r=e[s.indexOf(n)];return this._findMatches({key:n,value:r,searcher:i})}{const s=t.operator;let i=[];for(let r=0;r{r[n].matches.push(...t)}))}};return i.forEach(({$:t,i:s})=>{n(t)&&o(e,t,s)}),c}_searchObjectList(t){const e=A(t,this.options),{keys:s,records:i}=this._myIndex,r=[];return i.forEach(({$:t,i:i})=>{if(!n(t))return;let c=[];s.forEach((s,n)=>{c.push(...this._findMatches({key:s,value:t[n],searcher:e}))}),c.length&&r.push({idx:i,item:t,matches:c})}),r}_findMatches({key:e,value:s,searcher:i}){if(!n(s))return[];let r=[];if(t(s))s.forEach(({v:t,i:s,n:c})=>{if(!n(t))return;const{isMatch:o,score:h,indices:a}=i.searchIn(t);o&&r.push({score:h,key:e,value:t,idx:s,norm:c,indices:a})});else{const{v:t,n:n}=s,{isMatch:c,score:o,indices:h}=i.searchIn(t);c&&r.push({score:o,key:e,value:t,norm:n,indices:h})}return r}}O.version="6.2.0",O.createIndex=l,O.parseIndex=function(t,{getFn:e=o.getFn}={}){const{keys:s,records:n}=t,i=new a({getFn:e});return i.setKeys(s),i.setIndexRecords(n),i},O.config=o,function(...t){w.push(...t)}(C);export default O; \ No newline at end of file diff --git a/dist/fuse.js b/dist/fuse.js index ddbdbbc11..7d9774ec8 100644 --- a/dist/fuse.js +++ b/dist/fuse.js @@ -1,5 +1,5 @@ /** - * Fuse.js v6.2.0-beta.0 - Lightweight fuzzy-search (http://fusejs.io) + * Fuse.js v6.2.0 - Lightweight fuzzy-search (http://fusejs.io) * * Copyright (c) 2020 Kiro Risk (http://kiro.me) * All Rights Reserved. Apache Software License 2.0 @@ -2108,7 +2108,7 @@ }); } - Fuse.version = '6.2.0-beta.0'; + Fuse.version = '6.2.0'; Fuse.createIndex = createIndex; Fuse.parseIndex = parseIndex; Fuse.config = Config; diff --git a/dist/fuse.min.js b/dist/fuse.min.js index 3288f6e85..2dc70fc99 100644 --- a/dist/fuse.min.js +++ b/dist/fuse.min.js @@ -1,9 +1,9 @@ /** - * Fuse.js v6.2.0-beta.1 - Lightweight fuzzy-search (http://fusejs.io) + * Fuse.js v6.2.0 - 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 */ -var e,t;e=this,t=function(){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,r=new Array(t);n0&&void 0!==arguments[0]?arguments[0]:3,t=new Map;return{get:function(n){var r=n.match(_).length;if(t.has(r))return t.get(r);var i=parseFloat((1/Math.sqrt(r)).toFixed(e));return t.set(r,i),i},clear:function(){t.clear()}}}var L=function(){function e(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=n.getFn,i=void 0===r?S.getFn:r;t(this,e),this.norm=w(3),this.getFn=i,this.isCreated=!1,this.setIndexRecords()}return r(e,[{key:"setSources",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.docs=e}},{key:"setIndexRecords",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.records=e}},{key:"setKeys",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.keys=e}},{key:"create",value:function(){var e=this;!this.isCreated&&this.docs.length&&(this.isCreated=!0,y(this.docs[0])?this.docs.forEach((function(t,n){e._addString(t,n)})):this.docs.forEach((function(t,n){e._addObject(t,n)})),this.norm.clear())}},{key:"add",value:function(e){var t=this.size();y(e)?this._addString(e,t):this._addObject(e,t)}},{key:"removeAt",value:function(e){this.records.splice(e,1);for(var t=e,n=this.size();t2&&void 0!==arguments[2]?arguments[2]:{},r=n.getFn,i=void 0===r?S.getFn:r,o=new L({getFn:i});return o.setKeys(e),o.setSources(t),o.create(),o}function C(e,t){var n=e.matches;t.matches=[],p(n)&&n.forEach((function(e){if(p(e.indices)&&e.indices.length){var n={indices:e.indices,value:e.value};e.key&&(n.key=e.key),e.idx>-1&&(n.refIndex=e.idx),t.matches.push(n)}}))}function A(e,t){t.score=e.score}function E(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.errors,r=void 0===n?0:n,i=t.currentLocation,o=void 0===i?0:i,c=t.expectedLocation,a=void 0===c?0:c,s=t.distance,u=void 0===s?S.distance:s,h=t.ignoreLocation,f=void 0===h?S.ignoreLocation:h,l=r/e.length;if(f)return l;var d=Math.abs(a-o);return u?l+d/u:d?1:l}function j(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:S.minMatchCharLength,n=[],r=-1,i=-1,o=0,c=e.length;o=t&&n.push([r,i]),r=-1)}return e[o-1]&&o-r>=t&&n.push([r,o-1]),n}function I(e){for(var t={},n=0,r=e.length;n1&&void 0!==arguments[1]?arguments[1]:{},o=i.location,c=void 0===o?S.location:o,a=i.threshold,s=void 0===a?S.threshold:a,u=i.distance,h=void 0===u?S.distance:u,f=i.includeMatches,l=void 0===f?S.includeMatches:f,d=i.findAllMatches,v=void 0===d?S.findAllMatches:d,y=i.minMatchCharLength,g=void 0===y?S.minMatchCharLength:y,p=i.isCaseSensitive,m=void 0===p?S.isCaseSensitive:p,k=i.ignoreLocation,M=void 0===k?S.ignoreLocation:k;if(t(this,e),this.options={location:c,threshold:s,distance:h,includeMatches:l,findAllMatches:v,minMatchCharLength:g,isCaseSensitive:m,ignoreLocation:M},this.pattern=m?n:n.toLowerCase(),this.chunks=[],this.pattern.length){var x=function(e,t){r.chunks.push({pattern:e,alphabet:I(e),startIndex:t})},b=this.pattern.length;if(b>32){for(var _=0,w=b%32,L=b-w;_3&&void 0!==arguments[3]?arguments[3]:{},i=r.location,o=void 0===i?S.location:i,c=r.distance,a=void 0===c?S.distance:c,s=r.threshold,u=void 0===s?S.threshold:s,h=r.findAllMatches,f=void 0===h?S.findAllMatches:h,l=r.minMatchCharLength,d=void 0===l?S.minMatchCharLength:l,v=r.includeMatches,y=void 0===v?S.includeMatches:v,g=r.ignoreLocation,p=void 0===g?S.ignoreLocation:g;if(t.length>32)throw new Error(M(32));for(var m,k=t.length,x=e.length,b=Math.max(0,Math.min(o,x)),_=u,w=b,L=d>1||y,O=L?Array(x):[];(m=e.indexOf(t,w))>-1;){var C=E(t,{currentLocation:m,expectedLocation:b,distance:a,ignoreLocation:p});if(_=Math.min(C,_),w=m+k,L)for(var A=0;A=q;K-=1){var T=K-1,Q=n[e.charAt(T)];if(L&&(O[T]=+!!Q),J[K]=(J[K+1]<<1|1)&Q,P&&(J[K]|=(I[K+1]|I[K])<<1|1|I[K+1]),J[K]&F&&($=E(t,{errors:P,currentLocation:T,expectedLocation:b,distance:a,ignoreLocation:p}))<=_){if(_=$,(w=T)<=b)break;q=Math.max(1,2*b-w)}}var U=E(t,{errors:P+1,currentLocation:b,expectedLocation:b,distance:a,ignoreLocation:p});if(U>_)break;I=J}var B={isMatch:w>=0,score:Math.max(.001,$)};if(L){var G=j(O,d);G.length?y&&(B.indices=G):B.isMatch=!1}return B}(e,n,i,{location:c+o,distance:a,threshold:s,findAllMatches:u,minMatchCharLength:h,includeMatches:r,ignoreLocation:f}),p=g.isMatch,m=g.score,k=g.indices;p&&(y=!0),v+=m,p&&k&&(d=[].concat(l(d),l(k)))}));var g={isMatch:y,score:y?v/this.chunks.length:1};return y&&r&&(g.indices=d),g}}]),e}(),R=function(){function e(n){t(this,e),this.pattern=n}return r(e,[{key:"search",value:function(){}}],[{key:"isMultiMatch",value:function(e){return F(e,this.multiRegex)}},{key:"isSingleMatch",value:function(e){return F(e,this.singleRegex)}}]),e}();function F(e,t){var n=e.match(t);return n?n[1]:null}var P=function(e){a(i,e);var n=f(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){for(var t,n=0,r=[],i=this.pattern.length;(t=e.indexOf(this.pattern,n))>-1;)n=t+i,r.push([t,n-1]);var o=!!r.length;return{isMatch:o,score:o?1:0,indices:r}}}],[{key:"type",get:function(){return"exact"}},{key:"multiRegex",get:function(){return/^'"(.*)"$/}},{key:"singleRegex",get:function(){return/^'(.*)$/}}]),i}(R),N=function(e){a(i,e);var n=f(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){var t=-1===e.indexOf(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}}],[{key:"type",get:function(){return"inverse-exact"}},{key:"multiRegex",get:function(){return/^!"(.*)"$/}},{key:"singleRegex",get:function(){return/^!(.*)$/}}]),i}(R),D=function(e){a(i,e);var n=f(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){var t=e.startsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,this.pattern.length-1]}}}],[{key:"type",get:function(){return"prefix-exact"}},{key:"multiRegex",get:function(){return/^\^"(.*)"$/}},{key:"singleRegex",get:function(){return/^\^(.*)$/}}]),i}(R),z=function(e){a(i,e);var n=f(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){var t=!e.startsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}}],[{key:"type",get:function(){return"inverse-prefix-exact"}},{key:"multiRegex",get:function(){return/^!\^"(.*)"$/}},{key:"singleRegex",get:function(){return/^!\^(.*)$/}}]),i}(R),q=function(e){a(i,e);var n=f(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){var t=e.endsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[e.length-this.pattern.length,e.length-1]}}}],[{key:"type",get:function(){return"suffix-exact"}},{key:"multiRegex",get:function(){return/^"(.*)"\$$/}},{key:"singleRegex",get:function(){return/^(.*)\$$/}}]),i}(R),W=function(e){a(i,e);var n=f(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){var t=!e.endsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}}],[{key:"type",get:function(){return"inverse-suffix-exact"}},{key:"multiRegex",get:function(){return/^!"(.*)"\$$/}},{key:"singleRegex",get:function(){return/^!(.*)\$$/}}]),i}(R),J=function(e){a(i,e);var n=f(i);function i(e){var r,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},c=o.location,a=void 0===c?S.location:c,s=o.threshold,u=void 0===s?S.threshold:s,h=o.distance,f=void 0===h?S.distance:h,l=o.includeMatches,d=void 0===l?S.includeMatches:l,v=o.findAllMatches,y=void 0===v?S.findAllMatches:v,g=o.minMatchCharLength,p=void 0===g?S.minMatchCharLength:g,m=o.isCaseSensitive,k=void 0===m?S.isCaseSensitive:m;return t(this,i),(r=n.call(this,e))._bitapSearch=new $(e,{location:a,threshold:u,distance:f,includeMatches:d,findAllMatches:y,minMatchCharLength:p,isCaseSensitive:k}),r}return r(i,[{key:"search",value:function(e){return this._bitapSearch.searchIn(e)}}],[{key:"type",get:function(){return"fuzzy"}},{key:"multiRegex",get:function(){return/^"(.*)"$/}},{key:"singleRegex",get:function(){return/^(.*)$/}}]),i}(R),K=[P,D,z,W,q,N,J],T=K.length,Q=/ +(?=([^\"]*\"[^\"]*\")*[^\"]*$)/;function U(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return e.split("|").map((function(e){for(var n=e.trim().split(Q).filter((function(e){return e&&!!e.trim()})),r=[],i=0,o=n.length;i1&&void 0!==arguments[1]?arguments[1]:{},i=r.isCaseSensitive,o=void 0===i?S.isCaseSensitive:i,c=r.includeMatches,a=void 0===c?S.includeMatches:c,s=r.minMatchCharLength,u=void 0===s?S.minMatchCharLength:s,h=r.findAllMatches,f=void 0===h?S.findAllMatches:h,l=r.location,d=void 0===l?S.location:l,v=r.threshold,y=void 0===v?S.threshold:v,g=r.distance,p=void 0===g?S.distance:g;t(this,e),this.query=null,this.options={isCaseSensitive:o,includeMatches:a,minMatchCharLength:u,findAllMatches:f,location:d,threshold:y,distance:p},this.pattern=o?n:n.toLowerCase(),this.query=U(this.pattern,this.options)}return r(e,[{key:"searchIn",value:function(e){var t=this.query;if(!t)return{isMatch:!1,score:1};var n=this.options,r=n.includeMatches;e=n.isCaseSensitive?e:e.toLowerCase();for(var i=0,o=[],c=0,a=0,s=t.length;a1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;t(this,e),this.options=c({},S,{},r),this.options.useExtendedSearch,this._keyStore=new b(this.options.keys),this.setCollection(n,i)}return r(e,[{key:"setCollection",value:function(e,t){if(this._docs=e,t&&!(t instanceof L))throw new Error("Incorrect 'index' type");this._myIndex=t||O(this._keyStore.keys(),this._docs,{getFn:this.options.getFn})}},{key:"add",value:function(e){p(e)&&(this._docs.push(e),this._myIndex.add(e))}},{key:"remove",value:function(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:function(){return!1},t=[],n=0,r=this._docs.length;n1&&void 0!==arguments[1]?arguments[1]:{},n=t.limit,r=void 0===n?-1:n,i=this.options,o=i.includeMatches,c=i.includeScore,a=i.shouldSort,s=i.sortFn,u=i.ignoreFieldNorm,h=i.matchEmptyQuery;if(h&&(!p(e)||m(e)))return this._docs.map((function(e,t){return{item:e,score:1,refIndex:t}}));var f=y(e)?y(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return re(f,this._keyStore,{ignoreFieldNorm:u}),a&&f.sort(s),g(r)&&r>-1&&(f=f.slice(0,r)),ie(f,this._docs,{includeMatches:o,includeScore:c})}},{key:"_searchStringList",value:function(e){var t=V(e,this.options),n=this._myIndex.records,r=[];return n.forEach((function(e){var n=e.v,i=e.i,o=e.n;if(p(n)){var c=t.searchIn(n),a=c.isMatch,s=c.score,u=c.indices;a&&r.push({item:n,idx:i,matches:[{score:s,value:n,norm:o,indices:u}]})}})),r}},{key:"_searchLogical",value:function(e){var t=this,n=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n.auto,i=void 0===r||r,o=function e(n){var r=Object.keys(n);if(r.length>1&&!Z(n))return e(te(n));var o=r[0];if(ee(n)){var c=n[o];if(!y(c))throw new Error(k(o));var a={key:o,pattern:c};return i&&(a.searcher=V(c,t)),a}var s={children:[],operator:o};return r.forEach((function(t){var r=n[t];v(r)&&r.forEach((function(t){s.children.push(e(t))}))})),s};return Z(e)||(e=te(e)),o(e)}(e,this.options),r=this._myIndex,i=r.keys,o=r.records,c={},a=[];return o.forEach((function(e){var r=e.$,o=e.i;p(r)&&function e(n,r,o){if(!n.children){var s=n.key,u=n.searcher,h=r[i.indexOf(s)];return t._findMatches({key:s,value:h,searcher:u})}for(var f=n.operator,d=[],v=0;v2&&void 0!==arguments[2]?arguments[2]:{},r=n.includeMatches,i=void 0===r?S.includeMatches:r,o=n.includeScore,c=void 0===o?S.includeScore:o,a=[];return i&&a.push(C),c&&a.push(A),e.map((function(e){var n=e.idx,r={item:t[n],refIndex:n};return a.length&&a.forEach((function(t){t(e,r)})),r}))}return ne.version="6.2.0-beta.1",ne.createIndex=O,ne.parseIndex=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.getFn,r=void 0===n?S.getFn:n,i=e.keys,o=e.records,c=new L({getFn:r});return c.setKeys(i),c.setIndexRecords(o),c},ne.config=S,function(){H.push.apply(H,arguments)}(G),ne},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).Fuse=t(); \ No newline at end of file +var e,t;e=this,t=function(){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,r=new Array(t);n0&&void 0!==arguments[0]?arguments[0]:3,t=new Map;return{get:function(n){var r=n.match(_).length;if(t.has(r))return t.get(r);var i=parseFloat((1/Math.sqrt(r)).toFixed(e));return t.set(r,i),i},clear:function(){t.clear()}}}var L=function(){function e(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=n.getFn,i=void 0===r?S.getFn:r;t(this,e),this.norm=w(3),this.getFn=i,this.isCreated=!1,this.setIndexRecords()}return r(e,[{key:"setSources",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.docs=e}},{key:"setIndexRecords",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.records=e}},{key:"setKeys",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.keys=e}},{key:"create",value:function(){var e=this;!this.isCreated&&this.docs.length&&(this.isCreated=!0,g(this.docs[0])?this.docs.forEach((function(t,n){e._addString(t,n)})):this.docs.forEach((function(t,n){e._addObject(t,n)})),this.norm.clear())}},{key:"add",value:function(e){var t=this.size();g(e)?this._addString(e,t):this._addObject(e,t)}},{key:"removeAt",value:function(e){this.records.splice(e,1);for(var t=e,n=this.size();t2&&void 0!==arguments[2]?arguments[2]:{},r=n.getFn,i=void 0===r?S.getFn:r,o=new L({getFn:i}),c=new b(e);return o.setKeys(c.keys()),o.setSources(t),o.create(),o}function C(e,t){var n=e.matches;t.matches=[],p(n)&&n.forEach((function(e){if(p(e.indices)&&e.indices.length){var n={indices:e.indices,value:e.value};e.key&&(n.key=e.key),e.idx>-1&&(n.refIndex=e.idx),t.matches.push(n)}}))}function A(e,t){t.score=e.score}function j(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.errors,r=void 0===n?0:n,i=t.currentLocation,o=void 0===i?0:i,c=t.expectedLocation,a=void 0===c?0:c,s=t.distance,u=void 0===s?S.distance:s,h=t.ignoreLocation,f=void 0===h?S.ignoreLocation:h,l=r/e.length;if(f)return l;var d=Math.abs(a-o);return u?l+d/u:d?1:l}function E(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:S.minMatchCharLength,n=[],r=-1,i=-1,o=0,c=e.length;o=t&&n.push([r,i]),r=-1)}return e[o-1]&&o-r>=t&&n.push([r,o-1]),n}function I(e){for(var t={},n=0,r=e.length;n1&&void 0!==arguments[1]?arguments[1]:{},o=i.location,c=void 0===o?S.location:o,a=i.threshold,s=void 0===a?S.threshold:a,u=i.distance,h=void 0===u?S.distance:u,f=i.includeMatches,l=void 0===f?S.includeMatches:f,d=i.findAllMatches,v=void 0===d?S.findAllMatches:d,g=i.minMatchCharLength,y=void 0===g?S.minMatchCharLength:g,p=i.isCaseSensitive,m=void 0===p?S.isCaseSensitive:p,k=i.ignoreLocation,M=void 0===k?S.ignoreLocation:k;if(t(this,e),this.options={location:c,threshold:s,distance:h,includeMatches:l,findAllMatches:v,minMatchCharLength:y,isCaseSensitive:m,ignoreLocation:M},this.pattern=m?n:n.toLowerCase(),this.chunks=[],this.pattern.length){var x=function(e,t){r.chunks.push({pattern:e,alphabet:I(e),startIndex:t})},b=this.pattern.length;if(b>32){for(var _=0,w=b%32,L=b-w;_3&&void 0!==arguments[3]?arguments[3]:{},i=r.location,o=void 0===i?S.location:i,c=r.distance,a=void 0===c?S.distance:c,s=r.threshold,u=void 0===s?S.threshold:s,h=r.findAllMatches,f=void 0===h?S.findAllMatches:h,l=r.minMatchCharLength,d=void 0===l?S.minMatchCharLength:l,v=r.includeMatches,g=void 0===v?S.includeMatches:v,y=r.ignoreLocation,p=void 0===y?S.ignoreLocation:y;if(t.length>32)throw new Error(M(32));for(var m,k=t.length,x=e.length,b=Math.max(0,Math.min(o,x)),_=u,w=b,L=d>1||g,O=L?Array(x):[];(m=e.indexOf(t,w))>-1;){var C=j(t,{currentLocation:m,expectedLocation:b,distance:a,ignoreLocation:p});if(_=Math.min(C,_),w=m+k,L)for(var A=0;A=q;K-=1){var T=K-1,U=n[e.charAt(T)];if(L&&(O[T]=+!!U),J[K]=(J[K+1]<<1|1)&U,P&&(J[K]|=(I[K+1]|I[K])<<1|1|I[K+1]),J[K]&F&&($=j(t,{errors:P,currentLocation:T,expectedLocation:b,distance:a,ignoreLocation:p}))<=_){if(_=$,(w=T)<=b)break;q=Math.max(1,2*b-w)}}var B=j(t,{errors:P+1,currentLocation:b,expectedLocation:b,distance:a,ignoreLocation:p});if(B>_)break;I=J}var G={isMatch:w>=0,score:Math.max(.001,$)};if(L){var H=E(O,d);H.length?g&&(G.indices=H):G.isMatch=!1}return G}(e,n,i,{location:c+o,distance:a,threshold:s,findAllMatches:u,minMatchCharLength:h,includeMatches:r,ignoreLocation:f}),p=y.isMatch,m=y.score,k=y.indices;p&&(g=!0),v+=m,p&&k&&(d=[].concat(l(d),l(k)))}));var y={isMatch:g,score:g?v/this.chunks.length:1};return g&&r&&(y.indices=d),y}}]),e}(),R=function(){function e(n){t(this,e),this.pattern=n}return r(e,[{key:"search",value:function(){}}],[{key:"isMultiMatch",value:function(e){return F(e,this.multiRegex)}},{key:"isSingleMatch",value:function(e){return F(e,this.singleRegex)}}]),e}();function F(e,t){var n=e.match(t);return n?n[1]:null}var P=function(e){a(i,e);var n=f(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){for(var t,n=0,r=[],i=this.pattern.length;(t=e.indexOf(this.pattern,n))>-1;)n=t+i,r.push([t,n-1]);var o=!!r.length;return{isMatch:o,score:o?1:0,indices:r}}}],[{key:"type",get:function(){return"exact"}},{key:"multiRegex",get:function(){return/^'"(.*)"$/}},{key:"singleRegex",get:function(){return/^'(.*)$/}}]),i}(R),N=function(e){a(i,e);var n=f(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){var t=-1===e.indexOf(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}}],[{key:"type",get:function(){return"inverse-exact"}},{key:"multiRegex",get:function(){return/^!"(.*)"$/}},{key:"singleRegex",get:function(){return/^!(.*)$/}}]),i}(R),D=function(e){a(i,e);var n=f(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){var t=e.startsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,this.pattern.length-1]}}}],[{key:"type",get:function(){return"prefix-exact"}},{key:"multiRegex",get:function(){return/^\^"(.*)"$/}},{key:"singleRegex",get:function(){return/^\^(.*)$/}}]),i}(R),z=function(e){a(i,e);var n=f(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){var t=!e.startsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}}],[{key:"type",get:function(){return"inverse-prefix-exact"}},{key:"multiRegex",get:function(){return/^!\^"(.*)"$/}},{key:"singleRegex",get:function(){return/^!\^(.*)$/}}]),i}(R),q=function(e){a(i,e);var n=f(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){var t=e.endsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[e.length-this.pattern.length,e.length-1]}}}],[{key:"type",get:function(){return"suffix-exact"}},{key:"multiRegex",get:function(){return/^"(.*)"\$$/}},{key:"singleRegex",get:function(){return/^(.*)\$$/}}]),i}(R),W=function(e){a(i,e);var n=f(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){var t=!e.endsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}}],[{key:"type",get:function(){return"inverse-suffix-exact"}},{key:"multiRegex",get:function(){return/^!"(.*)"\$$/}},{key:"singleRegex",get:function(){return/^!(.*)\$$/}}]),i}(R),J=function(e){a(i,e);var n=f(i);function i(e){var r,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},c=o.location,a=void 0===c?S.location:c,s=o.threshold,u=void 0===s?S.threshold:s,h=o.distance,f=void 0===h?S.distance:h,l=o.includeMatches,d=void 0===l?S.includeMatches:l,v=o.findAllMatches,g=void 0===v?S.findAllMatches:v,y=o.minMatchCharLength,p=void 0===y?S.minMatchCharLength:y,m=o.isCaseSensitive,k=void 0===m?S.isCaseSensitive:m;return t(this,i),(r=n.call(this,e))._bitapSearch=new $(e,{location:a,threshold:u,distance:f,includeMatches:d,findAllMatches:g,minMatchCharLength:p,isCaseSensitive:k}),r}return r(i,[{key:"search",value:function(e){return this._bitapSearch.searchIn(e)}}],[{key:"type",get:function(){return"fuzzy"}},{key:"multiRegex",get:function(){return/^"(.*)"$/}},{key:"singleRegex",get:function(){return/^(.*)$/}}]),i}(R),K=[P,D,z,W,q,N,J],T=K.length,U=/ +(?=([^\"]*\"[^\"]*\")*[^\"]*$)/;function B(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return e.split("|").map((function(e){for(var n=e.trim().split(U).filter((function(e){return e&&!!e.trim()})),r=[],i=0,o=n.length;i1&&void 0!==arguments[1]?arguments[1]:{},i=r.isCaseSensitive,o=void 0===i?S.isCaseSensitive:i,c=r.includeMatches,a=void 0===c?S.includeMatches:c,s=r.minMatchCharLength,u=void 0===s?S.minMatchCharLength:s,h=r.findAllMatches,f=void 0===h?S.findAllMatches:h,l=r.location,d=void 0===l?S.location:l,v=r.threshold,g=void 0===v?S.threshold:v,y=r.distance,p=void 0===y?S.distance:y;t(this,e),this.query=null,this.options={isCaseSensitive:o,includeMatches:a,minMatchCharLength:u,findAllMatches:f,location:d,threshold:g,distance:p},this.pattern=o?n:n.toLowerCase(),this.query=B(this.pattern,this.options)}return r(e,[{key:"searchIn",value:function(e){var t=this.query;if(!t)return{isMatch:!1,score:1};var n=this.options,r=n.includeMatches;e=n.isCaseSensitive?e:e.toLowerCase();for(var i=0,o=[],c=0,a=0,s=t.length;a1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;t(this,e),this.options=c({},S,{},r),this.options.useExtendedSearch,this._keyStore=new b(this.options.keys),this.setCollection(n,i)}return r(e,[{key:"setCollection",value:function(e,t){if(this._docs=e,t&&!(t instanceof L))throw new Error("Incorrect 'index' type");this._myIndex=t||O(this._keyStore.keys(),this._docs,{getFn:this.options.getFn})}},{key:"add",value:function(e){p(e)&&(this._docs.push(e),this._myIndex.add(e))}},{key:"remove",value:function(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:function(){return!1},t=[],n=0,r=this._docs.length;n1&&void 0!==arguments[1]?arguments[1]:{},n=t.limit,r=void 0===n?-1:n,i=this.options,o=i.includeMatches,c=i.includeScore,a=i.shouldSort,s=i.sortFn,u=i.ignoreFieldNorm,h=g(e)?g(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return re(h,this._keyStore,{ignoreFieldNorm:u}),a&&h.sort(s),y(r)&&r>-1&&(h=h.slice(0,r)),ie(h,this._docs,{includeMatches:o,includeScore:c})}},{key:"_searchStringList",value:function(e){var t=V(e,this.options),n=this._myIndex.records,r=[];return n.forEach((function(e){var n=e.v,i=e.i,o=e.n;if(p(n)){var c=t.searchIn(n),a=c.isMatch,s=c.score,u=c.indices;a&&r.push({item:n,idx:i,matches:[{score:s,value:n,norm:o,indices:u}]})}})),r}},{key:"_searchLogical",value:function(e){var t=this,n=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n.auto,i=void 0===r||r,o=function e(n){var r=Object.keys(n);if(r.length>1&&!Z(n))return e(te(n));var o=r[0];if(ee(n)){var c=n[o];if(!g(c))throw new Error(k(o));var a={key:o,pattern:c};return i&&(a.searcher=V(c,t)),a}var s={children:[],operator:o};return r.forEach((function(t){var r=n[t];v(r)&&r.forEach((function(t){s.children.push(e(t))}))})),s};return Z(e)||(e=te(e)),o(e)}(e,this.options),r=this._myIndex,i=r.keys,o=r.records,c={},a=[];return o.forEach((function(e){var r=e.$,o=e.i;p(r)&&function e(n,r,o){if(!n.children){var s=n.key,u=n.searcher,h=r[i.indexOf(s)];return t._findMatches({key:s,value:h,searcher:u})}for(var f=n.operator,d=[],v=0;v2&&void 0!==arguments[2]?arguments[2]:{},r=n.includeMatches,i=void 0===r?S.includeMatches:r,o=n.includeScore,c=void 0===o?S.includeScore:o,a=[];return i&&a.push(C),c&&a.push(A),e.map((function(e){var n=e.idx,r={item:t[n],refIndex:n};return a.length&&a.forEach((function(t){t(e,r)})),r}))}return ne.version="6.2.0",ne.createIndex=O,ne.parseIndex=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.getFn,r=void 0===n?S.getFn:n,i=e.keys,o=e.records,c=new L({getFn:r});return c.setKeys(i),c.setIndexRecords(o),c},ne.config=S,function(){Q.push.apply(Q,arguments)}(H),ne},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).Fuse=t(); \ No newline at end of file