diff options
| author | rxliuli <rxliuli@gmail.com> | 2025-11-04 05:03:50 +0800 |
|---|---|---|
| committer | rxliuli <rxliuli@gmail.com> | 2025-11-04 05:03:50 +0800 |
| commit | bce557cc2dc767628bed6aac87301a1be7c5431b (patch) | |
| tree | b51a051228d01fe3306cd7626d4a96768aadb944 /src/utils/url.ts | |
init commit
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; +} |
