From e5c990744321d2b673944af65d98609198e37402 Mon Sep 17 00:00:00 2001 From: Kiro Risk <565580+krisk@users.noreply.github.com> Date: Sun, 26 Jul 2020 09:45:49 -0700 Subject: [PATCH] chore(release): 6.4.1 --- CHANGELOG.md | 7 +++++++ dist/fuse.basic.common.js | 28 +++++++++++++++++++------- dist/fuse.basic.esm.js | 40 ++++++++++++++++++++++++++++++++------ dist/fuse.basic.esm.min.js | 4 ++-- dist/fuse.basic.js | 28 +++++++++++++++++++------- dist/fuse.basic.min.js | 4 ++-- dist/fuse.common.js | 28 +++++++++++++++++++------- dist/fuse.d.ts | 2 +- dist/fuse.esm.js | 40 ++++++++++++++++++++++++++++++++------ dist/fuse.esm.min.js | 4 ++-- dist/fuse.js | 4 ++-- dist/fuse.min.js | 4 ++-- package.json | 2 +- 13 files changed, 150 insertions(+), 45 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1deb42cce..df2268819 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [6.4.1](https://github.com/krisk/Fuse/compare/v6.4.0...v6.4.1) (2020-07-26) + + +### Bug Fixes + +* handle booleans in the data ([226d868](https://github.com/krisk/Fuse/commit/226d868a1102402e1e773db305ddd3928ae92f79)), closes [#469](https://github.com/krisk/Fuse/issues/469) + ## [6.4.0](https://github.com/krisk/Fuse/compare/v6.3.1...v6.4.0) (2020-06-28) diff --git a/dist/fuse.basic.common.js b/dist/fuse.basic.common.js index d5f8b3d9c..d111f33d9 100644 --- a/dist/fuse.basic.common.js +++ b/dist/fuse.basic.common.js @@ -1,5 +1,5 @@ /** - * Fuse.js v6.4.0 - Lightweight fuzzy-search (http://fusejs.io) + * Fuse.js v6.4.1 - Lightweight fuzzy-search (http://fusejs.io) * * Copyright (c) 2020 Kiro Risk (http://kiro.me) * All Rights Reserved. Apache Software License 2.0 @@ -130,9 +130,8 @@ function _nonIterableSpread() { } function isArray(value) { - return !Array.isArray ? Object.prototype.toString.call(value) === '[object Array]' : Array.isArray(value); -} // Adapted from: -// https://github.com/lodash/lodash/blob/f4ca396a796435422bd4fd41fadbd225edddf175/.internal/baseToString.js + return !Array.isArray ? getTag(value) === '[object Array]' : Array.isArray(value); +} // Adapted from: https://github.com/lodash/lodash/blob/master/.internal/baseToString.js var INFINITY = 1 / 0; function baseToString(value) { @@ -152,15 +151,28 @@ function isString(value) { } function isNumber(value) { return typeof value === 'number'; +} // Adapted from: https://github.com/lodash/lodash/blob/master/isBoolean.js + +function isBoolean(value) { + return value === true || value === false || isObjectLike(value) && getTag(value) == '[object Boolean]'; } function isObject(value) { return _typeof(value) === 'object'; +} // Checks if `value` is object-like. + +function isObjectLike(value) { + return isObject(value) && value !== null; } function isDefined(value) { return value !== undefined && value !== null; } function isBlank(value) { return !value.trim().length; +} // Gets the `toStringTag` of `value`. +// Adapted from: https://github.com/lodash/lodash/blob/master/.internal/getTag.js + +function getTag(value) { + return value == null ? value === undefined ? '[object Undefined]' : '[object Null]' : Object.prototype.toString.call(value); } var EXTENDED_SEARCH_UNAVAILABLE = 'Extended search is not available'; @@ -282,9 +294,11 @@ function get(obj, path) { if (!isDefined(value)) { return; - } + } // If we're at the last value in the path, and if it's a string/number/bool, + // add it to the list + - if (index === path.length - 1 && (isString(value) || isNumber(value))) { + if (index === path.length - 1 && (isString(value) || isNumber(value) || isBoolean(value))) { list.push(toString(value)); } else if (isArray(value)) { arr = true; // Search each item in the array. @@ -1427,7 +1441,7 @@ function format(results, docs) { }); } -Fuse.version = '6.4.0'; +Fuse.version = '6.4.1'; Fuse.createIndex = createIndex; Fuse.parseIndex = parseIndex; Fuse.config = Config; diff --git a/dist/fuse.basic.esm.js b/dist/fuse.basic.esm.js index 1ca652e1c..e6785d5c7 100644 --- a/dist/fuse.basic.esm.js +++ b/dist/fuse.basic.esm.js @@ -1,5 +1,5 @@ /** - * Fuse.js v6.4.0 - Lightweight fuzzy-search (http://fusejs.io) + * Fuse.js v6.4.1 - Lightweight fuzzy-search (http://fusejs.io) * * Copyright (c) 2020 Kiro Risk (http://kiro.me) * All Rights Reserved. Apache Software License 2.0 @@ -9,12 +9,11 @@ function isArray(value) { return !Array.isArray - ? Object.prototype.toString.call(value) === '[object Array]' + ? getTag(value) === '[object Array]' : Array.isArray(value) } -// Adapted from: -// https://github.com/lodash/lodash/blob/f4ca396a796435422bd4fd41fadbd225edddf175/.internal/baseToString.js +// Adapted from: https://github.com/lodash/lodash/blob/master/.internal/baseToString.js const INFINITY = 1 / 0; function baseToString(value) { // Exit early for strings to avoid a performance hit in some environments. @@ -37,10 +36,24 @@ function isNumber(value) { return typeof value === 'number' } +// Adapted from: https://github.com/lodash/lodash/blob/master/isBoolean.js +function isBoolean(value) { + return ( + value === true || + value === false || + (isObjectLike(value) && getTag(value) == '[object Boolean]') + ) +} + function isObject(value) { return typeof value === 'object' } +// Checks if `value` is object-like. +function isObjectLike(value) { + return isObject(value) && value !== null +} + function isDefined(value) { return value !== undefined && value !== null } @@ -49,6 +62,16 @@ function isBlank(value) { return !value.trim().length } +// Gets the `toStringTag` of `value`. +// Adapted from: https://github.com/lodash/lodash/blob/master/.internal/getTag.js +function getTag(value) { + return value == null + ? value === undefined + ? '[object Undefined]' + : '[object Null]' + : Object.prototype.toString.call(value) +} + const EXTENDED_SEARCH_UNAVAILABLE = 'Extended search is not available'; const LOGICAL_SEARCH_UNAVAILABLE = 'Logical search is not available'; @@ -160,7 +183,12 @@ function get(obj, path) { return } - if (index === path.length - 1 && (isString(value) || isNumber(value))) { + // If we're at the last value in the path, and if it's a string/number/bool, + // add it to the list + if ( + index === path.length - 1 && + (isString(value) || isNumber(value) || isBoolean(value)) + ) { list.push(toString(value)); } else if (isArray(value)) { arr = true; @@ -1195,7 +1223,7 @@ function format( }) } -Fuse.version = '6.4.0'; +Fuse.version = '6.4.1'; Fuse.createIndex = createIndex; Fuse.parseIndex = parseIndex; Fuse.config = Config; diff --git a/dist/fuse.basic.esm.min.js b/dist/fuse.basic.esm.min.js index 6134724df..37747241a 100644 --- a/dist/fuse.basic.esm.min.js +++ b/dist/fuse.basic.esm.min.js @@ -1,9 +1,9 @@ /** - * Fuse.js v6.4.0 - Lightweight fuzzy-search (http://fusejs.io) + * Fuse.js v6.4.1 - Lightweight fuzzy-search (http://fusejs.io) * * Copyright (c) 2020 Kiro Risk (http://kiro.me) * All Rights Reserved. Apache Software License 2.0 * * http://www.apache.org/licenses/LICENSE-2.0 */ -function t(t){return Array.isArray?Array.isArray(t):"[object Array]"===Object.prototype.toString.call(t)}function e(t){return"string"==typeof t}function n(t){return"number"==typeof t}function s(t){return null!=t}function i(t){return!t.trim().length}const r=Object.prototype.hasOwnProperty;class o{constructor(t){this._keys=[],this._keyMap={};let e=0;t.forEach(t=>{let n=c(t);e+=n.weight,this._keys.push(n),this._keyMap[n.id]=n,e+=n.weight}),this._keys.forEach(t=>{t.weight/=e})}get(t){return this._keyMap[t]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function c(n){let s=null,i=null,o=null,c=1;if(e(n)||t(n))o=n,s=h(n),i=a(n);else{if(!r.call(n,"name"))throw new Error((t=>`Missing ${t} property in key`)("name"));const t=n.name;if(o=t,r.call(n,"weight")&&(c=n.weight,c<=0))throw new Error((t=>`Property 'weight' in key '${t}' must be a positive integer`)(t));s=h(t),i=a(t)}return{path:s,id:i,weight:c,src:o}}function h(e){return t(e)?e:e.split(".")}function a(e){return t(e)?e.join("."):e}var l={isCaseSensitive:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score===e.score?t.idx{if(r[a]){const l=i[r[a]];if(!s(l))return;if(a===r.length-1&&(e(l)||n(l)))o.push(function(t){return null==t?"":function(t){if("string"==typeof t)return t;let e=t+"";return"0"==e&&1/t==-1/0?"-0":e}(t)}(l));else if(t(l)){c=!0;for(let t=0,e=l.length;t{this._keysMap[t.id]=e})}create(){!this.isCreated&&this.docs.length&&(this.isCreated=!0,e(this.docs[0])?this.docs.forEach((t,e)=>{this._addString(t,e)}):this.docs.forEach((t,e)=>{this._addObject(t,e)}),this.norm.clear())}add(t){const n=this.size();e(t)?this._addString(t,n):this._addObject(t,n)}removeAt(t){this.records.splice(t,1);for(let e=t,n=this.size();e{let h=this.getFn(n,r.path);if(s(h))if(t(h)){let n=[];const r=[{nestedArrIndex:-1,value:h}];for(;r.length;){const{nestedArrIndex:o,value:c}=r.pop();if(s(c))if(e(c)&&!i(c)){let t={v:c,i:o,n:this.norm.get(c)};n.push(t)}else t(c)&&c.forEach((t,e)=>{r.push({nestedArrIndex:e,value:t})})}o.$[c]=n}else if(!i(h)){let t={v:h,n:this.norm.get(h)};o.$[c]=t}}),this.records.push(o)}toJSON(){return{keys:this.keys,records:this.records}}}function f(t,e,{getFn:n=l.getFn}={}){const s=new u({getFn:n});return s.setKeys(t.map(c)),s.setSources(e),s.create(),s}function g(t,e){const n=t.matches;e.matches=[],s(n)&&n.forEach(t=>{if(!s(t.indices)||!t.indices.length)return;const{indices:n,value:i}=t;let r={indices:n,value:i};t.key&&(r.key=t.key.src),t.idx>-1&&(r.refIndex=t.idx),e.matches.push(r)})}function p(t,e){e.score=t.score}function m(t,{errors:e=0,currentLocation:n=0,expectedLocation:s=0,distance:i=l.distance,ignoreLocation:r=l.ignoreLocation}={}){const o=e/t.length;if(r)return o;const c=Math.abs(s-n);return i?o+c/i:c?1:o}function y(t,e,n,{location:s=l.location,distance:i=l.distance,threshold:r=l.threshold,findAllMatches:o=l.findAllMatches,minMatchCharLength:c=l.minMatchCharLength,includeMatches:h=l.includeMatches,ignoreLocation:a=l.ignoreLocation}={}){if(e.length>32)throw new Error(`Pattern length exceeds max of ${32}.`);const d=e.length,u=t.length,f=Math.max(0,Math.min(s,u));let g=r,p=f;const y=c>1||h,M=y?Array(u):[];let x;for(;(x=t.indexOf(e,p))>-1;){let t=m(e,{currentLocation:x,expectedLocation:f,distance:i,ignoreLocation:a});if(g=Math.min(t,g),p=x+d,y){let t=0;for(;t=h;r-=1){let o=r-1,c=n[t.charAt(o)];if(y&&(M[o]=+!!c),x[r]=(x[r+1]<<1|1)&c,s&&(x[r]|=(L[r+1]|L[r])<<1|1|L[r+1]),x[r]&v&&(_=m(e,{errors:s,currentLocation:o,expectedLocation:f,distance:i,ignoreLocation:a}),_<=g)){if(g=_,p=o,p<=f)break;h=Math.max(1,2*f-p)}}if(m(e,{errors:s+1,currentLocation:f,expectedLocation:f,distance:i,ignoreLocation:a})>g)break;L=x}const w={isMatch:p>=0,score:Math.max(.001,_)};if(y){const t=function(t=[],e=l.minMatchCharLength){let n=[],s=-1,i=-1,r=0;for(let o=t.length;r=e&&n.push([s,i]),s=-1)}return t[r-1]&&r-s>=e&&n.push([s,r-1]),n}(M,c);t.length?h&&(w.indices=t):w.isMatch=!1}return w}function M(t){let e={};for(let n=0,s=t.length;n{this.chunks.push({pattern:t,alphabet:M(t),startIndex:e})},d=this.pattern.length;if(d>32){let t=0;const e=d%32,n=d-e;for(;t{const{isMatch:g,score:p,indices:m}=y(t,e,u,{location:s+f,distance:i,threshold:r,findAllMatches:o,minMatchCharLength:c,includeMatches:n,ignoreLocation:h});g&&(d=!0),l+=p,g&&m&&(a=[...a,...m])});let u={isMatch:d,score:d?l/this.chunks.length:1};return d&&n&&(u.indices=a),u}}const L=[];function _(t,e){for(let n=0,s=L.length;n!1)){const e=[];for(let n=0,s=this._docs.length;n{let n=1;t.matches.forEach(({key:t,norm:s,score:i})=>{const r=t?t.weight:null;n*=Math.pow(0===i&&r?Number.EPSILON:i,(r||1)*(e?1:s))}),t.score=n})}(a,{ignoreFieldNorm:h}),o&&a.sort(c),n(s)&&s>-1&&(a=a.slice(0,s)),function(t,e,{includeMatches:n=l.includeMatches,includeScore:s=l.includeScore}={}){const i=[];n&&i.push(g);s&&i.push(p);return t.map(t=>{const{idx:n}=t,s={item:e[n],refIndex:n};return i.length&&i.forEach(e=>{e(t,s)}),s})}(a,this._docs,{includeMatches:i,includeScore:r})}_searchStringList(t){const e=_(t,this.options),{records:n}=this._myIndex,i=[];return n.forEach(({v:t,i:n,n:r})=>{if(!s(t))return;const{isMatch:o,score:c,indices:h}=e.searchIn(t);o&&i.push({item:t,idx:n,matches:[{score:c,value:t,norm:r,indices:h}]})}),i}_searchLogical(t){throw new Error("Logical search is not available")}_searchObjectList(t){const e=_(t,this.options),{keys:n,records:i}=this._myIndex,r=[];return i.forEach(({$:t,i:i})=>{if(!s(t))return;let o=[];n.forEach((n,s)=>{o.push(...this._findMatches({key:n,value:t[s],searcher:e}))}),o.length&&r.push({idx:i,item:t,matches:o})}),r}_findMatches({key:e,value:n,searcher:i}){if(!s(n))return[];let r=[];if(t(n))n.forEach(({v:t,i:n,n:o})=>{if(!s(t))return;const{isMatch:c,score:h,indices:a}=i.searchIn(t);c&&r.push({score:h,key:e,value:t,idx:n,norm:o,indices:a})});else{const{v:t,n:s}=n,{isMatch:o,score:c,indices:h}=i.searchIn(t);o&&r.push({score:c,key:e,value:t,norm:s,indices:h})}return r}}k.version="6.4.0",k.createIndex=f,k.parseIndex=function(t,{getFn:e=l.getFn}={}){const{keys:n,records:s}=t,i=new u({getFn:e});return i.setKeys(n),i.setIndexRecords(s),i},k.config=l;export default k; \ No newline at end of file +function t(t){return Array.isArray?Array.isArray(t):"[object Array]"===o(t)}function e(t){return"string"==typeof t}function n(t){return"number"==typeof t}function s(t){return!0===t||!1===t||function(t){return function(t){return"object"==typeof t}(t)&&null!==t}(t)&&"[object Boolean]"==o(t)}function i(t){return null!=t}function r(t){return!t.trim().length}function o(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const c=Object.prototype.hasOwnProperty;class h{constructor(t){this._keys=[],this._keyMap={};let e=0;t.forEach(t=>{let n=a(t);e+=n.weight,this._keys.push(n),this._keyMap[n.id]=n,e+=n.weight}),this._keys.forEach(t=>{t.weight/=e})}get(t){return this._keyMap[t]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function a(n){let s=null,i=null,r=null,o=1;if(e(n)||t(n))r=n,s=l(n),i=d(n);else{if(!c.call(n,"name"))throw new Error((t=>`Missing ${t} property in key`)("name"));const t=n.name;if(r=t,c.call(n,"weight")&&(o=n.weight,o<=0))throw new Error((t=>`Property 'weight' in key '${t}' must be a positive integer`)(t));s=l(t),i=d(t)}return{path:s,id:i,weight:o,src:r}}function l(e){return t(e)?e:e.split(".")}function d(e){return t(e)?e.join("."):e}var u={isCaseSensitive:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score===e.score?t.idx{if(o[l]){const d=r[o[l]];if(!i(d))return;if(l===o.length-1&&(e(d)||n(d)||s(d)))c.push(function(t){return null==t?"":function(t){if("string"==typeof t)return t;let e=t+"";return"0"==e&&1/t==-1/0?"-0":e}(t)}(d));else if(t(d)){h=!0;for(let t=0,e=d.length;t{this._keysMap[t.id]=e})}create(){!this.isCreated&&this.docs.length&&(this.isCreated=!0,e(this.docs[0])?this.docs.forEach((t,e)=>{this._addString(t,e)}):this.docs.forEach((t,e)=>{this._addObject(t,e)}),this.norm.clear())}add(t){const n=this.size();e(t)?this._addString(t,n):this._addObject(t,n)}removeAt(t){this.records.splice(t,1);for(let e=t,n=this.size();e{let h=this.getFn(n,s.path);if(i(h))if(t(h)){let n=[];const s=[{nestedArrIndex:-1,value:h}];for(;s.length;){const{nestedArrIndex:o,value:c}=s.pop();if(i(c))if(e(c)&&!r(c)){let t={v:c,i:o,n:this.norm.get(c)};n.push(t)}else t(c)&&c.forEach((t,e)=>{s.push({nestedArrIndex:e,value:t})})}o.$[c]=n}else if(!r(h)){let t={v:h,n:this.norm.get(h)};o.$[c]=t}}),this.records.push(o)}toJSON(){return{keys:this.keys,records:this.records}}}function p(t,e,{getFn:n=u.getFn}={}){const s=new g({getFn:n});return s.setKeys(t.map(a)),s.setSources(e),s.create(),s}function m(t,e){const n=t.matches;e.matches=[],i(n)&&n.forEach(t=>{if(!i(t.indices)||!t.indices.length)return;const{indices:n,value:s}=t;let r={indices:n,value:s};t.key&&(r.key=t.key.src),t.idx>-1&&(r.refIndex=t.idx),e.matches.push(r)})}function y(t,e){e.score=t.score}function M(t,{errors:e=0,currentLocation:n=0,expectedLocation:s=0,distance:i=u.distance,ignoreLocation:r=u.ignoreLocation}={}){const o=e/t.length;if(r)return o;const c=Math.abs(s-n);return i?o+c/i:c?1:o}function x(t,e,n,{location:s=u.location,distance:i=u.distance,threshold:r=u.threshold,findAllMatches:o=u.findAllMatches,minMatchCharLength:c=u.minMatchCharLength,includeMatches:h=u.includeMatches,ignoreLocation:a=u.ignoreLocation}={}){if(e.length>32)throw new Error(`Pattern length exceeds max of ${32}.`);const l=e.length,d=t.length,f=Math.max(0,Math.min(s,d));let g=r,p=f;const m=c>1||h,y=m?Array(d):[];let x;for(;(x=t.indexOf(e,p))>-1;){let t=M(e,{currentLocation:x,expectedLocation:f,distance:i,ignoreLocation:a});if(g=Math.min(t,g),p=x+l,m){let t=0;for(;t=h;r-=1){let o=r-1,c=n[t.charAt(o)];if(m&&(y[o]=+!!c),x[r]=(x[r+1]<<1|1)&c,s&&(x[r]|=(L[r+1]|L[r])<<1|1|L[r+1]),x[r]&v&&(_=M(e,{errors:s,currentLocation:o,expectedLocation:f,distance:i,ignoreLocation:a}),_<=g)){if(g=_,p=o,p<=f)break;h=Math.max(1,2*f-p)}}if(M(e,{errors:s+1,currentLocation:f,expectedLocation:f,distance:i,ignoreLocation:a})>g)break;L=x}const w={isMatch:p>=0,score:Math.max(.001,_)};if(m){const t=function(t=[],e=u.minMatchCharLength){let n=[],s=-1,i=-1,r=0;for(let o=t.length;r=e&&n.push([s,i]),s=-1)}return t[r-1]&&r-s>=e&&n.push([s,r-1]),n}(y,c);t.length?h&&(w.indices=t):w.isMatch=!1}return w}function L(t){let e={};for(let n=0,s=t.length;n{this.chunks.push({pattern:t,alphabet:L(t),startIndex:e})},l=this.pattern.length;if(l>32){let t=0;const e=l%32,n=l-e;for(;t{const{isMatch:g,score:p,indices:m}=x(t,e,u,{location:s+f,distance:i,threshold:r,findAllMatches:o,minMatchCharLength:c,includeMatches:n,ignoreLocation:h});g&&(d=!0),l+=p,g&&m&&(a=[...a,...m])});let u={isMatch:d,score:d?l/this.chunks.length:1};return d&&n&&(u.indices=a),u}}const k=[];function v(t,e){for(let n=0,s=k.length;n!1)){const e=[];for(let n=0,s=this._docs.length;n{let n=1;t.matches.forEach(({key:t,norm:s,score:i})=>{const r=t?t.weight:null;n*=Math.pow(0===i&&r?Number.EPSILON:i,(r||1)*(e?1:s))}),t.score=n})}(a,{ignoreFieldNorm:h}),o&&a.sort(c),n(s)&&s>-1&&(a=a.slice(0,s)),function(t,e,{includeMatches:n=u.includeMatches,includeScore:s=u.includeScore}={}){const i=[];n&&i.push(m);s&&i.push(y);return t.map(t=>{const{idx:n}=t,s={item:e[n],refIndex:n};return i.length&&i.forEach(e=>{e(t,s)}),s})}(a,this._docs,{includeMatches:i,includeScore:r})}_searchStringList(t){const e=v(t,this.options),{records:n}=this._myIndex,s=[];return n.forEach(({v:t,i:n,n:r})=>{if(!i(t))return;const{isMatch:o,score:c,indices:h}=e.searchIn(t);o&&s.push({item:t,idx:n,matches:[{score:c,value:t,norm:r,indices:h}]})}),s}_searchLogical(t){throw new Error("Logical search is not available")}_searchObjectList(t){const e=v(t,this.options),{keys:n,records:s}=this._myIndex,r=[];return s.forEach(({$:t,i:s})=>{if(!i(t))return;let o=[];n.forEach((n,s)=>{o.push(...this._findMatches({key:n,value:t[s],searcher:e}))}),o.length&&r.push({idx:s,item:t,matches:o})}),r}_findMatches({key:e,value:n,searcher:s}){if(!i(n))return[];let r=[];if(t(n))n.forEach(({v:t,i:n,n:o})=>{if(!i(t))return;const{isMatch:c,score:h,indices:a}=s.searchIn(t);c&&r.push({score:h,key:e,value:t,idx:n,norm:o,indices:a})});else{const{v:t,n:i}=n,{isMatch:o,score:c,indices:h}=s.searchIn(t);o&&r.push({score:c,key:e,value:t,norm:i,indices:h})}return r}}w.version="6.4.1",w.createIndex=p,w.parseIndex=function(t,{getFn:e=u.getFn}={}){const{keys:n,records:s}=t,i=new g({getFn:e});return i.setKeys(n),i.setIndexRecords(s),i},w.config=u;export default w; \ No newline at end of file diff --git a/dist/fuse.basic.js b/dist/fuse.basic.js index c46a2b09e..7bd58dbae 100644 --- a/dist/fuse.basic.js +++ b/dist/fuse.basic.js @@ -1,5 +1,5 @@ /** - * Fuse.js v6.4.0 - Lightweight fuzzy-search (http://fusejs.io) + * Fuse.js v6.4.1 - Lightweight fuzzy-search (http://fusejs.io) * * Copyright (c) 2020 Kiro Risk (http://kiro.me) * All Rights Reserved. Apache Software License 2.0 @@ -134,9 +134,8 @@ } function isArray(value) { - return !Array.isArray ? Object.prototype.toString.call(value) === '[object Array]' : Array.isArray(value); - } // Adapted from: - // https://github.com/lodash/lodash/blob/f4ca396a796435422bd4fd41fadbd225edddf175/.internal/baseToString.js + return !Array.isArray ? getTag(value) === '[object Array]' : Array.isArray(value); + } // Adapted from: https://github.com/lodash/lodash/blob/master/.internal/baseToString.js var INFINITY = 1 / 0; function baseToString(value) { @@ -156,15 +155,28 @@ } function isNumber(value) { return typeof value === 'number'; + } // Adapted from: https://github.com/lodash/lodash/blob/master/isBoolean.js + + function isBoolean(value) { + return value === true || value === false || isObjectLike(value) && getTag(value) == '[object Boolean]'; } function isObject(value) { return _typeof(value) === 'object'; + } // Checks if `value` is object-like. + + function isObjectLike(value) { + return isObject(value) && value !== null; } function isDefined(value) { return value !== undefined && value !== null; } function isBlank(value) { return !value.trim().length; + } // Gets the `toStringTag` of `value`. + // Adapted from: https://github.com/lodash/lodash/blob/master/.internal/getTag.js + + function getTag(value) { + return value == null ? value === undefined ? '[object Undefined]' : '[object Null]' : Object.prototype.toString.call(value); } var EXTENDED_SEARCH_UNAVAILABLE = 'Extended search is not available'; @@ -286,9 +298,11 @@ if (!isDefined(value)) { return; - } + } // If we're at the last value in the path, and if it's a string/number/bool, + // add it to the list + - if (index === path.length - 1 && (isString(value) || isNumber(value))) { + if (index === path.length - 1 && (isString(value) || isNumber(value) || isBoolean(value))) { list.push(toString(value)); } else if (isArray(value)) { arr = true; // Search each item in the array. @@ -1431,7 +1445,7 @@ }); } - Fuse.version = '6.4.0'; + Fuse.version = '6.4.1'; Fuse.createIndex = createIndex; Fuse.parseIndex = parseIndex; Fuse.config = Config; diff --git a/dist/fuse.basic.min.js b/dist/fuse.basic.min.js index c8ee33005..2307c5376 100644 --- a/dist/fuse.basic.min.js +++ b/dist/fuse.basic.min.js @@ -1,9 +1,9 @@ /** - * Fuse.js v6.4.0 - Lightweight fuzzy-search (http://fusejs.io) + * Fuse.js v6.4.1 - Lightweight fuzzy-search (http://fusejs.io) * * Copyright (c) 2020 Kiro Risk (http://kiro.me) * All Rights Reserved. Apache Software License 2.0 * * http://www.apache.org/licenses/LICENSE-2.0 */ -var e,t;e=this,t=function(){"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function t(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,r=new Array(t);n0&&void 0!==arguments[0]?arguments[0]:3,t=new Map;return{get:function(n){var r=n.match(M).length;if(t.has(r))return t.get(r);var i=parseFloat((1/Math.sqrt(r)).toFixed(e));return t.set(r,i),i},clear:function(){t.clear()}}}var x=function(){function t(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=n.getFn,i=void 0===r?k.getFn:r;e(this,t),this.norm=b(3),this.getFn=i,this.isCreated=!1,this.setIndexRecords()}return n(t,[{key:"setSources",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.docs=e}},{key:"setIndexRecords",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.records=e}},{key:"setKeys",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.keys=t,this._keysMap={},t.forEach((function(t,n){e._keysMap[t.id]=n}))}},{key:"create",value:function(){var e=this;!this.isCreated&&this.docs.length&&(this.isCreated=!0,h(this.docs[0])?this.docs.forEach((function(t,n){e._addString(t,n)})):this.docs.forEach((function(t,n){e._addObject(t,n)})),this.norm.clear())}},{key:"add",value:function(e){var t=this.size();h(e)?this._addString(e,t):this._addObject(e,t)}},{key:"removeAt",value:function(e){this.records.splice(e,1);for(var t=e,n=this.size();t2&&void 0!==arguments[2]?arguments[2]:{},r=n.getFn,i=void 0===r?k.getFn:r,o=new x({getFn:i});return o.setKeys(e.map(y)),o.setSources(t),o.create(),o}function L(e,t){var n=e.matches;t.matches=[],d(n)&&n.forEach((function(e){if(d(e.indices)&&e.indices.length){var n={indices:e.indices,value:e.value};e.key&&(n.key=e.key.src),e.idx>-1&&(n.refIndex=e.idx),t.matches.push(n)}}))}function _(e,t){t.score=e.score}function O(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.errors,r=void 0===n?0:n,i=t.currentLocation,o=void 0===i?0:i,a=t.expectedLocation,c=void 0===a?0:a,s=t.distance,h=void 0===s?k.distance:s,u=t.ignoreLocation,d=void 0===u?k.ignoreLocation:u,l=r/e.length;if(d)return l;var f=Math.abs(c-o);return h?l+f/h:f?1:l}function S(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:k.minMatchCharLength,n=[],r=-1,i=-1,o=0,a=e.length;o=t&&n.push([r,i]),r=-1)}return e[o-1]&&o-r>=t&&n.push([r,o-1]),n}function A(e){for(var t={},n=0,r=e.length;n1&&void 0!==arguments[1]?arguments[1]:{},o=i.location,a=void 0===o?k.location:o,c=i.threshold,s=void 0===c?k.threshold:c,h=i.distance,u=void 0===h?k.distance:h,d=i.includeMatches,l=void 0===d?k.includeMatches:d,f=i.findAllMatches,v=void 0===f?k.findAllMatches:f,g=i.minMatchCharLength,y=void 0===g?k.minMatchCharLength:g,p=i.isCaseSensitive,m=void 0===p?k.isCaseSensitive:p,M=i.ignoreLocation,b=void 0===M?k.ignoreLocation:M;if(e(this,t),this.options={location:a,threshold:s,distance:u,includeMatches:l,findAllMatches:v,minMatchCharLength:y,isCaseSensitive:m,ignoreLocation:b},this.pattern=m?n:n.toLowerCase(),this.chunks=[],this.pattern.length){var x=function(e,t){r.chunks.push({pattern:e,alphabet:A(e),startIndex:t})},w=this.pattern.length;if(w>32){for(var L=0,_=w%32,O=w-_;L3&&void 0!==arguments[3]?arguments[3]:{},i=r.location,o=void 0===i?k.location:i,a=r.distance,c=void 0===a?k.distance:a,s=r.threshold,h=void 0===s?k.threshold:s,u=r.findAllMatches,d=void 0===u?k.findAllMatches:u,l=r.minMatchCharLength,v=void 0===l?k.minMatchCharLength:l,g=r.includeMatches,y=void 0===g?k.includeMatches:g,p=r.ignoreLocation,m=void 0===p?k.ignoreLocation:p;if(t.length>32)throw new Error(f(32));for(var M,b=t.length,x=e.length,w=Math.max(0,Math.min(o,x)),L=h,_=w,A=v>1||y,E=A?Array(x):[];(M=e.indexOf(t,_))>-1;){var I=O(t,{currentLocation:M,expectedLocation:w,distance:c,ignoreLocation:m});if(L=Math.min(I,L),_=M+b,A)for(var j=0;j=J;q-=1){var U=q-1,V=n[e.charAt(U)];if(A&&(E[U]=+!!V),T[q]=(T[q+1]<<1|1)&V,$&&(T[q]|=(F[q+1]|F[q])<<1|1|F[q+1]),T[q]&N&&(C=O(t,{errors:$,currentLocation:U,expectedLocation:w,distance:c,ignoreLocation:m}))<=L){if(L=C,(_=U)<=w)break;J=Math.max(1,2*w-_)}}var B=O(t,{errors:$+1,currentLocation:w,expectedLocation:w,distance:c,ignoreLocation:m});if(B>L)break;F=T}var G={isMatch:_>=0,score:Math.max(.001,C)};if(A){var H=S(E,v);H.length?y&&(G.indices=H):G.isMatch=!1}return G}(e,n,i,{location:c+o,distance:s,threshold:h,findAllMatches:u,minMatchCharLength:d,includeMatches:r,ignoreLocation:l}),m=p.isMatch,M=p.score,b=p.indices;m&&(y=!0),g+=M,m&&b&&(v=[].concat(a(v),a(b)))}));var p={isMatch:y,score:y?g/this.chunks.length:1};return y&&r&&(p.indices=v),p}}]),t}(),I=[];function j(e,t){for(var n=0,r=I.length;n1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;if(e(this,t),this.options=o({},k,{},r),this.options.useExtendedSearch)throw new Error("Extended search is not available");this._keyStore=new g(this.options.keys),this.setCollection(n,i)}return n(t,[{key:"setCollection",value:function(e,t){if(this._docs=e,t&&!(t instanceof x))throw new Error("Incorrect 'index' type");this._myIndex=t||w(this.options.keys,this._docs,{getFn:this.options.getFn})}},{key:"add",value:function(e){d(e)&&(this._docs.push(e),this._myIndex.add(e))}},{key:"remove",value:function(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:function(){return!1},t=[],n=0,r=this._docs.length;n1&&void 0!==arguments[1]?arguments[1]:{},n=t.limit,r=void 0===n?-1:n,i=this.options,o=i.includeMatches,a=i.includeScore,c=i.shouldSort,s=i.sortFn,d=i.ignoreFieldNorm,l=h(e)?h(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return C(l,{ignoreFieldNorm:d}),c&&l.sort(s),u(r)&&r>-1&&(l=l.slice(0,r)),P(l,this._docs,{includeMatches:o,includeScore:a})}},{key:"_searchStringList",value:function(e){var t=j(e,this.options),n=this._myIndex.records,r=[];return n.forEach((function(e){var n=e.v,i=e.i,o=e.n;if(d(n)){var a=t.searchIn(n),c=a.isMatch,s=a.score,h=a.indices;c&&r.push({item:n,idx:i,matches:[{score:s,value:n,norm:o,indices:h}]})}})),r}},{key:"_searchLogical",value:function(e){throw new Error("Logical search is not available")}},{key:"_searchObjectList",value:function(e){var t=this,n=j(e,this.options),r=this._myIndex,i=r.keys,o=r.records,c=[];return o.forEach((function(e){var r=e.$,o=e.i;if(d(r)){var s=[];i.forEach((function(e,i){s.push.apply(s,a(t._findMatches({key:e,value:r[i],searcher:n})))})),s.length&&c.push({idx:o,item:r,matches:s})}})),c}},{key:"_findMatches",value:function(e){var t=e.key,n=e.value,r=e.searcher;if(!d(n))return[];var i=[];if(s(n))n.forEach((function(e){var n=e.v,o=e.i,a=e.n;if(d(n)){var c=r.searchIn(n),s=c.isMatch,h=c.score,u=c.indices;s&&i.push({score:h,key:t,value:n,idx:o,norm:a,indices:u})}}));else{var o=n.v,a=n.n,c=r.searchIn(o),h=c.isMatch,u=c.score,l=c.indices;h&&i.push({score:u,key:t,value:o,norm:a,indices:l})}return i}}]),t}();function C(e,t){var n=t.ignoreFieldNorm,r=void 0===n?k.ignoreFieldNorm:n;e.forEach((function(e){var t=1;e.matches.forEach((function(e){var n=e.key,i=e.norm,o=e.score,a=n?n.weight:null;t*=Math.pow(0===o&&a?Number.EPSILON:o,(a||1)*(r?1:i))})),e.score=t}))}function P(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n.includeMatches,i=void 0===r?k.includeMatches:r,o=n.includeScore,a=void 0===o?k.includeScore:o,c=[];return i&&c.push(L),a&&c.push(_),e.map((function(e){var n=e.idx,r={item:t[n],refIndex:n};return c.length&&c.forEach((function(t){t(e,r)})),r}))}return F.version="6.4.0",F.createIndex=w,F.parseIndex=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.getFn,r=void 0===n?k.getFn:n,i=e.keys,o=e.records,a=new x({getFn:r});return a.setKeys(i),a.setIndexRecords(o),a},F.config=k,F},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).Fuse=t(); \ No newline at end of file +var e,t;e=this,t=function(){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,r=new Array(t);n0&&void 0!==arguments[0]?arguments[0]:3,t=new Map;return{get:function(n){var r=n.match(w).length;if(t.has(r))return t.get(r);var i=parseFloat((1/Math.sqrt(r)).toFixed(e));return t.set(r,i),i},clear:function(){t.clear()}}}var _=function(){function e(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=n.getFn,i=void 0===r?x.getFn:r;t(this,e),this.norm=L(3),this.getFn=i,this.isCreated=!1,this.setIndexRecords()}return r(e,[{key:"setSources",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.docs=e}},{key:"setIndexRecords",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.records=e}},{key:"setKeys",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.keys=t,this._keysMap={},t.forEach((function(t,n){e._keysMap[t.id]=n}))}},{key:"create",value:function(){var e=this;!this.isCreated&&this.docs.length&&(this.isCreated=!0,u(this.docs[0])?this.docs.forEach((function(t,n){e._addString(t,n)})):this.docs.forEach((function(t,n){e._addObject(t,n)})),this.norm.clear())}},{key:"add",value:function(e){var t=this.size();u(e)?this._addString(e,t):this._addObject(e,t)}},{key:"removeAt",value:function(e){this.records.splice(e,1);for(var t=e,n=this.size();t2&&void 0!==arguments[2]?arguments[2]:{},r=n.getFn,i=void 0===r?x.getFn:r,o=new _({getFn:i});return o.setKeys(e.map(b)),o.setSources(t),o.create(),o}function O(e,t){var n=e.matches;t.matches=[],f(n)&&n.forEach((function(e){if(f(e.indices)&&e.indices.length){var n={indices:e.indices,value:e.value};e.key&&(n.key=e.key.src),e.idx>-1&&(n.refIndex=e.idx),t.matches.push(n)}}))}function A(e,t){t.score=e.score}function j(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.errors,r=void 0===n?0:n,i=t.currentLocation,o=void 0===i?0:i,c=t.expectedLocation,a=void 0===c?0:c,s=t.distance,h=void 0===s?x.distance:s,u=t.ignoreLocation,l=void 0===u?x.ignoreLocation:u,d=r/e.length;if(l)return d;var f=Math.abs(a-o);return h?d+f/h:f?1:d}function E(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:x.minMatchCharLength,n=[],r=-1,i=-1,o=0,c=e.length;o=t&&n.push([r,i]),r=-1)}return e[o-1]&&o-r>=t&&n.push([r,o-1]),n}function I(e){for(var t={},n=0,r=e.length;n1&&void 0!==arguments[1]?arguments[1]:{},o=i.location,c=void 0===o?x.location:o,a=i.threshold,s=void 0===a?x.threshold:a,h=i.distance,u=void 0===h?x.distance:h,l=i.includeMatches,d=void 0===l?x.includeMatches:l,f=i.findAllMatches,v=void 0===f?x.findAllMatches:f,y=i.minMatchCharLength,g=void 0===y?x.minMatchCharLength:y,p=i.isCaseSensitive,m=void 0===p?x.isCaseSensitive:p,b=i.ignoreLocation,k=void 0===b?x.ignoreLocation:b;if(t(this,e),this.options={location:c,threshold:s,distance:u,includeMatches:d,findAllMatches:v,minMatchCharLength:g,isCaseSensitive:m,ignoreLocation:k},this.pattern=m?n:n.toLowerCase(),this.chunks=[],this.pattern.length){var M=function(e,t){r.chunks.push({pattern:e,alphabet:I(e),startIndex:t})},w=this.pattern.length;if(w>32){for(var L=0,_=w%32,S=w-_;L3&&void 0!==arguments[3]?arguments[3]:{},i=r.location,o=void 0===i?x.location:i,c=r.distance,a=void 0===c?x.distance:c,s=r.threshold,h=void 0===s?x.threshold:s,u=r.findAllMatches,l=void 0===u?x.findAllMatches:u,d=r.minMatchCharLength,f=void 0===d?x.minMatchCharLength:d,v=r.includeMatches,y=void 0===v?x.includeMatches:v,p=r.ignoreLocation,m=void 0===p?x.ignoreLocation:p;if(t.length>32)throw new Error(g(32));for(var b,k=t.length,M=e.length,w=Math.max(0,Math.min(o,M)),L=h,_=w,S=f>1||y,O=S?Array(M):[];(b=e.indexOf(t,_))>-1;){var A=j(t,{currentLocation:b,expectedLocation:w,distance:a,ignoreLocation:m});if(L=Math.min(A,L),_=b+k,S)for(var I=0;I=J;U-=1){var q=U-1,B=n[e.charAt(q)];if(S&&(O[q]=+!!B),T[U]=(T[U+1]<<1|1)&B,$&&(T[U]|=(F[U+1]|F[U])<<1|1|F[U+1]),T[U]&N&&(C=j(t,{errors:$,currentLocation:q,expectedLocation:w,distance:a,ignoreLocation:m}))<=L){if(L=C,(_=q)<=w)break;J=Math.max(1,2*w-_)}}var V=j(t,{errors:$+1,currentLocation:w,expectedLocation:w,distance:a,ignoreLocation:m});if(V>L)break;F=T}var G={isMatch:_>=0,score:Math.max(.001,C)};if(S){var H=E(O,f);H.length?y&&(G.indices=H):G.isMatch=!1}return G}(e,n,i,{location:c+o,distance:s,threshold:h,findAllMatches:u,minMatchCharLength:l,includeMatches:r,ignoreLocation:d}),m=p.isMatch,b=p.score,k=p.indices;m&&(y=!0),v+=b,m&&k&&(f=[].concat(a(f),a(k)))}));var p={isMatch:y,score:y?v/this.chunks.length:1};return y&&r&&(p.indices=f),p}}]),e}(),C=[];function P(e,t){for(var n=0,r=C.length;n1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;if(t(this,e),this.options=c({},x,{},r),this.options.useExtendedSearch)throw new Error("Extended search is not available");this._keyStore=new m(this.options.keys),this.setCollection(n,i)}return r(e,[{key:"setCollection",value:function(e,t){if(this._docs=e,t&&!(t instanceof _))throw new Error("Incorrect 'index' type");this._myIndex=t||S(this.options.keys,this._docs,{getFn:this.options.getFn})}},{key:"add",value:function(e){f(e)&&(this._docs.push(e),this._myIndex.add(e))}},{key:"remove",value:function(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:function(){return!1},t=[],n=0,r=this._docs.length;n1&&void 0!==arguments[1]?arguments[1]:{},n=t.limit,r=void 0===n?-1:n,i=this.options,o=i.includeMatches,c=i.includeScore,a=i.shouldSort,s=i.sortFn,h=i.ignoreFieldNorm,d=u(e)?u(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return $(d,{ignoreFieldNorm:h}),a&&d.sort(s),l(r)&&r>-1&&(d=d.slice(0,r)),D(d,this._docs,{includeMatches:o,includeScore:c})}},{key:"_searchStringList",value:function(e){var t=P(e,this.options),n=this._myIndex.records,r=[];return n.forEach((function(e){var n=e.v,i=e.i,o=e.n;if(f(n)){var c=t.searchIn(n),a=c.isMatch,s=c.score,h=c.indices;a&&r.push({item:n,idx:i,matches:[{score:s,value:n,norm:o,indices:h}]})}})),r}},{key:"_searchLogical",value:function(e){throw new Error("Logical search is not available")}},{key:"_searchObjectList",value:function(e){var t=this,n=P(e,this.options),r=this._myIndex,i=r.keys,o=r.records,c=[];return o.forEach((function(e){var r=e.$,o=e.i;if(f(r)){var s=[];i.forEach((function(e,i){s.push.apply(s,a(t._findMatches({key:e,value:r[i],searcher:n})))})),s.length&&c.push({idx:o,item:r,matches:s})}})),c}},{key:"_findMatches",value:function(e){var t=e.key,n=e.value,r=e.searcher;if(!f(n))return[];var i=[];if(h(n))n.forEach((function(e){var n=e.v,o=e.i,c=e.n;if(f(n)){var a=r.searchIn(n),s=a.isMatch,h=a.score,u=a.indices;s&&i.push({score:h,key:t,value:n,idx:o,norm:c,indices:u})}}));else{var o=n.v,c=n.n,a=r.searchIn(o),s=a.isMatch,u=a.score,l=a.indices;s&&i.push({score:u,key:t,value:o,norm:c,indices:l})}return i}}]),e}();function $(e,t){var n=t.ignoreFieldNorm,r=void 0===n?x.ignoreFieldNorm:n;e.forEach((function(e){var t=1;e.matches.forEach((function(e){var n=e.key,i=e.norm,o=e.score,c=n?n.weight:null;t*=Math.pow(0===o&&c?Number.EPSILON:o,(c||1)*(r?1:i))})),e.score=t}))}function D(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n.includeMatches,i=void 0===r?x.includeMatches:r,o=n.includeScore,c=void 0===o?x.includeScore:o,a=[];return i&&a.push(O),c&&a.push(A),e.map((function(e){var n=e.idx,r={item:t[n],refIndex:n};return a.length&&a.forEach((function(t){t(e,r)})),r}))}return N.version="6.4.1",N.createIndex=S,N.parseIndex=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.getFn,r=void 0===n?x.getFn:n,i=e.keys,o=e.records,c=new _({getFn:r});return c.setKeys(i),c.setIndexRecords(o),c},N.config=x,N},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).Fuse=t(); \ No newline at end of file diff --git a/dist/fuse.common.js b/dist/fuse.common.js index cf5124751..5f21fad42 100644 --- a/dist/fuse.common.js +++ b/dist/fuse.common.js @@ -1,5 +1,5 @@ /** - * Fuse.js v6.4.0 - Lightweight fuzzy-search (http://fusejs.io) + * Fuse.js v6.4.1 - Lightweight fuzzy-search (http://fusejs.io) * * Copyright (c) 2020 Kiro Risk (http://kiro.me) * All Rights Reserved. Apache Software License 2.0 @@ -209,9 +209,8 @@ function _nonIterableSpread() { } function isArray(value) { - return !Array.isArray ? Object.prototype.toString.call(value) === '[object Array]' : Array.isArray(value); -} // Adapted from: -// https://github.com/lodash/lodash/blob/f4ca396a796435422bd4fd41fadbd225edddf175/.internal/baseToString.js + return !Array.isArray ? getTag(value) === '[object Array]' : Array.isArray(value); +} // Adapted from: https://github.com/lodash/lodash/blob/master/.internal/baseToString.js var INFINITY = 1 / 0; function baseToString(value) { @@ -231,15 +230,28 @@ function isString(value) { } function isNumber(value) { return typeof value === 'number'; +} // Adapted from: https://github.com/lodash/lodash/blob/master/isBoolean.js + +function isBoolean(value) { + return value === true || value === false || isObjectLike(value) && getTag(value) == '[object Boolean]'; } function isObject(value) { return _typeof(value) === 'object'; +} // Checks if `value` is object-like. + +function isObjectLike(value) { + return isObject(value) && value !== null; } function isDefined(value) { return value !== undefined && value !== null; } function isBlank(value) { return !value.trim().length; +} // Gets the `toStringTag` of `value`. +// Adapted from: https://github.com/lodash/lodash/blob/master/.internal/getTag.js + +function getTag(value) { + return value == null ? value === undefined ? '[object Undefined]' : '[object Null]' : Object.prototype.toString.call(value); } var EXTENDED_SEARCH_UNAVAILABLE = 'Extended search is not available'; @@ -360,9 +372,11 @@ function get(obj, path) { if (!isDefined(value)) { return; - } + } // If we're at the last value in the path, and if it's a string/number/bool, + // add it to the list + - if (index === path.length - 1 && (isString(value) || isNumber(value))) { + if (index === path.length - 1 && (isString(value) || isNumber(value) || isBoolean(value))) { list.push(toString(value)); } else if (isArray(value)) { arr = true; // Search each item in the array. @@ -2205,7 +2219,7 @@ function format(results, docs) { }); } -Fuse.version = '6.4.0'; +Fuse.version = '6.4.1'; Fuse.createIndex = createIndex; Fuse.parseIndex = parseIndex; Fuse.config = Config; diff --git a/dist/fuse.d.ts b/dist/fuse.d.ts index dcde24801..43c13c77f 100644 --- a/dist/fuse.d.ts +++ b/dist/fuse.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Fuse.js v6.4.0 +// Type definitions for Fuse.js v6.4.1 // TypeScript v3.9.5 export default Fuse diff --git a/dist/fuse.esm.js b/dist/fuse.esm.js index 57e810fc1..86dc530f3 100644 --- a/dist/fuse.esm.js +++ b/dist/fuse.esm.js @@ -1,5 +1,5 @@ /** - * Fuse.js v6.4.0 - Lightweight fuzzy-search (http://fusejs.io) + * Fuse.js v6.4.1 - Lightweight fuzzy-search (http://fusejs.io) * * Copyright (c) 2020 Kiro Risk (http://kiro.me) * All Rights Reserved. Apache Software License 2.0 @@ -9,12 +9,11 @@ function isArray(value) { return !Array.isArray - ? Object.prototype.toString.call(value) === '[object Array]' + ? getTag(value) === '[object Array]' : Array.isArray(value) } -// Adapted from: -// https://github.com/lodash/lodash/blob/f4ca396a796435422bd4fd41fadbd225edddf175/.internal/baseToString.js +// Adapted from: https://github.com/lodash/lodash/blob/master/.internal/baseToString.js const INFINITY = 1 / 0; function baseToString(value) { // Exit early for strings to avoid a performance hit in some environments. @@ -37,10 +36,24 @@ function isNumber(value) { return typeof value === 'number' } +// Adapted from: https://github.com/lodash/lodash/blob/master/isBoolean.js +function isBoolean(value) { + return ( + value === true || + value === false || + (isObjectLike(value) && getTag(value) == '[object Boolean]') + ) +} + function isObject(value) { return typeof value === 'object' } +// Checks if `value` is object-like. +function isObjectLike(value) { + return isObject(value) && value !== null +} + function isDefined(value) { return value !== undefined && value !== null } @@ -49,6 +62,16 @@ function isBlank(value) { return !value.trim().length } +// Gets the `toStringTag` of `value`. +// Adapted from: https://github.com/lodash/lodash/blob/master/.internal/getTag.js +function getTag(value) { + return value == null + ? value === undefined + ? '[object Undefined]' + : '[object Null]' + : Object.prototype.toString.call(value) +} + const EXTENDED_SEARCH_UNAVAILABLE = 'Extended search is not available'; const INCORRECT_INDEX_TYPE = "Incorrect 'index' type"; @@ -158,7 +181,12 @@ function get(obj, path) { return } - if (index === path.length - 1 && (isString(value) || isNumber(value))) { + // If we're at the last value in the path, and if it's a string/number/bool, + // add it to the list + if ( + index === path.length - 1 && + (isString(value) || isNumber(value) || isBoolean(value)) + ) { list.push(toString(value)); } else if (isArray(value)) { arr = true; @@ -1723,7 +1751,7 @@ function format( }) } -Fuse.version = '6.4.0'; +Fuse.version = '6.4.1'; Fuse.createIndex = createIndex; Fuse.parseIndex = parseIndex; Fuse.config = Config; diff --git a/dist/fuse.esm.min.js b/dist/fuse.esm.min.js index ff160b26a..16ae1791a 100644 --- a/dist/fuse.esm.min.js +++ b/dist/fuse.esm.min.js @@ -1,9 +1,9 @@ /** - * Fuse.js v6.4.0 - Lightweight fuzzy-search (http://fusejs.io) + * Fuse.js v6.4.1 - Lightweight fuzzy-search (http://fusejs.io) * * Copyright (c) 2020 Kiro Risk (http://kiro.me) * All Rights Reserved. Apache Software License 2.0 * * http://www.apache.org/licenses/LICENSE-2.0 */ -function t(t){return Array.isArray?Array.isArray(t):"[object Array]"===Object.prototype.toString.call(t)}function e(t){return"string"==typeof t}function s(t){return"number"==typeof t}function n(t){return null!=t}function r(t){return!t.trim().length}const i=Object.prototype.hasOwnProperty;class c{constructor(t){this._keys=[],this._keyMap={};let e=0;t.forEach(t=>{let s=o(t);e+=s.weight,this._keys.push(s),this._keyMap[s.id]=s,e+=s.weight}),this._keys.forEach(t=>{t.weight/=e})}get(t){return this._keyMap[t]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function o(s){let n=null,r=null,c=null,o=1;if(e(s)||t(s))c=s,n=h(s),r=a(s);else{if(!i.call(s,"name"))throw new Error((t=>`Missing ${t} property in key`)("name"));const t=s.name;if(c=t,i.call(s,"weight")&&(o=s.weight,o<=0))throw new Error((t=>`Property 'weight' in key '${t}' must be a positive integer`)(t));n=h(t),r=a(t)}return{path:n,id:r,weight:o,src:c}}function h(e){return t(e)?e:e.split(".")}function a(e){return t(e)?e.join("."):e}var l={isCaseSensitive:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score===e.score?t.idx{if(i[a]){const l=r[i[a]];if(!n(l))return;if(a===i.length-1&&(e(l)||s(l)))c.push(function(t){return null==t?"":function(t){if("string"==typeof t)return t;let e=t+"";return"0"==e&&1/t==-1/0?"-0":e}(t)}(l));else if(t(l)){o=!0;for(let t=0,e=l.length;t{this._keysMap[t.id]=e})}create(){!this.isCreated&&this.docs.length&&(this.isCreated=!0,e(this.docs[0])?this.docs.forEach((t,e)=>{this._addString(t,e)}):this.docs.forEach((t,e)=>{this._addObject(t,e)}),this.norm.clear())}add(t){const s=this.size();e(t)?this._addString(t,s):this._addObject(t,s)}removeAt(t){this.records.splice(t,1);for(let e=t,s=this.size();e{let h=this.getFn(s,i.path);if(n(h))if(t(h)){let s=[];const i=[{nestedArrIndex:-1,value:h}];for(;i.length;){const{nestedArrIndex:c,value:o}=i.pop();if(n(o))if(e(o)&&!r(o)){let t={v:o,i:c,n:this.norm.get(o)};s.push(t)}else t(o)&&o.forEach((t,e)=>{i.push({nestedArrIndex:e,value:t})})}c.$[o]=s}else if(!r(h)){let t={v:h,n:this.norm.get(h)};c.$[o]=t}}),this.records.push(c)}toJSON(){return{keys:this.keys,records:this.records}}}function g(t,e,{getFn:s=l.getFn}={}){const n=new d({getFn:s});return n.setKeys(t.map(o)),n.setSources(e),n.create(),n}function f(t,e){const s=t.matches;e.matches=[],n(s)&&s.forEach(t=>{if(!n(t.indices)||!t.indices.length)return;const{indices:s,value:r}=t;let i={indices:s,value:r};t.key&&(i.key=t.key.src),t.idx>-1&&(i.refIndex=t.idx),e.matches.push(i)})}function p(t,e){e.score=t.score}function M(t,{errors:e=0,currentLocation:s=0,expectedLocation:n=0,distance:r=l.distance,ignoreLocation:i=l.ignoreLocation}={}){const c=e/t.length;if(i)return c;const o=Math.abs(n-s);return r?c+o/r:o?1:c}function m(t,e,s,{location:n=l.location,distance:r=l.distance,threshold:i=l.threshold,findAllMatches:c=l.findAllMatches,minMatchCharLength:o=l.minMatchCharLength,includeMatches:h=l.includeMatches,ignoreLocation:a=l.ignoreLocation}={}){if(e.length>32)throw new Error(`Pattern length exceeds max of ${32}.`);const u=e.length,d=t.length,g=Math.max(0,Math.min(n,d));let f=i,p=g;const m=o>1||h,x=m?Array(d):[];let y;for(;(y=t.indexOf(e,p))>-1;){let t=M(e,{currentLocation:y,expectedLocation:g,distance:r,ignoreLocation:a});if(f=Math.min(t,f),p=y+u,m){let t=0;for(;t=h;i-=1){let c=i-1,o=s[t.charAt(c)];if(m&&(x[c]=+!!o),y[i]=(y[i+1]<<1|1)&o,n&&(y[i]|=(L[i+1]|L[i])<<1|1|L[i+1]),y[i]&v&&(k=M(e,{errors:n,currentLocation:c,expectedLocation:g,distance:r,ignoreLocation:a}),k<=f)){if(f=k,p=c,p<=g)break;h=Math.max(1,2*g-p)}}if(M(e,{errors:n+1,currentLocation:g,expectedLocation:g,distance:r,ignoreLocation:a})>f)break;L=y}const S={isMatch:p>=0,score:Math.max(.001,k)};if(m){const t=function(t=[],e=l.minMatchCharLength){let s=[],n=-1,r=-1,i=0;for(let c=t.length;i=e&&s.push([n,r]),n=-1)}return t[i-1]&&i-n>=e&&s.push([n,i-1]),s}(x,o);t.length?h&&(S.indices=t):S.isMatch=!1}return S}function x(t){let e={};for(let s=0,n=t.length;s{this.chunks.push({pattern:t,alphabet:x(t),startIndex:e})},u=this.pattern.length;if(u>32){let t=0;const e=u%32,s=u-e;for(;t{const{isMatch:f,score:p,indices:M}=m(t,e,d,{location:n+g,distance:r,threshold:i,findAllMatches:c,minMatchCharLength:o,includeMatches:s,ignoreLocation:h});f&&(u=!0),l+=p,f&&M&&(a=[...a,...M])});let d={isMatch:u,score:u?l/this.chunks.length:1};return u&&s&&(d.indices=a),d}}class L{constructor(t){this.pattern=t}static isMultiMatch(t){return k(t,this.multiRegex)}static isSingleMatch(t){return k(t,this.singleRegex)}search(){}}function k(t,e){const s=t.match(e);return s?s[1]:null}class _ extends L{constructor(t,{location:e=l.location,threshold:s=l.threshold,distance:n=l.distance,includeMatches:r=l.includeMatches,findAllMatches:i=l.findAllMatches,minMatchCharLength:c=l.minMatchCharLength,isCaseSensitive:o=l.isCaseSensitive}={}){super(t),this._bitapSearch=new y(t,{location:e,threshold:s,distance:n,includeMatches:r,findAllMatches:i,minMatchCharLength:c,isCaseSensitive:o})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(t){return this._bitapSearch.searchIn(t)}}class v extends L{constructor(t){super(t)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(t){let e,s=0;const n=[],r=this.pattern.length;for(;(e=t.indexOf(this.pattern,s))>-1;)s=e+r,n.push([e,s-1]);const i=!!n.length;return{isMatch:i,score:i?1:0,indices:n}}}const S=[class extends L{constructor(t){super(t)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(t){const e=t===this.pattern;return{isMatch:e,score:e?0:1,indices:[0,this.pattern.length-1]}}},v,class extends L{constructor(t){super(t)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(t){const e=t.startsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,this.pattern.length-1]}}},class extends L{constructor(t){super(t)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(t){const e=!t.startsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,t.length-1]}}},class extends L{constructor(t){super(t)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(t){const e=!t.endsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,t.length-1]}}},class extends L{constructor(t){super(t)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(t){const e=t.endsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[t.length-this.pattern.length,t.length-1]}}},class extends L{constructor(t){super(t)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(t){const e=-1===t.indexOf(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,t.length-1]}}},_],C=S.length,I=/ +(?=([^\"]*\"[^\"]*\")*[^\"]*$)/;const w=new Set([_.type,v.type]);class ${constructor(t,{isCaseSensitive:e=l.isCaseSensitive,includeMatches:s=l.includeMatches,minMatchCharLength:n=l.minMatchCharLength,findAllMatches:r=l.findAllMatches,location:i=l.location,threshold:c=l.threshold,distance:o=l.distance}={}){this.query=null,this.options={isCaseSensitive:e,includeMatches:s,minMatchCharLength:n,findAllMatches:r,location:i,threshold:c,distance:o},this.pattern=e?t:t.toLowerCase(),this.query=function(t,e={}){return t.split("|").map(t=>{let s=t.trim().split(I).filter(t=>t&&!!t.trim()),n=[];for(let t=0,r=s.length;t!(!t[b]&&!t[F]),N=t=>({[b]:Object.keys(t).map(e=>({[e]:t[e]}))});function z(s,n,{auto:r=!0}={}){const i=s=>{let c=Object.keys(s);const o=(t=>!!t[R])(s);if(!o&&c.length>1&&!j(s))return i(N(s));if((e=>!t(e)&&"object"==typeof e&&!j(e))(s)){const t=o?s[R]:c[0],i=o?s[O]:s[t];if(!e(i))throw new Error((t=>"Invalid value for key "+t)(t));const h={keyId:a(t),pattern:i};return r&&(h.searcher=E(i,n)),h}let h={children:[],operator:c[0]};return c.forEach(e=>{const n=s[e];t(n)&&n.forEach(t=>{h.children.push(i(t))})}),h};return j(s)||(s=N(s)),i(s)}class K{constructor(t,e={},s){this.options={...l,...e},this.options.useExtendedSearch,this._keyStore=new c(this.options.keys),this.setCollection(t,s)}setCollection(t,e){if(this._docs=t,e&&!(e instanceof d))throw new Error("Incorrect 'index' type");this._myIndex=e||g(this.options.keys,this._docs,{getFn:this.options.getFn})}add(t){n(t)&&(this._docs.push(t),this._myIndex.add(t))}remove(t=(()=>!1)){const e=[];for(let s=0,n=this._docs.length;s{let s=1;t.matches.forEach(({key:t,norm:n,score:r})=>{const i=t?t.weight:null;s*=Math.pow(0===r&&i?Number.EPSILON:r,(i||1)*(e?1:n))}),t.score=s})}(a,{ignoreFieldNorm:h}),c&&a.sort(o),s(n)&&n>-1&&(a=a.slice(0,n)),function(t,e,{includeMatches:s=l.includeMatches,includeScore:n=l.includeScore}={}){const r=[];s&&r.push(f);n&&r.push(p);return t.map(t=>{const{idx:s}=t,n={item:e[s],refIndex:s};return r.length&&r.forEach(e=>{e(t,n)}),n})}(a,this._docs,{includeMatches:r,includeScore:i})}_searchStringList(t){const e=E(t,this.options),{records:s}=this._myIndex,r=[];return s.forEach(({v:t,i:s,n:i})=>{if(!n(t))return;const{isMatch:c,score:o,indices:h}=e.searchIn(t);c&&r.push({item:t,idx:s,matches:[{score:o,value:t,norm:i,indices:h}]})}),r}_searchLogical(t){const e=z(t,this.options),s=(t,e,n)=>{if(!t.children){const{keyId:s,searcher:r}=t,i=this._findMatches({key:this._keyStore.get(s),value:this._myIndex.getValueForItemAtKeyId(e,s),searcher:r});return i&&i.length?[{idx:n,item:e,matches:i}]:[]}switch(t.operator){case b:{const r=[];for(let i=0,c=t.children.length;i{if(n(t)){let n=s(e,t,r);n.length&&(i[r]||(i[r]={idx:r,item:t,matches:[]},c.push(i[r])),n.forEach(({matches:t})=>{i[r].matches.push(...t)}))}}),c}_searchObjectList(t){const e=E(t,this.options),{keys:s,records:r}=this._myIndex,i=[];return r.forEach(({$:t,i:r})=>{if(!n(t))return;let c=[];s.forEach((s,n)=>{c.push(...this._findMatches({key:s,value:t[n],searcher:e}))}),c.length&&i.push({idx:r,item:t,matches:c})}),i}_findMatches({key:e,value:s,searcher:r}){if(!n(s))return[];let i=[];if(t(s))s.forEach(({v:t,i:s,n:c})=>{if(!n(t))return;const{isMatch:o,score:h,indices:a}=r.searchIn(t);o&&i.push({score:h,key:e,value:t,idx:s,norm:c,indices:a})});else{const{v:t,n:n}=s,{isMatch:c,score:o,indices:h}=r.searchIn(t);c&&i.push({score:o,key:e,value:t,norm:n,indices:h})}return i}}K.version="6.4.0",K.createIndex=g,K.parseIndex=function(t,{getFn:e=l.getFn}={}){const{keys:s,records:n}=t,r=new d({getFn:e});return r.setKeys(s),r.setIndexRecords(n),r},K.config=l,function(...t){A.push(...t)}($);export default K; \ No newline at end of file +function t(t){return Array.isArray?Array.isArray(t):"[object Array]"===o(t)}function e(t){return"string"==typeof t}function s(t){return"number"==typeof t}function n(t){return!0===t||!1===t||function(t){return r(t)&&null!==t}(t)&&"[object Boolean]"==o(t)}function r(t){return"object"==typeof t}function i(t){return null!=t}function c(t){return!t.trim().length}function o(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const h=Object.prototype.hasOwnProperty;class a{constructor(t){this._keys=[],this._keyMap={};let e=0;t.forEach(t=>{let s=l(t);e+=s.weight,this._keys.push(s),this._keyMap[s.id]=s,e+=s.weight}),this._keys.forEach(t=>{t.weight/=e})}get(t){return this._keyMap[t]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function l(s){let n=null,r=null,i=null,c=1;if(e(s)||t(s))i=s,n=u(s),r=d(s);else{if(!h.call(s,"name"))throw new Error((t=>`Missing ${t} property in key`)("name"));const t=s.name;if(i=t,h.call(s,"weight")&&(c=s.weight,c<=0))throw new Error((t=>`Property 'weight' in key '${t}' must be a positive integer`)(t));n=u(t),r=d(t)}return{path:n,id:r,weight:c,src:i}}function u(e){return t(e)?e:e.split(".")}function d(e){return t(e)?e.join("."):e}var g={isCaseSensitive:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score===e.score?t.idx{if(c[l]){const u=r[c[l]];if(!i(u))return;if(l===c.length-1&&(e(u)||s(u)||n(u)))o.push(function(t){return null==t?"":function(t){if("string"==typeof t)return t;let e=t+"";return"0"==e&&1/t==-1/0?"-0":e}(t)}(u));else if(t(u)){h=!0;for(let t=0,e=u.length;t{this._keysMap[t.id]=e})}create(){!this.isCreated&&this.docs.length&&(this.isCreated=!0,e(this.docs[0])?this.docs.forEach((t,e)=>{this._addString(t,e)}):this.docs.forEach((t,e)=>{this._addObject(t,e)}),this.norm.clear())}add(t){const s=this.size();e(t)?this._addString(t,s):this._addObject(t,s)}removeAt(t){this.records.splice(t,1);for(let e=t,s=this.size();e{let h=this.getFn(s,n.path);if(i(h))if(t(h)){let s=[];const n=[{nestedArrIndex:-1,value:h}];for(;n.length;){const{nestedArrIndex:r,value:o}=n.pop();if(i(o))if(e(o)&&!c(o)){let t={v:o,i:r,n:this.norm.get(o)};s.push(t)}else t(o)&&o.forEach((t,e)=>{n.push({nestedArrIndex:e,value:t})})}r.$[o]=s}else if(!c(h)){let t={v:h,n:this.norm.get(h)};r.$[o]=t}}),this.records.push(r)}toJSON(){return{keys:this.keys,records:this.records}}}function M(t,e,{getFn:s=g.getFn}={}){const n=new p({getFn:s});return n.setKeys(t.map(l)),n.setSources(e),n.create(),n}function m(t,e){const s=t.matches;e.matches=[],i(s)&&s.forEach(t=>{if(!i(t.indices)||!t.indices.length)return;const{indices:s,value:n}=t;let r={indices:s,value:n};t.key&&(r.key=t.key.src),t.idx>-1&&(r.refIndex=t.idx),e.matches.push(r)})}function x(t,e){e.score=t.score}function y(t,{errors:e=0,currentLocation:s=0,expectedLocation:n=0,distance:r=g.distance,ignoreLocation:i=g.ignoreLocation}={}){const c=e/t.length;if(i)return c;const o=Math.abs(n-s);return r?c+o/r:o?1:c}function L(t,e,s,{location:n=g.location,distance:r=g.distance,threshold:i=g.threshold,findAllMatches:c=g.findAllMatches,minMatchCharLength:o=g.minMatchCharLength,includeMatches:h=g.includeMatches,ignoreLocation:a=g.ignoreLocation}={}){if(e.length>32)throw new Error(`Pattern length exceeds max of ${32}.`);const l=e.length,u=t.length,d=Math.max(0,Math.min(n,u));let f=i,p=d;const M=o>1||h,m=M?Array(u):[];let x;for(;(x=t.indexOf(e,p))>-1;){let t=y(e,{currentLocation:x,expectedLocation:d,distance:r,ignoreLocation:a});if(f=Math.min(t,f),p=x+l,M){let t=0;for(;t=h;i-=1){let c=i-1,o=s[t.charAt(c)];if(M&&(m[c]=+!!o),x[i]=(x[i+1]<<1|1)&o,n&&(x[i]|=(L[i+1]|L[i])<<1|1|L[i+1]),x[i]&v&&(k=y(e,{errors:n,currentLocation:c,expectedLocation:d,distance:r,ignoreLocation:a}),k<=f)){if(f=k,p=c,p<=d)break;h=Math.max(1,2*d-p)}}if(y(e,{errors:n+1,currentLocation:d,expectedLocation:d,distance:r,ignoreLocation:a})>f)break;L=x}const S={isMatch:p>=0,score:Math.max(.001,k)};if(M){const t=function(t=[],e=g.minMatchCharLength){let s=[],n=-1,r=-1,i=0;for(let c=t.length;i=e&&s.push([n,r]),n=-1)}return t[i-1]&&i-n>=e&&s.push([n,i-1]),s}(m,o);t.length?h&&(S.indices=t):S.isMatch=!1}return S}function k(t){let e={};for(let s=0,n=t.length;s{this.chunks.push({pattern:t,alphabet:k(t),startIndex:e})},l=this.pattern.length;if(l>32){let t=0;const e=l%32,s=l-e;for(;t{const{isMatch:f,score:p,indices:M}=L(t,e,d,{location:n+g,distance:r,threshold:i,findAllMatches:c,minMatchCharLength:o,includeMatches:s,ignoreLocation:h});f&&(u=!0),l+=p,f&&M&&(a=[...a,...M])});let d={isMatch:u,score:u?l/this.chunks.length:1};return u&&s&&(d.indices=a),d}}class v{constructor(t){this.pattern=t}static isMultiMatch(t){return S(t,this.multiRegex)}static isSingleMatch(t){return S(t,this.singleRegex)}search(){}}function S(t,e){const s=t.match(e);return s?s[1]:null}class C extends v{constructor(t,{location:e=g.location,threshold:s=g.threshold,distance:n=g.distance,includeMatches:r=g.includeMatches,findAllMatches:i=g.findAllMatches,minMatchCharLength:c=g.minMatchCharLength,isCaseSensitive:o=g.isCaseSensitive}={}){super(t),this._bitapSearch=new _(t,{location:e,threshold:s,distance:n,includeMatches:r,findAllMatches:i,minMatchCharLength:c,isCaseSensitive:o})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(t){return this._bitapSearch.searchIn(t)}}class I extends v{constructor(t){super(t)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(t){let e,s=0;const n=[],r=this.pattern.length;for(;(e=t.indexOf(this.pattern,s))>-1;)s=e+r,n.push([e,s-1]);const i=!!n.length;return{isMatch:i,score:i?1:0,indices:n}}}const w=[class extends v{constructor(t){super(t)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(t){const e=t===this.pattern;return{isMatch:e,score:e?0:1,indices:[0,this.pattern.length-1]}}},I,class extends v{constructor(t){super(t)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(t){const e=t.startsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,this.pattern.length-1]}}},class extends v{constructor(t){super(t)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(t){const e=!t.startsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,t.length-1]}}},class extends v{constructor(t){super(t)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(t){const e=!t.endsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,t.length-1]}}},class extends v{constructor(t){super(t)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(t){const e=t.endsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[t.length-this.pattern.length,t.length-1]}}},class extends v{constructor(t){super(t)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(t){const e=-1===t.indexOf(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,t.length-1]}}},C],$=w.length,A=/ +(?=([^\"]*\"[^\"]*\")*[^\"]*$)/;const b=new Set([C.type,I.type]);class E{constructor(t,{isCaseSensitive:e=g.isCaseSensitive,includeMatches:s=g.includeMatches,minMatchCharLength:n=g.minMatchCharLength,findAllMatches:r=g.findAllMatches,location:i=g.location,threshold:c=g.threshold,distance:o=g.distance}={}){this.query=null,this.options={isCaseSensitive:e,includeMatches:s,minMatchCharLength:n,findAllMatches:r,location:i,threshold:c,distance:o},this.pattern=e?t:t.toLowerCase(),this.query=function(t,e={}){return t.split("|").map(t=>{let s=t.trim().split(A).filter(t=>t&&!!t.trim()),n=[];for(let t=0,r=s.length;t!(!t[O]&&!t[j]),q=t=>({[O]:Object.keys(t).map(e=>({[e]:t[e]}))});function P(s,n,{auto:i=!0}={}){const c=s=>{let o=Object.keys(s);const h=(t=>!!t[N])(s);if(!h&&o.length>1&&!K(s))return c(q(s));if((e=>!t(e)&&r(e)&&!K(e))(s)){const t=h?s[N]:o[0],r=h?s[z]:s[t];if(!e(r))throw new Error((t=>"Invalid value for key "+t)(t));const c={keyId:d(t),pattern:r};return i&&(c.searcher=R(r,n)),c}let a={children:[],operator:o[0]};return o.forEach(e=>{const n=s[e];t(n)&&n.forEach(t=>{a.children.push(c(t))})}),a};return K(s)||(s=q(s)),c(s)}class W{constructor(t,e={},s){this.options={...g,...e},this.options.useExtendedSearch,this._keyStore=new a(this.options.keys),this.setCollection(t,s)}setCollection(t,e){if(this._docs=t,e&&!(e instanceof p))throw new Error("Incorrect 'index' type");this._myIndex=e||M(this.options.keys,this._docs,{getFn:this.options.getFn})}add(t){i(t)&&(this._docs.push(t),this._myIndex.add(t))}remove(t=(()=>!1)){const e=[];for(let s=0,n=this._docs.length;s{let s=1;t.matches.forEach(({key:t,norm:n,score:r})=>{const i=t?t.weight:null;s*=Math.pow(0===r&&i?Number.EPSILON:r,(i||1)*(e?1:n))}),t.score=s})}(a,{ignoreFieldNorm:h}),c&&a.sort(o),s(n)&&n>-1&&(a=a.slice(0,n)),function(t,e,{includeMatches:s=g.includeMatches,includeScore:n=g.includeScore}={}){const r=[];s&&r.push(m);n&&r.push(x);return t.map(t=>{const{idx:s}=t,n={item:e[s],refIndex:s};return r.length&&r.forEach(e=>{e(t,n)}),n})}(a,this._docs,{includeMatches:r,includeScore:i})}_searchStringList(t){const e=R(t,this.options),{records:s}=this._myIndex,n=[];return s.forEach(({v:t,i:s,n:r})=>{if(!i(t))return;const{isMatch:c,score:o,indices:h}=e.searchIn(t);c&&n.push({item:t,idx:s,matches:[{score:o,value:t,norm:r,indices:h}]})}),n}_searchLogical(t){const e=P(t,this.options),s=(t,e,n)=>{if(!t.children){const{keyId:s,searcher:r}=t,i=this._findMatches({key:this._keyStore.get(s),value:this._myIndex.getValueForItemAtKeyId(e,s),searcher:r});return i&&i.length?[{idx:n,item:e,matches:i}]:[]}switch(t.operator){case O:{const r=[];for(let i=0,c=t.children.length;i{if(i(t)){let i=s(e,t,n);i.length&&(r[n]||(r[n]={idx:n,item:t,matches:[]},c.push(r[n])),i.forEach(({matches:t})=>{r[n].matches.push(...t)}))}}),c}_searchObjectList(t){const e=R(t,this.options),{keys:s,records:n}=this._myIndex,r=[];return n.forEach(({$:t,i:n})=>{if(!i(t))return;let c=[];s.forEach((s,n)=>{c.push(...this._findMatches({key:s,value:t[n],searcher:e}))}),c.length&&r.push({idx:n,item:t,matches:c})}),r}_findMatches({key:e,value:s,searcher:n}){if(!i(s))return[];let r=[];if(t(s))s.forEach(({v:t,i:s,n:c})=>{if(!i(t))return;const{isMatch:o,score:h,indices:a}=n.searchIn(t);o&&r.push({score:h,key:e,value:t,idx:s,norm:c,indices:a})});else{const{v:t,n:i}=s,{isMatch:c,score:o,indices:h}=n.searchIn(t);c&&r.push({score:o,key:e,value:t,norm:i,indices:h})}return r}}W.version="6.4.1",W.createIndex=M,W.parseIndex=function(t,{getFn:e=g.getFn}={}){const{keys:s,records:n}=t,r=new p({getFn:e});return r.setKeys(s),r.setIndexRecords(n),r},W.config=g,function(...t){F.push(...t)}(E);export default W; \ No newline at end of file diff --git a/dist/fuse.js b/dist/fuse.js index bd0e1f070..6fcca8b2b 100644 --- a/dist/fuse.js +++ b/dist/fuse.js @@ -1,5 +1,5 @@ /** - * Fuse.js v6.4.0 - Lightweight fuzzy-search (http://fusejs.io) + * Fuse.js v6.4.1 - Lightweight fuzzy-search (http://fusejs.io) * * Copyright (c) 2020 Kiro Risk (http://kiro.me) * All Rights Reserved. Apache Software License 2.0 @@ -2223,7 +2223,7 @@ }); } - Fuse.version = '6.4.0'; + Fuse.version = '6.4.1'; Fuse.createIndex = createIndex; Fuse.parseIndex = parseIndex; Fuse.config = Config; diff --git a/dist/fuse.min.js b/dist/fuse.min.js index cf145dbc0..02ab1f248 100644 --- a/dist/fuse.min.js +++ b/dist/fuse.min.js @@ -1,9 +1,9 @@ /** - * Fuse.js v6.4.0 - Lightweight fuzzy-search (http://fusejs.io) + * Fuse.js v6.4.1 - Lightweight fuzzy-search (http://fusejs.io) * * Copyright (c) 2020 Kiro Risk (http://kiro.me) * All Rights Reserved. Apache Software License 2.0 * * http://www.apache.org/licenses/LICENSE-2.0 */ -var e,t;e=this,t=function(){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,r=new Array(t);n0&&void 0!==arguments[0]?arguments[0]:3,t=new Map;return{get:function(n){var r=n.match(O).length;if(t.has(r))return t.get(r);var i=parseFloat((1/Math.sqrt(r)).toFixed(e));return t.set(r,i),i},clear:function(){t.clear()}}}var I=function(){function e(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=n.getFn,i=void 0===r?L.getFn:r;t(this,e),this.norm=A(3),this.getFn=i,this.isCreated=!1,this.setIndexRecords()}return r(e,[{key:"setSources",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.docs=e}},{key:"setIndexRecords",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.records=e}},{key:"setKeys",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.keys=t,this._keysMap={},t.forEach((function(t,n){e._keysMap[t.id]=n}))}},{key:"create",value:function(){var e=this;!this.isCreated&&this.docs.length&&(this.isCreated=!0,g(this.docs[0])?this.docs.forEach((function(t,n){e._addString(t,n)})):this.docs.forEach((function(t,n){e._addObject(t,n)})),this.norm.clear())}},{key:"add",value:function(e){var t=this.size();g(e)?this._addString(e,t):this._addObject(e,t)}},{key:"removeAt",value:function(e){this.records.splice(e,1);for(var t=e,n=this.size();t2&&void 0!==arguments[2]?arguments[2]:{},r=n.getFn,i=void 0===r?L.getFn:r,o=new I({getFn:i});return o.setKeys(e.map(S)),o.setSources(t),o.create(),o}function j(e,t){var n=e.matches;t.matches=[],p(n)&&n.forEach((function(e){if(p(e.indices)&&e.indices.length){var n={indices:e.indices,value:e.value};e.key&&(n.key=e.key.src),e.idx>-1&&(n.refIndex=e.idx),t.matches.push(n)}}))}function E(e,t){t.score=e.score}function $(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.errors,r=void 0===n?0:n,i=t.currentLocation,o=void 0===i?0:i,c=t.expectedLocation,a=void 0===c?0:c,s=t.distance,u=void 0===s?L.distance:s,h=t.ignoreLocation,f=void 0===h?L.ignoreLocation:h,l=r/e.length;if(f)return l;var d=Math.abs(a-o);return u?l+d/u:d?1:l}function R(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:L.minMatchCharLength,n=[],r=-1,i=-1,o=0,c=e.length;o=t&&n.push([r,i]),r=-1)}return e[o-1]&&o-r>=t&&n.push([r,o-1]),n}function F(e){for(var t={},n=0,r=e.length;n1&&void 0!==arguments[1]?arguments[1]:{},o=i.location,c=void 0===o?L.location:o,a=i.threshold,s=void 0===a?L.threshold:a,u=i.distance,h=void 0===u?L.distance:u,f=i.includeMatches,l=void 0===f?L.includeMatches:f,d=i.findAllMatches,v=void 0===d?L.findAllMatches:d,g=i.minMatchCharLength,y=void 0===g?L.minMatchCharLength:g,p=i.isCaseSensitive,m=void 0===p?L.isCaseSensitive:p,k=i.ignoreLocation,M=void 0===k?L.ignoreLocation:k;if(t(this,e),this.options={location:c,threshold:s,distance:h,includeMatches:l,findAllMatches:v,minMatchCharLength:y,isCaseSensitive:m,ignoreLocation:M},this.pattern=m?n:n.toLowerCase(),this.chunks=[],this.pattern.length){var x=function(e,t){r.chunks.push({pattern:e,alphabet:F(e),startIndex:t})},b=this.pattern.length;if(b>32){for(var S=0,_=b%32,w=b-_;S3&&void 0!==arguments[3]?arguments[3]:{},i=r.location,o=void 0===i?L.location:i,c=r.distance,a=void 0===c?L.distance:c,s=r.threshold,u=void 0===s?L.threshold:s,h=r.findAllMatches,f=void 0===h?L.findAllMatches:h,l=r.minMatchCharLength,d=void 0===l?L.minMatchCharLength:l,v=r.includeMatches,g=void 0===v?L.includeMatches:v,y=r.ignoreLocation,p=void 0===y?L.ignoreLocation:y;if(t.length>32)throw new Error(M(32));for(var m,k=t.length,x=e.length,b=Math.max(0,Math.min(o,x)),S=u,_=b,w=d>1||g,O=w?Array(x):[];(m=e.indexOf(t,_))>-1;){var A=$(t,{currentLocation:m,expectedLocation:b,distance:a,ignoreLocation:p});if(S=Math.min(A,S),_=m+k,w)for(var I=0;I=K;J-=1){var T=J-1,V=n[e.charAt(T)];if(w&&(O[T]=+!!V),W[J]=(W[J+1]<<1|1)&V,P&&(W[J]|=(C[J+1]|C[J])<<1|1|C[J+1]),W[J]&F&&(j=$(t,{errors:P,currentLocation:T,expectedLocation:b,distance:a,ignoreLocation:p}))<=S){if(S=j,(_=T)<=b)break;K=Math.max(1,2*b-_)}}var U=$(t,{errors:P+1,currentLocation:b,expectedLocation:b,distance:a,ignoreLocation:p});if(U>S)break;C=W}var B={isMatch:_>=0,score:Math.max(.001,j)};if(w){var G=R(O,d);G.length?g&&(B.indices=G):B.isMatch=!1}return B}(e,n,i,{location:c+o,distance:a,threshold:s,findAllMatches:u,minMatchCharLength:h,includeMatches:r,ignoreLocation:f}),p=y.isMatch,m=y.score,k=y.indices;p&&(g=!0),v+=m,p&&k&&(d=[].concat(l(d),l(k)))}));var y={isMatch:g,score:g?v/this.chunks.length:1};return g&&r&&(y.indices=d),y}}]),e}(),N=function(){function e(n){t(this,e),this.pattern=n}return r(e,[{key:"search",value:function(){}}],[{key:"isMultiMatch",value:function(e){return D(e,this.multiRegex)}},{key:"isSingleMatch",value:function(e){return D(e,this.singleRegex)}}]),e}();function D(e,t){var n=e.match(t);return n?n[1]:null}var z=function(e){a(i,e);var n=f(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){var t=e===this.pattern;return{isMatch:t,score:t?0:1,indices:[0,this.pattern.length-1]}}}],[{key:"type",get:function(){return"exact"}},{key:"multiRegex",get:function(){return/^="(.*)"$/}},{key:"singleRegex",get:function(){return/^=(.*)$/}}]),i}(N),K=function(e){a(i,e);var n=f(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){var t=-1===e.indexOf(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}}],[{key:"type",get:function(){return"inverse-exact"}},{key:"multiRegex",get:function(){return/^!"(.*)"$/}},{key:"singleRegex",get:function(){return/^!(.*)$/}}]),i}(N),q=function(e){a(i,e);var n=f(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){var t=e.startsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,this.pattern.length-1]}}}],[{key:"type",get:function(){return"prefix-exact"}},{key:"multiRegex",get:function(){return/^\^"(.*)"$/}},{key:"singleRegex",get:function(){return/^\^(.*)$/}}]),i}(N),W=function(e){a(i,e);var n=f(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){var t=!e.startsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}}],[{key:"type",get:function(){return"inverse-prefix-exact"}},{key:"multiRegex",get:function(){return/^!\^"(.*)"$/}},{key:"singleRegex",get:function(){return/^!\^(.*)$/}}]),i}(N),J=function(e){a(i,e);var n=f(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){var t=e.endsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[e.length-this.pattern.length,e.length-1]}}}],[{key:"type",get:function(){return"suffix-exact"}},{key:"multiRegex",get:function(){return/^"(.*)"\$$/}},{key:"singleRegex",get:function(){return/^(.*)\$$/}}]),i}(N),T=function(e){a(i,e);var n=f(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){var t=!e.endsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}}],[{key:"type",get:function(){return"inverse-suffix-exact"}},{key:"multiRegex",get:function(){return/^!"(.*)"\$$/}},{key:"singleRegex",get:function(){return/^!(.*)\$$/}}]),i}(N),V=function(e){a(i,e);var n=f(i);function i(e){var r,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},c=o.location,a=void 0===c?L.location:c,s=o.threshold,u=void 0===s?L.threshold:s,h=o.distance,f=void 0===h?L.distance:h,l=o.includeMatches,d=void 0===l?L.includeMatches:l,v=o.findAllMatches,g=void 0===v?L.findAllMatches:v,y=o.minMatchCharLength,p=void 0===y?L.minMatchCharLength:y,m=o.isCaseSensitive,k=void 0===m?L.isCaseSensitive:m;return t(this,i),(r=n.call(this,e))._bitapSearch=new P(e,{location:a,threshold:u,distance:f,includeMatches:d,findAllMatches:g,minMatchCharLength:p,isCaseSensitive:k}),r}return r(i,[{key:"search",value:function(e){return this._bitapSearch.searchIn(e)}}],[{key:"type",get:function(){return"fuzzy"}},{key:"multiRegex",get:function(){return/^"(.*)"$/}},{key:"singleRegex",get:function(){return/^(.*)$/}}]),i}(N),U=function(e){a(i,e);var n=f(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){for(var t,n=0,r=[],i=this.pattern.length;(t=e.indexOf(this.pattern,n))>-1;)n=t+i,r.push([t,n-1]);var o=!!r.length;return{isMatch:o,score:o?1:0,indices:r}}}],[{key:"type",get:function(){return"include"}},{key:"multiRegex",get:function(){return/^'"(.*)"$/}},{key:"singleRegex",get:function(){return/^'(.*)$/}}]),i}(N),B=[z,U,q,W,T,J,K,V],G=B.length,H=/ +(?=([^\"]*\"[^\"]*\")*[^\"]*$)/;function Q(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return e.split("|").map((function(e){for(var n=e.trim().split(H).filter((function(e){return e&&!!e.trim()})),r=[],i=0,o=n.length;i1&&void 0!==arguments[1]?arguments[1]:{},i=r.isCaseSensitive,o=void 0===i?L.isCaseSensitive:i,c=r.includeMatches,a=void 0===c?L.includeMatches:c,s=r.minMatchCharLength,u=void 0===s?L.minMatchCharLength:s,h=r.findAllMatches,f=void 0===h?L.findAllMatches:h,l=r.location,d=void 0===l?L.location:l,v=r.threshold,g=void 0===v?L.threshold:v,y=r.distance,p=void 0===y?L.distance:y;t(this,e),this.query=null,this.options={isCaseSensitive:o,includeMatches:a,minMatchCharLength:u,findAllMatches:f,location:d,threshold:g,distance:p},this.pattern=o?n:n.toLowerCase(),this.query=Q(this.pattern,this.options)}return r(e,[{key:"searchIn",value:function(e){var t=this.query;if(!t)return{isMatch:!1,score:1};var n=this.options,r=n.includeMatches;e=n.isCaseSensitive?e:e.toLowerCase();for(var i=0,o=[],c=0,a=0,s=t.length;a1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;t(this,e),this.options=c({},L,{},r),this.options.useExtendedSearch,this._keyStore=new b(this.options.keys),this.setCollection(n,i)}return r(e,[{key:"setCollection",value:function(e,t){if(this._docs=e,t&&!(t instanceof I))throw new Error("Incorrect 'index' type");this._myIndex=t||C(this.options.keys,this._docs,{getFn:this.options.getFn})}},{key:"add",value:function(e){p(e)&&(this._docs.push(e),this._myIndex.add(e))}},{key:"remove",value:function(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:function(){return!1},t=[],n=0,r=this._docs.length;n1&&void 0!==arguments[1]?arguments[1]:{},n=t.limit,r=void 0===n?-1:n,i=this.options,o=i.includeMatches,c=i.includeScore,a=i.shouldSort,s=i.sortFn,u=i.ignoreFieldNorm,h=g(e)?g(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return he(h,{ignoreFieldNorm:u}),a&&h.sort(s),y(r)&&r>-1&&(h=h.slice(0,r)),fe(h,this._docs,{includeMatches:o,includeScore:c})}},{key:"_searchStringList",value:function(e){var t=ee(e,this.options),n=this._myIndex.records,r=[];return n.forEach((function(e){var n=e.v,i=e.i,o=e.n;if(p(n)){var c=t.searchIn(n),a=c.isMatch,s=c.score,u=c.indices;a&&r.push({item:n,idx:i,matches:[{score:s,value:n,norm:o,indices:u}]})}})),r}},{key:"_searchLogical",value:function(e){var t=this,n=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n.auto,i=void 0===r||r,o=function e(n){var r=Object.keys(n),o=ce(n);if(!o&&r.length>1&&!oe(n))return e(se(n));if(ae(n)){var c=o?n[re]:r[0],a=o?n[ie]:n[c];if(!g(a))throw new Error(k(c));var s={keyId:w(c),pattern:a};return i&&(s.searcher=ee(a,t)),s}var u={children:[],operator:r[0]};return r.forEach((function(t){var r=n[t];v(r)&&r.forEach((function(t){u.children.push(e(t))}))})),u};return oe(e)||(e=se(e)),o(e)}(e,this.options),r=this._myIndex.records,i={},o=[];return r.forEach((function(e){var r=e.$,c=e.i;if(p(r)){var a=function e(n,r,i){if(!n.children){var o=n.keyId,c=n.searcher,a=t._findMatches({key:t._keyStore.get(o),value:t._myIndex.getValueForItemAtKeyId(r,o),searcher:c});return a&&a.length?[{idx:i,item:r,matches:a}]:[]}switch(n.operator){case te:for(var s=[],u=0,h=n.children.length;u2&&void 0!==arguments[2]?arguments[2]:{},r=n.includeMatches,i=void 0===r?L.includeMatches:r,o=n.includeScore,c=void 0===o?L.includeScore:o,a=[];return i&&a.push(j),c&&a.push(E),e.map((function(e){var n=e.idx,r={item:t[n],refIndex:n};return a.length&&a.forEach((function(t){t(e,r)})),r}))}return ue.version="6.4.0",ue.createIndex=C,ue.parseIndex=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.getFn,r=void 0===n?L.getFn:n,i=e.keys,o=e.records,c=new I({getFn:r});return c.setKeys(i),c.setIndexRecords(o),c},ue.config=L,function(){Z.push.apply(Z,arguments)}(Y),ue},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).Fuse=t(); \ No newline at end of file +var e,t;e=this,t=function(){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,r=new Array(t);n0&&void 0!==arguments[0]?arguments[0]:3,t=new Map;return{get:function(n){var r=n.match(I).length;if(t.has(r))return t.get(r);var i=parseFloat((1/Math.sqrt(r)).toFixed(e));return t.set(r,i),i},clear:function(){t.clear()}}}var E=function(){function e(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=n.getFn,i=void 0===r?A.getFn:r;t(this,e),this.norm=C(3),this.getFn=i,this.isCreated=!1,this.setIndexRecords()}return r(e,[{key:"setSources",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.docs=e}},{key:"setIndexRecords",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.records=e}},{key:"setKeys",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.keys=t,this._keysMap={},t.forEach((function(t,n){e._keysMap[t.id]=n}))}},{key:"create",value:function(){var e=this;!this.isCreated&&this.docs.length&&(this.isCreated=!0,g(this.docs[0])?this.docs.forEach((function(t,n){e._addString(t,n)})):this.docs.forEach((function(t,n){e._addObject(t,n)})),this.norm.clear())}},{key:"add",value:function(e){var t=this.size();g(e)?this._addString(e,t):this._addObject(e,t)}},{key:"removeAt",value:function(e){this.records.splice(e,1);for(var t=e,n=this.size();t2&&void 0!==arguments[2]?arguments[2]:{},r=n.getFn,i=void 0===r?A.getFn:r,o=new E({getFn:i});return o.setKeys(e.map(L)),o.setSources(t),o.create(),o}function R(e,t){var n=e.matches;t.matches=[],k(n)&&n.forEach((function(e){if(k(e.indices)&&e.indices.length){var n={indices:e.indices,value:e.value};e.key&&(n.key=e.key.src),e.idx>-1&&(n.refIndex=e.idx),t.matches.push(n)}}))}function F(e,t){t.score=e.score}function P(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.errors,r=void 0===n?0:n,i=t.currentLocation,o=void 0===i?0:i,c=t.expectedLocation,a=void 0===c?0:c,s=t.distance,u=void 0===s?A.distance:s,h=t.ignoreLocation,f=void 0===h?A.ignoreLocation:h,l=r/e.length;if(f)return l;var d=Math.abs(a-o);return u?l+d/u:d?1:l}function N(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:A.minMatchCharLength,n=[],r=-1,i=-1,o=0,c=e.length;o=t&&n.push([r,i]),r=-1)}return e[o-1]&&o-r>=t&&n.push([r,o-1]),n}function D(e){for(var t={},n=0,r=e.length;n1&&void 0!==arguments[1]?arguments[1]:{},o=i.location,c=void 0===o?A.location:o,a=i.threshold,s=void 0===a?A.threshold:a,u=i.distance,h=void 0===u?A.distance:u,f=i.includeMatches,l=void 0===f?A.includeMatches:f,d=i.findAllMatches,v=void 0===d?A.findAllMatches:d,g=i.minMatchCharLength,y=void 0===g?A.minMatchCharLength:g,p=i.isCaseSensitive,m=void 0===p?A.isCaseSensitive:p,k=i.ignoreLocation,M=void 0===k?A.ignoreLocation:k;if(t(this,e),this.options={location:c,threshold:s,distance:h,includeMatches:l,findAllMatches:v,minMatchCharLength:y,isCaseSensitive:m,ignoreLocation:M},this.pattern=m?n:n.toLowerCase(),this.chunks=[],this.pattern.length){var x=function(e,t){r.chunks.push({pattern:e,alphabet:D(e),startIndex:t})},b=this.pattern.length;if(b>32){for(var S=0,_=b%32,w=b-_;S3&&void 0!==arguments[3]?arguments[3]:{},i=r.location,o=void 0===i?A.location:i,c=r.distance,a=void 0===c?A.distance:c,s=r.threshold,u=void 0===s?A.threshold:s,h=r.findAllMatches,f=void 0===h?A.findAllMatches:h,l=r.minMatchCharLength,d=void 0===l?A.minMatchCharLength:l,v=r.includeMatches,g=void 0===v?A.includeMatches:v,y=r.ignoreLocation,p=void 0===y?A.ignoreLocation:y;if(t.length>32)throw new Error(S(32));for(var m,k=t.length,M=e.length,x=Math.max(0,Math.min(o,M)),b=u,_=x,w=d>1||g,L=w?Array(M):[];(m=e.indexOf(t,_))>-1;){var O=P(t,{currentLocation:m,expectedLocation:x,distance:a,ignoreLocation:p});if(b=Math.min(O,b),_=m+k,w)for(var j=0;j=K;J-=1){var T=J-1,U=n[e.charAt(T)];if(w&&(L[T]=+!!U),W[J]=(W[J+1]<<1|1)&U,R&&(W[J]|=(I[J+1]|I[J])<<1|1|I[J+1]),W[J]&$&&(C=P(t,{errors:R,currentLocation:T,expectedLocation:x,distance:a,ignoreLocation:p}))<=b){if(b=C,(_=T)<=x)break;K=Math.max(1,2*x-_)}}var V=P(t,{errors:R+1,currentLocation:x,expectedLocation:x,distance:a,ignoreLocation:p});if(V>b)break;I=W}var B={isMatch:_>=0,score:Math.max(.001,C)};if(w){var G=N(L,d);G.length?g&&(B.indices=G):B.isMatch=!1}return B}(e,n,i,{location:c+o,distance:a,threshold:s,findAllMatches:u,minMatchCharLength:h,includeMatches:r,ignoreLocation:f}),p=y.isMatch,m=y.score,k=y.indices;p&&(g=!0),v+=m,p&&k&&(d=[].concat(l(d),l(k)))}));var y={isMatch:g,score:g?v/this.chunks.length:1};return g&&r&&(y.indices=d),y}}]),e}(),K=function(){function e(n){t(this,e),this.pattern=n}return r(e,[{key:"search",value:function(){}}],[{key:"isMultiMatch",value:function(e){return q(e,this.multiRegex)}},{key:"isSingleMatch",value:function(e){return q(e,this.singleRegex)}}]),e}();function q(e,t){var n=e.match(t);return n?n[1]:null}var W=function(e){a(i,e);var n=f(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){var t=e===this.pattern;return{isMatch:t,score:t?0:1,indices:[0,this.pattern.length-1]}}}],[{key:"type",get:function(){return"exact"}},{key:"multiRegex",get:function(){return/^="(.*)"$/}},{key:"singleRegex",get:function(){return/^=(.*)$/}}]),i}(K),J=function(e){a(i,e);var n=f(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){var t=-1===e.indexOf(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}}],[{key:"type",get:function(){return"inverse-exact"}},{key:"multiRegex",get:function(){return/^!"(.*)"$/}},{key:"singleRegex",get:function(){return/^!(.*)$/}}]),i}(K),T=function(e){a(i,e);var n=f(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){var t=e.startsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,this.pattern.length-1]}}}],[{key:"type",get:function(){return"prefix-exact"}},{key:"multiRegex",get:function(){return/^\^"(.*)"$/}},{key:"singleRegex",get:function(){return/^\^(.*)$/}}]),i}(K),U=function(e){a(i,e);var n=f(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){var t=!e.startsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}}],[{key:"type",get:function(){return"inverse-prefix-exact"}},{key:"multiRegex",get:function(){return/^!\^"(.*)"$/}},{key:"singleRegex",get:function(){return/^!\^(.*)$/}}]),i}(K),V=function(e){a(i,e);var n=f(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){var t=e.endsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[e.length-this.pattern.length,e.length-1]}}}],[{key:"type",get:function(){return"suffix-exact"}},{key:"multiRegex",get:function(){return/^"(.*)"\$$/}},{key:"singleRegex",get:function(){return/^(.*)\$$/}}]),i}(K),B=function(e){a(i,e);var n=f(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){var t=!e.endsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}}],[{key:"type",get:function(){return"inverse-suffix-exact"}},{key:"multiRegex",get:function(){return/^!"(.*)"\$$/}},{key:"singleRegex",get:function(){return/^!(.*)\$$/}}]),i}(K),G=function(e){a(i,e);var n=f(i);function i(e){var r,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},c=o.location,a=void 0===c?A.location:c,s=o.threshold,u=void 0===s?A.threshold:s,h=o.distance,f=void 0===h?A.distance:h,l=o.includeMatches,d=void 0===l?A.includeMatches:l,v=o.findAllMatches,g=void 0===v?A.findAllMatches:v,y=o.minMatchCharLength,p=void 0===y?A.minMatchCharLength:y,m=o.isCaseSensitive,k=void 0===m?A.isCaseSensitive:m;return t(this,i),(r=n.call(this,e))._bitapSearch=new z(e,{location:a,threshold:u,distance:f,includeMatches:d,findAllMatches:g,minMatchCharLength:p,isCaseSensitive:k}),r}return r(i,[{key:"search",value:function(e){return this._bitapSearch.searchIn(e)}}],[{key:"type",get:function(){return"fuzzy"}},{key:"multiRegex",get:function(){return/^"(.*)"$/}},{key:"singleRegex",get:function(){return/^(.*)$/}}]),i}(K),H=function(e){a(i,e);var n=f(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){for(var t,n=0,r=[],i=this.pattern.length;(t=e.indexOf(this.pattern,n))>-1;)n=t+i,r.push([t,n-1]);var o=!!r.length;return{isMatch:o,score:o?1:0,indices:r}}}],[{key:"type",get:function(){return"include"}},{key:"multiRegex",get:function(){return/^'"(.*)"$/}},{key:"singleRegex",get:function(){return/^'(.*)$/}}]),i}(K),Q=[W,H,T,U,B,V,J,G],X=Q.length,Y=/ +(?=([^\"]*\"[^\"]*\")*[^\"]*$)/;function Z(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return e.split("|").map((function(e){for(var n=e.trim().split(Y).filter((function(e){return e&&!!e.trim()})),r=[],i=0,o=n.length;i1&&void 0!==arguments[1]?arguments[1]:{},i=r.isCaseSensitive,o=void 0===i?A.isCaseSensitive:i,c=r.includeMatches,a=void 0===c?A.includeMatches:c,s=r.minMatchCharLength,u=void 0===s?A.minMatchCharLength:s,h=r.findAllMatches,f=void 0===h?A.findAllMatches:h,l=r.location,d=void 0===l?A.location:l,v=r.threshold,g=void 0===v?A.threshold:v,y=r.distance,p=void 0===y?A.distance:y;t(this,e),this.query=null,this.options={isCaseSensitive:o,includeMatches:a,minMatchCharLength:u,findAllMatches:f,location:d,threshold:g,distance:p},this.pattern=o?n:n.toLowerCase(),this.query=Z(this.pattern,this.options)}return r(e,[{key:"searchIn",value:function(e){var t=this.query;if(!t)return{isMatch:!1,score:1};var n=this.options,r=n.includeMatches;e=n.isCaseSensitive?e:e.toLowerCase();for(var i=0,o=[],c=0,a=0,s=t.length;a1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;t(this,e),this.options=c({},A,{},r),this.options.useExtendedSearch,this._keyStore=new w(this.options.keys),this.setCollection(n,i)}return r(e,[{key:"setCollection",value:function(e,t){if(this._docs=e,t&&!(t instanceof E))throw new Error("Incorrect 'index' type");this._myIndex=t||$(this.options.keys,this._docs,{getFn:this.options.getFn})}},{key:"add",value:function(e){k(e)&&(this._docs.push(e),this._myIndex.add(e))}},{key:"remove",value:function(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:function(){return!1},t=[],n=0,r=this._docs.length;n1&&void 0!==arguments[1]?arguments[1]:{},n=t.limit,r=void 0===n?-1:n,i=this.options,o=i.includeMatches,c=i.includeScore,a=i.shouldSort,s=i.sortFn,u=i.ignoreFieldNorm,h=g(e)?g(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return de(h,{ignoreFieldNorm:u}),a&&h.sort(s),y(r)&&r>-1&&(h=h.slice(0,r)),ve(h,this._docs,{includeMatches:o,includeScore:c})}},{key:"_searchStringList",value:function(e){var t=re(e,this.options),n=this._myIndex.records,r=[];return n.forEach((function(e){var n=e.v,i=e.i,o=e.n;if(k(n)){var c=t.searchIn(n),a=c.isMatch,s=c.score,u=c.indices;a&&r.push({item:n,idx:i,matches:[{score:s,value:n,norm:o,indices:u}]})}})),r}},{key:"_searchLogical",value:function(e){var t=this,n=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n.auto,i=void 0===r||r,o=function e(n){var r=Object.keys(n),o=ue(n);if(!o&&r.length>1&&!se(n))return e(fe(n));if(he(n)){var c=o?n[ce]:r[0],a=o?n[ae]:n[c];if(!g(a))throw new Error(b(c));var s={keyId:j(c),pattern:a};return i&&(s.searcher=re(a,t)),s}var u={children:[],operator:r[0]};return r.forEach((function(t){var r=n[t];v(r)&&r.forEach((function(t){u.children.push(e(t))}))})),u};return se(e)||(e=fe(e)),o(e)}(e,this.options),r=this._myIndex.records,i={},o=[];return r.forEach((function(e){var r=e.$,c=e.i;if(k(r)){var a=function e(n,r,i){if(!n.children){var o=n.keyId,c=n.searcher,a=t._findMatches({key:t._keyStore.get(o),value:t._myIndex.getValueForItemAtKeyId(r,o),searcher:c});return a&&a.length?[{idx:i,item:r,matches:a}]:[]}switch(n.operator){case ie:for(var s=[],u=0,h=n.children.length;u2&&void 0!==arguments[2]?arguments[2]:{},r=n.includeMatches,i=void 0===r?A.includeMatches:r,o=n.includeScore,c=void 0===o?A.includeScore:o,a=[];return i&&a.push(R),c&&a.push(F),e.map((function(e){var n=e.idx,r={item:t[n],refIndex:n};return a.length&&a.forEach((function(t){t(e,r)})),r}))}return le.version="6.4.1",le.createIndex=$,le.parseIndex=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.getFn,r=void 0===n?A.getFn:n,i=e.keys,o=e.records,c=new E({getFn:r});return c.setKeys(i),c.setIndexRecords(o),c},le.config=A,function(){ne.push.apply(ne,arguments)}(te),le},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).Fuse=t(); \ No newline at end of file diff --git a/package.json b/package.json index 343094b1b..f3b0b03c9 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "files": [ "dist" ], - "version": "6.4.0", + "version": "6.4.1", "description": "Lightweight fuzzy-search", "license": "Apache-2.0", "repository": {