Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

Commit

Permalink
feat(shared): add slash utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Jun 3, 2022
1 parent 0b69830 commit d265df7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/shared/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@ export {
getTag,
isAbsoluteUrl,
isUrl,
ensureEndingSlash,
ensureLeadingSlash,
removeEndingSlash,
removeLeadingSlash,
timeTransformer,
} from "../shared";
12 changes: 12 additions & 0 deletions packages/shared/src/shared/utils/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,15 @@ export const isUrl = (test: string): boolean => {
};

export const isAbsoluteUrl = (test: string): boolean => test.startsWith("/");

export const ensureEndingSlash = (str: string): string =>
str.replace(/\/?$/, "/");

export const ensureLeadingSlash = (str: string): string =>
str.replace(/^\/?/, "/");

export const removeEndingSlash = (str: string): string =>
str.replace(/\/$/, "");

export const removeLeadingSlash = (str: string): string =>
str.replace(/^\//, "");

0 comments on commit d265df7

Please sign in to comment.