Cleanup lib exports (#50)

This commit is contained in:
Ollie Taylor
2023-07-29 17:57:14 +01:00
committed by GitHub
parent bba24215eb
commit 528457fe59
59 changed files with 697 additions and 853 deletions
+33
View File
@@ -0,0 +1,33 @@
/**
* An object representing a relative URL.
*/
interface RelativeURL {
pathname: string;
search: string;
hash: string;
searchParams: URLSearchParams;
}
/**
* Converts a string to a URL object. If the string is not a valid URL, it will be appended to the Svelte website URL.
* @param href - The string to convert to a URL object.
* @returns A URL object.
*/
function string_to_url(href: string): URL {
try {
return new URL(href);
} catch (e) {
return new URL(href, 'https://svelte.dev');
}
}
/**
* Parses a URL string and returns an object containing its pathname, search, hash, and searchParams.
* @param href - The URL string to parse.
* @returns An object containing the pathname, search, hash, and searchParams of the URL.
*/
export function use_url(href: string): RelativeURL {
const { pathname, search, hash, searchParams } = string_to_url(href);
return { pathname, search, hash, searchParams };
}