UNPKG

foxts

Version:

Opinionated collection of common TypeScript utils by @SukkaW

2 lines (1 loc) 802 B
import{falseFn as e}from"./noop.mjs";let t=new Set([".","?","*","+","^","$","|","(",")","{","}","[","]","\\"]);function n(e,r=!1){let l={},o=(e,t)=>{let n,r=l;for(let l=0,o=e.length;l<o;++l)(n=e.charAt(l))in r||(r[n]=t?{"":""}:{}),r=r[n];r[""]=""};for(let t=0,n=e.length;t<n;++t)o(e[t],r);let i=()=>(function e(n){let r,l,o=!1,i=!1,u=[],f=[];for(let r in n){if(!r){o=!0;continue}((l=e(n[r]))?u:f).push(("-"===r?"\\x2d":t.has(r)?"\\"+r:r)+l)}return o&&null==l?"":(i=!u.length,f.length&&u.push(f[1]?"["+f.join("")+"]":f[0]),r=u[1]?"(?:"+u.join("|")+")":u[0],o&&(r=i?r+"?":"(?:"+r+")?"),r||"")})(l);return{tree:l,add:o,toString:i,toRe:()=>new RegExp((r?"^":"")+i())}}function r(t,l=!1){if(0===t.length)return e;let o=n(t,l).toRe();return o.test.bind(o)}export{r as createRetrieKeywordFilter,n as retrie};