UNPKG

@webreflection/re

Version:

A template literal tag that sanitizes interpolations

2 lines (1 loc) 371 B
const e=RegExp.escape||function(e){if("string"!=typeof e)throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")},r=r=>e(r);var t=({raw:e},...t)=>{let[n]=e,{length:a}=e,c=0;for(;++c<a;)n+=[].concat(t[c-1]).map(r).join("|")+e[c];return c=n.lastIndexOf("/"),new RegExp(n.slice(1,c),n.slice(c+1))};export{t as default};