qsu
Version:
qsu is a utility library that contains useful and frequently used functions. Start with your preferred language and the modern development environment.
1 lines • 504 B
JavaScript
export function removeLocalePrefix(e,r){const n=Array.isArray(r)?r:[r];if(n.includes(e.replace(/^\//,"")))return"";if("/"===e)return"/";const t=n.join("|");try{const r=new URL(e);return"/"===r.pathname||n.includes(r.pathname.replace(/^\//,""))?r.origin:`${r.origin}${r.pathname.replace(new RegExp(`^/(${t})/`),"/")}`.replace(/\/$/,"")}catch{let r=e;return r.startsWith("/")||(r=`/${r}`),r.endsWith("/")&&(r=r.replace(/\/$/,"")),new RegExp(`^/(${t})$`).test(r)?"/":r.replace(new RegExp(`^/(${t})/`),"/")}}