-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use plain url strings intead of URL instance
- Loading branch information
1 parent
a90318d
commit 04b1828
Showing
3 changed files
with
36 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,21 @@ | ||
exports.appendTrailingSlash = (url) => | ||
url.pathname.endsWith('/') ? url : new URL(`${url.pathname}/`, url.origin); | ||
const hasQueryParams = (urlString) => { | ||
const url = new URL(urlString); | ||
|
||
exports.stripTrailingSlash = (url) => | ||
url.pathname.endsWith('/') | ||
? new URL(url.replace(/\/$/, ''), url.origin) | ||
: url; | ||
return Boolean(url.search); | ||
}; | ||
|
||
exports.appendTrailingSlash = (url) => { | ||
if (hasQueryParams(url)) { | ||
return url; | ||
} | ||
|
||
return url.endsWith('/') ? url : `${url}/`; | ||
}; | ||
|
||
exports.stripTrailingSlash = (url) => { | ||
if (hasQueryParams(url)) { | ||
return url; | ||
} | ||
|
||
return url.endsWith('/') ? url.replace(/\/$/, '') : url; | ||
}; |