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.6 to 1.0.7

29

dist/uFuzzy.cjs.js

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

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

@@ -17,4 +17,8 @@

const NEGS_RE = /(?:\s+|^)-[a-z\d]+/ig;
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions#escaping
const escapeRegExp = str => str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
// meh, magic tmp placeholder, must be tolerant to toLowerCase(), interSplit, and intraSplit
const EXACT_HERE = 'eexxaacctt';
const OPTS = {

@@ -131,2 +135,5 @@ // whether regexps use a /u unicode flag

const EXACTS_RE = new RegExp('".+?"', 'gi' + uFlag);
const NEGS_RE = new RegExp(`(?:\\s+|^)-${intraChars}+`, 'gi' + uFlag);
let { intraRules } = opts;

@@ -185,2 +192,9 @@

const split = needle => {
let exacts = [];
needle = needle.replace(EXACTS_RE, m => {
exacts.push(m);
return EXACT_HERE;
});
needle = needle.replace(trimRe, '').toLowerCase();

@@ -191,3 +205,4 @@

return needle.split(interSplit).filter(t => t != '');
let j = 0;
return needle.split(interSplit).filter(t => t != '').map(v => v === EXACT_HERE ? exacts[j++] : v);
};

@@ -226,2 +241,5 @@

if (p[0] === '"')
return escapeRegExp(p.slice(1, -1));
let [lftIdx, rgtIdx] = intraSlice;

@@ -287,3 +305,3 @@ let lftChar = p.slice(0, lftIdx); // prefix

reTpl = parts.map((p, pi) => p.split('').map((c, i, chars) => {
reTpl = parts.map((p, pi) => p[0] === '"' ? escapeRegExp(p.slice(1, -1)) : p.split('').map((c, i, chars) => {
// neg lookahead to prefer matching 'Test' instead of 'tTest' in ManifestTest or fittest

@@ -428,3 +446,4 @@ // but skip when search term contains leading repetition (aardvark, aaa)

let group = m[k].toLowerCase();
let term = parts[j] + contrs[j];
let part = parts[j];
let term = part[0] == '"' ? part.slice(1, -1) : part + contrs[j];
let termLen = term.length;

@@ -431,0 +450,0 @@ let groupLen = group.length;

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

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

@@ -15,4 +15,8 @@

const NEGS_RE = /(?:\s+|^)-[a-z\d]+/ig;
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions#escaping
const escapeRegExp = str => str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
// meh, magic tmp placeholder, must be tolerant to toLowerCase(), interSplit, and intraSplit
const EXACT_HERE = 'eexxaacctt';
const OPTS = {

@@ -129,2 +133,5 @@ // whether regexps use a /u unicode flag

const EXACTS_RE = new RegExp('".+?"', 'gi' + uFlag);
const NEGS_RE = new RegExp(`(?:\\s+|^)-${intraChars}+`, 'gi' + uFlag);
let { intraRules } = opts;

@@ -183,2 +190,9 @@

const split = needle => {
let exacts = [];
needle = needle.replace(EXACTS_RE, m => {
exacts.push(m);
return EXACT_HERE;
});
needle = needle.replace(trimRe, '').toLowerCase();

@@ -189,3 +203,4 @@

return needle.split(interSplit).filter(t => t != '');
let j = 0;
return needle.split(interSplit).filter(t => t != '').map(v => v === EXACT_HERE ? exacts[j++] : v);
};

@@ -224,2 +239,5 @@

if (p[0] === '"')
return escapeRegExp(p.slice(1, -1));
let [lftIdx, rgtIdx] = intraSlice;

@@ -285,3 +303,3 @@ let lftChar = p.slice(0, lftIdx); // prefix

reTpl = parts.map((p, pi) => p.split('').map((c, i, chars) => {
reTpl = parts.map((p, pi) => p[0] === '"' ? escapeRegExp(p.slice(1, -1)) : p.split('').map((c, i, chars) => {
// neg lookahead to prefer matching 'Test' instead of 'tTest' in ManifestTest or fittest

@@ -426,3 +444,4 @@ // but skip when search term contains leading repetition (aardvark, aaa)

let group = m[k].toLowerCase();
let term = parts[j] + contrs[j];
let part = parts[j];
let term = part[0] == '"' ? part.slice(1, -1) : part + contrs[j];
let termLen = term.length;

@@ -429,0 +448,0 @@ let groupLen = group.length;

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

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

@@ -18,4 +18,8 @@

const NEGS_RE = /(?:\s+|^)-[a-z\d]+/ig;
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions#escaping
const escapeRegExp = str => str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
// meh, magic tmp placeholder, must be tolerant to toLowerCase(), interSplit, and intraSplit
const EXACT_HERE = 'eexxaacctt';
const OPTS = {

@@ -132,2 +136,5 @@ // whether regexps use a /u unicode flag

const EXACTS_RE = new RegExp('".+?"', 'gi' + uFlag);
const NEGS_RE = new RegExp(`(?:\\s+|^)-${intraChars}+`, 'gi' + uFlag);
let { intraRules } = opts;

@@ -186,2 +193,9 @@

const split = needle => {
let exacts = [];
needle = needle.replace(EXACTS_RE, m => {
exacts.push(m);
return EXACT_HERE;
});
needle = needle.replace(trimRe, '').toLowerCase();

@@ -192,3 +206,4 @@

return needle.split(interSplit).filter(t => t != '');
let j = 0;
return needle.split(interSplit).filter(t => t != '').map(v => v === EXACT_HERE ? exacts[j++] : v);
};

@@ -227,2 +242,5 @@

if (p[0] === '"')
return escapeRegExp(p.slice(1, -1));
let [lftIdx, rgtIdx] = intraSlice;

@@ -288,3 +306,3 @@ let lftChar = p.slice(0, lftIdx); // prefix

reTpl = parts.map((p, pi) => p.split('').map((c, i, chars) => {
reTpl = parts.map((p, pi) => p[0] === '"' ? escapeRegExp(p.slice(1, -1)) : p.split('').map((c, i, chars) => {
// neg lookahead to prefer matching 'Test' instead of 'tTest' in ManifestTest or fittest

@@ -429,3 +447,4 @@ // but skip when search term contains leading repetition (aardvark, aaa)

let group = m[k].toLowerCase();
let term = parts[j] + contrs[j];
let part = parts[j];
let term = part[0] == '"' ? part.slice(1, -1) : part + contrs[j];
let termLen = term.length;

@@ -432,0 +451,0 @@ let groupLen = group.length;

4

dist/uFuzzy.iife.min.js

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

/*! 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}();
/*! https://github.com/leeoniya/uFuzzy (v1.0.7) */
var uFuzzy=function(){"use strict";const e=new Intl.Collator("en").compare,t=1/0,l=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),n="eexxaacctt",r={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]])))}},i=(e,l)=>0==l?"":1==l?e+"??":l==t?e+"*?":e+`{0,${l}}?`,s="(?:\\b|_)";function a(e){e=Object.assign({},r,e);const{unicode:t,interLft:a,interRgt:g,intraMode:h,intraSlice:u,intraIns:c,intraSub:o,intraTrn:p,intraDel:m,intraContr:x,intraSplit:b,interSplit:R,intraBound:d,intraChars:S}=e;let E=t?"u":"";const I=RegExp('".+?"',"gi"+E),A=RegExp(`(?:\\s+|^)-${S}+`,"gi"+E);let{intraRules:k}=e;null==k&&(k=e=>{let t=r.intraSlice,l=0,n=0,i=0,s=0,a=e.length;return a>4?(t=u,l=c,n=o,i=p,s=m):3>a||(i=Math.min(p,1),4==a&&(l=Math.min(c,1))),{intraSlice:t,intraIns:l,intraSub:n,intraTrn:i,intraDel:s}});let z=!!b,C=RegExp(b,"g"+E),L=RegExp(R,"g"+E),y=RegExp("^"+R+"|"+R+"$","g"+E),j=RegExp(x,"gi"+E);const $=e=>{let t=[];e=(e=e.replace(I,(e=>(t.push(e),n)))).replace(y,"").toLowerCase(),z&&(e=e.replace(C,(e=>e[0]+" "+e[1])));let l=0;return e.split(L).filter((e=>""!=e)).map((e=>e===n?t[l++]:e))},w=(t,n=0,r=!1)=>{let f=$(t);if(0==f.length)return[];let u,o=Array(f.length).fill("");if(f=f.map(((e,t)=>e.replace(j,(e=>(o[t]=e,""))))),1==h)u=f.map(((e,t)=>{let{intraSlice:n,intraIns:r,intraSub:s,intraTrn:a,intraDel:g}=k(e);if(r+s+a+g==0)return e+o[t];if('"'===e[0])return l(e.slice(1,-1));let[f,h]=n,u=e.slice(0,f),c=e.slice(h),p=e.slice(f,h);1==r&&1==u.length&&u!=p[0]&&(u+="(?!"+u+")");let m=p.length,x=[e];if(s)for(let e=0;m>e;e++)x.push(u+p.slice(0,e)+S+p.slice(e+1)+c);if(a)for(let e=0;m-1>e;e++)p[e]!=p[e+1]&&x.push(u+p.slice(0,e)+p[e+1]+p[e]+p.slice(e+2)+c);if(g)for(let e=0;m>e;e++)x.push(u+p.slice(0,e+1)+"?"+p.slice(e+1)+c);if(r){let e=i(S,1);for(let t=0;m>t;t++)x.push(u+p.slice(0,t)+e+p.slice(t)+c)}return"(?:"+x.join("|")+")"+o[t]}));else{let e=i(S,c);2==n&&c>0&&(e=")("+e+")("),u=f.map(((t,n)=>'"'===t[0]?l(t.slice(1,-1)):t.split("").map(((e,t,l)=>(1==c&&0==t&&l.length>1&&e!=l[t+1]&&(e+="(?!"+e+")"),e))).join(e)+o[n]))}let p=2==a?s:"",m=2==g?s:"",x=m+i(e.interChars,e.interIns)+p;return n>0?r?u=p+"("+u.join(")"+m+"|"+p+"(")+")"+m:(u="("+u.join(")("+x+")(")+")",u="(.??"+p+")"+u+"("+m+".*)"):(u=u.join(x),u=p+u+m),[RegExp(u,"i"+E),f,o]},M=(e,t,l)=>{let[n]=w(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 Z=!!d,D=RegExp(R,E),T=RegExp(d,E);const F=(t,l,n)=>{let[r,i,s]=w(n,1),[f]=w(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==a||1==g,m=0;for(let n=0;t.length>n;n++){let u=l[t[n]],c=u.match(r),x=c.index+c[1].length,b=x,R=!1,d=0,S=0,I=0,A=0,k=0,z=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],f='"'==r[0]?r.slice(1,-1):r+s[t],o=f.length,m=n.length,j=n==f;if(!j&&c[l+1].length>=o){let e=c[l+1].toLowerCase().indexOf(f);e>-1&&(y.push(b,e,o),b+=O(c,l,e,o),n=f,m=o,j=!0,0==t&&(x=b))}if(p||j){let e=b-1,t=b+m,r=!0,i=!0;if(-1==e||D.test(u[e]))j&&d++;else{if(2==a){R=!0;break}if(Z&&T.test(u[e]+u[e+1]))j&&S++;else{if(1==a){let e=c[l+1],t=b+m;if(e.length>=o){let r,i=0,s=!1,a=RegExp(f,"ig"+E);for(;r=a.exec(e);){i=r.index;let e=t+i,l=e-1;if(-1==l||D.test(u[l])){d++,s=!0;break}if(T.test(u[l]+u[e])){S++,s=!0;break}}if(s){y.push(b,i,o),b+=O(c,l,i,o),n=f,m=o,j=!0;break}}R=!0;break}r=!1}}if(t==u.length||D.test(u[t]))j&&I++;else{if(2==g){R=!0;break}if(Z&&T.test(u[t-1]+u[t]))j&&A++;else{if(1==g){R=!0;break}i=!1}}j&&(k+=o,r&&i&&z++)}if(m>o&&(L+=m-o),t>0&&(C+=c[l-1].length),!e.intraFilt(f,n,b)){R=!0;break}h-1>t&&(b+=m+c[l+1].length)}if(!R){o.idx[m]=t[n],o.interLft2[m]=d,o.interLft1[m]=S,o.interRgt2[m]=I,o.interRgt1[m]=A,o.chars[m]=k,o.terms[m]=z,o.interIns[m]=C,o.intraIns[m]=L,o.start[m]=x;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},O=(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,l,n=!1,r=1e3,i)=>{let s=null,a=null,g=[];l=l.replace(A,(e=>(g.push(e.trim().slice(1)),"")));let h,u=$(l);if(g.length>0){if(h=RegExp(g.join("|"),"i"+E),0==u.length){let e=[];for(let l=0;t.length>l;l++)h.test(t[l])||e.push(l);return[e,null,null]}}else if(0==u.length)return[null,null,null];if(n){let e=$(l);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==i?.length)return[[],null,null];i=M(t,l[e],i)}s=f(e).map((e=>e.join(" "))),a=[];let n=new Set;for(let e=0;s.length>e;e++)if(i.length>n.size){let l=i.filter((e=>!n.has(e))),r=M(t,s[e],l);for(let e=0;r.length>e;e++)n.add(r[e]);a.push(r)}else a.push([])}}null==s&&(s=[l],a=[i?.length>0?i:M(t,l)]);let c=null,o=null;if(g.length>0&&(a=a.map((e=>e.filter((e=>!h.test(t[e])))))),r>=a.reduce(((e,t)=>e+t.length),0)){c={},o=[];for(let l=0;a.length>l;l++){let n=a[l];if(null==n||0==n.length)continue;let r=s[l],i=F(n,t,r),g=e.sort(i,t,r);if(l>0)for(let e=0;g.length>e;e++)g[e]+=o.length;for(let e in i)c[e]=(c[e]??[]).concat(i[e]);o=o.concat(g)}}return[[].concat(...a),c,o]})(...t),split:$,filter:M,info:F,sort:e.sort}}const g=(()=>{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 f(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 h=(e,t)=>t?`<mark>${e}</mark>`:e,u=(e,t)=>e+t;return a.latinize=g,a.permute=e=>f([...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])))),a.highlight=function(e,t,l=h,n="",r=u){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},a}();
{
"name": "@leeoniya/ufuzzy",
"version": "1.0.6",
"version": "1.0.7",
"description": "A tiny, efficient fuzzy matcher that doesn't suck",

@@ -41,5 +41,5 @@ "main": "./dist/uFuzzy.cjs.js",

"devDependencies": {
"@rollup/plugin-terser": "^0.4.0",
"rollup": "^3.19.0"
"@rollup/plugin-terser": "^0.4.3",
"rollup": "^3.23.0"
}
}

@@ -15,3 +15,3 @@ ## ▒ μFuzzy

in SingleError mode, single typos are tolerated in each term (like [Damerau–Levenshtein distance](https://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance) = 1, but much faster).
Its `.search()` API can efficiently [match out-of-order terms](https://leeoniya.github.io/uFuzzy/demos/compare.html?libs=uFuzzy&outOfOrder&search=spac%20ca) and supports multiple substring exclusions, e.g. `fruit -green -melon`.
Its `.search()` API can efficiently [match out-of-order terms](https://leeoniya.github.io/uFuzzy/demos/compare.html?libs=uFuzzy&outOfOrder&search=spac%20ca), supports multiple substring exclusions (e.g. `fruit -green -melon`), and exact terms with non-alphanum chars (e.g. `"C++"`, `"$100"`, `"#hashtag"`).
When held _just right_, it can efficiently match against multiple object properties, too.

@@ -43,2 +43,15 @@

This seems to work universally, at some perf cost:
```js
let opts = {
unicode: true,
interSplit: "[^\\p{L}\\d']+",
intraSplit: "\\p{Ll}\\p{Lu}",
intraBound: "\\p{L}\\d|\\d\\p{L}|\\p{Ll}\\p{Lu}",
intraChars: "[\\p{L}\\d']",
intraContr: "'\\p{L}{1,2}\\b",
};
```
All searches are currently case-insensitive; it is not possible to do a case-sensitive search.

@@ -827,2 +840,15 @@

<td>
<a href="https://github.com/localvoid/ndx">ndx</a>
(<a href="https://leeoniya.github.io/uFuzzy/demos/compare.html?libs=ndx&search=super%20ma">try</a>)
</td>
<td>★ 130</td>
<td>2.9KB</td>
<td>350ms</td>
<td>675ms</td>
<td>441MB</td>
<td>273MB</td>
<td>420ms</td>
</tr>
<tr>
<td>
<a href="https://github.com/jhawthorn/fzy.js/">fzy</a>

@@ -829,0 +855,0 @@ (<a href="https://leeoniya.github.io/uFuzzy/demos/compare.html?libs=fzy&search=super%20ma">try</a>)

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