diff options
Diffstat (limited to 'src/utils/url.ts')
| -rw-r--r-- | src/utils/url.ts | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/utils/url.ts b/src/utils/url.ts new file mode 100644 index 0000000..8596d89 --- /dev/null +++ b/src/utils/url.ts @@ -0,0 +1,13 @@ +/** + * Removes the protcol, host and port from a URL, returning + * just the path and search portions + * + * This is useful for taking a URL that points to the production site + * and removing anything specific to the location that it is deployed, + * creating a partial URL that works both locally or when deployed + */ +export function stripHost(input: string): string { + const url = new URL(input); + + return url.pathname + url.search; +} |
