UNPKG

fuzzball

Version:

Fuzzy string matching algorithms and utilities, port of the TheFuzz Python library.

2 lines (1 loc) 20.9 kB
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self).fuzzball=r()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},r={exports:{}},t={exports:{}};!function(r,t){(function(){var e,t,o,n,s,i,a,c,l,p,u,f,d,h,m;o=Math.floor,p=Math.min,t=function(e,r){return e<r?-1:e>r?1:0},l=function(e,r,n,s,i){var a;if(null==n&&(n=0),null==i&&(i=t),n<0)throw new Error("lo must be non-negative");for(null==s&&(s=e.length);n<s;)i(r,e[a=o((n+s)/2)])<0?s=a:n=a+1;return[].splice.apply(e,[n,n-n].concat(r)),r},i=function(e,r,o){return null==o&&(o=t),e.push(r),h(e,0,e.length-1,o)},s=function(e,r){var o,n;return null==r&&(r=t),o=e.pop(),e.length?(n=e[0],e[0]=o,m(e,0,r)):n=o,n},c=function(e,r,o){var n;return null==o&&(o=t),n=e[0],e[0]=r,m(e,0,o),n},a=function(e,r,o){var n;return null==o&&(o=t),e.length&&o(e[0],r)<0&&(r=(n=[e[0],r])[0],e[0]=n[1],m(e,0,o)),r},n=function(e,r){var n,s,i,a,c,l;for(null==r&&(r=t),c=[],s=0,i=(a=function(){l=[];for(var r=0,t=o(e.length/2);0<=t?r<t:r>t;0<=t?r++:r--)l.push(r);return l}.apply(this).reverse()).length;s<i;s++)n=a[s],c.push(m(e,n,r));return c},d=function(e,r,o){var n;if(null==o&&(o=t),-1!==(n=e.indexOf(r)))return h(e,0,n,o),m(e,n,o)},u=function(e,r,o){var s,i,c,l,p;if(null==o&&(o=t),!(i=e.slice(0,r)).length)return i;for(n(i,o),c=0,l=(p=e.slice(r)).length;c<l;c++)s=p[c],a(i,s,o);return i.sort(o).reverse()},f=function(e,r,o){var i,a,c,u,f,d,h,m,g;if(null==o&&(o=t),10*r<=e.length){if(!(c=e.slice(0,r).sort(o)).length)return c;for(a=c[c.length-1],u=0,d=(h=e.slice(r)).length;u<d;u++)o(i=h[u],a)<0&&(l(c,i,0,null,o),c.pop(),a=c[c.length-1]);return c}for(n(e,o),g=[],f=0,m=p(r,e.length);0<=m?f<m:f>m;0<=m?++f:--f)g.push(s(e,o));return g},h=function(e,r,o,n){var s,i,a;for(null==n&&(n=t),s=e[o];o>r&&n(s,i=e[a=o-1>>1])<0;)e[o]=i,o=a;return e[o]=s},m=function(e,r,o){var n,s,i,a,c;for(null==o&&(o=t),s=e.length,c=r,i=e[r],n=2*r+1;n<s;)(a=n+1)<s&&!(o(e[n],e[a])<0)&&(n=a),e[r]=e[n],n=2*(r=n)+1;return e[r]=i,h(e,c,r,o)},e=function(){function Heap(e){this.cmp=null!=e?e:t,this.nodes=[]}return Heap.push=i,Heap.pop=s,Heap.replace=c,Heap.pushpop=a,Heap.heapify=n,Heap.updateItem=d,Heap.nlargest=u,Heap.nsmallest=f,Heap.prototype.push=function(e){return i(this.nodes,e,this.cmp)},Heap.prototype.pop=function(){return s(this.nodes,this.cmp)},Heap.prototype.peek=function(){return this.nodes[0]},Heap.prototype.contains=function(e){return-1!==this.nodes.indexOf(e)},Heap.prototype.replace=function(e){return c(this.nodes,e,this.cmp)},Heap.prototype.pushpop=function(e){return a(this.nodes,e,this.cmp)},Heap.prototype.heapify=function(){return n(this.nodes,this.cmp)},Heap.prototype.updateItem=function(e){return d(this.nodes,e,this.cmp)},Heap.prototype.clear=function(){return this.nodes=[]},Heap.prototype.empty=function(){return 0===this.nodes.length},Heap.prototype.size=function(){return this.nodes.length},Heap.prototype.clone=function(){var e;return(e=new Heap).nodes=this.nodes.slice(0),e},Heap.prototype.toArray=function(){return this.nodes.slice(0)},Heap.prototype.insert=Heap.prototype.push,Heap.prototype.top=Heap.prototype.peek,Heap.prototype.front=Heap.prototype.peek,Heap.prototype.has=Heap.prototype.contains,Heap.prototype.copy=Heap.prototype.clone,Heap}(),r.exports=e}).call(e)}(t);var o=t.exports;var n,s={_intersect:function _intersect(e,r){if(!e||!r||0===e.length||0===r.length)return[];if(e.length<100&&r.length<100)return e.filter((e=>r.includes(e)));const t=new Set(r);return e.filter((e=>t.has(e)))},_intersectWith:function _intersectWith(e,r,t){return e&&r&&0!==e.length&&0!==r.length?e.filter((e=>r.some((r=>t(e,r))))):[]},_difference:function _difference(e,r){if(!e)return[];if(!r||0===r.length)return e.slice();if(e.length<100&&r.length<100)return e.filter((e=>!r.includes(e)));const t=new Set(r);return e.filter((e=>!t.has(e)))},_differenceWith:function _differenceWith(e,r,t){return e?r&&0!==r.length?e.filter((e=>!r.some((r=>t(e,r))))):e.slice():[]},_uniq:function _uniq(e){return e&&0!==e.length?1===e.length?e.slice():[...new Set(e)]:[]},_uniqWith:function _uniqWith(e,r){if(!e||0===e.length)return[];if(1===e.length)return e.slice();const t=[];e:for(let o=0;o<e.length;o++){const n=e[o];for(let e=0;e<t.length;e++)if(r(n,t[e]))continue e;t.push(n)}return t},_partialRight:function _partialRight(e){const r=Array.prototype.slice.call(arguments,1);return function(){const t=Array.prototype.slice.call(arguments);return e.apply(this,t.concat(r))}},_forEach:function _forEach(e,r){if(e)if(Array.isArray(e))for(let t=0;t<e.length;t++)r(e[t],t);else{const t=Object.keys(e);for(let o=0;o<t.length;o++)r(e[t[o]],t[o])}},_isArray:Array.isArray};try{n="undefined"!=typeof Intl&&void 0!==Intl.Collator?Intl.Collator("generic",{sensitivity:"base"}):null}catch(e){void 0!==typeof console&&console.warn("Collator could not be initialized and wouldn't be used")}var i,a=function leven(e,r,t){var o=[],s=[],i=t&&n&&t.useCollator,a=1;if(t&&t.subcost&&"number"==typeof t.subcost&&(a=t.subcost),e===r)return 0;var c,l,p,u,f=Array.from(e),d=Array.from(r),h=f.length,m=d.length;if(0===h)return m;if(0===m)return h;for(var g=0,y=0;g<h;)s[g]=f[g].codePointAt(0),o[g]=++g;if(i)for(;y<m;)for(c=d[y].codePointAt(0),p=y++,l=y,g=0;g<h;g++)u=0===n.compare(String.fromCodePoint(c),String.fromCodePoint(s[g]))?p:p+a,p=o[g],l=o[g]=p>l?u>l?l+1:u:u>p?p+1:u;else for(;y<m;)for(c=d[y].codePointAt(0),p=y++,l=y,g=0;g<h;g++)u=c===s[g]?p:p+a,p=o[g],l=o[g]=p>l?u>l?l+1:u:u>p?p+1:u;return l};try{i="undefined"!=typeof Intl&&void 0!==Intl.Collator?Intl.Collator("generic",{sensitivity:"base"}):null}catch(e){void 0!==typeof console&&console.warn("Collator could not be initialized and wouldn't be used")}var c,l=function leven(e,r,t,o){var n=[],s=[],a=t&&i&&t.useCollator,c=1;if(t&&t.subcost&&"number"==typeof t.subcost&&(c=t.subcost),e===r)return 0;var l=e.length,p=r.length;if(0===l)return p;if(0===p)return l;if(t&&t.wildcards&&"string"==typeof t.wildcards&&t.wildcards.length>0){var u,f,d,h,m,g;if(!1===t.full_process&&!0!==t.processed){f=(u=t.wildcards[0]).charCodeAt(0);var y="["+function escapeRegExp(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}(t.wildcards)+"]";if((e=e.replace(new RegExp(y,"g"),u))===(r=r.replace(new RegExp(y,"g"),u)))return 0}else f=(u=t.wildcards[0].toLowerCase()).charCodeAt(0);for(var v=0,_=0;v<l;)s[v]=e.charCodeAt(v),n[v]=++v;if(a)for(;_<p;)for(d=r.charCodeAt(_),m=_++,h=_,v=0;v<l;v++)g=0===i.compare(String.fromCharCode(d),String.fromCharCode(s[v]))||d===f||s[v]===f?m:m+c,m=n[v],h=n[v]=m>h?g>h?h+1:g:g>m?m+1:g;else for(;_<p;)for(d=r.charCodeAt(_),m=_++,h=_,v=0;v<l;v++)g=d===s[v]||d===f||s[v]===f?m:m+c,m=n[v],h=n[v]=m>h?g>h?h+1:g:g>m?m+1:g;return h}return o(e,r,t)};try{c="undefined"!=typeof Intl&&void 0!==Intl.Collator?Intl.Collator("generic",{sensitivity:"base"}):null}catch(e){void 0!==typeof console&&console.warn("Collator could not be initialized and wouldn't be used")}var p=function leven(e,r,t){var o=[],n=[],s=t&&c&&t.useCollator,i=1;if(t&&t.subcost&&"number"==typeof t.subcost&&(i=t.subcost),e===r)return 0;var a,l,p,u,f=e.length,d=r.length;if(0===f)return d;if(0===d)return f;for(var h=0,m=0;h<f;)n[h]=e.charCodeAt(h),o[h]=++h;if(s)for(;m<d;)for(a=r.charCodeAt(m),p=m++,l=m,h=0;h<f;h++)u=0===c.compare(String.fromCharCode(a),String.fromCharCode(n[h]))?p:p+i,p=o[h],l=o[h]=p>l?u>l?l+1:u:u>p?p+1:u;else for(;m<d;)for(a=r.charCodeAt(m),p=m++,l=m,h=0;h<f;h++)u=a===n[h]?p:p+i,p=o[h],l=o[h]=p>l?u>l?l+1:u:u>p?p+1:u;return l};!function(e,r){if(!e.setImmediate){var t,o=1,n={},s=!1,i=e.document,a=Object.getPrototypeOf&&Object.getPrototypeOf(e);a=a&&a.setTimeout?a:e,"[object process]"==={}.toString.call(e.process)?function installNextTickImplementation(){t=function(e){process.nextTick((function(){runIfPresent(e)}))}}():!function canUsePostMessage(){if(e.postMessage&&!e.importScripts){var r=!0,t=e.onmessage;return e.onmessage=function(){r=!1},e.postMessage("","*"),e.onmessage=t,r}}()?e.MessageChannel?function installMessageChannelImplementation(){var e=new MessageChannel;e.port1.onmessage=function(e){runIfPresent(e.data)},t=function(r){e.port2.postMessage(r)}}():i&&"onreadystatechange"in i.createElement("script")?function installReadyStateChangeImplementation(){var e=i.documentElement;t=function(r){var t=i.createElement("script");t.onreadystatechange=function(){runIfPresent(r),t.onreadystatechange=null,e.removeChild(t),t=null},e.appendChild(t)}}():function installSetTimeoutImplementation(){t=function(e){setTimeout(runIfPresent,0,e)}}():function installPostMessageImplementation(){var r="setImmediate$"+Math.random()+"$",onGlobalMessage=function(t){t.source===e&&"string"==typeof t.data&&0===t.data.indexOf(r)&&runIfPresent(+t.data.slice(r.length))};e.addEventListener?e.addEventListener("message",onGlobalMessage,!1):e.attachEvent("onmessage",onGlobalMessage),t=function(t){e.postMessage(r+t,"*")}}(),a.setImmediate=function setImmediate(e){"function"!=typeof e&&(e=new Function(""+e));for(var r=new Array(arguments.length-1),s=0;s<r.length;s++)r[s]=arguments[s+1];var i={callback:e,args:r};return n[o]=i,t(o),o++},a.clearImmediate=clearImmediate}function clearImmediate(e){delete n[e]}function runIfPresent(e){if(s)setTimeout(runIfPresent,0,e);else{var r=n[e];if(r){s=!0;try{!function run(e){var r=e.callback,t=e.args;switch(t.length){case 0:r();break;case 1:r(t[0]);break;case 2:r(t[0],t[1]);break;case 3:r(t[0],t[1],t[2]);break;default:r.apply(void 0,t)}}(r)}finally{clearImmediate(e),s=!1}}}}}("undefined"==typeof self?e:self);var u={exports:{}};return function(e){e.exports=function(r,t,o,n){return(e={}).dedupe=function dedupe(e,s){var i,a=r(s);if(!t(e)&&"object"!=typeof e)throw new Error("contains_dupes must be an array or object");if(0===Object.keys(e).length)return void 0!==typeof console&&console.warn("contains_dupes is empty"),[];a.limit&&(void 0!==typeof console&&console.warn("options.limit will be ignored in dedupe"),a.limit=0),a.cutoff&&"number"==typeof a.cutoff||(void 0!==typeof console&&console.warn("Using default cutoff of 70"),a.cutoff=70),a.scorer||(a.scorer=o,void 0!==typeof console&&console.log("Using default scorer 'ratio' for dedupe")),i=a.processor&&"function"==typeof a.processor?a.processor:function(e){return e};var c={};for(var l in e){var p=i(e[l]);if("string"!=typeof p&&p instanceof String==!1)throw new Error("Each processed item in dedupe must be a string.");var u=n(p,e,a);a.returnObjects?(1===u.length||(u=u.sort((function(e,r){var t=i(e.choice),o=i(r.choice),n=t.length,s=o.length;return n===s?t<o?-1:1:s-n}))),a.keepmap?c[i(u[0].choice)]={item:u[0].choice,key:u[0].key,matches:u}:c[i(u[0].choice)]={item:u[0].choice,key:u[0].key}):(1===u.length||(u=u.sort((function(e,r){var t=i(e[0]),o=i(r[0]),n=t.length,s=o.length;return n===s?t<o?-1:1:s-n}))),a.keepmap?c[i(u[0][0])]=[u[0][0],u[0][2],u]:c[i(u[0][0])]=[u[0][0],u[0][2]])}var f=[];for(var d in c)f.push(c[d]);return f},e}}(u),function(){var e=o,t=s._intersect,n=s._difference,i=a,c=l,f=p,d=function(e,r,t){var o={},n=l,s=p;function escapeRegExp(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function validate(e){return("string"==typeof e||e instanceof String)&&e.length>0}o.validate=validate,o.process_and_sort=function process_and_sort(e){return validate(e)?e.match(/\S+/g).sort().join(" ").trim():""},o.tokenize=function unique_tokens(o,i){if(i&&i.wildcards&&r&&t){var a=t(n,i,s);return r(o.match(/\S+/g),(function(e,r){return 0===a(e,r)}))}return e(o.match(/\S+/g))};const i=/[^\p{L}\p{N}]/gu;return o.full_process=function full_process(e,r){if(!(e instanceof String)&&"string"!=typeof e)return"";var t;if(r&&"object"==typeof r&&r.wildcards&&"string"==typeof r.wildcards&&r.wildcards.length>0){var o=r.wildcards.toLowerCase();if(e=e.toLowerCase(),r.force_ascii){var n="[^\0 -|"+escapeRegExp(o)+"]";e=e.replace(new RegExp(n,"g"),"");var s="["+escapeRegExp(o)+"]",a=o[0];e=e.replace(new RegExp(s,"g"),a);var c="[^A-Za-z0-9"+escapeRegExp(o)+"]";t=(e=(e=e.replace(new RegExp(c,"g")," ")).replace(/_/g," ")).trim()}else{var l="[^\\p{L}\\p{N}|"+escapeRegExp(o)+"]";e=e.replace(new RegExp(l,"gu")," "),s="["+escapeRegExp(o)+"]",a=o[0],t=(e=e.replace(new RegExp(s,"g"),a)).trim()}}else t=r&&(r.force_ascii||!0===r)?(e=e.replace(/[^\x00-\x7F]/g,"")).replace(/\W|_/g," ").toLowerCase().trim():e.replace(i," ").toLowerCase().trim();return r&&r.collapseWhitespace&&(t=t.replace(/\s+/g," ")),t},o.clone_and_set_option_defaults=function(e){if(e&&e.isAClone)return e;var r={isAClone:!0};if(e){var t,o=Object.keys(e);for(t=0;t<o.length;t++)r[o[t]]=e[o[t]]}return!1!==r.full_process&&(r.full_process=!0),!0!==r.force_ascii&&(r.force_ascii=!1),!1!==r.normalize&&!0===r.astral&&(r.normalize=!0),!1!==r.collapseWhitespace&&(r.collapseWhitespace=!0),r},o.isCustomFunc=function(e){return"function"!=typeof e||"token_set_ratio"!==e.name&&"partial_token_set_ratio"!==e.name&&"token_sort_ratio"!==e.name&&"partial_token_sort_ratio"!==e.name&&"QRatio"!==e.name&&"WRatio"!==e.name&&"distance"!==e.name&&"partial_ratio"!==e.name},o}(s._uniq),h=d.validate,m=d.process_and_sort,g=d.tokenize,y=d.full_process,v=d.clone_and_set_option_defaults,_=d.isCustomFunc;void 0===Array.isArray&&(Array.isArray=function(e){return"[object Array]"===Object.prototype.toString.call(e)});var b,w,k,C,x=u.exports(v,Array.isArray,QRatio,extract).dedupe;function QRatio(e,r,t){var o=v(t);return e=o.normalize?e.normalize():e,r=o.normalize?r.normalize():r,e=o.full_process?y(e,o):e,r=o.full_process?y(r,o):r,h(e)&&h(r)?_ratio(e,r,o):0}function extract(r,t,o){var n,s=v(o),i=!1;if(t&&t.length&&Array.isArray(t))n=t.length,i=!0;else{if(!(t instanceof Object))throw new Error("Invalid choices");n=Object.keys(t).length}if(!t||0===n)return void 0!==typeof console&&console.warn("No choices"),[];if(s.processor&&"function"!=typeof s.processor)throw new Error("Invalid Processor");if(s.processor||(s.processor=function(e){return e}),s.scorer&&"function"!=typeof s.scorer)throw new Error("Invalid Scorer");s.scorer||(s.scorer=QRatio);var a=_(s.scorer);s.cutoff&&"number"==typeof s.cutoff||(s.cutoff=-1);var pre_processor=function(e,r){return e};s.full_process&&(pre_processor=y,a||(s.processed=!0));var c=!1;a||(s.astral&&s.normalize&&(s.normalize=!1,String.prototype.normalize?(c=!0,r=r.normalize()):void 0!==typeof console&&console.warn("Normalization not supported in your environment")),r=pre_processor(r,s),s.full_process=!1,0===r.length&&void 0!==typeof console&&console.warn("Processed query is empty string"));var l,p,u,f,d,h=[],b=!1,w=!1,k=!1;if("token_sort_ratio"===s.scorer.name||"partial_token_sort_ratio"===s.scorer.name){var C=m(r);w=!0}else if("token_set_ratio"===s.scorer.name||"partial_token_set_ratio"===s.scorer.name){var x=g(r);k=!0}for(var z in s.returnObjects?(f=function(e,r){return e.score-r.score},d=function(e,r){return r.score-e.score}):(f=function(e,r){return e[1]-r[1]},d=function(e,r){return r[1]-e[1]}),t)(i||t.hasOwnProperty(z))&&(s.tokens=void 0,s.proc_sorted=!1,w?(s.proc_sorted=!0,t[z]&&t[z].proc_sorted?p=t[z].proc_sorted:(p=pre_processor(c?s.processor(t[z]).normalize():s.processor(t[z]),s),p=m(p)),u=s.scorer(C,p,s)):k?(p="x",t[z]&&t[z].tokens?(s.tokens=[x,t[z].tokens],s.trySimple&&(p=pre_processor(s.processor(t[z]),s))):(p=pre_processor(c?s.processor(t[z]).normalize():s.processor(t[z]),s),s.tokens=[x,g(p)]),u=s.scorer(r,p,s)):a?(p=s.processor(t[z]),u=s.scorer(r,p,s)):("string"==typeof(p=pre_processor(c?s.processor(t[z]).normalize():s.processor(t[z]),s))&&0!==p.length||(b=!0),u=s.scorer(r,p,s)),l=i?parseInt(z):z,u>s.cutoff&&(s.returnObjects?h.push({choice:t[z],score:u,key:l}):h.push([t[z],u,l])));return b&&void 0!==typeof console&&console.log("One or more choices were empty. (post-processing if applied)"),s.limit&&"number"==typeof s.limit&&s.limit>0&&s.limit<n&&!s.unsorted?h=e.nlargest(h,s.limit,f):s.unsorted||(h=h.sort(d)),h}function extractAsync(r,t,o,n){var s,i,a=v(o);"object"==typeof o.abortController&&(s=o.abortController),"object"==typeof o.cancelToken&&(i=o.cancelToken);var c=256;"number"==typeof a.asyncLoopOffset&&(c=a.asyncLoopOffset<1?1:a.asyncLoopOffset);var l,p=!1;if(t&&t.length&&Array.isArray(t))l=t.length,p=!0;else{if(!(t instanceof Object))return void n(new Error("Invalid choices"));l=Object.keys(t).length}if(!t||0===l)return void 0!==typeof console&&console.warn("No choices"),void n(null,[]);if(a.processor&&"function"!=typeof a.processor)n(new Error("Invalid Processor"));else if(a.processor||(a.processor=function(e){return e}),a.scorer&&"function"!=typeof a.scorer)n(new Error("Invalid Scorer"));else{a.scorer||(a.scorer=QRatio);var u=_(a.scorer);a.cutoff&&"number"==typeof a.cutoff||(a.cutoff=-1);var pre_processor=function(e,r){return e};a.full_process&&(pre_processor=y,u||(a.processed=!0));var f=!1;u||(a.astral&&a.normalize&&(a.normalize=!1,String.prototype.normalize?(f=!0,r=r.normalize()):void 0!==typeof console&&console.warn("Normalization not supported in your environment")),r=pre_processor(r,a),a.full_process=!1,0===r.length&&void 0!==typeof console&&console.warn("Processed query is empty string"));var d,h,b,w,k,C=[],x=!1,z=!1,A=!1;if("token_sort_ratio"===a.scorer.name||"partial_token_sort_ratio"===a.scorer.name){var I=m(r);z=!0}else if("token_set_ratio"===a.scorer.name||"partial_token_set_ratio"===a.scorer.name){var E=g(r);A=!0}a.returnObjects?(w=function(e,r){return e.score-r.score},k=function(e,r){return r.score-e.score}):(w=function(e,r){return e[1]-r[1]},k=function(e,r){return r[1]-e[1]});var O=Object.keys(t);p?searchLoop(0):searchLoop(O[0],0)}function searchLoop(o,y){(p||t.hasOwnProperty(o))&&(a.tokens=void 0,a.proc_sorted=!1,z?(a.proc_sorted=!0,t[o].proc_sorted?h=t[o].proc_sorted:(h=pre_processor(f?a.processor(t[o]).normalize():a.processor(t[o]),a),h=m(h)),b=a.scorer(I,h,a)):A?(h="x",t[o].tokens?(a.tokens=[E,t[o].tokens],a.trySimple&&(h=pre_processor(a.processor(t[o]),a))):(h=pre_processor(f?a.processor(t[o]).normalize():a.processor(t[o]),a),a.tokens=[E,g(h)]),b=a.scorer(r,h,a)):u?(h=a.processor(t[o]),b=a.scorer(r,h,a)):("string"==typeof(h=pre_processor(f?a.processor(t[o]).normalize():a.processor(t[o]),a))&&0!==h.length||(x=!0),b=a.scorer(r,h,a)),d=p?parseInt(o):o,b>a.cutoff&&(a.returnObjects?C.push({choice:t[o],score:b,key:d}):C.push([t[o],b,d]))),s&&!0===s.signal.aborted?n(new Error("aborted")):i&&!0===i.canceled?n(new Error("canceled")):p&&o<t.length-1?o%c==0?setImmediate((function(){searchLoop(o+1)})):searchLoop(o+1):y<O.length-1?y%c==0?setImmediate((function(){searchLoop(O[y+1],y+1)})):searchLoop(O[y+1],y+1):(x&&void 0!==typeof console&&console.log("One or more choices were empty. (post-processing if applied)"),a.limit&&"number"==typeof a.limit&&a.limit>0&&a.limit<l&&!a.unsorted?C=e.nlargest(C,a.limit,w):a.unsorted||(C=C.sort(k)),n(null,C))}}function _ratio(e,r,t){return h(e)&&h(r)?(void 0===t.subcost&&(t.subcost=2),t.astral?(o=i(e,r,t),n=Array.from(e).length+Array.from(r).length):t.wildcards?(o=c(e,r,t,f),n=e.length+r.length):(o=f(e,r,t),n=e.length+r.length),Math.round((n-o)/n*100)):0;var o,n}Object.keys||(Object.keys=(b=Object.prototype.hasOwnProperty,w=!{toString:null}.propertyIsEnumerable("toString"),C=(k=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"]).length,function(e){if("object"!=typeof e&&("function"!=typeof e||null===e))throw new TypeError("Object.keys called on non-object");var r,t,o=[];for(r in e)b.call(e,r)&&o.push(r);if(w)for(t=0;t<C;t++)b.call(e,k[t])&&o.push(k[t]);return o}));var z=void 0;"undefined"!=typeof Promise&&(z=function(e,r,t){return new Promise((function(o,n){extractAsync(e,r,t,(function(e,r){e?n(e):o(r)}))}))});var A={distance:function distance(e,r,t){var o=v(t);return e=o.normalize?e.normalize():e,r=o.normalize?r.normalize():r,e=o.full_process?y(e,o):e,r=o.full_process?y(r,o):r,void 0===o.subcost&&(o.subcost=1),o.astral?i(e,r,o):c(e,r,o,f)},ratio:QRatio,token_set_ratio:function token_set_ratio(e,r,o){var s=v(o);return e=s.normalize?e.normalize():e,r=s.normalize?r.normalize():r,e=s.full_process?y(e,s):e,r=s.full_process?y(r,s):r,h(e)&&h(r)?function _token_set(e,r,o){if(o.tokens)s=o.tokens[0],i=o.tokens[1];else var s=g(e),i=g(r);var a=t(s,i),c=n(s,i),l=n(i,s),p=a.sort().join(" "),u=c.sort().join(" "),f=l.sort().join(" "),d=p+" "+u,h=p+" "+f;p=p.trim(),d=d.trim(),h=h.trim();var m=_ratio,y=[m(p,d,o),m(p,h,o),m(d,h,o)];o.trySimple&&y.push(m(e,r,o));return Math.max.apply(null,y)}(e,r,s):0},token_sort_ratio:function token_sort_ratio(e,r,t){var o=v(t);return e=o.normalize?e.normalize():e,r=o.normalize?r.normalize():r,e=o.full_process?y(e,o):e,r=o.full_process?y(r,o):r,h(e)&&h(r)?(o.proc_sorted||(e=m(e),r=m(r)),_ratio(e,r,o)):0},full_process:y,extract:extract,extractAsync:extractAsync,extractAsPromised:z,process_and_sort:m,unique_tokens:g,dedupe:x};r.exports=A}(),r.exports}));