Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@leeoniya/ufuzzy

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@leeoniya/ufuzzy - npm Package Compare versions

Comparing version 1.0.5 to 1.0.6

19

dist/uFuzzy.cjs.js

@@ -7,3 +7,3 @@ /**

* A tiny, efficient fuzzy matcher that doesn't suck
* https://github.com/leeoniya/uFuzzy (v1.0.5)
* https://github.com/leeoniya/uFuzzy (v1.0.6)
*/

@@ -196,3 +196,3 @@

if (parts.length == 0)
throw `Empty needle!`;
return [];

@@ -327,5 +327,9 @@ // split out any detected contractions for each term that become required suffixes

let out = [];
let [query] = prepQuery(needle);
if (query == null)
return null;
let out = [];
if (idxs != null) {

@@ -645,2 +649,4 @@ for (let i = 0; i < idxs.length; i++) {

let terms = split(needle);
let negsRe;

@@ -651,3 +657,3 @@

if (needle.trim() == '') {
if (terms.length == 0) {
let idxs = [];

@@ -663,2 +669,7 @@

}
else {
// abort search (needle is empty after pre-processing, e.g. no alpha-numeric chars)
if (terms.length == 0)
return [null, null, null];
}

@@ -665,0 +676,0 @@ // console.log(negs);

@@ -18,3 +18,3 @@ declare class uFuzzy {

idxs?: uFuzzy.HaystackIdxs
): uFuzzy.HaystackIdxs;
): uFuzzy.HaystackIdxs | null;

@@ -67,2 +67,4 @@ /** collects stats about pre-filtered matches, does additional filtering based on term boundary settings, finds highlight ranges */

export type AbortedResult = [null, null, null];
export type FilteredResult = [uFuzzy.HaystackIdxs, null, null];

@@ -76,3 +78,3 @@

export type SearchResult = FilteredResult | RankedResult;
export type SearchResult = FilteredResult | RankedResult | AbortedResult;

@@ -79,0 +81,0 @@ /** partial RegExp */

@@ -7,3 +7,3 @@ /**

* A tiny, efficient fuzzy matcher that doesn't suck
* https://github.com/leeoniya/uFuzzy (v1.0.5)
* https://github.com/leeoniya/uFuzzy (v1.0.6)
*/

@@ -194,3 +194,3 @@

if (parts.length == 0)
throw `Empty needle!`;
return [];

@@ -325,5 +325,9 @@ // split out any detected contractions for each term that become required suffixes

let out = [];
let [query] = prepQuery(needle);
if (query == null)
return null;
let out = [];
if (idxs != null) {

@@ -643,2 +647,4 @@ for (let i = 0; i < idxs.length; i++) {

let terms = split(needle);
let negsRe;

@@ -649,3 +655,3 @@

if (needle.trim() == '') {
if (terms.length == 0) {
let idxs = [];

@@ -661,2 +667,7 @@

}
else {
// abort search (needle is empty after pre-processing, e.g. no alpha-numeric chars)
if (terms.length == 0)
return [null, null, null];
}

@@ -663,0 +674,0 @@ // console.log(negs);

@@ -7,3 +7,3 @@ /**

* A tiny, efficient fuzzy matcher that doesn't suck
* https://github.com/leeoniya/uFuzzy (v1.0.5)
* https://github.com/leeoniya/uFuzzy (v1.0.6)
*/

@@ -197,3 +197,3 @@

if (parts.length == 0)
throw `Empty needle!`;
return [];

@@ -328,5 +328,9 @@ // split out any detected contractions for each term that become required suffixes

let out = [];
let [query] = prepQuery(needle);
if (query == null)
return null;
let out = [];
if (idxs != null) {

@@ -646,2 +650,4 @@ for (let i = 0; i < idxs.length; i++) {

let terms = split(needle);
let negsRe;

@@ -652,3 +658,3 @@

if (needle.trim() == '') {
if (terms.length == 0) {
let idxs = [];

@@ -664,2 +670,7 @@

}
else {
// abort search (needle is empty after pre-processing, e.g. no alpha-numeric chars)
if (terms.length == 0)
return [null, null, null];
}

@@ -666,0 +677,0 @@ // console.log(negs);

@@ -1,2 +0,2 @@

/*! https://github.com/leeoniya/uFuzzy (v1.0.5) */
var uFuzzy=function(){"use strict";const e=new Intl.Collator("en").compare,t=1/0,n=/(?:\s+|^)-[a-z\d]+/gi,l={unicode:!1,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:t,intraChars:"[a-z\\d']",intraIns:0,intraContr:"'[a-z]{1,2}\\b",intraMode:0,intraSlice:[1,t],intraSub:0,intraTrn:0,intraDel:0,intraFilt:()=>!0,sort:(t,n)=>{let{idx:l,chars:r,terms:i,interLft2:s,interLft1:a,start:g,intraIns:h,interIns:f}=t;return l.map(((e,t)=>t)).sort(((t,c)=>r[c]-r[t]||h[t]-h[c]||i[c]+s[c]+.5*a[c]-(i[t]+s[t]+.5*a[t])||f[t]-f[c]||g[t]-g[c]||e(n[l[t]],n[l[c]])))}},r=(e,n)=>0==n?"":1==n?e+"??":n==t?e+"*?":e+`{0,${n}}?`,i="(?:\\b|_)";function s(e){e=Object.assign({},l,e);const{unicode:t,interLft:s,interRgt:a,intraMode:h,intraSlice:f,intraIns:c,intraSub:o,intraTrn:u,intraDel:p,intraContr:m,intraSplit:b,interSplit:d,intraBound:x,intraChars:R}=e;let S=t?"u":"",{intraRules:I}=e;null==I&&(I=e=>{let t=l.intraSlice,n=0,r=0,i=0,s=0,a=e.length;return a>4?(t=f,n=c,r=o,i=u,s=p):3>a||(i=Math.min(u,1),4==a&&(n=Math.min(c,1))),{intraSlice:t,intraIns:n,intraSub:r,intraTrn:i,intraDel:s}});let A=!!b,E=RegExp(b,"g"+S),z=RegExp(d,"g"+S),k=RegExp("^"+d+"|"+d+"$","g"+S),y=RegExp(m,"gi"+S);const C=e=>(e=e.replace(k,"").toLowerCase(),A&&(e=e.replace(E,(e=>e[0]+" "+e[1]))),e.split(z).filter((e=>""!=e))),L=(t,n=0,l=!1)=>{let g=C(t);if(0==g.length)throw"Empty needle!";let f,o=Array(g.length).fill("");if(g=g.map(((e,t)=>e.replace(y,(e=>(o[t]=e,""))))),1==h)f=g.map(((e,t)=>{let{intraSlice:n,intraIns:l,intraSub:i,intraTrn:s,intraDel:a}=I(e);if(l+i+s+a==0)return e+o[t];let[g,h]=n,f=e.slice(0,g),c=e.slice(h),u=e.slice(g,h);1==l&&1==f.length&&f!=u[0]&&(f+="(?!"+f+")");let p=u.length,m=[e];if(i)for(let e=0;p>e;e++)m.push(f+u.slice(0,e)+R+u.slice(e+1)+c);if(s)for(let e=0;p-1>e;e++)u[e]!=u[e+1]&&m.push(f+u.slice(0,e)+u[e+1]+u[e]+u.slice(e+2)+c);if(a)for(let e=0;p>e;e++)m.push(f+u.slice(0,e+1)+"?"+u.slice(e+1)+c);if(l){let e=r(R,1);for(let t=0;p>t;t++)m.push(f+u.slice(0,t)+e+u.slice(t)+c)}return"(?:"+m.join("|")+")"+o[t]}));else{let e=r(R,c);2==n&&c>0&&(e=")("+e+")("),f=g.map(((t,n)=>t.split("").map(((e,t,n)=>(1==c&&0==t&&n.length>1&&e!=n[t+1]&&(e+="(?!"+e+")"),e))).join(e)+o[n]))}let u=2==s?i:"",p=2==a?i:"",m=p+r(e.interChars,e.interIns)+u;return n>0?l?f=u+"("+f.join(")"+p+"|"+u+"(")+")"+p:(f="("+f.join(")("+m+")(")+")",f="(.??"+u+")"+f+"("+p+".*)"):(f=f.join(m),f=u+f+p),[RegExp(f,"i"+S),g,o]},j=(e,t,n)=>{let l=[],[r]=L(t);if(null!=n)for(let t=0;n.length>t;t++){let i=n[t];r.test(e[i])&&l.push(i)}else for(let t=0;e.length>t;t++)r.test(e[t])&&l.push(t);return l};let w=!!x,M=RegExp(d,S),Z=RegExp(x,S);const D=(t,n,l)=>{let[r,i,g]=L(l,1),[h]=L(l,2),f=i.length,c=t.length,o=Array(c).fill(0),u={idx:Array(c),start:o.slice(),chars:o.slice(),terms:o.slice(),interIns:o.slice(),intraIns:o.slice(),interLft2:o.slice(),interRgt2:o.slice(),interLft1:o.slice(),interRgt1:o.slice(),ranges:Array(c)},p=1==s||1==a,m=0;for(let l=0;t.length>l;l++){let c=n[t[l]],o=c.match(r),b=o.index+o[1].length,d=b,x=!1,R=0,I=0,A=0,E=0,z=0,k=0,y=0,C=0,L=[];for(let t=0,n=2;f>t;t++,n+=2){let l=o[n].toLowerCase(),r=i[t]+g[t],h=r.length,u=l.length,m=l==r;if(!m&&o[n+1].length>=h){let e=o[n+1].toLowerCase().indexOf(r);e>-1&&(L.push(d,e,h),d+=T(o,n,e,h),l=r,u=h,m=!0,0==t&&(b=d))}if(p||m){let e=d-1,t=d+u,i=!0,g=!0;if(-1==e||M.test(c[e]))m&&R++;else{if(2==s){x=!0;break}if(w&&Z.test(c[e]+c[e+1]))m&&I++;else{if(1==s){let e=o[n+1],t=d+u;if(e.length>=h){let i,s=0,a=!1,g=RegExp(r,"ig"+S);for(;i=g.exec(e);){s=i.index;let e=t+s,n=e-1;if(-1==n||M.test(c[n])){R++,a=!0;break}if(Z.test(c[n]+c[e])){I++,a=!0;break}}if(a){L.push(d,s,h),d+=T(o,n,s,h),l=r,u=h,m=!0;break}}x=!0;break}i=!1}}if(t==c.length||M.test(c[t]))m&&A++;else{if(2==a){x=!0;break}if(w&&Z.test(c[t-1]+c[t]))m&&E++;else{if(1==a){x=!0;break}g=!1}}m&&(z+=h,i&&g&&k++)}if(u>h&&(C+=u-h),t>0&&(y+=o[n-1].length),!e.intraFilt(r,l,d)){x=!0;break}f-1>t&&(d+=u+o[n+1].length)}if(!x){u.idx[m]=t[l],u.interLft2[m]=R,u.interLft1[m]=I,u.interRgt2[m]=A,u.interRgt1[m]=E,u.chars[m]=z,u.terms[m]=k,u.interIns[m]=y,u.intraIns[m]=C,u.start[m]=b;let e=c.match(h),n=u.ranges[m]=[],r=e.index+e[1].length,i=r,s=r,a=L.length,g=a>0?0:1/0,f=a-3;for(let t=2;e.length>t;t++){let l=e[t].length;if(g>f||L[g]!=r)r+=l;else{let n=L[g+2],s=L[g+1]+n;r+=l+s,i=r-n,e[t+1]=e[t+1].slice(s),g+=3}t%2==0?s=r:l>0&&(n.push(i,s),i=s=r)}s>i&&n.push(i,s),m++}}if(t.length>m)for(let e in u)u[e]=u[e].slice(0,m);return u},T=(e,t,n,l)=>{let r=e[t]+e[t+1].slice(0,n);return e[t-1]+=r,e[t]=e[t+1].slice(n,n+l),e[t+1]=e[t+1].slice(n+l),r.length};return{search:(...t)=>((t,l,r=!1,i=1e3,s)=>{let a,h=null,f=null,c=[];if(l=l.replace(n,(e=>(c.push(e.trim().slice(1)),""))),c.length>0&&(a=RegExp(c.join("|"),"i"+S),""==l.trim())){let e=[];for(let n=0;t.length>n;n++)a.test(t[n])||e.push(n);return[e,null,null]}if(r){let e=C(l);if(e.length>1){let n=e.slice().sort(((e,t)=>t.length-e.length));for(let e=0;n.length>e;e++){if(0==s?.length)return[[],null,null];s=j(t,n[e],s)}h=g(e).map((e=>e.join(" "))),f=[];let l=new Set;for(let e=0;h.length>e;e++)if(s.length>l.size){let n=s.filter((e=>!l.has(e))),r=j(t,h[e],n);for(let e=0;r.length>e;e++)l.add(r[e]);f.push(r)}else f.push([])}}null==h&&(h=[l],f=[s?.length>0?s:j(t,l)]);let o=null,u=null;if(c.length>0&&(f=f.map((e=>e.filter((e=>!a.test(t[e])))))),i>=f.reduce(((e,t)=>e+t.length),0)){o={},u=[];for(let n=0;f.length>n;n++){let l=f[n];if(null==l||0==l.length)continue;let r=h[n],i=D(l,t,r),s=e.sort(i,t,r);if(n>0)for(let e=0;s.length>e;e++)s[e]+=u.length;for(let e in i)o[e]=(o[e]??[]).concat(i[e]);u=u.concat(s)}}return[[].concat(...f),o,u]})(...t),split:C,filter:j,info:D,sort:e.sort}}const a=(()=>{let e={A:"ÁÀÃÂÄĄ",a:"áàãâäą",E:"ÉÈÊËĖ",e:"éèêëę",I:"ÍÌÎÏĮ",i:"íìîïį",O:"ÓÒÔÕÖ",o:"óòôõö",U:"ÚÙÛÜŪŲ",u:"úùûüūų",C:"ÇČ",c:"çč",N:"Ñ",n:"ñ",S:"Š",s:"š"},t=new Map,n="";for(let l in e)e[l].split("").forEach((e=>{n+=e,t.set(e,l)}));let l=RegExp(`[${n}]`,"g"),r=e=>t.get(e);return e=>{if("string"==typeof e)return e.replace(l,r);let t=Array(e.length);for(let n=0;e.length>n;n++)t[n]=e[n].replace(l,r);return t}})();function g(e){let t,n,l=(e=e.slice()).length,r=[e.slice()],i=Array(l).fill(0),s=1;for(;l>s;)s>i[s]?(t=s%2&&i[s],n=e[s],e[s]=e[t],e[t]=n,++i[s],s=1,r.push(e.slice())):(i[s]=0,++s);return r}const h=(e,t)=>t?`<mark>${e}</mark>`:e,f=(e,t)=>e+t;return s.latinize=a,s.permute=e=>g([...Array(e.length).keys()]).sort(((e,t)=>{for(let n=0;e.length>n;n++)if(e[n]!=t[n])return e[n]-t[n];return 0})).map((t=>t.map((t=>e[t])))),s.highlight=function(e,t,n=h,l="",r=f){l=r(l,n(e.substring(0,t[0]),!1))??l;for(let i=0;t.length>i;i+=2)l=r(l,n(e.substring(t[i],t[i+1]),!0))??l,t.length-3>i&&(l=r(l,n(e.substring(t[i+1],t[i+2]),!1))??l);return r(l,n(e.substring(t[t.length-1]),!1))??l},s}();
/*! https://github.com/leeoniya/uFuzzy (v1.0.6) */
var uFuzzy=function(){"use strict";const e=new Intl.Collator("en").compare,t=1/0,l=/(?:\s+|^)-[a-z\d]+/gi,n={unicode:!1,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:t,intraChars:"[a-z\\d']",intraIns:0,intraContr:"'[a-z]{1,2}\\b",intraMode:0,intraSlice:[1,t],intraSub:0,intraTrn:0,intraDel:0,intraFilt:()=>!0,sort:(t,l)=>{let{idx:n,chars:r,terms:i,interLft2:s,interLft1:a,start:g,intraIns:f,interIns:h}=t;return n.map(((e,t)=>t)).sort(((t,u)=>r[u]-r[t]||f[t]-f[u]||i[u]+s[u]+.5*a[u]-(i[t]+s[t]+.5*a[t])||h[t]-h[u]||g[t]-g[u]||e(l[n[t]],l[n[u]])))}},r=(e,l)=>0==l?"":1==l?e+"??":l==t?e+"*?":e+`{0,${l}}?`,i="(?:\\b|_)";function s(e){e=Object.assign({},n,e);const{unicode:t,interLft:s,interRgt:a,intraMode:f,intraSlice:h,intraIns:u,intraSub:c,intraTrn:o,intraDel:p,intraContr:m,intraSplit:b,interSplit:d,intraBound:x,intraChars:R}=e;let S=t?"u":"",{intraRules:I}=e;null==I&&(I=e=>{let t=n.intraSlice,l=0,r=0,i=0,s=0,a=e.length;return a>4?(t=h,l=u,r=c,i=o,s=p):3>a||(i=Math.min(o,1),4==a&&(l=Math.min(u,1))),{intraSlice:t,intraIns:l,intraSub:r,intraTrn:i,intraDel:s}});let A=!!b,z=RegExp(b,"g"+S),E=RegExp(d,"g"+S),k=RegExp("^"+d+"|"+d+"$","g"+S),C=RegExp(m,"gi"+S);const L=e=>(e=e.replace(k,"").toLowerCase(),A&&(e=e.replace(z,(e=>e[0]+" "+e[1]))),e.split(E).filter((e=>""!=e))),y=(t,l=0,n=!1)=>{let g=L(t);if(0==g.length)return[];let h,c=Array(g.length).fill("");if(g=g.map(((e,t)=>e.replace(C,(e=>(c[t]=e,""))))),1==f)h=g.map(((e,t)=>{let{intraSlice:l,intraIns:n,intraSub:i,intraTrn:s,intraDel:a}=I(e);if(n+i+s+a==0)return e+c[t];let[g,f]=l,h=e.slice(0,g),u=e.slice(f),o=e.slice(g,f);1==n&&1==h.length&&h!=o[0]&&(h+="(?!"+h+")");let p=o.length,m=[e];if(i)for(let e=0;p>e;e++)m.push(h+o.slice(0,e)+R+o.slice(e+1)+u);if(s)for(let e=0;p-1>e;e++)o[e]!=o[e+1]&&m.push(h+o.slice(0,e)+o[e+1]+o[e]+o.slice(e+2)+u);if(a)for(let e=0;p>e;e++)m.push(h+o.slice(0,e+1)+"?"+o.slice(e+1)+u);if(n){let e=r(R,1);for(let t=0;p>t;t++)m.push(h+o.slice(0,t)+e+o.slice(t)+u)}return"(?:"+m.join("|")+")"+c[t]}));else{let e=r(R,u);2==l&&u>0&&(e=")("+e+")("),h=g.map(((t,l)=>t.split("").map(((e,t,l)=>(1==u&&0==t&&l.length>1&&e!=l[t+1]&&(e+="(?!"+e+")"),e))).join(e)+c[l]))}let o=2==s?i:"",p=2==a?i:"",m=p+r(e.interChars,e.interIns)+o;return l>0?n?h=o+"("+h.join(")"+p+"|"+o+"(")+")"+p:(h="("+h.join(")("+m+")(")+")",h="(.??"+o+")"+h+"("+p+".*)"):(h=h.join(m),h=o+h+p),[RegExp(h,"i"+S),g,c]},j=(e,t,l)=>{let[n]=y(t);if(null==n)return null;let r=[];if(null!=l)for(let t=0;l.length>t;t++){let i=l[t];n.test(e[i])&&r.push(i)}else for(let t=0;e.length>t;t++)n.test(e[t])&&r.push(t);return r};let w=!!x,M=RegExp(d,S),Z=RegExp(x,S);const D=(t,l,n)=>{let[r,i,g]=y(n,1),[f]=y(n,2),h=i.length,u=t.length,c=Array(u).fill(0),o={idx:Array(u),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(u)},p=1==s||1==a,m=0;for(let n=0;t.length>n;n++){let u=l[t[n]],c=u.match(r),b=c.index+c[1].length,d=b,x=!1,R=0,I=0,A=0,z=0,E=0,k=0,C=0,L=0,y=[];for(let t=0,l=2;h>t;t++,l+=2){let n=c[l].toLowerCase(),r=i[t]+g[t],f=r.length,o=n.length,m=n==r;if(!m&&c[l+1].length>=f){let e=c[l+1].toLowerCase().indexOf(r);e>-1&&(y.push(d,e,f),d+=T(c,l,e,f),n=r,o=f,m=!0,0==t&&(b=d))}if(p||m){let e=d-1,t=d+o,i=!0,g=!0;if(-1==e||M.test(u[e]))m&&R++;else{if(2==s){x=!0;break}if(w&&Z.test(u[e]+u[e+1]))m&&I++;else{if(1==s){let e=c[l+1],t=d+o;if(e.length>=f){let i,s=0,a=!1,g=RegExp(r,"ig"+S);for(;i=g.exec(e);){s=i.index;let e=t+s,l=e-1;if(-1==l||M.test(u[l])){R++,a=!0;break}if(Z.test(u[l]+u[e])){I++,a=!0;break}}if(a){y.push(d,s,f),d+=T(c,l,s,f),n=r,o=f,m=!0;break}}x=!0;break}i=!1}}if(t==u.length||M.test(u[t]))m&&A++;else{if(2==a){x=!0;break}if(w&&Z.test(u[t-1]+u[t]))m&&z++;else{if(1==a){x=!0;break}g=!1}}m&&(E+=f,i&&g&&k++)}if(o>f&&(L+=o-f),t>0&&(C+=c[l-1].length),!e.intraFilt(r,n,d)){x=!0;break}h-1>t&&(d+=o+c[l+1].length)}if(!x){o.idx[m]=t[n],o.interLft2[m]=R,o.interLft1[m]=I,o.interRgt2[m]=A,o.interRgt1[m]=z,o.chars[m]=E,o.terms[m]=k,o.interIns[m]=C,o.intraIns[m]=L,o.start[m]=b;let e=u.match(f),l=o.ranges[m]=[],r=e.index+e[1].length,i=r,s=r,a=y.length,g=a>0?0:1/0,h=a-3;for(let t=2;e.length>t;t++){let n=e[t].length;if(g>h||y[g]!=r)r+=n;else{let l=y[g+2],s=y[g+1]+l;r+=n+s,i=r-l,e[t+1]=e[t+1].slice(s),g+=3}t%2==0?s=r:n>0&&(l.push(i,s),i=s=r)}s>i&&l.push(i,s),m++}}if(t.length>m)for(let e in o)o[e]=o[e].slice(0,m);return o},T=(e,t,l,n)=>{let r=e[t]+e[t+1].slice(0,l);return e[t-1]+=r,e[t]=e[t+1].slice(l,l+n),e[t+1]=e[t+1].slice(l+n),r.length};return{search:(...t)=>((t,n,r=!1,i=1e3,s)=>{let a=null,f=null,h=[];n=n.replace(l,(e=>(h.push(e.trim().slice(1)),"")));let u,c=L(n);if(h.length>0){if(u=RegExp(h.join("|"),"i"+S),0==c.length){let e=[];for(let l=0;t.length>l;l++)u.test(t[l])||e.push(l);return[e,null,null]}}else if(0==c.length)return[null,null,null];if(r){let e=L(n);if(e.length>1){let l=e.slice().sort(((e,t)=>t.length-e.length));for(let e=0;l.length>e;e++){if(0==s?.length)return[[],null,null];s=j(t,l[e],s)}a=g(e).map((e=>e.join(" "))),f=[];let n=new Set;for(let e=0;a.length>e;e++)if(s.length>n.size){let l=s.filter((e=>!n.has(e))),r=j(t,a[e],l);for(let e=0;r.length>e;e++)n.add(r[e]);f.push(r)}else f.push([])}}null==a&&(a=[n],f=[s?.length>0?s:j(t,n)]);let o=null,p=null;if(h.length>0&&(f=f.map((e=>e.filter((e=>!u.test(t[e])))))),i>=f.reduce(((e,t)=>e+t.length),0)){o={},p=[];for(let l=0;f.length>l;l++){let n=f[l];if(null==n||0==n.length)continue;let r=a[l],i=D(n,t,r),s=e.sort(i,t,r);if(l>0)for(let e=0;s.length>e;e++)s[e]+=p.length;for(let e in i)o[e]=(o[e]??[]).concat(i[e]);p=p.concat(s)}}return[[].concat(...f),o,p]})(...t),split:L,filter:j,info:D,sort:e.sort}}const a=(()=>{let e={A:"ÁÀÃÂÄĄ",a:"áàãâäą",E:"ÉÈÊËĖ",e:"éèêëę",I:"ÍÌÎÏĮ",i:"íìîïį",O:"ÓÒÔÕÖ",o:"óòôõö",U:"ÚÙÛÜŪŲ",u:"úùûüūų",C:"ÇČ",c:"çč",N:"Ñ",n:"ñ",S:"Š",s:"š"},t=new Map,l="";for(let n in e)e[n].split("").forEach((e=>{l+=e,t.set(e,n)}));let n=RegExp(`[${l}]`,"g"),r=e=>t.get(e);return e=>{if("string"==typeof e)return e.replace(n,r);let t=Array(e.length);for(let l=0;e.length>l;l++)t[l]=e[l].replace(n,r);return t}})();function g(e){let t,l,n=(e=e.slice()).length,r=[e.slice()],i=Array(n).fill(0),s=1;for(;n>s;)s>i[s]?(t=s%2&&i[s],l=e[s],e[s]=e[t],e[t]=l,++i[s],s=1,r.push(e.slice())):(i[s]=0,++s);return r}const f=(e,t)=>t?`<mark>${e}</mark>`:e,h=(e,t)=>e+t;return s.latinize=a,s.permute=e=>g([...Array(e.length).keys()]).sort(((e,t)=>{for(let l=0;e.length>l;l++)if(e[l]!=t[l])return e[l]-t[l];return 0})).map((t=>t.map((t=>e[t])))),s.highlight=function(e,t,l=f,n="",r=h){n=r(n,l(e.substring(0,t[0]),!1))??n;for(let i=0;t.length>i;i+=2)n=r(n,l(e.substring(t[i],t[i+1]),!0))??n,t.length-3>i&&(n=r(n,l(e.substring(t[i+1],t[i+2]),!1))??n);return r(n,l(e.substring(t[t.length-1]),!1))??n},s}();
{
"name": "@leeoniya/ufuzzy",
"version": "1.0.5",
"version": "1.0.6",
"description": "A tiny, efficient fuzzy matcher that doesn't suck",

@@ -42,4 +42,4 @@ "main": "./dist/uFuzzy.cjs.js",

"@rollup/plugin-terser": "^0.4.0",
"rollup": "^3.18.0"
"rollup": "^3.19.0"
}
}

@@ -111,23 +111,26 @@ ## ▒ μFuzzy

// sort/rank only when <= 1,000 items
let infoThresh = 1e3;
// idxs can be null when the needle is non-searchable (has no alpha-numeric chars)
if (idxs != null && idxs.length > 0) {
// sort/rank only when <= 1,000 items
let infoThresh = 1e3;
if (idxs.length <= infoThresh) {
let info = uf.info(idxs, haystack, needle);
if (idxs.length <= infoThresh) {
let info = uf.info(idxs, haystack, needle);
// order is a double-indirection array (a re-order of the passed-in idxs)
// this allows corresponding info to be grabbed directly by idx, if needed
let order = uf.sort(info, haystack, needle);
// order is a double-indirection array (a re-order of the passed-in idxs)
// this allows corresponding info to be grabbed directly by idx, if needed
let order = uf.sort(info, haystack, needle);
// render post-filtered & ordered matches
for (let i = 0; i < order.length; i++) {
// using info.idx here instead of idxs because uf.info() may have
// further reduced the initial idxs based on prefix/suffix rules
console.log(haystack[info.idx[order[i]]]);
// render post-filtered & ordered matches
for (let i = 0; i < order.length; i++) {
// using info.idx here instead of idxs because uf.info() may have
// further reduced the initial idxs based on prefix/suffix rules
console.log(haystack[info.idx[order[i]]]);
}
}
}
else {
// render pre-filtered but unordered matches
for (let i = 0; i < idxs.length; i++) {
console.log(haystack[idxs[i]]);
else {
// render pre-filtered but unordered matches
for (let i = 0; i < idxs.length; i++) {
console.log(haystack[idxs[i]]);
}
}

@@ -141,3 +144,3 @@ }

uFuzzy provides a `uf.search(haystack, needle, outOfOrder = false, infoThresh = 1e3) => [idxs, info, order]` wrapper which combines the `filter`, `info`, `sort` steps above.
This method also implements efficient logic for matching search terms out of order.
This method also implements efficient logic for matching search terms out of order and support for multiple substring exclusions, e.g. `fruit -green -melon`.

@@ -144,0 +147,0 @@ ---

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc