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.8 to 1.0.9

32

dist/uFuzzy.cjs.js

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

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

@@ -20,3 +20,3 @@

// meh, magic tmp placeholder, must be tolerant to toLowerCase(), interSplit, and intraSplit
// meh, magic tmp placeholder, must be tolerant to toLocaleLowerCase(), interSplit, and intraSplit
const EXACT_HERE = 'eexxaacctt';

@@ -27,3 +27,3 @@

const swapLetters = (str, upper, lower) => str.replace(LATIN_UPPER, upper).replace(LATIN_LOWER, lower);
const swapAlpha = (str, upper, lower) => str.replace(LATIN_UPPER, upper).replace(LATIN_LOWER, lower);

@@ -34,3 +34,3 @@ const OPTS = {

letters: null,
alpha: null,

@@ -142,13 +142,13 @@ // term segmentation & punct/whitespace merging

let letters = opts.letters;
let alpha = opts.letters ?? opts.alpha;
if (letters != null) {
let upper = letters.toUpperCase();
let lower = letters.toLowerCase();
if (alpha != null) {
let upper = alpha.toLocaleUpperCase();
let lower = alpha.toLocaleLowerCase();
_interSplit = swapLetters(_interSplit, upper, lower);
_intraSplit = swapLetters(_intraSplit, upper, lower);
_intraBound = swapLetters(_intraBound, upper, lower);
intraChars = swapLetters(intraChars, upper, lower);
intraContr = swapLetters(intraContr, upper, lower);
_interSplit = swapAlpha(_interSplit, upper, lower);
_intraSplit = swapAlpha(_intraSplit, upper, lower);
_intraBound = swapAlpha(_intraBound, upper, lower);
intraChars = swapAlpha(intraChars, upper, lower);
intraContr = swapAlpha(intraContr, upper, lower);
}

@@ -221,3 +221,3 @@

needle = needle.replace(trimRe, '').toLowerCase();
needle = needle.replace(trimRe, '').toLocaleLowerCase();

@@ -464,3 +464,3 @@ if (withIntraSplit)

for (let j = 0, k = 2; j < partsLen; j++, k+=2) {
let group = m[k].toLowerCase();
let group = m[k].toLocaleLowerCase();
let part = parts[j];

@@ -476,3 +476,3 @@ let term = part[0] == '"' ? part.slice(1, -1) : part + contrs[j];

// probe for exact match in inter junk
let idxOf = m[k+1].toLowerCase().indexOf(term);
let idxOf = m[k+1].toLocaleLowerCase().indexOf(term);

@@ -479,0 +479,0 @@ if (idxOf > -1) {

@@ -106,5 +106,8 @@ declare class uFuzzy {

// regexp character class [] of chars which should be treated as letters (case insensitive)
/** @deprecated renamed to opts.alpha */
letters?: PartialRegExp | null; // a-z
// regexp character class [] of chars which should be treated as letters (case insensitive)
alpha?: PartialRegExp | null; // a-z
/** term segmentation & punct/whitespace merging */

@@ -111,0 +114,0 @@ interSplit?: PartialRegExp; // '[^A-Za-z0-9]+'

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

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

@@ -18,3 +18,3 @@

// meh, magic tmp placeholder, must be tolerant to toLowerCase(), interSplit, and intraSplit
// meh, magic tmp placeholder, must be tolerant to toLocaleLowerCase(), interSplit, and intraSplit
const EXACT_HERE = 'eexxaacctt';

@@ -25,3 +25,3 @@

const swapLetters = (str, upper, lower) => str.replace(LATIN_UPPER, upper).replace(LATIN_LOWER, lower);
const swapAlpha = (str, upper, lower) => str.replace(LATIN_UPPER, upper).replace(LATIN_LOWER, lower);

@@ -32,3 +32,3 @@ const OPTS = {

letters: null,
alpha: null,

@@ -140,13 +140,13 @@ // term segmentation & punct/whitespace merging

let letters = opts.letters;
let alpha = opts.letters ?? opts.alpha;
if (letters != null) {
let upper = letters.toUpperCase();
let lower = letters.toLowerCase();
if (alpha != null) {
let upper = alpha.toLocaleUpperCase();
let lower = alpha.toLocaleLowerCase();
_interSplit = swapLetters(_interSplit, upper, lower);
_intraSplit = swapLetters(_intraSplit, upper, lower);
_intraBound = swapLetters(_intraBound, upper, lower);
intraChars = swapLetters(intraChars, upper, lower);
intraContr = swapLetters(intraContr, upper, lower);
_interSplit = swapAlpha(_interSplit, upper, lower);
_intraSplit = swapAlpha(_intraSplit, upper, lower);
_intraBound = swapAlpha(_intraBound, upper, lower);
intraChars = swapAlpha(intraChars, upper, lower);
intraContr = swapAlpha(intraContr, upper, lower);
}

@@ -219,3 +219,3 @@

needle = needle.replace(trimRe, '').toLowerCase();
needle = needle.replace(trimRe, '').toLocaleLowerCase();

@@ -462,3 +462,3 @@ if (withIntraSplit)

for (let j = 0, k = 2; j < partsLen; j++, k+=2) {
let group = m[k].toLowerCase();
let group = m[k].toLocaleLowerCase();
let part = parts[j];

@@ -474,3 +474,3 @@ let term = part[0] == '"' ? part.slice(1, -1) : part + contrs[j];

// probe for exact match in inter junk
let idxOf = m[k+1].toLowerCase().indexOf(term);
let idxOf = m[k+1].toLocaleLowerCase().indexOf(term);

@@ -477,0 +477,0 @@ if (idxOf > -1) {

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

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

@@ -21,3 +21,3 @@

// meh, magic tmp placeholder, must be tolerant to toLowerCase(), interSplit, and intraSplit
// meh, magic tmp placeholder, must be tolerant to toLocaleLowerCase(), interSplit, and intraSplit
const EXACT_HERE = 'eexxaacctt';

@@ -28,3 +28,3 @@

const swapLetters = (str, upper, lower) => str.replace(LATIN_UPPER, upper).replace(LATIN_LOWER, lower);
const swapAlpha = (str, upper, lower) => str.replace(LATIN_UPPER, upper).replace(LATIN_LOWER, lower);

@@ -35,3 +35,3 @@ const OPTS = {

letters: null,
alpha: null,

@@ -143,13 +143,13 @@ // term segmentation & punct/whitespace merging

let letters = opts.letters;
let alpha = opts.letters ?? opts.alpha;
if (letters != null) {
let upper = letters.toUpperCase();
let lower = letters.toLowerCase();
if (alpha != null) {
let upper = alpha.toLocaleUpperCase();
let lower = alpha.toLocaleLowerCase();
_interSplit = swapLetters(_interSplit, upper, lower);
_intraSplit = swapLetters(_intraSplit, upper, lower);
_intraBound = swapLetters(_intraBound, upper, lower);
intraChars = swapLetters(intraChars, upper, lower);
intraContr = swapLetters(intraContr, upper, lower);
_interSplit = swapAlpha(_interSplit, upper, lower);
_intraSplit = swapAlpha(_intraSplit, upper, lower);
_intraBound = swapAlpha(_intraBound, upper, lower);
intraChars = swapAlpha(intraChars, upper, lower);
intraContr = swapAlpha(intraContr, upper, lower);
}

@@ -222,3 +222,3 @@

needle = needle.replace(trimRe, '').toLowerCase();
needle = needle.replace(trimRe, '').toLocaleLowerCase();

@@ -465,3 +465,3 @@ if (withIntraSplit)

for (let j = 0, k = 2; j < partsLen; j++, k+=2) {
let group = m[k].toLowerCase();
let group = m[k].toLocaleLowerCase();
let part = parts[j];

@@ -477,3 +477,3 @@ let term = part[0] == '"' ? part.slice(1, -1) : part + contrs[j];

// probe for exact match in inter junk
let idxOf = m[k+1].toLowerCase().indexOf(term);
let idxOf = m[k+1].toLocaleLowerCase().indexOf(term);

@@ -480,0 +480,0 @@ if (idxOf > -1) {

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

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

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

"@rollup/plugin-terser": "^0.4.3",
"rollup": "^3.25.3"
"rollup": "^3.29.0"
}
}

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

Support for more languages works by augmenting the built-in Latin regexps with additional chars or by using the slower, universal `{unicode: true}` variant.
A more simple, but less flexible `{letters: "..."}` alternative replaces the `A-Z` and `a-z` parts of the built-in Latin regexps with chars of your choice (the letter case will be matched automatically during replacement).
A more simple, but less flexible `{alpha: "..."}` alternative replaces the `A-Z` and `a-z` parts of the built-in Latin regexps with chars of your choice (the letter case will be matched automatically during replacement).

@@ -43,3 +43,3 @@ The `uFuzzy.latinize()` util function may be used to strip common accents/diacritics from the haystack and needle prior to searching.

// Latin (default)
let opts = { letters: "a-z" };
let opts = { alpha: "a-z" };
// OR

@@ -57,3 +57,3 @@ let opts = {

// Latin + Norwegian
let opts = { letters: "a-zæøå" };
let opts = { alpha: "a-zæøå" };
// OR

@@ -69,3 +69,3 @@ let opts = {

// Latin + Russian
let opts = { letters: "a-zа-яё" };
let opts = { alpha: "a-zа-яё" };
// OR

@@ -72,0 +72,0 @@ let opts = {

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