@leeoniya/ufuzzy
Advanced tools
Comparing version 0.9.0 to 0.9.1
/** | ||
* Copyright (c) 2022, Leon Sorokin | ||
* Copyright (c) 2023, Leon Sorokin | ||
* All rights reserved. (MIT Licensed) | ||
@@ -7,3 +7,3 @@ * | ||
* A tiny, efficient fuzzy matcher that doesn't suck | ||
* https://github.com/leeoniya/uFuzzy (v0.9.0) | ||
* https://github.com/leeoniya/uFuzzy (v0.9.1) | ||
*/ | ||
@@ -17,11 +17,9 @@ | ||
const INTRA_BOUND = '[A-Za-z][0-9]|[0-9][A-Za-z]|[a-z][A-Z]'; | ||
const OPTS = { | ||
// term segmentation & punct/whitespace merging | ||
interSplit: '[^A-Za-z0-9]+', | ||
intraSplit: INTRA_BOUND, | ||
intraSplit: '[a-z][A-Z]', | ||
// intra bounds that will be used to increase lft1/rgt1 info counters | ||
intraBound: INTRA_BOUND, | ||
intraBound: '[A-Za-z][0-9]|[0-9][A-Za-z]|[a-z][A-Z]', | ||
@@ -28,0 +26,0 @@ // inter-bounds mode |
@@ -70,3 +70,3 @@ declare class uFuzzy { | ||
interSplit?: PartialRegExp; // '[^A-Za-z0-9]+' | ||
intraSplit?: PartialRegExp | null; // '[A-Za-z][0-9]|[0-9][A-Za-z]|[a-z][A-Z]' | ||
intraSplit?: PartialRegExp | null; // '[a-z][A-Z]' | ||
@@ -73,0 +73,0 @@ /** intra bounds that will be used to increase lft1/rgt1 info counters */ |
/** | ||
* Copyright (c) 2022, Leon Sorokin | ||
* Copyright (c) 2023, Leon Sorokin | ||
* All rights reserved. (MIT Licensed) | ||
@@ -7,3 +7,3 @@ * | ||
* A tiny, efficient fuzzy matcher that doesn't suck | ||
* https://github.com/leeoniya/uFuzzy (v0.9.0) | ||
* https://github.com/leeoniya/uFuzzy (v0.9.1) | ||
*/ | ||
@@ -15,11 +15,9 @@ | ||
const INTRA_BOUND = '[A-Za-z][0-9]|[0-9][A-Za-z]|[a-z][A-Z]'; | ||
const OPTS = { | ||
// term segmentation & punct/whitespace merging | ||
interSplit: '[^A-Za-z0-9]+', | ||
intraSplit: INTRA_BOUND, | ||
intraSplit: '[a-z][A-Z]', | ||
// intra bounds that will be used to increase lft1/rgt1 info counters | ||
intraBound: INTRA_BOUND, | ||
intraBound: '[A-Za-z][0-9]|[0-9][A-Za-z]|[a-z][A-Z]', | ||
@@ -26,0 +24,0 @@ // inter-bounds mode |
/** | ||
* Copyright (c) 2022, Leon Sorokin | ||
* Copyright (c) 2023, Leon Sorokin | ||
* All rights reserved. (MIT Licensed) | ||
@@ -7,3 +7,3 @@ * | ||
* A tiny, efficient fuzzy matcher that doesn't suck | ||
* https://github.com/leeoniya/uFuzzy (v0.9.0) | ||
* https://github.com/leeoniya/uFuzzy (v0.9.1) | ||
*/ | ||
@@ -18,11 +18,9 @@ | ||
const INTRA_BOUND = '[A-Za-z][0-9]|[0-9][A-Za-z]|[a-z][A-Z]'; | ||
const OPTS = { | ||
// term segmentation & punct/whitespace merging | ||
interSplit: '[^A-Za-z0-9]+', | ||
intraSplit: INTRA_BOUND, | ||
intraSplit: '[a-z][A-Z]', | ||
// intra bounds that will be used to increase lft1/rgt1 info counters | ||
intraBound: INTRA_BOUND, | ||
intraBound: '[A-Za-z][0-9]|[0-9][A-Za-z]|[a-z][A-Z]', | ||
@@ -29,0 +27,0 @@ // inter-bounds mode |
@@ -1,2 +0,2 @@ | ||
/*! https://github.com/leeoniya/uFuzzy (v0.9.0) */ | ||
var uFuzzy=function(){"use strict";const t=new Intl.Collator("en").compare,e=1/0,r="[A-Za-z][0-9]|[0-9][A-Za-z]|[a-z][A-Z]",n={interSplit:"[^A-Za-z0-9]+",intraSplit:r,intraBound:r,interLft:0,interRgt:0,interChars:".",interIns:e,intraChars:"[a-z\\d]",intraIns:0,intraMode:0,intraSlice:[1,e],intraSub:0,intraTrn:0,intraDel:0,intraFilt:()=>!0,sort:(e,r)=>{let{idx:n,chars:i,terms:l,interLft2:s,interLft1:a,start:g,intraIns:f,interIns:h}=e;return n.map(((t,e)=>e)).sort(((e,c)=>i[c]-i[e]||f[e]-f[c]||l[c]+s[c]+.5*a[c]-(l[e]+s[e]+.5*a[e])||h[e]-h[c]||g[e]-g[c]||t(r[n[e]],r[n[c]])))}},i=(t,r)=>0==r?"":1==r?t+"??":r==e?t+"*?":t+`{0,${r}}?`,l="(?:\\b|_)";function s(t){t=Object.assign({},n,t);const{interLft:e,interRgt:r,intraMode:s,intraSlice:a,intraIns:g,intraSub:f,intraTrn:h,intraDel:c,intraSplit:u,interSplit:o,intraBound:p,intraChars:b}=t;let{intraRules:m}=t;null==m&&(m=t=>{let e=n.intraSlice,r=0,i=0,l=0,s=0,u=t.length;return u>4?(e=a,r=g,i=f,l=h,s=c):3>u||(l=1,4==u&&(r=1)),{intraSlice:e,intraIns:r,intraSub:i,intraTrn:l,intraDel:s}});let I=!!u,R=RegExp(u,"g"),S=RegExp(o,"g"),x=RegExp("^"+o+"|"+o+"$","g");const d=t=>(t=t.replace(x,""),I&&(t=t.replace(R,(t=>t[0]+" "+t[1]))),t.split(S)),A=(n,a=0)=>{let f,h=d(n);if(1==s)f=h.map((t=>{let{intraSlice:e,intraIns:r,intraSub:n,intraTrn:l,intraDel:s}=m(t);if(r+n+l+s==0)return t;let[a,g]=e,f=t.slice(0,a),h=t.slice(g),c=t.slice(a,g),u=c.length,o=[];if(n)for(let t=0;u>t;t++)o.push(f+c.slice(0,t)+b+c.slice(t+1)+h);if(l)for(let t=0;u-1>t;t++)c[t]!=c[t+1]&&o.push(f+c.slice(0,t)+c[t+1]+c[t]+c.slice(t+2)+h);if(s)for(let t=0;u>t;t++)o.push(f+c.slice(0,t+1)+"?"+c.slice(t+1)+h);if(r){let t=i(b,1);for(let e=0;u+1>e;e++)o.push(f+c.slice(0,e)+t+c.slice(e)+h)}return"(?:"+t+"|"+o.join("|")+")"}));else{let t=i(b,g);2==a&&g>0&&(t=")("+t+")("),f=h.map((e=>e.split("").join(t)))}let c=2==e?l:"",u=2==r?l:"",o=u+i(t.interChars,t.interIns)+c;return f=a>0?"("+f.join(")("+o+")(")+")":f.join(o),f=a>0?2==e?"("+c+")"+f+"("+u+")":"(.?)"+f+"(.?)":c+f+u,[RegExp(f,"i"),h]};let E=!!p,L=RegExp(o),k=RegExp(p);return{split:d,filter:(t,e,r)=>{let n=[],[i]=A(e);if(null!=r)for(let e=0;r.length>e;e++){let l=r[e];i.test(t[l])&&n.push(l)}else for(let e=0;t.length>e;e++)i.test(t[e])&&n.push(e);return n},info:(n,i,l)=>{let[s,a]=A(l,1),[f]=A(l,2),h=n.length,c=Array(h).fill(0),u={idx:Array(h),start:c.slice(),chars:c.slice(),terms:c.slice(),interIns:c.slice(),intraIns:c.slice(),interLft2:c.slice(),interRgt2:c.slice(),interLft1:c.slice(),interRgt1:c.slice(),ranges:Array(h)},o=1==e||1==r,p=0;for(let l=0;n.length>l;l++){let h=i[n[l]],c=h.match(s),b=c.index+c[1].length,m=b,I=!1,R=0,S=0,x=0,d=0,A=0,y=0,z=0,C=0;for(let n=0,i=2;a.length>n;n++,i+=2){let l=c[i].toLowerCase(),s=l==a[n];if(!s&&g>0){let t=l.indexOf(a[n]);t>-1&&(s=!0,m+=t,c[i]=c[i].slice(t),0==n&&(b=m))}if(o||s){let t=m-1,l=m+c[i].length,g=!0,f=!0;if(-1==t||L.test(h[t]))s&&R++;else{if(2==e){I=!0;break}if(E&&k.test(h[t]+h[t+1]))s&&S++;else{if(1==e){I=!0;break}g=!1}}if(l==h.length||L.test(h[l]))s&&x++;else{if(2==r){I=!0;break}if(E&&k.test(h[l-1]+h[l]))s&&d++;else{if(1==r){I=!0;break}f=!1}}s&&(A+=a[n].length,g&&f&&y++)}else C+=l.length-a[n].length;if(n>0&&(z+=c[i-1].length),!t.intraFilt(a[n],l,m)){I=!0;break}a.length-1>n&&(m+=c[i].length+c[i+1].length)}if(!I){u.idx[p]=n[l],u.interLft2[p]=R,u.interLft1[p]=S,u.interRgt2[p]=x,u.interRgt1[p]=d,u.chars[p]=A,u.terms[p]=y,u.interIns[p]=z,u.intraIns[p]=C,u.start[p]=b;let t=h.match(f),e=u.ranges[p]=[],r=t.index+t[1].length,i=r,s=r;for(let n=2;t.length>n;n++){let l=t[n].length;r+=l,n%2==0?s=r:l>0&&(e.push(i,s),i=s=r)}s>i&&e.push(i,s),p++}}if(n.length>p)for(let t in u)u[t]=u[t].slice(0,p);return u},sort:t.sort}}const a=(()=>{let t={A:"ÁÀÃÂÄĄ",a:"áàãâäą",E:"ÉÈÊËĖ",e:"éèêëę",I:"ÍÌÎÏĮ",i:"íìîïį",O:"ÓÒÔÕÖ",o:"óòôõö",U:"ÚÙÛÜŪŲ",u:"úùûüūų",C:"ÇČ",c:"çč",N:"Ñ",n:"ñ",S:"Š",s:"š"},e=new Map,r="";for(let n in t)t[n].split("").forEach((t=>{r+=t,e.set(t,n)}));let n=RegExp(`[${r}]`,"g");return t=>{let r=Array(t.length);for(let i=0;t.length>i;i++)r[i]=t[i].replace(n,(t=>e.get(t)));return r}})(),g=(t,e)=>e?`<mark>${t}</mark>`:t,f=(t,e)=>t+e;return s.latinize=a,s.permute=t=>{let e=function(t){let e,r,n=t.length,i=[t.slice()],l=Array(n).fill(0),s=1;for(;n>s;)s>l[s]?(e=s%2&&l[s],r=t[s],t[s]=t[e],t[e]=r,++l[s],s=1,i.push(t.slice())):(l[s]=0,++s);return i}([...Array(t.length).keys()]).sort(((t,e)=>{for(let r=0;t.length>r;r++)if(t[r]!=e[r])return t[r]-e[r];return 0}));return e.map((e=>e.map((e=>t[e]))))},s.highlight=function(t,e,r=g,n="",i=f){n=i(n,r(t.substring(0,e[0]),!1))??n;for(let l=0;e.length>l;l+=2)n=i(n,r(t.substring(e[l],e[l+1]),!0))??n,e.length-3>l&&(n=i(n,r(t.substring(e[l+1],e[l+2]),!1))??n);return i(n,r(t.substring(e[e.length-1]),!1))??n},s}(); | ||
/*! https://github.com/leeoniya/uFuzzy (v0.9.1) */ | ||
var uFuzzy=function(){"use strict";const t=new Intl.Collator("en").compare,e=1/0,r={interSplit:"[^A-Za-z0-9]+",intraSplit:"[a-z][A-Z]",intraBound:"[A-Za-z][0-9]|[0-9][A-Za-z]|[a-z][A-Z]",interLft:0,interRgt:0,interChars:".",interIns:e,intraChars:"[a-z\\d]",intraIns:0,intraMode:0,intraSlice:[1,e],intraSub:0,intraTrn:0,intraDel:0,intraFilt:()=>!0,sort:(e,r)=>{let{idx:n,chars:i,terms:l,interLft2:s,interLft1:a,start:g,intraIns:f,interIns:h}=e;return n.map(((t,e)=>e)).sort(((e,c)=>i[c]-i[e]||f[e]-f[c]||l[c]+s[c]+.5*a[c]-(l[e]+s[e]+.5*a[e])||h[e]-h[c]||g[e]-g[c]||t(r[n[e]],r[n[c]])))}},n=(t,r)=>0==r?"":1==r?t+"??":r==e?t+"*?":t+`{0,${r}}?`,i="(?:\\b|_)";function l(t){t=Object.assign({},r,t);const{interLft:e,interRgt:l,intraMode:s,intraSlice:a,intraIns:g,intraSub:f,intraTrn:h,intraDel:c,intraSplit:u,interSplit:o,intraBound:p,intraChars:b}=t;let{intraRules:m}=t;null==m&&(m=t=>{let e=r.intraSlice,n=0,i=0,l=0,s=0,u=t.length;return u>4?(e=a,n=g,i=f,l=h,s=c):3>u||(l=1,4==u&&(n=1)),{intraSlice:e,intraIns:n,intraSub:i,intraTrn:l,intraDel:s}});let I=!!u,R=RegExp(u,"g"),S=RegExp(o,"g"),x=RegExp("^"+o+"|"+o+"$","g");const A=t=>(t=t.replace(x,""),I&&(t=t.replace(R,(t=>t[0]+" "+t[1]))),t.split(S)),d=(r,a=0)=>{let f,h=A(r);if(1==s)f=h.map((t=>{let{intraSlice:e,intraIns:r,intraSub:i,intraTrn:l,intraDel:s}=m(t);if(r+i+l+s==0)return t;let[a,g]=e,f=t.slice(0,a),h=t.slice(g),c=t.slice(a,g),u=c.length,o=[];if(i)for(let t=0;u>t;t++)o.push(f+c.slice(0,t)+b+c.slice(t+1)+h);if(l)for(let t=0;u-1>t;t++)c[t]!=c[t+1]&&o.push(f+c.slice(0,t)+c[t+1]+c[t]+c.slice(t+2)+h);if(s)for(let t=0;u>t;t++)o.push(f+c.slice(0,t+1)+"?"+c.slice(t+1)+h);if(r){let t=n(b,1);for(let e=0;u+1>e;e++)o.push(f+c.slice(0,e)+t+c.slice(e)+h)}return"(?:"+t+"|"+o.join("|")+")"}));else{let t=n(b,g);2==a&&g>0&&(t=")("+t+")("),f=h.map((e=>e.split("").join(t)))}let c=2==e?i:"",u=2==l?i:"",o=u+n(t.interChars,t.interIns)+c;return f=a>0?"("+f.join(")("+o+")(")+")":f.join(o),f=a>0?2==e?"("+c+")"+f+"("+u+")":"(.?)"+f+"(.?)":c+f+u,[RegExp(f,"i"),h]};let z=!!p,E=RegExp(o),L=RegExp(p);return{split:A,filter:(t,e,r)=>{let n=[],[i]=d(e);if(null!=r)for(let e=0;r.length>e;e++){let l=r[e];i.test(t[l])&&n.push(l)}else for(let e=0;t.length>e;e++)i.test(t[e])&&n.push(e);return n},info:(r,n,i)=>{let[s,a]=d(i,1),[f]=d(i,2),h=r.length,c=Array(h).fill(0),u={idx:Array(h),start:c.slice(),chars:c.slice(),terms:c.slice(),interIns:c.slice(),intraIns:c.slice(),interLft2:c.slice(),interRgt2:c.slice(),interLft1:c.slice(),interRgt1:c.slice(),ranges:Array(h)},o=1==e||1==l,p=0;for(let i=0;r.length>i;i++){let h=n[r[i]],c=h.match(s),b=c.index+c[1].length,m=b,I=!1,R=0,S=0,x=0,A=0,d=0,k=0,y=0,C=0;for(let r=0,n=2;a.length>r;r++,n+=2){let i=c[n].toLowerCase(),s=i==a[r];if(!s&&g>0){let t=i.indexOf(a[r]);t>-1&&(s=!0,m+=t,c[n]=c[n].slice(t),0==r&&(b=m))}if(o||s){let t=m-1,i=m+c[n].length,g=!0,f=!0;if(-1==t||E.test(h[t]))s&&R++;else{if(2==e){I=!0;break}if(z&&L.test(h[t]+h[t+1]))s&&S++;else{if(1==e){I=!0;break}g=!1}}if(i==h.length||E.test(h[i]))s&&x++;else{if(2==l){I=!0;break}if(z&&L.test(h[i-1]+h[i]))s&&A++;else{if(1==l){I=!0;break}f=!1}}s&&(d+=a[r].length,g&&f&&k++)}else C+=i.length-a[r].length;if(r>0&&(y+=c[n-1].length),!t.intraFilt(a[r],i,m)){I=!0;break}a.length-1>r&&(m+=c[n].length+c[n+1].length)}if(!I){u.idx[p]=r[i],u.interLft2[p]=R,u.interLft1[p]=S,u.interRgt2[p]=x,u.interRgt1[p]=A,u.chars[p]=d,u.terms[p]=k,u.interIns[p]=y,u.intraIns[p]=C,u.start[p]=b;let t=h.match(f),e=u.ranges[p]=[],n=t.index+t[1].length,l=n,s=n;for(let r=2;t.length>r;r++){let i=t[r].length;n+=i,r%2==0?s=n:i>0&&(e.push(l,s),l=s=n)}s>l&&e.push(l,s),p++}}if(r.length>p)for(let t in u)u[t]=u[t].slice(0,p);return u},sort:t.sort}}const s=(()=>{let t={A:"ÁÀÃÂÄĄ",a:"áàãâäą",E:"ÉÈÊËĖ",e:"éèêëę",I:"ÍÌÎÏĮ",i:"íìîïį",O:"ÓÒÔÕÖ",o:"óòôõö",U:"ÚÙÛÜŪŲ",u:"úùûüūų",C:"ÇČ",c:"çč",N:"Ñ",n:"ñ",S:"Š",s:"š"},e=new Map,r="";for(let n in t)t[n].split("").forEach((t=>{r+=t,e.set(t,n)}));let n=RegExp(`[${r}]`,"g");return t=>{let r=Array(t.length);for(let i=0;t.length>i;i++)r[i]=t[i].replace(n,(t=>e.get(t)));return r}})(),a=(t,e)=>e?`<mark>${t}</mark>`:t,g=(t,e)=>t+e;return l.latinize=s,l.permute=t=>{let e=function(t){let e,r,n=t.length,i=[t.slice()],l=Array(n).fill(0),s=1;for(;n>s;)s>l[s]?(e=s%2&&l[s],r=t[s],t[s]=t[e],t[e]=r,++l[s],s=1,i.push(t.slice())):(l[s]=0,++s);return i}([...Array(t.length).keys()]).sort(((t,e)=>{for(let r=0;t.length>r;r++)if(t[r]!=e[r])return t[r]-e[r];return 0}));return e.map((e=>e.map((e=>t[e]))))},l.highlight=function(t,e,r=a,n="",i=g){n=i(n,r(t.substring(0,e[0]),!1))??n;for(let l=0;e.length>l;l+=2)n=i(n,r(t.substring(e[l],e[l+1]),!0))??n,e.length-3>l&&(n=i(n,r(t.substring(e[l+1],e[l+2]),!1))??n);return i(n,r(t.substring(e[e.length-1]),!1))??n},l}(); |
{ | ||
"name": "@leeoniya/ufuzzy", | ||
"version": "0.9.0", | ||
"version": "0.9.1", | ||
"description": "A tiny, efficient fuzzy matcher that doesn't suck", | ||
@@ -40,5 +40,5 @@ "main": "./dist/uFuzzy.cjs.js", | ||
"devDependencies": { | ||
"@rollup/plugin-terser": "^0.2.0", | ||
"rollup": "^3.7.2" | ||
"@rollup/plugin-terser": "^0.3.0", | ||
"rollup": "^3.9.1" | ||
} | ||
} |
@@ -474,3 +474,3 @@ ## ▒ μFuzzy | ||
</td> | ||
<td>★ 1.5k</td> | ||
<td>★ 1.9k</td> | ||
<td>4KB</td> | ||
@@ -807,2 +807,15 @@ <td>0.3ms</td> | ||
<td> | ||
<a href="https://github.com/axules/fuzzy-tools">fuzzy-tools</a> | ||
(<a href="https://leeoniya.github.io/uFuzzy/demos/compare.html?libs=fuzzy-tools&search=super%20ma">try</a>) | ||
</td> | ||
<td>★ 13</td> | ||
<td>2.8KB</td> | ||
<td>0.1ms</td> | ||
<td>6000ms</td> | ||
<td>92MB</td> | ||
<td>7.7MB</td> | ||
<td>30ms</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<a href="https://github.com/grafana/grafana/blob/main/packages/grafana-ui/src/utils/fuzzy.ts">fuzzyMatch</a> | ||
@@ -809,0 +822,0 @@ (<a href="https://leeoniya.github.io/uFuzzy/demos/compare.html?libs=fuzzyMatch&search=super%20ma">try</a>) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
88587
831
1644