diff --git a/src/lib/Link.svelte b/src/lib/Link.svelte index b3aa972..c35a3cf 100644 --- a/src/lib/Link.svelte +++ b/src/lib/Link.svelte @@ -1,30 +1,43 @@ { } return str; }; + +/** + * Trims the specified character from the start and/or end of the string. + * @param str The string to trim. + * @param char The character to trim. + * @param trimStart Whether to trim from the start of the string. Default: true. + * @param trimEnd Whether to trim from the end of the string. Default: true. + * @returns The trimmed string. + */ +export const trimEdges = (str: string, char: string, trimStart?: boolean, trimEnd?: boolean) => { + let start = 0, + end = str.length; + + if (trimStart || trimStart === undefined) { + while (start < end && str[start] === char) start++; + } + + if (trimEnd || trimEnd === undefined) { + while (end > start && str[end - 1] === char) end--; + } + + return str.substring(start, end); +}; diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index c905127..0472751 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -476,6 +476,23 @@ {/snippet} + +
+

Link (with href rewriting)

+ +

+ href rewriting allows you to prepend a basepath to relative links, making it easier to manage + URLs in your application. It is recommended to wrap this element with your own, e.g. AppLink, + that automatically provides the basepath from your app's configuration. +

+ +
+ Go to About Page (with basepath) + External Svelte Site + Contact Us (relative link, no basepath) +
+
+