Comparing version 5.2.0-alpha.0 to 5.2.0-alpha.1
/** | ||
* Fuse.js v5.2.0-alpha.0 - Lightweight fuzzy-search (http://fusejs.io) | ||
* Fuse.js v5.2.0-alpha.1 - Lightweight fuzzy-search (http://fusejs.io) | ||
* | ||
@@ -83,54 +83,2 @@ * Copyright (c) 2020 Kiro Risk (http://kiro.me) | ||
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; | ||
} | ||
var INFINITY = 1 / 0; | ||
@@ -258,3 +206,57 @@ var isArray = function isArray(value) { | ||
function bitapSearch(text, pattern, patternAlphabet) { | ||
function computeScore(pattern) { | ||
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
_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 ? Config.distance : _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 convertMaskToIndices() { | ||
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 search(text, pattern, patternAlphabet) { | ||
var _ref = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}, | ||
@@ -291,3 +293,3 @@ _ref$location = _ref.location, | ||
if (bestLocation !== -1) { | ||
var score = bitapScore(pattern, { | ||
var score = computeScore(pattern, { | ||
errors: 0, | ||
@@ -303,3 +305,3 @@ currentLocation: bestLocation, | ||
if (bestLocation !== -1) { | ||
var _score = bitapScore(pattern, { | ||
var _score = computeScore(pattern, { | ||
errors: 0, | ||
@@ -330,3 +332,3 @@ currentLocation: bestLocation, | ||
while (binMin < binMid) { | ||
var _score3 = bitapScore(pattern, { | ||
var _score3 = computeScore(pattern, { | ||
errors: _i, | ||
@@ -371,3 +373,3 @@ currentLocation: expectedLocation + binMid, | ||
if (bitArr[j] & mask) { | ||
finalScore = bitapScore(pattern, { | ||
finalScore = computeScore(pattern, { | ||
errors: _i, | ||
@@ -396,3 +398,3 @@ currentLocation: currentLocation, | ||
var _score2 = bitapScore(pattern, { | ||
var _score2 = computeScore(pattern, { | ||
errors: _i + 1, | ||
@@ -418,3 +420,3 @@ currentLocation: expectedLocation, | ||
if (includeMatches) { | ||
result.matchedIndices = matchedIndiced(matchMask, minMatchCharLength); | ||
result.matchedIndices = convertMaskToIndices(matchMask, minMatchCharLength); | ||
} | ||
@@ -425,3 +427,3 @@ | ||
function patternAlphabet(pattern) { | ||
function createPatternAlphabet(pattern) { | ||
var mask = {}; | ||
@@ -459,3 +461,3 @@ var len = pattern.length; | ||
this.pattern = this.options.isCaseSensitive ? pattern : pattern.toLowerCase(); | ||
this.patternAlphabet = patternAlphabet(this.pattern); | ||
this.patternAlphabet = createPatternAlphabet(this.pattern); | ||
} | ||
@@ -501,3 +503,3 @@ | ||
minMatchCharLength = _this$options2.minMatchCharLength; | ||
return bitapSearch(text, this.pattern, this.patternAlphabet, { | ||
return search(text, this.pattern, this.patternAlphabet, { | ||
location: location, | ||
@@ -516,6 +518,6 @@ distance: distance, | ||
var NGRAM_LEN = 3; | ||
function ngram(text, _ref) { | ||
var NGRAMS = 3; | ||
function createNGram(text, _ref) { | ||
var _ref$n = _ref.n, | ||
n = _ref$n === void 0 ? NGRAM_LEN : _ref$n, | ||
n = _ref$n === void 0 ? NGRAMS : _ref$n, | ||
_ref$pad = _ref.pad, | ||
@@ -580,3 +582,3 @@ pad = _ref$pad === void 0 ? true : _ref$pad, | ||
if (ngrams) { | ||
record.ng = ngram(value, { | ||
record.ng = createNGram(value, { | ||
sort: true | ||
@@ -635,3 +637,3 @@ }); | ||
if (ngrams) { | ||
subRecord.ng = ngram(_value2, { | ||
subRecord.ng = createNGram(_value2, { | ||
sort: true | ||
@@ -662,3 +664,3 @@ }); | ||
if (ngrams) { | ||
_subRecord.ng = ngram(_value, { | ||
_subRecord.ng = createNGram(_value, { | ||
sort: true | ||
@@ -1082,3 +1084,3 @@ }); | ||
Fuse.version = '5.2.0-alpha.0'; | ||
Fuse.version = '5.2.0-alpha.1'; | ||
Fuse.createIndex = createIndex; | ||
@@ -1085,0 +1087,0 @@ Fuse.config = Config; |
/** | ||
* Fuse.js v5.2.0-alpha.0 - Lightweight fuzzy-search (http://fusejs.io) | ||
* Fuse.js v5.2.0-alpha.1 - Lightweight fuzzy-search (http://fusejs.io) | ||
* | ||
@@ -10,44 +10,2 @@ * Copyright (c) 2020 Kiro Risk (http://kiro.me) | ||
function bitapScore( | ||
pattern, | ||
{ errors = 0, currentLocation = 0, expectedLocation = 0, distance = 100 } | ||
) { | ||
const accuracy = errors / pattern.length; | ||
const proximity = Math.abs(expectedLocation - currentLocation); | ||
if (!distance) { | ||
// Dodge divide by zero error. | ||
return proximity ? 1.0 : accuracy | ||
} | ||
return accuracy + proximity / distance | ||
} | ||
function matchedIndiced(matchmask = [], minMatchCharLength = 1) { | ||
let matchedIndices = []; | ||
let start = -1; | ||
let end = -1; | ||
let i = 0; | ||
for (let len = matchmask.length; i < len; i += 1) { | ||
let 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 | ||
} | ||
const INFINITY = 1 / 0; | ||
@@ -181,3 +139,53 @@ | ||
function bitapSearch( | ||
function computeScore( | ||
pattern, | ||
{ | ||
errors = 0, | ||
currentLocation = 0, | ||
expectedLocation = 0, | ||
distance = Config.distance | ||
} = {} | ||
) { | ||
const accuracy = errors / pattern.length; | ||
const proximity = Math.abs(expectedLocation - currentLocation); | ||
if (!distance) { | ||
// Dodge divide by zero error. | ||
return proximity ? 1.0 : accuracy | ||
} | ||
return accuracy + proximity / distance | ||
} | ||
function convertMaskToIndices( | ||
matchmask = [], | ||
minMatchCharLength = 1 | ||
) { | ||
let matchedIndices = []; | ||
let start = -1; | ||
let end = -1; | ||
let i = 0; | ||
for (let len = matchmask.length; i < len; i += 1) { | ||
let 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 search( | ||
text, | ||
@@ -212,3 +220,3 @@ pattern, | ||
if (bestLocation !== -1) { | ||
let score = bitapScore(pattern, { | ||
let score = computeScore(pattern, { | ||
errors: 0, | ||
@@ -225,3 +233,3 @@ currentLocation: bestLocation, | ||
if (bestLocation !== -1) { | ||
let score = bitapScore(pattern, { | ||
let score = computeScore(pattern, { | ||
errors: 0, | ||
@@ -253,3 +261,3 @@ currentLocation: bestLocation, | ||
while (binMin < binMid) { | ||
const score = bitapScore(pattern, { | ||
const score = computeScore(pattern, { | ||
errors: i, | ||
@@ -301,3 +309,3 @@ currentLocation: expectedLocation + binMid, | ||
if (bitArr[j] & mask) { | ||
finalScore = bitapScore(pattern, { | ||
finalScore = computeScore(pattern, { | ||
errors: i, | ||
@@ -328,3 +336,3 @@ currentLocation, | ||
// No hope for a (better) match at greater error levels. | ||
const score = bitapScore(pattern, { | ||
const score = computeScore(pattern, { | ||
errors: i + 1, | ||
@@ -350,3 +358,3 @@ currentLocation: expectedLocation, | ||
if (includeMatches) { | ||
result.matchedIndices = matchedIndiced(matchMask, minMatchCharLength); | ||
result.matchedIndices = convertMaskToIndices(matchMask, minMatchCharLength); | ||
} | ||
@@ -357,3 +365,3 @@ | ||
function patternAlphabet(pattern) { | ||
function createPatternAlphabet(pattern) { | ||
let mask = {}; | ||
@@ -405,3 +413,3 @@ let len = pattern.length; | ||
: pattern.toLowerCase(); | ||
this.patternAlphabet = patternAlphabet(this.pattern); | ||
this.patternAlphabet = createPatternAlphabet(this.pattern); | ||
} | ||
@@ -443,3 +451,4 @@ | ||
} = this.options; | ||
return bitapSearch(text, this.pattern, this.patternAlphabet, { | ||
return search(text, this.pattern, this.patternAlphabet, { | ||
location, | ||
@@ -455,7 +464,7 @@ distance, | ||
const NGRAM_LEN = 3; | ||
const NGRAMS = 3; | ||
function ngram( | ||
function createNGram( | ||
text, | ||
{ n = NGRAM_LEN, pad = true, sort = false } | ||
{ n = NGRAMS, pad = true, sort = false } | ||
) { | ||
@@ -513,3 +522,3 @@ let nGrams = []; | ||
if (ngrams) { | ||
record.ng = ngram(value, { sort: true }); | ||
record.ng = createNGram(value, { sort: true }); | ||
} | ||
@@ -557,3 +566,3 @@ | ||
if (ngrams) { | ||
subRecord.ng = ngram(value, { sort: true }); | ||
subRecord.ng = createNGram(value, { sort: true }); | ||
} | ||
@@ -580,3 +589,3 @@ | ||
if (ngrams) { | ||
subRecord.ng = ngram(value, { sort: true }); | ||
subRecord.ng = createNGram(value, { sort: true }); | ||
} | ||
@@ -948,3 +957,3 @@ | ||
Fuse.version = '5.2.0-alpha.0'; | ||
Fuse.version = '5.2.0-alpha.1'; | ||
Fuse.createIndex = createIndex; | ||
@@ -951,0 +960,0 @@ Fuse.config = Config; |
/** | ||
* Fuse.js v5.2.0-alpha.0 - Lightweight fuzzy-search (http://fusejs.io) | ||
* Fuse.js v5.2.0-alpha.1 - Lightweight fuzzy-search (http://fusejs.io) | ||
* | ||
@@ -9,2 +9,2 @@ * Copyright (c) 2020 Kiro Risk (http://kiro.me) | ||
*/ | ||
function t(t,{errors:e=0,currentLocation:s=0,expectedLocation:n=0,distance:i=100}){const r=e/t.length,o=Math.abs(n-s);return i?r+o/i:o?1:r}const e=t=>Array.isArray?Array.isArray(t):"[object Array]"===Object.prototype.toString.call(t),s=t=>"string"==typeof t,n=t=>"number"==typeof t,i=t=>null!=t;function r(t,r){let o=[],h=!1;const c=(t,r)=>{if(r){const l=r.indexOf(".");let a=r,u=null;-1!==l&&(a=r.slice(0,l),u=r.slice(l+1));const d=t[a];if(i(d))if(u||!s(d)&&!n(d))if(e(d)){h=!0;for(let t=0,e=d.length;t<e;t+=1)c(d[t],u)}else u&&c(d,u);else o.push((t=>null==t?"":(t=>{if("string"==typeof t)return t;let e=t+"";return"0"==e&&1/t==-1/0?"-0":e})(t))(d))}else o.push(t)};return c(t,r),h?o:o[0]}var o={isCaseSensitive:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score-e.score,includeMatches:!1,findAllMatches:!1,minMatchCharLength:1,location:0,threshold:.6,distance:100,...{useExtendedSearch:!1,getFn:r}};class h{constructor(t,e=({location:location=o.location,threshold:threshold=o.threshold,distance:distance=o.distance,includeMatches:includeMatches=o.includeMatches,findAllMatches:findAllMatches=o.findAllMatches,minMatchCharLength:minMatchCharLength=o.minMatchCharLength,isCaseSensitive:isCaseSensitive=o.isCaseSensitive}={})){if(this.options=e,t.length>32)throw new Error("Pattern length exceeds max of 32.");this.pattern=this.options.isCaseSensitive?t:t.toLowerCase(),this.patternAlphabet=function(t){let e={},s=t.length;for(let n=0;n<s;n+=1)e[t.charAt(n)]=0;for(let n=0;n<s;n+=1)e[t.charAt(n)]|=1<<s-n-1;return e}(this.pattern)}searchIn(t){let e=t.$;return this.searchInString(e)}searchInString(e){const{isCaseSensitive:s,includeMatches:n}=this.options;if(s||(e=e.toLowerCase()),this.pattern===e){let t={isMatch:!0,score:0};return n&&(t.matchedIndices=[[0,e.length-1]]),t}const{location:i,distance:r,threshold:h,findAllMatches:c,minMatchCharLength:l}=this.options;return function(e,s,n,{location:i=o.location,distance:r=o.distance,threshold:h=o.threshold,findAllMatches:c=o.findAllMatches,minMatchCharLength:l=o.minMatchCharLength,includeMatches:a=o.includeMatches}={}){const u=s.length,d=e.length,f=Math.max(0,Math.min(i,d));let g=h,p=e.indexOf(s,f);const y=[];for(let t=0;t<d;t+=1)y[t]=0;if(-1!==p){let n=t(s,{errors:0,currentLocation:p,expectedLocation:f,distance:r});if(g=Math.min(n,g),p=e.lastIndexOf(s,f+u),-1!==p){let e=t(s,{errors:0,currentLocation:p,expectedLocation:f,distance:r});g=Math.min(e,g)}}p=-1;let m=[],M=1,x=u+d;const _=1<<(u<=31?u-1:30);for(let i=0;i<u;i+=1){let o=0,h=x;for(;o<h;){t(s,{errors:i,currentLocation:f+h,expectedLocation:f,distance:r})<=g?o=h:x=h,h=Math.floor((x-o)/2+o)}x=h;let l=Math.max(1,f-h+1),a=c?d:Math.min(f+h,d)+u,k=Array(a+2);k[a+1]=(1<<i)-1;for(let o=a;o>=l;o-=1){let h=o-1,c=n[e.charAt(h)];if(c&&(y[h]=1),k[o]=(k[o+1]<<1|1)&c,0!==i&&(k[o]|=(m[o+1]|m[o])<<1|1|m[o+1]),k[o]&_&&(M=t(s,{errors:i,currentLocation:h,expectedLocation:f,distance:r}),M<=g)){if(g=M,p=h,p<=f)break;l=Math.max(1,2*f-p)}}if(t(s,{errors:i+1,currentLocation:f,expectedLocation:f,distance:r})>g)break;m=k}let k={isMatch:p>=0,score:M||.001};return a&&(k.matchedIndices=function(t=[],e=1){let s=[],n=-1,i=-1,r=0;for(let o=t.length;r<o;r+=1){let o=t[r];o&&-1===n?n=r:o||-1===n||(i=r-1,i-n+1>=e&&s.push([n,i]),n=-1)}return t[r-1]&&r-n>=e&&s.push([n,r-1]),s}(y,l)),k}(e,this.pattern,this.patternAlphabet,{location:i,distance:r,threshold:h,findAllMatches:c,minMatchCharLength:l,includeMatches:n})}}function c(t,{n:e=3,pad:s=!0,sort:n=!1}){let i=[];if(null==t)return i;t=t.toLowerCase(),s&&(t=` ${t} `);let r=t.length-e+1;if(r<1)return i;for(;r--;)i[r]=t.substr(r,e);return n&&i.sort((t,e)=>t==e?0:t<e?-1:1),i}function l(t,n,{getFn:o=r,ngrams:h=!1}={}){let l=[];if(s(n[0]))for(let t=0,e=n.length;t<e;t+=1){const e=n[t];if(i(e)){let s={$:e,idx:t};h&&(s.ng=c(e,{sort:!0})),l.push(s)}}else{const r=t.length;for(let a=0,u=n.length;a<u;a+=1){let u=n[a],d={idx:a,$:{}};for(let n=0;n<r;n+=1){let r=t[n],l=o(u,r);if(i(l))if(e(l)){let t=[];const n=[{arrayIndex:-1,value:l}];for(;n.length;){const{arrayIndex:r,value:o}=n.pop();if(i(o))if(s(o)){let e={$:o,idx:r};h&&(e.ng=c(o,{sort:!0})),t.push(e)}else if(e(o))for(let t=0,e=o.length;t<e;t+=1)n.push({arrayIndex:t,value:o[t]})}d.$[r]=t}else{let t={$:l};h&&(t.ng=c(l,{sort:!0})),d.$[r]=t}}l.push(d)}}return l}class a{constructor(t){if(this._keys={},this._keyNames=[],this._length=t.length,t.length&&s(t[0]))for(let e=0;e<this._length;e+=1){const s=t[e];this._keys[s]={weight:1},this._keyNames.push(s)}else{let e=0;for(let s=0;s<this._length;s+=1){const n=t[s];if(!Object.prototype.hasOwnProperty.call(n,"name"))throw new Error('Missing "name" property in key object');const i=n.name;if(this._keyNames.push(i),!Object.prototype.hasOwnProperty.call(n,"weight"))throw new Error('Missing "weight" property in key object');const r=n.weight;if(r<=0||r>=1)throw new Error('"weight" property in key must be in the range of (0, 1)');this._keys[i]={weight:r},e+=r}for(let t=0;t<this._length;t+=1){const s=this._keyNames[t],n=this._keys[s].weight;this._keys[s].weight=n/e}}}get(t,e){return this._keys[t]?this._keys[t][e]:-1}keys(){return this._keyNames}count(){return this._length}toJSON(){return JSON.stringify(this._keys)}}function u(t,e){const s=t.matches;if(e.matches=[],i(s))for(let t=0,n=s.length;t<n;t+=1){let n=s[t];if(!i(n.indices)||0===n.indices.length)continue;let r={indices:n.indices,value:n.value};n.key&&(r.key=n.key),n.idx>-1&&(r.refIndex=n.idx),e.matches.push(r)}}function d(t,e){e.score=t.score}const f=[];class g{constructor(t,e={},s=null){this.options={...o,...e},this._processKeys(this.options.keys),this.setCollection(t,s)}static register(...t){f.push(...t)}setCollection(t,e=null){this.list=t,this.listIsStringArray=s(t[0]),e?this.setIndex(e):this.setIndex(this._createIndex())}setIndex(t){this._indexedList=t}_processKeys(t){this._keyStore=new a(t)}_createIndex(){return l(this._keyStore.keys(),this.list,{getFn:this.options.getFn})}search(t,e={limit:!1}){const{shouldSort:s}=this.options;let i=null;for(let e=0,s=f.length;e<s;e+=1){let s=f[e];if(s.condition(t,this.options)){i=new s(t,this.options);break}}i||(i=new h(t,this.options));let r=this._searchUsing(i);return this._computeScore(r),s&&this._sort(r),e.limit&&n(e.limit)&&(r=r.slice(0,e.limit)),this._format(r)}_searchUsing(t){const s=this._indexedList,n=[],{includeMatches:r}=this.options;if(this.listIsStringArray)for(let e=0,o=s.length;e<o;e+=1){let o=s[e],{$:h,idx:c}=o;if(!i(h))continue;let l=t.searchIn(o);const{isMatch:a,score:u}=l;if(!a)continue;let d={score:u,value:h};r&&(d.indices=l.matchedIndices),n.push({item:h,idx:c,matches:[d]})}else{const o=this._keyStore.keys(),h=this._keyStore.count();for(let c=0,l=s.length;c<l;c+=1){let{$:l,idx:a}=s[c];if(!i(l))continue;let u=[];for(let s=0;s<h;s+=1){let n=o[s],h=l[n];if(i(h))if(e(h))for(let e=0,s=h.length;e<s;e+=1){let s=h[e],o=s.$,c=s.idx;if(!i(o))continue;let l=t.searchIn(s);const{isMatch:a,score:d}=l;if(!a)continue;let f={score:d,key:n,value:o,idx:c};r&&(f.indices=l.matchedIndices),u.push(f)}else{let e=h.$,s=t.searchIn(h);const{isMatch:i,score:o}=s;if(!i)continue;let c={score:o,key:n,value:e};r&&(c.indices=s.matchedIndices),u.push(c)}}u.length&&n.push({idx:a,item:l,matches:u})}}return n}_computeScore(t){for(let e=0,s=t.length;e<s;e+=1){const s=t[e],n=s.matches,i=n.length;let r=1;for(let t=0;t<i;t+=1){const e=n[t],s=e.key,i=this._keyStore.get(s,"weight"),o=i>-1?i:1,h=0===e.score&&i>-1?Number.EPSILON:e.score;r*=Math.pow(h,o)}s.score=r}}_sort(t){t.sort(this.options.sortFn)}_format(t){const e=[],{includeMatches:s,includeScore:n}=this.options;let i=[];s&&i.push(u),n&&i.push(d);for(let s=0,n=t.length;s<n;s+=1){const n=t[s],{idx:r}=n,o={item:this.list[r],refIndex:r};if(i.length)for(let t=0,e=i.length;t<e;t+=1)i[t](n,o);e.push(o)}return e}}g.version="5.2.0-alpha.0",g.createIndex=l,g.config=o;export default g; | ||
const t=t=>Array.isArray?Array.isArray(t):"[object Array]"===Object.prototype.toString.call(t),e=t=>"string"==typeof t,s=t=>"number"==typeof t,n=t=>null!=t;function i(i,r){let o=[],h=!1;const c=(i,r)=>{if(r){const l=r.indexOf(".");let a=r,u=null;-1!==l&&(a=r.slice(0,l),u=r.slice(l+1));const d=i[a];if(n(d))if(u||!e(d)&&!s(d))if(t(d)){h=!0;for(let t=0,e=d.length;t<e;t+=1)c(d[t],u)}else u&&c(d,u);else o.push((t=>null==t?"":(t=>{if("string"==typeof t)return t;let e=t+"";return"0"==e&&1/t==-1/0?"-0":e})(t))(d))}else o.push(i)};return c(i,r),h?o:o[0]}var r={isCaseSensitive:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score-e.score,includeMatches:!1,findAllMatches:!1,minMatchCharLength:1,location:0,threshold:.6,distance:100,...{useExtendedSearch:!1,getFn:i}};function o(t,{errors:e=0,currentLocation:s=0,expectedLocation:n=0,distance:i=r.distance}={}){const o=e/t.length,h=Math.abs(n-s);return i?o+h/i:h?1:o}class h{constructor(t,e=({location:location=r.location,threshold:threshold=r.threshold,distance:distance=r.distance,includeMatches:includeMatches=r.includeMatches,findAllMatches:findAllMatches=r.findAllMatches,minMatchCharLength:minMatchCharLength=r.minMatchCharLength,isCaseSensitive:isCaseSensitive=r.isCaseSensitive}={})){if(this.options=e,t.length>32)throw new Error("Pattern length exceeds max of 32.");this.pattern=this.options.isCaseSensitive?t:t.toLowerCase(),this.patternAlphabet=function(t){let e={},s=t.length;for(let n=0;n<s;n+=1)e[t.charAt(n)]=0;for(let n=0;n<s;n+=1)e[t.charAt(n)]|=1<<s-n-1;return e}(this.pattern)}searchIn(t){let e=t.$;return this.searchInString(e)}searchInString(t){const{isCaseSensitive:e,includeMatches:s}=this.options;if(e||(t=t.toLowerCase()),this.pattern===t){let e={isMatch:!0,score:0};return s&&(e.matchedIndices=[[0,t.length-1]]),e}const{location:n,distance:i,threshold:h,findAllMatches:c,minMatchCharLength:l}=this.options;return function(t,e,s,{location:n=r.location,distance:i=r.distance,threshold:h=r.threshold,findAllMatches:c=r.findAllMatches,minMatchCharLength:l=r.minMatchCharLength,includeMatches:a=r.includeMatches}={}){const u=e.length,d=t.length,f=Math.max(0,Math.min(n,d));let g=h,p=t.indexOf(e,f);const y=[];for(let t=0;t<d;t+=1)y[t]=0;if(-1!==p){let s=o(e,{errors:0,currentLocation:p,expectedLocation:f,distance:i});if(g=Math.min(s,g),p=t.lastIndexOf(e,f+u),-1!==p){let t=o(e,{errors:0,currentLocation:p,expectedLocation:f,distance:i});g=Math.min(t,g)}}p=-1;let m=[],M=1,x=u+d;const _=1<<(u<=31?u-1:30);for(let n=0;n<u;n+=1){let r=0,h=x;for(;r<h;){o(e,{errors:n,currentLocation:f+h,expectedLocation:f,distance:i})<=g?r=h:x=h,h=Math.floor((x-r)/2+r)}x=h;let l=Math.max(1,f-h+1),a=c?d:Math.min(f+h,d)+u,k=Array(a+2);k[a+1]=(1<<n)-1;for(let r=a;r>=l;r-=1){let h=r-1,c=s[t.charAt(h)];if(c&&(y[h]=1),k[r]=(k[r+1]<<1|1)&c,0!==n&&(k[r]|=(m[r+1]|m[r])<<1|1|m[r+1]),k[r]&_&&(M=o(e,{errors:n,currentLocation:h,expectedLocation:f,distance:i}),M<=g)){if(g=M,p=h,p<=f)break;l=Math.max(1,2*f-p)}}if(o(e,{errors:n+1,currentLocation:f,expectedLocation:f,distance:i})>g)break;m=k}let k={isMatch:p>=0,score:M||.001};return a&&(k.matchedIndices=function(t=[],e=1){let s=[],n=-1,i=-1,r=0;for(let o=t.length;r<o;r+=1){let o=t[r];o&&-1===n?n=r:o||-1===n||(i=r-1,i-n+1>=e&&s.push([n,i]),n=-1)}return t[r-1]&&r-n>=e&&s.push([n,r-1]),s}(y,l)),k}(t,this.pattern,this.patternAlphabet,{location:n,distance:i,threshold:h,findAllMatches:c,minMatchCharLength:l,includeMatches:s})}}function c(t,{n:e=3,pad:s=!0,sort:n=!1}){let i=[];if(null==t)return i;t=t.toLowerCase(),s&&(t=` ${t} `);let r=t.length-e+1;if(r<1)return i;for(;r--;)i[r]=t.substr(r,e);return n&&i.sort((t,e)=>t==e?0:t<e?-1:1),i}function l(s,r,{getFn:o=i,ngrams:h=!1}={}){let l=[];if(e(r[0]))for(let t=0,e=r.length;t<e;t+=1){const e=r[t];if(n(e)){let s={$:e,idx:t};h&&(s.ng=c(e,{sort:!0})),l.push(s)}}else{const i=s.length;for(let a=0,u=r.length;a<u;a+=1){let u=r[a],d={idx:a,$:{}};for(let r=0;r<i;r+=1){let i=s[r],l=o(u,i);if(n(l))if(t(l)){let s=[];const r=[{arrayIndex:-1,value:l}];for(;r.length;){const{arrayIndex:i,value:o}=r.pop();if(n(o))if(e(o)){let t={$:o,idx:i};h&&(t.ng=c(o,{sort:!0})),s.push(t)}else if(t(o))for(let t=0,e=o.length;t<e;t+=1)r.push({arrayIndex:t,value:o[t]})}d.$[i]=s}else{let t={$:l};h&&(t.ng=c(l,{sort:!0})),d.$[i]=t}}l.push(d)}}return l}class a{constructor(t){if(this._keys={},this._keyNames=[],this._length=t.length,t.length&&e(t[0]))for(let e=0;e<this._length;e+=1){const s=t[e];this._keys[s]={weight:1},this._keyNames.push(s)}else{let e=0;for(let s=0;s<this._length;s+=1){const n=t[s];if(!Object.prototype.hasOwnProperty.call(n,"name"))throw new Error('Missing "name" property in key object');const i=n.name;if(this._keyNames.push(i),!Object.prototype.hasOwnProperty.call(n,"weight"))throw new Error('Missing "weight" property in key object');const r=n.weight;if(r<=0||r>=1)throw new Error('"weight" property in key must be in the range of (0, 1)');this._keys[i]={weight:r},e+=r}for(let t=0;t<this._length;t+=1){const s=this._keyNames[t],n=this._keys[s].weight;this._keys[s].weight=n/e}}}get(t,e){return this._keys[t]?this._keys[t][e]:-1}keys(){return this._keyNames}count(){return this._length}toJSON(){return JSON.stringify(this._keys)}}function u(t,e){const s=t.matches;if(e.matches=[],n(s))for(let t=0,i=s.length;t<i;t+=1){let i=s[t];if(!n(i.indices)||0===i.indices.length)continue;let r={indices:i.indices,value:i.value};i.key&&(r.key=i.key),i.idx>-1&&(r.refIndex=i.idx),e.matches.push(r)}}function d(t,e){e.score=t.score}const f=[];class g{constructor(t,e={},s=null){this.options={...r,...e},this._processKeys(this.options.keys),this.setCollection(t,s)}static register(...t){f.push(...t)}setCollection(t,s=null){this.list=t,this.listIsStringArray=e(t[0]),s?this.setIndex(s):this.setIndex(this._createIndex())}setIndex(t){this._indexedList=t}_processKeys(t){this._keyStore=new a(t)}_createIndex(){return l(this._keyStore.keys(),this.list,{getFn:this.options.getFn})}search(t,e={limit:!1}){const{shouldSort:n}=this.options;let i=null;for(let e=0,s=f.length;e<s;e+=1){let s=f[e];if(s.condition(t,this.options)){i=new s(t,this.options);break}}i||(i=new h(t,this.options));let r=this._searchUsing(i);return this._computeScore(r),n&&this._sort(r),e.limit&&s(e.limit)&&(r=r.slice(0,e.limit)),this._format(r)}_searchUsing(e){const s=this._indexedList,i=[],{includeMatches:r}=this.options;if(this.listIsStringArray)for(let t=0,o=s.length;t<o;t+=1){let o=s[t],{$:h,idx:c}=o;if(!n(h))continue;let l=e.searchIn(o);const{isMatch:a,score:u}=l;if(!a)continue;let d={score:u,value:h};r&&(d.indices=l.matchedIndices),i.push({item:h,idx:c,matches:[d]})}else{const o=this._keyStore.keys(),h=this._keyStore.count();for(let c=0,l=s.length;c<l;c+=1){let{$:l,idx:a}=s[c];if(!n(l))continue;let u=[];for(let s=0;s<h;s+=1){let i=o[s],h=l[i];if(n(h))if(t(h))for(let t=0,s=h.length;t<s;t+=1){let s=h[t],o=s.$,c=s.idx;if(!n(o))continue;let l=e.searchIn(s);const{isMatch:a,score:d}=l;if(!a)continue;let f={score:d,key:i,value:o,idx:c};r&&(f.indices=l.matchedIndices),u.push(f)}else{let t=h.$,s=e.searchIn(h);const{isMatch:n,score:o}=s;if(!n)continue;let c={score:o,key:i,value:t};r&&(c.indices=s.matchedIndices),u.push(c)}}u.length&&i.push({idx:a,item:l,matches:u})}}return i}_computeScore(t){for(let e=0,s=t.length;e<s;e+=1){const s=t[e],n=s.matches,i=n.length;let r=1;for(let t=0;t<i;t+=1){const e=n[t],s=e.key,i=this._keyStore.get(s,"weight"),o=i>-1?i:1,h=0===e.score&&i>-1?Number.EPSILON:e.score;r*=Math.pow(h,o)}s.score=r}}_sort(t){t.sort(this.options.sortFn)}_format(t){const e=[],{includeMatches:s,includeScore:n}=this.options;let i=[];s&&i.push(u),n&&i.push(d);for(let s=0,n=t.length;s<n;s+=1){const n=t[s],{idx:r}=n,o={item:this.list[r],refIndex:r};if(i.length)for(let t=0,e=i.length;t<e;t+=1)i[t](n,o);e.push(o)}return e}}g.version="5.2.0-alpha.1",g.createIndex=l,g.config=r;export default g; |
/** | ||
* Fuse.js v5.2.0-alpha.0 - Lightweight fuzzy-search (http://fusejs.io) | ||
* Fuse.js v5.2.0-alpha.1 - Lightweight fuzzy-search (http://fusejs.io) | ||
* | ||
@@ -87,54 +87,2 @@ * Copyright (c) 2020 Kiro Risk (http://kiro.me) | ||
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; | ||
} | ||
var INFINITY = 1 / 0; | ||
@@ -262,3 +210,57 @@ var isArray = function isArray(value) { | ||
function bitapSearch(text, pattern, patternAlphabet) { | ||
function computeScore(pattern) { | ||
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
_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 ? Config.distance : _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 convertMaskToIndices() { | ||
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 search(text, pattern, patternAlphabet) { | ||
var _ref = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}, | ||
@@ -295,3 +297,3 @@ _ref$location = _ref.location, | ||
if (bestLocation !== -1) { | ||
var score = bitapScore(pattern, { | ||
var score = computeScore(pattern, { | ||
errors: 0, | ||
@@ -307,3 +309,3 @@ currentLocation: bestLocation, | ||
if (bestLocation !== -1) { | ||
var _score = bitapScore(pattern, { | ||
var _score = computeScore(pattern, { | ||
errors: 0, | ||
@@ -334,3 +336,3 @@ currentLocation: bestLocation, | ||
while (binMin < binMid) { | ||
var _score3 = bitapScore(pattern, { | ||
var _score3 = computeScore(pattern, { | ||
errors: _i, | ||
@@ -375,3 +377,3 @@ currentLocation: expectedLocation + binMid, | ||
if (bitArr[j] & mask) { | ||
finalScore = bitapScore(pattern, { | ||
finalScore = computeScore(pattern, { | ||
errors: _i, | ||
@@ -400,3 +402,3 @@ currentLocation: currentLocation, | ||
var _score2 = bitapScore(pattern, { | ||
var _score2 = computeScore(pattern, { | ||
errors: _i + 1, | ||
@@ -422,3 +424,3 @@ currentLocation: expectedLocation, | ||
if (includeMatches) { | ||
result.matchedIndices = matchedIndiced(matchMask, minMatchCharLength); | ||
result.matchedIndices = convertMaskToIndices(matchMask, minMatchCharLength); | ||
} | ||
@@ -429,3 +431,3 @@ | ||
function patternAlphabet(pattern) { | ||
function createPatternAlphabet(pattern) { | ||
var mask = {}; | ||
@@ -463,3 +465,3 @@ var len = pattern.length; | ||
this.pattern = this.options.isCaseSensitive ? pattern : pattern.toLowerCase(); | ||
this.patternAlphabet = patternAlphabet(this.pattern); | ||
this.patternAlphabet = createPatternAlphabet(this.pattern); | ||
} | ||
@@ -505,3 +507,3 @@ | ||
minMatchCharLength = _this$options2.minMatchCharLength; | ||
return bitapSearch(text, this.pattern, this.patternAlphabet, { | ||
return search(text, this.pattern, this.patternAlphabet, { | ||
location: location, | ||
@@ -520,6 +522,6 @@ distance: distance, | ||
var NGRAM_LEN = 3; | ||
function ngram(text, _ref) { | ||
var NGRAMS = 3; | ||
function createNGram(text, _ref) { | ||
var _ref$n = _ref.n, | ||
n = _ref$n === void 0 ? NGRAM_LEN : _ref$n, | ||
n = _ref$n === void 0 ? NGRAMS : _ref$n, | ||
_ref$pad = _ref.pad, | ||
@@ -584,3 +586,3 @@ pad = _ref$pad === void 0 ? true : _ref$pad, | ||
if (ngrams) { | ||
record.ng = ngram(value, { | ||
record.ng = createNGram(value, { | ||
sort: true | ||
@@ -639,3 +641,3 @@ }); | ||
if (ngrams) { | ||
subRecord.ng = ngram(_value2, { | ||
subRecord.ng = createNGram(_value2, { | ||
sort: true | ||
@@ -666,3 +668,3 @@ }); | ||
if (ngrams) { | ||
_subRecord.ng = ngram(_value, { | ||
_subRecord.ng = createNGram(_value, { | ||
sort: true | ||
@@ -1086,3 +1088,3 @@ }); | ||
Fuse.version = '5.2.0-alpha.0'; | ||
Fuse.version = '5.2.0-alpha.1'; | ||
Fuse.createIndex = createIndex; | ||
@@ -1089,0 +1091,0 @@ Fuse.config = Config; |
/** | ||
* Fuse.js v5.2.0-alpha.0 - Lightweight fuzzy-search (http://fusejs.io) | ||
* Fuse.js v5.2.0-alpha.1 - Lightweight fuzzy-search (http://fusejs.io) | ||
* | ||
@@ -9,2 +9,2 @@ * Copyright (c) 2020 Kiro Risk (http://kiro.me) | ||
*/ | ||
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 r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function r(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function i(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function o(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?i(Object(r),!0).forEach((function(t){n(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):i(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function s(e,t){var r=t.errors,n=void 0===r?0:r,i=t.currentLocation,o=void 0===i?0:i,s=t.expectedLocation,a=void 0===s?0:s,c=t.distance,h=void 0===c?100:c,l=n/e.length,u=Math.abs(a-o);return h?l+u/h:u?1:l}function a(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,r=[],n=-1,i=-1,o=0,s=e.length;o<s;o+=1){var a=e[o];a&&-1===n?n=o:a||-1===n||((i=o-1)-n+1>=t&&r.push([n,i]),n=-1)}return e[o-1]&&o-n>=t&&r.push([n,o-1]),r}var c=function(e){return Array.isArray?Array.isArray(e):"[object Array]"===Object.prototype.toString.call(e)},h=function(e){return"string"==typeof e},l=function(e){return"number"==typeof e},u=function(e){return null!=e};function f(e,t){var r=[],n=!1;return function e(t,i){if(i){var o=i.indexOf("."),s=i,a=null;-1!==o&&(s=i.slice(0,o),a=i.slice(o+1));var f=t[s];if(u(f))if(a||!h(f)&&!l(f))if(c(f)){n=!0;for(var v=0,d=f.length;v<d;v+=1)e(f[v],a)}else a&&e(f,a);else r.push(function(e){return null==e?"":function(e){if("string"==typeof e)return e;var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}(e)}(f))}else r.push(t)}(e,t),n?r:r[0]}var v=o({},{isCaseSensitive:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:function(e,t){return e.score-t.score}},{},{includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},{},{location:0,threshold:.6,distance:100},{},{useExtendedSearch:!1,getFn:f});function d(e){for(var t={},r=e.length,n=0;n<r;n+=1)t[e.charAt(n)]=0;for(var i=0;i<r;i+=1)t[e.charAt(i)]|=1<<r-i-1;return t}var p=function(){function t(r){var n,i,o,s,a,c,h,l,u=arguments.length>1&&void 0!==arguments[1]?arguments[1]:(i=(n={}).location,location=void 0===i?v.location:i,o=n.threshold,threshold=void 0===o?v.threshold:o,s=n.distance,distance=void 0===s?v.distance:s,a=n.includeMatches,includeMatches=void 0===a?v.includeMatches:a,c=n.findAllMatches,findAllMatches=void 0===c?v.findAllMatches:c,h=n.minMatchCharLength,minMatchCharLength=void 0===h?v.minMatchCharLength:h,l=n.isCaseSensitive,isCaseSensitive=void 0===l?v.isCaseSensitive:l,n);if(e(this,t),this.options=u,r.length>32)throw new Error("Pattern length exceeds max of ".concat(32,"."));this.pattern=this.options.isCaseSensitive?r:r.toLowerCase(),this.patternAlphabet=d(this.pattern)}return r(t,[{key:"searchIn",value:function(e){var t=e.$;return this.searchInString(t)}},{key:"searchInString",value:function(e){var t=this.options,r=t.isCaseSensitive,n=t.includeMatches;if(r||(e=e.toLowerCase()),this.pattern===e){var i={isMatch:!0,score:0};return n&&(i.matchedIndices=[[0,e.length-1]]),i}var o=this.options,c=o.location,h=o.distance,l=o.threshold,u=o.findAllMatches,f=o.minMatchCharLength;return function(e,t,r){for(var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},i=n.location,o=void 0===i?v.location:i,c=n.distance,h=void 0===c?v.distance:c,l=n.threshold,u=void 0===l?v.threshold:l,f=n.findAllMatches,d=void 0===f?v.findAllMatches:f,p=n.minMatchCharLength,g=void 0===p?v.minMatchCharLength:p,y=n.includeMatches,m=void 0===y?v.includeMatches:y,k=t.length,M=e.length,x=Math.max(0,Math.min(o,M)),b=u,_=e.indexOf(t,x),w=[],O=0;O<M;O+=1)w[O]=0;if(-1!==_){var S=s(t,{errors:0,currentLocation:_,expectedLocation:x,distance:h});if(b=Math.min(S,b),-1!==(_=e.lastIndexOf(t,x+k))){var I=s(t,{errors:0,currentLocation:_,expectedLocation:x,distance:h});b=Math.min(I,b)}}_=-1;for(var L=[],A=1,j=k+M,C=1<<(k<=31?k-1:30),P=0;P<k;P+=1){for(var $=0,E=j;$<E;){var N=s(t,{errors:P,currentLocation:x+E,expectedLocation:x,distance:h});N<=b?$=E:j=E,E=Math.floor((j-$)/2+$)}j=E;var F=Math.max(1,x-E+1),D=d?M:Math.min(x+E,M)+k,J=Array(D+2);J[D+1]=(1<<P)-1;for(var K=D;K>=F;K-=1){var U=K-1,T=r[e.charAt(U)];if(T&&(w[U]=1),J[K]=(J[K+1]<<1|1)&T,0!==P&&(J[K]|=(L[K+1]|L[K])<<1|1|L[K+1]),J[K]&C&&(A=s(t,{errors:P,currentLocation:U,expectedLocation:x,distance:h}))<=b){if(b=A,(_=U)<=x)break;F=Math.max(1,2*x-_)}}var q=s(t,{errors:P+1,currentLocation:x,expectedLocation:x,distance:h});if(q>b)break;L=J}var z={isMatch:_>=0,score:A||.001};return m&&(z.matchedIndices=a(w,g)),z}(e,this.pattern,this.patternAlphabet,{location:c,distance:h,threshold:l,findAllMatches:u,minMatchCharLength:f,includeMatches:n})}}]),t}();function g(e,t){var r=t.n,n=void 0===r?3:r,i=t.pad,o=void 0===i||i,s=t.sort,a=void 0!==s&&s,c=[];if(null==e)return c;e=e.toLowerCase(),o&&(e=" ".concat(e," "));var h=e.length-n+1;if(h<1)return c;for(;h--;)c[h]=e.substr(h,n);return a&&c.sort((function(e,t){return e==t?0:e<t?-1:1})),c}function y(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r.getFn,i=void 0===n?f:n,o=r.ngrams,s=void 0!==o&&o,a=[];if(h(t[0]))for(var l=0,v=t.length;l<v;l+=1){var d=t[l];if(u(d)){var p={$:d,idx:l};s&&(p.ng=g(d,{sort:!0})),a.push(p)}}else for(var y=e.length,m=0,k=t.length;m<k;m+=1){for(var M=t[m],x={idx:m,$:{}},b=0;b<y;b+=1){var _=e[b],w=i(M,_);if(u(w))if(c(w)){for(var O=[],S=[{arrayIndex:-1,value:w}];S.length;){var I=S.pop(),L=I.arrayIndex,A=I.value;if(u(A))if(h(A)){var j={$:A,idx:L};s&&(j.ng=g(A,{sort:!0})),O.push(j)}else if(c(A))for(var C=0,P=A.length;C<P;C+=1)S.push({arrayIndex:C,value:A[C]})}x.$[_]=O}else{var $={$:w};s&&($.ng=g(w,{sort:!0})),x.$[_]=$}}a.push(x)}return a}var m=function(){function t(r){if(e(this,t),this._keys={},this._keyNames=[],this._length=r.length,r.length&&h(r[0]))for(var n=0;n<this._length;n+=1){var i=r[n];this._keys[i]={weight:1},this._keyNames.push(i)}else{for(var o=0,s=0;s<this._length;s+=1){var a=r[s];if(!Object.prototype.hasOwnProperty.call(a,"name"))throw new Error('Missing "name" property in key object');var c=a.name;if(this._keyNames.push(c),!Object.prototype.hasOwnProperty.call(a,"weight"))throw new Error('Missing "weight" property in key object');var l=a.weight;if(l<=0||l>=1)throw new Error('"weight" property in key must be in the range of (0, 1)');this._keys[c]={weight:l},o+=l}for(var u=0;u<this._length;u+=1){var f=this._keyNames[u],v=this._keys[f].weight;this._keys[f].weight=v/o}}}return r(t,[{key:"get",value:function(e,t){return this._keys[e]?this._keys[e][t]:-1}},{key:"keys",value:function(){return this._keyNames}},{key:"count",value:function(){return this._length}},{key:"toJSON",value:function(){return JSON.stringify(this._keys)}}]),t}();function k(e,t){var r=e.matches;if(t.matches=[],u(r))for(var n=0,i=r.length;n<i;n+=1){var o=r[n];if(u(o.indices)&&0!==o.indices.length){var s={indices:o.indices,value:o.value};o.key&&(s.key=o.key),o.idx>-1&&(s.refIndex=o.idx),t.matches.push(s)}}}function M(e,t){t.score=e.score}var x=[],b=function(){function t(r){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;e(this,t),this.options=o({},v,{},n),this._processKeys(this.options.keys),this.setCollection(r,i)}return r(t,[{key:"setCollection",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;this.list=e,this.listIsStringArray=h(e[0]),t?this.setIndex(t):this.setIndex(this._createIndex())}},{key:"setIndex",value:function(e){this._indexedList=e}},{key:"_processKeys",value:function(e){this._keyStore=new m(e)}},{key:"_createIndex",value:function(){return y(this._keyStore.keys(),this.list,{getFn:this.options.getFn})}},{key:"search",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{limit:!1},r=this.options.shouldSort,n=null,i=0,o=x.length;i<o;i+=1){var s=x[i];if(s.condition(e,this.options)){n=new s(e,this.options);break}}n||(n=new p(e,this.options));var a=this._searchUsing(n);return this._computeScore(a),r&&this._sort(a),t.limit&&l(t.limit)&&(a=a.slice(0,t.limit)),this._format(a)}},{key:"_searchUsing",value:function(e){var t=this._indexedList,r=[],n=this.options.includeMatches;if(this.listIsStringArray)for(var i=0,o=t.length;i<o;i+=1){var s=t[i],a=s.$,h=s.idx;if(u(a)){var l=e.searchIn(s),f=l.isMatch,v=l.score;if(f){var d={score:v,value:a};n&&(d.indices=l.matchedIndices),r.push({item:a,idx:h,matches:[d]})}}}else for(var p=this._keyStore.keys(),g=this._keyStore.count(),y=0,m=t.length;y<m;y+=1){var k=t[y],M=k.$,x=k.idx;if(u(M)){for(var b=[],_=0;_<g;_+=1){var w=p[_],O=M[w];if(u(O))if(c(O))for(var S=0,I=O.length;S<I;S+=1){var L=O[S],A=L.$,j=L.idx;if(u(A)){var C=e.searchIn(L),P=C.isMatch,$=C.score;if(P){var E={score:$,key:w,value:A,idx:j};n&&(E.indices=C.matchedIndices),b.push(E)}}}else{var N=O.$,F=e.searchIn(O),D=F.isMatch,J=F.score;if(!D)continue;var K={score:J,key:w,value:N};n&&(K.indices=F.matchedIndices),b.push(K)}}b.length&&r.push({idx:x,item:M,matches:b})}}return r}},{key:"_computeScore",value:function(e){for(var t=0,r=e.length;t<r;t+=1){for(var n=e[t],i=n.matches,o=i.length,s=1,a=0;a<o;a+=1){var c=i[a],h=c.key,l=this._keyStore.get(h,"weight"),u=l>-1?l:1,f=0===c.score&&l>-1?Number.EPSILON:c.score;s*=Math.pow(f,u)}n.score=s}}},{key:"_sort",value:function(e){e.sort(this.options.sortFn)}},{key:"_format",value:function(e){var t=[],r=this.options,n=r.includeMatches,i=r.includeScore,o=[];n&&o.push(k),i&&o.push(M);for(var s=0,a=e.length;s<a;s+=1){var c=e[s],h=c.idx,l={item:this.list[h],refIndex:h};if(o.length)for(var u=0,f=o.length;u<f;u+=1)o[u](c,l);t.push(l)}return t}}],[{key:"register",value:function(){x.push.apply(x,arguments)}}]),t}();return b.version="5.2.0-alpha.0",b.createIndex=y,b.config=v,b},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).Fuse=t(); | ||
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 r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function r(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function i(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function o(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?i(Object(r),!0).forEach((function(t){n(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):i(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var s=function(e){return Array.isArray?Array.isArray(e):"[object Array]"===Object.prototype.toString.call(e)},a=function(e){return"string"==typeof e},c=function(e){return"number"==typeof e},h=function(e){return null!=e};function l(e,t){var r=[],n=!1;return function e(t,i){if(i){var o=i.indexOf("."),l=i,u=null;-1!==o&&(l=i.slice(0,o),u=i.slice(o+1));var f=t[l];if(h(f))if(u||!a(f)&&!c(f))if(s(f)){n=!0;for(var v=0,d=f.length;v<d;v+=1)e(f[v],u)}else u&&e(f,u);else r.push(function(e){return null==e?"":function(e){if("string"==typeof e)return e;var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}(e)}(f))}else r.push(t)}(e,t),n?r:r[0]}var u=o({},{isCaseSensitive:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:function(e,t){return e.score-t.score}},{},{includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},{},{location:0,threshold:.6,distance:100},{},{useExtendedSearch:!1,getFn:l});function f(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.errors,n=void 0===r?0:r,i=t.currentLocation,o=void 0===i?0:i,s=t.expectedLocation,a=void 0===s?0:s,c=t.distance,h=void 0===c?u.distance:c,l=n/e.length,f=Math.abs(a-o);return h?l+f/h:f?1:l}function v(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,r=[],n=-1,i=-1,o=0,s=e.length;o<s;o+=1){var a=e[o];a&&-1===n?n=o:a||-1===n||((i=o-1)-n+1>=t&&r.push([n,i]),n=-1)}return e[o-1]&&o-n>=t&&r.push([n,o-1]),r}function d(e){for(var t={},r=e.length,n=0;n<r;n+=1)t[e.charAt(n)]=0;for(var i=0;i<r;i+=1)t[e.charAt(i)]|=1<<r-i-1;return t}var p=function(){function t(r){var n,i,o,s,a,c,h,l,f=arguments.length>1&&void 0!==arguments[1]?arguments[1]:(i=(n={}).location,location=void 0===i?u.location:i,o=n.threshold,threshold=void 0===o?u.threshold:o,s=n.distance,distance=void 0===s?u.distance:s,a=n.includeMatches,includeMatches=void 0===a?u.includeMatches:a,c=n.findAllMatches,findAllMatches=void 0===c?u.findAllMatches:c,h=n.minMatchCharLength,minMatchCharLength=void 0===h?u.minMatchCharLength:h,l=n.isCaseSensitive,isCaseSensitive=void 0===l?u.isCaseSensitive:l,n);if(e(this,t),this.options=f,r.length>32)throw new Error("Pattern length exceeds max of ".concat(32,"."));this.pattern=this.options.isCaseSensitive?r:r.toLowerCase(),this.patternAlphabet=d(this.pattern)}return r(t,[{key:"searchIn",value:function(e){var t=e.$;return this.searchInString(t)}},{key:"searchInString",value:function(e){var t=this.options,r=t.isCaseSensitive,n=t.includeMatches;if(r||(e=e.toLowerCase()),this.pattern===e){var i={isMatch:!0,score:0};return n&&(i.matchedIndices=[[0,e.length-1]]),i}var o=this.options,s=o.location,a=o.distance,c=o.threshold,h=o.findAllMatches,l=o.minMatchCharLength;return function(e,t,r){for(var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},i=n.location,o=void 0===i?u.location:i,s=n.distance,a=void 0===s?u.distance:s,c=n.threshold,h=void 0===c?u.threshold:c,l=n.findAllMatches,d=void 0===l?u.findAllMatches:l,p=n.minMatchCharLength,g=void 0===p?u.minMatchCharLength:p,y=n.includeMatches,m=void 0===y?u.includeMatches:y,k=t.length,M=e.length,x=Math.max(0,Math.min(o,M)),b=h,_=e.indexOf(t,x),w=[],O=0;O<M;O+=1)w[O]=0;if(-1!==_){var S=f(t,{errors:0,currentLocation:_,expectedLocation:x,distance:a});if(b=Math.min(S,b),-1!==(_=e.lastIndexOf(t,x+k))){var I=f(t,{errors:0,currentLocation:_,expectedLocation:x,distance:a});b=Math.min(I,b)}}_=-1;for(var L=[],A=1,j=k+M,C=1<<(k<=31?k-1:30),P=0;P<k;P+=1){for(var $=0,E=j;$<E;){var N=f(t,{errors:P,currentLocation:x+E,expectedLocation:x,distance:a});N<=b?$=E:j=E,E=Math.floor((j-$)/2+$)}j=E;var F=Math.max(1,x-E+1),D=d?M:Math.min(x+E,M)+k,J=Array(D+2);J[D+1]=(1<<P)-1;for(var K=D;K>=F;K-=1){var U=K-1,T=r[e.charAt(U)];if(T&&(w[U]=1),J[K]=(J[K+1]<<1|1)&T,0!==P&&(J[K]|=(L[K+1]|L[K])<<1|1|L[K+1]),J[K]&C&&(A=f(t,{errors:P,currentLocation:U,expectedLocation:x,distance:a}))<=b){if(b=A,(_=U)<=x)break;F=Math.max(1,2*x-_)}}var q=f(t,{errors:P+1,currentLocation:x,expectedLocation:x,distance:a});if(q>b)break;L=J}var z={isMatch:_>=0,score:A||.001};return m&&(z.matchedIndices=v(w,g)),z}(e,this.pattern,this.patternAlphabet,{location:s,distance:a,threshold:c,findAllMatches:h,minMatchCharLength:l,includeMatches:n})}}]),t}();function g(e,t){var r=t.n,n=void 0===r?3:r,i=t.pad,o=void 0===i||i,s=t.sort,a=void 0!==s&&s,c=[];if(null==e)return c;e=e.toLowerCase(),o&&(e=" ".concat(e," "));var h=e.length-n+1;if(h<1)return c;for(;h--;)c[h]=e.substr(h,n);return a&&c.sort((function(e,t){return e==t?0:e<t?-1:1})),c}function y(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r.getFn,i=void 0===n?l:n,o=r.ngrams,c=void 0!==o&&o,u=[];if(a(t[0]))for(var f=0,v=t.length;f<v;f+=1){var d=t[f];if(h(d)){var p={$:d,idx:f};c&&(p.ng=g(d,{sort:!0})),u.push(p)}}else for(var y=e.length,m=0,k=t.length;m<k;m+=1){for(var M=t[m],x={idx:m,$:{}},b=0;b<y;b+=1){var _=e[b],w=i(M,_);if(h(w))if(s(w)){for(var O=[],S=[{arrayIndex:-1,value:w}];S.length;){var I=S.pop(),L=I.arrayIndex,A=I.value;if(h(A))if(a(A)){var j={$:A,idx:L};c&&(j.ng=g(A,{sort:!0})),O.push(j)}else if(s(A))for(var C=0,P=A.length;C<P;C+=1)S.push({arrayIndex:C,value:A[C]})}x.$[_]=O}else{var $={$:w};c&&($.ng=g(w,{sort:!0})),x.$[_]=$}}u.push(x)}return u}var m=function(){function t(r){if(e(this,t),this._keys={},this._keyNames=[],this._length=r.length,r.length&&a(r[0]))for(var n=0;n<this._length;n+=1){var i=r[n];this._keys[i]={weight:1},this._keyNames.push(i)}else{for(var o=0,s=0;s<this._length;s+=1){var c=r[s];if(!Object.prototype.hasOwnProperty.call(c,"name"))throw new Error('Missing "name" property in key object');var h=c.name;if(this._keyNames.push(h),!Object.prototype.hasOwnProperty.call(c,"weight"))throw new Error('Missing "weight" property in key object');var l=c.weight;if(l<=0||l>=1)throw new Error('"weight" property in key must be in the range of (0, 1)');this._keys[h]={weight:l},o+=l}for(var u=0;u<this._length;u+=1){var f=this._keyNames[u],v=this._keys[f].weight;this._keys[f].weight=v/o}}}return r(t,[{key:"get",value:function(e,t){return this._keys[e]?this._keys[e][t]:-1}},{key:"keys",value:function(){return this._keyNames}},{key:"count",value:function(){return this._length}},{key:"toJSON",value:function(){return JSON.stringify(this._keys)}}]),t}();function k(e,t){var r=e.matches;if(t.matches=[],h(r))for(var n=0,i=r.length;n<i;n+=1){var o=r[n];if(h(o.indices)&&0!==o.indices.length){var s={indices:o.indices,value:o.value};o.key&&(s.key=o.key),o.idx>-1&&(s.refIndex=o.idx),t.matches.push(s)}}}function M(e,t){t.score=e.score}var x=[],b=function(){function t(r){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;e(this,t),this.options=o({},u,{},n),this._processKeys(this.options.keys),this.setCollection(r,i)}return r(t,[{key:"setCollection",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;this.list=e,this.listIsStringArray=a(e[0]),t?this.setIndex(t):this.setIndex(this._createIndex())}},{key:"setIndex",value:function(e){this._indexedList=e}},{key:"_processKeys",value:function(e){this._keyStore=new m(e)}},{key:"_createIndex",value:function(){return y(this._keyStore.keys(),this.list,{getFn:this.options.getFn})}},{key:"search",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{limit:!1},r=this.options.shouldSort,n=null,i=0,o=x.length;i<o;i+=1){var s=x[i];if(s.condition(e,this.options)){n=new s(e,this.options);break}}n||(n=new p(e,this.options));var a=this._searchUsing(n);return this._computeScore(a),r&&this._sort(a),t.limit&&c(t.limit)&&(a=a.slice(0,t.limit)),this._format(a)}},{key:"_searchUsing",value:function(e){var t=this._indexedList,r=[],n=this.options.includeMatches;if(this.listIsStringArray)for(var i=0,o=t.length;i<o;i+=1){var a=t[i],c=a.$,l=a.idx;if(h(c)){var u=e.searchIn(a),f=u.isMatch,v=u.score;if(f){var d={score:v,value:c};n&&(d.indices=u.matchedIndices),r.push({item:c,idx:l,matches:[d]})}}}else for(var p=this._keyStore.keys(),g=this._keyStore.count(),y=0,m=t.length;y<m;y+=1){var k=t[y],M=k.$,x=k.idx;if(h(M)){for(var b=[],_=0;_<g;_+=1){var w=p[_],O=M[w];if(h(O))if(s(O))for(var S=0,I=O.length;S<I;S+=1){var L=O[S],A=L.$,j=L.idx;if(h(A)){var C=e.searchIn(L),P=C.isMatch,$=C.score;if(P){var E={score:$,key:w,value:A,idx:j};n&&(E.indices=C.matchedIndices),b.push(E)}}}else{var N=O.$,F=e.searchIn(O),D=F.isMatch,J=F.score;if(!D)continue;var K={score:J,key:w,value:N};n&&(K.indices=F.matchedIndices),b.push(K)}}b.length&&r.push({idx:x,item:M,matches:b})}}return r}},{key:"_computeScore",value:function(e){for(var t=0,r=e.length;t<r;t+=1){for(var n=e[t],i=n.matches,o=i.length,s=1,a=0;a<o;a+=1){var c=i[a],h=c.key,l=this._keyStore.get(h,"weight"),u=l>-1?l:1,f=0===c.score&&l>-1?Number.EPSILON:c.score;s*=Math.pow(f,u)}n.score=s}}},{key:"_sort",value:function(e){e.sort(this.options.sortFn)}},{key:"_format",value:function(e){var t=[],r=this.options,n=r.includeMatches,i=r.includeScore,o=[];n&&o.push(k),i&&o.push(M);for(var s=0,a=e.length;s<a;s+=1){var c=e[s],h=c.idx,l={item:this.list[h],refIndex:h};if(o.length)for(var u=0,f=o.length;u<f;u+=1)o[u](c,l);t.push(l)}return t}}],[{key:"register",value:function(){x.push.apply(x,arguments)}}]),t}();return b.version="5.2.0-alpha.1",b.createIndex=y,b.config=u,b},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).Fuse=t(); |
/** | ||
* Fuse.js v5.2.0-alpha.0 - Lightweight fuzzy-search (http://fusejs.io) | ||
* Fuse.js v5.2.0-alpha.1 - Lightweight fuzzy-search (http://fusejs.io) | ||
* | ||
@@ -193,54 +193,2 @@ * Copyright (c) 2020 Kiro Risk (http://kiro.me) | ||
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; | ||
} | ||
var INFINITY = 1 / 0; | ||
@@ -368,3 +316,57 @@ var isArray = function isArray(value) { | ||
function bitapSearch(text, pattern, patternAlphabet) { | ||
function computeScore(pattern) { | ||
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
_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 ? Config.distance : _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 convertMaskToIndices() { | ||
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 search(text, pattern, patternAlphabet) { | ||
var _ref = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}, | ||
@@ -401,3 +403,3 @@ _ref$location = _ref.location, | ||
if (bestLocation !== -1) { | ||
var score = bitapScore(pattern, { | ||
var score = computeScore(pattern, { | ||
errors: 0, | ||
@@ -413,3 +415,3 @@ currentLocation: bestLocation, | ||
if (bestLocation !== -1) { | ||
var _score = bitapScore(pattern, { | ||
var _score = computeScore(pattern, { | ||
errors: 0, | ||
@@ -440,3 +442,3 @@ currentLocation: bestLocation, | ||
while (binMin < binMid) { | ||
var _score3 = bitapScore(pattern, { | ||
var _score3 = computeScore(pattern, { | ||
errors: _i, | ||
@@ -481,3 +483,3 @@ currentLocation: expectedLocation + binMid, | ||
if (bitArr[j] & mask) { | ||
finalScore = bitapScore(pattern, { | ||
finalScore = computeScore(pattern, { | ||
errors: _i, | ||
@@ -506,3 +508,3 @@ currentLocation: currentLocation, | ||
var _score2 = bitapScore(pattern, { | ||
var _score2 = computeScore(pattern, { | ||
errors: _i + 1, | ||
@@ -528,3 +530,3 @@ currentLocation: expectedLocation, | ||
if (includeMatches) { | ||
result.matchedIndices = matchedIndiced(matchMask, minMatchCharLength); | ||
result.matchedIndices = convertMaskToIndices(matchMask, minMatchCharLength); | ||
} | ||
@@ -535,3 +537,3 @@ | ||
function patternAlphabet(pattern) { | ||
function createPatternAlphabet(pattern) { | ||
var mask = {}; | ||
@@ -569,3 +571,3 @@ var len = pattern.length; | ||
this.pattern = this.options.isCaseSensitive ? pattern : pattern.toLowerCase(); | ||
this.patternAlphabet = patternAlphabet(this.pattern); | ||
this.patternAlphabet = createPatternAlphabet(this.pattern); | ||
} | ||
@@ -611,3 +613,3 @@ | ||
minMatchCharLength = _this$options2.minMatchCharLength; | ||
return bitapSearch(text, this.pattern, this.patternAlphabet, { | ||
return search(text, this.pattern, this.patternAlphabet, { | ||
location: location, | ||
@@ -626,5 +628,5 @@ distance: distance, | ||
var Match = /*#__PURE__*/function () { | ||
function Match(pattern) { | ||
_classCallCheck(this, Match); | ||
var BaseMatch = /*#__PURE__*/function () { | ||
function BaseMatch(pattern) { | ||
_classCallCheck(this, BaseMatch); | ||
@@ -634,3 +636,3 @@ this.pattern = pattern; | ||
_createClass(Match, [{ | ||
_createClass(BaseMatch, [{ | ||
key: "search", | ||
@@ -652,3 +654,3 @@ value: function search() | ||
return Match; | ||
return BaseMatch; | ||
}(); | ||
@@ -661,4 +663,4 @@ | ||
var ExactMatch = /*#__PURE__*/function (_Match) { | ||
_inherits(ExactMatch, _Match); | ||
var ExactMatch = /*#__PURE__*/function (_BaseMatch) { | ||
_inherits(ExactMatch, _BaseMatch); | ||
@@ -702,6 +704,6 @@ var _super = _createSuper(ExactMatch); | ||
return ExactMatch; | ||
}(Match); | ||
}(BaseMatch); | ||
var InverseExactMatch = /*#__PURE__*/function (_Match) { | ||
_inherits(InverseExactMatch, _Match); | ||
var InverseExactMatch = /*#__PURE__*/function (_BaseMatch) { | ||
_inherits(InverseExactMatch, _BaseMatch); | ||
@@ -745,6 +747,6 @@ var _super = _createSuper(InverseExactMatch); | ||
return InverseExactMatch; | ||
}(Match); | ||
}(BaseMatch); | ||
var PrefixExactMatch = /*#__PURE__*/function (_Match) { | ||
_inherits(PrefixExactMatch, _Match); | ||
var PrefixExactMatch = /*#__PURE__*/function (_BaseMatch) { | ||
_inherits(PrefixExactMatch, _BaseMatch); | ||
@@ -787,6 +789,6 @@ var _super = _createSuper(PrefixExactMatch); | ||
return PrefixExactMatch; | ||
}(Match); | ||
}(BaseMatch); | ||
var InversePrefixExactMatch = /*#__PURE__*/function (_Match) { | ||
_inherits(InversePrefixExactMatch, _Match); | ||
var InversePrefixExactMatch = /*#__PURE__*/function (_BaseMatch) { | ||
_inherits(InversePrefixExactMatch, _BaseMatch); | ||
@@ -829,6 +831,6 @@ var _super = _createSuper(InversePrefixExactMatch); | ||
return InversePrefixExactMatch; | ||
}(Match); | ||
}(BaseMatch); | ||
var SuffixExactMatch = /*#__PURE__*/function (_Match) { | ||
_inherits(SuffixExactMatch, _Match); | ||
var SuffixExactMatch = /*#__PURE__*/function (_BaseMatch) { | ||
_inherits(SuffixExactMatch, _BaseMatch); | ||
@@ -871,6 +873,6 @@ var _super = _createSuper(SuffixExactMatch); | ||
return SuffixExactMatch; | ||
}(Match); | ||
}(BaseMatch); | ||
var InverseSuffixExactMatch = /*#__PURE__*/function (_Match) { | ||
_inherits(InverseSuffixExactMatch, _Match); | ||
var InverseSuffixExactMatch = /*#__PURE__*/function (_BaseMatch) { | ||
_inherits(InverseSuffixExactMatch, _BaseMatch); | ||
@@ -913,6 +915,6 @@ var _super = _createSuper(InverseSuffixExactMatch); | ||
return InverseSuffixExactMatch; | ||
}(Match); | ||
}(BaseMatch); | ||
var FuzzyMatch = /*#__PURE__*/function (_Match) { | ||
_inherits(FuzzyMatch, _Match); | ||
var FuzzyMatch = /*#__PURE__*/function (_BaseMatch) { | ||
_inherits(FuzzyMatch, _BaseMatch); | ||
@@ -958,3 +960,3 @@ var _super = _createSuper(FuzzyMatch); | ||
return FuzzyMatch; | ||
}(Match); | ||
}(BaseMatch); | ||
@@ -1139,6 +1141,6 @@ var searchers = [ExactMatch, PrefixExactMatch, InversePrefixExactMatch, InverseSuffixExactMatch, SuffixExactMatch, InverseExactMatch, FuzzyMatch]; | ||
var NGRAM_LEN = 3; | ||
function ngram(text, _ref) { | ||
var NGRAMS = 3; | ||
function createNGram(text, _ref) { | ||
var _ref$n = _ref.n, | ||
n = _ref$n === void 0 ? NGRAM_LEN : _ref$n, | ||
n = _ref$n === void 0 ? NGRAMS : _ref$n, | ||
_ref$pad = _ref.pad, | ||
@@ -1258,3 +1260,3 @@ pad = _ref$pad === void 0 ? true : _ref$pad, | ||
this.options = options; | ||
this.patternNgram = ngram(pattern, { | ||
this.patternNgram = createNGram(pattern, { | ||
sort: true | ||
@@ -1270,3 +1272,3 @@ }); | ||
if (!textNgram) { | ||
textNgram = ngram(value.$, { | ||
textNgram = createNGram(value.$, { | ||
sort: true | ||
@@ -1318,3 +1320,3 @@ }); | ||
if (ngrams) { | ||
record.ng = ngram(value, { | ||
record.ng = createNGram(value, { | ||
sort: true | ||
@@ -1373,3 +1375,3 @@ }); | ||
if (ngrams) { | ||
subRecord.ng = ngram(_value2, { | ||
subRecord.ng = createNGram(_value2, { | ||
sort: true | ||
@@ -1400,3 +1402,3 @@ }); | ||
if (ngrams) { | ||
_subRecord.ng = ngram(_value, { | ||
_subRecord.ng = createNGram(_value, { | ||
sort: true | ||
@@ -1821,3 +1823,3 @@ }); | ||
Fuse.register(ExtendedSearch, NGramSearch); | ||
Fuse.version = '5.2.0-alpha.0'; | ||
Fuse.version = '5.2.0-alpha.1'; | ||
Fuse.createIndex = createIndex; | ||
@@ -1824,0 +1826,0 @@ Fuse.config = Config; |
@@ -1,2 +0,2 @@ | ||
// Type definitions for Fuse.js v5.2.0-alpha.0 | ||
// Type definitions for Fuse.js v5.2.0-alpha.1 | ||
// TypeScript v3.8.3 | ||
@@ -3,0 +3,0 @@ |
/** | ||
* Fuse.js v5.2.0-alpha.0 - Lightweight fuzzy-search (http://fusejs.io) | ||
* Fuse.js v5.2.0-alpha.1 - Lightweight fuzzy-search (http://fusejs.io) | ||
* | ||
@@ -10,44 +10,2 @@ * Copyright (c) 2020 Kiro Risk (http://kiro.me) | ||
function bitapScore( | ||
pattern, | ||
{ errors = 0, currentLocation = 0, expectedLocation = 0, distance = 100 } | ||
) { | ||
const accuracy = errors / pattern.length; | ||
const proximity = Math.abs(expectedLocation - currentLocation); | ||
if (!distance) { | ||
// Dodge divide by zero error. | ||
return proximity ? 1.0 : accuracy | ||
} | ||
return accuracy + proximity / distance | ||
} | ||
function matchedIndiced(matchmask = [], minMatchCharLength = 1) { | ||
let matchedIndices = []; | ||
let start = -1; | ||
let end = -1; | ||
let i = 0; | ||
for (let len = matchmask.length; i < len; i += 1) { | ||
let 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 | ||
} | ||
const INFINITY = 1 / 0; | ||
@@ -181,3 +139,53 @@ | ||
function bitapSearch( | ||
function computeScore( | ||
pattern, | ||
{ | ||
errors = 0, | ||
currentLocation = 0, | ||
expectedLocation = 0, | ||
distance = Config.distance | ||
} = {} | ||
) { | ||
const accuracy = errors / pattern.length; | ||
const proximity = Math.abs(expectedLocation - currentLocation); | ||
if (!distance) { | ||
// Dodge divide by zero error. | ||
return proximity ? 1.0 : accuracy | ||
} | ||
return accuracy + proximity / distance | ||
} | ||
function convertMaskToIndices( | ||
matchmask = [], | ||
minMatchCharLength = 1 | ||
) { | ||
let matchedIndices = []; | ||
let start = -1; | ||
let end = -1; | ||
let i = 0; | ||
for (let len = matchmask.length; i < len; i += 1) { | ||
let 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 search( | ||
text, | ||
@@ -212,3 +220,3 @@ pattern, | ||
if (bestLocation !== -1) { | ||
let score = bitapScore(pattern, { | ||
let score = computeScore(pattern, { | ||
errors: 0, | ||
@@ -225,3 +233,3 @@ currentLocation: bestLocation, | ||
if (bestLocation !== -1) { | ||
let score = bitapScore(pattern, { | ||
let score = computeScore(pattern, { | ||
errors: 0, | ||
@@ -253,3 +261,3 @@ currentLocation: bestLocation, | ||
while (binMin < binMid) { | ||
const score = bitapScore(pattern, { | ||
const score = computeScore(pattern, { | ||
errors: i, | ||
@@ -301,3 +309,3 @@ currentLocation: expectedLocation + binMid, | ||
if (bitArr[j] & mask) { | ||
finalScore = bitapScore(pattern, { | ||
finalScore = computeScore(pattern, { | ||
errors: i, | ||
@@ -328,3 +336,3 @@ currentLocation, | ||
// No hope for a (better) match at greater error levels. | ||
const score = bitapScore(pattern, { | ||
const score = computeScore(pattern, { | ||
errors: i + 1, | ||
@@ -350,3 +358,3 @@ currentLocation: expectedLocation, | ||
if (includeMatches) { | ||
result.matchedIndices = matchedIndiced(matchMask, minMatchCharLength); | ||
result.matchedIndices = convertMaskToIndices(matchMask, minMatchCharLength); | ||
} | ||
@@ -357,3 +365,3 @@ | ||
function patternAlphabet(pattern) { | ||
function createPatternAlphabet(pattern) { | ||
let mask = {}; | ||
@@ -405,3 +413,3 @@ let len = pattern.length; | ||
: pattern.toLowerCase(); | ||
this.patternAlphabet = patternAlphabet(this.pattern); | ||
this.patternAlphabet = createPatternAlphabet(this.pattern); | ||
} | ||
@@ -443,3 +451,4 @@ | ||
} = this.options; | ||
return bitapSearch(text, this.pattern, this.patternAlphabet, { | ||
return search(text, this.pattern, this.patternAlphabet, { | ||
location, | ||
@@ -455,3 +464,3 @@ distance, | ||
class Match { | ||
class BaseMatch { | ||
constructor(pattern) { | ||
@@ -476,3 +485,3 @@ this.pattern = pattern; | ||
class ExactMatch extends Match { | ||
class ExactMatch extends BaseMatch { | ||
constructor(pattern) { | ||
@@ -504,3 +513,3 @@ super(pattern); | ||
class InverseExactMatch extends Match { | ||
class InverseExactMatch extends BaseMatch { | ||
constructor(pattern) { | ||
@@ -532,3 +541,3 @@ super(pattern); | ||
class PrefixExactMatch extends Match { | ||
class PrefixExactMatch extends BaseMatch { | ||
constructor(pattern) { | ||
@@ -559,3 +568,3 @@ super(pattern); | ||
class InversePrefixExactMatch extends Match { | ||
class InversePrefixExactMatch extends BaseMatch { | ||
constructor(pattern) { | ||
@@ -586,3 +595,3 @@ super(pattern); | ||
class SuffixExactMatch extends Match { | ||
class SuffixExactMatch extends BaseMatch { | ||
constructor(pattern) { | ||
@@ -613,3 +622,3 @@ super(pattern); | ||
class InverseSuffixExactMatch extends Match { | ||
class InverseSuffixExactMatch extends BaseMatch { | ||
constructor(pattern) { | ||
@@ -637,3 +646,3 @@ super(pattern); | ||
class FuzzyMatch extends Match { | ||
class FuzzyMatch extends BaseMatch { | ||
constructor( | ||
@@ -858,7 +867,7 @@ pattern, | ||
const NGRAM_LEN = 3; | ||
const NGRAMS = 3; | ||
function ngram( | ||
function createNGram( | ||
text, | ||
{ n = NGRAM_LEN, pad = true, sort = false } | ||
{ n = NGRAMS, pad = true, sort = false } | ||
) { | ||
@@ -973,3 +982,3 @@ let nGrams = []; | ||
this.options = options; | ||
this.patternNgram = ngram(pattern, { sort: true }); | ||
this.patternNgram = createNGram(pattern, { sort: true }); | ||
} | ||
@@ -982,3 +991,3 @@ static condition(pattern) { | ||
if (!textNgram) { | ||
textNgram = ngram(value.$, { sort: true }); | ||
textNgram = createNGram(value.$, { sort: true }); | ||
value.ng = textNgram; | ||
@@ -1022,3 +1031,3 @@ } | ||
if (ngrams) { | ||
record.ng = ngram(value, { sort: true }); | ||
record.ng = createNGram(value, { sort: true }); | ||
} | ||
@@ -1066,3 +1075,3 @@ | ||
if (ngrams) { | ||
subRecord.ng = ngram(value, { sort: true }); | ||
subRecord.ng = createNGram(value, { sort: true }); | ||
} | ||
@@ -1089,3 +1098,3 @@ | ||
if (ngrams) { | ||
subRecord.ng = ngram(value, { sort: true }); | ||
subRecord.ng = createNGram(value, { sort: true }); | ||
} | ||
@@ -1459,3 +1468,3 @@ | ||
Fuse.version = '5.2.0-alpha.0'; | ||
Fuse.version = '5.2.0-alpha.1'; | ||
Fuse.createIndex = createIndex; | ||
@@ -1462,0 +1471,0 @@ Fuse.config = Config; |
/** | ||
* Fuse.js v5.2.0-alpha.0 - Lightweight fuzzy-search (http://fusejs.io) | ||
* Fuse.js v5.2.0-alpha.1 - Lightweight fuzzy-search (http://fusejs.io) | ||
* | ||
@@ -9,2 +9,2 @@ * Copyright (c) 2020 Kiro Risk (http://kiro.me) | ||
*/ | ||
function t(t,{errors:e=0,currentLocation:s=0,expectedLocation:n=0,distance:i=100}){const r=e/t.length,c=Math.abs(n-s);return i?r+c/i:c?1:r}const e=t=>Array.isArray?Array.isArray(t):"[object Array]"===Object.prototype.toString.call(t),s=t=>"string"==typeof t,n=t=>"number"==typeof t,i=t=>null!=t;function r(t,r){let c=[],h=!1;const o=(t,r)=>{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=t[l];if(i(d))if(u||!s(d)&&!n(d))if(e(d)){h=!0;for(let t=0,e=d.length;t<e;t+=1)o(d[t],u)}else u&&o(d,u);else c.push((t=>null==t?"":(t=>{if("string"==typeof t)return t;let e=t+"";return"0"==e&&1/t==-1/0?"-0":e})(t))(d))}else c.push(t)};return o(t,r),h?c:c[0]}var c={isCaseSensitive:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score-e.score,includeMatches:!1,findAllMatches:!1,minMatchCharLength:1,location:0,threshold:.6,distance:100,...{useExtendedSearch:!1,getFn:r}};class h{constructor(t,e=({location:location=c.location,threshold:threshold=c.threshold,distance:distance=c.distance,includeMatches:includeMatches=c.includeMatches,findAllMatches:findAllMatches=c.findAllMatches,minMatchCharLength:minMatchCharLength=c.minMatchCharLength,isCaseSensitive:isCaseSensitive=c.isCaseSensitive}={})){if(this.options=e,t.length>32)throw new Error("Pattern length exceeds max of 32.");this.pattern=this.options.isCaseSensitive?t:t.toLowerCase(),this.patternAlphabet=function(t){let e={},s=t.length;for(let n=0;n<s;n+=1)e[t.charAt(n)]=0;for(let n=0;n<s;n+=1)e[t.charAt(n)]|=1<<s-n-1;return e}(this.pattern)}searchIn(t){let e=t.$;return this.searchInString(e)}searchInString(e){const{isCaseSensitive:s,includeMatches:n}=this.options;if(s||(e=e.toLowerCase()),this.pattern===e){let t={isMatch:!0,score:0};return n&&(t.matchedIndices=[[0,e.length-1]]),t}const{location:i,distance:r,threshold:h,findAllMatches:o,minMatchCharLength:a}=this.options;return function(e,s,n,{location:i=c.location,distance:r=c.distance,threshold:h=c.threshold,findAllMatches:o=c.findAllMatches,minMatchCharLength:a=c.minMatchCharLength,includeMatches:l=c.includeMatches}={}){const u=s.length,d=e.length,g=Math.max(0,Math.min(i,d));let f=h,p=e.indexOf(s,g);const M=[];for(let t=0;t<d;t+=1)M[t]=0;if(-1!==p){let n=t(s,{errors:0,currentLocation:p,expectedLocation:g,distance:r});if(f=Math.min(n,f),p=e.lastIndexOf(s,g+u),-1!==p){let e=t(s,{errors:0,currentLocation:p,expectedLocation:g,distance:r});f=Math.min(e,f)}}p=-1;let m=[],y=1,x=u+d;const _=1<<(u<=31?u-1:30);for(let i=0;i<u;i+=1){let c=0,h=x;for(;c<h;){t(s,{errors:i,currentLocation:g+h,expectedLocation:g,distance:r})<=f?c=h:x=h,h=Math.floor((x-c)/2+c)}x=h;let a=Math.max(1,g-h+1),l=o?d:Math.min(g+h,d)+u,S=Array(l+2);S[l+1]=(1<<i)-1;for(let c=l;c>=a;c-=1){let h=c-1,o=n[e.charAt(h)];if(o&&(M[h]=1),S[c]=(S[c+1]<<1|1)&o,0!==i&&(S[c]|=(m[c+1]|m[c])<<1|1|m[c+1]),S[c]&_&&(y=t(s,{errors:i,currentLocation:h,expectedLocation:g,distance:r}),y<=f)){if(f=y,p=h,p<=g)break;a=Math.max(1,2*g-p)}}if(t(s,{errors:i+1,currentLocation:g,expectedLocation:g,distance:r})>f)break;m=S}let S={isMatch:p>=0,score:y||.001};return l&&(S.matchedIndices=function(t=[],e=1){let s=[],n=-1,i=-1,r=0;for(let c=t.length;r<c;r+=1){let c=t[r];c&&-1===n?n=r:c||-1===n||(i=r-1,i-n+1>=e&&s.push([n,i]),n=-1)}return t[r-1]&&r-n>=e&&s.push([n,r-1]),s}(M,a)),S}(e,this.pattern,this.patternAlphabet,{location:i,distance:r,threshold:h,findAllMatches:o,minMatchCharLength:a,includeMatches:n})}}class o{constructor(t){this.pattern=t}static isLiteralMatch(t){return a(t,this.literal)}static isRegMatch(t){return a(t,this.re)}search(){}}function a(t,e){const s=t.match(e);return s?s[1]:null}class l extends o{constructor(t,e=({location:location=c.location,threshold:threshold=c.threshold,distance:distance=c.distance,includeMatches:includeMatches=c.includeMatches,findAllMatches:findAllMatches=c.findAllMatches,minMatchCharLength:minMatchCharLength=c.minMatchCharLength,isCaseSensitive:isCaseSensitive=c.isCaseSensitive}={})){super(t),this._bitapSearch=new h(t,e)}static get type(){return"fuzzy"}static get literal(){return/^"(.*)"$/}static get re(){return/^(.*)$/}search(t){return this._bitapSearch.searchInString(t)}}const u=[class extends o{constructor(t){super(t)}static get type(){return"exact"}static get literal(){return/^'"(.*)"$/}static get re(){return/^'(.*)$/}search(t){const e=t.indexOf(this.pattern),s=e>-1;return{isMatch:s,score:s?1:0,matchedIndices:[e,e+this.pattern.length-1]}}},class extends o{constructor(t){super(t)}static get type(){return"prefix-exact"}static get literal(){return/^\^"(.*)"$/}static get re(){return/^\^(.*)$/}search(t){const e=t.startsWith(this.pattern);return{isMatch:e,score:e?0:1,matchedIndices:[0,this.pattern.length-1]}}},class extends o{constructor(t){super(t)}static get type(){return"inverse-prefix-exact"}static get literal(){return/^!\^"(.*)"$/}static get re(){return/^!\^(.*)$/}search(t){const e=!t.startsWith(this.pattern);return{isMatch:e,score:e?0:1,matchedIndices:[0,t.length-1]}}},class extends o{constructor(t){super(t)}static get type(){return"inverse-suffix-exact"}static get literal(){return/^!"(.*)"\$$/}static get re(){return/^!(.*)\$$/}search(t){const e=!t.endsWith(this.pattern);return{isMatch:e,score:e?0:1,matchedIndices:[0,t.length-1]}}},class extends o{constructor(t){super(t)}static get type(){return"suffix-exact"}static get literal(){return/^"(.*)"\$$/}static get re(){return/^(.*)\$$/}search(t){const e=t.endsWith(this.pattern);return{isMatch:e,score:e?0:1,matchedIndices:[t.length-this.pattern.length,t.length-1]}}},class extends o{constructor(t){super(t)}static get type(){return"inverse-exact"}static get literal(){return/^!"(.*)"$/}static get re(){return/^!(.*)$/}search(t){const e=-1===t.indexOf(this.pattern);return{isMatch:e,score:e?0:1,matchedIndices:[0,t.length-1]}}},l],d=u.length,g=/ +(?=([^\"]*\"[^\"]*\")*[^\"]*$)/;function f(t,{n:e=3,pad:s=!0,sort:n=!1}){let i=[];if(null==t)return i;t=t.toLowerCase(),s&&(t=` ${t} `);let r=t.length-e+1;if(r<1)return i;for(;r--;)i[r]=t.substr(r,e);return n&&i.sort((t,e)=>t==e?0:t<e?-1:1),i}function p(t,n,{getFn:c=r,ngrams:h=!1}={}){let o=[];if(s(n[0]))for(let t=0,e=n.length;t<e;t+=1){const e=n[t];if(i(e)){let s={$:e,idx:t};h&&(s.ng=f(e,{sort:!0})),o.push(s)}}else{const r=t.length;for(let a=0,l=n.length;a<l;a+=1){let l=n[a],u={idx:a,$:{}};for(let n=0;n<r;n+=1){let r=t[n],o=c(l,r);if(i(o))if(e(o)){let t=[];const n=[{arrayIndex:-1,value:o}];for(;n.length;){const{arrayIndex:r,value:c}=n.pop();if(i(c))if(s(c)){let e={$:c,idx:r};h&&(e.ng=f(c,{sort:!0})),t.push(e)}else if(e(c))for(let t=0,e=c.length;t<e;t+=1)n.push({arrayIndex:t,value:c[t]})}u.$[r]=t}else{let t={$:o};h&&(t.ng=f(o,{sort:!0})),u.$[r]=t}}o.push(u)}}return o}class M{constructor(t){if(this._keys={},this._keyNames=[],this._length=t.length,t.length&&s(t[0]))for(let e=0;e<this._length;e+=1){const s=t[e];this._keys[s]={weight:1},this._keyNames.push(s)}else{let e=0;for(let s=0;s<this._length;s+=1){const n=t[s];if(!Object.prototype.hasOwnProperty.call(n,"name"))throw new Error('Missing "name" property in key object');const i=n.name;if(this._keyNames.push(i),!Object.prototype.hasOwnProperty.call(n,"weight"))throw new Error('Missing "weight" property in key object');const r=n.weight;if(r<=0||r>=1)throw new Error('"weight" property in key must be in the range of (0, 1)');this._keys[i]={weight:r},e+=r}for(let t=0;t<this._length;t+=1){const s=this._keyNames[t],n=this._keys[s].weight;this._keys[s].weight=n/e}}}get(t,e){return this._keys[t]?this._keys[t][e]:-1}keys(){return this._keyNames}count(){return this._length}toJSON(){return JSON.stringify(this._keys)}}function m(t,e){const s=t.matches;if(e.matches=[],i(s))for(let t=0,n=s.length;t<n;t+=1){let n=s[t];if(!i(n.indices)||0===n.indices.length)continue;let r={indices:n.indices,value:n.value};n.key&&(r.key=n.key),n.idx>-1&&(r.refIndex=n.idx),e.matches.push(r)}}function y(t,e){e.score=t.score}const x=[];class _{constructor(t,e={},s=null){this.options={...c,...e},this._processKeys(this.options.keys),this.setCollection(t,s)}static register(...t){x.push(...t)}setCollection(t,e=null){this.list=t,this.listIsStringArray=s(t[0]),e?this.setIndex(e):this.setIndex(this._createIndex())}setIndex(t){this._indexedList=t}_processKeys(t){this._keyStore=new M(t)}_createIndex(){return p(this._keyStore.keys(),this.list,{getFn:this.options.getFn})}search(t,e={limit:!1}){const{shouldSort:s}=this.options;let i=null;for(let e=0,s=x.length;e<s;e+=1){let s=x[e];if(s.condition(t,this.options)){i=new s(t,this.options);break}}i||(i=new h(t,this.options));let r=this._searchUsing(i);return this._computeScore(r),s&&this._sort(r),e.limit&&n(e.limit)&&(r=r.slice(0,e.limit)),this._format(r)}_searchUsing(t){const s=this._indexedList,n=[],{includeMatches:r}=this.options;if(this.listIsStringArray)for(let e=0,c=s.length;e<c;e+=1){let c=s[e],{$:h,idx:o}=c;if(!i(h))continue;let a=t.searchIn(c);const{isMatch:l,score:u}=a;if(!l)continue;let d={score:u,value:h};r&&(d.indices=a.matchedIndices),n.push({item:h,idx:o,matches:[d]})}else{const c=this._keyStore.keys(),h=this._keyStore.count();for(let o=0,a=s.length;o<a;o+=1){let{$:a,idx:l}=s[o];if(!i(a))continue;let u=[];for(let s=0;s<h;s+=1){let n=c[s],h=a[n];if(i(h))if(e(h))for(let e=0,s=h.length;e<s;e+=1){let s=h[e],c=s.$,o=s.idx;if(!i(c))continue;let a=t.searchIn(s);const{isMatch:l,score:d}=a;if(!l)continue;let g={score:d,key:n,value:c,idx:o};r&&(g.indices=a.matchedIndices),u.push(g)}else{let e=h.$,s=t.searchIn(h);const{isMatch:i,score:c}=s;if(!i)continue;let o={score:c,key:n,value:e};r&&(o.indices=s.matchedIndices),u.push(o)}}u.length&&n.push({idx:l,item:a,matches:u})}}return n}_computeScore(t){for(let e=0,s=t.length;e<s;e+=1){const s=t[e],n=s.matches,i=n.length;let r=1;for(let t=0;t<i;t+=1){const e=n[t],s=e.key,i=this._keyStore.get(s,"weight"),c=i>-1?i:1,h=0===e.score&&i>-1?Number.EPSILON:e.score;r*=Math.pow(h,c)}s.score=r}}_sort(t){t.sort(this.options.sortFn)}_format(t){const e=[],{includeMatches:s,includeScore:n}=this.options;let i=[];s&&i.push(m),n&&i.push(y);for(let s=0,n=t.length;s<n;s+=1){const n=t[s],{idx:r}=n,c={item:this.list[r],refIndex:r};if(i.length)for(let t=0,e=i.length;t<e;t+=1)i[t](n,c);e.push(c)}return e}}_.register(class{constructor(t,e=({isCaseSensitive:isCaseSensitive=c.isCaseSensitive,includeMatches:includeMatches=c.includeMatches,minMatchCharLength:minMatchCharLength=c.minMatchCharLength,findAllMatches:findAllMatches=c.findAllMatches,location:location=c.location,threshold:threshold=c.threshold,distance:distance=c.distance,includeMatches:includeMatches=c.includeMatches}={})){this.query=null,this.options=e,this.pattern=e.isCaseSensitive?t:t.toLowerCase(),this.query=function(t,e){return t.split("|").map(t=>{let s=t.trim().split(g).filter(t=>t&&!!t.trim()),n=[];for(let t=0,i=s.length;t<i;t+=1){const i=s[t];let r=!1,c=-1;for(;!r&&++c<d;){const t=u[c];let s=t.isLiteralMatch(i);s&&(n.push(new t(s,e)),r=!0)}if(!r)for(c=-1;++c<d;){const t=u[c];let s=t.isRegMatch(i);if(s){n.push(new t(s,e));break}}}return n})}(this.pattern,e)}static condition(t,e){return e.useExtendedSearch}searchIn(t){const e=this.query;if(!e)return{isMatch:!1,score:1};let s=t.$;const{includeMatches:n,isCaseSensitive:i}=this.options;s=i?s:s.toLowerCase();let r=0,c=[];for(let t=0,i=e.length;t<i;t+=1){const i=e[t];c.length=0,r=0;for(let t=0,e=i.length;t<e;t+=1){const e=i[t],{isMatch:h,matchedIndices:o}=e.search(s);if(!h){r=0,c.length=0;break}r+=1,n&&(e.constructor.type===l.type?c=[...c,...o]:c.push(o))}if(r){let t={isMatch:!0,score:0};return n&&(t.matchedIndices=c),t}}return{isMatch:!1,score:1}}},class{constructor(t,e=({threshold:threshold=c.threshold}={})){this.options=e,this.patternNgram=f(t,{sort:!0})}static condition(t){return t.length>32}searchIn(t){let e=t.ng;e||(e=f(t.$,{sort:!0}),t.ng=e);let s=function(t,e){let s=function(t,e){let s=[],n=0,i=0;for(;n<t.length&&i<e.length;){let r=t[n],c=e[i];r<c?(s.push(r),n+=1):c<r?(s.push(c),i+=1):(s.push(c),n+=1,i+=1)}for(;n<t.length;)s.push(t[n]),n+=1;for(;i<e.length;)s.push(e[i]),i+=1;return s}(t,e);return 1-function(t,e){let s=[],n=0,i=0;for(;n<t.length&&i<e.length;){let r=t[n],c=e[i];r==c?(s.push(r),n+=1,i+=1):r<c?n+=1:(r>c||(n+=1),i+=1)}return s}(t,e).length/s.length}(this.patternNgram,e);const n=s<this.options.threshold;return{score:n?s:1,isMatch:n}}}),_.version="5.2.0-alpha.0",_.createIndex=p,_.config=c;export default _; | ||
const t=t=>Array.isArray?Array.isArray(t):"[object Array]"===Object.prototype.toString.call(t),e=t=>"string"==typeof t,s=t=>"number"==typeof t,n=t=>null!=t;function i(i,r){let c=[],h=!1;const o=(i,r)=>{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))if(u||!e(d)&&!s(d))if(t(d)){h=!0;for(let t=0,e=d.length;t<e;t+=1)o(d[t],u)}else u&&o(d,u);else c.push((t=>null==t?"":(t=>{if("string"==typeof t)return t;let e=t+"";return"0"==e&&1/t==-1/0?"-0":e})(t))(d))}else c.push(i)};return o(i,r),h?c:c[0]}var r={isCaseSensitive:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score-e.score,includeMatches:!1,findAllMatches:!1,minMatchCharLength:1,location:0,threshold:.6,distance:100,...{useExtendedSearch:!1,getFn:i}};function c(t,{errors:e=0,currentLocation:s=0,expectedLocation:n=0,distance:i=r.distance}={}){const c=e/t.length,h=Math.abs(n-s);return i?c+h/i:h?1:c}class h{constructor(t,e=({location:location=r.location,threshold:threshold=r.threshold,distance:distance=r.distance,includeMatches:includeMatches=r.includeMatches,findAllMatches:findAllMatches=r.findAllMatches,minMatchCharLength:minMatchCharLength=r.minMatchCharLength,isCaseSensitive:isCaseSensitive=r.isCaseSensitive}={})){if(this.options=e,t.length>32)throw new Error("Pattern length exceeds max of 32.");this.pattern=this.options.isCaseSensitive?t:t.toLowerCase(),this.patternAlphabet=function(t){let e={},s=t.length;for(let n=0;n<s;n+=1)e[t.charAt(n)]=0;for(let n=0;n<s;n+=1)e[t.charAt(n)]|=1<<s-n-1;return e}(this.pattern)}searchIn(t){let e=t.$;return this.searchInString(e)}searchInString(t){const{isCaseSensitive:e,includeMatches:s}=this.options;if(e||(t=t.toLowerCase()),this.pattern===t){let e={isMatch:!0,score:0};return s&&(e.matchedIndices=[[0,t.length-1]]),e}const{location:n,distance:i,threshold:h,findAllMatches:o,minMatchCharLength:a}=this.options;return function(t,e,s,{location:n=r.location,distance:i=r.distance,threshold:h=r.threshold,findAllMatches:o=r.findAllMatches,minMatchCharLength:a=r.minMatchCharLength,includeMatches:l=r.includeMatches}={}){const u=e.length,d=t.length,g=Math.max(0,Math.min(n,d));let f=h,p=t.indexOf(e,g);const M=[];for(let t=0;t<d;t+=1)M[t]=0;if(-1!==p){let s=c(e,{errors:0,currentLocation:p,expectedLocation:g,distance:i});if(f=Math.min(s,f),p=t.lastIndexOf(e,g+u),-1!==p){let t=c(e,{errors:0,currentLocation:p,expectedLocation:g,distance:i});f=Math.min(t,f)}}p=-1;let m=[],y=1,x=u+d;const _=1<<(u<=31?u-1:30);for(let n=0;n<u;n+=1){let r=0,h=x;for(;r<h;){c(e,{errors:n,currentLocation:g+h,expectedLocation:g,distance:i})<=f?r=h:x=h,h=Math.floor((x-r)/2+r)}x=h;let a=Math.max(1,g-h+1),l=o?d:Math.min(g+h,d)+u,S=Array(l+2);S[l+1]=(1<<n)-1;for(let r=l;r>=a;r-=1){let h=r-1,o=s[t.charAt(h)];if(o&&(M[h]=1),S[r]=(S[r+1]<<1|1)&o,0!==n&&(S[r]|=(m[r+1]|m[r])<<1|1|m[r+1]),S[r]&_&&(y=c(e,{errors:n,currentLocation:h,expectedLocation:g,distance:i}),y<=f)){if(f=y,p=h,p<=g)break;a=Math.max(1,2*g-p)}}if(c(e,{errors:n+1,currentLocation:g,expectedLocation:g,distance:i})>f)break;m=S}let S={isMatch:p>=0,score:y||.001};return l&&(S.matchedIndices=function(t=[],e=1){let s=[],n=-1,i=-1,r=0;for(let c=t.length;r<c;r+=1){let c=t[r];c&&-1===n?n=r:c||-1===n||(i=r-1,i-n+1>=e&&s.push([n,i]),n=-1)}return t[r-1]&&r-n>=e&&s.push([n,r-1]),s}(M,a)),S}(t,this.pattern,this.patternAlphabet,{location:n,distance:i,threshold:h,findAllMatches:o,minMatchCharLength:a,includeMatches:s})}}class o{constructor(t){this.pattern=t}static isLiteralMatch(t){return a(t,this.literal)}static isRegMatch(t){return a(t,this.re)}search(){}}function a(t,e){const s=t.match(e);return s?s[1]:null}class l extends o{constructor(t,e=({location:location=r.location,threshold:threshold=r.threshold,distance:distance=r.distance,includeMatches:includeMatches=r.includeMatches,findAllMatches:findAllMatches=r.findAllMatches,minMatchCharLength:minMatchCharLength=r.minMatchCharLength,isCaseSensitive:isCaseSensitive=r.isCaseSensitive}={})){super(t),this._bitapSearch=new h(t,e)}static get type(){return"fuzzy"}static get literal(){return/^"(.*)"$/}static get re(){return/^(.*)$/}search(t){return this._bitapSearch.searchInString(t)}}const u=[class extends o{constructor(t){super(t)}static get type(){return"exact"}static get literal(){return/^'"(.*)"$/}static get re(){return/^'(.*)$/}search(t){const e=t.indexOf(this.pattern),s=e>-1;return{isMatch:s,score:s?1:0,matchedIndices:[e,e+this.pattern.length-1]}}},class extends o{constructor(t){super(t)}static get type(){return"prefix-exact"}static get literal(){return/^\^"(.*)"$/}static get re(){return/^\^(.*)$/}search(t){const e=t.startsWith(this.pattern);return{isMatch:e,score:e?0:1,matchedIndices:[0,this.pattern.length-1]}}},class extends o{constructor(t){super(t)}static get type(){return"inverse-prefix-exact"}static get literal(){return/^!\^"(.*)"$/}static get re(){return/^!\^(.*)$/}search(t){const e=!t.startsWith(this.pattern);return{isMatch:e,score:e?0:1,matchedIndices:[0,t.length-1]}}},class extends o{constructor(t){super(t)}static get type(){return"inverse-suffix-exact"}static get literal(){return/^!"(.*)"\$$/}static get re(){return/^!(.*)\$$/}search(t){const e=!t.endsWith(this.pattern);return{isMatch:e,score:e?0:1,matchedIndices:[0,t.length-1]}}},class extends o{constructor(t){super(t)}static get type(){return"suffix-exact"}static get literal(){return/^"(.*)"\$$/}static get re(){return/^(.*)\$$/}search(t){const e=t.endsWith(this.pattern);return{isMatch:e,score:e?0:1,matchedIndices:[t.length-this.pattern.length,t.length-1]}}},class extends o{constructor(t){super(t)}static get type(){return"inverse-exact"}static get literal(){return/^!"(.*)"$/}static get re(){return/^!(.*)$/}search(t){const e=-1===t.indexOf(this.pattern);return{isMatch:e,score:e?0:1,matchedIndices:[0,t.length-1]}}},l],d=u.length,g=/ +(?=([^\"]*\"[^\"]*\")*[^\"]*$)/;function f(t,{n:e=3,pad:s=!0,sort:n=!1}){let i=[];if(null==t)return i;t=t.toLowerCase(),s&&(t=` ${t} `);let r=t.length-e+1;if(r<1)return i;for(;r--;)i[r]=t.substr(r,e);return n&&i.sort((t,e)=>t==e?0:t<e?-1:1),i}function p(s,r,{getFn:c=i,ngrams:h=!1}={}){let o=[];if(e(r[0]))for(let t=0,e=r.length;t<e;t+=1){const e=r[t];if(n(e)){let s={$:e,idx:t};h&&(s.ng=f(e,{sort:!0})),o.push(s)}}else{const i=s.length;for(let a=0,l=r.length;a<l;a+=1){let l=r[a],u={idx:a,$:{}};for(let r=0;r<i;r+=1){let i=s[r],o=c(l,i);if(n(o))if(t(o)){let s=[];const r=[{arrayIndex:-1,value:o}];for(;r.length;){const{arrayIndex:i,value:c}=r.pop();if(n(c))if(e(c)){let t={$:c,idx:i};h&&(t.ng=f(c,{sort:!0})),s.push(t)}else if(t(c))for(let t=0,e=c.length;t<e;t+=1)r.push({arrayIndex:t,value:c[t]})}u.$[i]=s}else{let t={$:o};h&&(t.ng=f(o,{sort:!0})),u.$[i]=t}}o.push(u)}}return o}class M{constructor(t){if(this._keys={},this._keyNames=[],this._length=t.length,t.length&&e(t[0]))for(let e=0;e<this._length;e+=1){const s=t[e];this._keys[s]={weight:1},this._keyNames.push(s)}else{let e=0;for(let s=0;s<this._length;s+=1){const n=t[s];if(!Object.prototype.hasOwnProperty.call(n,"name"))throw new Error('Missing "name" property in key object');const i=n.name;if(this._keyNames.push(i),!Object.prototype.hasOwnProperty.call(n,"weight"))throw new Error('Missing "weight" property in key object');const r=n.weight;if(r<=0||r>=1)throw new Error('"weight" property in key must be in the range of (0, 1)');this._keys[i]={weight:r},e+=r}for(let t=0;t<this._length;t+=1){const s=this._keyNames[t],n=this._keys[s].weight;this._keys[s].weight=n/e}}}get(t,e){return this._keys[t]?this._keys[t][e]:-1}keys(){return this._keyNames}count(){return this._length}toJSON(){return JSON.stringify(this._keys)}}function m(t,e){const s=t.matches;if(e.matches=[],n(s))for(let t=0,i=s.length;t<i;t+=1){let i=s[t];if(!n(i.indices)||0===i.indices.length)continue;let r={indices:i.indices,value:i.value};i.key&&(r.key=i.key),i.idx>-1&&(r.refIndex=i.idx),e.matches.push(r)}}function y(t,e){e.score=t.score}const x=[];class _{constructor(t,e={},s=null){this.options={...r,...e},this._processKeys(this.options.keys),this.setCollection(t,s)}static register(...t){x.push(...t)}setCollection(t,s=null){this.list=t,this.listIsStringArray=e(t[0]),s?this.setIndex(s):this.setIndex(this._createIndex())}setIndex(t){this._indexedList=t}_processKeys(t){this._keyStore=new M(t)}_createIndex(){return p(this._keyStore.keys(),this.list,{getFn:this.options.getFn})}search(t,e={limit:!1}){const{shouldSort:n}=this.options;let i=null;for(let e=0,s=x.length;e<s;e+=1){let s=x[e];if(s.condition(t,this.options)){i=new s(t,this.options);break}}i||(i=new h(t,this.options));let r=this._searchUsing(i);return this._computeScore(r),n&&this._sort(r),e.limit&&s(e.limit)&&(r=r.slice(0,e.limit)),this._format(r)}_searchUsing(e){const s=this._indexedList,i=[],{includeMatches:r}=this.options;if(this.listIsStringArray)for(let t=0,c=s.length;t<c;t+=1){let c=s[t],{$:h,idx:o}=c;if(!n(h))continue;let a=e.searchIn(c);const{isMatch:l,score:u}=a;if(!l)continue;let d={score:u,value:h};r&&(d.indices=a.matchedIndices),i.push({item:h,idx:o,matches:[d]})}else{const c=this._keyStore.keys(),h=this._keyStore.count();for(let o=0,a=s.length;o<a;o+=1){let{$:a,idx:l}=s[o];if(!n(a))continue;let u=[];for(let s=0;s<h;s+=1){let i=c[s],h=a[i];if(n(h))if(t(h))for(let t=0,s=h.length;t<s;t+=1){let s=h[t],c=s.$,o=s.idx;if(!n(c))continue;let a=e.searchIn(s);const{isMatch:l,score:d}=a;if(!l)continue;let g={score:d,key:i,value:c,idx:o};r&&(g.indices=a.matchedIndices),u.push(g)}else{let t=h.$,s=e.searchIn(h);const{isMatch:n,score:c}=s;if(!n)continue;let o={score:c,key:i,value:t};r&&(o.indices=s.matchedIndices),u.push(o)}}u.length&&i.push({idx:l,item:a,matches:u})}}return i}_computeScore(t){for(let e=0,s=t.length;e<s;e+=1){const s=t[e],n=s.matches,i=n.length;let r=1;for(let t=0;t<i;t+=1){const e=n[t],s=e.key,i=this._keyStore.get(s,"weight"),c=i>-1?i:1,h=0===e.score&&i>-1?Number.EPSILON:e.score;r*=Math.pow(h,c)}s.score=r}}_sort(t){t.sort(this.options.sortFn)}_format(t){const e=[],{includeMatches:s,includeScore:n}=this.options;let i=[];s&&i.push(m),n&&i.push(y);for(let s=0,n=t.length;s<n;s+=1){const n=t[s],{idx:r}=n,c={item:this.list[r],refIndex:r};if(i.length)for(let t=0,e=i.length;t<e;t+=1)i[t](n,c);e.push(c)}return e}}_.register(class{constructor(t,e=({isCaseSensitive:isCaseSensitive=r.isCaseSensitive,includeMatches:includeMatches=r.includeMatches,minMatchCharLength:minMatchCharLength=r.minMatchCharLength,findAllMatches:findAllMatches=r.findAllMatches,location:location=r.location,threshold:threshold=r.threshold,distance:distance=r.distance,includeMatches:includeMatches=r.includeMatches}={})){this.query=null,this.options=e,this.pattern=e.isCaseSensitive?t:t.toLowerCase(),this.query=function(t,e){return t.split("|").map(t=>{let s=t.trim().split(g).filter(t=>t&&!!t.trim()),n=[];for(let t=0,i=s.length;t<i;t+=1){const i=s[t];let r=!1,c=-1;for(;!r&&++c<d;){const t=u[c];let s=t.isLiteralMatch(i);s&&(n.push(new t(s,e)),r=!0)}if(!r)for(c=-1;++c<d;){const t=u[c];let s=t.isRegMatch(i);if(s){n.push(new t(s,e));break}}}return n})}(this.pattern,e)}static condition(t,e){return e.useExtendedSearch}searchIn(t){const e=this.query;if(!e)return{isMatch:!1,score:1};let s=t.$;const{includeMatches:n,isCaseSensitive:i}=this.options;s=i?s:s.toLowerCase();let r=0,c=[];for(let t=0,i=e.length;t<i;t+=1){const i=e[t];c.length=0,r=0;for(let t=0,e=i.length;t<e;t+=1){const e=i[t],{isMatch:h,matchedIndices:o}=e.search(s);if(!h){r=0,c.length=0;break}r+=1,n&&(e.constructor.type===l.type?c=[...c,...o]:c.push(o))}if(r){let t={isMatch:!0,score:0};return n&&(t.matchedIndices=c),t}}return{isMatch:!1,score:1}}},class{constructor(t,e=({threshold:threshold=r.threshold}={})){this.options=e,this.patternNgram=f(t,{sort:!0})}static condition(t){return t.length>32}searchIn(t){let e=t.ng;e||(e=f(t.$,{sort:!0}),t.ng=e);let s=function(t,e){let s=function(t,e){let s=[],n=0,i=0;for(;n<t.length&&i<e.length;){let r=t[n],c=e[i];r<c?(s.push(r),n+=1):c<r?(s.push(c),i+=1):(s.push(c),n+=1,i+=1)}for(;n<t.length;)s.push(t[n]),n+=1;for(;i<e.length;)s.push(e[i]),i+=1;return s}(t,e);return 1-function(t,e){let s=[],n=0,i=0;for(;n<t.length&&i<e.length;){let r=t[n],c=e[i];r==c?(s.push(r),n+=1,i+=1):r<c?n+=1:(r>c||(n+=1),i+=1)}return s}(t,e).length/s.length}(this.patternNgram,e);const n=s<this.options.threshold;return{score:n?s:1,isMatch:n}}}),_.version="5.2.0-alpha.1",_.createIndex=p,_.config=r;export default _; |
198
dist/fuse.js
/** | ||
* Fuse.js v5.2.0-alpha.0 - Lightweight fuzzy-search (http://fusejs.io) | ||
* Fuse.js v5.2.0-alpha.1 - Lightweight fuzzy-search (http://fusejs.io) | ||
* | ||
@@ -197,54 +197,2 @@ * Copyright (c) 2020 Kiro Risk (http://kiro.me) | ||
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; | ||
} | ||
var INFINITY = 1 / 0; | ||
@@ -372,3 +320,57 @@ var isArray = function isArray(value) { | ||
function bitapSearch(text, pattern, patternAlphabet) { | ||
function computeScore(pattern) { | ||
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
_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 ? Config.distance : _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 convertMaskToIndices() { | ||
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 search(text, pattern, patternAlphabet) { | ||
var _ref = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}, | ||
@@ -405,3 +407,3 @@ _ref$location = _ref.location, | ||
if (bestLocation !== -1) { | ||
var score = bitapScore(pattern, { | ||
var score = computeScore(pattern, { | ||
errors: 0, | ||
@@ -417,3 +419,3 @@ currentLocation: bestLocation, | ||
if (bestLocation !== -1) { | ||
var _score = bitapScore(pattern, { | ||
var _score = computeScore(pattern, { | ||
errors: 0, | ||
@@ -444,3 +446,3 @@ currentLocation: bestLocation, | ||
while (binMin < binMid) { | ||
var _score3 = bitapScore(pattern, { | ||
var _score3 = computeScore(pattern, { | ||
errors: _i, | ||
@@ -485,3 +487,3 @@ currentLocation: expectedLocation + binMid, | ||
if (bitArr[j] & mask) { | ||
finalScore = bitapScore(pattern, { | ||
finalScore = computeScore(pattern, { | ||
errors: _i, | ||
@@ -510,3 +512,3 @@ currentLocation: currentLocation, | ||
var _score2 = bitapScore(pattern, { | ||
var _score2 = computeScore(pattern, { | ||
errors: _i + 1, | ||
@@ -532,3 +534,3 @@ currentLocation: expectedLocation, | ||
if (includeMatches) { | ||
result.matchedIndices = matchedIndiced(matchMask, minMatchCharLength); | ||
result.matchedIndices = convertMaskToIndices(matchMask, minMatchCharLength); | ||
} | ||
@@ -539,3 +541,3 @@ | ||
function patternAlphabet(pattern) { | ||
function createPatternAlphabet(pattern) { | ||
var mask = {}; | ||
@@ -573,3 +575,3 @@ var len = pattern.length; | ||
this.pattern = this.options.isCaseSensitive ? pattern : pattern.toLowerCase(); | ||
this.patternAlphabet = patternAlphabet(this.pattern); | ||
this.patternAlphabet = createPatternAlphabet(this.pattern); | ||
} | ||
@@ -615,3 +617,3 @@ | ||
minMatchCharLength = _this$options2.minMatchCharLength; | ||
return bitapSearch(text, this.pattern, this.patternAlphabet, { | ||
return search(text, this.pattern, this.patternAlphabet, { | ||
location: location, | ||
@@ -630,5 +632,5 @@ distance: distance, | ||
var Match = /*#__PURE__*/function () { | ||
function Match(pattern) { | ||
_classCallCheck(this, Match); | ||
var BaseMatch = /*#__PURE__*/function () { | ||
function BaseMatch(pattern) { | ||
_classCallCheck(this, BaseMatch); | ||
@@ -638,3 +640,3 @@ this.pattern = pattern; | ||
_createClass(Match, [{ | ||
_createClass(BaseMatch, [{ | ||
key: "search", | ||
@@ -656,3 +658,3 @@ value: function search() | ||
return Match; | ||
return BaseMatch; | ||
}(); | ||
@@ -665,4 +667,4 @@ | ||
var ExactMatch = /*#__PURE__*/function (_Match) { | ||
_inherits(ExactMatch, _Match); | ||
var ExactMatch = /*#__PURE__*/function (_BaseMatch) { | ||
_inherits(ExactMatch, _BaseMatch); | ||
@@ -706,6 +708,6 @@ var _super = _createSuper(ExactMatch); | ||
return ExactMatch; | ||
}(Match); | ||
}(BaseMatch); | ||
var InverseExactMatch = /*#__PURE__*/function (_Match) { | ||
_inherits(InverseExactMatch, _Match); | ||
var InverseExactMatch = /*#__PURE__*/function (_BaseMatch) { | ||
_inherits(InverseExactMatch, _BaseMatch); | ||
@@ -749,6 +751,6 @@ var _super = _createSuper(InverseExactMatch); | ||
return InverseExactMatch; | ||
}(Match); | ||
}(BaseMatch); | ||
var PrefixExactMatch = /*#__PURE__*/function (_Match) { | ||
_inherits(PrefixExactMatch, _Match); | ||
var PrefixExactMatch = /*#__PURE__*/function (_BaseMatch) { | ||
_inherits(PrefixExactMatch, _BaseMatch); | ||
@@ -791,6 +793,6 @@ var _super = _createSuper(PrefixExactMatch); | ||
return PrefixExactMatch; | ||
}(Match); | ||
}(BaseMatch); | ||
var InversePrefixExactMatch = /*#__PURE__*/function (_Match) { | ||
_inherits(InversePrefixExactMatch, _Match); | ||
var InversePrefixExactMatch = /*#__PURE__*/function (_BaseMatch) { | ||
_inherits(InversePrefixExactMatch, _BaseMatch); | ||
@@ -833,6 +835,6 @@ var _super = _createSuper(InversePrefixExactMatch); | ||
return InversePrefixExactMatch; | ||
}(Match); | ||
}(BaseMatch); | ||
var SuffixExactMatch = /*#__PURE__*/function (_Match) { | ||
_inherits(SuffixExactMatch, _Match); | ||
var SuffixExactMatch = /*#__PURE__*/function (_BaseMatch) { | ||
_inherits(SuffixExactMatch, _BaseMatch); | ||
@@ -875,6 +877,6 @@ var _super = _createSuper(SuffixExactMatch); | ||
return SuffixExactMatch; | ||
}(Match); | ||
}(BaseMatch); | ||
var InverseSuffixExactMatch = /*#__PURE__*/function (_Match) { | ||
_inherits(InverseSuffixExactMatch, _Match); | ||
var InverseSuffixExactMatch = /*#__PURE__*/function (_BaseMatch) { | ||
_inherits(InverseSuffixExactMatch, _BaseMatch); | ||
@@ -917,6 +919,6 @@ var _super = _createSuper(InverseSuffixExactMatch); | ||
return InverseSuffixExactMatch; | ||
}(Match); | ||
}(BaseMatch); | ||
var FuzzyMatch = /*#__PURE__*/function (_Match) { | ||
_inherits(FuzzyMatch, _Match); | ||
var FuzzyMatch = /*#__PURE__*/function (_BaseMatch) { | ||
_inherits(FuzzyMatch, _BaseMatch); | ||
@@ -962,3 +964,3 @@ var _super = _createSuper(FuzzyMatch); | ||
return FuzzyMatch; | ||
}(Match); | ||
}(BaseMatch); | ||
@@ -1143,6 +1145,6 @@ var searchers = [ExactMatch, PrefixExactMatch, InversePrefixExactMatch, InverseSuffixExactMatch, SuffixExactMatch, InverseExactMatch, FuzzyMatch]; | ||
var NGRAM_LEN = 3; | ||
function ngram(text, _ref) { | ||
var NGRAMS = 3; | ||
function createNGram(text, _ref) { | ||
var _ref$n = _ref.n, | ||
n = _ref$n === void 0 ? NGRAM_LEN : _ref$n, | ||
n = _ref$n === void 0 ? NGRAMS : _ref$n, | ||
_ref$pad = _ref.pad, | ||
@@ -1262,3 +1264,3 @@ pad = _ref$pad === void 0 ? true : _ref$pad, | ||
this.options = options; | ||
this.patternNgram = ngram(pattern, { | ||
this.patternNgram = createNGram(pattern, { | ||
sort: true | ||
@@ -1274,3 +1276,3 @@ }); | ||
if (!textNgram) { | ||
textNgram = ngram(value.$, { | ||
textNgram = createNGram(value.$, { | ||
sort: true | ||
@@ -1322,3 +1324,3 @@ }); | ||
if (ngrams) { | ||
record.ng = ngram(value, { | ||
record.ng = createNGram(value, { | ||
sort: true | ||
@@ -1377,3 +1379,3 @@ }); | ||
if (ngrams) { | ||
subRecord.ng = ngram(_value2, { | ||
subRecord.ng = createNGram(_value2, { | ||
sort: true | ||
@@ -1404,3 +1406,3 @@ }); | ||
if (ngrams) { | ||
_subRecord.ng = ngram(_value, { | ||
_subRecord.ng = createNGram(_value, { | ||
sort: true | ||
@@ -1825,3 +1827,3 @@ }); | ||
Fuse.register(ExtendedSearch, NGramSearch); | ||
Fuse.version = '5.2.0-alpha.0'; | ||
Fuse.version = '5.2.0-alpha.1'; | ||
Fuse.createIndex = createIndex; | ||
@@ -1828,0 +1830,0 @@ Fuse.config = Config; |
/** | ||
* Fuse.js v5.2.0-alpha.0 - Lightweight fuzzy-search (http://fusejs.io) | ||
* Fuse.js v5.2.0-alpha.1 - Lightweight fuzzy-search (http://fusejs.io) | ||
* | ||
@@ -9,2 +9,2 @@ * Copyright (c) 2020 Kiro Risk (http://kiro.me) | ||
*/ | ||
var t,e;t=this,e=function(){"use strict";function t(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function e(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function n(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}function r(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function i(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function o(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?i(Object(n),!0).forEach((function(e){r(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function a(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&c(t,e)}function s(t){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function c(t,e){return(c=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function h(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function u(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function l(t){return function(){var e,n=s(t);if(h()){var r=s(this).constructor;e=Reflect.construct(n,arguments,r)}else e=n.apply(this,arguments);return u(this,e)}}function f(t){return function(t){if(Array.isArray(t))return v(t)}(t)||function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return v(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(n):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?v(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function v(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function d(t,e){var n=e.errors,r=void 0===n?0:n,i=e.currentLocation,o=void 0===i?0:i,a=e.expectedLocation,s=void 0===a?0:a,c=e.distance,h=void 0===c?100:c,u=r/t.length,l=Math.abs(s-o);return h?u+l/h:l?1:u}function p(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=[],r=-1,i=-1,o=0,a=t.length;o<a;o+=1){var s=t[o];s&&-1===r?r=o:s||-1===r||((i=o-1)-r+1>=e&&n.push([r,i]),r=-1)}return t[o-1]&&o-r>=e&&n.push([r,o-1]),n}var y=function(t){return Array.isArray?Array.isArray(t):"[object Array]"===Object.prototype.toString.call(t)},g=function(t){return"string"==typeof t},m=function(t){return"number"==typeof t},k=function(t){return null!=t};function M(t,e){var n=[],r=!1;return function t(e,i){if(i){var o=i.indexOf("."),a=i,s=null;-1!==o&&(a=i.slice(0,o),s=i.slice(o+1));var c=e[a];if(k(c))if(s||!g(c)&&!m(c))if(y(c)){r=!0;for(var h=0,u=c.length;h<u;h+=1)t(c[h],s)}else s&&t(c,s);else n.push(function(t){return null==t?"":function(t){if("string"==typeof t)return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}(t)}(c))}else n.push(e)}(t,e),r?n:n[0]}var b=o({},{isCaseSensitive:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:function(t,e){return t.score-e.score}},{},{includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},{},{location:0,threshold:.6,distance:100},{},{useExtendedSearch:!1,getFn:M});function x(t){for(var e={},n=t.length,r=0;r<n;r+=1)e[t.charAt(r)]=0;for(var i=0;i<n;i+=1)e[t.charAt(i)]|=1<<n-i-1;return e}var w=function(){function e(n){var r,i,o,a,s,c,h,u,l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:(i=(r={}).location,location=void 0===i?b.location:i,o=r.threshold,threshold=void 0===o?b.threshold:o,a=r.distance,distance=void 0===a?b.distance:a,s=r.includeMatches,includeMatches=void 0===s?b.includeMatches:s,c=r.findAllMatches,findAllMatches=void 0===c?b.findAllMatches:c,h=r.minMatchCharLength,minMatchCharLength=void 0===h?b.minMatchCharLength:h,u=r.isCaseSensitive,isCaseSensitive=void 0===u?b.isCaseSensitive:u,r);if(t(this,e),this.options=l,n.length>32)throw new Error("Pattern length exceeds max of ".concat(32,"."));this.pattern=this.options.isCaseSensitive?n:n.toLowerCase(),this.patternAlphabet=x(this.pattern)}return n(e,[{key:"searchIn",value:function(t){var e=t.$;return this.searchInString(e)}},{key:"searchInString",value:function(t){var e=this.options,n=e.isCaseSensitive,r=e.includeMatches;if(n||(t=t.toLowerCase()),this.pattern===t){var i={isMatch:!0,score:0};return r&&(i.matchedIndices=[[0,t.length-1]]),i}var o=this.options,a=o.location,s=o.distance,c=o.threshold,h=o.findAllMatches,u=o.minMatchCharLength;return function(t,e,n){for(var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},i=r.location,o=void 0===i?b.location:i,a=r.distance,s=void 0===a?b.distance:a,c=r.threshold,h=void 0===c?b.threshold:c,u=r.findAllMatches,l=void 0===u?b.findAllMatches:u,f=r.minMatchCharLength,v=void 0===f?b.minMatchCharLength:f,y=r.includeMatches,g=void 0===y?b.includeMatches:y,m=e.length,k=t.length,M=Math.max(0,Math.min(o,k)),x=h,w=t.indexOf(e,M),S=[],_=0;_<k;_+=1)S[_]=0;if(-1!==w){var O=d(e,{errors:0,currentLocation:w,expectedLocation:M,distance:s});if(x=Math.min(O,x),-1!==(w=t.lastIndexOf(e,M+m))){var I=d(e,{errors:0,currentLocation:w,expectedLocation:M,distance:s});x=Math.min(I,x)}}w=-1;for(var C=[],L=1,A=m+k,$=1<<(m<=31?m-1:30),j=0;j<m;j+=1){for(var P=0,E=A;P<E;){var N=d(e,{errors:j,currentLocation:M+E,expectedLocation:M,distance:s});N<=x?P=E:A=E,E=Math.floor((A-P)/2+P)}A=E;var R=Math.max(1,M-E+1),F=l?k:Math.min(M+E,k)+m,D=Array(F+2);D[F+1]=(1<<j)-1;for(var W=F;W>=R;W-=1){var q=W-1,T=n[t.charAt(q)];if(T&&(S[q]=1),D[W]=(D[W+1]<<1|1)&T,0!==j&&(D[W]|=(C[W+1]|C[W])<<1|1|C[W+1]),D[W]&$&&(L=d(e,{errors:j,currentLocation:q,expectedLocation:M,distance:s}))<=x){if(x=L,(w=q)<=M)break;R=Math.max(1,2*M-w)}}var U=d(e,{errors:j+1,currentLocation:M,expectedLocation:M,distance:s});if(U>x)break;C=D}var z={isMatch:w>=0,score:L||.001};return g&&(z.matchedIndices=p(S,v)),z}(t,this.pattern,this.patternAlphabet,{location:a,distance:s,threshold:c,findAllMatches:h,minMatchCharLength:u,includeMatches:r})}}]),e}(),S=function(){function e(n){t(this,e),this.pattern=n}return n(e,[{key:"search",value:function(){}}],[{key:"isLiteralMatch",value:function(t){return _(t,this.literal)}},{key:"isRegMatch",value:function(t){return _(t,this.re)}}]),e}();function _(t,e){var n=t.match(e);return n?n[1]:null}var O=function(e){a(i,e);var r=l(i);function i(e){return t(this,i),r.call(this,e)}return n(i,[{key:"search",value:function(t){var e=t.indexOf(this.pattern),n=e>-1;return{isMatch:n,score:n?1:0,matchedIndices:[e,e+this.pattern.length-1]}}}],[{key:"type",get:function(){return"exact"}},{key:"literal",get:function(){return/^'"(.*)"$/}},{key:"re",get:function(){return/^'(.*)$/}}]),i}(S),I=function(e){a(i,e);var r=l(i);function i(e){return t(this,i),r.call(this,e)}return n(i,[{key:"search",value:function(t){var e=-1===t.indexOf(this.pattern);return{isMatch:e,score:e?0:1,matchedIndices:[0,t.length-1]}}}],[{key:"type",get:function(){return"inverse-exact"}},{key:"literal",get:function(){return/^!"(.*)"$/}},{key:"re",get:function(){return/^!(.*)$/}}]),i}(S),C=function(e){a(i,e);var r=l(i);function i(e){return t(this,i),r.call(this,e)}return n(i,[{key:"search",value:function(t){var e=t.startsWith(this.pattern);return{isMatch:e,score:e?0:1,matchedIndices:[0,this.pattern.length-1]}}}],[{key:"type",get:function(){return"prefix-exact"}},{key:"literal",get:function(){return/^\^"(.*)"$/}},{key:"re",get:function(){return/^\^(.*)$/}}]),i}(S),L=function(e){a(i,e);var r=l(i);function i(e){return t(this,i),r.call(this,e)}return n(i,[{key:"search",value:function(t){var e=!t.startsWith(this.pattern);return{isMatch:e,score:e?0:1,matchedIndices:[0,t.length-1]}}}],[{key:"type",get:function(){return"inverse-prefix-exact"}},{key:"literal",get:function(){return/^!\^"(.*)"$/}},{key:"re",get:function(){return/^!\^(.*)$/}}]),i}(S),A=function(e){a(i,e);var r=l(i);function i(e){return t(this,i),r.call(this,e)}return n(i,[{key:"search",value:function(t){var e=t.endsWith(this.pattern);return{isMatch:e,score:e?0:1,matchedIndices:[t.length-this.pattern.length,t.length-1]}}}],[{key:"type",get:function(){return"suffix-exact"}},{key:"literal",get:function(){return/^"(.*)"\$$/}},{key:"re",get:function(){return/^(.*)\$$/}}]),i}(S),$=function(e){a(i,e);var r=l(i);function i(e){return t(this,i),r.call(this,e)}return n(i,[{key:"search",value:function(t){var e=!t.endsWith(this.pattern);return{isMatch:e,score:e?0:1,matchedIndices:[0,t.length-1]}}}],[{key:"type",get:function(){return"inverse-suffix-exact"}},{key:"literal",get:function(){return/^!"(.*)"\$$/}},{key:"re",get:function(){return/^!(.*)\$$/}}]),i}(S),j=function(e){a(i,e);var r=l(i);function i(e){var n,o,a,s,c,h,u,l,f,v=arguments.length>1&&void 0!==arguments[1]?arguments[1]:(o=(n={}).location,location=void 0===o?b.location:o,a=n.threshold,threshold=void 0===a?b.threshold:a,s=n.distance,distance=void 0===s?b.distance:s,c=n.includeMatches,includeMatches=void 0===c?b.includeMatches:c,h=n.findAllMatches,findAllMatches=void 0===h?b.findAllMatches:h,u=n.minMatchCharLength,minMatchCharLength=void 0===u?b.minMatchCharLength:u,l=n.isCaseSensitive,isCaseSensitive=void 0===l?b.isCaseSensitive:l,n);return t(this,i),(f=r.call(this,e))._bitapSearch=new w(e,v),f}return n(i,[{key:"search",value:function(t){return this._bitapSearch.searchInString(t)}}],[{key:"type",get:function(){return"fuzzy"}},{key:"literal",get:function(){return/^"(.*)"$/}},{key:"re",get:function(){return/^(.*)$/}}]),i}(S),P=[O,C,L,$,A,I,j],E=P.length,N=/ +(?=([^\"]*\"[^\"]*\")*[^\"]*$)/;function R(t,e){return t.split("|").map((function(t){for(var n=t.trim().split(N).filter((function(t){return t&&!!t.trim()})),r=[],i=0,o=n.length;i<o;i+=1){for(var a=n[i],s=!1,c=-1;!s&&++c<E;){var h=P[c],u=h.isLiteralMatch(a);u&&(r.push(new h(u,e)),s=!0)}if(!s)for(c=-1;++c<E;){var l=P[c],f=l.isRegMatch(a);if(f){r.push(new l(f,e));break}}}return r}))}var F=function(){function e(n){var r,i,o,a,s,c,h,u,l,f=arguments.length>1&&void 0!==arguments[1]?arguments[1]:(i=(r={}).isCaseSensitive,isCaseSensitive=void 0===i?b.isCaseSensitive:i,o=r.includeMatches,includeMatches=void 0===o?b.includeMatches:o,a=r.minMatchCharLength,minMatchCharLength=void 0===a?b.minMatchCharLength:a,s=r.findAllMatches,findAllMatches=void 0===s?b.findAllMatches:s,c=r.location,location=void 0===c?b.location:c,h=r.threshold,threshold=void 0===h?b.threshold:h,u=r.distance,distance=void 0===u?b.distance:u,l=r.includeMatches,includeMatches=void 0===l?b.includeMatches:l,r);t(this,e),this.query=null,this.options=f,this.pattern=f.isCaseSensitive?n:n.toLowerCase(),this.query=R(this.pattern,f)}return n(e,[{key:"searchIn",value:function(t){var e=this.query;if(!e)return{isMatch:!1,score:1};var n=t.$,r=this.options,i=r.includeMatches;n=r.isCaseSensitive?n:n.toLowerCase();for(var o=0,a=[],s=0,c=e.length;s<c;s+=1){var h=e[s];a.length=0,o=0;for(var u=0,l=h.length;u<l;u+=1){var v=h[u],d=v.search(n),p=d.isMatch,y=d.matchedIndices;if(!p){o=0,a.length=0;break}o+=1,i&&(v.constructor.type===j.type?a=[].concat(f(a),f(y)):a.push(y))}if(o){var g={isMatch:!0,score:0};return i&&(g.matchedIndices=a),g}}return{isMatch:!1,score:1}}}],[{key:"condition",value:function(t,e){return e.useExtendedSearch}}]),e}();function D(t,e){var n=e.n,r=void 0===n?3:n,i=e.pad,o=void 0===i||i,a=e.sort,s=void 0!==a&&a,c=[];if(null==t)return c;t=t.toLowerCase(),o&&(t=" ".concat(t," "));var h=t.length-r+1;if(h<1)return c;for(;h--;)c[h]=t.substr(h,r);return s&&c.sort((function(t,e){return t==e?0:t<e?-1:1})),c}var W=function(){function e(n){var r,i,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:(i=(r={}).threshold,threshold=void 0===i?b.threshold:i,r);t(this,e),this.options=o,this.patternNgram=D(n,{sort:!0})}return n(e,[{key:"searchIn",value:function(t){var e=t.ng;e||(e=D(t.$,{sort:!0}),t.ng=e);var n,r,i,o=(n=this.patternNgram,i=function(t,e){for(var n=[],r=0,i=0;r<t.length&&i<e.length;){var o=t[r],a=e[i];o<a?(n.push(o),r+=1):a<o?(n.push(a),i+=1):(n.push(a),r+=1,i+=1)}for(;r<t.length;)n.push(t[r]),r+=1;for(;i<e.length;)n.push(e[i]),i+=1;return n}(n,r=e),1-function(t,e){for(var n=[],r=0,i=0;r<t.length&&i<e.length;){var o=t[r],a=e[i];o==a?(n.push(o),r+=1,i+=1):o<a?r+=1:(o>a||(r+=1),i+=1)}return n}(n,r).length/i.length),a=o<this.options.threshold;return{score:a?o:1,isMatch:a}}}],[{key:"condition",value:function(t){return t.length>32}}]),e}();function q(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n.getFn,i=void 0===r?M:r,o=n.ngrams,a=void 0!==o&&o,s=[];if(g(e[0]))for(var c=0,h=e.length;c<h;c+=1){var u=e[c];if(k(u)){var l={$:u,idx:c};a&&(l.ng=D(u,{sort:!0})),s.push(l)}}else for(var f=t.length,v=0,d=e.length;v<d;v+=1){for(var p=e[v],m={idx:v,$:{}},b=0;b<f;b+=1){var x=t[b],w=i(p,x);if(k(w))if(y(w)){for(var S=[],_=[{arrayIndex:-1,value:w}];_.length;){var O=_.pop(),I=O.arrayIndex,C=O.value;if(k(C))if(g(C)){var L={$:C,idx:I};a&&(L.ng=D(C,{sort:!0})),S.push(L)}else if(y(C))for(var A=0,$=C.length;A<$;A+=1)_.push({arrayIndex:A,value:C[A]})}m.$[x]=S}else{var j={$:w};a&&(j.ng=D(w,{sort:!0})),m.$[x]=j}}s.push(m)}return s}var T=function(){function e(n){if(t(this,e),this._keys={},this._keyNames=[],this._length=n.length,n.length&&g(n[0]))for(var r=0;r<this._length;r+=1){var i=n[r];this._keys[i]={weight:1},this._keyNames.push(i)}else{for(var o=0,a=0;a<this._length;a+=1){var s=n[a];if(!Object.prototype.hasOwnProperty.call(s,"name"))throw new Error('Missing "name" property in key object');var c=s.name;if(this._keyNames.push(c),!Object.prototype.hasOwnProperty.call(s,"weight"))throw new Error('Missing "weight" property in key object');var h=s.weight;if(h<=0||h>=1)throw new Error('"weight" property in key must be in the range of (0, 1)');this._keys[c]={weight:h},o+=h}for(var u=0;u<this._length;u+=1){var l=this._keyNames[u],f=this._keys[l].weight;this._keys[l].weight=f/o}}}return n(e,[{key:"get",value:function(t,e){return this._keys[t]?this._keys[t][e]:-1}},{key:"keys",value:function(){return this._keyNames}},{key:"count",value:function(){return this._length}},{key:"toJSON",value:function(){return JSON.stringify(this._keys)}}]),e}();function U(t,e){var n=t.matches;if(e.matches=[],k(n))for(var r=0,i=n.length;r<i;r+=1){var o=n[r];if(k(o.indices)&&0!==o.indices.length){var a={indices:o.indices,value:o.value};o.key&&(a.key=o.key),o.idx>-1&&(a.refIndex=o.idx),e.matches.push(a)}}}function z(t,e){e.score=t.score}var J=[],K=function(){function e(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;t(this,e),this.options=o({},b,{},r),this._processKeys(this.options.keys),this.setCollection(n,i)}return n(e,[{key:"setCollection",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;this.list=t,this.listIsStringArray=g(t[0]),e?this.setIndex(e):this.setIndex(this._createIndex())}},{key:"setIndex",value:function(t){this._indexedList=t}},{key:"_processKeys",value:function(t){this._keyStore=new T(t)}},{key:"_createIndex",value:function(){return q(this._keyStore.keys(),this.list,{getFn:this.options.getFn})}},{key:"search",value:function(t){for(var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{limit:!1},n=this.options.shouldSort,r=null,i=0,o=J.length;i<o;i+=1){var a=J[i];if(a.condition(t,this.options)){r=new a(t,this.options);break}}r||(r=new w(t,this.options));var s=this._searchUsing(r);return this._computeScore(s),n&&this._sort(s),e.limit&&m(e.limit)&&(s=s.slice(0,e.limit)),this._format(s)}},{key:"_searchUsing",value:function(t){var e=this._indexedList,n=[],r=this.options.includeMatches;if(this.listIsStringArray)for(var i=0,o=e.length;i<o;i+=1){var a=e[i],s=a.$,c=a.idx;if(k(s)){var h=t.searchIn(a),u=h.isMatch,l=h.score;if(u){var f={score:l,value:s};r&&(f.indices=h.matchedIndices),n.push({item:s,idx:c,matches:[f]})}}}else for(var v=this._keyStore.keys(),d=this._keyStore.count(),p=0,g=e.length;p<g;p+=1){var m=e[p],M=m.$,b=m.idx;if(k(M)){for(var x=[],w=0;w<d;w+=1){var S=v[w],_=M[S];if(k(_))if(y(_))for(var O=0,I=_.length;O<I;O+=1){var C=_[O],L=C.$,A=C.idx;if(k(L)){var $=t.searchIn(C),j=$.isMatch,P=$.score;if(j){var E={score:P,key:S,value:L,idx:A};r&&(E.indices=$.matchedIndices),x.push(E)}}}else{var N=_.$,R=t.searchIn(_),F=R.isMatch,D=R.score;if(!F)continue;var W={score:D,key:S,value:N};r&&(W.indices=R.matchedIndices),x.push(W)}}x.length&&n.push({idx:b,item:M,matches:x})}}return n}},{key:"_computeScore",value:function(t){for(var e=0,n=t.length;e<n;e+=1){for(var r=t[e],i=r.matches,o=i.length,a=1,s=0;s<o;s+=1){var c=i[s],h=c.key,u=this._keyStore.get(h,"weight"),l=u>-1?u:1,f=0===c.score&&u>-1?Number.EPSILON:c.score;a*=Math.pow(f,l)}r.score=a}}},{key:"_sort",value:function(t){t.sort(this.options.sortFn)}},{key:"_format",value:function(t){var e=[],n=this.options,r=n.includeMatches,i=n.includeScore,o=[];r&&o.push(U),i&&o.push(z);for(var a=0,s=t.length;a<s;a+=1){var c=t[a],h=c.idx,u={item:this.list[h],refIndex:h};if(o.length)for(var l=0,f=o.length;l<f;l+=1)o[l](c,u);e.push(u)}return e}}],[{key:"register",value:function(){J.push.apply(J,arguments)}}]),e}();return K.register(F,W),K.version="5.2.0-alpha.0",K.createIndex=q,K.config=b,K},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).Fuse=e(); | ||
var t,e;t=this,e=function(){"use strict";function t(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function e(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function n(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}function r(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function i(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function o(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?i(Object(n),!0).forEach((function(e){r(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function a(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&c(t,e)}function s(t){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function c(t,e){return(c=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function h(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function u(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function l(t){return function(){var e,n=s(t);if(h()){var r=s(this).constructor;e=Reflect.construct(n,arguments,r)}else e=n.apply(this,arguments);return u(this,e)}}function f(t){return function(t){if(Array.isArray(t))return v(t)}(t)||function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return v(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(n):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?v(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function v(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var d=function(t){return Array.isArray?Array.isArray(t):"[object Array]"===Object.prototype.toString.call(t)},p=function(t){return"string"==typeof t},y=function(t){return"number"==typeof t},g=function(t){return null!=t};function m(t,e){var n=[],r=!1;return function t(e,i){if(i){var o=i.indexOf("."),a=i,s=null;-1!==o&&(a=i.slice(0,o),s=i.slice(o+1));var c=e[a];if(g(c))if(s||!p(c)&&!y(c))if(d(c)){r=!0;for(var h=0,u=c.length;h<u;h+=1)t(c[h],s)}else s&&t(c,s);else n.push(function(t){return null==t?"":function(t){if("string"==typeof t)return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}(t)}(c))}else n.push(e)}(t,e),r?n:n[0]}var k=o({},{isCaseSensitive:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:function(t,e){return t.score-e.score}},{},{includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},{},{location:0,threshold:.6,distance:100},{},{useExtendedSearch:!1,getFn:m});function M(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=e.errors,r=void 0===n?0:n,i=e.currentLocation,o=void 0===i?0:i,a=e.expectedLocation,s=void 0===a?0:a,c=e.distance,h=void 0===c?k.distance:c,u=r/t.length,l=Math.abs(s-o);return h?u+l/h:l?1:u}function b(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=[],r=-1,i=-1,o=0,a=t.length;o<a;o+=1){var s=t[o];s&&-1===r?r=o:s||-1===r||((i=o-1)-r+1>=e&&n.push([r,i]),r=-1)}return t[o-1]&&o-r>=e&&n.push([r,o-1]),n}function x(t){for(var e={},n=t.length,r=0;r<n;r+=1)e[t.charAt(r)]=0;for(var i=0;i<n;i+=1)e[t.charAt(i)]|=1<<n-i-1;return e}var w=function(){function e(n){var r,i,o,a,s,c,h,u,l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:(i=(r={}).location,location=void 0===i?k.location:i,o=r.threshold,threshold=void 0===o?k.threshold:o,a=r.distance,distance=void 0===a?k.distance:a,s=r.includeMatches,includeMatches=void 0===s?k.includeMatches:s,c=r.findAllMatches,findAllMatches=void 0===c?k.findAllMatches:c,h=r.minMatchCharLength,minMatchCharLength=void 0===h?k.minMatchCharLength:h,u=r.isCaseSensitive,isCaseSensitive=void 0===u?k.isCaseSensitive:u,r);if(t(this,e),this.options=l,n.length>32)throw new Error("Pattern length exceeds max of ".concat(32,"."));this.pattern=this.options.isCaseSensitive?n:n.toLowerCase(),this.patternAlphabet=x(this.pattern)}return n(e,[{key:"searchIn",value:function(t){var e=t.$;return this.searchInString(e)}},{key:"searchInString",value:function(t){var e=this.options,n=e.isCaseSensitive,r=e.includeMatches;if(n||(t=t.toLowerCase()),this.pattern===t){var i={isMatch:!0,score:0};return r&&(i.matchedIndices=[[0,t.length-1]]),i}var o=this.options,a=o.location,s=o.distance,c=o.threshold,h=o.findAllMatches,u=o.minMatchCharLength;return function(t,e,n){for(var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},i=r.location,o=void 0===i?k.location:i,a=r.distance,s=void 0===a?k.distance:a,c=r.threshold,h=void 0===c?k.threshold:c,u=r.findAllMatches,l=void 0===u?k.findAllMatches:u,f=r.minMatchCharLength,v=void 0===f?k.minMatchCharLength:f,d=r.includeMatches,p=void 0===d?k.includeMatches:d,y=e.length,g=t.length,m=Math.max(0,Math.min(o,g)),x=h,w=t.indexOf(e,m),S=[],_=0;_<g;_+=1)S[_]=0;if(-1!==w){var O=M(e,{errors:0,currentLocation:w,expectedLocation:m,distance:s});if(x=Math.min(O,x),-1!==(w=t.lastIndexOf(e,m+y))){var I=M(e,{errors:0,currentLocation:w,expectedLocation:m,distance:s});x=Math.min(I,x)}}w=-1;for(var C=[],L=1,A=y+g,$=1<<(y<=31?y-1:30),j=0;j<y;j+=1){for(var P=0,E=A;P<E;){var N=M(e,{errors:j,currentLocation:m+E,expectedLocation:m,distance:s});N<=x?P=E:A=E,E=Math.floor((A-P)/2+P)}A=E;var R=Math.max(1,m-E+1),F=l?g:Math.min(m+E,g)+y,D=Array(F+2);D[F+1]=(1<<j)-1;for(var W=F;W>=R;W-=1){var q=W-1,T=n[t.charAt(q)];if(T&&(S[q]=1),D[W]=(D[W+1]<<1|1)&T,0!==j&&(D[W]|=(C[W+1]|C[W])<<1|1|C[W+1]),D[W]&$&&(L=M(e,{errors:j,currentLocation:q,expectedLocation:m,distance:s}))<=x){if(x=L,(w=q)<=m)break;R=Math.max(1,2*m-w)}}var U=M(e,{errors:j+1,currentLocation:m,expectedLocation:m,distance:s});if(U>x)break;C=D}var z={isMatch:w>=0,score:L||.001};return p&&(z.matchedIndices=b(S,v)),z}(t,this.pattern,this.patternAlphabet,{location:a,distance:s,threshold:c,findAllMatches:h,minMatchCharLength:u,includeMatches:r})}}]),e}(),S=function(){function e(n){t(this,e),this.pattern=n}return n(e,[{key:"search",value:function(){}}],[{key:"isLiteralMatch",value:function(t){return _(t,this.literal)}},{key:"isRegMatch",value:function(t){return _(t,this.re)}}]),e}();function _(t,e){var n=t.match(e);return n?n[1]:null}var O=function(e){a(i,e);var r=l(i);function i(e){return t(this,i),r.call(this,e)}return n(i,[{key:"search",value:function(t){var e=t.indexOf(this.pattern),n=e>-1;return{isMatch:n,score:n?1:0,matchedIndices:[e,e+this.pattern.length-1]}}}],[{key:"type",get:function(){return"exact"}},{key:"literal",get:function(){return/^'"(.*)"$/}},{key:"re",get:function(){return/^'(.*)$/}}]),i}(S),I=function(e){a(i,e);var r=l(i);function i(e){return t(this,i),r.call(this,e)}return n(i,[{key:"search",value:function(t){var e=-1===t.indexOf(this.pattern);return{isMatch:e,score:e?0:1,matchedIndices:[0,t.length-1]}}}],[{key:"type",get:function(){return"inverse-exact"}},{key:"literal",get:function(){return/^!"(.*)"$/}},{key:"re",get:function(){return/^!(.*)$/}}]),i}(S),C=function(e){a(i,e);var r=l(i);function i(e){return t(this,i),r.call(this,e)}return n(i,[{key:"search",value:function(t){var e=t.startsWith(this.pattern);return{isMatch:e,score:e?0:1,matchedIndices:[0,this.pattern.length-1]}}}],[{key:"type",get:function(){return"prefix-exact"}},{key:"literal",get:function(){return/^\^"(.*)"$/}},{key:"re",get:function(){return/^\^(.*)$/}}]),i}(S),L=function(e){a(i,e);var r=l(i);function i(e){return t(this,i),r.call(this,e)}return n(i,[{key:"search",value:function(t){var e=!t.startsWith(this.pattern);return{isMatch:e,score:e?0:1,matchedIndices:[0,t.length-1]}}}],[{key:"type",get:function(){return"inverse-prefix-exact"}},{key:"literal",get:function(){return/^!\^"(.*)"$/}},{key:"re",get:function(){return/^!\^(.*)$/}}]),i}(S),A=function(e){a(i,e);var r=l(i);function i(e){return t(this,i),r.call(this,e)}return n(i,[{key:"search",value:function(t){var e=t.endsWith(this.pattern);return{isMatch:e,score:e?0:1,matchedIndices:[t.length-this.pattern.length,t.length-1]}}}],[{key:"type",get:function(){return"suffix-exact"}},{key:"literal",get:function(){return/^"(.*)"\$$/}},{key:"re",get:function(){return/^(.*)\$$/}}]),i}(S),$=function(e){a(i,e);var r=l(i);function i(e){return t(this,i),r.call(this,e)}return n(i,[{key:"search",value:function(t){var e=!t.endsWith(this.pattern);return{isMatch:e,score:e?0:1,matchedIndices:[0,t.length-1]}}}],[{key:"type",get:function(){return"inverse-suffix-exact"}},{key:"literal",get:function(){return/^!"(.*)"\$$/}},{key:"re",get:function(){return/^!(.*)\$$/}}]),i}(S),j=function(e){a(i,e);var r=l(i);function i(e){var n,o,a,s,c,h,u,l,f,v=arguments.length>1&&void 0!==arguments[1]?arguments[1]:(o=(n={}).location,location=void 0===o?k.location:o,a=n.threshold,threshold=void 0===a?k.threshold:a,s=n.distance,distance=void 0===s?k.distance:s,c=n.includeMatches,includeMatches=void 0===c?k.includeMatches:c,h=n.findAllMatches,findAllMatches=void 0===h?k.findAllMatches:h,u=n.minMatchCharLength,minMatchCharLength=void 0===u?k.minMatchCharLength:u,l=n.isCaseSensitive,isCaseSensitive=void 0===l?k.isCaseSensitive:l,n);return t(this,i),(f=r.call(this,e))._bitapSearch=new w(e,v),f}return n(i,[{key:"search",value:function(t){return this._bitapSearch.searchInString(t)}}],[{key:"type",get:function(){return"fuzzy"}},{key:"literal",get:function(){return/^"(.*)"$/}},{key:"re",get:function(){return/^(.*)$/}}]),i}(S),P=[O,C,L,$,A,I,j],E=P.length,N=/ +(?=([^\"]*\"[^\"]*\")*[^\"]*$)/;function R(t,e){return t.split("|").map((function(t){for(var n=t.trim().split(N).filter((function(t){return t&&!!t.trim()})),r=[],i=0,o=n.length;i<o;i+=1){for(var a=n[i],s=!1,c=-1;!s&&++c<E;){var h=P[c],u=h.isLiteralMatch(a);u&&(r.push(new h(u,e)),s=!0)}if(!s)for(c=-1;++c<E;){var l=P[c],f=l.isRegMatch(a);if(f){r.push(new l(f,e));break}}}return r}))}var F=function(){function e(n){var r,i,o,a,s,c,h,u,l,f=arguments.length>1&&void 0!==arguments[1]?arguments[1]:(i=(r={}).isCaseSensitive,isCaseSensitive=void 0===i?k.isCaseSensitive:i,o=r.includeMatches,includeMatches=void 0===o?k.includeMatches:o,a=r.minMatchCharLength,minMatchCharLength=void 0===a?k.minMatchCharLength:a,s=r.findAllMatches,findAllMatches=void 0===s?k.findAllMatches:s,c=r.location,location=void 0===c?k.location:c,h=r.threshold,threshold=void 0===h?k.threshold:h,u=r.distance,distance=void 0===u?k.distance:u,l=r.includeMatches,includeMatches=void 0===l?k.includeMatches:l,r);t(this,e),this.query=null,this.options=f,this.pattern=f.isCaseSensitive?n:n.toLowerCase(),this.query=R(this.pattern,f)}return n(e,[{key:"searchIn",value:function(t){var e=this.query;if(!e)return{isMatch:!1,score:1};var n=t.$,r=this.options,i=r.includeMatches;n=r.isCaseSensitive?n:n.toLowerCase();for(var o=0,a=[],s=0,c=e.length;s<c;s+=1){var h=e[s];a.length=0,o=0;for(var u=0,l=h.length;u<l;u+=1){var v=h[u],d=v.search(n),p=d.isMatch,y=d.matchedIndices;if(!p){o=0,a.length=0;break}o+=1,i&&(v.constructor.type===j.type?a=[].concat(f(a),f(y)):a.push(y))}if(o){var g={isMatch:!0,score:0};return i&&(g.matchedIndices=a),g}}return{isMatch:!1,score:1}}}],[{key:"condition",value:function(t,e){return e.useExtendedSearch}}]),e}();function D(t,e){var n=e.n,r=void 0===n?3:n,i=e.pad,o=void 0===i||i,a=e.sort,s=void 0!==a&&a,c=[];if(null==t)return c;t=t.toLowerCase(),o&&(t=" ".concat(t," "));var h=t.length-r+1;if(h<1)return c;for(;h--;)c[h]=t.substr(h,r);return s&&c.sort((function(t,e){return t==e?0:t<e?-1:1})),c}var W=function(){function e(n){var r,i,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:(i=(r={}).threshold,threshold=void 0===i?k.threshold:i,r);t(this,e),this.options=o,this.patternNgram=D(n,{sort:!0})}return n(e,[{key:"searchIn",value:function(t){var e=t.ng;e||(e=D(t.$,{sort:!0}),t.ng=e);var n,r,i,o=(n=this.patternNgram,i=function(t,e){for(var n=[],r=0,i=0;r<t.length&&i<e.length;){var o=t[r],a=e[i];o<a?(n.push(o),r+=1):a<o?(n.push(a),i+=1):(n.push(a),r+=1,i+=1)}for(;r<t.length;)n.push(t[r]),r+=1;for(;i<e.length;)n.push(e[i]),i+=1;return n}(n,r=e),1-function(t,e){for(var n=[],r=0,i=0;r<t.length&&i<e.length;){var o=t[r],a=e[i];o==a?(n.push(o),r+=1,i+=1):o<a?r+=1:(o>a||(r+=1),i+=1)}return n}(n,r).length/i.length),a=o<this.options.threshold;return{score:a?o:1,isMatch:a}}}],[{key:"condition",value:function(t){return t.length>32}}]),e}();function q(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n.getFn,i=void 0===r?m:r,o=n.ngrams,a=void 0!==o&&o,s=[];if(p(e[0]))for(var c=0,h=e.length;c<h;c+=1){var u=e[c];if(g(u)){var l={$:u,idx:c};a&&(l.ng=D(u,{sort:!0})),s.push(l)}}else for(var f=t.length,v=0,y=e.length;v<y;v+=1){for(var k=e[v],M={idx:v,$:{}},b=0;b<f;b+=1){var x=t[b],w=i(k,x);if(g(w))if(d(w)){for(var S=[],_=[{arrayIndex:-1,value:w}];_.length;){var O=_.pop(),I=O.arrayIndex,C=O.value;if(g(C))if(p(C)){var L={$:C,idx:I};a&&(L.ng=D(C,{sort:!0})),S.push(L)}else if(d(C))for(var A=0,$=C.length;A<$;A+=1)_.push({arrayIndex:A,value:C[A]})}M.$[x]=S}else{var j={$:w};a&&(j.ng=D(w,{sort:!0})),M.$[x]=j}}s.push(M)}return s}var T=function(){function e(n){if(t(this,e),this._keys={},this._keyNames=[],this._length=n.length,n.length&&p(n[0]))for(var r=0;r<this._length;r+=1){var i=n[r];this._keys[i]={weight:1},this._keyNames.push(i)}else{for(var o=0,a=0;a<this._length;a+=1){var s=n[a];if(!Object.prototype.hasOwnProperty.call(s,"name"))throw new Error('Missing "name" property in key object');var c=s.name;if(this._keyNames.push(c),!Object.prototype.hasOwnProperty.call(s,"weight"))throw new Error('Missing "weight" property in key object');var h=s.weight;if(h<=0||h>=1)throw new Error('"weight" property in key must be in the range of (0, 1)');this._keys[c]={weight:h},o+=h}for(var u=0;u<this._length;u+=1){var l=this._keyNames[u],f=this._keys[l].weight;this._keys[l].weight=f/o}}}return n(e,[{key:"get",value:function(t,e){return this._keys[t]?this._keys[t][e]:-1}},{key:"keys",value:function(){return this._keyNames}},{key:"count",value:function(){return this._length}},{key:"toJSON",value:function(){return JSON.stringify(this._keys)}}]),e}();function U(t,e){var n=t.matches;if(e.matches=[],g(n))for(var r=0,i=n.length;r<i;r+=1){var o=n[r];if(g(o.indices)&&0!==o.indices.length){var a={indices:o.indices,value:o.value};o.key&&(a.key=o.key),o.idx>-1&&(a.refIndex=o.idx),e.matches.push(a)}}}function z(t,e){e.score=t.score}var J=[],K=function(){function e(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;t(this,e),this.options=o({},k,{},r),this._processKeys(this.options.keys),this.setCollection(n,i)}return n(e,[{key:"setCollection",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;this.list=t,this.listIsStringArray=p(t[0]),e?this.setIndex(e):this.setIndex(this._createIndex())}},{key:"setIndex",value:function(t){this._indexedList=t}},{key:"_processKeys",value:function(t){this._keyStore=new T(t)}},{key:"_createIndex",value:function(){return q(this._keyStore.keys(),this.list,{getFn:this.options.getFn})}},{key:"search",value:function(t){for(var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{limit:!1},n=this.options.shouldSort,r=null,i=0,o=J.length;i<o;i+=1){var a=J[i];if(a.condition(t,this.options)){r=new a(t,this.options);break}}r||(r=new w(t,this.options));var s=this._searchUsing(r);return this._computeScore(s),n&&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,n=[],r=this.options.includeMatches;if(this.listIsStringArray)for(var i=0,o=e.length;i<o;i+=1){var a=e[i],s=a.$,c=a.idx;if(g(s)){var h=t.searchIn(a),u=h.isMatch,l=h.score;if(u){var f={score:l,value:s};r&&(f.indices=h.matchedIndices),n.push({item:s,idx:c,matches:[f]})}}}else for(var v=this._keyStore.keys(),p=this._keyStore.count(),y=0,m=e.length;y<m;y+=1){var k=e[y],M=k.$,b=k.idx;if(g(M)){for(var x=[],w=0;w<p;w+=1){var S=v[w],_=M[S];if(g(_))if(d(_))for(var O=0,I=_.length;O<I;O+=1){var C=_[O],L=C.$,A=C.idx;if(g(L)){var $=t.searchIn(C),j=$.isMatch,P=$.score;if(j){var E={score:P,key:S,value:L,idx:A};r&&(E.indices=$.matchedIndices),x.push(E)}}}else{var N=_.$,R=t.searchIn(_),F=R.isMatch,D=R.score;if(!F)continue;var W={score:D,key:S,value:N};r&&(W.indices=R.matchedIndices),x.push(W)}}x.length&&n.push({idx:b,item:M,matches:x})}}return n}},{key:"_computeScore",value:function(t){for(var e=0,n=t.length;e<n;e+=1){for(var r=t[e],i=r.matches,o=i.length,a=1,s=0;s<o;s+=1){var c=i[s],h=c.key,u=this._keyStore.get(h,"weight"),l=u>-1?u:1,f=0===c.score&&u>-1?Number.EPSILON:c.score;a*=Math.pow(f,l)}r.score=a}}},{key:"_sort",value:function(t){t.sort(this.options.sortFn)}},{key:"_format",value:function(t){var e=[],n=this.options,r=n.includeMatches,i=n.includeScore,o=[];r&&o.push(U),i&&o.push(z);for(var a=0,s=t.length;a<s;a+=1){var c=t[a],h=c.idx,u={item:this.list[h],refIndex:h};if(o.length)for(var l=0,f=o.length;l<f;l+=1)o[l](c,u);e.push(u)}return e}}],[{key:"register",value:function(){J.push.apply(J,arguments)}}]),e}();return K.register(F,W),K.version="5.2.0-alpha.1",K.createIndex=q,K.config=k,K},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).Fuse=e(); |
@@ -16,3 +16,3 @@ { | ||
], | ||
"version": "5.2.0-alpha.0", | ||
"version": "5.2.0-alpha.1", | ||
"description": "Lightweight fuzzy-search", | ||
@@ -19,0 +19,0 @@ "license": "Apache-2.0", |
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
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
300183
6885