Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(shared): reduce regexp match usage (#1315)
- Loading branch information
1 parent
3382bb1
commit 23bdec6
Showing
5 changed files
with
13 additions
and
8 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,4 +1,5 @@ | ||
/** | ||
* Remove ending slash / from a string | ||
*/ | ||
export const removeEndingSlash = (str: string): string => str.replace(/\/$/, '') | ||
export const removeEndingSlash = (str: string): string => | ||
str[str.length - 1] === '/' ? str.slice(0, -1) : str |
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,6 +1,10 @@ | ||
export const resolveRoutePathFromUrl = (url: string, base = '/'): string => | ||
url | ||
export const resolveRoutePathFromUrl = (url: string, base = '/'): string => { | ||
const pathname = url | ||
// remove url origin | ||
.replace(/^(https?:)?\/\/[^/]*/, '') | ||
// remove site base | ||
.replace(new RegExp(`^${base}`), '/') | ||
|
||
// remove site base | ||
return pathname.startsWith(base) | ||
? `/${pathname.slice(base.length)}` | ||
: pathname | ||
} |