stripOrigin.tsx 343 B

12345678910111213141516
  1. function parseUrl(url: string) {
  2. try {
  3. return new URL(url);
  4. } catch {
  5. return undefined;
  6. }
  7. }
  8. /**
  9. * Accept a url like:
  10. * `https://example.com/path/name?query=params#hash` and return
  11. * `/path/name?query=params#hash`
  12. */
  13. export default function stripOrigin(url: string) {
  14. return url.replace(parseUrl(url)?.origin ?? '', '');
  15. }